def run(args, parser): # Nothing will ever be stored in args.output; need to manually find # if its supplied by checking extensions. if args.filenames[-1].endswith('.pdf'): args.output = args.filenames.pop(-1) else: args.output = 'nebplots.pdf' images = Images() images.read(args.filenames) nebtools = NEBTools(images=images) nebtools.plot_bands(constant_x=args.constant_x, constant_y=args.constant_y, nimages=args.n_images, label=args.output[:-4])
final.positions[2:5] = initial.positions[[3, 4, 2]] # Generate blank images. images = [initial] for i in range(9): images.append(initial.copy()) for image in images: image.calc = EMT() images.append(final) neb = NEB(images, climb=True) neb.interpolate(method='idpp') #idpp插值,设置初猜 # set calculator for atoms in images: atoms.calc = EMT() atoms.get_potential_energy() # Optimize: py_fname = os.path.splitext(sys.argv[0])[0] traj_fname = "{}.traj".format(py_fname) log_fname = "{}.log".format(py_fname) optimizer = FIRE(neb, trajectory=traj_fname, logfile=log_fname) optimizer.run(fmax=0.04) neb_result = list(iread(traj_fname)) for i in neb_result: #print(i.get_potential_energy()) pass neb_result = NEBTools(neb_result) neb_result.plot_bands(True, True, label=py_fname) print(neb_result.get_barrier(), neb_result.get_fmax())
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()