示例#1
0
def get_data(name):
    assert name in ("Co", "Zn")
    traj = Trajectory(traj_name(name))
    nb = NEBTools(traj)
    s, E, *_ = nb.get_fit()
    E[-1] = E[0]  # force energy to be same
    ss = numpy.linspace(min(s), max(s))
    ee = interp1d(s, E, kind="cubic")(ss)
    print(max(ee))
    return s, E, ss, ee
示例#2
0
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)
示例#3
0
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
y_fit *= 23.06
示例#4
0
def plotneb(trajectory='ML_NEB_catlearn.traj', view_path=True):
    """
    Plot NEB path from a trajectory file containing the optimized images.
    This is meant to be used with ML-NEB.
    The error bars show the uncertainty for each image along the path.
    """

    images = read(trajectory, ':')

    # Get fit from NEBTools.
    nebtools = NEBTools(images)
    nebfit = nebtools.get_fit()

    x_pred = nebfit[0]
    e_pred = nebfit[1]

    x_fit = nebfit[2]
    e_fit = nebfit[3]

    e_barrier = np.max(e_pred)
    print('Energy barrier:', e_barrier, 'eV')

    u_pred = []
    for i in images:
        u_pred.append(i.info['uncertainty'])

    fig, ax = plt.subplots(figsize=(8, 5))

    prop_plots = dict(arrowstyle="<|-|>, head_width=0.5, head_length=1.",
                      connectionstyle="arc3",
                      color='teal',
                      ls='-',
                      lw=0.0)
    ax.annotate("",
                xy=(x_pred[np.argmax(e_pred)], np.max(e_pred)),
                xycoords='data',
                xytext=(x_pred[np.argmax(e_pred)], 0.0),
                textcoords='data',
                arrowprops=prop_plots)

    prop_plots = dict(arrowstyle="|-|",
                      connectionstyle="arc3",
                      ls='-',
                      lw=2.,
                      color='teal')
    ax.annotate("",
                xy=(x_pred[np.argmax(e_pred)], np.max(e_pred)),
                xycoords='data',
                xytext=(x_pred[np.argmax(e_pred)], 0.0),
                textcoords='data',
                arrowprops=prop_plots)

    ax.annotate(s=str(np.round(e_barrier, 3)) + ' eV',
                xy=(x_pred[np.argmax(e_pred)], np.max(e_pred) / 1.65),
                xycoords='data',
                fontsize=15.0,
                textcoords='data',
                ha='right',
                rotation=90,
                color='teal')

    ax.plot(x_fit, e_fit, color='black', linestyle='--', linewidth=1.5)

    ax.errorbar(x_pred,
                e_pred,
                yerr=u_pred,
                alpha=0.8,
                markersize=0.0,
                ecolor='midnightblue',
                ls='',
                elinewidth=3.0,
                capsize=1.0)

    ax.plot(x_pred,
            e_pred,
            color='firebrick',
            alpha=0.7,
            marker='o',
            markersize=13.0,
            markeredgecolor='black',
            ls='')

    ax.set_xlabel('Path distance ($\AA$)')
    ax.set_ylabel('Energy (eV)')
    plt.tight_layout(h_pad=1)

    print('Saving pdf file with the NEB profile in file: ' + 'MLNEB.pdf')
    plt.savefig('./' 'MLNEB.pdf', format='pdf')
    plt.show()

    if view_path is True:
        print('Visualizing NEB images in ASE...')
        view(images)