Algorithmcore
Nudged elastic band method
Also called NEB method, climbing image nudged elastic band, NEB.
Finds a minimum energy path between two minima: a chain of images moves under the true force across the path and spring forces along it. A climbing image converges to the saddle.
- Time
- O(I N (G + d)) worst
- Space
- O(N d) extra
- Where
- G = the cost of one gradient; I = the number of iterations; N = the number of segments of the band; d = the number of coordinates
- Model
- Real RAM
- Properties
- deterministicnot exactiterativenot randomized
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Greg Mills, Hannes Jonsson, Karsten W. Jacobsen, Graeme Henkelman, Blas P. Uberuaga, 1994
The nudged elastic band (NEB) method finds a minimum energy path between two minima of a potential energy, and the saddle point on it. It places a chain of copies of the system, called images, between the two minima, joins them by springs, and moves each image under a force with two parts: the true force across the path and the spring force along it. When the forces are zero, the images lie on a minimum energy path, evenly spaced. With a climbing image, the highest image moves up along the path to the saddle. The barrier height and the curvatures at the saddle then give the rate by harmonic transition state theory.
In plain words
Two valleys of an energy landscape are joined by many paths. The most likely path for a slow transition goes over the lowest pass, and on it each step goes straight downhill, away from the pass. This is the minimum energy path.
The band is a string of beads from one valley to the other. Each bead feels the pull of the landscape, but only across the string, so it does not slide back into a valley. Springs pull the beads only along the string, so they stay evenly spaced and do not cut corners. The string falls into the bottom of the channel that joins the valleys. One bead, the highest, gets a different rule: it climbs up along the string and stays down across it. It stops exactly at the pass.
The problem
The input is a potential with its gradient , two minima and , and the number of segments. For atoms, is the potential energy of the energy landscape and the coordinates are mass weighted if the masses differ. The output is a band that approximates a minimum energy path (MEP): a curve on which the gradient is parallel to the tangent at every point. The highest point of an MEP is a first-order saddle: a stationary point whose Hessian has exactly one negative eigenvalue.
The algorithm
NUDGED-ELASTIC-BAND(V, R_0, R_N, N, k, h, tol)- 1
R_i ← R_0 + (i/N)(R_N - R_0) for i = 0, ..., N - 2
repeat - 3
E_i ← V(R_i), g_i ← ∇V(R_i) for i = 1, ..., N-1 - 4
τ_i ← the unit tangent at R_i from E_{i-1}, E_i, E_{i+1} - 5
F_i^s ← k (|R_{i+1} - R_i| - |R_i - R_{i-1}|) τ_i ▷ spring force, along the path - 6
F_i ← -g_i + (g_i · τ_i) τ_i + F_i^s ▷ true force, across the path - 7
if climbing then c ← the i with the largest E_i, F_c ← -g_c + 2 (g_c · τ_c) τ_c - 8
if max_i |F_i| < tol then return R_0, ..., R_N - 9
R_i ← R_i + h F_i for i = 1, ..., N-1 ▷ the ends stay fixed
Line L1 starts from the straight line between the two minima. Line L4 uses the tangent of Henkelman and Jonsson: if the energy rises from through to , points along ; if it falls, along . At a maximum or a minimum of the energy along the band, is a mean of the two vectors with the weights and , the larger weight on the vector to the neighbour with the higher energy. Line L5 is the spring force of the same paper: it depends on the difference of the two distances, not on the vectors. Line L6 removes the part of the true force along . These two projections are the "nudging". Line L7 is the climbing image: no spring, and the component of the true force along the band is inverted, so the image goes uphill along the band and downhill across it. Line L9 is a step of steepest descent along the NEB force with a fixed step . The implementation switches the climbing image on when the largest force first falls below a threshold, so that the band is near the path when the climbing starts.
Example
One force by hand. Take , with minima at and the saddle , and three images , , . The energies are , so the middle image is a maximum along the band. The two weights are both and . The gradient at is , so and the true force across the band is . The two distances are both , so the spring force is zero. The force is , with or without climbing. A step with moves the image to . A band of 9 images started on converges in 101 iterations to with the images at , and the climbing image at the saddle .
The Muller-Brown surface. The Muller-Brown potential has minima with , with and with . The saddle between A and C is with , and between C and B it is with . On the straight line from A to C the energy reaches , far above the saddle: the MEP bends far to the side. With , and , and the climbing image on below a force of 5, the band from A to C gives:
| segments | highest image, plain NEB | iterations | climbing image | iterations |
|---|---|---|---|---|
| 4 | at | 1303 | at | 440 |
| 8 | at | 4180 | at | 1350 |
| 16 | at | 14128 | at | 4310 |
The plain band puts no image at the saddle, so its highest image underestimates the barrier, by 3.1 for . The climbing image finds the saddle to the tolerance with any . From C to B, the climbing image converges to S2. From A to B with , the band passes through C (one image has ), and the climbing image goes to S1, the higher of the two saddles. A band joins two minima through every intermediate minimum on the way, and the climbing image finds only the highest saddle.
Correctness
The proof below shows what a converged band is. Split each force into its parts along and across . For an image that does not climb, the force is , where , and the two parts are orthogonal. So the force is zero only if is parallel to the tangent (the discrete MEP condition) and the two distances are equal. For the climbing image, the force is , a reflection of , so it has the length of the gradient, and a zero force means a stationary point of . These are facts about the fixed points. The NEB force is not the gradient of any function, so there is no proof that the iteration converges; it does in practice when is small enough.
Proof: The fixed points of the nudged elastic bandfull
We assume exact arithmetic and a potential that is continuously differentiable. The band is with fixed ends, , is a unit vector (the tangent of line L4), for , and . A converged band is one where every force of lines L6 and L7 is zero. The claim is about such a band. It is not a claim that the iteration converges.
Lemma 1 (the climbing force is a reflection). Let for a unit vector . Then the force of line L7 is , and .
Proof. . The matrix is symmetric and , so is orthogonal and keeps lengths.
So the stop test of line L8 also bounds the gradient at the climbing image: .
Theorem (the fixed points). Assume that all forces of lines L6 and L7 are zero, with the climbing image (if any).
- For every image , the gradient is parallel to : the perpendicular part of the true force is zero.
- For every image , . So the images are equally spaced on each side of the climbing image: and . Without a climbing image, all distances are equal.
- The climbing image is a stationary point of : .
Proof. Write with . For , line L6 gives
The two terms are orthogonal, so holds if and only if and . Since , this gives parts 1 and 2. For the climbing image, Lemma 1 gives , which is part 3.
Why the projections are needed. Without the projections, the force of a plain elastic band has two faults that the theorem shows NEB does not have. The parallel part of is not balanced by anything but the springs, so the images slide down from the barrier towards the minima and the region of the saddle has few images. The perpendicular part of the spring force is not zero where the path bends, so a converged plain band cuts the corner of a curved path and has . In NEB, the true force acts only across the path and the spring force acts only along it, so the two effects separate: part 1 holds whatever is, and affects only the spacing.
The link to the minimum energy path. A minimum energy path (MEP) is a curve from one minimum to another on which : at every point, the gradient is parallel to the tangent. Part 1 is the discrete form of this condition at the images. If the images lie on a smooth curve and approximates its tangent, a converged band is a discrete approximation of an MEP, and part 3 places one image exactly at a stationary point on it. The tangent of Henkelman and Jonsson is chosen so that points to the neighbour with the higher energy, with a smooth switch at the extremes of the energy along the band. It approximates the tangent of the curve to first order in the spacing.
What is not proved. The NEB force is not the gradient of any function, because the projections depend on the band, so there is no energy that the iteration decreases, and the convergence of line L9 is not proved in general. Near a converged band, the iteration is a linear fixed point iteration, and it converges if is small enough compared with the largest curvature of and with . The theorem does not say that the stationary point of part 3 is a first-order saddle, that it is the lowest saddle between the two minima, or that the band finds the MEP of lowest barrier. In practice the climbing image is the highest point of a converged band and is a first-order saddle, and the band finds the MEP closest to its start.
Complexity
One iteration costs evaluations of and , of cost each, and arithmetic for the tangents, projections and steps, in the real RAM model. The memory is for the band. The number of iterations depends on the conditioning of the landscape: steepest descent with step is stable only for , where is the largest curvature, and it converges in a number of steps proportional to . For Muller-Brown, , so . For atoms, is the cost of a force call of the interatomic potential or of an electronic structure code, and it dominates everything else. The force calls of one iteration are independent and run in parallel.
Properties
- Deterministic. The same start gives the same band.
- Gradients only. No Hessian is needed. The curvatures at the saddle, needed for the rate, are computed once at the end.
- Local. The band finds an MEP near its start, not the MEP with the lowest barrier. Two different starts can give two different paths.
- Not a minimization. The NEB force is not the gradient of an objective, so optimizers that need a line search on an energy must be adapted (Sheppard, Terrell and Henkelman 2008).
- Spacing control. The spring constant sets only the spacing and the speed of convergence along the band, not the position of the converged path.
Variants and improvements
- The original tangent. The first form of NEB estimated the tangent from the two neighbours without regard to their energies, and projected the vector sum of the two spring forces on it. Where the force along the path is large compared with the force across it, this gives kinks in the band; the improved tangent of line L4 removes them (Henkelman and Jonsson 2000).
- The climbing image. Line L7 is a modification of NEB that converges one image to the saddle. Without it, the barrier is found by interpolation between the images.
- Optimizers. Steepest descent is the simplest. Quick-min and FIRE are damped dynamics on the NEB force; conjugate gradient and limited memory BFGS over the whole band are often faster. Sheppard, Terrell and Henkelman compared them in 2008.
- Variable springs. A larger near the highest image puts more images near the saddle.
- The string method. The string method has no springs: it moves the images by the perpendicular force and then redistributes them by arc length.
- Saddle refinement. A short band, then the dimer method started from the highest image, often costs less than a fully converged band.
When to use it
Use NEB when you know both end states of a transition, for example a vacancy hop or a surface reaction, and you need the barrier and the path. It needs only forces, and the images run in parallel. Use the dimer method when only the initial state is known, for example to build an event catalog for kinetic Monte Carlo. At a finite temperature, when many paths contribute and the entropy matters, sample paths with transition path sampling instead of finding one MEP.
Pitfalls
- End states that are not minima. Relax both ends first. If an end is not at a minimum, the barrier is measured from a wrong reference.
- A step that is too large. With the stiff directions oscillate and the band blows up. Use a smaller or a damped optimizer.
- Climbing too early. If the climbing image is switched on far from the path, it can climb to a wrong region. Relax the plain band first.
- Intermediate minima. If an image sits in a minimum between the ends, the band has two barriers, and the climbing image finds only the higher one. Split the band into two at the intermediate minimum.
- Too few images. A band of few images can miss a bend of the MEP, and without a climbing image it underestimates the barrier, as in the table above.
- The straight line start. If the straight line passes through a region of very high energy, or atoms come too close on it, the first forces are huge. Start from a better interpolation.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/nudged-elastic-band/. The authors are listed in prov/NNCV7X.jsonl.
"""The nudged elastic band method with the improved tangent and the climbing image.
A chain of images R_0, ..., R_N joins two minima of a potential V. The end
images stay fixed. Each inner image moves under the NEB force: the part of
the true force -grad V that is perpendicular to the path, plus a spring
force along the path. The climbing image (the image with the highest
energy) feels no spring and has the parallel part of the true force
inverted, so it moves up along the path and down in the other directions.
The tangent is the one of Henkelman and Jonsson (2000): the vector to the
neighbour with the higher energy, and a weighted mean of the two vectors at
an extremum of the energy along the path.
The iteration is plain steepest descent on the NEB force with a fixed
step h. The NEB force is not the gradient of a function, so the iteration
is a fixed point iteration and its convergence is not proved in general.
A potential is a function that maps a point (a list of floats) to the pair
(V, gradient). Coordinates are mass weighted if masses are not all equal.
"""
import math
from typing import Callable, Sequence
Point = list[float]
Potential = Callable[[Sequence[float]], tuple[float, list[float]]]
def _sub(a, b):
return [p - q for p, q in zip(a, b)]
def _dot(a, b):
return sum(p * q for p, q in zip(a, b))
def _norm(a):
return math.sqrt(_dot(a, a))
def improved_tangent(r_prev, r, r_next, e_prev, e, e_next) -> Point:
"""The unit tangent at r of Henkelman and Jonsson (2000)."""
t_plus = _sub(r_next, r)
t_minus = _sub(r, r_prev)
if e_next > e > e_prev:
t = t_plus
elif e_next < e < e_prev:
t = t_minus
else:
d_max = max(abs(e_next - e), abs(e_prev - e))
d_min = min(abs(e_next - e), abs(e_prev - e))
if e_next > e_prev:
t = [d_max * p + d_min * m for p, m in zip(t_plus, t_minus)]
else:
t = [d_min * p + d_max * m for p, m in zip(t_plus, t_minus)]
n = _norm(t)
if n == 0.0:
# e_next = e = e_prev: use the mean of the two segment vectors.
t = [p + m for p, m in zip(t_plus, t_minus)]
n = _norm(t)
return [c / n for c in t]
def neb_forces(images: Sequence[Point], energies: Sequence[float], grads: Sequence[Point],
k: float, climb: bool) -> tuple[list[Point], int]:
"""The NEB forces on the inner images 1..N-1 (zero vectors at the ends).
Returns the list of forces and the index of the climbing image (-1 if
climb is False).
"""
n = len(images) - 1
forces = [[0.0] * len(images[0]) for _ in range(n + 1)]
i_max = -1
if climb:
i_max = max(range(1, n), key=lambda i: energies[i])
for i in range(1, n):
tau = improved_tangent(images[i - 1], images[i], images[i + 1], # @line L4
energies[i - 1], energies[i], energies[i + 1])
g = grads[i]
g_par = _dot(g, tau)
if i == i_max:
# Invert the parallel part of the true force; no spring.
forces[i] = [-gc + 2.0 * g_par * tc for gc, tc in zip(g, tau)] # @line L7
continue
stretch = _norm(_sub(images[i + 1], images[i])) - _norm(_sub(images[i], images[i - 1]))
f_spring = k * stretch # @line L5
forces[i] = [-gc + g_par * tc + f_spring * tc for gc, tc in zip(g, tau)] # @line L6
return forces, i_max
def nudged_elastic_band(potential: Potential, r_start: Sequence[float], r_end: Sequence[float],
n: int, k: float, h: float, tol: float, climb: bool = True,
climb_tol: float = math.inf, max_iter: int = 10000,
images: Sequence[Point] = None):
"""Relax a band of n + 1 images from r_start to r_end.
The start band is the straight line (or the given images). The climbing
image is switched on when climb is True and the largest force is below
climb_tol. The iteration stops when the largest force is below tol and
the climbing image is on (if climb is True).
Returns (images, energies, i_climb, iterations, converged).
"""
if images is None:
images = [[a + (i / n) * (b - a) for a, b in zip(r_start, r_end)] # @line L1
for i in range(n + 1)]
else:
images = [list(p) for p in images]
climbing = climb and climb_tol == math.inf
energies, grads = [], []
for p in images:
e, g = potential(p)
energies.append(e)
grads.append(g)
i_max = -1
for it in range(max_iter): # @line L2
for i in range(1, n): # @line L3
energies[i], grads[i] = potential(images[i])
forces, i_max = neb_forces(images, energies, grads, k, climbing)
f_max = max(_norm(f) for f in forces) # @line L8
if climb and not climbing and f_max < climb_tol:
climbing = True
continue
if f_max < tol and climbing == climb: # @line L8
return images, energies, i_max, it, True
for i in range(1, n): # @line L9
images[i] = [c + h * f for c, f in zip(images[i], forces[i])]
return images, energies, i_max, max_iter, False
def muller_brown(p: Sequence[float]) -> tuple[float, list[float]]:
"""The Muller-Brown potential (Muller and Brown 1979) and its gradient."""
x, y = p
A = (-200.0, -100.0, -170.0, 15.0)
a = (-1.0, -1.0, -6.5, 0.7)
b = (0.0, 0.0, 11.0, 0.6)
c = (-10.0, -10.0, -6.5, 0.7)
x0 = (1.0, 0.0, -0.5, -1.0)
y0 = (0.0, 0.5, 1.5, 1.0)
v = gx = gy = 0.0
for j in range(4):
dx, dy = x - x0[j], y - y0[j]
e = A[j] * math.exp(a[j] * dx * dx + b[j] * dx * dy + c[j] * dy * dy)
v += e
gx += e * (2.0 * a[j] * dx + b[j] * dy)
gy += e * (b[j] * dx + 2.0 * c[j] * dy)
return v, [gx, gy]
test_nudged_elastic_band.py 86 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/nudged-elastic-band/. The authors are listed in prov/NNCV7X.jsonl.
import math
import pytest
from nudged_elastic_band import improved_tangent, muller_brown, neb_forces, nudged_elastic_band
A = [-0.55822, 1.44173]
B = [0.62350, 0.02804]
C = [-0.05001, 0.46669]
S1 = (-0.82200, 0.62431, -40.6648)
S2 = (0.21249, 0.29299, -72.2489)
def double_well(p):
x, y = p
return (x * x - 1.0) ** 2 + 2.0 * y * y, [4.0 * x * (x * x - 1.0), 4.0 * y]
def test_tangent_rules():
r0, r1, r2 = [0.0, 0.0], [1.0, 0.0], [1.0, 2.0]
# Energy rises along the path: the tangent points to the next image.
assert improved_tangent(r0, r1, r2, 0.0, 1.0, 2.0) == pytest.approx([0.0, 1.0])
# Energy falls: the tangent points from the previous image.
assert improved_tangent(r0, r1, r2, 2.0, 1.0, 0.0) == pytest.approx([1.0, 0.0])
# A maximum with e_next > e_prev: weights d_max = 1 on t_plus, d_min = 0.5 on t_minus.
t = improved_tangent(r0, r1, r2, 0.5, 1.0, 0.0)
w = [0.5 * 0.0 + 1.0 * 1.0, 0.5 * 2.0 + 1.0 * 0.0]
assert t == pytest.approx([c / math.hypot(*w) for c in w])
def test_force_by_hand():
# The page example: images (-1, 0), (0, 0.5), (1, 0) on the double well.
ims = [[-1.0, 0.0], [0.0, 0.5], [1.0, 0.0]]
en = [double_well(p)[0] for p in ims]
gr = [double_well(p)[1] for p in ims]
assert en == pytest.approx([0.0, 1.5, 0.0])
f, i_c = neb_forces(ims, en, gr, 5.0, False)
assert i_c == -1
assert f[1] == pytest.approx([0.0, -2.0])
f, i_c = neb_forces(ims, en, gr, 5.0, True)
assert i_c == 1
assert f[1] == pytest.approx([0.0, -2.0])
def test_double_well_band_goes_to_the_axis():
n = 8
init = [[-1.0 + 2.0 * i / n, 0.5 * math.sin(math.pi * i / n)] for i in range(n + 1)]
ims, en, i_c, it, ok = nudged_elastic_band(double_well, init[0], init[-1], n, k=5.0, h=0.05,
tol=1e-8, climb=True, images=init)
assert ok and it < 1000
assert i_c == 4
assert ims[i_c] == pytest.approx([0.0, 0.0], abs=1e-8)
for i, p in enumerate(ims):
assert p == pytest.approx([-1.0 + 2.0 * i / n, 0.0], abs=1e-6)
def mb_band(start, end, climb):
return nudged_elastic_band(muller_brown, start, end, 8, k=50.0, h=2e-4, tol=1e-3,
climb=climb, climb_tol=5.0, max_iter=10000)
@pytest.mark.parametrize("start,end,saddle", [(A, C, S1), (C, B, S2)])
def test_climbing_image_finds_the_muller_brown_saddle(start, end, saddle):
ims, en, i_c, it, ok = mb_band(start, end, True)
assert ok
assert ims[i_c] == pytest.approx(list(saddle[:2]), abs=1e-4)
assert en[i_c] == pytest.approx(saddle[2], abs=1e-3)
# The force on the climbing image has the norm of the gradient, so the image is a stationary point.
assert math.hypot(*muller_brown(ims[i_c])[1]) < 1e-3
def test_plain_band_is_below_the_saddle_and_evenly_spaced():
ims, en, i_c, it, ok = mb_band(A, C, False)
assert ok and i_c == -1
top = max(en)
assert -44.5 < top < S1[2] - 1.0
gaps = [math.dist(ims[i], ims[i + 1]) for i in range(8)]
assert max(gaps) - min(gaps) < 1e-3
def test_straight_line_is_far_above_the_path():
top = max(muller_brown([A[0] + s / 200 * (C[0] - A[0]), A[1] + s / 200 * (C[1] - A[1])])[0]
for s in range(201))
assert top > 0.0 > S1[2]
History
Mills and Jonsson introduced the nudged elastic band in 1994, in a study of the dissociative adsorption of H2 that used paths of quantum systems. Jonsson, Mills and Jacobsen gave the full method in 1998, with the projections that separate the true force from the spring force. In 2000 Henkelman, Uberuaga and Jonsson added the climbing image, and Henkelman and Jonsson gave the improved tangent that removes kinks. Muller and Brown had introduced their two-dimensional test potential in 1979 for an earlier method of finding saddles.
References
- Greg Mills and Hannes Jonsson, Quantum and thermal effects in H2 dissociative adsorption: evaluation of free energy barriers in multidimensional quantum systems, Physical Review Letters 72(7), 1994, 1124-1127, the first use of the nudged elastic band, there for paths of quantum (path integral) systems
- Hannes Jonsson, Greg Mills and Karsten W. Jacobsen, Nudged elastic band method for finding minimum energy paths of transitions, in Classical and Quantum Dynamics in Condensed Phase Simulations, World Scientific, 1998, 385-404, the full description, the projections of the true force and the spring force, and the comparison with the plain elastic band
- Graeme Henkelman, Blas P. Uberuaga and Hannes Jonsson, A climbing image nudged elastic band method for finding saddle points and minimum energy paths, Journal of Chemical Physics 113(22), 2000, 9901-9904, the climbing image, with the parallel force inverted and no spring force
- Graeme Henkelman and Hannes Jonsson, Improved tangent estimate in the nudged elastic band method for finding minimum energy paths and saddle points, Journal of Chemical Physics 113(22), 2000, 9978-9985, the tangent to the neighbour of higher energy, the weighted tangent at extremes, and the spring force from the difference of the distances
- Daniel Sheppard, Rye Terrell and Graeme Henkelman, Optimization methods for finding minimum energy paths, Journal of Chemical Physics 128(13), 2008, 134106, the comparison of optimizers for the NEB force, which is not the gradient of an objective
- Klaus Muller and Leo D. Brown, Location of saddle points and minimum energy paths by a constrained simplex optimization procedure, Theoretica Chimica Acta 53(1), 1979, 75-93, the two-dimensional test potential of the example
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag NNCV7X Edit this page History Report an error Markdown