Algorithmadvanced
Iterative Boltzmann inversion
Fits a coarse-grained pair potential to a target radial distribution function, by adding kT ln(g/g_target) to the potential after each simulation until g matches.
- Time
- O(I (S + M)) worst
- Space
- O(M) extra
- Where
- I = the number of iterations; M = the number of grid points of the potential; S = the cost of one simulation with its histogram
- Model
- Real RAM
- Properties
- deterministicnot exactiterativenot randomized
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Dirk Reith, Mathias Putz, Florian Muller Plathe, 2003
Iterative Boltzmann inversion (IBI) builds a pair potential for coarse-grained beads, so that a simulation of the beads reproduces a target radial distribution function , usually the one of the beads mapped from an atomistic simulation. It starts from the potential of mean force , runs a simulation with the current potential, and corrects the potential at each distance by : where the beads are found too often, the potential goes up. It stops when the simulated agrees with the target. Each iteration costs one simulation. Henderson's theorem says that the answer, if it exists, is unique up to a constant, but no theorem says that the iteration converges.
In plain words
You have a detailed simulation of a liquid, and you want a simple model in which each molecule is one ball. You measure how often two molecules sit at each distance in the detailed run. Now you guess a force law for the balls and run the simple model.
At distances where the balls meet more often than the molecules did, you make the balls repel a bit more. Where they meet less often, you make them repel less. You run the simple model again and repeat. The size of each correction comes from the ratio of the two counts. When the counts match at every distance, you stop. You then have a force law that gives the right structure, but not always the right pressure.
The problem
The input is a target on a grid up to a cutoff , the temperature (with ), the density of the beads, and a simulator: a function that takes a tabulated pair potential and returns the radial distribution function of an equilibrium run with it, in the canonical ensemble at the same and . The output is a potential with to a tolerance. The beads interact only by the pair potential; three-body terms are outside the model, so a target from a system with many-body forces can be matched in , but other properties then need not match.
Two facts frame the problem. First, is the pair potential of mean force: the free energy of two beads at distance , averaged over all others. In the limit , , so . At finite density, with the cavity function , so . Second, by Henderson's theorem (1974), for a fluid of pairwise additive particles at fixed and , two pair potentials with the same differ only by a constant. So the problem has at most one solution with .
The algorithm
ITERATIVE-BOLTZMANN-INVERSION(g*, SIMULATE, k_B T, α, tol)- 1
V(r) ← -k_B T ln g*(r) at each grid point ▷ the potential of mean force - 2
repeat - 3
g ← SIMULATE(V) ▷ MD or MC with V, then a histogram of pair distances - 4
if max_r |g(r) - g*(r)| < tol then return V - 5
for each grid point r with g(r) > 0 and g*(r) > 0 - 6
V(r) ← V(r) + α k_B T ln(g(r) / g*(r)) - 7
return V ▷ the iteration budget is spent
Line L1 is plain Boltzmann inversion. It is exact at zero density and a good start at moderate density. Line L3 is the expensive step: an equilibrium simulation, long enough that the histogram noise in is below the corrections that line L6 makes. Line L6 is the update of Reith, Putz and Muller-Plathe (2003) with ; a factor damps it. Line L5 skips the points where a logarithm is not defined: inside the core, where no pair is seen, the potential keeps its start value (in practice it is extrapolated from the points outside).
Example
One step by hand. The implementation has a closed form simulator for tests: a one-dimensional fluid of density to first order in , with , where is the Mayer function and is the convolution on the line. This is the density expansion of the cavity function, cut after the first term; it is a model of a simulator, not a simulation. Take , , a grid with from to (81 points), and the true potential , a soft core with a well near . The target has . Line L1 gives , below the true , because the neighbors push pairs together and raise above . The simulator with gives , more than the target, so line L6 raises the potential: . Over the whole grid, the largest error of the potential falls from for to for .
Convergence. On the same problem, the largest error in the iterations is
| 0 | 1 | 2 | 3 | 4 | 5 | 10 | 16 | |
|---|---|---|---|---|---|---|---|---|
so the error falls by a factor of about per iteration, and after 17 simulations the potential matches to . At the factor is about and 37 simulations are needed; with the damping at , 45 are needed. In the dilute model , line L1 is already exact and the loop stops after one simulation. These are measurements on a model, without the noise of a real simulation.
Correctness
The proof in the proofs file shows three things. First, a returned potential satisfies the stop test of line L4, and a fixed point of line L6 with is exactly a potential with at every updated grid point. By Henderson's theorem, if the simulator is exact and the target comes from a pair potential at the same state, this fixed point is that potential up to a constant. Second, in the dilute limit , line L1 is the exact answer. Third, the update is a Newton step for the equation with the Jacobian , which is the exact Jacobian at zero density. So IBI is a quasi-Newton method whose Jacobian is right in the dilute limit and wrong by terms of order at finite density. This explains the fast convergence in the example and the rate that grows with , but it is a heuristic, not a proof: there is no general convergence theorem for IBI, and with a noisy simulator the iteration converges at best to a neighborhood of the answer whose size is set by the noise.
Proof: Fixed points of iterative Boltzmann inversion, the dilute limit and the quasi-Newton formfull
The grid is . A simulator is a map from a tabulated potential to a function on the grid, , the target is , and . We assume exact arithmetic and an exact (noise free) simulator. Let be the set of grid points where , and assume that on for the potentials that occur, so that line L5 updates exactly the points of .
Lemma 1 (what is returned). If the procedure returns at line L4, then for the returned .
Proof. Line L4 returns only after line L3 has computed for this and the test has held. Nothing changes between line L3 and the return.
Lemma 2 (fixed points). A potential is left unchanged by lines L5 and L6 if and only if at every point of .
Proof. Line L6 changes by at each . Since , the change is zero if and only if , that is . Points outside are never changed.
Corollary (uniqueness). Let the simulator be exact for a fluid of particles with pairwise additive interactions, in the canonical ensemble at the density and temperature of the target, and let for a pair potential . By Henderson's theorem (1974), two pair potentials with the same pair correlation function at the same density and temperature differ by a constant. So a fixed point of Lemma 2 with the whole grid equals , and if both potentials vanish at the cutoff. The corollary uses Henderson's theorem as stated in the source; it is not proved here.
Lemma 3 (the dilute limit). If for every , then line L1 gives a fixed point at once: on , and the loop returns after one simulation for any .
Proof. Line L1 sets on , so , and the test of line L4 holds with error .
Lemma 4 (the quasi-Newton form). Write , with the cavity function . Consider the equation on . Its Jacobian is , where . The update of line L6 is exactly the step with , the Jacobian of the dilute limit, where .
Proof. , so . With , , which is the change of line L6.
So IBI is a quasi-Newton iteration with a fixed approximate Jacobian. Near a solution the error map has the linear part , and the iteration converges locally if the spectral radius of this matrix is less than . For it is the spectral radius of , which tends to with the density for a smooth exact simulator, because for every as . This gives local convergence at low enough density. There is no general bound on the spectral radius at liquid densities, so global convergence is not claimed.
Theorem. With an exact simulator, a returned potential reproduces the target to the tolerance (Lemma 1). A limit of the iteration reproduces it exactly on (Lemma 2), and it is the true pair potential up to a constant under the hypotheses of Henderson's theorem (corollary). In the dilute limit the first inversion is exact (Lemma 3). The update is the quasi-Newton step of Lemma 4.
Proof. Lemmas 1 to 4 and the corollary.
Complexity
Each iteration runs one simulation and one update of grid points, so the cost is in the real RAM model, with memory beyond the simulation. The simulation dominates by far: a run of beads for many steps, with a cutoff and a linked cell list, costs per step. The number of iterations depends on the density and on the noise, and no bound on it is known. The coarse-grained run is much cheaper than the atomistic run that produced the target, because the beads are fewer and softer and allow a longer time step.
Properties
- Structure-based. IBI matches , a structural target. It does not match forces, as force matching does, and it does not use the atomistic forces at all.
- Unique target, uncertain path (theorem and heuristic). The solution is unique up to a constant by Henderson's theorem. Convergence of the iteration is not proved.
- State dependent. The potential depends on the density and temperature of the target, because it absorbs the effect of the removed degrees of freedom; it is a free energy, not an energy.
- Pressure. A potential that gives the right can give the wrong pressure, because the pressure comes from weighted by , and small changes of at large change the pressure much and little.
- Several interactions. With bonds, angles and nonbonded pairs, each distribution has its own update, and the updates are done one after the other or together.
Variants and improvements
- Damping and smoothing. A factor in line L6 and a smoothing of the update reduce oscillations and the effect of noise.
- Pressure correction. A common correction adds a small linear term to the potential, with the sign of chosen to move the pressure toward the target. This is a heuristic; the amplitude is a choice.
- Inverse Monte Carlo. The inverse Monte Carlo method of Lyubartsev and Laaksonen (1995) uses the cross correlations of the histogram from the same simulation as the full Jacobian of with respect to . It is a Newton method with the right Jacobian, at the cost of more statistics per iteration.
- Relative entropy and force matching. Other ways to fit a coarse-grained model minimize the relative entropy between the mapped and coarse-grained distributions, or fit the mean forces by least squares (force matching). The Mori-Zwanzig formalism explains what all of them leave out: the memory and the noise of the removed variables.
When to use it
Use IBI when the target is structural, for example to build a bead model of a polymer melt or of a liquid that keeps the packing of the atomistic model, and when the atomistic forces are not at hand or too noisy. Use force matching when the atomistic forces are available and many-body effects matter, since it needs one least squares solve in place of many simulations. Neither gives the right dynamics; for that, add friction and noise, as in dissipative particle dynamics.
Pitfalls
- The sign of the update. Writing line L6 as drives the potential away from the answer: where it lowers and draws more pairs to that distance. The right line is .
- The core region. Where no pair is seen, and the logarithm is undefined. Line L5 must skip these points, and the potential there must stay repulsive; extrapolate it from the first points with good statistics.
- Noise. Histogram noise in goes straight into through the logarithm. Run each simulation long enough, smooth the update, and stop when the change is below the noise, not at a tolerance the data cannot reach.
- An approximate simulator. Henderson's theorem holds for the exact of a fluid. In the example simulator, which is not a real fluid, at IBI converged to a potential that differs from by up to but gives the same to . A short or biased simulation can do the same.
- Transfer to another state. The potential is fitted at one density and temperature. Using it at another state point without a check is a common source of error.
- The constant and the cutoff. The potential is unique only up to a constant; fix and make the potential and its derivative go to zero at .
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/iterative-boltzmann-inversion/. The authors are listed in prov/JKHDRS.jsonl.
"""Iterative Boltzmann inversion (Reith, Putz and Muller-Plathe 2003).
IBI fits a pair potential V(r) on a grid r_0, ..., r_(M-1) so that a
simulation with V gives a target radial distribution function g*(r).
It starts from the Boltzmann inversion V_0 = -kT ln g* and repeats
V_(i+1)(r) = V_i(r) + alpha kT ln(g_i(r) / g*(r)),
where g_i is the g(r) of a simulation with V_i. A point where g* or g_i
is below g_min is not updated, because the logarithm is not defined or
is pure noise there; the start value there is -kT ln g_min.
The simulator is a function V -> g on the same grid. A real one is a
molecular dynamics or Monte Carlo run with a histogram of pair
distances. For tests, this file gives two closed forms:
- dilute_g: the low density limit g(r) = exp(-V(r) / kT).
- virial_g_1d: a one-dimensional fluid of density rho to first order in
rho, g(r) = exp(-V(r)/kT) (1 + rho (f * f)(r)) with the Mayer function
f = exp(-V/kT) - 1 and the convolution on the line. This is the
density expansion of the cavity function y(r) = g(r) exp(V(r)/kT)
truncated after the first term.
"""
import math
from typing import Callable, Sequence
Simulator = Callable[[Sequence[float]], list[float]]
def dilute_g(kt: float) -> Simulator:
"""The simulator g = exp(-V / kT) of a dilute gas."""
def simulate(v):
return [math.exp(-x / kt) for x in v]
return simulate
def virial_g_1d(kt: float, rho: float, dr: float) -> Simulator:
"""The simulator g = exp(-V/kT) (1 + rho (f * f)) of a 1D fluid, first order in rho.
The grid is r_k = k dr, k = 0..M-1, and V = 0 beyond the grid.
"""
def simulate(v):
m = len(v)
f = [math.exp(-x / kt) - 1.0 for x in v]
g = []
for k in range(m):
conv = 0.0
for j in range(k - m + 1, m): # both |j| and |k - j| stay below m
conv += f[abs(j)] * f[abs(k - j)]
g.append(math.exp(-v[k] / kt) * (1.0 + rho * dr * conv))
return g
return simulate
def iterative_boltzmann_inversion(g_target: Sequence[float], simulate: Simulator, kt: float,
tol: float = 1e-10, max_iter: int = 100, alpha: float = 1.0,
g_min: float = 1e-8) -> tuple[list[float], list[float]]:
"""Return the potential V on the grid and the list of max |g_i - g*| per iteration."""
v = [-kt * math.log(max(g, g_min)) for g in g_target] # @line L1
errors = []
for _ in range(max_iter): # @line L2
g = simulate(v) # @line L3
err = max(abs(a - b) for a, b in zip(g, g_target))
errors.append(err)
if err < tol: # @line L4
return v, errors
for k in range(len(v)): # @line L5
if g[k] > g_min and g_target[k] > g_min:
v[k] += alpha * kt * math.log(g[k] / g_target[k]) # @line L6
return v, errors # @line L7
test_iterative_boltzmann_inversion.py 82 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/iterative-boltzmann-inversion/. The authors are listed in prov/JKHDRS.jsonl.
import math
import random
import pytest
from iterative_boltzmann_inversion import dilute_g, iterative_boltzmann_inversion, virial_g_1d
DR = 0.05
M = 81
R = [k * DR for k in range(M)]
def soft(a, b, c=1.5, w=4.0):
return [a * math.exp(-x * x) - b * math.exp(-w * (x - c) ** 2) for x in R]
def test_dilute_gas_is_solved_by_the_first_inversion():
v_true = soft(2.0, 0.5)
sim = dilute_g(1.0)
v, errors = iterative_boltzmann_inversion(sim(v_true), sim, 1.0)
assert errors == [0.0]
assert max(abs(a - b) for a, b in zip(v, v_true)) < 1e-12
def test_one_update_step_by_hand():
v_true = soft(2.0, 0.5)
sim = virial_g_1d(1.0, 0.1, DR)
g_star = sim(v_true)
v1, errors = iterative_boltzmann_inversion(g_star, sim, 1.0, max_iter=1)
v0 = [-math.log(g) for g in g_star]
g0 = sim(v0)
assert len(errors) == 1
for k in range(M):
assert v1[k] == pytest.approx(v0[k] + math.log(g0[k] / g_star[k]), abs=1e-14)
assert v0[0] == pytest.approx(1.878199, abs=1e-6)
assert v1[0] == pytest.approx(1.992859, abs=1e-6)
def test_virial_fluid_converges_geometrically_to_the_true_potential():
v_true = soft(2.0, 0.5)
sim = virial_g_1d(1.0, 0.1, DR)
v, errors = iterative_boltzmann_inversion(sim(v_true), sim, 1.0, tol=1e-10)
assert len(errors) == 17
assert max(abs(a - b) for a, b in zip(v, v_true)) < 1e-9
ratios = [errors[i + 1] / errors[i] for i in range(len(errors) - 1)]
assert all(q < 0.35 for q in ratios)
def test_damping_slows_but_keeps_convergence():
v_true = soft(2.0, 0.5)
sim = virial_g_1d(1.0, 0.1, DR)
g_star = sim(v_true)
_, full = iterative_boltzmann_inversion(g_star, sim, 1.0, tol=1e-10)
v, half = iterative_boltzmann_inversion(g_star, sim, 1.0, tol=1e-10, alpha=0.5, max_iter=200)
assert len(half) > len(full)
assert half[-1] < 1e-10
assert max(abs(a - b) for a, b in zip(v, v_true)) < 1e-8
@pytest.mark.parametrize("seed", range(5))
def test_random_soft_potentials_are_recovered(seed):
rng = random.Random(seed)
kt = rng.uniform(0.8, 1.5)
v_true = soft(rng.uniform(0.5, 3.0), rng.uniform(0.0, 0.8), rng.uniform(1.0, 2.0), rng.uniform(2.0, 6.0))
sim = virial_g_1d(kt, rng.uniform(0.02, 0.1), DR)
v, errors = iterative_boltzmann_inversion(sim(v_true), sim, kt, tol=1e-11)
assert errors[-1] < 1e-11
assert max(abs(a - b) for a, b in zip(v, v_true)) < 1e-8
def test_points_with_zero_target_are_not_updated():
v_true = [50.0 if x < 0.5 else y for x, y in zip(R, soft(2.0, 0.5))]
sim = dilute_g(1.0)
g_star = sim(v_true)
v, errors = iterative_boltzmann_inversion(g_star, sim, 1.0, tol=1e-6)
for k in range(M):
if R[k] < 0.5:
assert v[k] == pytest.approx(-math.log(1e-8))
else:
assert v[k] == pytest.approx(v_true[k], abs=1e-12)
History
Boltzmann inversion of a distribution function into a potential of mean force is old in liquid state theory. Henderson proved in 1974 that a pair potential is fixed by its at a given density and temperature, up to a constant. Reith, Putz and Muller-Plathe turned the inversion into an iteration in 2003 and used it to derive mesoscale potentials for polymers from atomistic simulations, for bonded and nonbonded interactions. It became one of the standard structure-based coarse-graining methods, next to inverse Monte Carlo and force matching.
References
- Dirk Reith, Mathias Putz and Florian Muller-Plathe, Deriving effective mesoscale potentials from atomistic simulations, Journal of Computational Chemistry 24(13), 2003, 1624-1636, the iterative update of the potential from the ratio of the distribution functions, for bonded and nonbonded coarse-grained interactions
- R. L. Henderson, A uniqueness theorem for fluid pair correlation functions, Physics Letters A 49(3), 1974, 197-198, the theorem that at fixed density and temperature a pair potential is fixed by g(r) up to a constant
- Michael P. Allen and Dominic J. Tildesley, Computer Simulation of Liquids, second edition, Oxford University Press, 2017, Section 2.6 (the radial distribution function and its estimate from a histogram)
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 JKHDRS Edit this page History Report an error Markdown