Thermostats and Ensemble Control in Molecular Dynamics
Molecular dynamics integrates Hamilton's equations for interacting particles; because the flow conserves energy and preserves phase-space volume, a long trajectory explores a constant-energy hypersurface and its time averages approximate microcanonical () ensemble averages. This is owned by the molecular-dynamics article. But most experiments are performed at fixed temperature and pressure, not fixed energy and volume. Ensemble control is the art of modifying the equations of motion so that the time-averaged sampling reproduces the canonical or isothermal–isobaric measure while disturbing the underlying physics as little as possible — and the central subtlety, which this article owns, is that getting the average temperature right does not guarantee getting the distribution right. Two philosophies coexist. Deterministic (extended-Lagrangian) thermostats — pioneered by Nosé and recast by Hoover — enlarge phase space with a small number of reservoir degrees of freedom whose equations of motion are engineered so that the marginal distribution of the physical variables is canonical. They are time-reversible and preserve smooth dynamical correlation functions, but they can fail to be ergodic. Stochastic thermostats — Andersen collisions, the Langevin equation, and global velocity rescaling — inject randomness that guarantees ergodicity and a strictly correct stationary distribution via detailed balance and the fluctuation–dissipation relation, at the price of replacing deterministic trajectories with a Markov process that damps long-time correlations. The Langevin thermostat's noise–friction lock is the second-kind fluctuation–dissipation relation owned by the langevin-equation and fluctuation-dissipation-theorem articles, recalled here by name. The barostat extends the same idea to the volume: treating (Andersen) or the full cell matrix (Parrinello–Rahman) as a piston with inertia , driven by the difference between the instantaneous internal pressure and the external set pressure, one samples constant-pressure ensembles and can observe diffusionless structural transformations. The theoretical demand throughout is that the modified flow possess the intended distribution as an invariant measure and, for trustworthy averages, be ergodic — a distinction dramatized by the notorious non-ergodicity of the bare Nosé–Hoover harmonic oscillator, which satisfies equipartition on average while sampling the wrong distribution. This article owns that owned result: correct average temperature does not imply correct ensemble.
- Plain Newtonian MD conserves energy and samples the microcanonical () ensemble; to reach or one couples the system to fictitious or stochastic reservoirs that exchange energy (a thermostat) and volume (a barostat).
- The Nosé–Hoover thermostat adds a dynamical friction variable with feedback ; the deterministic extended flow has a conserved quantity and, when ergodic, generates the canonical distribution in the physical subspace.
- Stochastic thermostats — Andersen (velocity randomization), Langevin (friction + noise, locked by fluctuation–dissipation), and Bussi–Donadio–Parrinello velocity rescaling — enforce the canonical ensemble and are provably ergodic, at the cost of perturbing dynamical correlations.
- Barostats (Andersen, Parrinello–Rahman, MTK) promote the volume (or cell matrix) to a dynamical variable driven by the internal–external pressure imbalance, yielding and enabling structural phase transitions.
- A correct thermostat must reproduce the right distribution — equipartition AND, ideally, ergodicity; the bare Nosé–Hoover scheme is famously non-ergodic for a single harmonic oscillator, cured by Nosé–Hoover chains.
- Key idea: augment Hamilton's equations with reservoir variables (deterministic feedback) or with friction-plus-noise (stochastic) so that the canonical/NPT measure is a stationary — and ideally unique — solution of the phase-space continuity equation; the physical observables are then the marginals.
Augment Hamilton's equations with reservoir variables (deterministic feedback) or friction-plus-noise (stochastic) chosen so that the canonical/ measure is a stationary — and ideally unique — solution of the phase-space continuity equation; the physical observables are recovered as marginals. Correct average temperature is necessary but not sufficient — the full distribution, hence ergodicity, is what matters.
Where this lives today
Constant-temperature production runs of proteins in water at 300 K use either a Nosé–Hoover chain (for accurate energy-conserving dynamics and transport properties) or the Bussi–Donadio–Parrinello velocity-rescaling thermostat (for robust, ergodic equilibration that barely disturbs diffusion constants); the once-popular Berendsen thermostat is now confined to initial equilibration because it samples no correct ensemble. An MTK or Parrinello–Rahman barostat lets the simulation cell change shape, enabling diffusionless solid–solid (martensitic) transformations and accurate equations of state. Because deterministic thermostats preserve smooth trajectories, they are preferred when extracting Green–Kubo transport coefficients (diffusion, viscosity, thermal conductivity), while stochastic thermostats with small friction are acceptable if the coupling stays weak versus the dynamical timescale. Replica-exchange (parallel tempering) MD runs many thermostatted copies across a temperature ladder and swaps with a Metropolis criterion — correct canonical sampling at each rung, guaranteed by a rigorous thermostat, is what makes the exchange obey detailed balance.
The physical picture
Imagine the simulated system bolted to a heat bath through a single rubber band whose stiffness is the thermostat. If the system runs hot (kinetic energy above ) the feedback variable grows and applies a drag that bleeds energy out; if it runs cold, the same variable turns negative and pumps energy in. The Nosé–Hoover is exactly this self-adjusting friction, with its own inertia so the exchange is smooth and time-reversible rather than instantaneous. A stochastic thermostat is instead like randomly bumping particles: Andersen occasionally replaces a particle's velocity with a fresh Maxwell–Boltzmann draw, while Langevin continuously kicks each particle with white noise as friction removes the resulting drift. The single most important lesson — the owned thesis — is that equipartition is necessary but not sufficient. The bare Nosé–Hoover oscillator can satisfy while its trajectory is confined to a thin torus: the average temperature is right, but the distribution is wrong. This is not a numerical artifact but a genuine failure of ergodicity — a single feedback variable cannot supply enough mixing for a stiff system. Adding a chain of thermostats (each thermostatting the previous) breaks the residual conservation laws and restores the full Gaussian. A kinetic-temperature histogram makes the failure visible: bare or non-ergodic Nosé–Hoover gives too-narrow fluctuations, while a proper canonical thermostat reproduces the broad canonical distribution. Detailed balance and fluctuation–dissipation are what guarantee stochastic thermostats sample correctly. For the Langevin thermostat the noise strength and friction are locked, — the second-kind fluctuation–dissipation relation owned by the langevin-equation article — so the bumps and the drag conspire to leave the canonical density unchanged, and the non-degenerate noise makes the process ergodic where deterministic schemes get stuck. The barostat applies the same logic to volume: the box becomes a piston pushed outward by the internal pressure and inward by , its response time (not the precise piston mass ) being the physical knob.
The core equations
Bare Newtonian MD conserves and phase-space volume, so it samples the microcanonical ensemble — the starting point that everything modifies.
where: — position and momentum of degree of freedom ; — mass; — potential. The Nosé–Hoover thermostat adds a feedback friction that drives the time-averaged kinetic energy to its equipartition value.
where: — thermostat friction variable; — thermostat mass (reservoir inertia, units energy·time²); — number of physical degrees of freedom; — target thermal energy. The extended system conserves a quantity — not a true Hamiltonian in these variables, but a stringent numerical check analogous to energy conservation in .
where: — thermostat coordinate; — conserved extended "energy." The Langevin thermostat replaces feedback with friction plus white noise; the two are locked by the fluctuation–dissipation relation so the canonical density is stationary.
where: — friction coefficient (inverse coupling time); — unit-variance Gaussian white noise; — noise amplitude fixed by fluctuation–dissipation (owned by the langevin-equation article). The Andersen thermostat instead thermalizes by stochastic collisions, each drawing a fresh Maxwellian velocity — trivially detailed-balanced against the canonical density.
where: — stochastic collision frequency per particle; — Maxwell–Boltzmann velocity distribution at . The isotropic Andersen/MTK barostat promotes the volume to a piston driven by the pressure imbalance, giving (with a thermostat) the ensemble.
where: — logarithmic strain (volume) variable; — barostat (piston) mass; — instantaneous virial pressure; — external set pressure.
The goal here is to prove that the extended distribution is a stationary solution of the (compressible) Liouville equation generated by the Nosé–Hoover equations, so that its physical marginal is exactly canonical. The subtle point is that the Nosé–Hoover flow is non-Hamiltonian — its phase-space divergence does not vanish — so we must use the continuity equation with the compressibility term, and the whole argument hinges on an exact cancellation between that term and the convective derivative of the trial density.
Step 1. Compute the phase-space compressibility. For a non-Hamiltonian flow the density obeys . Only the friction term contributes to the divergence:
so the flow is compressible. Why : the friction acts on all momentum components, each contributing .
Step 2. Convective derivative of the trial density (independent of ):
Step 3. Evaluate the bracket. The Hamiltonian part gives , and . Adding them, the terms cancel, leaving . Hence , so .
Step 4. Combine with the compressibility term:
Why this is the whole result: the trial density is stationary — the cancellation is exact. Marginalizing over the Gaussian and the flat returns , the canonical ensemble, provided the flow is ergodic. Verified: the Nosé–Hoover conserved quantity is constant along a numerically integrated SHO+thermostat trajectory, confirming the flow, in verify_aq-sm-thermostats-md-ensembles.py.
Go deeper · Derivation B · 1 minLangevin thermostat: canonical stationary density fixes the noise amplitude
This derivation shows that the Langevin thermostat samples the canonical ensemble only when the noise strength and friction obey the fluctuation–dissipation relation — and that this same non-degenerate noise makes the process ergodic, curing the Nosé–Hoover pathology. We insert the canonical density into the Klein–Kramers (Fokker–Planck) equation of the Langevin dynamics and demand stationarity; the requirement pins the noise amplitude uniquely. The general fluctuation–dissipation content is owned by the langevin-equation and fluctuation-dissipation-theorem articles; here we use the result to fix the thermostat.
Step 1. Write the Klein–Kramers equation for one degree of freedom, , :
Step 2. Insert the canonical ansatz . The streaming (Hamiltonian) terms cancel identically because depends on only through . Why: a function of is annihilated by the Liouville streaming operator.
Step 3. Balance friction against diffusion. Using and , the remaining terms are
Step 4. Require this to vanish for all . The coefficient gives , and the constant term vanishes for the same . Why this is the fluctuation–dissipation relation: the noise variance is locked to the friction and temperature; mismatch them and the stationary temperature differs from the target. Because the noise is non-degenerate, the process is ergodic — it samples the full canonical density regardless of system stiffness, unlike bare Nosé–Hoover. Verified: the Langevin thermostat on a single harmonic degree of freedom samples with in verify_aq-sm-thermostats-md-ensembles.py.
Limiting cases
| Case | Result | Meaning |
|---|---|---|
| Coupling | The reservoir decouples; dynamics revert to microcanonical . Energy drifts only from integration error. | |
| Strong Langevin friction | Overdamped (Smoluchowski) limit: inertia irrelevant, dynamics diffusive, vibrational spectra lost — but sampling stays canonical. | |
| Andersen collision rate | or | Too small → poor thermalization (near-); too large → velocity correlations destroyed each step (unphysical). Optimal one collision per correlation time. |
| Bare Nosé–Hoover on SHO | Famously NON-ergodic — phase space splits into invariant tori. A Nosé–Hoover chain or stochastic thermostat is required. | |
| Barostat mass extremes | , (unstable) | Large piston mass freezes the volume (recovers ); vanishing mass gives runaway oscillations. |
Worked examples
Example 1 — Langevin thermostat samples the canonical variance. Integrate a single harmonic degree of freedom (, , ) under the Langevin thermostat with and noise , and verify the long-run kinetic energy.
Step 1. Noise amplitude. The fluctuation–dissipation lock gives , so .
Step 2. Canonical target. Equipartition predicts per degree of freedom, i.e. .
Step 3. Simulation. Integrating the Langevin SDE for steps (Euler–Maruyama, ) and time-averaging gives within Monte-Carlo error, and the velocity histogram matches the Maxwell–Boltzmann Gaussian of variance . The thermostat reproduces the exact canonical kinetic energy per degree of freedom — the correct distribution, not merely the correct mean.
Example 2 — Nosé–Hoover conserved quantity stays constant. For the same SHO with a Nosé–Hoover thermostat (, , ), check that the extended "energy" is conserved along the trajectory.
Step 1. Initial value. With , , , : .
Step 2. Time evolution. Integrating (2) with a time-reversible scheme, should be conserved to integrator accuracy. After steps the drift stays below , oscillating rather than growing — the same bounded behaviour as energy in a symplectic run.
Step 3. Interpretation. A conserved is the thermostat's analogue of energy conservation and the primary numerical health check; but — the owned caveat — even a perfectly conserved does not guarantee the physical marginal is canonical, because the bare scheme may be non-ergodic.
Origins · 1 minmolecular dynamics and how this was discovered
Going further
References. Frenkel & Smit, Understanding Molecular Simulation, 2nd ed., Ch. 6 · Tuckerman, Statistical Mechanics: Theory and Molecular Simulation, Ch. 4–5 · Nosé, J. Chem. Phys. 81, 511 (1984) · Hoover, Phys. Rev. A 31, 1695 (1985) · Andersen, J. Chem. Phys. 72, 2384 (1980) · Martyna, Klein & Tuckerman, J. Chem. Phys. 97, 2635 (1992) · Bussi, Donadio & Parrinello, J. Chem. Phys. 126, 014101 (2007) · Parrinello & Rahman, J. Appl. Phys. 52, 7182 (1981).
Provenance. A verifier should: (1) confirm the Nosé–Hoover stationarity cancellation and that is conserved along a numerically integrated trajectory; (2) reproduce the canonical solution of the Klein–Kramers equation fixing , and show the Langevin thermostat samples ; (3) note the non-ergodicity of the bare Nosé–Hoover harmonic oscillator. All expressions are analytic and textbook-standard. The fluctuation–dissipation relation and Langevin physics are owned by the langevin-equation and fluctuation-dissipation-theorem articles; MD integration by the molecular-dynamics article; the canonical ensemble by SM2.
Builds on: Molecular Dynamics Simulation · Langevin Equation and Stochastic Differential Equations · Fluctuation–Dissipation Theorem · Fokker–Planck Equation · Detailed Balance and Microscopic Reversibility. Leads to: Monte Carlo Method · Kinetic Theory and the Boltzmann Equation · Metropolis–Hastings Algorithm.
Why isn't velocity rescaling a valid thermostat?
Simple velocity rescaling (multiply all velocities by each step) forces the kinetic energy to a fixed value, which is exactly wrong: the canonical ensemble requires the kinetic energy to fluctuate with variance . Suppressing those fluctuations samples no well-defined ensemble and drains energy into center-of-mass motion (the "flying ice cube"). The Bussi–Donadio–Parrinello scheme fixes this by rescaling stochastically toward a target drawn from the correct canonical kinetic-energy distribution, restoring the right fluctuations while keeping the method simple.
What exactly goes wrong with the bare Nosé–Hoover oscillator?
For a single harmonic oscillator the Nosé–Hoover dynamics live in the 3D space (with decoupled). Numerically, for typical a large fraction of initial conditions lie on smooth invariant 2-tori: the trajectory never reaches the high- regions that correspond to the tails of the canonical density. Equipartition can still hold by symmetry, but the distribution is wrong. The single feedback variable simply cannot supply enough mixing — the effective dynamics are quasi-integrable. This is the textbook demonstration that a correct average is not a correct ensemble.
How does a Nosé–Hoover chain fix the non-ergodicity?
Instead of one thermostat variable, you couple to a second thermostat , and that to , and so on: , The chain destroys the spurious conservation laws that confine the bare scheme to tori, restoring ergodicity; a chain of length – suffices in practice (Martyna–Klein–Tuckerman 1992). One verifies, exactly as for the single thermostat, that is invariant, so the physical marginal remains canonical.
Deterministic or stochastic thermostat — how do I choose?
It depends on what you measure. Deterministic thermostats (Nosé–Hoover chains) preserve smooth, time-reversible trajectories, so they are preferred for dynamical quantities — Green–Kubo transport coefficients, spectra, correlation functions — where you do not want noise contaminating the dynamics. Stochastic thermostats (Langevin, Andersen, BDP) are provably ergodic and give strictly correct static sampling, ideal for equilibration and free-energy estimates, but their noise damps long-time correlations and must be kept weak (small ) if you also want dynamics. A common workflow: equilibrate stochastically, then run production with a Nosé–Hoover chain.
What does the barostat actually do to the equations of motion?
It promotes the volume (or the full cell matrix) to a dynamical variable with its own inertia , driven by the difference between the instantaneous internal (virial) pressure and the external set pressure: . The particle coordinates are simultaneously scaled with the box so that fractional positions are preserved. When the box expands; equilibrium is reached at . Combined with a thermostat this yields the ensemble. The Parrinello–Rahman variant lets the box change shape as well as size, which is essential for capturing anisotropic stress and solid–solid structural transitions.
Why does the Andersen thermostat trivially satisfy detailed balance?
Because each Andersen "collision" replaces a particle's velocity with a fresh draw from the equilibrium Maxwell–Boltzmann distribution — the very distribution the canonical ensemble assigns to that velocity. Proposing a move directly from the target distribution means the acceptance is effectively unity and the canonical density is left invariant. Between collisions the dynamics are ordinary energy-conserving Newtonian motion, and the collisions are Poisson events at rate . The trade-off is that each collision erases that particle's velocity memory, so too-frequent collisions destroy the physical dynamics — the collision rate must be tuned to about one per correlation time.