def pure_phase_entropy(small_bc): from cemc.mcmc import Montecarlo from ase.clease.tools import wrap_and_sort_by_position from ase.io import read from cemc.mcmc import SiteOrderParameter, Snapshot import dataset T = [1, 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 420, 440, 460, 480, 500] calc = get_ce_calc(small_bc, kwargs, ecis, size=[10, 10, 10], db_name="data/db10x10x10Al3Mg.db") bc = calc.BC bc.atoms.set_calculator(calc) atoms = read("data/al3mg_template.xyz") atoms = wrap_and_sort_by_position(atoms) symbs = [atom.symbol for atom in atoms] calc.set_symbols(symbs) site_order = SiteOrderParameter(bc.atoms) db = dataset.connect("sqlite:///data/pure_al3mg3.db") syst = db["thermodynamic"] camera = Snapshot(trajfile="data/pure_phase_entropy.traj", atoms=bc.atoms) for temp in T: print("Current temperature: {}K".format(temp)) site_order.reset() mc = Montecarlo(bc.atoms, temp) mc.attach(site_order) mc.attach(camera, interval=50000) equil_param = {"window_length": 100000, "mode": "fixed"} mc.runMC(mode="fixed", steps=500000, equil=True, equil_params=equil_param) mean, stddev = site_order.get_average() thermo = mc.get_thermodynamic() thermo["site_order"] = mean thermo["site_order_std"] = stddev syst.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 insert_atoms( self, bc_kwargs, size=[1,1,1], composition=None, cetype="CEBulk", \ T=None, n_steps_per_temp=10000, eci=None ): """ Insert a new atoms object into the database """ if (composition is None): raise TypeError("No composition given") allowed_ce_types = ["CEBulk", "CECrystal"] if (not cetype in allowed_ce_types): raise ValueError( "cetype has to be one of {}".format(allowed_ce_types)) self.cetype = cetype if (eci is None): raise ValueError( "No ECIs given! Cannot determine required energy range!") if (cetype == "CEBulk"): small_bc = CEBulk(**bc_kwargs) small_bc.reconfigure_settings() elif (ctype == "CECrystal"): small_bc = CECrystal(**bc_kwargs) small_bc.reconfigure_settings() self._check_eci(small_bc, eci) calc = get_ce_calc(small_bc, bc_kwargs, eci=eci, size=size) calc.set_composition(composition) bc = calc.BC bc.atoms.set_calculator(calc) formula = bc.atoms.get_chemical_formula() if (self.template_atoms_exists(formula)): raise AtomExistsError( "An atom object with the specified composition already exists in the database" ) Emin, Emax = self._find_energy_range(bc.atoms, T, n_steps_per_temp) cf = calc.get_cf() data = {"cf": cf} # Store this entry into the database db = connect(self.wl_db_name) scalc = SinglePointCalculator(bc.atoms, energy=Emin) bc.atoms.set_calculator(scalc) outfname = "BC_wanglandau_{}.pkl".format( bc.atoms.get_chemical_formula()) with open(outfname, 'wb') as outfile: pck.dump(bc, outfile) kvp = { "Emin": Emin, "Emax": Emax, "bcfile": outfname, "cetype": self.cetype } data["bc_kwargs"] = bc_kwargs data["supercell_size"] = size db.write(calc.BC.atoms, key_value_pairs=kvp, data=data)
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 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 test_no_throw(self): if (not has_CE): self.skipTest("ASE version does not have ASE") return no_throw = True msg = "" try: conc_args = { "conc_ratio_min_1": [[1, 0]], "conc_ratio_max_1": [[0, 1]], } kwargs = { "crystalstructure": "fcc", "a": 4.05, "size": [3, 3, 3], "basis_elements": [["Al", "Mg"]], "conc_args": conc_args, "db_name": "temporary_bcnucleationdb.db", "max_cluster_size": 3 } ceBulk = CEBulk(**kwargs) cf = CorrFunction(ceBulk) cf_dict = cf.get_cf(ceBulk.atoms) ecis = {key: 1.0 for key, value in cf_dict.items()} #calc = CE( ceBulk, ecis, size=(3,3,3) ) calc = get_ce_calc(ceBulk, kwargs, ecis, size=[6, 6, 6], db_name="sc6x6x6.db") 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=5, n_bins=10, min_singlet=0.5, max_singlet=1.0 ) mc.run(nsteps=100, chem_pot=chem_pot) mc.save(fname="free_energy_barrier.json") # Try to load the object stored mc = SGCFreeEnergyBarrier.load(ceBulk.atoms, "free_energy_barrier.json") mc.run(nsteps=100, chem_pot=chem_pot) mc.save(fname="free_energy_barrier.json") os.remove("sc6x6x6.db") except Exception as exc: msg = str(exc) no_throw = False self.assertTrue(no_throw, msg=msg)
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 test_supercell( self ): if ( not has_ase_with_ce ): self.skipTest("ASE version does not have CE") return calc, ceBulk, eci = self.get_calc("fcc") db_name = "test_db_fcc_super.db" conc_args = { "conc_ratio_min_1":[[1,0]], "conc_ratio_max_1":[[0,1]], } kwargs = { "crystalstructure": "fcc", "a": 4.05, "size":[3, 3, 3], "basis_elements":[["Al","Mg"]], "conc_args": conc_args, "db_name": db_name, "max_cluster_size": 3, "max_cluster_dia": 4.05 } kwargs_template = copy.deepcopy(kwargs) kwargs_template["size"] = [4, 4, 4] kwargs_template["db_name"] = "template_bc.db" template_supercell_bc = CEBulk(**kwargs_template) template_supercell_bc.reconfigure_settings() ceBulk = CEBulk(**kwargs) ceBulk.reconfigure_settings() calc = get_ce_calc(ceBulk, kwargs, eci, size=[4, 4, 4], db_name="sc4x4x.db") ceBulk = calc.BC ceBulk.atoms.set_calculator(calc) corr_func = CorrFunction(template_supercell_bc) for i in range(10): calc.calculate(ceBulk.atoms, ["energy"], [(i, "Al", "Mg")]) updated_cf = calc.get_cf() brute_force = corr_func.get_cf_by_cluster_names( ceBulk.atoms, list(updated_cf.keys())) for key, value in brute_force.items(): self.assertAlmostEqual(value, updated_cf[key]) os.remove("sc4x4x.db")
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 get_atoms(self, atomID, eci): """ Returns an instance of the atoms object requested """ db = connect(self.wl_db_name) row = db.get(id=atomID) bcfname = row.key_value_pairs["bcfile"] init_cf = row.data["cf"] try: with open(bcfname, 'rb') as infile: bc = pck.load(infile) calc = CE(bc, eci, initial_cf=init_cf) bc.atoms.set_calculator(calc) return bc.atoms except IOError as exc: print(str(exc)) print("Will try to recover the CEBulk object") bc_kwargs = row.data["bc_kwargs"] cetype = row.key_value_pairs["cetype"] if (cetype == "CEBulk"): small_bc = CEBulk(**bc_kwargs) small_bc.reconfigure_settings() else: small_bc = CECrystal(**bc_kwargs) small_bc.reconfigure_settings() size = row.data["supercell_size"] calc = get_ce_calc(small_bc, bc_kwargs, eci=eci, size=size) # Determine the composition count = row.count_atoms() for key in count.keys(): count /= float(row.natoms) calc.set_composition(count) bc = calc.BC bc.atoms.set_calculator(calc) return bc.atoms except: raise RuntimeError( "Did not manage to return the atoms object with the proper calculator attached..." )
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 get_ce_with_calc(): conc = Concentration(basis_elements=[["Al", "Mg", "Si"]]) kwargs = { "crystalstructure": "fcc", "a": 4.05, "size": [4, 4, 4], "concentration": conc, "db_name": DB_NAME, "max_cluster_size": 4 } ceBulk = BulkCrystal(**kwargs) with open(ECI_FILE, 'r') as infile: ecis = json.load(infile) db_name = "large_cell_db10x10x10.db" calc = get_ce_calc(ceBulk, kwargs, ecis, size=[10, 10, 10], db_name=db_name) ceBulk = calc.BC ceBulk.atoms.set_calculator(calc) return ceBulk
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 surface_energy(): 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 = CEBulk(**kwargs) eci_file = "data/almgsi_fcc_eci_newconfig.json" with open(eci_file, 'r') as infile: ecis = json.load(infile) size = (8, 8, 8) 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) print(calc.get_energy() / len(calc.atoms)) ceBulk = calc.BC ceBulk.atoms.set_calculator(calc) # Get the energy of MgSi mgsi = wrap_and_sort_by_position(get_mgsi() * (4, 4, 4)) symbs = [atom.symbol for atom in mgsi] calc.set_symbols(symbs) view(calc.atoms) mgsi_energy = calc.get_energy() / len(calc.atoms) print("Energy MgSi: {} eV/atom".format(mgsi_energy)) # Get the energy of pure al symbs = ["Al" for _ in range(len(mgsi))] calc.set_symbols(symbs) view(calc.atoms) al_energy = calc.get_energy() / len(calc.atoms) print("Energy Al: {} eV/atom".format(al_energy)) # Get the energy of a 50% mixture mgsi = wrap_and_sort_by_position(get_mgsi() * (4, 4, 2)) # mgsi = get_mgsi_surface100_si_si() from scipy.spatial import cKDTree as KDTree cell = calc.atoms.get_cell() tree = KDTree(calc.atoms.get_positions()) symbs = [atom.symbol for atom in calc.atoms] for atom in mgsi: pos = np.zeros((1, 3)) pos[0, :] = atom.position wrapped = wrap_positions(pos, cell) if not np.allclose(wrapped, atom.position): continue _, indx = tree.query(atom.position) symbs[indx] = atom.symbol calc.set_symbols(symbs) view(calc.atoms) # Surface energy mix_energy = calc.get_energy() print("Mix energy: {} eV ({} eV/atom)".format(mix_energy, mix_energy / len(calc.atoms))) num_al = 0 num_mgsi = 0 for atom in calc.atoms: if atom.symbol == "Al": num_al += 1 elif atom.symbol == "Mg" or atom.symbol == "Si": num_mgsi += 1 assert num_al + num_mgsi == len(calc.atoms) dE = mix_energy - num_al * al_energy - num_mgsi * mgsi_energy cell = calc.atoms.get_cell() a1 = cell[0, :] a2 = cell[1, :] normal = np.cross(a1, a2) area = np.sqrt(normal.dot(normal)) # Convert units surface_tension = dE / area mJ = J / 1000.0 # milli joules surface_tension *= (m * m / mJ) unit_normal = normal / area print("Surface tension: {} mJ/m^2".format(surface_tension)) print("Direction: {}".format(unit_normal))
def test_no_throw(self): if not available: self.skipTest("ASE version does not have CE!") return no_throw = True msg = "" try: conc_args = { "conc_ratio_min_1": [[1, 0]], "conc_ratio_max_1": [[0, 1]], } db_name = "temp_nuc_db.db" if os.path.exists(db_name): os.remove(db_name) kwargs = { "crystalstructure": "fcc", "a": 4.05, "size": [3, 3, 3], "basis_elements": [["Al", "Mg"]], "conc_args": conc_args, "db_name": db_name, "max_cluster_size": 3 } ceBulk = CEBulk(**kwargs) ceBulk.reconfigure_settings() cf = CorrFunction(ceBulk) cf = cf.get_cf(ceBulk.atoms) ecis = {key: 0.001 for key in cf.keys()} calc = get_ce_calc(ceBulk, kwargs, ecis, size=[5, 5, 5], db_name="sc5x5x5.db") ceBulk = calc.BC ceBulk.atoms.set_calculator(calc) chem_pot = {"c1_0": -1.0651526881167124} sampler = NucleationSampler(size_window_width=10, chemical_potential=chem_pot, max_cluster_size=20, merge_strategy="normalize_overlap") nn_name = get_network_name(ceBulk.cluster_family_names_by_size) mc = SGCNucleation(ceBulk.atoms, 300, nucleation_sampler=sampler, network_name=[nn_name], network_element=["Mg"], symbols=["Al", "Mg"], chem_pot=chem_pot) mc.runMC(steps=2) sampler.save(fname="test_nucl.h5") mc = CanonicalNucleationMC(ceBulk.atoms, 300, nucleation_sampler=sampler, network_name=[nn_name], network_element=["Mg"], concentration={ "Al": 0.8, "Mg": 0.2 }) mc.runMC(steps=2) sampler.save(fname="test_nucl_canonical.h5") elements = {"Mg": 6} calc.set_composition({"Al": 1.0, "Mg": 0.0}) mc = FixedNucleusMC(ceBulk.atoms, 300, network_name=[nn_name], network_element=["Mg"]) mc.insert_symbol_random_places("Mg", num=1, swap_symbs=["Al"]) mc.runMC(steps=2, elements=elements) os.remove("sc5x5x5.db") except Exception as exc: msg = str(exc) no_throw = False self.assertTrue(no_throw, msg=msg)
def main(option="relax", size=8): from copy import deepcopy ceBulk = BulkCrystal( **kwargs ) bc_copy = deepcopy(ceBulk) print (ecis) al,mg = get_pure_energies(ecis) print ("Al energy: {} eV/atom".format(al)) print ("Mg energy: {} eV/atom".format(mg)) #exit() #calc = CE( ceBulk, ecis, size=(3,3,3) ) calc = get_ce_calc(ceBulk, kwargs, ecis, size=[15,15,15]) ceBulk = calc.BC ceBulk.atoms.set_calculator( calc ) #pure_energy = calc.get_energy() #print (pure_energy) #energy = calc.calculate( ceBulk.atoms, ["energy"],[(0,"Al","Mg")]) #print (energy) #energy = calc.calculate( ceBulk.atoms, ["energy"], [()]) #exit() if option == "heat": print("Running with cluser size {}".format(size)) mc = FixedNucleusMC( ceBulk.atoms, 293, network_name=["c2_4p050_3"], network_element=["Mg"] ) cluster_entropy(mc, size=size) return elif option == "pure_phase": pure_phase_entropy(bc_copy) return else: sizes = range(3,51) #sizes = np.arange(3, 51) energies = [] cell = ceBulk.atoms.get_cell() diag = 0.5*(cell[0, :] + cell[1, :] + cell[2, :]) pos = ceBulk.atoms.get_positions() pos -= diag lengths = np.sum(pos**2, axis=1) indx = np.argmin(lengths) symbs = [atom.symbol for atom in ceBulk.atoms] symbs[indx] = "Mg" print("Orig energy: {}".format(calc.get_energy())) calc.set_symbols(symbs) print("One atom: {}".format(calc.get_energy())) exit() for size in sizes: elements = {"Mg": size} T = np.linspace(50,1000,40)[::-1] # Reset the symbols to only Mg calc.set_symbols(symbs) mc = FixedNucleusMC( ceBulk.atoms, T, network_name=["c2_4p050_3"], network_element=["Mg"] ) mc.grow_cluster(elements) mc.current_energy = calc.get_energy() low_en = LowestEnergyStructure( calc, mc, verbose=True ) mc.attach( low_en ) for temp in T: print ("Temperature {}K".format(temp)) mc.T = temp mc.runMC(steps=10000, init_cluster=False) mc.reset() mc.is_first = False # atoms,clust = mc.get_atoms( atoms=low_en.atoms ) write( "{}cluster{}_all.cif".format(folder,size), low_en.atoms ) # write( "{}cluster{}_cluster.cif".format(folder,size), clust ) energies.append(low_en.lowest_energy) print (sizes,energies) data = np.vstack((sizes,energies)).T np.savetxt( "{}energies_run2.txt".format(folder), data, delimiter=",")
"db_name": db_name, "conc_args": conc_args, "max_cluster_size": 3 } # In this example, we just use some example ecis eci = get_example_ecis(bc_kwargs=kwargs) # Initialize a template CEBulk Object ceBulk = CEBulk( **kwargs ) ceBulk.reconfigure_settings() # Nessecary for the unittests to pass # Now we want to get a Cluster Expansion calculator for a big cell mc_cell_size = [10,10,10] from cemc import get_ce_calc calc = get_ce_calc( ceBulk, kwargs, eci=eci, size=mc_cell_size, db_name="mc_obs.db") ceBulk = calc.BC ceBulk.atoms.set_calculator(calc) conc = { "Al":0.8, "Mg":0.2 } calc.set_composition(conc) # Now we import the Monte Carlo class from cemc.mcmc.montecarlo import Montecarlo T = 400 # Run the simulation at 400K mc_obj = Montecarlo( ceBulk.atoms, T ) # Now we define the observers
"conc_args": conc_args, "max_cluster_size": 3 } # Use some example ecis eci = get_example_ecis(bc_kwargs=kwargs) # Initialize a template CEBulk Object ceBulk = CEBulk( **kwargs ) ceBulk.reconfigure_settings() # Nessecary for the unittest to pass # Now we want to get a Cluster Expansion calculator for a big cell mc_cell_size = [10, 10, 10] from cemc import get_ce_calc calc = get_ce_calc(ceBulk, kwargs, eci=eci, size=mc_cell_size, db_name="sgc_large.db") # Now er are finished with the template CEBulk ceBulk = calc.BC ceBulk.atoms.set_calculator( calc ) # In the SGC ensemble the simulation is run at fixed chemical potential # The chemical potentials are subtracted from the singlet terms # Those are ECIs starting with c1. # In a binary system there is only one singlet term, so there is only one # chemical potential to specify chem_pot = { "c1_0":-1.04 } # Speciy the temperature