Lesson 3.6 · 15 min

Pressure and barostats

Pressure in MD comes from the virial: atoms hitting the walls plus the forces between them. It is very noisy. A barostat lets the box breathe so the pressure is right on average. Berendsen gets the density right but the fluctuations wrong; C-rescale and Parrinello–Rahman/MTTK get both right.

The idea

Where pressure comes from. Pressure has two parts. The kinetic part is the momentum carried by atoms moving through any surface (the ideal-gas term NkBT/V). The virial part comes from forces acting across that surface: repulsion pushes the box outwards, attraction pulls it in. MD computes both every step from the velocities and from Σ r·F over pairs, a quantity we already have from the force loop.

It is noisy. The instantaneous pressure fluctuates strongly, much more than the temperature. For a few thousand water molecules it swings by hundreds of bar from step to step, even when the average is exactly 1 bar. Only long averages mean anything. And like the energy (Lesson 2.5), a cutoff needs a tail correction for the pressure.

Barostats. To simulate at constant pressure (NPT, Lesson 3.2) the box volume becomes a variable. All positions are scaled with the box, so the atoms are not squeezed against one wall.

How the box may deform. Isotropic: all sides scale together (liquids). Semi-isotropic: the xy plane and z are coupled separately (membranes, interfaces). Anisotropic / fully flexible: each box vector can change, including shape (crystals, phase transitions).

Key idea. P = kinetic + virial, averaged over a long run. Equilibrate with Berendsen or C-rescale; produce with C-rescale or Parrinello–Rahman/MTTK. Choose the coupling (isotropic, semi-isotropic, anisotropic) to match the physics.

The algorithm

One NPT step (thermostat inside the MD step, barostat after it):

MD step with a thermostat
P = (2 K / 3 + W / 3) / V              # W = Σ r·F over pairs

# Berendsen
de = -(beta / tau_P) * (P0 - P) * dt

# C-rescale (adds the right noise; also scale v)
de = -(beta / tau_P) * (P0 - P - kB T / V) * dt
     + sqrt(2 kB T beta dt / (V tau_P)) * gaussian()

mu = exp(de / 3)                       # de = change of ln V
positions *= mu;  box *= mu
velocities /= mu                       # C-rescale only
  1. β is the (estimated) isothermal compressibility; for water use 4.5 × 10⁻⁵ bar⁻¹. A wrong β only changes the effective coupling speed.
  2. Typical τP: 1–2 ps for Berendsen and C-rescale, 2–5 ps for Parrinello–Rahman. τP should be several times τT.
  3. Discard the part of the run where the volume is still drifting. Then average.
  4. GROMACS: pcoupl = C-rescale or Parrinello-Rahman, pcoupltype = isotropic / semiisotropic / anisotropic, tau-p, compressibility, ref-p. LAMMPS: fix npt temp ... iso / aniso / tri ... (MTTK) or fix press/berendsen.