Diffusion benchmark by Peterson¶
In Petersons original publication on machine learning accelerated nudged elastic band the method is first tested on a simple benchmark of a gold atom moving on a Al-Pt slab.
The initial guess for the trajectory visualized above can be generated using the following snippet:
from ase import io
from ase.build import fcc100, add_adsorbate
from ase.constraints import FixAtoms
from ase.calculators.emt import EMT
from ase.optimize import QuasiNewton
from ase.neb import NEB
# 2x2-Al(001) surface with 3 layers and an
# Au atom adsorbed in a hollow site:
initial = fcc100('Al', size=(3, 2, 3))
# Replace two Al atoms by Pt:
initial[12].symbol = 'Pt'
initial[15].symbol = 'Pt'
add_adsorbate(initial, 'Au', 1.7, 'hollow')
initial.center(axis=2, vacuum=4.0)
# Fix all substrate atoms.
mask = [atom.tag > 0 for atom in initial]
constraint = FixAtoms(mask=[atom.tag > 0 for atom in initial])
initial.set_constraint(constraint)
# Use EMT potential:
initial.set_calculator(EMT())
# Initial state:
qn = QuasiNewton(initial)
qn.run(fmax=0.05)
# Final state:
final = initial.copy()
final.set_calculator(EMT())
final[-1].x += final.get_cell()[0, 0] / 3
qn = QuasiNewton(final)
qn.run(fmax=0.05)
images = [initial]
for i in range(5):
image = initial.copy()
image.set_calculator(EMT())
image.set_constraint(constraint)
images.append(image)
images.append(final)
neb = NEB(images)
neb.interpolate()
io.write('diffusion.traj', images)
io.write('diffusion.gif', images, rotation='-80x,-30y,-5z')
Standard nudged elastic band¶
A calculation with the ASE standard NEB method can be run in a few lines:
from ase.io import read
from ase.calculators.emt import EMT
from ase.neb import NEB
from ase.optimize import FIRE
images = read('diffusion.traj', index=':')
for image in images:
image.set_calculator(EMT())
neb = NEB(images)
opt = FIRE(neb)
opt.run()
and converges after 24 iterations:
Step Time Energy fmax
*Force-consistent energies used in optimization.
FIRE: 0 17:30:33 6.043962* 3.7816
FIRE: 1 17:30:33 5.912006* 3.2047
FIRE: 2 17:30:33 5.722624* 2.2477
...
FIRE: 22 17:30:37 5.490102* 0.0570
FIRE: 23 17:30:37 5.490091* 0.0514
FIRE: 24 17:30:37 5.490079* 0.0446
Machine learning accelerated nudged elastic band¶
Using Gaussian process regression with a squared exponential kernel
from ase.io import read
from ase.calculators.emt import EMT
from ase.neb import NEB
from mlpot.mlneb import run_mla_neb
from mlpot.calculators.gprcalculator import GPRCalculator
from mlpot.kernels import RBFKernel
images = read('diffusion.traj', index=':')
for image in images:
image.set_calculator(EMT())
neb = NEB(images)
kernel = RBFKernel(constant=100.0, length_scale=1.0)
ml_calc = GPRCalculator(kernel=kernel, C1=1e8, C2=1e8, opt_restarts=1)
run_mla_neb(neb, ml_calc)
convergence is reached after just 3 evaluations of the band:
r_max = 1.49
Maximum force per image after 1 evaluations of the band:
[0.29568641 2.40409944 3.78158447 2.86624199 0.90700111]
Fit called with 7 geometries.
Starting hyperparameter optimization 1/1 with parameters: [1.]
Finished hyperparameter optimization after 6 iterations with value: 312.7611772253583 and parameters: [0.67832091]
Fit finished. Final RMSE energy = 0.000132, RMSE force = 0.000014.
Starting machine learning neb run.
Step Time Energy fmax
*Force-consistent energies used in optimization.
FIRE: 0 17:32:14 6.043930* 3.7816
...
FIRE: 7 17:32:14 5.109532* 0.4979
Switching to climbing image NEB
Starting machine learning neb run.
Step Time Energy fmax
*Force-consistent energies used in optimization.
FIRE: 0 17:32:14 5.109532* 0.4979
...
FIRE: 31 17:32:16 5.096236* 0.0233
Maximum force per image after 2 evaluations of the band:
[0.64545486 1.40822419 1.53210775 1.30412201 0.69528136]
Fit called with 12 geometries.
Starting hyperparameter optimization 1/1 with parameters: [0.67832091]
Finished hyperparameter optimization after 9 iterations with value: 368.2374911559936 and parameters: [0.77545366]
Fit finished. Final RMSE energy = 0.000409, RMSE force = 0.000040.
Starting machine learning neb run.
Step Time Energy fmax
*Force-consistent energies used in optimization.
FIRE: 0 17:32:23 6.043569* 3.7816
...
FIRE: 4 17:32:23 5.441238* 0.4421
Switching to climbing image NEB
Starting machine learning neb run.
Step Time Energy fmax
*Force-consistent energies used in optimization.
FIRE: 0 17:32:23 5.441238* 0.4421
...
FIRE: 11 17:32:24 5.439436* 0.0241
Maximum force per image after 3 evaluations of the band:
[0.01156111 0.03813662 0.01763575 0.00411534 0.01259674]
Converged after 3 evaluations of the band.