def find_swaps(): all_atoms = [] e_ref = [] db = connect(db_name) for row in db.select(converged=True): all_atoms.append(row.toatoms()) final_struct_id = row.final_struct_id final = db.get(id=final_struct_id) e_ref.append(final.energy) extractor = MCTrajectoryExtractor() swaps = extractor.find_swaps(all_atoms) with open(eci_file, 'r') as infile: eci = json.load(infile) e_pred = [] setting = settingFromJSON("almgsixSettings.json") e_pred = {} for swap in swaps: print(swap) for s in swap: if s in e_pred.keys(): continue atoms = attach_calculator(setting, atoms=all_atoms[s], eci=eci) atoms.numbers = all_atoms[s].numbers e_pred[s] = atoms.get_potential_energy() for k, v in e_pred.items(): print(k, v, e_ref[k]) dev = extractor.swap_energy_deviations(swaps, e_pred, e_ref) extractor.plot_swap_deviation(dev) plt.show()
def get_gs(): atoms = bulk('Al', cubic=True) * (5, 1, 1) setting = settingFromJSON(FNAME) with open(ECI_FILE, 'r') as infile: eci = json.load(infile) atoms = attach_calculator(setting=setting, atoms=atoms, eci=eci) setting.set_active_template(atoms=atoms) cluster = setting.cluster_list.get_by_name("c2_d0000_0")[0] cnst = PairConstraint(['X', 'X'], cluster, setting.trans_matrix, atoms) symbols = ['Al', 'Mg', 'Si', 'X'] numX = 0 removed = False for atom in atoms: new_symb = choice(symbols) atom.symbol = new_symb if new_symb == 'X': numX += 1 if numX == 1 and not removed: symbols.remove('X') removed = True T = [1000, 800, 600, 400, 200, 100, 50] for temp in T: mc = Montecarlo(atoms, temp) mc.add_constraint(cnst) mc.run(steps=10 * len(atoms)) return atoms
def main(rowNum): conc = get_conc(rowNum) print(conc) if conc is None: return settings = settings_from_json(settings_file) atoms = bulk('Al', a=4.05, crystalstructure='fcc', cubic=True) * (N, N, N) atoms = attach_calculator(settings, atoms, get_eci()) cu = ['Cu'] * int(conc['Cu'] * len(atoms)) si = ['Si'] * int(conc['Si'] * len(atoms)) mg = ['Mg'] * int(conc['Mg'] * len(atoms)) al = ['Al'] * (len(atoms) - len(cu) - len(mg) - len(si)) symbols = al + mg + si + cu shuffle(symbols) atoms.symbols = symbols # Trigger a calculation atoms.get_potential_energy() temperatures = list(range(1000, 1, -50)) obs = LowestEnergyStructure(atoms) for T in temperatures: print(f"Temperature {T}") mc = Montecarlo(atoms, T) mc.attach(obs) mc.run(steps=20 * len(atoms)) db = connect(db_name) calc = SinglePointCalculator(obs.emin_atoms, energy=obs.lowest_energy) obs.emin_atoms.set_calculator(calc) db.write(obs.emin_atoms)
def mgsi(initial=None, comment=None): if initial is None: pureAl = bulk('Al', cubic=True) * (N, N, N) pureAl = wrap_and_sort_by_position(pureAl) tags, _ = get_layers(pureAl, (0, 0, 1)) success = False while not success: print("Generating new initial precipitate") initial, success = create_precipitate(pureAl.copy(), tags, normal_radius) db = dataset.connect(DB_NAME) ref_tbl = db[REF] vac_tbl = db[VAC] sol_tbl = db[SOL] comment_tbl = db[COMMENT] runID = hex(random.randint(0, 2**32 - 1)) if comment is not None: comment_tbl.insert({'runID': runID, 'comment': comment}) eci = {} with open("data/almgsix_normal_ce.json", 'r') as infile: data = json.load(infile) eci = data['eci'] settings = settingsFromJSON("data/settings_almgsiX_voldev.json") settings.basis_func_type = "binary_linear" atoms = attach_calculator(settings, initial.copy(), eci) atoms.numbers = initial.numbers ref_energy = atoms.get_potential_energy() ref_tbl.insert({'runID': runID, 'energy': ref_energy}) for atom in atoms: if atom.symbol in ['Mg', 'Si']: pos = atom.position sol_tbl.insert({ 'runID': runID, 'symbol': atom.symbol, 'X': pos[0], 'Y': pos[1], 'Z': pos[2] }) ref, neighbors = neighbor_list('ij', atoms, 3.0) for ref, nb in zip(ref, neighbors): if atoms[ref].symbol == 'Al' and atoms[nb].symbol in ['Mg', 'Si']: atoms[ref].symbol = 'X' e = atoms.get_potential_energy() atoms[ref].symbol = 'Al' pos = atoms[ref].position vac_tbl.insert({ 'runID': runID, 'X': pos[0], 'Y': pos[1], 'Z': pos[2], 'energy': e }) atoms = removeAl(atoms)
def main(argv): fname = argv[0] chem_pot = argv[1:] initial = read(fname) db = dataset.connect("sqlite:///data/almgsi_mc_sgc.db") tbl = db['local_environ_mgsi'] runID = hex(random.randint(0, 2**32-1)) eci = {} with open("data/almgsix_normal_ce.json", 'r') as infile: data = json.load(infile) eci = data['eci'] cf_names = [k for k in eci.keys() if k[1] == '2'] settings = settingsFromJSON("data/settings_almgsiX_voldev.json") settings.basis_func_type = "binary_linear" atoms = attach_calculator(settings, initial.copy(), eci) atoms.numbers = initial.numbers for i, atom in enumerate(initial): atoms[i].tag = atom.tag mc = SGCMonteCarlo(atoms, 1000, symbols=['Al', 'X']) temps = [1000, 800, 700, 600, 500, 400, 300, 200, 100] active_sites = [i for i, atom in enumerate(atoms) if atom.tag != -1] constraint = ActiveElementConstraint(atoms, active_sites) observer = TaggedSiteSymbol('X', atoms) mc.add_constraint(constraint) mc.attach(observer) snap_fname = f"/work/sophus/local_environ_mc/traj/run{runID}" snap = Snapshot(fname=snap_fname, atoms=atoms) mc.attach(snap, interval=10*len(atoms)) chem_pot_dict = { 'Mg': 0.0, 'Si': 0.0, 'X': float(chem_pot[0]) } chem_pot_dict = species_chempot2eci(settings.basis_functions, chem_pot_dict) for T in temps: mc.T = T mc.run(steps=100*len(atoms), chem_pot=chem_pot_dict) thermo = mc.get_thermodynamic_quantities() thermo['runID'] = runID thermo['initial'] = fname avgOcupp = {f'occupLayer{k}': v for k, v in observer.averages().items()} thermo.update(avgOcupp) tbl.insert(thermo)
def fixed_comp(conc_array): db = dataset.connect("sqlite:///data/almgsi_mc_sgc.db") tbl = db['sa_fixed_conc'] runID = hex(random.randint(0, 2**32 - 1)) conc = { 'Mg': float(conc_array[0]), 'Si': float(conc_array[1]), 'X': float(conc_array[2]) } eci = {} with open("data/almgsix_normal_ce.json", 'r') as infile: data = json.load(infile) eci = data['eci'] settings = settingsFromJSON("data/settings_almgsiX_voldev.json") settings.basis_func_type = "binary_linear" #print(settings.basis_functions) #exit() atoms = bulk('Al', a=4.05, cubic=True) * (4, 4, 4) atoms = attach_calculator(settings, atoms, eci) start = 0 for k, v in conc.items(): num = int(v * len(atoms)) for i in range(start, start + num): atoms[i].symbol = k start += num mc = Montecarlo(atoms, 1000) temps = [1000, 800, 600, 500, 400, 300, 200, 100] for T in temps: mc.T = T mc.run(steps=10 * len(atoms)) thermo = mc.get_thermodynamic_quantities() thermo['runID'] = runID tbl.insert(thermo) fname = "data/gs/" + atoms.get_chemical_formula() + str(runID) + ".xyz" write(fname, atoms)
def main(argv): db = dataset.connect("sqlite:///data/almgsi_mc_sgc.db") tbl = db['random_direction_sa'] runID = hex(random.randint(0, 2**32 - 1)) eci = {} with open("data/almgsix_normal_ce.json", 'r') as infile: data = json.load(infile) eci = data['eci'] cf_names = [k for k in eci.keys() if k[1] == '2'] settings = settingsFromJSON("data/settings_almgsiX_voldev.json") settings.basis_func_type = "binary_linear" #print(settings.basis_functions) #exit() atoms = bulk('Al', a=4.05, cubic=True) * (4, 4, 4) atoms = attach_calculator(settings, atoms, eci) obs = CorrelationFunctionObserver(atoms.get_calculator(), names=cf_names) temps = [1000, 800, 600, 500, 400, 300, 200] chem_pot = { 'Mg': float(argv[0]), 'Si': float(argv[1]), 'X': float(argv[2]), } chem_pot = species_chempot2eci(settings.basis_functions, chem_pot) mc = SGCMonteCarlo(atoms, 1000, symbols=['Al', 'Mg', 'Si', 'X']) mc.attach(obs, interval=100) for T in temps: mc.T = T mc.run(steps=100 * len(atoms), chem_pot=chem_pot) thermo = mc.get_thermodynamic_quantities() cfs = obs.get_averages() cfs = {k: v for k, v in cfs.items() if 'c2' in k} mc.reset() thermo.update(cfs) thermo['runID'] = runID tbl.insert(thermo)
def main(): kmc_run = True eci = {} with open("data/almgsix_normal_ce.json", 'r') as infile: data = json.load(infile) eci = data['eci'] settings = settingsFromJSON("data/settings_almgsiX_voldev.json") settings.basis_func_type = "binary_linear" initial = settings.atoms * (10, 10, 10) atoms = attach_calculator(settings, initial.copy(), eci) # Insert Mg and Si for s in ['Mg', 'Si']: for _ in range(40): idx = random.randint(0, len(atoms) - 1) atoms[idx].symbol = s vac_idx = 80 atoms[vac_idx].symbol = 'X' T = 100 barrier = SSTEBarrier({'Al': 0.6, 'Mg': 0.6, 'Si': 0.6}) snapshot = SnapshotNoAl("data/kmc_test100.traj", atoms) neighbor = NeighbourSwap(atoms, 3.0) for l in neighbor.nl: assert len(l) == 12 if kmc_run: kmc = KineticMonteCarlo(atoms, T, barrier, [neighbor]) kmc.epr = EntropyProductionRate(buffer_length=1000) kmc.attach(snapshot, 100) kmc.run(10000, vac_idx) else: mc = Montecarlo(atoms, T) mc.attach(snapshot, 100) mc.run(steps=100000) snapshot.close()
def test_mgsi100(): eci = {} with open("data/almgsix_normal_ce.json", 'r') as infile: data = json.load(infile) eci = data['eci'] settings = settings_from_json("data/settings_almgsiX_voldev.json") settings.basis_func_type = "binary_linear" atoms = bulk('Al', a=4.05, cubic=True) * (4, 4, 4) atoms = attach_calculator(settings, atoms, eci) for i in range(int(len(atoms) / 2)): atoms[i].symbol = 'Mg' atoms[i + int(len(atoms) / 2)].symbol = 'Si' mc = Montecarlo(atoms, 1000) temps = [1000, 800, 600, 500, 400, 300, 200, 100] for T in temps: mc.T = T mc.run(steps=100 * len(atoms)) fname = "data/" + atoms.get_chemical_formula() + "_mc_test.xyz" write(fname, atoms)
def explore(): eci_file = 'data/almgsiX_eci.json' with open(eci_file, 'r') as infile: eci = json.load(infile) settings = settingFromJSON('almgsixSettings.json') atoms = settings.atoms*(5, 5, 5) atoms = attach_calculator(setting=settings, atoms=atoms, eci=eci) num_structs = 10*len(atoms) energies = [] symbs = ['Al', 'Mg', 'Si', 'X'] now = time.time() for i in range(num_structs): if time.time() - now > 30: print("{} of {}".format(i, num_structs)) now = time.time() idx = np.random.randint(0, high=len(atoms)) symb = choice(symbs) atoms[idx].symbol = symb energies.append(atoms.get_potential_energy()/len(atoms)) np.savetxt("data/energies.txt", energies)
with open(file_name) as json_file: eci=json.load(json_file) except FileNotFoundError: #print("ECI file not found, returning to home directory and running again.") os.chdir(home_path) with open(file_name) as json_file: eci=json.load(json_file) else: print("ECI loaded correctly, proceeding to load structure") ##Now we read in our atoms and replace them to reach the appropriate concentration. ReadIn=read('au1000.vasp') ReadIn=attach_calculator(settings, atoms=ReadIn, eci=eci) atoms_default=ReadIn atoms_to_replace=10*conc_name for j in range(0, atoms_to_replace): atoms_default[j].symbol='Cu' from clease.montecarlo import BinnedBiasPotential from clease.montecarlo import Montecarlo from clease.montecarlo import MetaDynamicsSampler ##We setup the monte carlo simulation for this temperature using the appropriate concentration of atoms mc=Montecarlo(atoms_default,Temp) obs=EnergyEvolution(mc) mc.attach(obs,interval=1000) energies=obs.energies steps=1000000