Algorithmadvanced
Dimer method
Finds saddle points from one minimum using only gradients, by rotating a pair of close images to the lowest curvature mode and climbing along it.
- Time
- O(I r (G + d)) worst
- Space
- O(d) extra
- Where
- G = the cost of one gradient; I = the number of translations; d = the number of coordinates; r = the number of rotations per translation
- Model
- Real RAM
- Properties
- deterministicnot exactiterativenot randomized
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Graeme Henkelman, Hannes Jonsson, 1999
The dimer method finds a first-order saddle point of a potential energy, starting from a point near a minimum, without knowing the final state and without computing the Hessian. It uses a dimer: two points close together, at . The two gradients give the curvature along the direction . The method rotates the dimer to the direction of the lowest curvature, then moves its centre uphill along that direction and downhill in all others. Each step needs only a few gradient evaluations, so it works for systems with thousands of atoms. Saddles found from one minimum give the possible escapes and, by harmonic transition state theory, their rates, for example for the event catalog of kinetic Monte Carlo.
In plain words
You stand in a valley in fog and want to find the lowest passes out of it. You cannot see the shape of the land, but you can feel the slope under your feet. With a short stick held at two points, you can feel how the slope changes along the stick, which tells you how much the ground bends in that direction.
Turn the stick until it points in the direction where the ground bends upward the least, or bends down. That is the easiest way out of the valley. Then walk uphill along the stick and downhill across it. In a valley, this takes you up the softest side. Near a pass, it takes you to the top of the pass and keeps you in the middle of it. Different starts lead to different passes.
The problem
The input is a potential with its gradient, a start point (often a minimum plus a small random displacement) and a start direction . The output is a first-order saddle : and the Hessian has exactly one negative eigenvalue , together with its eigenvector , the direction of the reaction. The final state is not given. For atoms, the coordinates are mass weighted if the masses differ.
The algorithm
DIMER-METHOD(V, R, N, ΔR, h, tol)- 1
N ← N / |N| - 2
repeat - 3
F ← -∇V(R), F_1 ← -∇V(R + ΔR N), F_2 ← 2F - F_1 - 4
C ← (F_2 - F_1) · N / (2 ΔR) ▷ curvature along N - 5
F_rot ← (F_1 - F_2) - ((F_1 - F_2) · N) N, Θ ← F_rot / |F_rot| - 6
from C, dC/dφ and the curvature at one trial angle, fit C(φ) = a_0/2 + a_1 cos 2φ + b_1 sin 2φ and take its minimum φ - 7
N ← cos φ N + sin φ Θ ▷ repeat L3 to L7 until |F_rot| is small - 8
if |F| < tol and C < 0 then return R, N, C - 9
F† ← F - 2 (F · N) N if C < 0, else F† ← -(F · N) N - 10
R ← R + h F†, with the length of the step at most s_max (equal to s_max where C ≥ 0)
Line L3 evaluates the gradient at the centre and at one end of the dimer; the other end follows from a central difference. Line L4 is the curvature along , which is . Lines L5 to L7 rotate the dimer. The rotational force is the part of perpendicular to ; it is zero when is an eigenvector of . The rotation of line L6 is the one of Heyden, Bell and Keil: the curvature in the plane of and is exactly for a quadratic , so one trial rotation by a small angle , with one more gradient, fixes the three numbers and gives the angle of the minimum. Henkelman and Jonsson's original rotation used a trial angle and a fit of the rotational force instead. Line L9 is the force of the translation: where the curvature is negative, the component along is inverted, which turns the saddle into a minimum of the modified landscape. Where the dimer is still in the convex region of the basin, so it moves only along , uphill, with a full step of length .
Example
One rotation by hand. Take the quadratic with , eigenvalues , and start with . Then . , its part perpendicular to is , so . The fit numbers are , and . The curvature in the plane is , with . The minimum is at , with , the lowest eigenvalue, and the new is its eigenvector. In two dimensions one rotation is exact. The translation with from then reaches the saddle to in 76 steps.
Searches on the Muller-Brown surface. From each of the three minima, 20 searches started at the minimum plus a Gaussian displacement of standard deviation 0.05 in each coordinate, with a random (random.Random(1)), , , and , gave:
| start | found S1 , | found S2 , | no saddle in 2000 steps |
|---|---|---|---|
| minimum C | 6 | 14 | 0 |
| minimum B | 0 | 13 | 7 |
| minimum A | 3 | 0 | 17 |
From C, all 20 searches converged, in 55 translations for the median search and at most 145, and the curvature at the end agrees with the negative eigenvalue of the Hessian ( at S1, at S2). From A and B, the soft direction of the basin often points away from both saddles, and the search climbs the walls of the surface into the region where grows without bound. This is the typical behavior: a set of searches from one minimum gives some of the saddles, not all, and some searches are lost.
Correctness
The proof below has three parts. First, by a Taylor expansion, the difference of the two forces is , so the dimer measures and the curvature with two gradients. Second, the curvature along is a Rayleigh quotient, which is a constant plus a sinusoid in ; three values fix it, and its minimum is the lowest eigenvalue of in that plane. In two dimensions this is the lowest eigenvalue, so one rotation is exact. Third, the modified force is , a reflection of , so it is zero only where the gradient is zero; and near a first-order saddle, with the eigenvector of the negative eigenvalue, the step of line L10 is a contraction for . So a first-order saddle is an attracting fixed point. The proof does not show that a search from a minimum reaches a saddle, or which one.
Proof: The rotation and the translation of the dimer methodfull
We assume exact arithmetic and a potential that is three times continuously differentiable. is the force, the Hessian, the dimer has the centre , the unit vector and the half length , and , . The implementation computes as , which is the same up to and is exact when is quadratic.
Lemma 1 (the curvature). , and . Both are exact for a quadratic .
Proof. By Taylor's theorem, . The difference of the two cancels the even terms: . Divide by and take the dot product with . For a quadratic the gradient is affine, so there are no remainder terms.
So with small the dimer measures with two gradients and never forms .
Lemma 2 (the rotation is exact for a quadratic). Let be quadratic with Hessian , let be the unit vector of the part of that is perpendicular to (line L5), and let . Then the curvature along is
with , and . The three numbers are fixed by , and one value with , and the angle of line L6 gives the minimum of over the plane of and , which is the smaller eigenvalue of restricted to this plane.
Proof. By Lemma 1, , and the double angle formulas give the form above. Then and . By Lemma 1, , which is the value of that the code uses. The value gives , which is the formula of the code, and then . Write with and . The maximum of is at and the minimum at , with the value . The code computes , sees that unless , and adds . The minimum of a Rayleigh quotient over the unit vectors of a plane is the smaller eigenvalue of the restriction.
Consequences for the rotation. In two dimensions the plane is the whole space, so one rotation gives the lowest eigenvalue and its eigenvector exactly. In dimensions each rotation does not increase , and the rotational force minus its part along is zero exactly when is parallel to , so the fixed points of the rotation are the eigenvectors of . The minimum of the Rayleigh quotient over all unit vectors is the smallest eigenvalue , and repeated rotations are a descent method for it. We do not prove that they converge to the eigenvector of from every start; they do if is simple and the start is not orthogonal to its eigenvector.
Lemma 3 (the fixed points of the translation). Let . Where , the force of line L9 is , and if and only if .
Proof. , and is orthogonal (, ), so .
So the stop test of line L8 is a test on .
Theorem (local convergence to a first-order saddle). Let be a first-order saddle: and has eigenvalues . Assume that is the unit eigenvector of at every step (exact rotation) and that is quadratic. Then the step of line L10 converges to from every start with if .
Proof. For a quadratic , , so changes by the matrix . With the eigenvector of , and have the same eigenvectors, and has the eigenvalues , all positive. The matrix has the eigenvalues , all in under the condition on . So geometrically.
The inversion of the force along turns the saddle, which is not a minimum of , into a minimum of the modified landscape seen by the translation: the step goes uphill along the lowest mode and downhill in all others. For a smooth that is not quadratic, the same argument holds near for the linearized step, so a first-order saddle is a locally attracting fixed point.
What is not proved. The theorem is local. Far from a saddle, where , the method moves along only, and nothing guarantees that it reaches a region with : on the Muller-Brown surface many searches from the minimum A run away to the region where grows without bound. The method does not say which saddle it finds, and a set of searches from one minimum gives a sample of nearby saddles, not a complete list.
Complexity
One translation costs one gradient at the centre and two gradients for each rotation (one at the dimer end, one at the trial angle), so gradients for rotations, plus arithmetic in the real RAM model. The memory is . For atoms, the gradient costs (a force call) and dominates. The number of translations depends on the start and the landscape; near the saddle it falls like the linear rate of steepest descent on the reflected Hessian, and with a quasi-Newton step it is much smaller. The method never stores or factors the Hessian, which is why it is used where is large.
Properties
- First derivatives only. The curvature and the lowest mode come from finite differences of gradients.
- One end state. The final state is not needed. The final state is found after the search, by a relaxation from both sides of the saddle along .
- Local and incomplete. A search finds one saddle near its start, and a set of searches samples the saddles around a minimum without a guarantee of completeness.
- Deterministic. The same start and the same give the same saddle. The randomness in practice is in the choice of the starts.
Variants and improvements
- Rotation by a fit of the curvature. The rotation of line L6 (Heyden, Bell and Keil 2005) uses the exact form of the curvature as a function of the angle. The original rotation of Henkelman and Jonsson used a fit of the rotational force at a trial angle.
- Conjugate gradient rotations. In many dimensions, the search directions of the rotation are chosen by a conjugate gradient rule instead of the plain rotational force, as in an eigenvalue solver.
- Translation with memory. A conjugate gradient or limited memory BFGS step on the modified force converges faster than the fixed step of line L10.
- Other lowest mode solvers. The lowest eigenvector can also come from the Lanczos algorithm on the Hessian applied by finite differences, as in the activation relaxation technique; the dimer rotation is a gradient method for the Rayleigh quotient.
- Use in on-the-fly KMC. Many dimer searches from one state give the event catalog of adaptive kinetic Monte Carlo; the rates follow from harmonic transition state theory.
When to use it
Use the dimer method when you know the initial state and want the escapes from it, with no guess of the final state: to explore the events of a defect, to build an event catalog, or to refine a saddle from the highest image of a short nudged elastic band. Use the nudged elastic band when both end states are known and you also need the whole path. For a small system where the Hessian is cheap, a Newton method on the gradient with the eigenvector following of the Hessian is simpler.
Pitfalls
- A dimer that is too short or too long. A large gives an error of in the curvature. A very small one gives rounding error: the error in is about for the machine epsilon , so the error in grows like . Noisy forces, for example from an electronic structure code, make this much worse. Check that changes little when changes by a factor of 2.
- Runaway searches. In the convex region the dimer climbs along the softest mode, which may lead to a high wall instead of a saddle. Limit the step and the number of steps, and drop searches that go too far.
- The same saddle again. Many searches find the same low saddles; compare each new saddle with those already found, by energy and position.
- A higher-order saddle. If the lowest mode is not resolved (a rotation that stops too early), the dimer can converge to a point with two negative curvatures. Check the curvature along a second direction at the end.
- Stop tests on the force only. The stop test must also check ; a small force with is a minimum.
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/dimer-method/. The authors are listed in prov/JXAQP4.jsonl.
"""The dimer method for saddle points (Henkelman and Jonsson 1999).
A dimer is a pair of points R +- dR N around a centre R, with a unit
vector N. Only gradients are used. From the two gradients:
- the curvature along N is C = (F2 - F1) . N / (2 dR), where F = -grad V
at the two points. It is N^T H N up to O(dR^2).
- the rotation turns N in the plane of N and the rotational force, to the
angle that minimizes the curvature. The angle comes from the fit
C(phi) = a0 / 2 + a1 cos(2 phi) + b1 sin(2 phi), which is exact for a
quadratic V (Heyden, Bell and Keil 2005). It costs one extra gradient.
- the translation moves R along the force with the component along N
inverted (F - 2 (F . N) N) if C < 0, and along -(F . N) N only if
C >= 0, so that the dimer leaves a convex region fast.
A potential maps a point (list of floats) to (V, gradient).
"""
import math
from typing import Callable, Sequence
Point = list[float]
Potential = Callable[[Sequence[float]], tuple[float, list[float]]]
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 _axpy(alpha, x, y):
return [alpha * p + q for p, q in zip(x, y)]
def _unit(a):
n = _norm(a)
return [c / n for c in a]
def curvature(potential: Potential, r: Sequence[float], n: Sequence[float], dr: float,
g0: Sequence[float]) -> tuple[float, list[float]]:
"""The curvature along the unit vector n and the force difference F1 - F2.
Uses the gradient g0 at the centre and one new gradient at R1 = r + dr n;
the gradient at R2 = r - dr n is taken as 2 g0 - g1 (central difference).
"""
g1 = potential(_axpy(dr, n, r))[1]
f1 = [-c for c in g1]
f2 = [-(2.0 * a - b) for a, b in zip(g0, g1)]
c = _dot([b - a for a, b in zip(f1, f2)], n) / (2.0 * dr) # @line L4
return c, [a - b for a, b in zip(f1, f2)]
def rotate(potential: Potential, r, n, dr, g0, phi_trial=None):
"""One rotation of the dimer to the lowest curvature in one plane.
Returns (n_new, c_new, c_old, f_rot): the new unit vector, its estimated
curvature, the curvature before, and the norm of the rotational force.
"""
c0, df = curvature(potential, r, n, dr, g0)
f_perp = _axpy(-_dot(df, n), n, df) # @line L5
f_rot = _norm(f_perp)
if f_rot == 0.0:
return list(n), c0, c0, 0.0
theta = [c / f_rot for c in f_perp]
# dC/dphi at phi = 0 is 2 theta^T H n = -(F1 - F2) . theta / dR.
dc = -_dot(df, theta) / dr
if phi_trial is None:
phi_trial = -0.5 * math.atan(dc / (2.0 * abs(c0)))
if abs(phi_trial) < 1e-3:
phi_trial = 1e-3 if phi_trial >= 0 else -1e-3
n1 = _unit(_axpy(math.sin(phi_trial), theta, [math.cos(phi_trial) * c for c in n]))
c1, _ = curvature(potential, r, n1, dr, g0)
b1 = 0.5 * dc # @line L6
a1 = (c0 - c1 + b1 * math.sin(2.0 * phi_trial)) / (1.0 - math.cos(2.0 * phi_trial))
a0 = 2.0 * (c0 - a1)
phi = 0.5 * math.atan2(b1, a1) # @line L6
c_min = 0.5 * a0 + a1 * math.cos(2.0 * phi) + b1 * math.sin(2.0 * phi)
if c_min > c0:
phi += 0.5 * math.pi
c_min = 0.5 * a0 + a1 * math.cos(2.0 * phi) + b1 * math.sin(2.0 * phi)
n_new = _unit(_axpy(math.sin(phi), theta, [math.cos(phi) * c for c in n])) # @line L7
return n_new, c_min, c0, f_rot
def dimer_method(potential: Potential, r0: Sequence[float], n0: Sequence[float], dr: float,
h: float, tol: float, max_step: float = 0.02, rot_tol: float = 1e-3,
max_rot: int = 4, max_iter: int = 2000):
"""Search for a first-order saddle point from r0 with the start direction n0.
h is the step factor of the translation where c < 0, and each step is
at most max_step long. Where c >= 0 every step has the length max_step. Returns (r, n, c, iterations, converged): the centre,
the unit vector of the lowest curvature mode, the curvature along it,
the number of translations and whether |grad V| < tol with c < 0.
"""
r = list(r0)
n = _unit(n0) # @line L1
c = 0.0
for it in range(max_iter): # @line L2
g0 = potential(r)[1] # @line L3
for _ in range(max_rot):
n, c, _c_old, f_rot = rotate(potential, r, n, dr, g0)
if f_rot < rot_tol:
break
if _norm(g0) < tol and c < 0.0: # @line L8
return r, n, c, it, True
f = [-a for a in g0]
f_par = _dot(f, n)
if c < 0.0:
f_eff = _axpy(-2.0 * f_par, n, f) # @line L9
else:
f_eff = [-f_par * a for a in n] # @line L9
step = [h * a for a in f_eff]
s = _norm(step)
if s > max_step or (c >= 0.0 and s > 0.0):
# In a convex region, take a full step of length max_step uphill along n.
step = [a * max_step / s for a in step]
r = [a + b for a, b in zip(r, step)] # @line L10
return r, n, c, 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_dimer_method.py 87 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/dimer-method/. The authors are listed in prov/JXAQP4.jsonl.
import math
import random
import pytest
from dimer_method import curvature, dimer_method, muller_brown, rotate
C_MIN = [-0.05001, 0.46669]
S1 = (-0.82200, 0.62431, -40.6648)
S2 = (0.21249, 0.29299, -72.2489)
def quadratic(p):
# V = (3 x^2 + 2 x y - y^2) / 2, Hessian [[3, 1], [1, -1]], eigenvalues 1 +- sqrt(5).
x, y = p
return 0.5 * (3.0 * x * x + 2.0 * x * y - y * y), [3.0 * x + y, x - y]
def hessian_fd(potential, p, e=1e-5):
h = [[0.0, 0.0], [0.0, 0.0]]
for j in range(2):
q1 = list(p)
q2 = list(p)
q1[j] += e
q2[j] -= e
g1 = potential(q1)[1]
g2 = potential(q2)[1]
for i in range(2):
h[i][j] = (g1[i] - g2[i]) / (2.0 * e)
return h
def eig2(h):
t = h[0][0] + h[1][1]
d = h[0][0] * h[1][1] - h[0][1] * h[1][0]
s = math.sqrt(t * t / 4.0 - d)
return t / 2.0 - s, t / 2.0 + s
def test_curvature_is_the_rayleigh_quotient_for_a_quadratic():
p = [0.3, 0.2]
g0 = quadratic(p)[1]
c, _ = curvature(quadratic, p, [1.0, 0.0], 1e-3, g0)
assert c == pytest.approx(3.0, abs=1e-9)
n = [1.0 / math.sqrt(2.0), 1.0 / math.sqrt(2.0)]
c, _ = curvature(quadratic, p, n, 1e-3, g0)
assert c == pytest.approx((3.0 + 2.0 - 1.0) / 2.0, abs=1e-9)
def test_one_rotation_finds_the_lowest_mode_of_a_quadratic():
p = [0.3, 0.2]
n, c, c0, f_rot = rotate(quadratic, p, [1.0, 0.0], 1e-3, quadratic(p)[1])
lam = 1.0 - math.sqrt(5.0)
assert c0 == pytest.approx(3.0, abs=1e-9)
assert c == pytest.approx(lam, abs=1e-9)
# n is an eigenvector: H n = lam n.
hn = [3.0 * n[0] + n[1], n[0] - n[1]]
assert hn == pytest.approx([lam * n[0], lam * n[1]], abs=1e-8)
def test_translation_converges_to_the_saddle_of_a_quadratic():
r, n, c, it, ok = dimer_method(quadratic, [0.3, 0.2], [1.0, 0.0], 1e-3, 0.2, 1e-10)
assert ok and it < 200
assert r == pytest.approx([0.0, 0.0], abs=1e-9)
assert c == pytest.approx(1.0 - math.sqrt(5.0), abs=1e-9)
def test_searches_from_muller_brown_minimum_c_find_both_saddles():
rng = random.Random(1)
found = {"S1": 0, "S2": 0}
for _ in range(20):
r0 = [C_MIN[0] + rng.gauss(0.0, 0.05), C_MIN[1] + rng.gauss(0.0, 0.05)]
a = rng.uniform(0.0, 2.0 * math.pi)
r, n, c, it, ok = dimer_method(muller_brown, r0, [math.cos(a), math.sin(a)], 1e-4, 1e-3, 1e-6)
assert ok and it < 500
name = "S1" if r[0] < -0.4 else "S2"
s = S1 if name == "S1" else S2
found[name] += 1
assert r == pytest.approx(list(s[:2]), abs=1e-5)
assert muller_brown(r)[0] == pytest.approx(s[2], abs=1e-4)
# A first-order saddle: one negative eigenvalue, and c is it.
lo, hi = eig2(hessian_fd(muller_brown, r))
assert lo < 0.0 < hi
assert c == pytest.approx(lo, rel=1e-3)
assert found == {"S1": 6, "S2": 14}
History
Henkelman and Jonsson introduced the dimer method in 1999 for saddle searches on high-dimensional potential surfaces where only forces are available, for example from density functional theory. Heyden, Bell and Keil improved the rotation in 2005 with the fit of the curvature as a function of the rotation angle and compared the method with Hessian-based saddle searches. The method became a standard tool for building event catalogs in adaptive kinetic Monte Carlo.
References
- Graeme Henkelman and Hannes Jonsson, A dimer method for finding saddle points on high dimensional potential surfaces using only first derivatives, Journal of Chemical Physics 111(15), 1999, 7010-7022, the dimer, the curvature from two gradients, the rotation to the lowest mode and the modified force of the translation
- Andreas Heyden, Alexis T. Bell and Frerich J. Keil, Efficient methods for finding transition states in chemical reactions: comparison of improved dimer method and partitioned rational function optimization method, Journal of Chemical Physics 123(22), 2005, 224101, the improved rotation, with the curvature fitted as a function of the rotation angle
- 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 JXAQP4 Edit this page History Report an error Markdown