Algorithmadvanced
String method
Also called zero-temperature string method, simplified string method.
Moves a curve between two minima by the potential force and reparametrizes it by arc length, converging to the minimum energy path.
- 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 string; d = the number of coordinates
- Model
- Real RAM
- Properties
- deterministicnot exactiterativenot randomized
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Weinan E, Weiqing Ren, Eric Vanden Eijnden, 2002
The string method finds a minimum energy path (MEP) between two minima of a potential energy: the curve on which the gradient is parallel to the curve at every point, and whose highest point is a saddle. It represents the path by a list of points, the images, and repeats two steps: every image takes a step of steepest descent, then the images are redistributed along the curve through them so that they are equally spaced in arc length. The second step cancels any motion along the curve, so the curve moves only across itself, until it lies in the bottom of the channel between the minima. Unlike the nudged elastic band, it needs no springs and no projections of the force.
In plain words
Lay a chain of beads across the hills between two valleys. Let every bead roll downhill for a short time. Most beads roll partly along the chain, and they bunch up at the bottom of the valleys.
So after each roll, slide the beads back along the chain until they are evenly spaced again. The slide only moves beads along the chain, so it does not change where the chain lies. What is left of each roll is the part across the chain. The chain moves sideways until rolling downhill only pushes the beads along it. Then it lies on the lowest route from one valley to the other. The two end beads roll into the bottoms of the valleys.
The problem
The input is a potential with its gradient, two points near two minima, and the number of segments. The output is a string that approximates an MEP: a curve with along it, where is the part perpendicular to the tangent. The highest image approximates the saddle on the path. For atoms the coordinates are mass weighted if the masses differ; in the finite temperature version, the space is a set of collective variables.
The algorithm
STRING-METHOD(V, a, b, N, h, tol)- 1
φ_i ← a + (i/N)(b - a) for i = 0, ..., N - 2
repeat - 3
φ*_i ← φ_i - h ∇V(φ_i) for i = 0, ..., N ▷ evolve, the ends too - 4
s_0 ← 0, s_i ← s_{i-1} + |φ*_i - φ*_{i-1}|, α_i ← s_i / s_N - 5
φ_i ← the linear interpolation of the points (α_j, φ*_j) at α = i/N - 6
until max_i |φ_i (new) - φ_i (old)| / h < tol - 7
return φ_0, ..., φ_N
Line L3 moves every image by the full force , with a step ; any other ODE step works too. Line L4 computes the normalized arc length at each image of the evolved polygon. Line L5 puts the new images at equal arc length along this polygon. It is a linear interpolation, the simplest form of Lagrange interpolation; a cubic spline in is more accurate. The ends are not moved by line L5, so they do steepest descent on their own and fall into the two minima. Line L6 stops when the string no longer moves; the motion divided by is a force.
Example
A reparametrization by hand. Take the polygon with segment lengths and total length 5, so . With , the targets are and . The first lies on the second segment at the fraction , which is . The second lies on the third segment at , which is . The new points are , each apart along the polygon.
A path that is a circle. For in polar coordinates, the minima are , the saddles are with , and the MEP through is the upper half of the unit circle. A string started on , with , converges in about 85 iterations. The middle image is at to , with , by symmetry. The largest distance of an image from the circle is , and for . It falls roughly like , because the linear interpolation shifts the images to the inside of the bend.
The Muller-Brown surface. From to , with and , the ends stay at the two minima and the highest image is:
| iterations | highest image | there | |
|---|---|---|---|
| 8 | 120 | ||
| 16 | 134 | ||
| 32 | 121 |
The saddle is with . The straight line from A to C goes over a hill with , so the string moves far to find the path. The highest image approaches the saddle as grows; to locate the saddle exactly, interpolate along the string, or start a dimer search or a climbing image from the highest image.
Correctness
The proof below makes three points. First, lines L4 and L5 put the images at exactly equal arc lengths on the evolved polygon, and keep the ends. Second, a motion along the string does not change the string after the reparametrization, so only the perpendicular part of the force moves it. The iteration is a splitting scheme for the string equation of the 2002 paper, where the tangential term keeps the parametrization by arc length. Third, a curve is a stationary solution of this equation exactly when along it, which is the definition of an MEP: the two terms are orthogonal, so both must vanish. The converged discrete string has an error that depends on and on the interpolation, as the circle example shows. The proof does not show that the iteration converges or which MEP it finds.
Proof: What the simplified string method computesfull
We assume exact arithmetic and a potential with a Lipschitz continuous gradient. The string is ; one iteration is the evolution step of line L3 and the reparametrization of lines L4 and L5.
Lemma 1 (the reparametrization). Let be the polygon through the points , with total length . Lines L4 and L5 return the points , where is the point at arc length along . So , , every lies on , and the arc length along between and is for every .
Proof. Line L4 computes the arc length of at its vertex and , an increasing sequence from 0 to 1 (strictly increasing when consecutive points differ). For a target , line L5 finds with and returns with . On the segment from to , arc length is linear in , so this point has arc length .
Lemma 2 (the ends). The ends never change in line L5, so and each follow steepest descent on their own. If an end starts in the basin of a nondegenerate minimum and , where is the largest eigenvalue of the Hessian at , it converges to when it starts close enough to .
Proof. Near , the map is , and the eigenvalues of lie in .
The motion along the string does nothing. If the evolution step moves every image along only, the polygon does not change as a set, and by Lemma 1 the reparametrization returns the same equally spaced points. So, to first order in , only the part of perpendicular to the string changes the string. This is why the simplified method needs no projection of the force: the original string method of 2002 writes the motion as
with the unit tangent and a multiplier that keeps the parametrization by normalized arc length. The simplified method replaces by , because the difference is a tangential term that the reparametrization absorbs into . One iteration is a splitting step of this equation: an Euler step of , then the constraint.
Theorem (the stationary curves). Let , , be a smooth curve parametrized by normalized arc length with . It is a stationary solution of the equation above if and only if for all , that is, the gradient is parallel to the tangent at every point. This is the definition of a minimum energy path (MEP).
Proof. If , then . The first term is perpendicular to and the second is parallel, so both are zero, and . Conversely, if , the choice gives , and the arc length constraint holds because the curve does not move.
On an MEP, along the curve has , so changes monotonically between the stationary points on the curve; the highest point of an MEP between two minima is a stationary point of , a saddle.
The discrete string. The converged string of the algorithm is a fixed point of the discrete map, not an exact MEP. Its error has two sources: the points lie on chords of the curve, and the evolution step moves points along the string, which the linear interpolation turns into a small shift towards the inside of a bend. On the test potential , whose MEP is the unit circle, the largest distance from the circle is , and for with : the error falls roughly like . Interpolation with a cubic spline reduces it.
What is not proved. The theorem is about stationary curves. It does not show that the iteration converges, that it converges to the MEP closest to the start, or that the MEP has a single barrier. If an MEP passes through an intermediate minimum, the string passes through it as well.
Complexity
One iteration costs gradients and arithmetic for the arc lengths and the interpolation, in the real RAM model, and memory. The gradients are independent and run in parallel. The number of iterations is that of steepest descent on the perpendicular motion: the step must satisfy for the largest curvature, and the rate depends on the smallest curvature across the path. The reparametrization is cheap; with a cubic spline it is still .
Properties
- No springs. The spacing is set by the reparametrization, so there is no spring constant to choose and no interaction between the spacing and the force.
- Any parametrization. Equal arc length is one choice; a weight can put more images near the saddle, by targets that are not equally spaced.
- Simple to code. An existing steepest descent or ODE step for single images is reused; only the interpolation is new.
- Deterministic and local. The same start gives the same path, and the string finds an MEP near its start.
Variants and improvements
- The original string method. The 2002 method moves the images by the perpendicular force and then reparametrizes. The simplified method of 2007 uses the full force, which removes the need for a tangent in the evolution step.
- Higher order steps. The evolution step can be a Runge-Kutta step or another ODE solver, and the interpolation a cubic spline, which improves the accuracy of the converged string.
- Climbing string. The highest image moves by the force with the parallel component inverted, as in the climbing image of NEB, to converge to the saddle exactly.
- Finite temperature string method. In a space of collective variables, the images are averages over restrained molecular dynamics, and the string approximates a principal curve of the transition, with the free energy along it.
- Swarms of trajectories. This variant in collective variables moves each image by the mean drift of many short unbiased runs.
When to use it
Use the string method when both end states are known and you want the MEP, in the same setting as the nudged elastic band. It is simpler to add to an existing code, and it is the base of the finite temperature methods in collective variables, which have a free energy along the path. Use the dimer method when only the initial state is known, and transition path sampling when you need the dynamics of the transitions, not one path.
Pitfalls
- A step that is too large. As for steepest descent, makes the stiff directions oscillate. On Muller-Brown, at the minimum A, so .
- Too few images. A coarse string cuts corners and its highest image is below the saddle, by 3.7 for in the table.
- Ends that are not minima. If the ends start on the far side of a ridge, they fall into other minima, and the string joins the wrong states.
- Intermediate minima. If the MEP passes through another minimum, the string goes through it, and the highest image is the highest of the barriers on the way.
- The interpolation error. Linear interpolation shifts the images to the inside of a bend by an amount that falls only like in the example; use a spline when the path bends strongly.
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/string-method/. The authors are listed in prov/SDPAV5.jsonl.
"""The simplified zero-temperature string method (E, Ren and Vanden-Eijnden 2007).
A string is a list of N + 1 images phi_0, ..., phi_N. One iteration has
two steps:
1. evolve: each image takes one step of steepest descent,
phi_i <- phi_i - h grad V(phi_i). The ends fall into the minima.
2. reparametrize: the images are moved along the piecewise linear curve
through the new images, so that the arc lengths between neighbours
are equal.
The second step removes the component of the motion along the string, so
the string moves only by the perpendicular part of the force, as in the
original method of 2002, without any projection. A fixed point is a
string on which the gradient is parallel to the string (up to the error
of the discretization): a minimum energy path.
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 arc_lengths(images: Sequence[Sequence[float]]) -> list[float]:
"""The normalized arc length alpha_i in [0, 1] at each image."""
s = [0.0]
for a, b in zip(images, images[1:]):
s.append(s[-1] + math.dist(a, b)) # @line L4
total = s[-1]
return [v / total for v in s]
def reparametrize(images: Sequence[Sequence[float]]) -> list[Point]:
"""Points at equal arc length along the polygon through the images."""
n = len(images) - 1
alpha = arc_lengths(images)
out = [list(images[0])]
j = 1
for i in range(1, n):
target = i / n
while alpha[j] < target:
j += 1
w = (target - alpha[j - 1]) / (alpha[j] - alpha[j - 1]) # @line L5
out.append([(1.0 - w) * a + w * b for a, b in zip(images[j - 1], images[j])])
out.append(list(images[n]))
return out
def string_method(potential: Potential, r_start: Sequence[float], r_end: Sequence[float],
n: int, h: float, tol: float, max_iter: int = 10000,
images: Sequence[Sequence[float]] = None):
"""Evolve a string of n + 1 images to a minimum energy path.
The start string is the straight line from r_start to r_end, or the
given images. The iteration stops when no image moves by more than
h * tol in one iteration (the motion divided by h is a force).
Returns (images, energies, iterations, converged).
"""
if images is None:
phi = [[a + (i / n) * (b - a) for a, b in zip(r_start, r_end)] # @line L1
for i in range(n + 1)]
else:
phi = [list(p) for p in images]
for it in range(max_iter): # @line L2
moved = []
for p in phi:
g = potential(p)[1]
moved.append([c - h * gc for c, gc in zip(p, g)]) # @line L3
new = reparametrize(moved) # @line L5
change = max(math.dist(a, b) for a, b in zip(new, phi)) / h # @line L6
phi = new
if change < tol: # @line L6
return phi, [potential(p)[0] for p in phi], it + 1, True
return phi, [potential(p)[0] for p in phi], max_iter, False # @line L7
def perpendicular_gradient(potential: Potential, images: Sequence[Sequence[float]]) -> list[float]:
"""|grad V - (grad V . t) t| at each inner image, with the central tangent t."""
out = []
for i in range(1, len(images) - 1):
t = [b - a for a, b in zip(images[i - 1], images[i + 1])]
nt = math.sqrt(sum(c * c for c in t))
t = [c / nt for c in t]
g = potential(images[i])[1]
gp = sum(a * b for a, b in zip(g, t))
out.append(math.sqrt(sum((a - gp * b) ** 2 for a, b in zip(g, t))))
return out
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_string_method.py 72 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/string-method/. The authors are listed in prov/SDPAV5.jsonl.
import math
import pytest
from string_method import arc_lengths, muller_brown, reparametrize, string_method
A = [-0.55822, 1.44173]
C = [-0.05001, 0.46669]
S1 = (-0.82200, 0.62431, -40.6648)
def ring(p):
# V = 4 (r - 1)^2 + sin(theta)^2: minima (1, 0) and (-1, 0), saddles (0, 1) and (0, -1)
# with V = 1, and the minimum energy path is the unit circle.
x, y = p
r = math.hypot(x, y)
th = math.atan2(y, x)
dvdr = 8.0 * (r - 1.0)
dvdth = 2.0 * math.sin(th) * math.cos(th)
v = 4.0 * (r - 1.0) ** 2 + math.sin(th) ** 2
return v, [dvdr * x / r - dvdth * y / (r * r), dvdr * y / r + dvdth * x / (r * r)]
def test_reparametrize_by_hand():
poly = [[0.0, 0.0], [1.0, 0.0], [1.0, 2.0], [3.0, 2.0]]
assert arc_lengths(poly) == pytest.approx([0.0, 0.2, 0.6, 1.0])
out = reparametrize(poly)
assert out[0] == [0.0, 0.0] and out[3] == [3.0, 2.0]
assert out[1] == pytest.approx([1.0, 2.0 / 3.0])
assert out[2] == pytest.approx([4.0 / 3.0, 2.0])
gaps = [math.dist(a, b) for a, b in zip(poly, poly[1:])]
assert sum(gaps) == pytest.approx(5.0)
def ring_string(n):
init = [[1.0 - 2.0 * i / n, 0.8 * math.sin(math.pi * i / n)] for i in range(n + 1)]
return string_method(ring, None, None, n, h=0.02, tol=1e-6, images=init)
def test_ring_string_goes_to_the_circle():
errors = []
for n in (8, 32):
phi, en, it, ok = ring_string(n)
assert ok and it < 200
j = max(range(n + 1), key=lambda i: en[i])
assert j == n // 2
assert phi[j] == pytest.approx([0.0, 1.0], abs=1e-6)
assert en[j] == pytest.approx(1.0, abs=1e-9)
# The arc lengths are equal along the polygon before the last
# reparametrization; along the new polygon they are nearly equal.
gaps = [math.dist(a, b) for a, b in zip(phi, phi[1:])]
assert max(gaps) - min(gaps) < 0.01 * min(gaps)
errors.append(max(abs(math.hypot(*p) - 1.0) for p in phi))
assert errors[0] < 0.025 and errors[1] < 0.004
assert errors[1] < errors[0] / 4.0
def test_muller_brown_string():
tops = []
for n in (8, 32):
phi, en, it, ok = string_method(muller_brown, A, C, n, h=2e-4, tol=1e-2)
assert ok and it < 1000
# The ends do steepest descent on their own and stay in the minima.
assert phi[0] == pytest.approx(A, abs=1e-4)
assert phi[-1] == pytest.approx(C, abs=1e-4)
j = max(range(n + 1), key=lambda i: en[i])
tops.append((en[j], phi[j]))
assert tops[0][0] < S1[2] - 3.0
assert tops[1][0] == pytest.approx(S1[2], abs=2e-3)
assert tops[1][1] == pytest.approx(list(S1[:2]), abs=2e-3)
History
E, Ren and Vanden-Eijnden introduced the string method in 2002, as a method that evolves a curve by the perpendicular force and keeps its parametrization by an explicit reparametrization step instead of springs. In 2007 they gave the simplified and improved string method, which moves the images by the full force before the reparametrization. The same authors developed the finite temperature string method for transitions in collective variables.
References
- Weinan E, Weiqing Ren and Eric Vanden-Eijnden, String method for the study of rare events, Physical Review B 66(5), 2002, 052301, the evolution of the string by the perpendicular force and the reparametrization by arc length
- Weinan E, Weiqing Ren and Eric Vanden-Eijnden, Simplified and improved string method for computing the minimum energy paths in barrier-crossing events, Journal of Chemical Physics 126(16), 2007, 164103, the simplified method, with the full force followed by the reparametrization, and the interpolation step
- 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 SDPAV5 Edit this page History Report an error Markdown