Lab 3.8 · 35 min

Lab: barostats by hand

A barostat changes the box size so that the pressure matches a target. Like a thermostat, it has two jobs: reach the target, and then let the box breathe by exactly the right amount. We compute the pressure of our 9-atom box by hand, work out how much its area should fluctuate, and test Berendsen, C-rescale and the Parrinello–Rahman piston against that number.

The setup

Same 9 atoms in a 2D periodic box. The temperature is held at T₀ = 0.72 by a Langevin thermostat on the atoms (Lab 3.7 showed it gives the right fluctuations for any system). Now the box side L is allowed to change, so that the pressure is P₀ = 3.0.

atoms N = 9, 2D, periodic, square box L × L area A = L² (the 2D "volume") temperature T₀ = 0.72, Langevin γ = 1 on the atoms target P₀ = 3.0 time step dt = 0.005 cutoff r_c = 1.5 (truncated and shifted) the box may shrink to L = 2 r_c = 3.0 before the minimum image breaks (Lab 2)

Why P₀ = 3.0 and not 0? In two dimensions, Lennard-Jones atoms at T = 0.72 are above the critical temperature: at zero pressure they would fly apart like a gas and the box would grow without limit. A pressure of 3 keeps them a dense fluid.

Step 1

Pressure of one configuration, by hand

Why: A barostat can only react to a pressure it can measure. In a simulation there are no walls to push on, so the pressure is computed from two things we already have: how fast the atoms move (kinetic part) and how hard they push or pull on each other (virial part).

2D: P = ( Σ m v² + Σ_pairs r·F ) / (2A) average of Σ m v² = N T₀ (Langevin: N_f = 2N) lattice, L = 3.6, A = 12.96 kinetic part N T₀ / A = 9 × 0.72 / 12.96 = 0.500 pairs inside r_c = 1.5: 18 at r = 1.2 (the diagonal 1.697 is beyond the cutoff) F(1.2) = 24(2/1.2¹³ − 1/1.2⁷) = −2.2117 (attraction) virial part ½ × 18 × 1.2 × (−2.2117) / 12.96 = −1.843 P = 0.500 − 1.843 = −1.343

Now let the atoms move in the same box (NVT, 290 time units):

average P = 1.074 instantaneous P fluctuates by ± 1.189 averages over 1 time unit (200 steps) still ± 0.708

What the numbers say: The frozen lattice says −1.343 (the box wants to shrink); the moving atoms say +1.074 (it wants to grow). A single configuration is not "the pressure". Worse, the instantaneous pressure jumps by more than its own average every step. A barostat that reacted fully to each step would shake the box violently, so every barostat responds slowly, through a coupling time τ_P or a piston mass W. It also means that a pressure from a short run is unreliable: always quote averages over long runs.

Step 2

How much should the box breathe?

Why: At constant pressure the box area is not fixed; it fluctuates. As for temperature in Lab 3.7, we need the correct amount before we can judge any barostat. It follows from the equation of state P(A): how the average pressure depends on the box area.

Run NVT at a series of areas (each 300 time units):

ALaverage P
9.63.09810.512
10.03.1626.946
10.43.2254.513
10.83.2863.046
11.03.3172.673
11.23.3472.080
11.63.4061.715
12.03.4641.316
12.43.5211.193
rule: growing the box by dA does work (P − P₀) dA. probability changes by exp( (P − P₀) dA / T₀ ) A 11.0 -> 11.2: mean P = (2.673 + 2.080)/2 = 2.377 (2.377 − 3.0) × 0.2 / 0.72 = −0.173 probability × e^(−0.173) = × 0.841 chain these factors over the whole table: correct ⟨A⟩ = 11.006, σ_A = 0.564 quick estimate from the slope near P = P₀ (A = 10.8): dP/dA = −2.55 compressibility κ = −1/(A dP/dA) = 0.0363 σ_A = √(T₀ A κ) = √(0.72 × 10.8 × 0.0363) = 0.532

What the numbers say: Where the box pressure is above P₀ the box tends to grow, where it is below it tends to shrink, and the exponential tells us by how much: this gives the full distribution of areas, the amber curve in the widget. The box should fluctuate by σ_A = 0.564 (5 % of its area) around ⟨A⟩ = 11.006. Note that the curve is lopsided: P(A) is steep at small A and flat at large A, so the average area is larger than the area where P = P₀ (about 10.83). This is the test for every barostat below, and the size of the fluctuation is how compressibilities are computed from simulations.

Step 3

Berendsen barostat

Why: The simplest idea, the same as the Berendsen thermostat: scale the box (and all coordinates) a little each step, in the direction that brings P towards P₀. The user supplies a coupling time τ_P and a guess of the compressibility β.

μ² = 1 − β (dt/τ_P)(P₀ − P) (area factor) β = 0.03, τ_P = 0.5 -> β dt/τ_P = 0.0003 from the lattice, P = −1.343: μ² = 1 − 0.0003 × (3.0 + 1.343) = 0.998697 μ = 0.999348 L: 3.6 -> 3.59765 A: 12.96 -> 12.9431 every x and y is multiplied by μ too
long run (700 time units)⟨A⟩σ_A
correct11.0060.564
Berendsen τ_P = 0.510.8320.247
Berendsen τ_P = 510.8460.110

What the numbers say: Merit: smooth and safe, it never overshoots, so it is a good way to bring the density to the right value (step 6). Limitation 1: the box fluctuates by 0.247 (τ_P = 0.5) or 0.110 (τ_P = 5) instead of 0.564, so any compressibility computed from it would be 5 to 25 times too small (σ² enters). Limitation 2: the average area is wrong too, 10.83 instead of 11.01, a 1.6 % error in density. Berendsen holds the box near the point where P = P₀ and never explores the lopsided tail of step 2. Weaker coupling makes the fluctuation smaller, not better. Not for production.

Step 4

C-rescale: Berendsen plus the missing randomness

Why: Exactly the fix of the Bussi thermostat, applied to the box (Bernetti and Bussi, 2020). Keep Berendsen's smooth pull, add a random kick of the right size, and a small correction T₀/A. Working with ln A makes the update a simple sum.

d(ln A) = −(β/τ_P)(P₀ − P − T₀/A) dt + √(2 T₀ β dt / (A τ_P)) × R drift = −(0.03/0.5)(3.0 + 1.343 − 0.0556) × 0.005 = −0.001286 (= Berendsen) noise = √(2 × 0.72 × 0.03 × 0.005 / (12.96 × 0.5)) = 0.005774 R = +1: d(ln A) = +0.004487 -> A = 13.0183 R = −1: d(ln A) = −0.007060 -> A = 12.8688 R = 0: d(ln A) = −0.001286 -> A = 12.9433 coordinates × e^(d(ln A)/2), velocities × e^(−d(ln A)/2)
long run⟨A⟩σ_A
correct11.0060.564
Berendsen τ_P = 0.510.8320.247
C-rescale τ_P = 0.511.0400.587

What the numbers say: Merit: the noise is 4.5 times larger than the drift in a single step, yet on average the drift wins, so equilibration is as smooth as Berendsen's, and the fluctuation (0.587) and average (11.04) now agree with the correct values within the noise of a 700-time-unit run. It is first order (no piston to oscillate) and works for any τ_P. Limitation: like Bussi, it is stochastic, so trajectories are reproducible only with the same seed, and the compressibility β is still a user guess (it sets the speed, not the result). GROMACS: pcoupl = C-rescale (available since version 2021).

Step 5

The piston: Parrinello–Rahman (Andersen in 1 dimension)

Why: Instead of nudging the box, give it a mass W and let it move like a piston under Newton's law: the force on the piston is the pressure difference. This is deterministic, like Nosé–Hoover, and with a correctly thermostatted system it samples the right volumes. The new question is how heavy the piston should be.

W d²A/dt² = P − P₀ from the lattice (P = −1.343), W = 0.1: box acceleration = (−1.343 − 3.0)/0.1 = −43.43 box velocity after 1 step −0.217 after 10 steps −2.17 (it keeps speeding up) near equilibrium the piston oscillates like a spring: period = 2π √(W κ A), κ A = 0.0363 × 10.8 = 0.392
Wperiod: handperiod: measured⟨A⟩σ_A
correct——11.0060.564
0.010.390.2911.0520.583
0.11.241.0211.0540.574
25.574.7611.0500.559

What the numbers say: Merit: all three masses give the correct fluctuation (0.56–0.58) and average (11.05), and the dynamics are smooth and deterministic. The hand formula gets the oscillation period within 20 % (the rest is because P(A) is not a straight line). The mass only sets how fast the box breathes: W = 0.01 oscillates every 58 steps, which is too close to the atomic motions and disturbs them; W = 2 needs about 5 time units per breath, so a run must be many periods long to sample the volume. A common starting point: LAMMPS suggests a damping time of about 1000 time steps. The real limitation appears when you start far from equilibrium (next step). The full Parrinello–Rahman method lets the box shape change too (solids, phase transitions); MTK (LAMMPS fix npt) is the version with Nosé–Hoover chains and exact equations.

Step 6

Starting far away: equilibration

Why: Production barostats are judged by the fluctuations; equilibration barostats by how safely they reach the target. We start from a box that is far too big, A = 14 (P ≈ 1.1, well below 3.0), and watch the area.

time0.51251020
Berendsen τ_P 0.512.6211.5310.9810.8910.9210.68
C-rescale τ_P 0.511.1711.1610.5410.5511.9411.49
piston W 0.19.9912.2511.5310.8210.8811.25
piston W 213.7613.1211.1412.7611.0911.23
correct range: 11.0 ± 0.56 -> about 10.4 to 11.6 A = 9.99: P ≈ 7 from the table in step 2 more than twice the target

What the numbers say: Berendsen glides smoothly into the right range within 1–2 time units and stays there (with the wrong, too-small fluctuations). C-rescale is just as fast and then fluctuates correctly. The light piston (W = 0.1) gathers speed and overshoots to A = 9.99 within half a time unit, where the pressure is more than twice the target; in a real system with a big initial mismatch this can crash the run or melt a solid. The heavy piston (W = 2) swings back to 12.76 at t = 5 and takes many periods to settle. Practical rule: equilibrate with Berendsen or C-rescale, then switch to a piston for production, or simply use C-rescale for both.

Step 7

What the cutoff leaves out of the pressure

Why: Our forces stop at r_c = 1.5, but the real attraction continues beyond it. Every pair beyond the cutoff would pull the box inward a little. Because a barostat sets the box size from the pressure, a missing piece of pressure becomes a wrong density.

2D tail pressure (atoms beyond r_c spread evenly): P_tail = −(π ρ² / 2) ∫ r² U′(r) dr, from r_c to ∞ ∫ = −24 (0.2 r_c⁻¹⁰ − 0.25 r_c⁻⁴) = 1.1019 ρ = 9 / 11.01 = 0.818 P_tail = −(π × 0.818² / 2) × 1.1019 = −1.157 effect on the box: dA = κ A P_tail = 0.0363 × 11.01 × (−1.157) = −0.46 (−4.2 %) 3D LJ liquid, ρ = 0.8, r_c = 2.5: P_tail = (16/3) π ρ² [ (2/3) r_c⁻⁹ − r_c⁻³ ] = −0.684

What the numbers say: With our short cutoff the missing attraction is −1.157, a third of the target pressure, and the box comes out 4.2 % too large. Even the standard 3D choice r_c = 2.5 misses −0.68 in a dense liquid, which is comparable to the pressure itself. Merit of the tail correction: it is one formula, added once. Limitation: it assumes the atoms beyond r_c are spread evenly, which fails at interfaces (liquid–vapour, membranes); there use a longer cutoff or a long-range method (LAMMPS pair_modify tail yes, GROMACS DispCorr = EnerPres).

Summary

methodmerit (number)limitation (number)use it for
Berendsensmooth: 14 -> 11 in 2 time unitsσ_A 0.247 vs 0.564; ⟨A⟩ 1.6 % offequilibration only
C-rescalesmooth and σ_A 0.587, ⟨A⟩ 11.04stochastic; needs a seedequilibration and production
piston (PR / MTK)σ_A 0.56–0.58, deterministicovershoots from far away (A = 9.99)production, after equilibration
piston mass Wperiod 2π√(W κ A)too light: shakes atoms; too heavy: slowstart near 1000 steps (LAMMPS)
tail correctionrestores −1.157 of pressurewrong at interfaceshomogeneous liquids