def test_gs_finder(self): if (not has_CE): self.skipTest("ASE version does not have CE") return no_throw = True msg = "" try: db_name = "test_db_gsfinder.db" conc_args = { "conc_ratio_min_1": [[1, 0]], "conc_ratio_max_1": [[0, 1]], } a = 4.05 ceBulk = CEBulk( crystalstructure="fcc", a=a, size=[3,3,3], basis_elements=[["Al","Mg"]], conc_args=conc_args, \ db_name=db_name, max_cluster_size=4) cf = CorrFunction(ceBulk) cf = cf.get_cf(ceBulk.atoms) eci = {key: 1.0 for key in cf.keys()} gsfinder = GSFinder() comp = {"Al": 0.5, "Mg": 0.5} gsfinder.get_gs(ceBulk, eci, composition=comp) except Exception as exc: msg = str(exc) no_throw = False self.assertTrue(no_throw, msg=msg)
def find_gs(formula="MgSi"): ceBulk = get_ce_with_calc() symbs = ["Mg" for _ in range(len(ceBulk.atoms))] if formula == "MgSi": for i in range(int(len(symbs) / 2), len(symbs)): symbs[i] = "Si" elif formula == "Mg3Si": for i in range(int(3 * len(symbs) / 4), len(symbs)): symbs[i] = "Si" ceBulk.atoms.get_calculator().set_symbols(symbs) gs = GSFinder() temps = np.linspace(1.0, 1500, 30)[::-1] result = gs.get_gs(ceBulk, temps=temps, n_steps_per_temp=10000) fname = "data/ground_state{}.xyz".format(formula) from ase.io import write write(fname, result["atoms"]) print("Atoms written to {}".format(fname))
def gs_struct(bc): from cemc.tools import GSFinder from ase.visualize import view with open("data/eci_aucu.json", 'r') as infile: eci = json.load(infile) struct_gen = GenerateStructures(bc, struct_per_gen=20) conc = np.arange(0.25, 0.75) conc = [0.25, 0.75] for au_conc in conc: comp = {"Au": au_conc, "Cu": 1.0 - au_conc} T = [800, 700, 600, 500, 400, 300, 200, 100, 50, 20, 10] nsteps_per_temp = 100 * len(bc.atoms) finder = GSFinder() gs = finder.get_gs(bc, eci, composition=comp, n_steps_per_temp=nsteps_per_temp, temps=T) try: # view(gs["atoms"]) # struct_gen.insert_structure(init_struct=gs["atoms"]) fname = "Emin_structure_{}_{}.xyz".format(int(au_conc*100), time.time()) write(fname, gs["atoms"]) except Exception as exc: print(exc)
def insert_gs_struct(bs,struct_gen,n_structs=20): n_X = 16 N = float(len(bs.atoms)) assert len(bs.atoms) == 40 gs_searcher = GSFinder() # fixed_vac = FixedElement(element="X") # gs_searcher.add_constraint(fixed_vac) counter = 0 with open(eci_fname,'r') as infile: ecis = json.load(infile) for _ in range(n_structs): natoms = len(bs.atoms)-n_X max_Si = 0.5 n_si = 0 for atom in bs.atoms: if atom.symbol == "X": continue val = rand() if val < 0.05: atom.symbol = "Al" elif val < 0.7: atom.symbol = "Mg" else: atom.symbol = "Si" n_si += 1 if ( n_si/N > 0.5 ): continue T = np.linspace(50,2000,20)[::-1] result = gs_searcher.get_gs(bs, ecis, temps=T) fname = "data/gs_serach.xyz" write(fname, result["atoms"]) print ("Lowest energy: {} eV".format(result["energy"]/natoms)) try: struct_gen.insert_structure( init_struct=fname ) counter += 1 except Exception as exc: print (str(exc)) print ("Insert {} ground state strutures".format(counter))
def main(): folder = "/home/gudrun/davidkl/Documents/GPAWTutorial/AlMgSiMC/data" fname = folder + "/MgSi_mgsi_free_eng.xyz" atoms_read = wrap_and_sort_by_position(read(fname)) db_energy = -218.272/64 symbols = [atom.symbol for atom in atoms_read] T = np.linspace(100.0, 1300.0, 20)[::-1].tolist() #T = [300] atoms = get_atoms() symbols = ["Mg"]*1024 + ["Si"]*1024 atoms.get_calculator().set_symbols(symbols) print("Init energy: {}".format(atoms.get_calculator().get_energy())) print(db_energy, atoms.get_calculator().get_energy()/len(atoms)) #assert abs(db_energy - atoms.get_calculator().get_energy()/len(atoms)) < 1E-3 gs = GSFinder() bc = atoms.get_calculator().BC res = gs.get_gs(bc, temps=T, n_steps_per_temp=1000000, atoms=atoms) print(res["energy"]) write("data/mgsi_gs_bcs.xyz", res["atoms"])
def find_gs( BC, mg_conc, vac_conc ): composition = { "Mg":mg_conc, "X":vac_conc, "Al":1.0-mg_conc-vac_conc } print ("Reading ECIs from {}".format(eci_fname)) with open( eci_fname, 'r') as infile: ecis = json.load( infile ) T = [1000,800,600,400,200,100,50,20,10,5,1] n_steps_per = 5000 gsfinder = GSFinder() result = gsfinder.get_gs( BC, ecis, composition=composition, temps=T, n_steps_per_temp=n_steps_per ) atoms = result["atoms"] formula = atoms.get_chemical_formula() outfname = "data/gs_fcc_vac_{}_{}mev.xyz".format( formula, int(result["energy"]*1000) ) write( outfname, atoms ) print ("GS energy: {} eV".format(result["energy"]) ) print ("Structure written to {}".format(outfname) ) print (result["cf"]) return outfname
# Loop over temperatures for T in temps: mc_obj = Montecarlo(atoms, T) # Give the Lowest Energy Structure a reference to the monte carlo object obs.mc_obj = mc_obj # Attach the observer to the monte carlo object mc_obj.attach(obs) # The Ground State Atoms object can now be obtained gs_atoms = obs.lowest_energy_atoms # A simpler approach that essentially follow exactly the same procedure # as above is to use the GSFinder class from cemc.tools import GSFinder gs_search = GSFinder() gs = gs_search.get_gs(bc, eci, temps=temps, n_steps_per_temp=100, composition=composition) """ gs is now a dictionary with the following form { "atoms": the structure having the lowest energy "energy": Energy of that structure "cf": The correlation functions of the structure with the lowest energy } """
# Now we import the Monte Carlo class from cemc.mcmc.montecarlo import Montecarlo # Loop over temperatures for T in temps: mc_obj = Montecarlo(bc.atoms, T) # Give the Lowest Energy Structure a reference to the monte carlo object obs.mc_obj = mc_obj # Attach the observer to the monte carlo object mc_obj.attach(obs) # The Ground State Atoms object can now be obtained gs_atoms = obs.lowest_energy_atoms # A simpler approach that essentially follow exactly the same procedure # as above is to use the GSFinder class from cemc.tools import GSFinder gs_search = GSFinder() gs = gs_search.get_gs(bc, eci, temps=temps, n_steps_per_temp=100) """ gs is now a dictionary with the following form { "atoms": the structure having the lowest energy "energy": Energy of that structure "cf": The correlation functions of the structure with the lowest energy } """