コード例 #1
0
def test_ethene_rotation(tmpdir):

    tmpdir.chdir()

    # Optimise molecule
    initial = molecule('C2H6')
    smart_cell(initial, vac=4.0, h=0.01)
    initial.set_calculator(iEspresso(pw=300, dw=4000, kpts='gamma'))
    qn = QuasiNewton(initial, 'initial.traj')
    qn.run(fmax=0.01)

    # Create final state
    final = initial.copy()
    final.positions[2:5] = initial.positions[[3, 4, 2]]
    final.set_calculator(iEspresso(pw=300, dw=4000, kpts='gamma'))
    final.get_potential_energy()

    # Generate blank images
    images = [initial]
    nimage = 7

    for i in range(nimage):
        image = initial.copy()
        image.set_calculator(iEspresso(pw=300, dw=4000, kpts='gamma'))
        images.append(image)
    images.append(final)

    # Run IDPP interpolation
    neb = NEBEspresso(images)
    neb.interpolate('idpp')

    # Run NEB calculation
    qn = QuasiNewton(neb, logfile='ethane_linear.log', trajectory='neb.traj')
    qn.run(fmax=0.05)

    nt = NEBTools(neb.images)
    print('fmax: ', nt.get_fmax())
    print('Ef, dE: ', nt.get_barrier())
コード例 #2
0
ファイル: neb.py プロジェクト: essil1/ase-laser
for i in range(nimages):
    images.append(images[0].copy())
images[-1].positions[6, 1] = 2 - images[0].positions[6, 1]
neb = NEB(images)
neb.interpolate()
if 0:  # verify that initial images make sense
    from ase.visualize import view
    view(neb.images)

for image in images:
    image.set_calculator(MorsePotential())

dyn = BFGS(neb, trajectory='mep.traj')  # , logfile='mep.log')

dyn.run(fmax=fmax)

for a in neb.images:
    print(a.positions[-1], a.get_potential_energy())

neb.climb = True
dyn.run(fmax=fmax)

# Check NEB tools.
nt_images = read('mep.traj@-4:')
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
コード例 #3
0
ファイル: neb.py プロジェクト: rchiechi/QuantumParse
for i in range(nimages):
    images.append(images[0].copy())
images[-1].positions[6, 1] = 2 - images[0].positions[6, 1]
neb = NEB(images)
neb.interpolate()
if 0:  # verify that initial images make sense
    from ase.visualize import view
    view(neb.images)

for image in images:
    image.set_calculator(MorsePotential())

dyn = BFGS(neb, trajectory='mep.traj')  # , logfile='mep.log')

dyn.run(fmax=fmax)

for a in neb.images:
    print(a.positions[-1], a.get_potential_energy())

neb.climb = True
dyn.run(fmax=fmax)

# Check NEB tools.
nt_images = read('mep.traj@-4:')
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
コード例 #4
0
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')
コード例 #5
0
        PySCF_simple(atoms=image, method='MP2', basis='6-31g*'))

neb = NEB(images, climb=True, k=0.6)
nebTools = NEBTools(images)

neb.interpolate('idpp')

print(" -> start neb run")
opt = FIRE(neb)
opt.run(fmax=0.05)

print(nebTools.get_barrier())

# get IRC data
Ef, dE = nebTools.get_barrier()
max_force = nebTools.get_fmax()
x, y, x_fit, y_fit, forces = nebTools.get_fit()

# save IRC data
np.save("x_claisen_mp2.npy", x)
np.save("y_claisen_mp2.npy", y)
np.save("x_claisen_fit_mp2.npy", x_fit)
np.save("y_claisen_fit_mp2.npy", y_fit)

# write NEB guess of interpolation
for i, image in enumerate(images):
    out_name = "claisen_{:03d}.xyz".format(i)
    io.write(out_name, image)

# plot IRC
y2 *= 23.06
コード例 #6
0
# 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())
コード例 #7
0
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()