Exemplo n.º 1
0
def main(argv):
    n_mg = int(argv[0])
    atoms = bulk("Al")
    atoms = atoms * (4, 4, 4)
    for i in range(n_mg):
        atoms[i].symbol = "Mg"

    atoms.rattle(stdev=0.005)

    calc = gp.GPAW(mode=gp.PW(500), xc="PBE", kpts=(4, 4, 4), nbands="120%")
    atoms.set_calculator(calc)

    logfile = "preconTest%d.log" % (n_mg)
    traj = "preconTest%d.traj" % (n_mg)
    trajObj = Trajectory(traj, 'w', atoms)

    precon = Exp(mu=1)
    relaxer = PreconLBFGS(atoms,
                          logfile=logfile,
                          use_armijo=True,
                          precon=precon)
    relaxer.attach(trajObj)
    try:
        relaxer.run(fmax=0.05)
    except:
        pass
    print("Mu: %.2E" % (relaxer.precon.mu))
Exemplo n.º 2
0
def do_lattice(bulk, elastic=True):
    tol = 1e-3  # max force tol for relaxation
    n_E_vs_V_steps = 10

    # use one of the routines from utilities module to relax the initial
    # unit cell and atomic positions
    bulk = relax_atoms_cell(bulk, tol=tol, traj_file=None, symmetrize=True)

    print("relaxed bulk")
    ase.io.write(sys.stdout, bulk, format='extxyz')

    if elastic:
        # reset calculator to non-symmetrized one (not optimal, but would otherwise need to have optimizer used by fit_elastic_constants to reset symmetry for each relaxation):w
        calc = bulk.get_calculator().calc
        bulk.set_calculator(calc)
        precon = Exp(3.0)
        opt = lambda atoms, **kwargs: PreconLBFGS(
            atoms, precon=precon, **kwargs)
        elastic_consts = matscipy.elasticity.fit_elastic_constants(
            bulk, symmetry='cubic', optimizer=opt)
        c11 = elastic_consts[0][0, 0] / GPa
        c12 = elastic_consts[0][0, 1] / GPa
        c44 = elastic_consts[0][3, 3] / GPa

    V0 = bulk.get_volume()
    E_vs_V = []

    f = open("relaxed_E_vs_V_configs.xyz", "w")
    cell_scalings = np.linspace(0.90**(1.0 / 3.0), 1.1**(1.0 / 3.0), 30)
    for cell_scaling in cell_scalings:
        scaled_bulk = bulk.copy()
        scaled_bulk.set_calculator(bulk.get_calculator())
        scaled_bulk.set_cell(scaled_bulk.get_cell() * cell_scaling,
                             scale_atoms=True)
        scaled_bulk = relax_atoms_cell(scaled_bulk,
                                       tol=tol,
                                       traj_file=None,
                                       constant_volume=True,
                                       method='fire',
                                       symmetrize=True)
        # evaluate(scaled_bulk)
        ase.io.write(f, scaled_bulk, format='extxyz')
        E_vs_V.insert(0, (scaled_bulk.get_volume() / len(scaled_bulk),
                          scaled_bulk.get_potential_energy() / len(bulk)))

    for (V, E) in E_vs_V:
        print("EV_final ", V, E)

    if elastic:
        return (c11, c12, c44, E_vs_V)
    else:
        return (E_vs_V)
Exemplo n.º 3
0
def main(argv):
    relax_mode = "cell"  # both, cell, positions
    system = "AlMg"
    runID = int(argv[0])
    print("Running job: %d" % (runID))
    db_paths = [
        "/home/ntnu/davidkl/GPAWTutorial/CE/almg_217.db", "almg_217.db",
        "/home/davidkl/GPAWTutorial/CE/almg_217.db"
    ]
    for path in db_paths:
        if (os.path.isfile(path)):
            db_name = path
            break
    #db_name = "test_db.db"
    db = ase.db.connect(db_name)

    con = sq.connect(db_name)
    cur = con.cursor()
    cur.execute("SELECT value FROM text_key_values WHERE id=? AND key='name'",
                (runID, ))
    name = cur.fetchone()[0]
    con.close()

    new_run = not db.get(id=runID).key_value_pairs["started"]
    # Update the databse
    db.update(runID, started=True, converged=False)

    atoms = db.get_atoms(id=runID)

    calc = gp.GPAW(mode=gp.PW(500), xc="PBE", kpts=(4, 4, 4), nbands="120%")
    #calc = gp.GPAW( mode=gp.PW(500), xc="PBE", kpts=(4,4,4), nbands=-10 )
    atoms.set_calculator(calc)

    logfile = "almg_bcc%d.log" % (runID)
    traj = "almg_bcc%d.traj" % (runID)
    trajObj = Trajectory(traj, 'w', atoms)

    storeBest = SaveToDB(db_name, runID, name, mode=relax_mode)
    volume = atoms.get_volume()

    try:
        precon = Exp(mu=1.0, mu_c=1.0)
        fmax = 0.025
        smax = 0.003
        if (relax_mode == "both"):
            relaxer = PreconLBFGS(atoms,
                                  logfile=logfile,
                                  use_armijo=True,
                                  precon=precon,
                                  variable_cell=True)
        elif (relax_mode == "positions"):
            relaxer = SciPyFminCG(atoms, logfile=logfile)
            #relaxer = BFGS( atoms, logfile=logfile )
        elif (relax_mode == "cell"):
            str_f = StrainFilter(atoms, mask=[1, 1, 1, 0, 0, 0])
            relaxer = BFGS(str_f, logfile=logfile)
            fmax = smax * volume

        relaxer.attach(trajObj)
        relaxer.attach(storeBest, interval=1, atoms=atoms)
        if (relax_mode == "both"):
            relaxer.run(fmax=fmax, smax=smax)
        else:
            relaxer.run(fmax=fmax)
        energy = atoms.get_potential_energy()

        if (relax_mode == "positions"):
            db.update(storeBest.runID, converged_force=True)
        elif (relax_mode == "cell"):
            db.update(storeBest.runID, converged_stress=True)
        else:
            db.update(storeBest.runID,
                      converged_stress=True,
                      converged_force=True)

        row = db.get(id=storeBest.runID)
        conv_force = row.get("converged_force", default=0)
        conv_stress = row.get("converged_stress", default=0)
        if ((conv_force == 1) and (conv_stress == 1)):
            db.update(storeBest.runID, converged=True)
    except Exception as exc:
        print(exc)
Exemplo n.º 4
0
def main(argv):
    relaxCell = True
    system = "AlMg"
    runID = int(argv[0])
    print("Running job: %d" % (runID))
    db_paths = [
        "/home/ntnu/davidkl/GPAWTutorial/CE/ce_hydrostatic.db",
        "ce_hydrostatic.db", "/home/davidkl/GPAWTutorial/CE/ce_hydrostatic.db"
    ]
    for path in db_paths:
        if (os.path.isfile(path)):
            db_name = path
            break
    #db_name = "/home/ntnu/davidkl/Documents/GPAWTutorials/ceTest.db"
    db = ase.db.connect(db_name)

    con = sq.connect(db_name)
    cur = con.cursor()
    cur.execute("SELECT value FROM text_key_values WHERE id=? AND key='name'",
                (runID, ))
    name = cur.fetchone()[0]
    con.close()

    new_run = not db.get(id=runID).key_value_pairs["started"]
    # Update the databse
    db.update(runID, started=True, converged=False)

    atoms = db.get_atoms(id=runID)
    if (system == "AlMg" and new_run == False):
        atoms = change_cell_composition_AlMg(atoms)

    convergence = {"density": 1E-4, "eigenstates": 4E-8}
    calc = gp.GPAW(mode=gp.PW(500),
                   xc="PBE",
                   kpts=(4, 4, 4),
                   nbands="120%",
                   convergence=convergence)
    atoms.set_calculator(calc)

    logfile = "ceTest%d.log" % (runID)
    traj = "ceTest%d.traj" % (runID)
    trajObj = Trajectory(traj, 'w', atoms)

    storeBest = SaveToDB(db_name, runID, name)

    try:
        precon = Exp(mu=1.0, mu_c=1.0)
        if (relaxCell):
            uf = UnitCellFilter(atoms, hydrostatic_strain=True)
            relaxer = PreconLBFGS(uf,
                                  logfile=logfile,
                                  use_armijo=True,
                                  precon=precon)
        else:
            relaxer = PreconFIRE(atoms, logfile=logfile, precon=precon)
            relaxer = SciPyFminCG(atoms, logfile=logfile)
        relaxer.attach(trajObj)
        relaxer.attach(storeBest, interval=1, atoms=atoms)
        if (relaxCell):
            relaxer.run(fmax=0.025, smax=0.003)
        else:
            relaxer.run(fmax=0.025)
        energy = atoms.get_potential_energy()
        db.update(storeBest.runID, converged=True)
        print("Energy: %.2E eV/atom" % (energy / len(atoms)))
        print("Preconditioner parameters")
        print("Mu:", precon.mu)
        print("Mu_c:", precon.mu_c)
    except Exception as exc:
        print(exc)