def run(self, calc, filename): """ Runs NEB calculations. Parameters ---------- calc: object. Calculator to be used to run method. filename: str. Label to save generated trajectory files.""" initial = self.starting_images[0].copy() final = self.starting_images[-1].copy() if self.ml2relax: # Relax initial and final images ml_initial = initial ml_initial.set_calculator(calc) ml_final = final ml_final.set_calculator(calc) print("BUILDING INITIAL") qn = BFGS(ml_initial, trajectory="initial.traj", logfile="initial_relax_log.txt") qn.run(fmax=0.01, steps=100) print("BUILDING FINAL") qn = BFGS(ml_final, trajectory="final.traj", logfile="final_relax_log.txt") qn.run(fmax=0.01, steps=100) initial = ml_initial.copy() final = ml_final.copy() initial.set_calculator(calc) final.set_calculator(calc) images = [initial] for i in range(self.intermediate_samples): image = initial.copy() image.set_calculator(calc) images.append(image) images.append(final) print("NEB BEING BUILT") neb = SingleCalculatorNEB(images) neb.interpolate() print("NEB BEING OPTIMISED") opti = BFGS(neb, trajectory=filename + ".traj", logfile="al_neb_log.txt") opti.run(fmax=0.01, steps=100) print("NEB DONE") """ The following code is used to visualise the NEB at every iteration """ built_neb = NEBTools(images) barrier, dE = built_neb.get_barrier() # max_force = built_neb.get_fmax() # fig = built_neb.plot_band() plt.show()
def run(self, calc, filename): """ Runs NEB calculations. Parameters ---------- calc: object. Calculator to be used to run method. filename: str. Label to save generated trajectory files.""" initial = self.starting_images[0].copy() final = self.starting_images[-1].copy() # Relax initial and final images ml_initial = initial ml_initial.set_calculator(calc) ml_final = final ml_final.set_calculator(calc) print("BUILDING INITIAL") qn = BFGS(ml_initial, trajectory="initial.traj", logfile="initial_relax_log.txt") qn.run(fmax=0.01, steps=100) print("BUILDING FINAL") qn = BFGS(ml_final, trajectory="final.traj", logfile="final_relax_log.txt") qn.run(fmax=0.01, steps=100) initial = ml_initial.copy() final = ml_final.copy() initial.set_calculator(calc) final.set_calculator(calc) images = [initial] for i in range(self.intermediate_samples): image = initial.copy() image.set_calculator(calc) images.append(image) images.append(final) print("NEB BEING BUILT") neb = SingleCalculatorNEB(images) neb.interpolate() print("NEB BEING OPTIMISED") opti = BFGS(neb, trajectory=filename + ".traj", logfile="al_neb_log.txt") opti.run(fmax=0.01, steps=100) print("NEB DONE")
def neural_neb_ase(reactantxyzfile, productxyzfile, nff_dir, rxn_name, steps=500, n_images=24, fmax=0.004, isclimb=False): #reactant and products as ase Atoms initial = AtomsBatch(xyz_to_ase_atoms(reactantxyzfile), cutoff=5.5, nbr_torch=True, directed=True) final = AtomsBatch(xyz_to_ase_atoms(productxyzfile), cutoff=5.5, nbr_torch=True, directed=True) # Make a band consisting of n_images: images = [initial] images += [initial.copy() for i in range(n_images)] images += [final] neb = SingleCalculatorNEB(images, k=0.02, climb=isclimb) neb.method = 'improvedtangent' # Interpolate linearly the potisions of the n_images: neb.interpolate() neb.idpp_interpolate(optimizer=BFGS, steps=steps) images = read('idpp.traj@-{}:'.format(str(n_images + 2))) # # Set calculators: nff_ase = NeuralFF.from_file(nff_dir, device='cuda:0') neb.set_calculators(nff_ase) # # Optimize: optimizer = BFGS(neb, trajectory='{}/{}.traj'.format(nff_dir, rxn_name)) optimizer.run(fmax=fmax, steps=steps) # Read NEB images from File images = read('{}/{}.traj@-{}:'.format(nff_dir, rxn_name, str(n_images + 2))) return images
def set_calculators(all=False): c = GPAW(h=.3, convergence={ 'eigenstates': 0.1, 'energy': 0.1, 'density': 0.01 }, txt=txt) # c = EMT() n = len(images) if not all: n -= 2 neb.set_calculators([c] * n) images = [mol] for i in range(4): images.append(images[0].copy()) images[-1].positions[2, 1] = 2 - images[0].positions[2, 1] neb = SingleCalculatorNEB(images) neb.interpolate() for image in images: print(image[2].position) set_calculators(True) dyn = FIRE(neb, trajectory='mep.traj') dyn.insert_observer(set_calculators) print(dyn.run(fmax=8.))
mol = Cluster([Atom('H'), Atom('H',[1,0,0]), Atom('H',[.5,.5,.5])], cell = [2,2,2], pbc=True) def set_calculators(all=False): c=GPAW(h=.3, convergence={'eigenstates':0.1, 'energy' : 0.1, 'density' : 0.01}, txt=txt) # c = EMT() n = len(images) if not all: n -= 2 neb.set_calculators([c] * n) images = [mol] for i in range(4): images.append(images[0].copy()) images[-1].positions[2, 1] = 2 - images[0].positions[2, 1] neb = SingleCalculatorNEB(images) neb.interpolate() for image in images: print(image[2].position) set_calculators(True) dyn = FIRE(neb, trajectory='mep.traj') dyn.insert_observer(set_calculators) print(dyn.run(fmax=8.))