Algorithm Search⌘K

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
Properties
deterministicnot exactiterativenot randomized
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 R±ΔR NR \pm \Delta R\, N. The two gradients give the curvature along the direction NN. 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 V:Rd→RV: \mathbb{R}^d \to \mathbb{R} with its gradient, a start point R0R_0 (often a minimum plus a small random displacement) and a start direction N0N_0. The output is a first-order saddle RsR_s: ∇V(Rs)=0\nabla V(R_s) = 0 and the Hessian H(Rs)H(R_s) has exactly one negative eigenvalue λ1\lambda_1, together with its eigenvector NN, the direction of the reaction. The final state is not given. For atoms, the coordinates are mass weighted if the masses differ.

The algorithm

  1. DIMER-METHOD(V, R, N, ΔR, h, tol)
  2. 1N ← N / |N|
  3. 2repeat
  4. 3F ← -∇V(R), F_1 ← -∇V(R + ΔR N), F_2 ← 2F - F_1
  5. 4C ← (F_2 - F_1) · N / (2 ΔR) ▷ curvature along N
  6. 5F_rot ← (F_1 - F_2) - ((F_1 - F_2) · N) N, Θ ← F_rot / |F_rot|
  7. 6from 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 φ
  8. 7N ← cos φ N + sin φ Θ ▷ repeat L3 to L7 until |F_rot| is small
  9. 8if |F| < tol and C < 0 then return R, N, C
  10. 9F† ← F - 2 (F · N) N if C < 0, else F† ← -(F · N) N
  11. 10R ← 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 NN, which is NTHN+O(ΔR2)N^{\mathsf T} H N + O(\Delta R^2). Lines L5 to L7 rotate the dimer. The rotational force FrotF_{\mathrm{rot}} is the part of F1−F2F_1 - F_2 perpendicular to NN; it is zero when NN is an eigenvector of HH. The rotation of line L6 is the one of Heyden, Bell and Keil: the curvature in the plane of NN and Θ\Theta is exactly a0/2+a1cos⁡2φ+b1sin⁡2φa_0/2 + a_1 \cos 2\varphi + b_1 \sin 2\varphi for a quadratic VV, so one trial rotation by a small angle φ1\varphi_1, 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 NN is inverted, which turns the saddle into a minimum of the modified landscape. Where C≥0C \ge 0 the dimer is still in the convex region of the basin, so it moves only along NN, uphill, with a full step of length smax⁡s_{\max}.

Example

One rotation by hand. Take the quadratic V(x,y)=12(3x2+2xy−y2)V(x, y) = \frac12 (3x^2 + 2xy - y^2) with H=(311−1)H = \begin{pmatrix} 3 & 1 \\ 1 & -1 \end{pmatrix}, eigenvalues 1±51 \pm \sqrt5, and start with N=(1,0)N = (1, 0). Then C(0)=NTHN=3C(0) = N^{\mathsf T} H N = 3. F1−F2=−2ΔR HN=−2ΔR (3,1)F_1 - F_2 = -2\Delta R\, H N = -2\Delta R\, (3, 1), its part perpendicular to NN is (0,−2ΔR)(0, -2\Delta R), so Θ=(0,−1)\Theta = (0, -1). The fit numbers are b1=ΘTHN=−1b_1 = \Theta^{\mathsf T} H N = -1, a1=12(3−(−1))=2a_1 = \frac12 (3 - (-1)) = 2 and a0=2a_0 = 2. The curvature in the plane is 1+2cos⁡2φ−sin⁡2φ=1+5cos⁡(2φ−2φ∗)1 + 2\cos 2\varphi - \sin 2\varphi = 1 + \sqrt5 \cos(2\varphi - 2\varphi^*), with 2φ∗=atan2⁡(−1,2)=−0.46362\varphi^* = \operatorname{atan2}(-1, 2) = -0.4636. The minimum is at φ=φ∗+π/2=1.3390\varphi = \varphi^* + \pi/2 = 1.3390, with C=1−5=−1.2361C = 1 - \sqrt5 = -1.2361, the lowest eigenvalue, and the new N=(cos⁡1.3390,−sin⁡1.3390)=(0.2298,−0.9732)N = (\cos 1.3390, -\sin 1.3390) = (0.2298, -0.9732) is its eigenvector. In two dimensions one rotation is exact. The translation with h=0.2h = 0.2 from (0.3,0.2)(0.3, 0.2) then reaches the saddle (0,0)(0, 0) to 10−1010^{-10} 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 NN (random.Random(1)), ΔR=10−4\Delta R = 10^{-4}, h=10−3h = 10^{-3}, smax⁡=0.02s_{\max} = 0.02 and ∣∇V∣<10−6|\nabla V| < 10^{-6}, gave:

start found S1 (−0.82200,0.62431)(-0.82200, 0.62431), V=−40.6648V = -40.6648 found S2 (0.21249,0.29299)(0.21249, 0.29299), V=−72.2489V = -72.2489 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 (−750.86-750.86 at S1, −735.25-735.25 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 VV 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 −2ΔR HN+O(ΔR3)-2\Delta R\, H N + O(\Delta R^3), so the dimer measures HNH N and the curvature NTHNN^{\mathsf T} H N with two gradients. Second, the curvature along cos⁡φ N+sin⁡φ Θ\cos\varphi\, N + \sin\varphi\, \Theta is a Rayleigh quotient, which is a constant plus a sinusoid in 2φ2\varphi; three values fix it, and its minimum is the lowest eigenvalue of HH in that plane. In two dimensions this is the lowest eigenvalue, so one rotation is exact. Third, the modified force is F†=(I−2NNT)FF^{\dagger} = (I - 2NN^{\mathsf T}) F, a reflection of FF, so it is zero only where the gradient is zero; and near a first-order saddle, with NN the eigenvector of the negative eigenvalue, the step of line L10 is a contraction for h<2/max⁡i∣λi∣h < 2 / \max_i |\lambda_i|. 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 VV that is three times continuously differentiable. F=−∇VF = -\nabla V is the force, H(R)=∇2V(R)H(R) = \nabla^2 V(R) the Hessian, the dimer has the centre RR, the unit vector NN and the half length ΔR\Delta R, and F1=F(R+ΔRN)F_1 = F(R + \Delta R N), F2=F(R−ΔRN)F_2 = F(R - \Delta R N). The implementation computes F2F_2 as 2F(R)−F12F(R) - F_1, which is the same up to O(ΔR2)O(\Delta R^2) and is exact when VV is quadratic.

Lemma 1 (the curvature). C=(F2−F1)⋅N/(2ΔR)=NTH(R)N+O(ΔR2)C = (F_2 - F_1) \cdot N / (2\Delta R) = N^{\mathsf T} H(R) N + O(\Delta R^2), and (F1−F2)/(2ΔR)=−H(R)N+O(ΔR2)(F_1 - F_2) / (2\Delta R) = -H(R) N + O(\Delta R^2). Both are exact for a quadratic VV.

Proof. By Taylor's theorem, ∇V(R±ΔRN)=∇V(R)±ΔR HN+12ΔR2D3V[N,N]+O(ΔR3)\nabla V(R \pm \Delta R N) = \nabla V(R) \pm \Delta R\, H N + \frac12 \Delta R^2 D^3V[N, N] + O(\Delta R^3). The difference of the two cancels the even terms: F1−F2=−2ΔR HN+O(ΔR3)F_1 - F_2 = -2\Delta R\, H N + O(\Delta R^3). Divide by 2ΔR2\Delta R and take the dot product with NN. For a quadratic VV the gradient is affine, so there are no remainder terms. □\square

So with ΔR\Delta R small the dimer measures HNH N with two gradients and never forms HH.

Lemma 2 (the rotation is exact for a quadratic). Let VV be quadratic with Hessian HH, let Θ\Theta be the unit vector of the part of F1−F2F_1 - F_2 that is perpendicular to NN (line L5), and let N(φ)=cos⁡φ N+sin⁡φ ΘN(\varphi) = \cos\varphi\, N + \sin\varphi\, \Theta. Then the curvature along N(φ)N(\varphi) is

C(φ)=12a0+a1cos⁡2φ+b1sin⁡2φ,C(\varphi) = \tfrac12 a_0 + a_1 \cos 2\varphi + b_1 \sin 2\varphi,

with a0=NTHN+ΘTHΘa_0 = N^{\mathsf T} H N + \Theta^{\mathsf T} H \Theta, a1=12(NTHN−ΘTHΘ)a_1 = \frac12 (N^{\mathsf T} H N - \Theta^{\mathsf T} H \Theta) and b1=ΘTHNb_1 = \Theta^{\mathsf T} H N. The three numbers are fixed by C(0)C(0), C′(0)=2b1C'(0) = 2 b_1 and one value C(φ1)C(\varphi_1) with cos⁡2φ1≠1\cos 2\varphi_1 \ne 1, and the angle of line L6 gives the minimum of CC over the plane of NN and Θ\Theta, which is the smaller eigenvalue of HH restricted to this plane.

Proof. By Lemma 1, C(φ)=N(φ)THN(φ)=cos⁡2φ NTHN+2sin⁡φcos⁡φ ΘTHN+sin⁡2φ ΘTHΘC(\varphi) = N(\varphi)^{\mathsf T} H N(\varphi) = \cos^2\varphi\, N^{\mathsf T} H N + 2 \sin\varphi \cos\varphi\, \Theta^{\mathsf T} H N + \sin^2\varphi\, \Theta^{\mathsf T} H \Theta, and the double angle formulas give the form above. Then C(0)=12a0+a1C(0) = \frac12 a_0 + a_1 and C′(0)=2b1C'(0) = 2 b_1. By Lemma 1, ΘTHN=−(F1−F2)⋅Θ/(2ΔR)\Theta^{\mathsf T} H N = -(F_1 - F_2) \cdot \Theta / (2\Delta R), which is the value of b1b_1 that the code uses. The value C(φ1)C(\varphi_1) gives a1(1−cos⁡2φ1)=C(0)−C(φ1)+b1sin⁡2φ1a_1 (1 - \cos 2\varphi_1) = C(0) - C(\varphi_1) + b_1 \sin 2\varphi_1, which is the formula of the code, and then a0=2(C(0)−a1)a_0 = 2(C(0) - a_1). Write a1cos⁡2φ+b1sin⁡2φ=ρcos⁡(2φ−2φ∗)a_1 \cos 2\varphi + b_1 \sin 2\varphi = \rho \cos(2\varphi - 2\varphi^*) with ρ=(a12+b12)1/2\rho = (a_1^2 + b_1^2)^{1/2} and 2φ∗=atan2⁡(b1,a1)2\varphi^* = \operatorname{atan2}(b_1, a_1). The maximum of CC is at φ∗\varphi^* and the minimum at φ∗+π/2\varphi^* + \pi/2, with the value 12a0−ρ\frac12 a_0 - \rho. The code computes φ∗\varphi^*, sees that C(φ∗)>C(0)C(\varphi^*) > C(0) unless ρ=0\rho = 0, and adds π/2\pi/2. The minimum of a Rayleigh quotient over the unit vectors of a plane is the smaller eigenvalue of the restriction. □\square

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 nn dimensions each rotation does not increase CC, and the rotational force F1−F2F_1 - F_2 minus its part along NN is zero exactly when HNH N is parallel to NN, so the fixed points of the rotation are the eigenvectors of HH. The minimum of the Rayleigh quotient over all unit vectors is the smallest eigenvalue λ1\lambda_1, and repeated rotations are a descent method for it. We do not prove that they converge to the eigenvector of λ1\lambda_1 from every start; they do if λ1\lambda_1 is simple and the start is not orthogonal to its eigenvector.

Lemma 3 (the fixed points of the translation). Let P=I−2NNTP = I - 2NN^{\mathsf T}. Where C<0C < 0, the force of line L9 is F†=PFF^{\dagger} = P F, and F†=0F^{\dagger} = 0 if and only if F=0F = 0.

Proof. F−2(F⋅N)N=PFF - 2(F \cdot N) N = P F, and PP is orthogonal (P2=IP^2 = I, P=PTP = P^{\mathsf T}), so ∣F†∣=∣F∣|F^{\dagger}| = |F|. □\square

So the stop test ∣∇V∣<tol|\nabla V| < \mathrm{tol} of line L8 is a test on ∣F†∣|F^{\dagger}|.

Theorem (local convergence to a first-order saddle). Let RsR_s be a first-order saddle: ∇V(Rs)=0\nabla V(R_s) = 0 and H(Rs)H(R_s) has eigenvalues λ1<0<λ2≤⋯≤λn\lambda_1 < 0 < \lambda_2 \le \cdots \le \lambda_n. Assume that NN is the unit eigenvector of λ1\lambda_1 at every step (exact rotation) and that VV is quadratic. Then the step R←R+hF†R \leftarrow R + h F^{\dagger} of line L10 converges to RsR_s from every start with C<0C < 0 if 0<h<2/max⁡(∣λ1∣,λn)0 < h < 2 / \max(|\lambda_1|, \lambda_n).

Proof. For a quadratic VV, F(R)=−H(R−Rs)F(R) = -H (R - R_s), so R−RsR - R_s changes by the matrix I−hPHI - h P H. With NN the eigenvector of λ1\lambda_1, PP and HH have the same eigenvectors, and PHP H has the eigenvalues −λ1=∣λ1∣,λ2,…,λn-\lambda_1 = |\lambda_1|, \lambda_2, \ldots, \lambda_n, all positive. The matrix I−hPHI - h P H has the eigenvalues 1−h∣λ1∣,1−hλ2,…1 - h|\lambda_1|, 1 - h\lambda_2, \ldots, all in (−1,1)(-1, 1) under the condition on hh. So R−Rs→0R - R_s \to 0 geometrically. ■\blacksquare

The inversion of the force along NN turns the saddle, which is not a minimum of VV, 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 VV that is not quadratic, the same argument holds near RsR_s 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 C≥0C \ge 0, the method moves along NN only, and nothing guarantees that it reaches a region with C<0C < 0: on the Muller-Brown surface many searches from the minimum A run away to the region where VV 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 1+2r1 + 2r gradients for rr rotations, plus O(rd)O(r d) arithmetic in the real RAM model. The memory is O(d)O(d). For atoms, the gradient costs GG (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 d×dd \times d Hessian, which is why it is used where dd 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 ±N\pm N.
  • 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 NN 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 ΔR\Delta R gives an error of O(ΔR2)O(\Delta R^2) in the curvature. A very small one gives rounding error: the error in F1−F2F_1 - F_2 is about ε∣F∣\varepsilon |F| for the machine epsilon ε\varepsilon, so the error in CC grows like ε∣F∣/ΔR\varepsilon |F| / \Delta R. Noisy forces, for example from an electronic structure code, make this much worse. Check that CC changes little when ΔR\Delta R 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 C<0C < 0; a small force with C>0C > 0 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.

dimer_method.pyI0RawGitHub
# 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

  1. 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
  2. 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
  3. 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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example