Learn

Statistical mechanics

MD gives positions and velocities. Statistical mechanics turns them into temperature, pressure, free energy, and heat capacity. Every number from a simulation depends on these ideas, even when nobody mentions them.

    The Boltzmann distribution

    At equilibrium, a state with energy U is visited with probability proportional to e−U/kT. Low energy states are favored, but how strongly they are favored depends on temperature. At high T, the system spreads out, and at low T, it sits in the minima.

    P(x) = e−U(x)/kT / Z, Z = ∫ e−U(x)/kT dx

    The normalization Z is the partition function. Everything thermodynamic can be derived from it, and the free energy is F = −kT ln Z. Turned around, any histogram from a simulation gives a free energy profile, F(x) = −kT ln P(x), which is the idea behind most of enhanced sampling.

    Try: tilt the well and watch the population move to the lower side. Then lower kT and see that the same tilt matters much more.

    Velocities and equipartition

    Every quadratic term in the energy carries kT/2 on average. This is equipartition, and it is why MD can read the temperature from the kinetic energy. In 3D, <½mv2> = 3kT/2 per atom, minus the constrained degrees of freedom, which are a classic source of small errors in reported temperatures.

    The velocities themselves follow the Maxwell-Boltzmann distribution, whatever the potential. You never have to put it in by hand, because collisions produce it.

    3D: P(v) = 4πv2 (m/2πkT)3/2 e−mv²/2kT 2D: P(v) = (mv/kT) e−mv²/2kT

    Try: all particles start at the same speed, so the histogram begins as one spike. Watch it relax to the dashed curve within a few collision times, and note that x and y share the energy equally.

    Ensembles and fluctuations

    An isolated system (NVE, the microcanonical ensemble) has a fixed energy. A system in contact with a heat bath (NVT, canonical) exchanges energy, so its energy fluctuates. These fluctuations are not noise to be removed. They are a property of the system, as the heat capacity shows.

    CV = (<E2> − <E>2) / kT2

    The same pattern holds for other ensembles. Volume fluctuations in NPT give the compressibility, and so do particle number fluctuations in the grand canonical ensemble. The relative size of fluctuations shrinks like 1/√N, which is why ensembles agree on averages for large systems but not for small ones.

    This is also why a thermostat that suppresses fluctuations, such as Berendsen, gives the right average temperature but the wrong heat capacity. See the thermostats section.

    Try: switch the bath off, and the energy freezes (NVE). Switch it on, and compare the heat capacity from the fluctuations with the exact value of 2N. Then, change N and watch the trace get smoother.

    Entropy and the second law

    Entropy counts how many microscopic arrangements belong to the same macroscopic state, S = k ln Ω. A gas squeezed into one corner has far fewer arrangements than one filling the box, so spreading out is overwhelmingly likely.

    The equations of motion are time-reversible, yet entropy only goes up. The answer is that the second law is statistical. Going back is not forbidden, but it is extremely unlikely for a random start. Reversing every velocity at once is the one way to do it, and MD can do that exactly, which no experiment can.

    Try: let the gas spread, and then click to reverse all velocities. The gas walks back into its corner, and the entropy drops. With more particles, wait longer before reversing. Small rounding errors grow, and the return becomes less perfect.

    Ergodicity: time averages and ensemble averages

    Statistical mechanics averages over the ensemble, which means all states with their Boltzmann weights. MD averages over time along one trajectory. The two agree only if the trajectory visits all the relevant states, which is the ergodic hypothesis.

    In practice, the danger is not strict non-ergodicity, but barriers. The waiting time to cross a barrier grows like eΔU/kT, so a barrier of 10 kT can already hold a simulation in one state for its whole length. The averages then look converged, with small error bars, and are still wrong.

    Try: at h = 3, the running average settles near zero. At h = 8, the particle stays on one side, and the average sits near −1, which looks certain but is wrong. This is the problem that enhanced sampling solves.