print('\nSummary of the results: \n') atoms_ase = read('neb_ase.traj', ':') n_eval_ase = int(len(atoms_ase) - 2 * (len(atoms_ase) / n_images)) print('Number of function evaluations CI-NEB implemented in ASE:', n_eval_ase) # ML-NEB: atoms_catlearn = read('evaluated_structures.traj', ':') n_eval_catlearn = len(atoms_catlearn) - 2 print('Number of function evaluations CatLearn:', n_eval_catlearn) # Comparison: print( '\nThe ML-NEB algorithm required ', (n_eval_ase / n_eval_catlearn), 'times less number of function evaluations than ' 'the standard NEB algorithm.') # Plot ASE NEB: nebtools_ase = NEBTools(images_ase) Sf_ase = nebtools_ase.get_fit()[2] Ef_ase = nebtools_ase.get_fit()[3] Ef_neb_ase, dE_neb_ase = nebtools_ase.get_barrier(fit=False) nebtools_ase.plot_band() plt.show() # Plot ML-NEB predicted path and show images along the path: plotneb(trajectory='ML-NEB.traj', view_path=False)
import matplotlib.pyplot as plt from ase.neb import NEBTools from ase.io import read images = read('neb.traj@-5:') nebtools = NEBTools(images) # Get the calculated barrier and the energy change of the reaction. Ef, dE = nebtools.get_barrier() # Get the barrier without any interpolation between highest images. Ef, dE = nebtools.get_barrier(fit=False) # Get the actual maximum force at this point in the simulation. max_force = nebtools.get_fmax() # Create a figure like that coming from ASE-GUI. fig = nebtools.plot_band() fig.savefig('diffusion-barrier.png') # Create a figure with custom parameters. fig = plt.figure(figsize=(5.5, 4.0)) ax = fig.add_axes((0.15, 0.15, 0.8, 0.75)) nebtools.plot_band(ax) fig.savefig('diffusion-barrier.png')
images = [initial] for i in range(3): image = initial.copy() image.set_calculator(EMT()) image.set_constraint(constraint) images.append(image) images.append(final) neb = NEB(images) neb.interpolate() qn = BFGS(neb, trajectory='neb.traj') qn.run(fmax=0.05) images = read('neb.traj@-5:') nebtools = NEBTools(images) # Get the calculated barrier and the energy change of the reaction. Ef, dE = nebtools.get_barrier() # Get the barrier without any interpolation between highest images. Ef, dE = nebtools.get_barrier(fit=False) # Get the actual maximum force at this point in the simulation. max_force = nebtools.get_fmax() # Create a figure like that coming from ase-gui. fig = nebtools.plot_band() fig.savefig('diffusion-barrier.png')
images = [initial] for index in range(nimages - 2): images += [initial.copy()] images[-1].set_calculator(calc()) images += [final] neb = NEB(images) neb.interpolate() dyn = BFGS(neb, trajectory='mep.traj') dyn.run(fmax=fmax) # Check climbing image. neb.climb = True dyn.run(fmax=fmax) # Check NEB tools. nt_images = ase.io.read('mep.traj', index='-{:d}:'.format(nimages)) nebtools = NEBTools(nt_images) nt_fmax = nebtools.get_fmax(climb=True) Ef, dE = nebtools.get_barrier() print(Ef, dE, fmax, nt_fmax) assert nt_fmax < fmax assert abs(Ef - 1.389) < 0.001 # Plot one band. nebtools.plot_band() # Plot many (ok, 2) bands. nt_images = ase.io.read('mep.traj', index='-{:d}:'.format(2 * nimages)) nebtools = NEBTools(nt_images) nebtools.plot_bands()
def test_neb(plt): from ase import Atoms from ase.constraints import FixAtoms import ase.io from ase.neb import NEB, NEBTools from ase.calculators.morse import MorsePotential from ase.optimize import BFGS, QuasiNewton def calc(): # Common calculator for all images. return MorsePotential() # Create and relax initial and final states. initial = Atoms('H7', positions=[(0, 0, 0), (1, 0, 0), (0, 1, 0), (1, 1, 0), (0, 2, 0), (1, 2, 0), (0.5, 0.5, 1)], constraint=[FixAtoms(range(6))], calculator=calc()) dyn = QuasiNewton(initial) dyn.run(fmax=0.01) final = initial.copy() final.calc = calc() final.positions[6, 1] = 2 - initial.positions[6, 1] dyn = QuasiNewton(final) dyn.run(fmax=0.01) # Run NEB without climbing image. fmax = 0.05 nimages = 4 images = [initial] for index in range(nimages - 2): images += [initial.copy()] images[-1].calc = calc() images += [final] neb = NEB(images) neb.interpolate() with BFGS(neb, trajectory='mep.traj') as dyn: dyn.run(fmax=fmax) # Check climbing image. neb.climb = True dyn.run(fmax=fmax) # Check NEB tools. nt_images = ase.io.read('mep.traj', index='-{:d}:'.format(nimages)) nebtools = NEBTools(nt_images) nt_fmax = nebtools.get_fmax(climb=True) Ef, dE = nebtools.get_barrier() print(Ef, dE, fmax, nt_fmax) assert nt_fmax < fmax assert abs(Ef - 1.389) < 0.001 # Plot one band. nebtools.plot_band() # Plot many (ok, 2) bands. nt_images = ase.io.read('mep.traj', index='-{:d}:'.format(2 * nimages)) nebtools = NEBTools(nt_images) nebtools.plot_bands()