Algorithm Search⌘K

Algorithmcore

Umbrella sampling

Adds biasing potentials that restrain a collective variable in overlapping windows so rare regions are sampled, and removes the bias afterwards.

Time
O(K n + K B) worst
Space
O(K B) extra
Where
B = the number of histogram bins; K = the number of windows; n = the number of samples per window
Properties
consistentrandomizednot iterativeparallelrandomizednot unbiased
Origin
Glenn M. Torrie, John P. Valleau, 1977

Umbrella sampling computes the free energy profile F(s)=−kBTln⁡p(s)F(s) = -k_B T \ln p(s) along a collective variable s(x)s(x) when ordinary sampling never crosses the barriers between the low regions of FF. It runs KK separate simulations, called windows. Window kk adds a bias wk(s)w_k(s), usually a harmonic spring κ2(s−sk)2\frac{\kappa}{2}(s - s_k)^2, that holds ss near the centre sks_k, so each window samples a narrow range of ss, including the high-energy ones. In each window the bias is known exactly, so it can be removed from the window histogram, which leaves FF on that range up to an unknown constant. The constants come from the overlap of neighbouring windows. This page uses a simple join of neighbours; the weighted histogram analysis method (WHAM) is the standard way to combine all windows at once. It is a form of importance sampling with a chosen, non-physical sampling distribution (Torrie and Valleau 1977).

In plain words

Some molecular events, such as a bond breaking or a protein changing shape, need the system to climb over a high hill of energy. An ordinary simulation stays in a valley and almost never makes that climb.

Umbrella sampling puts a spring on the system that holds one chosen quantity near a chosen value. One simulation is held at the bottom of the valley, the next a little higher up the hill, and so on over the top. Each simulation sees only its own small piece of the hill.

The spring changes what each simulation sees, but its effect is known exactly, so it can be taken away afterwards. The pieces overlap, which tells us how to fit them together into the full shape of the hill.

The problem

The input is a potential U(x)U(x), a collective variable s(x)s(x), the inverse temperature β=1/(kBT)\beta = 1/(k_B T), window centres s1<⋯<sKs_1 < \dots < s_K, a spring constant κ\kappa, and bins on an interval of ss. The target is the free energy profile

F(s)=−β−1ln⁡p(s)+const,p(s)=1Z∫δ(s(x)−s) e−βU(x) dx,F(s) = -\beta^{-1} \ln p(s) + \text{const}, \qquad p(s) = \frac{1}{Z} \int \delta(s(x) - s)\, e^{-\beta U(x)}\,dx,

on the bins. In window kk the sampled density is proportional to e−β(U(x)+wk(s(x)))e^{-\beta (U(x) + w_k(s(x)))}, and its marginal in ss is p(s) e−βwk(s)p(s)\, e^{-\beta w_k(s)} up to a constant factor, so

F(s)=−β−1ln⁡pkbiased(s)−wk(s)+ckF(s) = -\beta^{-1} \ln p_k^{\text{biased}}(s) - w_k(s) + c_k

with one unknown constant ckc_k per window (Claim 1 of the proof).

The algorithm

  1. UMBRELLA(U, s_1..s_K, kappa, beta, bins)
  2. 1for k ← 1 to K do ▷ the windows are independent
  3. 2sample x from exp(-beta (U(x) + kappa/2 (s(x) - s_k)^2)), by Monte Carlo or MD
  4. 3n_k(b) ← number of samples with s(x) in bin b
  5. 4F_k(b) ← -ln(n_k(b)) / beta - w_k(centre of b) on bins with enough counts
  6. 5F ← F_1
  7. 6for k ← 2 to K do c ← mean of F(b) - F_k(b) over the bins defined in both
  8. 7merge F_k + c into F, as a count-weighted mean on shared bins
  9. 8return F - min F

Lines L1 to L4 are the sampling; the KK windows can run in parallel. Line L4 uses only bins with enough samples (50 in the code here), because −ln⁡n-\ln n of a small count is noisy and biased. Lines L5 to L7 fix the constants: each new window is shifted to agree on average with the profile so far on the bins they share. Line L8 sets the lowest point to 0, since FF is defined only up to a constant.

The spacing of the windows must let each pair of neighbours share several well-sampled bins. With a harmonic bias the width of window kk is about 1/β(κ+F′′(sk))1/\sqrt{\beta(\kappa + F''(s_k))} when κ+F′′>0\kappa + F'' > 0, so a spacing of one or two such widths is usual.

Example

Take the double well U(x)=8(x2−1)2U(x) = 8(x^2 - 1)^2 with s=xs = x and kBT=1k_B T = 1, so the exact profile is F=UF = U, with minima at ±1\pm 1 and a barrier of 8 kBT8\,k_B T at 0. A plain Metropolis chain started at x=−1x = -1 with step 0.3 did not reach x>0x > 0 once in 50000 steps.

With 17 windows centred at −1.6,−1.4,…,1.6-1.6, -1.4, \dots, 1.6, κ=50\kappa = 50, 20000 Metropolis samples per window with step 0.3 and 32 bins on [−1.6,1.6][-1.6, 1.6] (seed 1):

quantity umbrella sampling exact at the bin centres
barrier, F(0.05)−F(0.95)F(0.05) - F(0.95) 7.787 7.884
asymmetry, F(−0.95)−F(0.95)F(-0.95) - F(0.95) −0.195-0.195 0
largest error on bins with U<9U < 9 0.263

The barrier is within 0.1 kBT0.1\,k_B T. The asymmetry error comes from the 16 joins: each shift has a small error, and these errors add up from the left end to the right end. Other seeds gave barrier errors below 0.10.1 and asymmetry errors from 0.1 to 0.25. With only 3000 samples per window and a count threshold of 10, the largest error was 0.247, so the join and the bin width, not the number of samples, limit the result here.

Correctness

The proof in proofs/correctness.md shows:

  1. Unbiasing a window. The marginal of ss in window kk is p(s)e−βwk(s)p(s) e^{-\beta w_k(s)} up to a constant, so −β−1ln⁡pkbiased−wk-\beta^{-1} \ln p_k^{\text{biased}} - w_k equals FF up to a constant, for every bias wkw_k that depends on xx only through ss.
  2. Consistency of one window. As the number of samples grows, line L4 converges to FF averaged over the bin, up to a constant, with a bin error at most the variation of wkw_k across the bin.
  3. The join. If each window profile is exact up to its constant on the shared bins, lines L5 to L8 return FF exactly up to a global constant; with errors in the windows, the error of the joined profile is bounded by a sum of window errors along the chain of joins.
Proof: Unbiasing of a window, the bin error, and the join of the windowsfull

Let U(x)U(x) be a potential with Z=∫e−βU dxZ = \int e^{-\beta U}\,dx finite and positive, s(x)s(x) a measurable collective variable, and p(s)p(s) the density of s(x)s(x) when xx has density e−βU/Ze^{-\beta U} / Z; assume pp is continuous and positive on the interval of interest. Define F(s)=−β−1ln⁡p(s)F(s) = -\beta^{-1} \ln p(s). Window kk samples the density proportional to e−β(U(x)+wk(s(x)))e^{-\beta (U(x) + w_k(s(x)))}, where wkw_k is continuous and Zk=∫e−β(U+wk(s)) dxZ_k = \int e^{-\beta(U + w_k(s))}\,dx is finite.

Claim 1 (unbiasing a window). The density of ss in window kk is pk(s)=(Z/Zk) p(s) e−βwk(s)p_k(s) = (Z / Z_k)\, p(s)\, e^{-\beta w_k(s)}. Hence

F(s)=−β−1ln⁡pk(s)−wk(s)+ck,ck=β−1ln⁡(Z/Zk),F(s) = -\beta^{-1} \ln p_k(s) - w_k(s) + c_k, \qquad c_k = \beta^{-1} \ln(Z / Z_k),

with ckc_k independent of ss.

Proof. For a bounded measurable gg, Ek[g(s(x))]=Zk−1∫g(s(x)) e−βwk(s(x))e−βU(x) dx=(Z/Zk) E[g(s(x)) e−βwk(s(x))]=(Z/Zk)∫g(s) e−βwk(s)p(s) dsE_k[g(s(x))] = Z_k^{-1} \int g(s(x))\, e^{-\beta w_k(s(x))} e^{-\beta U(x)}\,dx = (Z / Z_k)\, E[g(s(x))\, e^{-\beta w_k(s(x))}] = (Z / Z_k) \int g(s)\, e^{-\beta w_k(s)} p(s)\,ds. So pk(s)=(Z/Zk) p(s)e−βwk(s)p_k(s) = (Z/Z_k)\, p(s) e^{-\beta w_k(s)}. Take −β−1ln⁡-\beta^{-1} \ln of both sides and rearrange. □\square

The proof uses only that the bias depends on xx through s(x)s(x). A bias on another variable would change the conditional distribution of xx given ss, and the identity would fail.

Claim 2 (one window, many samples). Let bin bb be an interval IbI_b with centre mbm_b and half-width hh, and define the bin free energy Fb=−β−1ln⁡∫Ibp(s) dsF_b = -\beta^{-1} \ln \int_{I_b} p(s)\,ds. Let δk(b)=max⁡s∈Ib∣wk(s)−wk(mb)∣\delta_k(b) = \max_{s \in I_b} |w_k(s) - w_k(m_b)|. If the samples of window kk come from an ergodic chain with stationary density pkp_k, then with probability 1, as n→∞n \to \infty,

−β−1ln⁡nk(b)n−wk(mb)→Fb−ck+ek(b),∣ek(b)∣≤δk(b).-\beta^{-1} \ln \frac{n_k(b)}{n} - w_k(m_b) \to F_b - c_k + e_k(b), \qquad |e_k(b)| \le \delta_k(b).

For the harmonic bias wk(s)=κ2(s−sk)2w_k(s) = \frac{\kappa}{2}(s - s_k)^2, δk(b)≤κh∣mb−sk∣+κ2h2\delta_k(b) \le \kappa h |m_b - s_k| + \frac{\kappa}{2} h^2.

Proof. By the ergodic theorem nk(b)/n→Pk(b)=∫Ibpk(s) dsn_k(b) / n \to P_k(b) = \int_{I_b} p_k(s)\,ds, which is positive, and ln⁡\ln is continuous on (0,∞)(0, \infty). By Claim 1, Pk(b)=(Z/Zk)∫Ibp(s)e−βwk(s) dsP_k(b) = (Z / Z_k) \int_{I_b} p(s) e^{-\beta w_k(s)}\,ds, and on IbI_b the factor e−βwk(s)e^{-\beta w_k(s)} lies between e−β(wk(mb)+δk(b))e^{-\beta (w_k(m_b) + \delta_k(b))} and e−β(wk(mb)−δk(b))e^{-\beta (w_k(m_b) - \delta_k(b))}. So

−β−1ln⁡Pk(b)=−ck+Fb+wk(mb)+ek(b)-\beta^{-1} \ln P_k(b) = -c_k + F_b + w_k(m_b) + e_k(b)

with ∣ek(b)∣≤δk(b)|e_k(b)| \le \delta_k(b). Subtract wk(mb)w_k(m_b). For the harmonic bias, wk(s)−wk(mb)=κ(mb−sk)(s−mb)+κ2(s−mb)2w_k(s) - w_k(m_b) = \kappa (m_b - s_k)(s - m_b) + \frac{\kappa}{2}(s - m_b)^2, and ∣s−mb∣≤h|s - m_b| \le h. □\square

Taking −ln⁡nk(b)-\ln n_k(b) instead of −ln⁡(nk(b)/n)-\ln(n_k(b)/n), as line L4 does, only adds the constant β−1ln⁡n\beta^{-1} \ln n to every bin of the window, which is absorbed into the window constant. Thus each window profile converges to the bin free energy up to a constant, with an error that is small when the bins are narrow compared with 1/(βκ∣mb−sk∣)1 / (\beta \kappa |m_b - s_k|).

Claim 3 (the join). Let Gk(b)G_k(b), for bb in a set SkS_k of bins, be the window profiles of line L4, and suppose Gk(b)=Fb+ak+ϵk(b)G_k(b) = F_b + a_k + \epsilon_k(b) with constants aka_k and errors ∣ϵk(b)∣≤ϵ|\epsilon_k(b)| \le \epsilon. Suppose that for each k≥2k \ge 2 the set SkS_k shares at least one bin with S1∪⋯∪Sk−1S_1 \cup \dots \cup S_{k-1}. Then lines L5 to L8 return a profile F^\hat F with

F^(b)=Fb+a1−min⁡b′F^′(b′)+r(b),∣r(b)∣≤(2K−1) ϵ,\hat F(b) = F_b + a_1 - \min_{b'} \hat F'(b') + r(b), \qquad |r(b)| \le (2K - 1)\,\epsilon,

where F^′\hat F' is the profile before line L8, on every bin covered by some window. In particular, if all errors are 0, the output is Fb−min⁡FF_b - \min F exactly on the covered bins.

Proof. Induction on kk. Let F^k\hat F_k be the profile after window kk is merged, and claim F^k(b)=Fb+a1+rk(b)\hat F_k(b) = F_b + a_1 + r_k(b) with ∣rk(b)∣≤(2k−1)ϵ|r_k(b)| \le (2k - 1)\epsilon. For k=1k = 1, F^1=G1\hat F_1 = G_1 and ∣r1∣≤ϵ|r_1| \le \epsilon. At step kk the shift is c=meanb∈S(F^k−1(b)−Gk(b))=a1−ak+meanb∈S(rk−1(b)−ϵk(b))c = \mathrm{mean}_{b \in S} (\hat F_{k-1}(b) - G_k(b)) = a_1 - a_k + \mathrm{mean}_{b \in S}(r_{k-1}(b) - \epsilon_k(b)), where SS is the shared set, which is not empty by assumption. So Gk(b)+c=Fb+a1+ρ(b)G_k(b) + c = F_b + a_1 + \rho(b) with ∣ρ(b)∣≤ϵ+(2k−3)ϵ+ϵ=(2k−1)ϵ|\rho(b)| \le \epsilon + (2k - 3)\epsilon + \epsilon = (2k - 1)\epsilon. Line L7 sets each bin either to this value or to a weighted mean of it and F^k−1(b)\hat F_{k-1}(b), whose error is at most (2k−3)ϵ(2k - 3)\epsilon; a weighted mean with nonnegative weights has error at most the larger of the two. This gives the bound for kk. Line L8 subtracts the same number from every bin. □\square

The bound of Claim 3 is a worst case. Window errors of random sign add more like a random walk, so the error between the two ends of a chain of KK windows grows roughly like K ϵ\sqrt{K}\,\epsilon, which matches the asymmetry error of the example on the page. WHAM avoids the order of joins by solving for all constants at once.

Remark (the example). In the example s=xs = x, so p(s)∝e−βU(s)p(s) \propto e^{-\beta U(s)} and F=UF = U up to a constant. The bin free energy FbF_b differs from U(mb)U(m_b) by at most the variation of UU over the bin, which is why the page compares with UU at the bin centres on bins where the variation is small.

Complexity

Sampling costs O(n)O(n) energy evaluations per window, so O(Kn)O(K n) in total, and this term dominates in practice. The histograms cost O(Kn)O(K n) and the join O(KB)O(K B). The windows are independent and run in parallel. The extra space is O(KB)O(K B) for the histograms. The number of windows needed grows with the length of the path in ss divided by the window width, and the statistical error of FF at a point grows roughly with the square root of the number of joins between it and the reference point.

Properties

  • Exact unbiasing. The bias is removed exactly in each window; the only errors are statistical, the bin width, and the join.
  • Any bias that depends only on ss can be used; the harmonic spring is the common choice.
  • Parallel. The windows need no communication.
  • Depends on the collective variable. It gives FF along ss; if a slow motion is not described by ss, each window can stay stuck in one valley of the hidden motion and the profile is wrong.
  • Consistent, not unbiased. The log of a histogram count is biased for finite counts.

Variants and improvements

  • WHAM and MBAR. The weighted histogram analysis method combines all windows with weights of least variance and needs no order of joins; MBAR does the same without bins.
  • Umbrella integration. Estimate the mean force dF/dsdF/ds in each window from the mean and variance of ss, and integrate it; this needs no overlap between histograms (Kästner 2011).
  • Replica exchange umbrella sampling. Run the windows in parallel and swap configurations between neighbouring windows, as in parallel tempering, to relax hidden slow motions.
  • Adaptive biases. Metadynamics and Wang-Landau sampling build a bias that flattens the profile during the run instead of using fixed windows.
  • Multidimensional windows. Biases on two or three collective variables give a free energy surface, at a cost that grows with the number of windows on the grid.

When to use it

Use umbrella sampling when a good collective variable is known, the path between the states along it is clear, and the barrier is too high for plain sampling. It is robust and simple, and with WHAM or MBAR it is a standard tool for potentials of mean force, for example along a distance in ligand unbinding or along a reaction coordinate in a QM/MM study. For many collective variables, or when the path is not known, adaptive methods such as metadynamics are often easier.

Pitfalls

  • Too little overlap. Neighbouring windows must share well-sampled bins; check the histograms of all windows on one plot.
  • Springs that are too stiff or too soft. A stiff spring gives narrow windows and needs many of them; a soft one does not hold the system on a steep part of FF.
  • Hidden slow motions. If each window samples only one of two valleys orthogonal to ss, the profile depends on the starting configuration; compare runs from different starts.
  • Equilibration. Each window starts from a configuration that may be far from its biased equilibrium; discard the first part of each run.
  • Bin width. Evaluating the bias at the bin centre adds an error up to the change of wkw_k across the bin, which is largest far from the window centre.
  • Jacobian terms. For a distance or an angle, F(s)F(s) contains the entropy of the volume element, such as −2kBTln⁡r-2 k_B T \ln r for a distance in three dimensions; this is part of FF, not an error.

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.

umbrella_sampling.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/umbrella-sampling/. The authors are listed in prov/H90CB5.jsonl.
"""Umbrella sampling (Torrie and Valleau 1977) on a one-dimensional coordinate.

Each window k adds the bias w_k(s) = (kappa / 2) (s - s_k)^2 to the potential
and samples exp(-beta (U + w_k)). In window k the free energy is known up to a
constant from the biased histogram,

    F(b) = -kT ln n_k(b) - w_k(b) + c_k,

and the constants c_k are fixed by asking neighbouring windows to agree on the
bins they share. This file uses that simple join (a least-squares match on the
shared bins). WHAM is the better way to combine the windows; see the WHAM page.

The coordinate is s = x here, so the exact free energy profile is U itself,
which the tests use.
"""

import math
from typing import Callable, Sequence


def double_well(height: float) -> Callable[[float], float]:
    """U(x) = height (x^2 - 1)^2, minima at x = -1 and x = 1, barrier height at x = 0."""
    return lambda x: height * (x * x - 1.0) ** 2


def harmonic_bias(center: float, kappa: float) -> Callable[[float], float]:
    return lambda s: 0.5 * kappa * (s - center) ** 2


def metropolis(u: Callable[[float], float], beta: float, x0: float, step: float,
               n: int, rng, burn: int = 500) -> list[float]:
    """Random walk Metropolis chain for the density exp(-beta u)."""
    x, ux = x0, u(x0)
    out = []
    for i in range(burn + n):
        y = x + step * (2.0 * rng.random() - 1.0)
        uy = u(y)
        if uy <= ux or rng.random() < math.exp(-beta * (uy - ux)):
            x, ux = y, uy
        if i >= burn:
            out.append(x)
    return out


def histogram(values: Sequence[float], lo: float, hi: float, nbins: int) -> list[int]:
    counts = [0] * nbins
    width = (hi - lo) / nbins
    for v in values:
        b = int((v - lo) // width)
        if 0 <= b < nbins:
            counts[b] += 1
    return counts


def bin_centers(lo: float, hi: float, nbins: int) -> list[float]:
    width = (hi - lo) / nbins
    return [lo + (b + 0.5) * width for b in range(nbins)]


def unbias(counts: Sequence[int], bias: Callable[[float], float], centers: Sequence[float],
           beta: float, min_count: int = 50) -> list:
    """-kT ln n(b) - w(b) on bins with at least min_count samples, None elsewhere."""
    return [(-math.log(c) / beta - bias(s)) if c >= min_count else None
            for c, s in zip(counts, centers)]


def join_windows(profiles: Sequence[list], counts: Sequence[Sequence[int]]) -> list:
    """Join window profiles, in order along s, into one profile with minimum 0."""
    f = list(profiles[0])                                        # @line L5
    weight = [c if p is not None else 0 for p, c in zip(f, counts[0])]
    for prof, cnt in zip(profiles[1:], counts[1:]):              # @line L6
        shared = [b for b, (a, p) in enumerate(zip(f, prof)) if a is not None and p is not None]
        if not shared:
            raise ValueError("neighbouring windows share no bins")
        shift = sum(f[b] - prof[b] for b in shared) / len(shared)  # @line L6
        for b, p in enumerate(prof):                             # @line L7
            if p is None:
                continue
            p += shift
            if f[b] is None:
                f[b], weight[b] = p, cnt[b]
            else:                                                # count-weighted mean
                f[b] = (weight[b] * f[b] + cnt[b] * p) / (weight[b] + cnt[b])
                weight[b] += cnt[b]
    m = min(v for v in f if v is not None)
    return [v - m if v is not None else None for v in f]         # @line L8


def umbrella_sampling(u: Callable[[float], float], centers_s: Sequence[float], kappa: float,
                      beta: float, n: int, step: float, lo: float, hi: float, nbins: int,
                      rng) -> tuple[list, list[list[int]]]:
    """Free energy profile on the bins of [lo, hi], and the window histograms."""
    centers = bin_centers(lo, hi, nbins)
    profiles, all_counts = [], []
    for s_k in centers_s:                                        # @line L1
        w = harmonic_bias(s_k, kappa)
        xs = metropolis(lambda x: u(x) + w(x), beta, s_k, step, n, rng)  # @line L2
        counts = histogram(xs, lo, hi, nbins)                    # @line L3
        profiles.append(unbias(counts, w, centers, beta))        # @line L4
        all_counts.append(counts)
    return join_windows(profiles, all_counts), all_counts
test_umbrella_sampling.py 80 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/umbrella-sampling/. The authors are listed in prov/H90CB5.jsonl.
import math
import random

import pytest

from umbrella_sampling import (
    bin_centers,
    double_well,
    harmonic_bias,
    histogram,
    join_windows,
    metropolis,
    umbrella_sampling,
    unbias,
)


def test_histogram_and_bin_centers():
    assert histogram([0.05, 0.15, 0.17, 0.99, 1.2, -0.1], 0.0, 1.0, 10) == [1, 2, 0, 0, 0, 0, 0, 0, 0, 1]
    assert bin_centers(0.0, 1.0, 4) == pytest.approx([0.125, 0.375, 0.625, 0.875])


def test_unbias_recovers_profile_from_exact_counts():
    # Counts proportional to exp(-(F + w)) give back F up to one constant.
    centers = bin_centers(-1.0, 1.0, 20)
    f = [math.sin(3 * s) for s in centers]
    w = harmonic_bias(0.3, 5.0)
    counts = [1e5 * math.exp(-(fb + w(s))) for fb, s in zip(f, centers)]
    prof = unbias(counts, w, centers, 1.0)
    shifts = [p - fb for p, fb in zip(prof, f)]
    assert max(shifts) - min(shifts) < 1e-12


def test_unbias_drops_sparse_bins():
    centers = bin_centers(0.0, 1.0, 3)
    prof = unbias([100, 3, 0], lambda s: 0.0, centers, 1.0, min_count=10)
    assert prof[1] is None and prof[2] is None
    assert prof[0] == pytest.approx(-math.log(100))


def test_join_removes_window_constants_exactly():
    true = [0.0, 1.0, 3.0, 2.0, 0.5, 1.5]
    a = [v + 7.0 for v in true[:4]] + [None, None]
    b = [None, None] + [v - 2.0 for v in true[2:]]
    joined = join_windows([a, b], [[100] * 6, [100] * 6])
    assert joined == pytest.approx(true)


def test_join_needs_shared_bins():
    with pytest.raises(ValueError):
        join_windows([[0.0, None], [None, 0.0]], [[100, 0], [0, 100]])


def test_plain_sampling_is_trapped_in_one_well():
    # Barrier of 8 kT: a plain chain started at x = -1 does not cross in 50000 steps.
    xs = metropolis(double_well(8.0), 1.0, -1.0, 0.3, 50000, random.Random(2))
    assert max(xs) < 0.0


def test_double_well_profile_against_exact():
    u = double_well(8.0)
    lo, hi, nb = -1.6, 1.6, 32
    windows = [-1.6 + 0.2 * k for k in range(17)]
    f, counts = umbrella_sampling(u, windows, 50.0, 1.0, 20000, 0.3, lo, hi, nb, random.Random(1))
    centers = bin_centers(lo, hi, nb)
    # Every bin below 9 kT has enough samples, including the barrier top.
    assert all(v is not None for v, s in zip(f, centers) if u(s) < 9.0)
    assert min(v for v in f if v is not None) == 0.0
    # Here s = x, so the exact profile is U up to a constant.
    pairs = [(v, u(s)) for v, s in zip(f, centers) if u(s) < 9.0]
    off = sum(e - v for v, e in pairs) / len(pairs)
    assert max(abs(v + off - e) for v, e in pairs) < 0.4
    i0, im, ip = 16, 6, 25  # bins centred at 0.05, -0.95 and 0.95
    assert centers[i0] == pytest.approx(0.05) and centers[im] == pytest.approx(-0.95)
    assert centers[ip] == pytest.approx(0.95)
    barrier = f[i0] - f[ip]
    assert barrier == pytest.approx(u(centers[i0]) - u(centers[ip]), abs=0.4)
    assert abs(f[im] - f[ip]) < 0.4

History

Torrie and Valleau (1977) used sampling distributions that are not physical but cover the important regions of two states at once, and reweighted the samples to compute free energy differences; the distribution that spans both states gave the name. The use of many harmonic windows along a coordinate, combined with WHAM (Kumar and co-workers 1992), became the standard method for potentials of mean force in biomolecular simulation. Kästner (2011) reviews the method and its analysis.

References

  1. Glenn M. Torrie and John P. Valleau, Nonphysical sampling distributions in Monte Carlo free-energy estimation, umbrella sampling, Journal of Computational Physics 23(2), 1977, 187-199, the biased sampling distribution and the reweighting of its samples to the unbiased ensemble
  2. Johannes Kästner, Umbrella sampling, Wiley Interdisciplinary Reviews, Computational Molecular Science 1(6), 2011, 932-942, the review of harmonic window biases, the choice of force constant and window spacing, and the ways to combine windows
  3. Shankar Kumar, John M. Rosenberg, Djamal Bouzida, Robert H. Swendsen and Peter A. Kollman, The weighted histogram analysis method for free-energy calculations on biomolecules. I. The method, Journal of Computational Chemistry 13(8), 1992, 1011-1021, the combination of the biased histograms of many umbrella windows into one free energy profile
  4. Daan Frenkel and Berend Smit, Understanding Molecular Simulation, From Algorithms to Applications, second edition, Academic Press, 2002, the chapter on free energy calculations, the section on umbrella sampling

Where this leads

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