def test_ignore_atoms(self): if not has_ase_with_ce: self.skipTest("ASE does not have CE") from cemc.mcmc import FixedElement no_trow = True msg = "" try: from copy import deepcopy conc = Concentration(basis_elements=[['V', 'Li'], ['O']]) kwargs = { "crystalstructure": "rocksalt", "concentration": conc, "a": 4.12, 'size': [2, 2, 2], 'cubic': True, "max_cluster_size": 4, "max_cluster_dia": 4.12, "db_name": 'database.db', 'basis_function': 'sluiter', 'ignore_background_atoms': True } fix_elem = FixedElement(element="O") kw_args_cpy = deepcopy(kwargs) ceBulk = CEBulk(**kw_args_cpy) ecis = get_example_ecis(ceBulk) atoms = get_atoms_with_ce_calc(ceBulk, kwargs, eci=ecis, size=[3, 3, 3], db_name="ignore_test_large.db") calc = atoms.get_calculator() # Insert some Li atoms num_li = 5 symbols = [atom.symbol for atom in atoms] num_inserted = 0 for i in range(0, len(symbols)): if symbols[i] == "V": symbols[i] = "Li" num_inserted += 1 if num_inserted >= num_li: break calc.set_symbols(symbols) mc = Montecarlo(atoms, 800) mc.add_constraint(fix_elem) mc.runMC(steps=100, equil=False, mode="fixed") # Clean up files os.remove("ignore_test_large.db") os.remove("database.db") except Exception as exc: no_trow = False msg = str(exc) self.assertTrue(no_trow, msg=msg)
def free_energy_vs_layered(T, mod): from cemc.mcmc import AdaptiveBiasReactionPathSampler from cemc.mcmc import ReactionCrdRangeConstraint from cemc.mcmc import DiffractionObserver from cemc.mcmc import MinimalEnergyPath from ase.geometry import get_layers atoms = get_atoms(cubic=True) atoms_cpy = atoms.copy() layers, dist = get_layers(atoms, (0, 1, 0)) for atom in atoms_cpy: if layers[atom.index] % 2 == 0: atom.symbol = "Mg" else: atom.symbol = "Si" symbols = [atom.symbol for atom in atoms_cpy] atoms.get_calculator().set_symbols(symbols) lamb = 4.05 k = 2.0 * np.pi / lamb workdir = "data/diffraction" # Have to perform only insert moves mc = Montecarlo(atoms, T) k_vec = [k, 0, 0] observer = DiffractionObserver(atoms=atoms, active_symbols=["Si"], all_symbols=["Mg", "Si"], k_vector=k_vec, name="reflection") if T < 250: mc.max_attempts = 5 nsteps = 100 * len(atoms) mep = MinimalEnergyPath(mc_obj=mc, observer=observer, value_name="reflection", relax_steps=nsteps, search_steps=nsteps, traj_file="{}/mep_diffract{}K.traj".format( workdir, T), max_reac_crd=1999.0) mep.run() mep.save(fname="{}/mep_mep_diffract_path{}.csv".format(workdir, T)) else: conc_cnst = ReactionCrdRangeConstraint(observer, value_name="reflection") conc_cnst.update_range([0, 0.5]) mc.add_constraint(conc_cnst) reac_path = AdaptiveBiasReactionPathSampler( mc_obj=mc, react_crd=[0.0, 0.5], observer=observer, n_bins=500, data_file="{}/layered_bias{}K.h5".format(workdir, T), mod_factor=mod, delete_db_if_exists=True, mpicomm=None, db_struct="{}/layered_bias_struct{}K.db".format(workdir, T), react_crd_name="reflection", ignore_equil_steps=False, smear=2000) reac_path.run() reac_path.save()