def sa_sgc(): alat = 3.8 conc_args = {} conc_args['conc_ratio_min_1'] = [[1, 0]] conc_args['conc_ratio_max_1'] = [[0, 1]] kwargs = { "crystalstructure": 'fcc', "a": 3.8, "size": [10, 10, 10], # "size": [2, 2, 2], "basis_elements": [['Cu', 'Au']], "conc_args": conc_args, "db_name": 'temp_sgc{}.db'.format(rank), "max_cluster_size": 3, "max_cluster_dist": 1.5 * alat } with open("data/eci_aucu.json", 'r') as infile: eci = json.load(infile) bc = BulkCrystal(**kwargs) bc.reconfigure_settings() with open("data/eci_aucu.json", 'r') as infile: eci = json.load(infile) calc = get_ce_calc(bc, kwargs, eci=eci, size=[10, 10, 10]) bc = calc.BC bc.atoms.set_calculator(calc) atoms = bc.atoms chem_pot = (np.linspace(0.19, 0.35, 50)).tolist() T = np.linspace(100, 1000, 50)[::-1] equil_param = {"mode": "fixed", "maxiter": 10 * len(atoms)} nsteps = 100 * len(atoms) sgc_db = dataset.connect("sqlite:///{}".format(sgc_db_name)) tbl = sgc_db["results"] tbl_cf = sgc_db["corr_func"] orig_symbs = [atom.symbol for atom in atoms] for mu in chem_pot: chemical_potential = {"c1_0": mu} calc.set_symbols(orig_symbs) for temp in T: mc = SGCMonteCarlo(atoms, temp, mpicomm=comm, symbols=["Au", "Cu"]) init_formula = atoms.get_chemical_formula() mc.runMC(steps=nsteps, equil_params=equil_param, chem_potential=chemical_potential) thermo = mc.get_thermodynamic(reset_ecis=True) thermo["init_formula"] = init_formula thermo["final_formula"] = atoms.get_chemical_formula() if rank == 0: uid = tbl.insert(thermo) cf = calc.get_cf() cf["runID"] = uid tbl_cf.insert(cf)
def insert_energy(conc, T): alat = 3.8 conc_args = {} conc_args['conc_ratio_min_1'] = [[1, 0]] conc_args['conc_ratio_max_1'] = [[0, 1]] kwargs = { "crystalstructure": 'fcc', "a": 3.8, "size": [4, 4, 2], "basis_elements": [['Cu', 'Au']], "conc_args": conc_args, "db_name": 'temp_sgc{}.db'.format(rank), "max_cluster_size": 3, "max_cluster_dist": 1.5 * alat } bc = BulkCrystal(**kwargs) bc.reconfigure_settings() with open("data/eci_aucu.json", 'r') as infile: eci = json.load(infile) names = bc.cluster_names for key in eci.keys(): if key not in names: raise ValueError("{} is not in cluster_names".format(key)) calc = get_ce_calc(bc, kwargs, eci=eci, size=[10, 10, 10]) bc = calc.BC atoms = bc.atoms atoms.set_calculator(calc) comp = {"Au": conc, "Cu": 1.0 - conc} calc.set_composition(comp) symbs = [atom.symbol for atom in atoms] shuffle(symbs) calc.set_symbols(symbs) sampler = ActivitySampler(atoms, T, moves=[("Au", "Cu")], mpicomm=comm, prob_insert_move=0.1) equil = {"mode": "fixed", "maxiter": 10 * len(atoms)} nsteps = 100 * len(atoms) sampler.runMC(steps=nsteps, mode="fixed", equil_params=equil) thermo = sampler.get_thermodynamic() if rank == 0: db = dataset.connect("sqlite:///{}".format(db_name)) tbl = db["results"] tbl.insert(thermo)
def sa(al_comp, kwargs, eci, db_name, size, lattice): comp = {"Al": al_comp, "Zn": 1.0 - al_comp} bc = BulkCrystal(**kwargs) calc = get_ce_calc(bc, kwargs, eci, size) bc = calc.BC bc.atoms.set_calculator(calc) temperatures = [800, 700, 600, 500, 400, 300, 200, 100] N = len(bc.atoms) if rank == 0: print("Supercell has {} atoms".format(N)) # Define parameters for equillibration equil_params = {"maxiter": 10 * N, "mode": "fixed"} nsteps = 100 * N calc.set_composition(comp) for T in temperatures: mc = Montecarlo(bc.atoms, T, mpicomm=comm) mc.runMC(mode="fixed", steps=nsteps, equil_params=equil_params) thermo = mc.get_thermodynamic() thermo["converged"] = True thermo["al_conc"] = al_comp thermo["temperature"] = T if rank == 0: db = dataset.connect("sqlite:///{}".format(db_name)) tbl = db["results"] tbl.insert(thermo) if rank == 0: fname = "data/atoms_{}_{}.xyz".format(lattice, bc.atoms.get_chemical_formula()) write(fname, bc.atoms)
def main( argv ): option = argv[0] conc_args = { "conc_ratio_min_1":[[64,0,0]], "conc_ratio_max_1":[[0,48,16]], } ceBulk = BulkCrystal( crystalstructure="fcc", a=4.05, size=[4,4,4], basis_elements=[["Al","Mg","X"]], \ conc_args=conc_args, db_name=db_name, max_cluster_size=4 ) #ceBulk._get_cluster_information() #print (ceBulk.basis_functions) #cf = CorrFunction( ceBulk ) #cf.reconfig_db_entries() struct_gen = GenerateStructures( ceBulk, struct_per_gen=10 ) if ( option == "eval" ): evaluate( ceBulk ) elif( option == "gs" ): mg_conc = float(argv[1]) vac_conc = float(argv[2]) find_gs( ceBulk, mg_conc, vac_conc ) elif( option == "insert" ): fname = argv[1] struct_gen.insert_structure( init_struct=fname ) elif ( option == "gs_all" ): find_all_gs( ceBulk, struct_gen )
def main(): alat = 3.8 conc_args = {} conc_args['conc_ratio_min_1'] = [[1, 0]] conc_args['conc_ratio_max_1'] = [[0, 1]] kwargs_fcc = { "crystalstructure": 'fcc', "a": 3.8, "size": [4, 4, 2], # "size": [2, 2, 2], "basis_elements": [['Cu', 'Au']], "conc_args": conc_args, "db_name": 'cu-au_fcc_final.db', "max_cluster_size": 3, "max_cluster_dist": 1.5*alat } # alat = 3.9 # Something in between Cu and Au # kwargs_fcc = { # "crystalstructure": "fcc", # "a": alat, # "size": [2, 2, 4], # "basis_elements": [["Au", "Cu"]], # "conc_args": {"conc_ratio_min_1": [[1, 0]], # "conc_ratio_max_1": [[0, 1]]}, # "max_cluster_size": 4, # "max_cluster_dist": 1.05*alat, # "db_name": "data/au-cu_fcc.db" # } fcc = BulkCrystal(**kwargs_fcc) # fcc.reconfigure_settings() # gen_struct(fcc) # gs_struct(fcc) evaluate(fcc)
def init_BC(): conc_args = { "conc_ratio_min_1": [[64, 0, 0]], "conc_ratio_max_1": [[24, 40, 0]], "conc_ratio_min_2": [[64, 0, 0]], "conc_ratio_max_2": [[22, 21, 21]] } orig_spin_dict = {"Mg": 1.0, "Si": -1.0, "Al": 0.0} kwargs = { "crystalstructure": "fcc", "a": 4.05, "size": [4, 4, 4], "basis_elements": [["Mg", "Si", "Al"]], "conc_args": conc_args, "db_name": "data/almgsi.db", "max_cluster_size": 4 } ceBulk = BulkCrystal(**kwargs) ceBulk.spin_dict = orig_spin_dict ceBulk.basis_functions = ceBulk._get_basis_functions() ceBulk._get_cluster_information() eci_file = "data/almgsi_fcc_eci.json" with open(eci_file, 'r') as infile: ecis = json.load(infile) print(ecis) #calc = CE( ceBulk, ecis, size=(3,3,3) ) calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10]) ceBulk = calc.BC ceBulk.atoms.set_calculator(calc) return ceBulk
def get_ref_energies(): conc_args = { "conc_ratio_min_1": [[64, 0, 0]], "conc_ratio_max_1": [[0, 64, 0]], "conc_ratio_min_2": [[64, 0, 0]], "conc_ratio_max_2": [[0, 0, 64]] } orig_spin_dict = {"Mg": 1.0, "Si": -1.0, "Al": 0.0} kwargs = { "crystalstructure": "fcc", "a": 4.05, "size": [4, 4, 4], "basis_elements": [["Mg", "Si", "Al"]], "conc_args": conc_args, "db_name": "data/almgsi_excess.db", "max_cluster_size": 4 } ceBulk = BulkCrystal(**kwargs) ceBulk.spin_dict = orig_spin_dict ceBulk.basis_functions = ceBulk._get_basis_functions() # ceBulk._get_cluster_information() # ceBulk.reconfigure_settings() eci_file = "data/almgsi_fcc_eci_newconfig.json" with open(eci_file, 'r') as infile: ecis = json.load(infile) cf = CorrFunction(ceBulk) atoms = ceBulk.atoms cluster_names = ecis.keys() for atom in atoms: atom.symbol = "Al" corr_func = cf.get_cf_by_cluster_names(atoms, cluster_names) ref_energies = {} ref_energies["Al"] = get_energy(corr_func, ecis) for atom in atoms: atom.symbol = "Mg" corr_func = cf.get_cf_by_cluster_names(atoms, cluster_names) ref_energies["Mg"] = get_energy(corr_func, ecis) for atom in atoms: atom.symbol = "Si" corr_func = cf.get_cf_by_cluster_names(atoms, cluster_names) ref_energies["Si"] = get_energy(corr_func, ecis) return ref_energies
def run(T, mg_conc, si_conc, precs): conc_args = { "conc_ratio_min_1": [[64, 0, 0]], "conc_ratio_max_1": [[24, 40, 0]], "conc_ratio_min_2": [[64, 0, 0]], "conc_ratio_max_2": [[22, 21, 21]] } orig_spin_dict = { "Mg": 1.0, "Si": -1.0, "Al": 0.0 } kwargs = { "crystalstructure": "fcc", "a": 4.05, "size": [4, 4, 4], "basis_elements": [["Mg", "Si", "Al"]], "conc_args": conc_args, "db_name": "data/almgsi.db", "max_cluster_size": 4 } ceBulk = BulkCrystal(**kwargs) ceBulk.spin_dict = orig_spin_dict ceBulk.basis_functions = ceBulk._get_basis_functions() ceBulk._get_cluster_information() eci_file = "data/almgsi_fcc_eci.json" with open(eci_file, 'r') as infile: ecis = json.load(infile) print(ecis) #calc = CE( ceBulk, ecis, size=(3,3,3) ) calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10]) ceBulk = calc.BC ceBulk.atoms.set_calculator(calc) comp = { "Mg": mg_conc, "Si": si_conc, "Al": 1.0 - mg_conc - si_conc } calc.set_composition(comp) for temp, prec in zip(T, precs): print("Current temperature {}K".format(temp)) mc_obj = Montecarlo(ceBulk.atoms, temp, mpicomm=comm) mode = "prec" mc_obj.runMC(mode=mode, prec=prec) thermo = mc_obj.get_thermodynamic() thermo["temperature"] = temp thermo["prec"] = prec thermo["internal_energy"] = thermo.pop("energy") thermo["converged"] = True thermo["prec"] = prec if (rank == 0): db = dataset.connect("sqlite:///{}".format(mc_db_name)) tbl = db["results"] thermo["sysID"] = sysID tbl.insert(thermo)
def main(): conc_args = { "conc_ratio_min_1": [[1, 0]], "conc_ratio_max_1": [[0, 1]], } kwargs = { "crystalstructure": "fcc", "a": 4.05, "size": [4, 4, 4], "basis_elements": [["Al", "Mg"]], "conc_args": conc_args, "db_name": "data/temporary_bcnucleationdb.db", "max_cluster_size": 4 } ceBulk = BulkCrystal(**kwargs) print(ceBulk.basis_functions) eci_file = "data/ce_hydrostatic.json" with open(eci_file, 'r') as infile: ecis = json.load(infile) print(ecis) #calc = CE( ceBulk, ecis, size=(3,3,3) ) calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10], free_unused_arrays_BC=True) ceBulk = calc.BC ceBulk.atoms.set_calculator(calc) T = 500 temps = [200, 300, 400, 500, 600, 700, 800] mg_concs = [ 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.70, 0.75, 0.8, 0.85, 0.9 ] mg_concs = np.linspace(0.005, 0.995, 100) act_coeffs = [] eff_conc = [] for T in temps: for c_mg in mg_concs: comp = {"Mg": c_mg, "Al": 1.0 - c_mg} calc.set_composition(comp) act_sampler = ActivitySampler(ceBulk.atoms, T, moves=[("Al", "Mg")], mpicomm=comm) act_sampler.runMC(mode="fixed", steps=100000) thermo = act_sampler.get_thermodynamic() act_sampler.save( fname="data/effective_concentration_full_range.db")
def main(size, T): atoms = create_surface(size) atoms = wrap_and_sort_by_position(atoms) conc_args = { "conc_ratio_min_1": [[64, 0, 0]], "conc_ratio_max_1": [[24, 40, 0]], "conc_ratio_min_2": [[64, 0, 0]], "conc_ratio_max_2": [[22, 21, 21]] } kwargs = { "crystalstructure": "fcc", "a": 4.05, "size": [4, 4, 4], "basis_elements": [["Al", "Mg", "Si"]], "conc_args": conc_args, "db_name": "data/almgsi.db", "max_cluster_size": 4 } ceBulk = BulkCrystal(**kwargs) eci_file = "data/almgsi_fcc_eci_newconfig.json" with open(eci_file, 'r') as infile: ecis = json.load(infile) db_name = "large_cell_db{}x{}x{}.db".format(size[0], size[1], size[2]) calc = get_ce_calc(ceBulk, kwargs, ecis, size=size, db_name=db_name) ceBulk = calc.BC ceBulk.atoms.set_calculator(calc) mc = Montecarlo(ceBulk.atoms, T) symbs = [atom.symbol for atom in atoms] mc.set_symbols(symbs) # Write a copy of the current atoms object from ase.io import write shape_str = "-".join((str(item) for item in size)) uid_str = "{}K_{}".format(T, shape_str) write(WORKDIR + "initial_config{}.xyz".format(uid_str), mc.atoms) backup = MCBackup(mc, backup_file=WORKDIR + "backup{}.xyz".format(uid_str), db_name=WORKDIR + "mc_surface.db") camera = Snapshot(atoms=mc.atoms, trajfile=WORKDIR + "surface{}.traj".format(uid_str)) evol = EnergyEvolution(mc) nsteps = int(10E6) mc.attach(backup, interval=100000) mc.attach(camera, interval=int(nsteps / 20)) mc.attach(evol, interval=10 * len(mc.atoms)) mc.runMC(mode="fixed", steps=nsteps, equil=False) write(WORKDIR + "final_config{}.xyz".format(uid_str), mc.atoms)
def main(): conc_args = { "conc_ratio_min_1": [[1, 0]], "conc_ratio_max_1": [[0, 1]], } #with open(bc_filename,'rb') as infile: # ceBulk = pck.load(infile) kwargs = { "crystalstructure": "fcc", "a": 4.05, "size": [4, 4, 4], "basis_elements": [["Al", "Mg"]], "conc_args": conc_args, "db_name": "dos-db.db", "max_cluster_size": 4 } ceBulk = BulkCrystal(**kwargs) print(ceBulk.basis_functions) eci_file = "data/ce_hydrostatic.json" with open(eci_file, 'r') as infile: ecis = json.load(infile) print(ecis) #calc = CE( ceBulk, ecis, size=(3,3,3) ) calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10]) ceBulk = calc.BC ceBulk.atoms.set_calculator(calc) print("Number of atoms: {}".format(len(ceBulk.atoms))) T = 300 dos = SGCCompositionFreeEnergy(nbins=10000, hist_limits=[("c1_0", 0.45, 1.0)]) mc = sgc.SGCMonteCarlo(ceBulk.atoms, T, symbols=["Al", "Mg"]) mc.chemical_potential = {"c1_0": -1.066} if (run_array): T = [ 150, 200, 250, 300, 350, 375, 390, 400, 410, 420, 430, 440, 450, 460, 470 ] mus = np.linspace(-1.064, -1.069, 10) mu = [{"c1_0": value} for value in mus] array_runner = FreeEnergyMuTempArray( T, mu, fname="data/free_energy_al_rich.h5") array_runner.run(mc, dos, min_num_steps=100000) else: comp_free_eng = dos.find_dos(mc, min_num_steps=500000, max_rel_unc=0.01) comp_free_eng.plot() plt.show()
def main(): alat = 3.9 # Something in between Cu and Au kwargs_fcc = { "crystalstructure": "fcc", "a": alat, "size": [2, 2, 2], "basis_elements": [["Au", "Cu"]], "conc_args": { "conc_ratio_min_1": [[1, 0]], "conc_ratio_max_1": [[0, 1]] }, "max_cluster_size": 4, "db_name": "data/au_cu.db" } fcc = BulkCrystal(**kwargs_fcc) gen_struct(fcc)
def run(maxT, minT, n_temp, mg_conc): T = np.linspace(minT, maxT, n_temp)[::-1] conc_args = { "conc_ratio_min_1": [[1, 0]], "conc_ratio_max_1": [[0, 1]], } kwargs = { "crystalstructure": "fcc", "a": 4.05, "size": [4, 4, 4], "basis_elements": [["Al", "Mg"]], "conc_args": conc_args, "db_name": "data/temporary_bcdb.db", "max_cluster_size": 4 } ceBulk = BulkCrystal(**kwargs) print(ceBulk.basis_functions) eci_file = "data/ce_hydrostatic.json" with open(eci_file, 'r') as infile: ecis = json.load(infile) print(ecis) #calc = CE( ceBulk, ecis, size=(3,3,3) ) calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10]) ceBulk = calc.BC ceBulk.atoms.set_calculator(calc) comp = {"Al": 1.0 - mg_conc, "Mg": mg_conc} calc.set_composition(comp) print("Number of atoms: {}".format(len(ceBulk.atoms))) for temp in T: print("Current temperature {}K".format(temp)) mc_obj = Montecarlo(ceBulk.atoms, temp, mpicomm=comm) mode = "prec" prec = 1E-5 mc_obj.runMC(mode=mode, prec=prec) thermo = mc_obj.get_thermodynamic() thermo["temperature"] = temp thermo["prec"] = prec thermo["internal_energy"] = thermo.pop("energy") thermo["converged"] = True if (rank == 0): db = connect(mc_db_name) db.write(ceBulk.atoms, key_value_pairs=thermo)
def main(): conc_args = { "conc_ratio_min_1": [[1, 0]], "conc_ratio_max_1": [[0, 1]], } kwargs = { "crystalstructure": "fcc", "a": 4.05, "size": [4, 4, 4], "basis_elements": [["Al", "Mg"]], "conc_args": conc_args, "db_name": "data/temporary_bcnucleationdb.db", "max_cluster_size": 4 } ceBulk = BulkCrystal(**kwargs) print(ceBulk.basis_functions) eci_file = "data/ce_hydrostatic.json" with open(eci_file, 'r') as infile: ecis = json.load(infile) print(ecis) #calc = CE( ceBulk, ecis, size=(3,3,3) ) calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10], free_unused_arrays_BC=True) ceBulk = calc.BC ceBulk.atoms.set_calculator(calc) chem_pot = {"c1_0": -1.069} T = 300 #mc = SGCFreeEnergyBarrier( ceBulk.atoms, T, symbols=["Al","Mg"], \ #n_windows=20, n_bins=10, min_singlet=0.5, max_singlet=1.0, mpicomm=comm ) mc = SGCFreeEnergyBarrier.load(ceBulk.atoms, "data/free_energy_barrier_restart.json", mpicomm=comm) #mc.run( nsteps=100000, chem_pot=chem_pot ) #mc.save( fname="data/free_energy_barrier_restart.json" ) mc.plot(fname="data/free_energy_barrier_restart.json") plt.show()
def run_huge(): conc_args = { "conc_ratio_min_1":[[64,0,0]], "conc_ratio_max_1":[[24,40,0]], "conc_ratio_min_2":[[64,0,0]], "conc_ratio_max_2":[[22,21,21]] } kwargs = { "crystalstructure":"fcc", "size":[4,4,4], "basis_elements":[["Al","Mg","Si"]], "conc_args":conc_args, "db_name":"some_db.db", "max_cluster_size":4, "a":4.05, "ce_init_alg":"fast" } ceBulk = BulkCrystal( **kwargs ) with open(eci_file, 'r') as infile: eci = json.load(infile) calc = get_ce_calc(ceBulk, kwargs, eci=eci, size=[50,50,50]) calc.BC.atoms.set_calculator(calc) print(calc.BC.basis_functions) comp = { "Al":0.9, "Mg":0.05, "Si":0.05 } calc.set_composition(comp) T = 150 T = [2000, 1500, 1200, 1000, 800, 600, 400, 293] camera = Snapshot(trajfile=traj_file, atoms=calc.BC.atoms) for temp in T: print("Current temperature {}K".format(temp)) mc = Montecarlo(calc.BC.atoms, temp) mc.attach(camera, interval=125000*20) mc.runMC(mode="fixed", steps=125000*100, equil=False)
def run(chem_pot, min_c1, max_c1, T): alat = 3.8 conc_args = {} conc_args['conc_ratio_min_1'] = [[1, 0]] conc_args['conc_ratio_max_1'] = [[0, 1]] kwargs = { "crystalstructure": 'fcc', "a": 3.8, "size": [10, 10, 10], # "size": [2, 2, 2], "basis_elements": [['Cu', 'Au']], "conc_args": conc_args, "db_name": 'temp_sgc_{}.db'.format(rank), "max_cluster_size": 3, "max_cluster_dist": 1.5 * alat } bc = BulkCrystal(**kwargs) with open("data/eci_aucu.json", 'r') as infile: eci = json.load(infile) calc = get_ce_calc(bc, kwargs, eci=eci, size=[10, 10, 10]) bc = calc.BC bc.atoms.set_calculator(calc) if rank == 0: print("Number of atoms: {}".format(len(bc.atoms))) mc = SGCFreeEnergyBarrier(bc.atoms, T, n_windows=10, n_bins=8, min_singlet=min_c1, max_singlet=max_c1, mpicomm=comm, symbols=["Au", "Cu"], save_last_state=True) mu = {"c1_0": chem_pot} mc.run(nsteps=100000, chem_pot=mu) # mc.save(fname="data/barriers/free_eng_{}_{}_{}_{}.json".format(int(min_c1*100), int(max_c1*100), int(1E6*chem_pot), T)) mc.save(fname="data/barrier_sgc_waste4.json")
def main(): chem_pots = {"c1_0": -1.067} conc_args = { "conc_ratio_min_1": [[1, 0]], "conc_ratio_max_1": [[0, 1]], } #with open(bc_filename,'rb') as infile: # ceBulk = pck.load(infile) kwargs = { "crystalstructure": "fcc", "a": 4.05, "size": [4, 4, 4], "basis_elements": [["Al", "Mg"]], "conc_args": conc_args, "db_name": "random_test.db", "max_cluster_size": 4 } ceBulk = BulkCrystal(**kwargs) print(ceBulk.basis_functions) eci_file = "../data/ce_hydrostatic.json" with open(eci_file, 'r') as infile: ecis = json.load(infile) print(ecis) #calc = CE( ceBulk, ecis, size=(3,3,3) ) calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10]) ceBulk = calc.BC ceBulk.atoms.set_calculator(calc) print("Number of atoms: {}".format(len(ceBulk.atoms))) mc = SGCMonteCarlo(ceBulk.atoms, 100000, symbols=["Al", "Mg"]) mc.chemical_potential = chem_pots dn_sampler = DNSampler(mc_sampler=mc) dnest4_args = {"max_num_levels": 50, "lam": 10} dn_sampler.run(dnest4_args=dnest4_args) dn_sampler.make_histograms(bins=100) plt.show()
def main(): # Concentation arguments. NOTE: The way of specifying concentrations # will be changed in the future conc_args = { "conc_ratio_min_1": [[64, 0, 0]], "conc_ratio_max_1": [[24, 40, 0]], "conc_ratio_min_2": [[64, 0, 0]], "conc_ratio_max_2": [[22, 21, 21]] } ceBulk = BulkCrystal(crystalstructure="fcc", a=4.05, size=[4, 4, 4], basis_elements=[["Al", "Mg", "Si"]], conc_args=conc_args, db_name=db_name, max_cluster_size=4) # Create an instance of the structure generator struc_generator = GenerateStructures(ceBulk, struct_per_gen=10) # Generate new structures struc_generator.generate_probe_structure()
def main(outfname, action): conc_args = { "conc_ratio_min_1": [[1, 0]], "conc_ratio_max_1": [[0, 1]], } kwargs = { "crystalstructure": "fcc", "a": 4.05, "size": [4, 4, 4], "basis_elements": [["Al", "Mg"]], "conc_args": conc_args, "db_name": "data/temporary_bcnucleationdb.db", "max_cluster_size": 4 } ceBulk = BulkCrystal(**kwargs) print(ceBulk.basis_functions) eci_file = "data/ce_hydrostatic.json" with open(eci_file, 'r') as infile: ecis = json.load(infile) print(ecis) #calc = CE( ceBulk, ecis, size=(3,3,3) ) ecis = {"c1_0": 1.0} calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10], free_unused_arrays_BC=True, convert_trans_matrix=False) exit() ceBulk = calc.BC ceBulk.atoms.set_calculator(calc) chem_pot = {"c1_0": -1.0651526881167124} chem_pot = {"c1_0": -1.068} sampler = NucleationSampler( size_window_width=10, \ chemical_potential=chem_pot, max_cluster_size=150, \ merge_strategy="normalize_overlap", mpicomm=comm, max_one_cluster=True ) T = 300 mc = SGCNucleation( ceBulk.atoms, T, nucleation_sampler=sampler, \ network_name="c2_1414_1", network_element="Mg", symbols=["Al","Mg"], \ chem_pot=chem_pot, allow_solutes=True ) mg_conc = 0.04 concentration = {"Mg": mg_conc, "Al": 1.0 - mg_conc} mc_canonical = CanonicalNucleationMC(ceBulk.atoms, T, nucleation_sampler=sampler, network_name="c2_1414_1", network_element="Mg", concentration=concentration) if (action == "barrier"): mc.run(nsteps=100000) sampler.save(fname=outfname) elif (action == "barrier_canonical"): mc_canonical.run(nsteps=50000) sampler.save(fname=outfname) elif (action == "trans_path"): mc.find_transition_path( initial_cluster_size=90, max_size_reactant=20, min_size_product=135, \ folder="data", path_length=1000, max_attempts=10, nsteps=int(0.1*len(ceBulk.atoms)), mpicomm=comm ) #plt.show() elif (action == "relax_path"): relaxer = TransitionPathRelaxer(nuc_mc=mc) relaxer.relax_path(initial_path=outfname, n_shooting_moves=50) relaxer.path2trajectory(fname="data/relaxed_path.traj") elif (action == "generate_paths"): relaxer = TransitionPathRelaxer(nuc_mc=mc) relaxer.generate_paths(initial_path=outfname, n_paths=4, outfile="data/tse_ensemble.json", mpicomm=comm) elif (action == "view_tps_indicators"): relaxer = TransitionPathRelaxer(nuc_mc=mc) relaxer.plot_path_statistics(path_file=outfname) plt.show()
def run(T,mg_conc): conc_args = { "conc_ratio_min_1":[[1,0]], "conc_ratio_max_1":[[0,1]], } kwargs = { "crystalstructure":"fcc", "a":4.05, "size":[4,4,4], "basis_elements":[["Al","Mg"]], "conc_args":conc_args, "db_name":"data/temporary_bcdb.db", "max_cluster_size":4 } ceBulk = BulkCrystal( **kwargs ) print (ceBulk.basis_functions) eci_file = "data/ce_hydrostatic.json" with open( eci_file, 'r' ) as infile: ecis = json.load( infile ) print (ecis) #calc = CE( ceBulk, ecis, size=(3,3,3) ) calc = get_ce_calc( ceBulk, kwargs, ecis, size=[10,10,10], free_unused_arrays_BC=True ) ceBulk = calc.BC ceBulk.atoms.set_calculator( calc ) comp = { "Al":1.0-mg_conc, "Mg":mg_conc } calc.set_composition(comp) mc_obj = Montecarlo( ceBulk.atoms, T, mpicomm=comm ) pairs = PairCorrelationObserver( calc ) network = NetworkObserver( calc=calc, cluster_name="c2_1414_1", element="Mg", nbins=100 ) mode = "fixed" camera = Snapshot( "data/precipitation.traj", atoms=ceBulk.atoms ) mc_obj.attach( camera, interval=10000 ) mc_obj.attach( pairs, interval=1 ) mc_obj.attach( network, interval=500 ) mc_obj.runMC( mode=mode, steps=10000, equil=True ) pair_mean = pairs.get_average() pair_std = pairs.get_std() if ( rank == 0 ): data = { "pairs":pair_mean, "pairs_std":pair_std, "mg_conc":mg_conc, "temperature":T } pairfname = "data/precipitation_pairs/precipitation_pairs_{}_{}K.json".format(int(1000*mg_conc),int(T)) with open(pairfname,'w') as outfile: json.dump(data,outfile,indent=2, separators=(",",":")) print ( "Thermal averaged pair correlation functions written to {}".format(pairfname) ) atoms = network.get_atoms_with_largest_cluster() data = network.get_statistics() # This collects the histogram data from all processors size,occurence = network.get_size_histogram() data["histogram"] = {} data["histogram"]["size"] = size.tolist() data["histogram"]["occurence"] = occurence.tolist() data["temperature"] = T data["mg_conc"] = mg_conc cluster_fname = "data/cluster_statistics_{}_{}K.json".format(int(1000*mg_conc),int(T)) atoms_fname = "data/largest_cluster_{}_{}K.cif".format( int(1000*mg_conc), int(T) ) if ( rank == 0 ): print (occurence) if ( rank == 0 ): try: with open( cluster_fname,'r') as infile: data = json.load(infile) old_size = np.array(data["histogram"]["size"]) old_hist = np.array(data["histogram"]["occurence"]) if ( np.allclose(old_size,size) ): occurence += old_hist data["histogram"]["occurence"] = occurence.tolist() except Exception as exc: print (str(exc)) with open( cluster_fname, 'w' ) as outfile: json.dump( data, outfile, indent=2, separators=(",",":") ) print ("Cluster statistics written to {}".format(cluster_fname) ) write( atoms_fname, atoms ) print ("Atoms with largest cluster written to {}".format(atoms_fname)) #view(atoms) #plt.plot( network.size_histogram, ls="steps") #plt.show() print ("Proc: {} reached final barrier".format(rank)) comm.barrier()
def run_mc(phase1, phase2): alat = 3.8 conc_args = {} conc_args['conc_ratio_min_1'] = [[1, 0]] conc_args['conc_ratio_max_1'] = [[0, 1]] kwargs = { "crystalstructure": 'fcc', "a": 3.8, "size": [10, 10, 10], # "size": [2, 2, 2], "basis_elements": [['Cu', 'Au']], "conc_args": conc_args, "db_name": 'temp_sgc.db', "max_cluster_size": 3, "max_cluster_dist": 1.5 * alat } bc1 = BulkCrystal(**kwargs) bc2 = copy.deepcopy(bc1) bf = bc1._get_basis_functions()[0] with open("data/eci_aucu.json", 'r') as infile: eci = json.load(infile) db = dataset.connect("sqlite:///{}".format(canonical_db)) tbl = db["corrfunc"] if phase1 == "Au" or phase1 == "Cu": atoms1 = bc1.atoms for atom in atoms1: atom.symbol = phase1 cf1 = get_pure_cf(eci, bf[phase1]) else: atoms1 = read(phase1) row = tbl.find_one(runID=gs[phase1]) row.pop("id") row.pop("runID") cf1 = row bc1.atoms = atoms1 atoms2 = read(phase2) row = tbl.find_one(runID=gs[phase2]) row.pop("id") row.pop("runID") cf2 = row bc2.atoms = atoms2 calc1 = CE(bc1, eci=eci, initial_cf=cf1) atoms1.set_calculator(calc1) calc2 = CE(bc2, eci=eci, initial_cf=cf2) atoms2.set_calculator(calc2) gs1 = {"bc": bc1, "eci": eci, "cf": cf1} gs2 = {"bc": bc2, "eci": eci, "cf": cf2} both_gs = [gs1, gs2] mc_args = { "mode": "fixed", "steps": 100 * len(atoms1), "equil_params": { "mode": "fixed", "maxiter": 10 * len(atoms1) } } init_mu = None # init_mu = [0.271791267568668] Tend = None # Tend = 100 for i in range(5, 100): tracker = PhaseBoundaryTracker(both_gs, backupfile="{}/backup_{}.h5".format( folder, i)) res = tracker.separation_line_adaptive_euler(init_temp=100, stepsize=50, min_step=5.0, mc_args=mc_args, symbols=["Au", "Cu"], init_mu=init_mu, Tend=Tend) if rank == 0: save_phase_boundary( "{}/phase_boundary_almg_{}.h5".format(folder, i), res)
def thermodynamic_integration(phase): alat = 3.8 conc_args = {} conc_args['conc_ratio_min_1'] = [[1, 0]] conc_args['conc_ratio_max_1'] = [[0, 1]] kwargs = { "crystalstructure": 'fcc', "a": 3.8, "size": [10, 10, 10], "basis_elements": [['Cu', 'Au']], "conc_args": conc_args, "db_name": 'temp_sgc.db', "max_cluster_size": 3, "max_cluster_dist": 1.5 * alat } bc1 = BulkCrystal(**kwargs) bf = bc1._get_basis_functions()[0] with open("data/eci_aucu.json", 'r') as infile: eci = json.load(infile) db = dataset.connect("sqlite:///{}".format(canonical_db)) tbl = db["corrfunc"] if phase == "Au" or phase == "Cu": atoms1 = bc1.atoms for atom in atoms1: atom.symbol = phase cf1 = get_pure_cf(eci, bf[phase]) else: atoms = read(phase) row = tbl.find_one(runID=gs[phase]) row.pop("id") row.pop("runID") cf1 = row # TODO: Fix this when running with a pure phase symbs = [atom.symbol for atom in atoms] cf1 = get_pure_cf(eci, bf[bc1.atoms[0].symbol]) atoms = bc1.atoms calc = CE(bc1, eci=eci, initial_cf=cf1) calc.set_symbols(symbs) atoms.set_calculator(calc) sgc_db = dataset.connect("sqlite:///{}".format(sgc_db_name)) tbl = sgc_db["results"] tbl_cf = sgc_db["corr_func"] mu = 0.223 nsteps = 100 * len(atoms) equil_param = {"mode": "fixed", "maxiter": 10 * len(atoms)} order_param = SiteOrderParameter(atoms) T = np.linspace(100, 600, 40) # mu = np.linspace(0.223, 0.19, 20).tolist() mu = [0.223] for temp in T: for m in mu: chemical_potential = {"c1_0": m} # mc = SGCMonteCarlo(atoms, temp, mpicomm=comm, symbols=["Au", "Cu"]) mc = Montecarlo(atoms, temp) mc.attach(order_param) init_formula = atoms.get_chemical_formula() # mc.runMC(steps=nsteps, equil_params=equil_param, # chem_potential=chemical_potential) mc.runMC(steps=nsteps, equil_params=equil_param) # thermo = mc.get_thermodynamic(reset_ecis=True) thermo = mc.get_thermodynamic() thermo["init_formula"] = init_formula thermo["final_formula"] = atoms.get_chemical_formula() avg, std = order_param.get_average() thermo["order_avg"] = avg thermo["order_std"] = std thermo["valid"] = True thermo["integration_path"] = "NN" if rank == 0: uid = tbl.insert(thermo) cf = calc.get_cf() cf["runID"] = uid tbl_cf.insert(cf)
def run(mu, temps, save=False): chem_pots = {"c1_0": mu} linvib = LinearVibCorrection(vib_eci) conc_args = { "conc_ratio_min_1": [[1, 0]], "conc_ratio_max_1": [[0, 1]], } #with open(bc_filename,'rb') as infile: # ceBulk = pck.load(infile) kwargs = { "crystalstructure": "fcc", "a": 4.05, "size": [4, 4, 4], "basis_elements": [["Al", "Mg"]], "conc_args": conc_args, "db_name": "random_test.db", "max_cluster_size": 4 } ceBulk = BulkCrystal(**kwargs) print(ceBulk.basis_functions) eci_file = "data/ce_hydrostatic.json" with open(eci_file, 'r') as infile: ecis = json.load(infile) print(ecis) #calc = CE( ceBulk, ecis, size=(3,3,3) ) calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10]) ceBulk = calc.BC ceBulk.atoms.set_calculator(calc) print("Number of atoms: {}".format(len(ceBulk.atoms))) #view(ceBulk.atoms) #exit() n_burn = 40000 n_sample = 10000 thermo = [] #size = comm.Get_size() #n_per_proc = int( len(temps)/size ) #if ( rank == comm.Get_size()-1 ): # my_temps = temps[n_per_proc*rank:] #else: # my_temps = temps[n_per_proc*rank:n_per_proc*(rank+1)] for T in temps: if (rank == 0): print("{}: Current temperature {}".format(rank, T)) mc = sgc.SGCMonteCarlo(ceBulk.atoms, T, symbols=["Al", "Mg"], mpicomm=comm) #mc.linear_vib_correction = linvib mc.runMC(steps=2000000, chem_potential=chem_pots, equil=False) exit() mc.runMC(mode="prec", chem_potential=chem_pots, prec=1E-4) if (rank == 0): print(mc.atoms._calc.eci["c1_0"]) thermo_properties = mc.get_thermodynamic() thermo.append(thermo_properties) mc.reset() n_unreachable = gc.collect() print("GC number of unreachable: {}".format(n_unreachable)) #all_thermos = [] #all_thermos = comm.gather( thermo, root=0 ) if ((rank == 0) and save): #thermo = [] #for sublist in all_thermos: # thermo += sublist name = "mu%d" % (int(abs(mu) * 10000)) if (mu < 0.0): name += "m" data_written_to_file = False data = {} try: with open(OUTFILE, 'r') as infile: data = json.load(infile) if (name in data.keys()): for i, entry in enumerate(thermo): for key, value in entry.iteritems(): data[name][key].append(value) #data[name]["singlets"].append( entry["singlets"][0] ) #data[name]["energy"].append( entry["energy"] ) #data[name]["heat_capacity"].append( entry["heat_capacity"] ) #data[name]["temperature"].append( entry["temperature"] ) data_written_to_file = True except Exception as exc: print(str(exc)) print("Could not load file! Creating a new one!") if (not data_written_to_file): data[name] = {} for key in thermo[0].keys(): for entry in thermo: data[name][key] = [entry[key] for entry in thermo] #data[name]["singlets"] = [entry["singlets"][0] for entry in thermo] #data[name]["temperature"] = list(temps) #data[name]["energy"] = [entry["energy"] for entry in thermo] #data[name]["heat_capacity"] = [entry["heat_capacity"] for entry in thermo] #data[name]["mu"] = mu with open(OUTFILE, 'w') as outfile: json.dump(data, outfile, sort_keys=True, indent=2, separators=(",", ":")) print("Data written to {}".format(OUTFILE)) if (comm.Get_rank() == 0): print(ceBulk.atoms.get_chemical_formula()) #view( ceBulk.atoms ) ceBulk.atoms.set_calculator(None) if (rank == 0): with open(pck_file, 'wb') as outfile: pck.dump((ceBulk, calc.get_cf(), calc.eci), outfile) print("Bulk crystal object pickled to {}".format(pck_file))