Lesson 3.2 · 13 min

NVE, NVT and NPT

An ensemble says which quantities a simulation holds fixed. Plain MD conserves energy (NVE); a thermostat gives constant temperature (NVT); adding a barostat gives constant pressure (NPT), like most experiments.

The idea

A simulation of N atoms in a box can be connected to the outside world in different ways. Statistical mechanics calls each choice an ensemble, named after the three quantities held fixed.

For large systems the averages agree between ensembles (at the same state point). What differs is which quantities fluctuate, and how much. Those fluctuations are physics, not noise: energy fluctuations in NVT give the heat capacity, volume fluctuations in NPT give the compressibility.

A typical workflow: minimise the energy → short NVT run to reach the temperature → NPT run until the density is stable → production run (NPT, or NVT at the equilibrated density, or NVE for clean dynamics).

Key idea. Choose the ensemble by what you want to compare. Measure densities in NPT. Check the integrator in NVE. Remember that thermostats and barostats change the dynamics a little (Lessons 3.3–3.6).

The algorithm

One MD step, and what each ensemble adds to it:

velocity Verlet step                    # NVE: nothing else
if NVT or NPT:
    thermostat(v, T_target)             # e.g. Andersen: some atoms get new
                                        # Maxwell-Boltzmann velocities
if NPT:
    P = (N kB T + W / 3) / V            # virial pressure, W = Σ r·F over pairs
    mu = (1 - k (P_target - P))^(1/3)   # e.g. Berendsen barostat
    positions *= mu;  L *= mu           # rescale the box and the atoms
  1. The simple thermostat and barostat used here (Andersen, Berendsen) are easy to understand. Lessons 3.3–3.6 compare them with better choices (Nosé–Hoover, Langevin, Parrinello–Rahman, MTTK, C-rescale).
  2. In NPT, discard the part of the run where the box is still shrinking or growing. Then average.
  3. Do not compute dynamical properties (diffusion, viscosity) with a strong thermostat that randomises velocities often: it disturbs the dynamics.
  4. In LAMMPS these are fix nve, fix nvt and fix npt. In GROMACS, set tcoupl and pcoupl in the .mdp file.