Lab 7.5 · 40 min

Lab: free energies by hand

Most research questions are about free energies: binding, solvation, which conformation wins, how high a barrier is. A free energy is not an average of the energy, so it needs special methods. We compute a potential of mean force from g(r), do free-energy perturbation on six numbers, charge an ion with thermodynamic integration, and stitch umbrella windows together by hand before letting WHAM do it, always on systems whose exact answer we know.

The setup

Why a special method? The free energy F = −k_BT ln Z counts how many states are accessible, not just how low they are. An ordinary simulation gives averages like ⟨U⟩; the free energy difference between two states can be written as an average too, but of an exponential, which brings its own problems.

step 1 PMF from g(r) (the 9-atom LJ box, k_BT = 0.72) steps 2–3 a spring that gets stiffer (k_BT = 1) exact: ΔF = (k_BT/2) ln(k₁/k₀) step 4 charging an ion, solvent modelled by a fluctuating potential (k_BT = 2.494 kJ/mol) steps 5–6 the double well of Lab 7.4, U = 5(s² − 1)² exact barrier 5 k_BT

Step 1

Potential of mean force from g(r)

Why: g(r) says how much more often two atoms are found at distance r than in an ideal gas. Turning this probability into an energy, w(r) = −k_BT ln g(r), gives the free energy of the pair at that distance, averaged over everything else: the potential of mean force (PMF). For ion pairs it tells whether contact pairs or solvent-separated pairs are preferred.

dilute gas (no other atoms): g = e^(−U/k_BT) r = 1.12: g = e^(0.9998/0.72) = 4.009 w = −0.72 ln 4.009 = −0.9998 = U(r) dense liquid (our 9-atom box, ρ = 0.69): r g w = −0.72 ln g bare U 1.025 1.453 −0.2690 −0.4750 1.125 2.687 −0.7117 −0.9998 1.475 0.929 +0.0531 −0.3507 1.675 0.612 +0.3536 −0.1729

What the numbers say: In a gas the PMF is just the pair potential. In the liquid it is not: the well is shallower (−0.71 instead of −1.00), and at 1.675, where the bare potential is still attractive, the PMF is repulsive (+0.35), because the pair at that distance has to push away the neighbours that would like to sit between them. The PMF contains the solvent. Merit: it costs nothing beyond g(r). Limitation: it only works where g(r) is well sampled; at high PMF values (rare distances) g is tiny and noisy, which is why barriers need the biased methods of steps 5–6.

Step 2

Free-energy perturbation by hand

Why: Zwanzig's formula gives the free-energy change from state 0 to state 1 using samples of state 0 only: ΔF = −k_BT ln ⟨e^(−ΔU/k_BT)⟩₀, where ΔU = U₁ − U₀ is evaluated on each sample. Test it on a spring whose stiffness doubles, where the exact answer is known.

U₀ = ½ x² -> U₁ = ½ (2) x², k_BT = 1 exact ΔF = ½ ln 2 = 0.3466 six samples of state 0: x ΔU = ½x² e^(−ΔU) 0.30 0.0450 0.9560 −1.20 0.7200 0.4868 0.80 0.3200 0.7261 −0.10 0.0050 0.9950 1.90 1.8050 0.1645 −0.60 0.1800 0.8353 average e^(−ΔU) = 0.6939 ΔF = −ln 0.6939 = 0.3654 100 000 samples: 0.3488 energy change: ⟨U₁⟩₁ − ⟨U₀⟩₀ = ½ − ½ = 0 so T ΔS = ΔU − ΔF = −0.3466

What the numbers say: Six samples already give 0.365 against the exact 0.347. The free energy rises although the average energy does not change at all (½k_BT in both states, by equipartition): the stiffer spring confines the particle to a narrower range, and the whole ΔF is entropy. This is why free energies cannot be computed from energy averages alone. Note the sample at x = 1.90 contributes only 0.16 to the average: FEP is dominated by the samples where U₁ is low.

Step 3

The overlap problem

Why: FEP only works if the samples of state 0 include the configurations that matter for state 1. Make the spring 100 times stiffer and run FEP in both directions: forward (sample the soft spring, evaluate the stiff one) and backward (sample the stiff spring, evaluate the soft one).

exact ΔF = ½ ln 100 = 2.3026 (20 repeats each) samples forward (sample k = 1) backward (sample k = 100) 100 2.358 ± 0.287 0.862 ± 0.269 1 000 2.298 ± 0.094 1.105 ± 0.245 100 000 2.301 ± 0.008 1.345 ± 0.127 backward in 4 stages (k = 1, 3.16, 10, 31.6, 100), 1000 samples each: 2.180 k = 1 has 32 % of its weight at |x| > 1; samples of k = 100 found there: 0.0000 %

What the numbers say: Forward works: the soft spring visits the narrow region the stiff one needs. Backward fails badly, and more samples barely help (1.35 after 100 000 samples, still 40 % low), because the stiff spring never visits |x| > 1, where the soft spring has a third of its weight: the missing part is never seen, so the estimate is biased, not just noisy. The cures: go in the direction from the broad to the narrow distribution, split a large change into stages so that neighbours overlap (2.18 with 4 stages), and use both directions together (the Bennett acceptance ratio, BAR/MBAR, the standard in GROMACS and alchemical tools).

Step 4

Charging an ion: FEP fails, TI works

Why: Solvation free energies are computed by slowly switching on an ion's charge. A simple model of the solvent: the electrostatic potential φ at the ion site fluctuates like a Gaussian with spread s; the energy of charge q is qφ. Linear response gives the exact answer, so we can test one-step FEP and thermodynamic integration (TI), which integrates the average slope ⟨∂U/∂λ⟩ along a switching parameter λ.

s = 50 kJ/mol/e, k_BT = 2.494 kJ/mol, q: 0 -> +1 exact ΔF = −q² s² / (2 k_BT) = −2500 / 4.988 = −501.2 kJ/mol one-step FEP from the uncharged state, 10⁶ samples: −k_BT ln ⟨e^(−φ/k_BT)⟩ = −199.4 needed: φ near −s²/k_BT = −1002 = −20 standard deviations most negative sample: −232 (−4.6 s) TI: U = λ q φ, ∂U/∂λ = φ, ΔF = ∫₀¹ ⟨φ⟩_λ dλ λ = 0.0 ⟨φ⟩ = −1.2 (1000 samples) λ = 0.5 ⟨φ⟩ = −498.8 λ = 1.0 ⟨φ⟩ = −1002.1 trapezoid: 0.5 × (−1.2 − 498.8)/2 + 0.5 × (−498.8 − 1002.1)/2 = −500.2 kJ/mol FEP in 10 stages (1000 samples each): −502.1

What the numbers say: One-step FEP is off by 300 kJ/mol even with a million samples: the charged ion needs solvent configurations 20 standard deviations away from what the neutral solute ever sees. TI with just three λ points gets −500.2 against −501.2, because it only needs ordinary averages at each λ, where the samples are typical. Staged FEP works for the same reason. In this model ⟨φ⟩ is a straight line in λ, so three points suffice; for real ions (and especially for switching off LJ, where soft-core potentials are needed) the curve bends and needs 10–20 λ windows. A value of −500 kJ/mol is the right order of magnitude for the hydration of a small ion such as Na⁺ (about −400 kJ/mol), and a real calculation also needs the charged-box correction of Lab 5.5.

Step 5

Umbrella sampling by hand

Why: A barrier top is visited too rarely to measure its probability. Umbrella sampling adds a spring w(s) = ½k(s − s₀)² that holds the system near s₀, measures the histogram there, and removes the known bias afterwards: F(s) = −k_BT ln P(s) − w(s) + constant.

window at s₀ = 0 (the barrier top), k = 30, 10⁶ steps s count P −ln P − w(s) = F + C₀ exact U −0.15 119134 0.1191 2.128 −0.338 1.790 4.778 −0.05 139700 0.1397 1.968 −0.038 1.931 4.975 0.05 146083 0.1461 1.924 −0.038 1.886 4.975 0.15 130550 0.1305 2.036 −0.338 1.698 4.778 0.25 97314 0.0973 2.330 −0.938 1.392 4.395 0.35 71569 0.0716 2.637 −1.837 0.800 3.850 window at s₀ = 0.5: at the shared bin s = 0.35 it gives 3.297 shift it by 0.800 − 3.297 = −2.498 to match window 0 then F(0.75) − F(0.05) = −3.943 (exact −4.018)

What the numbers say: Without the spring, the barrier top would be visited a fraction e^(−5) of the time; with it, 10⁵ samples per bin. After removing the bias, the window reproduces the shape of the barrier (the F + C₀ column falls from 1.93 to 0.80 as the exact U falls from 4.98 to 3.85), but only up to an unknown constant C₀. Neighbouring windows are connected through bins they both sample. By hand we matched them at one bin and got −3.94 against −4.02. Limitation: the matching relies on the overlap; a bin seen rarely by one of the windows makes the shift noisy.

Step 6

WHAM: all windows at once

Why: Matching windows one bin at a time wastes data and accumulates errors. The weighted histogram analysis method (WHAM) finds the constants of all windows together, so that every bin uses all the windows that visited it, weighted by how much they saw. How many windows, and how long, does a 5 k_BT barrier need?

windows (s₀ from −1.2 to 1.2)steps eachtotal stepsbarrier (exact 5.0)
5100 000500 0005.32 ± 0.25
920 000180 0005.18 ± 0.37
9100 000900 0005.14 ± 0.29
1750 000850 0005.07 ± 0.14
mean ± spread over 4 independent repeats one plain run of 900 000 steps: 3 barrier crossings

What the numbers say: Umbrella sampling with WHAM recovers the 5 k_BT barrier, which a plain run of the same length crosses only three times (far too few to measure anything). With 5 windows spaced 0.6 apart the overlap is poor and the result is high by 0.3; with 17 windows the error drops to ±0.14 for the same total cost as 9 long windows: overlap matters more than length. Merits: every window is an ordinary, independent simulation (easy to run in parallel), and the method is the same as metadynamics' result in Lab 7.4 (5.00), from a different route. Limitations: the collective variable must be chosen in advance, as in metadynamics, and slow motions orthogonal to it make windows converge slowly. In practice: PLUMED for the biases, gmx wham or WHAM by Grossfield for the analysis.

Summary

methodmerit (number)limitation (number)
PMF from g(r)free: −0.71 well, +0.35 solvent barrieronly where g(r) is well sampled
FEP (Zwanzig)6 samples: 0.365 vs 0.347needs overlap: backward 1.35 vs 2.30
staged FEP / BAR4 stages: 2.18; 10 stages: −502 vs −501more windows to run
TI3 λ points: −500.2 vs −501.2curved ⟨∂U/∂λ⟩ needs 10–20 λ
umbrella + WHAMbarrier 5.07 ± 0.14 (plain run: 3 crossings)needs overlapping windows and a good CV