Ejemplo n.º 1
0
def main():
    initial_structs = []
    final_structs = []
    with connect(dft_db) as db:
        groups = set()
        for row in db.select():
            groups.add(row.get('group', -1))

        for g in groups:
            try:
                init = db.get([('group', '=', g),
                               ('struct_type', '=', 'initial')])
                final = db.get([('group', '=', g),
                                ('struct_type', '=', 'relaxed')])
                initial_structs.append(init.toatoms())
                final_structs.append(final.toatoms())
            except KeyError:
                pass

    # Sanity checks
    for i, f in zip(initial_structs, final_structs):
        i_formula = i.get_chemical_formula()
        f_formula = f.get_chemical_formula()
        assert i_formula == f_formula

    print(f"Extracted {len(initial_structs)} structures")

    new_struct = NewStructures(settings)
    for i, f in zip(initial_structs, final_structs):
        print(f"Inserting struct {i.get_chemical_formula()}")
        try:
            new_struct.insert_structure(i, f)
        except:
            pass
Ejemplo n.º 2
0
def new_db(kwargs, new_db_name):
    db_name = "almgsi_newconfig.db"
    kwargs["db_name"] = new_db_name
    bc = BulkCrystal(**kwargs)
    names = []
    db = connect(db_name)
    for row in db.select(converged=1):
        names.append(row.name)

    ns = GenerateStructures(bc, struct_per_gen=10)
    for name in names:
        print(name)
        init_struct = None
        final_struct = None
        energy = 0.0
        for row in db.select(name=name):
            if row["calculator"] == "unknown":
                energy = row.energy
                init_struct = row.toatoms()
            else:
                final_struct = row.toatoms()
        calc = SinglePointCalculator(final_struct, energy=energy)
        final_struct.set_calculator(calc)
        try:
            ns.insert_structure(init_struct=init_struct, final_struct=final_struct, generate_template=True)
        except Exception as exc:
            print(str(exc))
Ejemplo n.º 3
0
def main(argv):
    option = argv[0]
    N = 4
    conc = Concentration(basis_elements=[["Al", "Mg", "Si", "X"]])
    kwargs = dict(crystalstructure="fcc", a=4.05, size=[N,N,N],
        db_name=db_name, max_cluster_size=4, max_cluster_dia=[0.0, 0.0, 5.0, 4.1, 4.1],
        concentration=conc)
    ceBulk = BulkCrystal(**kwargs)

    struc_generator = GenerateStructures( ceBulk, struct_per_gen=10, generation_number=100 )
    if option == "reconfig_settings":
        ceBulk.reconfigure_settings()
    elif option == "insert":
        fname = argv[1]
        struc_generator.insert_structure(init_struct=fname)
    elif option == "random":
        atoms = get_random_structure()
        struc_generator.insert_structure(init_struct=atoms)
    elif option == "evaluate":
        evaluate(ceBulk)
    elif option == "newdb":
        new_db_name = argv[1]
        new_db(kwargs, new_db_name)
    elif option == "reconfig_db":
        corr_func = CorrFunction(ceBulk, parallel=True)
        scond = [("calculator", "!=", "gpaw"),
                 ("name", "!=", "information"),
                 ("name", "!=", "template"),
                 ("converged", "=", 1)]
        corr_func.reconfigure_db_entries(select_cond=scond)
    elif option == "gs":
        get_gs_allgs(ceBulk, struc_generator)
Ejemplo n.º 4
0
def main(argv):
    option = argv[0]
    atoms = bulk("Al")
    N = 4
    atoms = atoms*(N, N, N)
    conc = Concentration(basis_elements=[["Al","Mg","Si"]])
    kwargs = dict(crystalstructure="fcc", a=4.05, size=[N, N, N], \
        db_name=db_name, max_cluster_size=4, concentration=conc,
        basis_function="sanchez", max_cluster_dia=[7.8, 5.0, 5.0])
    ceBulk = BulkCrystal(**kwargs)
    #ceBulk.reconfigure_settings()
    #print (ceBulk.basis_functions)
    #cf = CorrFunction( ceBulk, parallel=True)
    #cf.reconfigure_db_entries(select_cond=[("converged","=","1")])
    #exit()
    #print(ceBulk.basis_functions)
    struc_generator = GenerateStructures( ceBulk, struct_per_gen=10 )
    if ( option == "generateNew" ):
        struc_generator.generate_probe_structure()
    elif ( option == "eval" ):
        #evaluate(ceBulk)
        #evaluate_l1(ceBulk)
        evaluate_test(ceBulk)
        #evaluate_car(ceBulk)
        #evaluate_sklearn(ceBulk)
    elif option == "skew":
        insert_skewed_full(struc_generator, size1=int(argv[1]), size2=int(argv[2]))
    elif ( option == "insert" ):
        fname = argv[1]
        atoms = read(fname)
        struc_generator.insert_structure( init_struct=atoms )
        #insert_specific_structure( ceBulk, struc_generator, atoms )
    elif ( option == "formation" ):
        enthalpy_of_formation(ceBulk)
    elif ( option == "gsstruct" ):
        if ( len(argv) != 3 ):
            raise ValueError( "If option is gsstruct. The arguments has to be gsstruct mg_conc si_conc" )
        mg_conc = float( argv[1] )
        si_conc = float( argv[2] )
        find_gs_structure( ceBulk, mg_conc, si_conc )
    elif ( option == "update_conc_range" ):
        update_in_conc_range()
    elif ( option == "allgs" ):
        find_all_gs( ceBulk, struc_generator )
    elif( option == "cv_hist" ):
        lambdas = np.logspace(-7,-3,8)
        history = CVScoreHistory(setting=ceBulk, penalization="L1", select_cond=[("in_conc_range","=","1")] )
        history.get_history( lambdas=lambdas )
        history.plot()
        plt.show()
    elif( option == "chempot" ):
        estimate_chemical_potentials(ceBulk)
    elif (option == "convert2cubic"):
        convert_to_cubic(ceBulk)
    elif option == "new_db":
        new_db_name = argv[1]
        new_db(kwargs, new_db_name)
def initialize_db():
    db_name = "data/almgsiX_clease_voldep.db"

    settings = CEBulk(
        Concentration(basis_elements=[['Al', 'Mg', 'Si', 'X']]),
        crystalstructure='fcc',
        a=4.05, size=[1, 1, 1], max_cluster_size=3,
        max_cluster_dia=[5.0, 5.0],
        db_name=db_name
    )
    settings.basis_func_type = 'binary_linear'

    newStruct = NewStructures(settings)

    # Insert all initial structures
    counter = 0
    with connect(db_local) as db:
        for row in db.select():
            counter += 1
            print(f"Inserting structure {counter}")
            name = f"group{row.group}"
            atoms = row.toatoms()
            newStruct.insert_structure(atoms, name=name)
    
    data = pd.read_csv("data/bulk_mod_fit.csv")
    db = connect(settings.db_name)
    counter = 0
    for row in data.itertuples():
        print(f"Inserting final structure {counter}")
        counter += 1
        try:
            name = f"group{row[1]}"
            #print(name)
            #exit()
            E = row[2]
            B = row[3]
            V = row[4]
            dBdP = row[5]
            L = V**(1.0/3.0)
            atoms = Atoms(cell=[L, L, L])
            calc = SinglePointCalculator(atoms, energy=E)
            atoms.set_calculator(calc)

            print(name)
            init_id = db.get([('name', '=', name)]).id
            update_db(init_id, final_struct=atoms, db_name=settings.db_name,
                    custom_kvp_init={'bulk_mod': B, 'dBdP': dBdP})
        except Exception as exc:
            print(exc)
            traceback.print_exc()

    settings.save("data/settings_almgsiX_voldev.json")
Ejemplo n.º 6
0
def main():
    conc = Concentration(basis_elements=[['Al', 'Mg']],
                         A_lb=[[10, 0]],
                         b_lb=[7])
    settings = CEBulk(conc,
                      crystalstructure='fcc',
                      a=4.05,
                      size=[4, 4, 4],
                      max_cluster_size=4,
                      max_cluster_dia=[4.1, 4.1, 4.1],
                      db_name='almg_ce.db')

    # Generate 30 structures
    new_struct = NewStructures(settings, struct_per_gen=30)
    new_struct.generate_random_structures()
Ejemplo n.º 7
0
def insert_from_db(old_db_name, setting):
    db = connect(old_db_name)
    names = []
    for row in db.select(converged=1):
        names.append(row.name)

    ns = NewStructures(setting, struct_per_gen=10)
    for name in names:
        ignore = False
        print(name)
        init_struct = None
        final_struct = None
        energy = 0.0
        num_occ = sum(1 for _ in db.select(name=name))
        for row in db.select(name=name):
            if row["calculator"] == "unknown":
                energy = row.energy
                init_struct = row.toatoms()

                if num_occ != 2:
                    final_struct = row.toatoms()
            elif row["calculator"] == 'none':
                init_struct = row.toatoms()

                fid = row.get('final_struct_id', -1)
                if fid != -1:
                    final_struct = db.get(id=fid).toatoms()
                    energy = db.get(id=fid).get('energy', None)
                    if energy is None:
                        ignore = True
                    break
            else:
                final_struct = row.toatoms()

        calc = SinglePointCalculator(final_struct, energy=energy)
        final_struct.set_calculator(calc)
        try:
            ns.insert_structure(init_struct=init_struct,
                                final_struct=final_struct,
                                generate_template=True)
        except Exception as exc:
            print(str(exc))
Ejemplo n.º 8
0
def reconfigure_almgsi(): 
    conc = Concentration(basis_elements=[["Al", "Mg", "Si"]])
    kwargs = dict(crystalstructure="fcc", a=4.05, size=[1, 1, 1], \
        db_name=db_name, max_cluster_size=4, concentration=conc, max_cluster_dia=[7.8, 5.0, 5.0])
    ceBulk = CEBulk(**kwargs)

    db = connect(db_name_old)
    counter = 0
    new_struct = NewStructures(ceBulk)
    for row in db.select([('converged', '=', 1)]):
        print("ROW: {}".format(counter))
        counter += 1
        init = row.toatoms()
        final = init.copy()
        energy = row.get('energy', None)
        if energy is None:
            final_struct_id = row.final_struct_id
            energy = db.get(id=final_struct_id).energy
        calc = SinglePointCalculator(final, energy=energy)
        final.set_calculator(calc)
        new_struct.insert_structure(init_struct=init, final_struct=final)
Ejemplo n.º 9
0
def new_db(kwargs, new_db_name):
    from ase.db import connect
    from ase.calculators.singlepoint import SinglePointCalculator
    old_db_name = kwargs["db_name"]
    kwargs["db_name"] = new_db_name
    ceBulk = BulkCrystal(**kwargs)
    struc_generator = GenerateStructures( ceBulk, struct_per_gen=10 )
    names = []
    db = connect(old_db_name)
    for row in db.select(converged=1):
        names.append(row.name)
    
    for name in names:
        row = db.get(name=name, struct_type='initial')
        calc = row.get("calculator", "")
        energy = None
        init_struct = row.toatoms()
        if calc == "unknown":
            energy = row.energy

        if calc == "":
            final_struct = db.get(id=row.final_struct_id).toatoms()
        else:
            try:
                final_struct = db.get(name=name, struct_type='final').toatoms()
            except KeyError:
                final_struct = db.get(name=name, calculator='gpaw').toatoms()
        
        if energy is not None:
            sp = SinglePointCalculator(final_struct, energy=energy)
            final_struct.set_calculator(sp)
        
        assert final_struct.get_calculator() is not None
        try:
            struc_generator.insert_structure(init_struct=init_struct, final_struct=final_struct)
        except Exception as exc:
            print(str(exc))
Ejemplo n.º 10
0
def main():
    setting = settingFromJSON("almgsixSettings.json")
    setting.db_name = 'almgsiX_dft.db'
    new_struct = NewStructures(setting)
    new_struct.insert_structures(traj_init="data/restricted_gs_5x1x1.traj")