Physics and statistical mechanics

The mechanics of particles and the statistical mechanics built on it: entropy and temperature, the Boltzmann distribution, ensembles and free energy, fluctuations, phase transitions and liquids.

Mechanics

Newtonian and Hamiltonian mechanics, phase space, and quantised energy levels.

1Classical mechanics and phase space

The classical mechanics every simulation rests on: velocity and momentum, Newton's second law, forces as slopes of a potential, conservation of energy, and phase space, the map in which a whole motion becomes a single curve. Hamilton's equations included.

about 12 min read

Why start with a ball on a hill

A molecular dynamics simulation of a protein or a crystal follows millions of atoms, but each atom obeys the same laws as a single ball rolling in a valley. If you understand one particle moving in one dimension, its position, velocity, momentum, force and energy, and the picture called phase space, you understand what every MD code computes, and why its results can be trusted. This chapter builds that picture.

Describing motion

The position x(t)x(t) says where the particle is at time tt. Its rate of change is the velocity, and the rate of change of velocity is the acceleration:

v=dxdt=x˙,a=dvdt=x¨. v = \frac{\mathrm dx}{\mathrm dt} = \dot x, \qquad a = \frac{\mathrm dv}{\mathrm dt} = \ddot x .

Newton recognised that the quantity a force changes is not velocity alone but velocity weighted by how much matter is moving, the momentum:

The second law is a differential equation: given the position and velocity now, and the force as a function of position, it determines the entire future and past. This determinism is what lets a computer predict motion step by step.

Forces from a landscape

For atoms, forces are not arbitrary: they come from a potential energy V(x)V(x), a landscape that depends on where the particles are (the chapter on potential energy surfaces shows where atomic landscapes come from). The force is the downhill slope:

Three landscapes appear in the lab. A spring, V=12kx2V = \tfrac12 kx^2, gives a force F=−kxF = -kx that always pulls back towards the centre (Hooke’s law), the model of a chemical bond near equilibrium. A double well has two valleys separated by a barrier, the simplest model of a chemical reaction, a conformational change or a phase transition. A pendulum, V=1−cos⁡xV = 1 - \cos x, is a model of a rotating chemical group with a periodic barrier.

A particle in a potential, and its path in phase space

Loading the interactive figure…

Left: the landscape V(x), the particle, its force (orange arrow) and velocity (teal arrow), and a bar showing kinetic (K) and potential (V) energy. Right: phase space, momentum against position. Click in the phase plane to start a new motion; add friction and watch the trajectory spiral inwards.

Energy, and why it is conserved

Watch the energy bar while the particle moves. As it rolls downhill, potential energy turns into kinetic energy K=12mv2=p2/2mK = \tfrac12 mv^2 = p^2/2m; as it climbs, kinetic turns back into potential; and without friction their sum never changes.

Conservation gives a lot for free. The particle can only be where V(x)≤EV(x) \le E; the points where V(x)=EV(x) = E are turning points, where it momentarily stops and reverses. With EE below the barrier of the double well, it is trapped in one valley forever; above it, it crosses back and forth. In molecular dynamics, the fact that a correct integrator keeps the total energy constant is the first and most important test of a simulation (the MD chapter).

Add friction in the lab: energy now leaks away, and the particle settles into a minimum. That is what an energy minimisation does to a structure, and what a thermostat has to counteract when it adds the right amount of random kicks back.

Phase space

Here is the central picture of this volume. The state of the particle at any instant is not its position alone, because two particles at the same place moving in opposite directions have different futures. The complete state is the pair (x,p)(x, p), a point in a plane called phase space. Newton’s law moves that point along a curve, the trajectory, and because the state determines the future uniquely, trajectories never cross.

Since energy is conserved, the trajectory stays on a curve of constant EE: the energy contour p=±2m(E−V(x))p = \pm\sqrt{2m(E - V(x))}. In the lab:

  • the spring gives ellipses: the particle oscillates forever around the centre;
  • the double well shows two families of loops, one inside each valley, enclosed by a figure-of-eight called the separatrix; outside it, large loops circle both valleys;
  • the pendulum shows closed loops (swinging) inside wavy open curves (rotating all the way round);
  • friction turns closed loops into spirals that end at a minimum.

For NN atoms in three dimensions phase space has 6N6N dimensions, three positions and three momenta per atom, and a molecular dynamics run traces one trajectory through it. Statistical mechanics, the subject of the chapters after next, is the art of saying what fraction of that enormous space a system visits.

Hamilton’s formulation

Writing the energy as a function of position and momentum, H(x,p)=p2/2m+V(x)H(x, p) = p^2/2m + V(x), called the Hamiltonian, puts Newton’s law in a beautifully symmetric form:

Hamiltonian flow has a deep property, Liouville’s theorem: a small blob of initial conditions changes shape as it flows but never changes its area (volume, in many dimensions). This is why the integrators used in molecular dynamics are built to be symplectic, preserving phase-space volume exactly, and it is the foundation on which statistical mechanics builds its probabilities.

Check yourself

  1. A particle sits at a point where V(x)V(x) has its minimum. What is the force on it?
  2. In the harmonic potential, what shape is a trajectory in phase space?
  3. Why can two different phase-space trajectories never cross?
  4. In the double well, the particle’s energy is just below the barrier top. What happens?

References and further reading

  1. L. D. Landau and E. M. Lifshitz, Mechanics, 3rd ed., Course of Theoretical Physics vol. 1, Butterworth-Heinemann (1976), chapters 1–2 and 7.
  2. J. R. Taylor, Classical Mechanics, University Science Books (2005), chapters 1–4 and 13 (Hamiltonian mechanics).
  3. H. Goldstein, C. P. Poole and J. L. Safko, Classical Mechanics, 3rd ed., Addison-Wesley (2002), chapters 8–9.
  4. M. E. Tuckerman, Statistical Mechanics: Theory and Molecular Simulation, 2nd ed., Oxford University Press (2023), chapter 1 (classical mechanics, phase space and Liouville’s theorem).
  5. R. P. Feynman, R. B. Leighton and M. Sands, The Feynman Lectures on Physics, vol. I, chapters 9 and 14 (Newton’s laws, work and potential energy), free online at feynmanlectures.caltech.edu.

2Quantum energy levels

Why energy comes in steps: the Schrödinger equation, the particle in a box, the harmonic oscillator and zero-point energy, how quantum turns into classical at high energy, and how temperature populates the levels. The bridge from quantum mechanics to statistical mechanics.

about 13 min readBuilds on Classical mechanics and phase space

Why a simulation chapter needs quantum mechanics

Molecular dynamics moves nuclei with Newton’s laws, as in the previous chapter. Yet the forces between atoms come from electrons, which obey quantum mechanics, and even the nuclei are quantum particles. This chapter answers two questions every simulator should be able to answer. Where does quantisation come from? And when is it safe to forget about it?

Waves of matter

In 1924 de Broglie proposed that every particle with momentum pp behaves like a wave of wavelength λ=h/p\lambda = h/p, where h=6.626×10−34h = 6.626 \times 10^{-34} J s is Planck’s constant. For a cricket ball the wavelength is absurdly small; for an electron in an atom it is about the size of the atom, and wave behaviour dominates. The state of a quantum particle is described by a wavefunction ψ(x)\psi(x), and the probability of finding the particle near xx is ∣ψ(x)∣2 dx|\psi(x)|^2\,\mathrm dx (Born’s rule).

States of definite energy satisfy the time-independent Schrödinger equation, in which the classical energy p2/2m+Vp^2/2m + V becomes an operator:

The equation itself is not mysterious: it says that a wave curves more sharply where the kinetic energy E−VE - V is larger. What creates quantisation is the boundary condition. A confined wave has to fit inside its container, like the standing wave on a guitar string, and only a discrete set of wavelengths do.

The particle in a box

Trap a particle between two impenetrable walls, V=0V = 0 for 0<x<L0 < x < L and V=∞V = \infty outside. The wavefunction must vanish at both walls, so it must be a sine wave with a whole number of half-wavelengths in the box:

Three consequences matter for materials. Energy is quantised. The lowest energy is not zero: squeezing a particle into a small space forces short wavelengths and therefore kinetic energy, the reason electrons do not collapse into the nucleus. And the spacing falls as 1/L21/L^2, so in a big box the levels are so close that the energy looks continuous. Quantum dots exploit the 1/L21/L^2 law: the smaller the nanocrystal, the larger its gap and the bluer its light.

The harmonic oscillator

Near the bottom of any valley the potential is a parabola, V=12mω2x2V = \tfrac12 m\omega^2 x^2, so the harmonic oscillator describes every chemical bond vibration and every phonon in a crystal. Its levels are equally spaced:

Energy levels, wavefunctions and thermal populations

Loading the interactive figure…

Left: the potential (blue), the levels (dashed) and each level’s wavefunction drawn at its energy; the highlighted level is orange. Switch to |ψ|² and turn on the classical overlay to compare with where a classical particle of the same energy spends its time. The bars show how temperature shares the system among the levels (units with ħ = m = 1).

Zero-point energy is measurable and important. It is why liquid helium does not freeze at normal pressure, it shifts reaction barriers and bond lengths, and it makes deuterated molecules react more slowly than ordinary ones (the kinetic isotope effect), because the heavier isotope has a lower 12ℏω\tfrac12\hbar\omega.

From quantum to classical

Highlight a high level in the lab and switch to ∣ψ∣2|\psi|^2. The quantum probability oscillates rapidly, but its average follows the teal dashed curve, the classical probability density: a classical oscillator moves fastest through the centre and slowest near the turning points, so it spends most of its time near the edges,

ρcl(x)=1πa2−x2,a=amplitude. \rho_{\text{cl}}(x) = \frac{1}{\pi\sqrt{a^2 - x^2}}, \qquad a = \text{amplitude}.

At high quantum number the two agree, as Bohr’s correspondence principle demands. Quantum effects matter when the level spacing is comparable to the energy available, and that brings temperature in.

Temperature populates the levels

At temperature TT a system in contact with its surroundings occupies level nn with a probability given by the Boltzmann distribution, derived in the chapter on Boltzmann and Maxwell:

Slide the temperature in the lab. When kBT≪ℏωk_BT \ll \hbar\omega almost everything sits in the ground state, and the oscillator is frozen: it cannot absorb heat, and its thermal energy is pinned at the zero-point value. When kBT≫ℏωk_BT \gg \hbar\omega many levels are populated, and the mean energy approaches the classical value kBTk_BT (for the box, kBT/2k_BT/2), as the statistics row shows.

The numbers for real molecules are revealing. A C–H stretch vibrates at about 3000 cm⁻¹, so ℏω/kBT≈14\hbar\omega/k_BT \approx 14 at room temperature and the ground state holds 99.9999 % of the molecules: that vibration is completely quantum. A soft torsion or lattice mode at 200 cm⁻¹ has ℏω/kBT≈1\hbar\omega/k_BT \approx 1, and is close to classical. Einstein used exactly this freezing-out to explain in 1907 why the heat capacity of solids falls at low temperature.

Is classical molecular dynamics allowed?

Classical MD treats nuclei as points obeying Newton’s laws, so it gives each vibration kBTk_BT of energy whether or not it should. A useful yardstick is the thermal de Broglie wavelength, the typical quantum blur of a particle at temperature TT:

The verdict is that classical dynamics of nuclei is accurate for heavy atoms and for structure, diffusion and most thermodynamics at room temperature. It fails for light atoms (hydrogen, lithium), for high-frequency vibrations, for low temperatures and for heat capacities. The remedies are to constrain stiff bonds (as most biomolecular force fields do with bonds to hydrogen), to apply quantum corrections afterwards, or to use path-integral MD, which represents each quantum nucleus as a ring of classical beads.

Check yourself

  1. You halve the length of a box. What happens to its energy levels?
  2. What is the lowest energy of a quantum harmonic oscillator?
  3. A vibration has ℏω=10 kBT\hbar\omega = 10\,k_BT. Which statement is right?
  4. For which system is classical MD of the nuclei most questionable at room temperature?

References and further reading

  1. D. J. Griffiths and D. F. Schroeter, Introduction to Quantum Mechanics, 3rd ed., Cambridge University Press (2018), chapter 2 (infinite square well, harmonic oscillator).
  2. P. Atkins and R. Friedman, Molecular Quantum Mechanics, 5th ed., Oxford University Press (2011), chapters 2–3.
  3. D. V. Schroeder, An Introduction to Thermal Physics, Addison-Wesley (2000), chapter 6 (Boltzmann statistics, equipartition and its failure).
  4. A. Einstein, “Die Plancksche Theorie der Strahlung und die Theorie der spezifischen Wärme”, Annalen der Physik 22, 180 (1907).
  5. L. de Broglie, Recherches sur la théorie des quanta, thesis, Paris (1924); Annales de Physique 3, 22 (1925).
  6. M. E. Tuckerman, Statistical Mechanics: Theory and Molecular Simulation, 2nd ed., Oxford University Press (2023), chapter on quantum statistical mechanics and path integrals.
  7. T. E. Markland and M. Ceriotti, “Nuclear quantum effects enter the mainstream”, Nature Reviews Chemistry 2, 0109 (2018).

Statistical mechanics

Entropy and temperature, the Boltzmann distribution, ensembles and free energy, fluctuations, phase transitions and liquid structure.

3Entropy and temperature

Statistical mechanics from scratch: microstates and macrostates, counting them in an Einstein solid, why energy flows from hot to cold, entropy as S = k ln Ω, and temperature defined as the rate at which entropy grows with energy.

about 12 min readBuilds on Quantum energy levels

The question statistical mechanics answers

A glass of water contains about 102510^{25} molecules. Following every one is hopeless, and also unnecessary: we want the temperature, the pressure, the heat capacity, whether ice melts. Statistical mechanics connects the microscopic world of quantum levels and phase-space trajectories to those few macroscopic numbers. The whole subject rests on a single idea, which this chapter makes concrete by counting.

Microstates and macrostates

A microstate is a complete specification of the system: which quantum level every particle occupies, or every position and momentum. A macrostate is what we measure: total energy, volume, number of particles. One macrostate corresponds to an enormous number of microstates, written Ω\Omega (the multiplicity).

The single assumption of statistical mechanics, the fundamental postulate, is that an isolated system in equilibrium is equally likely to be found in any of its accessible microstates. Everything else, including the second law of thermodynamics, follows by counting.

Counting energy in a solid

Einstein’s model of a solid treats each atom’s vibration as quantum harmonic oscillators with the same frequency, so energy comes in identical quanta ε=ℏω\varepsilon = \hbar\omega. A microstate says how many quanta each oscillator holds. With NN oscillators and qq quanta, the number of microstates is the number of ways to drop qq identical balls into NN boxes:

The ten microstates of the example are easy to list: (3,0,0) in three arrangements, (2,1,0) in six, and (1,1,1) in one. Multiplicities grow at a ferocious rate: 100 oscillators sharing 100 quanta already have about 5×10585 \times 10^{58} microstates.

Two solids in contact

Now put two solids, A and B, in thermal contact so that quanta can hop between them while the total qq stays fixed. A macrostate is now “how many quanta are in A”, and since every microstate of the whole is equally likely, the probability of a macrostate is proportional to its multiplicity,

P(qA)∝ΩA(NA,qA)  ΩB(NB,q−qA). P(q_A) \propto \Omega_A(N_A, q_A)\;\Omega_B(N_B, q - q_A).

Two Einstein solids sharing energy

Loading the interactive figure…

Left: the probability of every way of splitting the quanta, computed exactly by counting; the orange line marks the current state. Right: the oscillators (blue borders belong to solid A, teal to solid B) and the history of q_A while quanta hop at random. Start with all the energy in A and let it go.

Press the button and watch. Every hop moves one quantum from a random oscillator to another random oscillator, and nothing in the rule prefers either solid. Yet the energy flows out of A until A’s share fluctuates around the peak of the probability curve, and it never comes back. For the default settings (60 and 40 oscillators, 100 quanta) the peak is at qA=60q_A = 60 with a spread of about ±7\pm 7, while the probability of finding all 100 quanta back in A is about 5×10−155 \times 10^{-15}.

That is the second law of thermodynamics, and nothing more: energy flows to the macrostate with overwhelmingly more microstates, simply because there are overwhelmingly more ways to be there. Increase the sizes in the lab and the peak becomes narrower in relative terms, its width falling as 1/N1/\sqrt N. For 102310^{23} oscillators the fluctuations are invisible and the macrostate behaves as if it were exact.

Entropy

Multiplicities multiply when systems are combined, Ω=ΩAΩB\Omega = \Omega_A\Omega_B. It is more convenient to work with a quantity that adds, so Boltzmann defined the entropy as the logarithm of the multiplicity:

This equation is carved on Boltzmann’s tombstone in Vienna. Entropy is not a measure of “disorder” in any vague sense: it is the logarithm of a count.

Temperature

What decides where the peak lies? At the maximum of ln⁡ΩA+ln⁡ΩB\ln\Omega_A + \ln\Omega_B, moving one quantum from B to A leaves the total unchanged, so

∂ln⁡ΩA∂UA=∂ln⁡ΩB∂UB. \frac{\partial \ln \Omega_A}{\partial U_A} = \frac{\partial \ln \Omega_B}{\partial U_B}.

The two solids are in equilibrium when this quantity is the same for both. That shared quantity is what a thermometer measures, and it defines temperature:

The lab prints the temperature of each solid, computed from the exact counts. Start with all energy in A: A is hot and B is cold. As quanta flow, the two temperatures move towards each other and meet where the probability peaks. Energy flows from hot to cold because the cold body gains more entropy per quantum than the hot body loses; the total entropy rises until it can rise no further.

From counting to thermodynamics

Everything in classical thermodynamics follows from S(U,V,N)S(U, V, N). Differentiating with respect to volume and particle number gives pressure and chemical potential,

dS=1T dU+PT dV−μT dN, \mathrm dS = \frac{1}{T}\,\mathrm dU + \frac{P}{T}\,\mathrm dV - \frac{\mu}{T}\,\mathrm dN,

which is the thermodynamic identity dU=T dS−P dV+μ dN\mathrm dU = T\,\mathrm dS - P\,\mathrm dV + \mu\,\mathrm dN. This isolated-system picture, fixed NN, VV and EE, is the microcanonical ensemble, and it is exactly what an MD simulation without a thermostat samples (the NVE ensemble). For classical particles, Ω\Omega becomes the volume of the shell of phase space with energy EE, measured in units of h3Nh^{3N}.

Check yourself

  1. How many microstates do 2 oscillators sharing 3 quanta have?
  2. In the lab, why does energy not flow back into solid A?
  3. Two systems are in contact. System 1 gains more entropy per joule than system 2 loses. Which way does heat flow?
  4. What happens to the relative width of the probability peak as the solids get larger?

References and further reading

  1. D. V. Schroeder, An Introduction to Thermal Physics, Addison-Wesley (2000), chapters 2–3. The two-solid example here follows his treatment.
  2. T. A. Moore and D. V. Schroeder, “A different approach to introducing statistical mechanics”, American Journal of Physics 65, 26 (1997).
  3. A. Einstein, “Die Plancksche Theorie der Strahlung und die Theorie der spezifischen Wärme”, Annalen der Physik 22, 180 (1907).
  4. L. Boltzmann, “Über die Beziehung zwischen dem zweiten Hauptsatze der mechanischen Wärmetheorie und der Wahrscheinlichkeitsrechnung respektive den Sätzen über das Wärmegleichgewicht”, Wiener Berichte 76, 373 (1877).
  5. F. Reif, Fundamentals of Statistical and Thermal Physics, McGraw-Hill (1965), chapters 2–3.
  6. M. E. Tuckerman, Statistical Mechanics: Theory and Molecular Simulation, 2nd ed., Oxford University Press (2023), chapter 3 (the microcanonical ensemble).

4The Boltzmann distribution

From counting microstates to the most useful formula in statistical mechanics: the Boltzmann factor and the partition function, the Maxwell–Boltzmann distribution of speeds, equipartition of energy, and pressure from molecular collisions, all watched emerging in a simulated gas.

about 13 min readBuilds on Entropy and temperature

From an isolated system to one at a temperature

The previous chapter treated an isolated system: fixed energy, every microstate equally likely. Real samples, and most simulations, are instead in contact with surroundings at a fixed temperature, which can lend and borrow energy. What is the probability of finding a small system in a particular microstate then? The answer, the Boltzmann distribution, is used in every corner of chemistry and materials science.

Deriving the Boltzmann factor

Let a small system share energy with a huge reservoir, with total energy EtotE_{\text{tot}} fixed. When the system is in a particular microstate ss with energy EsE_s, the reservoir has energy Etot−EsE_{\text{tot}} - E_s, and the combined system is still isolated, so every joint microstate is equally likely. The probability of ss is therefore proportional to the number of reservoir microstates compatible with it:

P(s)∝ΩR(Etot−Es)=eSR(Etot−Es)/kB. P(s) \propto \Omega_R(E_{\text{tot}} - E_s) = e^{S_R(E_{\text{tot}} - E_s)/k_B}.

Because the reservoir is huge, EsE_s is a tiny change for it, and a first-order Taylor expansion is exact in the limit: SR(Etot−Es)≈SR(Etot)−Es ∂SR/∂E=SR(Etot)−Es/TS_R(E_{\text{tot}} - E_s) \approx S_R(E_{\text{tot}}) - E_s\,\partial S_R/\partial E = S_R(E_{\text{tot}}) - E_s/T. The constant first term cancels on normalising, which leaves one of the great results of physics:

This is the canonical ensemble (fixed NN, VV, TT), the ensemble a thermostatted MD run samples (NVT). Its consequences are everywhere: vibrational populations, the Arrhenius law k∝e−Ea/kBTk \propto e^{-E_a/k_BT} for reaction rates, vacancy concentrations in crystals, the exponential thinning of the atmosphere with height.

The partition function knows everything

ZZ looks like a mere normalising constant, but all of thermodynamics can be extracted from it by differentiation. With β=1/kBT\beta = 1/k_BT:

For a classical particle the sum over states becomes an integral over phase space, Z=1h3NN!∫e−H(r,p)/kBT dr dpZ = \frac{1}{h^{3N}N!}\int e^{-H(\mathbf r, \mathbf p)/k_BT}\,\mathrm d\mathbf r\,\mathrm d\mathbf p. Because H=K(p)+V(r)H = K(\mathbf p) + V(\mathbf r), the integral splits into a momentum part, which can always be done exactly, and a configurational part, which is the hard part that MD and Monte Carlo exist to sample.

The speeds of molecules

The momentum part gives a striking prediction. Each velocity component has a Boltzmann weight e−mvx2/2kBTe^{-mv_x^2/2k_BT}, a Gaussian. Combining the components and counting how many velocity vectors have the same speed (a circle of circumference 2πv2\pi v in 2D, a sphere of area 4πv24\pi v^2 in 3D) gives the Maxwell–Boltzmann distribution of speeds:

Maxwell derived this in 1860 from symmetry arguments alone, before anyone could measure molecular speeds. The lab lets you watch it happen.

A gas of hard disks finds its own distribution

Loading the interactive figure…

Left: 160 disks in a box, coloured by speed, colliding elastically. Right: a histogram of their speeds against the 2D Maxwell–Boltzmann curve for the current temperature. Every particle starts with exactly the same speed; collisions alone produce the distribution. Tick “two species” to watch heavy and light particles share energy.

Restart and look at the histogram. At first every particle has the same speed, a single spike. Within a few hundred collisions the spike spreads into exactly the Maxwell–Boltzmann shape, though nothing in the program knows that curve: collisions conserve energy and momentum, and the distribution is simply the one with the most microstates. This is the second law happening in front of you. Boltzmann’s H-theorem (1872) proved that collisions drive any initial distribution towards this one.

Equipartition

Now tick “two species”. The orange particles are four times heavier but start with the same speed, so each carries four times the kinetic energy of a light particle. Watch the readout of mean kinetic energy: within a short time the two species have the same average kinetic energy, and the heavy particles move half as fast. This is the equipartition theorem:

Equipartition is how MD codes measure temperature. They compute the instantaneous kinetic temperature T=2⟨K⟩Ndf kBT = \frac{2\langle K \rangle}{N_{\text{df}}\,k_B}, with NdfN_{\text{df}} the number of degrees of freedom (about 3N3N, less any constraints), and a thermostat nudges velocities to keep it near the target. It also explains the classical-MD error discussed earlier: equipartition gives every vibration kBTk_BT, even those that quantum mechanics would freeze.

Pressure from collisions

Pressure is the momentum delivered to the walls per unit time per unit area. A particle bouncing off a wall reverses its normal velocity and delivers momentum 2m∣vx∣2m|v_x|. Averaging over the Maxwell–Boltzmann distribution gives the ideal gas law:

The lab measures pressure by adding up the momentum transferred to the walls. Compare it with the ideal-gas value: the measured pressure is somewhat higher, because the disks have a finite size and the free area is smaller than the box. That is the excluded-volume correction in van der Waals’s equation, and the starting point of the theory of real gases and liquids. In MD, pressure is computed from the virial, PV=NkBT+1d⟨∑iri⋅Fi⟩PV = Nk_BT + \frac{1}{d}\left\langle \sum_i \mathbf r_i \cdot \mathbf F_i \right\rangle in dd dimensions, which adds the interparticle forces to the kinetic term (the MD chapter).

Check yourself

  1. State A lies 2 kBT2\,k_BT above state B. What is the ratio of their probabilities PA/PBP_A/P_B?
  2. Why is the most probable speed in a 3D gas not zero, even though zero speed has the largest Boltzmann factor?
  3. Helium (4 u) and xenon (131 u) are mixed at the same temperature. Which statement is true?
  4. How does an MD code compute the instantaneous temperature?

References and further reading

  1. D. V. Schroeder, An Introduction to Thermal Physics, Addison-Wesley (2000), chapter 6 (Boltzmann factor, partition function, equipartition, the Maxwell speed distribution).
  2. J. C. Maxwell, “Illustrations of the dynamical theory of gases”, Philosophical Magazine 19, 19 (1860).
  3. L. Boltzmann, “Weitere Studien über das Wärmegleichgewicht unter Gasmolekülen”, Wiener Berichte 66, 275 (1872).
  4. D. Chandler, Introduction to Modern Statistical Mechanics, Oxford University Press (1987), chapter 3.
  5. D. Frenkel and B. Smit, Understanding Molecular Simulation, 3rd ed., Academic Press (2023), chapter 2 (statistical mechanics for simulation: temperature and pressure estimators).
  6. M. P. Allen and D. J. Tildesley, Computer Simulation of Liquids, 2nd ed., Oxford University Press (2017), chapter 2.

5Ensembles and free energy

The canonical ensemble in depth: the partition function as a sum of Boltzmann weights and the generator of all thermodynamics; energy, entropy, heat capacity and the Gibbs entropy formula; free energy as the competition between energy and entropy; free-energy profiles and the potential of mean force; the classical partition function, the ideal gas and the Sackur–Tetrode entropy; and the isothermal–isobaric and grand canonical ensembles.

about 24 min readBuilds on The Boltzmann distribution, Integrals

Ensembles

An experiment never controls the microscopic state of a sample. It controls a few macroscopic quantities, such as the temperature, the pressure or the number of molecules, and the sample explores all the microstates compatible with those constraints. Statistical mechanics describes this exploration with an ensemble: an imagined collection of infinitely many copies of the system, each in a different microstate, with the copies distributed according to the probability of each microstate under the given conditions. The average of any quantity over the ensemble is what an experiment measures.

The chapter on entropy used the microcanonical ensemble, which describes an isolated system with fixed number of particles NN, volume VV and energy EE, and in which every accessible microstate is equally likely. The chapter on the Boltzmann distribution derived the canonical ensemble for a system at fixed NN, VV and temperature TT, in contact with a heat bath, and showed that a microstate of energy EsE_s occurs with probability proportional to e−Es/kBTe^{-E_s/k_BT}. This chapter develops the canonical ensemble fully, because it is the ensemble of most experiments and of most simulations, and then introduces the ensembles at constant pressure and at constant chemical potential.

Different ensembles describe different experimental conditions, but for large systems they give the same thermodynamics, because the fluctuations that distinguish them are tiny compared with the averages; this is called the equivalence of ensembles. The choice is therefore a matter of convenience: one picks the ensemble in which the calculation is easiest or the simulation most natural.

The partition function

In the canonical ensemble the probability of microstate ss is

The partition function ZZ looks like a mere normalising constant, but it is the central object of statistical mechanics. Its name is apt: it describes how the system’s probability is partitioned among its states. At low temperature only the lowest states have appreciable weight and ZZ is close to the degeneracy of the ground state. As the temperature rises, more states acquire weight and ZZ grows; roughly, ZZ counts the number of states the system can effectively reach at temperature TT.

The figure below makes this concrete. Each energy level contributes a weight gie−βEig_i e^{-\beta E_i}, drawn as a gold bar; the weights add up to ZZ, and each level’s share of the total is its probability. Lower the temperature and the weights of the excited levels collapse exponentially; raise it and they approach their degeneracies.

The partition function as a sum of Boltzmann weights

Loading the interactive figure…

Left: the energy levels, with dots for their degeneracy. Middle: each level’s Boltzmann weight. Right: the weights stacked into Z, showing each level’s probability. Bottom: the mean energy U, the entropy S and the heat capacity C as functions of temperature (each scaled to its maximum); the dashed line is the current temperature. With ‘your own levels’ you can drag the levels up and down.

Partition functions factorise in a way that makes them practical. If a system consists of independent parts, its energy is a sum of their energies, so each Boltzmann factor is a product and Z=z1z2⋯Z = z_1 z_2 \cdots. A molecule’s partition function factorises approximately into translational, rotational, vibrational and electronic parts, z=ztrans zrot zvib zelecz = z_{\text{trans}}\,z_{\text{rot}}\,z_{\text{vib}}\,z_{\text{elec}}, each computed separately; this is how thermodynamic tables of gases are calculated from spectroscopic data. For NN identical, non-interacting molecules, Z=zN/N!Z = z^N/N!, where the N!N! corrects for the fact that exchanging identical molecules does not produce a new microstate.

Thermodynamics from the partition function

Every thermodynamic quantity follows from ln⁡Z\ln Z by differentiation. The derivations are short, and they explain what each quantity means.

The mean energy formula follows because differentiating Z=∑e−βEsZ = \sum e^{-\beta E_s} with respect to β\beta brings down a factor −Es-E_s in each term, so −∂ln⁡Z/∂β=∑Ese−βEs/Z=⟨E⟩-\partial \ln Z/\partial\beta = \sum E_s e^{-\beta E_s}/Z = \langle E\rangle. Differentiating again gives the variance of the energy, which is why the heat capacity equals the energy fluctuations divided by kBT2k_BT^2: a system can absorb heat only if it has states at nearby energies to move into, and the same states allow its energy to fluctuate. This fluctuation formula is how heat capacities are computed from simulations, and the chapter on fluctuations develops it.

The entropy formula S=−kB∑psln⁡psS = -k_B\sum p_s \ln p_s, the Gibbs entropy, generalises Boltzmann’s S=kBln⁡ΩS = k_B \ln \Omega. If all Ω\Omega accessible states are equally likely, each ps=1/Ωp_s = 1/\Omega and the sum reduces to kBln⁡Ωk_B \ln\Omega. If the probabilities are uneven, the entropy is lower, because the system is effectively confined to fewer states. The same expression, without kBk_B, is Shannon’s measure of information, which is why entropy is often described as missing information about the microstate.

The figure’s bottom panel shows these quantities for each system. For the two-level system, the heat capacity rises from zero, peaks and falls again. This Schottky anomaly occurs because at low temperature the excited level is out of reach, and at high temperature both levels are already equally populated, so further heating changes nothing; only in between can the system absorb energy. The peak lies at kBT≈0.42 Δk_BT \approx 0.42\,\Delta for a level spacing Δ\Delta, and such peaks are measured in magnetic materials and used to determine their energy levels. For the harmonic oscillator, the heat capacity rises from zero to the classical value kBk_B, the freezing-out of vibrations described in the chapter on quantum energy levels.

Free energy: energy against entropy

The Helmholtz free energy F=U−TSF = U - TS is the quantity a system at constant temperature minimises. Its two terms pull in opposite directions. The energy term favours the states of lowest energy: atoms packed in a crystal, a protein in its folded form, a molecule in its deepest potential well. The entropy term, weighted by temperature, favours whatever has the most microstates: a gas filling its container, a disordered chain, a broad, shallow well rather than a narrow, deep one. Which wins depends on the temperature, and that competition is the origin of melting, boiling, unfolding and most other changes of state.

The cleanest way to see this is a system with two states, A and B. The probability of being in state A is the sum of the Boltzmann weights of all microstates belonging to A, so it is natural to define a partition function for each state, ZAZ_A and ZBZ_B, and a free energy for each, FA=−kBTln⁡ZAF_A = -k_BT\ln Z_A. The ratio of probabilities then depends only on the free-energy difference:

The figure below samples a particle moving in a one-dimensional potential with two wells by the Metropolis Monte Carlo method (its own chapter). Well A is deep and narrow; well B is shallower but much broader. At low temperature the particle stays almost entirely in A, the state of lower energy. Raise the temperature and B gains, until above some temperature the particle spends more time in the shallow well than in the deep one. Nothing about the energies has changed. B wins because it offers more room: its larger entropy, multiplied by the higher temperature, outweighs its energy penalty. The readout decomposes the exact free-energy difference into its energy and entropy parts.

Energy against entropy in a two-well system

Loading the interactive figure…

Top: the potential energy (blue), and the free energy F(x) = −kT ln P(x) reconstructed from the sampled histogram (orange), with a violet bar showing the size of kT. Bottom: the histogram of positions visited and the exact Boltzmann density. Raise the temperature or widen well B and watch the population shift from A to B.

This is not a toy effect. Rubber contracts when heated because a stretched polymer chain has fewer conformations than a coiled one, so the entropic force pulling it back grows with temperature. Water and oil separate largely because water molecules next to an oily surface lose orientational freedom, an entropic penalty; this hydrophobic effect drives protein folding and the self-assembly of surfactants and nanoparticle ligands. And every first-order phase transition, from ice melting to a crystal changing its structure, is the point where the free energies of two phases cross.

Free-energy profiles and the potential of mean force

The same idea extends from two states to a continuous variable. Choose a collective variable ξ\xi that describes the progress of some process: the distance between two molecules, a dihedral angle, the number of atoms in a crystalline cluster. Its probability distribution P(ξ)P(\xi), obtained by summing the Boltzmann weights of all microstates with a given value of ξ\xi, defines a free-energy profile:

In the two-well figure, the orange curve is exactly this: a histogram of where the particle has been, turned into a free energy. The difference between it and the blue potential-energy curve is entropy. Free-energy profiles are central to molecular simulation. The barrier height ΔF‡\Delta F^\ddagger of a profile along a reaction coordinate controls the rate of the process through a factor e−βΔF‡e^{-\beta\Delta F^\ddagger}, and the depth of a minimum controls binding constants and solubilities. When the barrier is many kBTk_BT high, as in the figure at low temperature, an unbiased simulation almost never crosses it and the histogram cannot be measured on the far side; the readout warns when this happens. The chapter on free-energy methods describes umbrella sampling and metadynamics, which bias the simulation to overcome this.

The classical partition function and the ideal gas

For a classical system of NN atoms, the sum over microstates becomes an integral over phase space, the 3N3N positions and 3N3N momenta:

Because the kinetic energy is a sum of squares of momenta, the momentum integrals are products of Gaussian integrals and can always be done exactly. All the difficulty, and all the interesting physics of interacting matter, lies in the remaining configurational integral over the potential energy. It is a 3N3N-dimensional integral that cannot be computed on a grid, which is why it is sampled by Monte Carlo or molecular dynamics.

For an ideal gas, U=0U = 0 and the configurational integral is simply VNV^N, so Z=VN/(N! Λ3N)Z = V^N/(N!\,\Lambda^{3N}). Everything follows from this one line. The pressure is P=kBT ∂ln⁡Z/∂V=NkBT/VP = k_BT\,\partial\ln Z/\partial V = Nk_BT/V, the ideal gas law. The entropy, using Stirling’s approximation ln⁡N!≈Nln⁡N−N\ln N! \approx N\ln N - N, is the Sackur–Tetrode equation,

S=NkB[ln⁡ ⁣(VNΛ3)+52]. S = N k_B \left[\ln\!\left(\frac{V}{N\Lambda^3}\right) + \frac52\right].

For argon at 298.15 K and 1 bar, the thermal wavelength is 0.16 Å, V/(NΛ3)≈107V/(N\Lambda^3) \approx 10^7, and the formula gives a molar entropy of 154.8 J mol⁻¹ K⁻¹, which matches the value measured calorimetrically. That an absolute entropy can be calculated from Planck’s constant and the mass of an atom, and agree with experiment, was one of the early triumphs of quantum statistical mechanics: the factor h3Nh^{3N} and the N!N! both matter.

Other ensembles

Experiments are more often done at constant pressure than at constant volume. In the isothermal–isobaric ensemble (NPT), the volume fluctuates as the system exchanges work with a barostat, a microstate with energy EsE_s and volume VV has weight e−β(Es+PV)e^{-\beta(E_s + PV)}, and the corresponding free energy is the Gibbs free energy G=F+PVG = F + PV, minimised at constant temperature and pressure. Phase equilibria, reaction equilibria and solubilities at ordinary conditions are governed by GG. Molecular dynamics simulations of liquids and solids are usually run in this ensemble, with a thermostat and a barostat (the chapter on thermostats).

In the grand canonical ensemble (μVT\mu VT), the system exchanges particles as well as energy with a reservoir at fixed chemical potential μ\mu, the free-energy cost of adding one particle. A microstate with NN particles and energy EsE_s has weight e−β(Es−μN)e^{-\beta(E_s - \mu N)}, and the grand potential Ω=−kBTln⁡Ξ=−PV\Omega = -k_BT\ln\Xi = -PV follows from the grand partition function Ξ\Xi. This is the natural ensemble for adsorption: grand canonical Monte Carlo simulations of gases in porous materials such as zeolites and metal–organic frameworks predict adsorption isotherms by letting molecules be inserted and deleted at a chemical potential fixed by the gas pressure.

The pattern is always the same. Each ensemble has a weight for each microstate, a partition function that normalises the weights, and a thermodynamic potential equal to −kBT-k_BT times its logarithm. The potentials are related by Legendre transforms, F=U−TSF = U - TS, G=F+PVG = F + PV, Ω=F−μN\Omega = F - \mu N, each swapping a controlled extensive variable for its conjugate intensive one, and each minimised at equilibrium under its own constraints.

Check yourself

  1. A system has levels E = 0 (g = 1) and E = Δ (g = 3). What is Z at very high temperature?
  2. How is the heat capacity usually computed from a canonical simulation?
  3. State B has higher energy than A but is found more often at 400 K. Why?
  4. A histogram shows ξ = 1 visited 100 times more often than ξ = 2. What is F(2) − F(1)?
  5. Why can the momentum part of the classical partition function always be done exactly?

References and further reading

  1. D. Chandler, Introduction to Modern Statistical Mechanics, Oxford University Press (1987), chapters 3 and 6.
  2. M. E. Tuckerman, Statistical Mechanics: Theory and Molecular Simulation, 2nd ed., Oxford University Press (2023), chapters 3–6 (microcanonical, canonical, isothermal–isobaric and grand canonical ensembles).
  3. D. A. McQuarrie, Statistical Mechanics, University Science Books (2000), chapters 2–8.
  4. T. L. Hill, An Introduction to Statistical Thermodynamics, Addison-Wesley (1960); Dover reprint (1986).
  5. D. V. Schroeder, An Introduction to Thermal Physics, Addison-Wesley (2000), chapters 6–7, including the Schottky anomaly and the Sackur–Tetrode equation.
  6. O. Sackur, “Die Anwendung der kinetischen Theorie der Gase auf chemische Probleme”, Annalen der Physik 36, 958–980 (1911); H. Tetrode, “Die chemische Konstante der Gase und das elementare Wirkungsquantum”, Annalen der Physik 38, 434–442 (1912).
  7. D. Chandler, “Interfaces and the driving force of hydrophobic assembly”, Nature 437, 640–647 (2005).

6Fluctuations and response

Why thermodynamic quantities fluctuate, how large the fluctuations are, and what they measure: energy fluctuations and the heat capacity, the 1/√N law and the thermodynamic limit, density fluctuations and compressibility, volume and enthalpy fluctuations at constant pressure, the fluctuation–dissipation theorem and linear response, and what all this means for simulations of small systems.

about 18 min readBuilds on Ensembles and free energy

Averages are not the whole story

Thermodynamics treats the energy of a beaker of water in a thermostat, or the number of molecules in a cubic millimetre of air, as definite numbers. Statistical mechanics says they are not. A system in contact with a heat bath constantly exchanges energy with it, so its energy fluctuates about its average; a region of a gas constantly exchanges molecules with its surroundings, so the number inside it fluctuates too. For a macroscopic sample these fluctuations are far too small to notice, which is why thermodynamics works. For the systems studied in molecular simulation, a few thousand atoms, and for the nanoparticles, single molecules and small droplets of modern experiments, they are large enough to see and to matter.

Fluctuations are not merely noise. Their size is fixed by the same statistical mechanics that fixes the averages, and it turns out to be directly related to how the system responds when it is disturbed. The heat capacity, the compressibility and the magnetic susceptibility can all be written as the size of a spontaneous fluctuation. This is one of the most useful results in statistical physics, because it means that response functions can be computed from an equilibrium simulation simply by recording the fluctuations, without ever disturbing the system.

Energy fluctuations and the heat capacity

In the canonical ensemble, the mean energy is U=−∂ln⁡Z/∂βU = -\partial \ln Z/\partial\beta, as the chapter on ensembles showed. Differentiating once more with respect to β\beta gives the variance of the energy, and since ∂/∂β=−kBT2 ∂/∂T\partial/\partial\beta = -k_BT^2\,\partial/\partial T, the variance is proportional to the temperature derivative of the energy, which is the heat capacity:

The figure below samples the total energy of NN independent two-level units, each with an excited level at energy Δ\Delta, in contact with a heat bath. Each unit is excited with probability p=1/(1+eΔ/kBT)p = 1/(1 + e^{\Delta/k_BT}), so the number of excited units fluctuates from moment to moment. The readout computes the heat capacity from nothing but the variance of the sampled energies and compares it with the exact result. Change the temperature: the fluctuations, and the heat capacity, are largest at intermediate temperatures where the units are most uncertain about their state, the Schottky peak seen in the ensembles topic.

Fluctuations shrink as 1/√N, and measure the response

Loading the interactive figure…

Left: the system. Right: the distribution of the fluctuating quantity divided by its mean, on a fixed axis, with the Gaussian predicted by theory. Increase N from 10 to 10 000 and watch the distribution narrow; the readout recovers the heat capacity (or the compressibility) from the sampled variance alone.

The formula also explains why heat capacities are always positive: a variance cannot be negative. A system with a negative heat capacity would heat up when it lost energy, which cannot happen in a stable system in contact with a bath. (Isolated, self-gravitating systems such as stars can have negative heat capacities, and small isolated clusters near a melting transition can show them in the microcanonical ensemble, a reminder that the equivalence of ensembles holds only for large systems.)

The thermodynamic limit

How large are these fluctuations? For NN independent units, the energies add, and so do the variances (the chapter on probability), so the mean grows as NN and the standard deviation as N\sqrt N. The relative fluctuation therefore shrinks:

This holds well beyond independent units: whenever correlations between parts of a system extend over a finite distance, the system behaves like many independent blocks, and the same 1/N1/\sqrt N law applies. In the figure, increasing NN by a factor of 100 narrows the distribution tenfold. For a mole of matter, N≈6×1023N \approx 6 \times 10^{23}, the relative fluctuation is about 10−1210^{-12}, utterly negligible: this is the thermodynamic limit, in which averages become sharp and thermodynamics becomes exact. The exception is near a critical point, where correlations extend over macroscopic distances, the parts of the system cease to be independent, and fluctuations grow enormously; the chapter on phase transitions shows this.

For a simulation of 1000 atoms, by contrast, the relative energy fluctuation is a few per cent, which is easily visible in a plot of the energy against time. That is not a malfunction of the thermostat; it is the canonical ensemble behaving as it should.

Density fluctuations and compressibility

The same reasoning applies to other quantities. Consider a small region inside a fluid, open to the rest. Molecules wander in and out, so the number nn inside fluctuates. In the grand canonical ensemble, where the region exchanges particles with a reservoir at fixed chemical potential, differentiating the grand partition function twice with respect to μ\mu gives the variance of nn, and thermodynamic identities relate it to the isothermal compressibility κT=−1V(∂V/∂P)T\kappa_T = -\frac1V(\partial V/\partial P)_T:

Switch the figure to the gas. Molecules are scattered at random through a box, and the shaded sub-volume holds a fraction of them. The ratio of the variance to the mean of the count comes out close to 1, as the formula predicts for an ideal gas, reduced by the sub-volume fraction because the total number in the whole box is fixed. In a liquid, molecules repel each other at short range, so they cannot crowd into one region, the count fluctuates much less than for a gas, and ρkBTκT\rho k_BT\kappa_T is small; for water at room temperature it is about 0.06. Liquids are nearly incompressible precisely because their density fluctuations are suppressed.

Density fluctuations are directly observable. They scatter light, X-rays and neutrons: the intensity scattered at small angles is proportional to ⟨(δn)2⟩/⟨n⟩\langle(\delta n)^2\rangle/\langle n\rangle, which is the structure factor S(q)S(q) at q→0q \to 0 discussed in the chapter on liquids. Near the liquid–gas critical point the compressibility diverges, density fluctuations grow to the size of the wavelength of light, and an otherwise transparent fluid turns milky, the phenomenon of critical opalescence explained by Einstein and Smoluchowski in 1908–1910.

Fluctuations at constant pressure

In the isothermal–isobaric ensemble, the volume of the system is not fixed but fluctuates, and the corresponding formulas are the ones used in most molecular dynamics simulations, which run at constant temperature and pressure:

⟨(δV)2⟩=kBT ⟨V⟩ κT,⟨(δH)2⟩=kBT2 CP, \langle(\delta V)^2\rangle = k_BT\,\langle V\rangle\,\kappa_T, \qquad \langle(\delta H)^2\rangle = k_BT^2\,C_P ,

where H=E+PVH = E + PV is the enthalpy. Recording the box volume and the enthalpy during a simulation therefore gives the compressibility and the constant-pressure heat capacity without any additional calculation. A further formula of the same kind gives the thermal expansion coefficient from the correlation between volume and enthalpy fluctuations. These estimators are widely used to validate force fields against experiment, and their accuracy depends on long simulations, because the variance of a fluctuation converges more slowly than the mean.

The fluctuations of a quantity depend on the ensemble even when its average does not. In a microcanonical (NVE) simulation the total energy does not fluctuate at all, while the kinetic and potential energies fluctuate against each other; in a canonical simulation the total energy fluctuates as above. A thermostat or barostat that gets the average temperature or pressure right but the fluctuations wrong produces the wrong ensemble and wrong response functions. The Berendsen thermostat is the classic example, discussed in the chapter on thermostats.

The fluctuation–dissipation theorem

The formulas above are special cases of a general principle. Suppose a small external field hh is applied that couples to some quantity AA of the system, adding −hA-hA to the energy: a magnetic field coupling to the magnetisation, an electric field coupling to the dipole moment, a pressure coupling to the volume. The system responds by shifting the average of AA. To first order in hh, statistical mechanics gives

The proof is two lines: ⟨A⟩=∑sAse−β(Es−hAs)/Z\langle A\rangle = \sum_s A_s e^{-\beta(E_s - hA_s)}/Z, and differentiating with respect to hh brings down βAs\beta A_s in each term, giving β(⟨A2⟩−⟨A⟩2)\beta(\langle A^2\rangle - \langle A\rangle^2). The dielectric constant of water in simulations is computed exactly this way, from the fluctuations of the total dipole moment of the box.

The dynamic version of this result is the fluctuation–dissipation theorem, formulated by Callen and Welton in 1951 and by Kubo in 1957. It states that the way a system relaxes back to equilibrium after a small disturbance is the same as the way its spontaneous fluctuations decay, a principle Onsager had stated in 1931 as the regression hypothesis. Quantitatively, transport coefficients, which measure dissipation, are integrals of equilibrium time-correlation functions, which measure fluctuations. The diffusion coefficient is the time integral of the velocity autocorrelation function, the viscosity is the integral of the autocorrelation of the stress, and the electrical conductivity is the integral of the autocorrelation of the current. These Green–Kubo relations are how transport coefficients are computed from equilibrium simulations, and the chapter on transport coefficients develops them. Einstein’s 1905 relation between the diffusion coefficient of a Brownian particle and the friction it feels, D=kBT/ζD = k_BT/\zeta, was the first example of the theorem: the same molecular collisions that make the particle jiggle also slow it down when it is pushed.

Consequences for simulations

Several practical lessons follow. Fluctuations in a small simulation are real and expected: a 1000-atom canonical simulation at 300 K shows temperature fluctuations of about 3 %, and a pressure that fluctuates by hundreds of bar is normal for a small box of liquid. Response functions computed from fluctuations need long runs, since a variance converges more slowly than a mean and correlated samples count less than they seem (the chapter on probability explains effective sample sizes). Fluctuation formulas are only valid if the simulation samples the correct ensemble, so the choice of thermostat and barostat matters. And finite-size effects are themselves a kind of fluctuation effect: quantities that depend on long-wavelength fluctuations, such as the compressibility near a critical point, converge slowly with system size and should be checked by repeating the calculation in a larger box.

Check yourself

  1. In a canonical simulation the energy variance is 4 (kJ/mol)² at 300 K. What determines the heat capacity?
  2. System size grows from 1 000 to 100 000 atoms. The relative energy fluctuation…
  3. For an ideal gas, the number of molecules in a small open sub-volume follows…
  4. Why are liquids nearly incompressible, in the language of fluctuations?
  5. A thermostat reproduces the correct average temperature but suppresses energy fluctuations. What goes wrong?

References and further reading

  1. D. Chandler, Introduction to Modern Statistical Mechanics, Oxford University Press (1987), chapters 3 and 8 (fluctuations, linear response).
  2. M. P. Allen and D. J. Tildesley, Computer Simulation of Liquids, 2nd ed., Oxford University Press (2017), section 2.5 (fluctuations) and chapter 2 on estimators.
  3. H. B. Callen and T. A. Welton, “Irreversibility and generalized noise”, Physical Review 83, 34–40 (1951).
  4. R. Kubo, “Statistical-mechanical theory of irreversible processes. I”, Journal of the Physical Society of Japan 12, 570–586 (1957).
  5. L. Onsager, “Reciprocal relations in irreversible processes. I”, Physical Review 37, 405–426 (1931).
  6. A. Einstein, “Über die von der molekularkinetischen Theorie der Wärme geforderte Bewegung von in ruhenden Flüssigkeiten suspendierten Teilchen”, Annalen der Physik 17, 549–560 (1905).
  7. A. Einstein, “Theorie der Opaleszenz von homogenen Flüssigkeiten und Flüssigkeitsgemischen in der Nähe des kritischen Zustandes”, Annalen der Physik 33, 1275–1298 (1910).

7Phase transitions and the Ising model

How collective order appears: order parameters and the classification of transitions, the Ising model and its lattice-gas and alloy interpretations, Onsager's exact solution, Monte Carlo simulation of the model, mean-field theory solved graphically, Landau theory of continuous and first-order transitions, critical exponents, universality and finite-size effects in simulations.

about 22 min readBuilds on Ensembles and free energy, Fluctuations and response

Phases and order parameters

Water freezes at 0 °C, iron loses its magnetism above 770 °C, and the copper and zinc atoms of β-brass, arranged in an ordered alternating pattern at room temperature, mix randomly on the same lattice above about 460 °C. These are phase transitions: changes in the collective organisation of matter that happen abruptly as a control parameter, usually temperature or pressure, passes a definite value. They are the most dramatic consequence of the competition between energy and entropy described in the chapter on free energy. Below the transition, the ordered arrangement has the lower free energy because its energy is lower; above it, the disordered arrangement wins because its entropy, multiplied by the temperature, outweighs the energy cost.

A phase transition is described by an order parameter, a quantity that is zero in the disordered phase and non-zero in the ordered one. For a magnet it is the magnetisation; for an alloy, the excess of one kind of atom on one sublattice; for the liquid–gas transition, the difference between the liquid and gas densities; for a nematic liquid crystal, the average alignment of the molecules. Transitions fall into two broad classes. In a first-order or discontinuous transition, such as melting or boiling, the order parameter jumps, the two phases coexist at the transition, a latent heat is absorbed, and the system can be superheated or supercooled. In a continuous or second-order transition, such as the loss of ferromagnetism at the Curie temperature, the order parameter falls smoothly to zero, there is no latent heat, but the heat capacity, the susceptibility and the size of fluctuations become very large near the critical point.

The Ising model

The simplest model that shows a phase transition was proposed by Wilhelm Lenz and solved in one dimension by his student Ernst Ising in 1925. Each site ii of a lattice carries a spin sis_i that can point up (+1+1) or down (−1-1). Neighbouring spins prefer to align, and an external field hh favours one direction:

Its simplicity is deceptive, because the same mathematics describes very different physical systems. Reading “up” as “site occupied by a molecule” and “down” as “empty site” turns the Ising model into a lattice gas, with JJ an attraction between neighbouring molecules and hh related to the chemical potential; its transition is then the condensation of a gas into a liquid. Reading “up” and “down” as two kinds of atom turns it into a binary alloy, whose transition is ordering or phase separation. Lattice models of this kind, with JJ fitted to first-principles calculations through a cluster expansion, are used today to predict the ordering of real alloys and of ions in battery electrodes.

Ising found that the one-dimensional chain has no transition at any non-zero temperature: a single break in an aligned chain costs a fixed energy 2J2J but can be placed anywhere, so its entropy always wins. He wrongly concluded that the model was useless in higher dimensions too. In 1944 Lars Onsager solved the two-dimensional square-lattice model exactly, a celebrated feat of mathematical physics, and showed that it orders spontaneously below a critical temperature

kBTc=2Jln⁡(1+2)≈2.269 J. k_BT_c = \frac{2J}{\ln(1 + \sqrt 2)} \approx 2.269\,J .

The spontaneous magnetisation below TcT_c, published by Chen Ning Yang in 1952, is m=[1−sinh⁡−4(2J/kBT)]1/8m = [1 - \sinh^{-4}(2J/k_BT)]^{1/8}. These exact results make the 2D Ising model the standard test of approximate theories and of simulation methods.

Simulating the model

The model is easily simulated with the Metropolis Monte Carlo method (its own chapter explains why it samples the canonical ensemble). Repeatedly pick a spin, compute the energy change ΔE\Delta E that flipping it would cause, which depends only on its four neighbours, and accept the flip with probability min⁡(1,e−ΔE/kBT)\min(1, e^{-\Delta E/k_BT}). One attempted flip per spin is called a sweep.

The two-dimensional Ising model

Loading the interactive figure…

Left: the lattice, blue spins up and orange spins down, with periodic boundaries. Right, top: the magnetisation per spin over time. Right, bottom: the average |m| you record at different temperatures against Onsager’s exact curve (gold); point colours mark the lattice size. The readouts give the susceptibility and heat capacity estimated from fluctuations.

Start at a temperature well below TcT_c, say kBT=1.5Jk_BT = 1.5J, with random spins. The lattice does not order all at once. Small aligned domains of each sign form, and their boundaries move and smooth out, so that domains coarsen over time; eventually one sign usually takes over, although stripes spanning the periodic box can survive for a long time. Above TcT_c, at kBT=3Jk_BT = 3J, the spins remain a fine-grained mixture and the magnetisation fluctuates around zero. Close to TcT_c, the picture is remarkable: clusters of every size, from single spins to the size of the lattice, coexist and fluctuate, and the magnetisation wanders widely. This is the critical state, in which the system has no characteristic length scale.

To rebuild the phase diagram, set a temperature, wait until the magnetisation has settled, and press Record. Points well below and well above TcT_c fall on Onsager’s curve. Near TcT_c they do not: a finite lattice cannot have a sharp transition, so the recorded ⟨∣m∣⟩\langle|m|\rangle is rounded off and stays above zero slightly beyond TcT_c, and the rounding shrinks as the lattice grows. Recording the same temperatures on 32, 64 and 128 spin lattices shows this finite-size effect directly. Close to TcT_c the simulation also slows down dramatically, because large clusters take many sweeps to change, a phenomenon called critical slowing down. Cluster algorithms such as those of Swendsen and Wang or Wolff, which flip whole correlated clusters at once, were invented to overcome it.

The readouts show the susceptibility and heat capacity estimated from the fluctuations of the magnetisation and energy, using the formulas of the chapter on fluctuations. Both peak near TcT_c, where fluctuations are largest.

Mean-field theory

Onsager’s solution is a mathematical tour de force that does not generalise to three dimensions or to other models. A simple approximate theory that works in any dimension is mean-field theory, introduced by Pierre Weiss in 1907 for ferromagnets. Its idea is to replace the fluctuating neighbours of each spin by their average. Each spin then feels an effective field, the external field plus JJ times the sum of its zz neighbours’ average values, heff=h+zJmh_{\text{eff}} = h + zJm. A single spin in a field heffh_{\text{eff}} has average value tanh⁡(βheff)\tanh(\beta h_{\text{eff}}), and since every spin is equivalent, this average must equal mm itself:

The equation cannot be solved in closed form, but it can be solved by drawing. Plot the straight line y=my = m and the curve y=tanh⁡((zJm+h)/kBT)y = \tanh((zJm + h)/k_BT); the solutions are where they cross.

Mean-field theory solved graphically

Loading the interactive figure…

Blue: y = m. Orange: y = tanh((zJm + h)/kT). Their intersections are the self-consistent magnetisations; filled dots are stable, open dots unstable. Lower the temperature through zJ/k_B with h = 0 and watch two new solutions split off from m = 0.

At high temperature the tanh curve is shallow and crosses the line only at m=0m = 0: the disordered phase. As the temperature falls, the curve steepens, and when its slope at the origin, zJ/kBTzJ/k_BT, exceeds 1, it crosses the line at two more points, ±m0\pm m_0; the solution m=0m = 0 becomes unstable and the system orders spontaneously. Mean-field theory thus predicts a transition at kBTc=zJk_BT_c = zJ, which for the square lattice is 4J4J, well above the exact 2.269J2.269J. It overestimates TcT_c because it ignores fluctuations, which disrupt order; it even predicts a transition in the one-dimensional chain, where there is none. It improves as the number of neighbours grows, and becomes exact when every spin interacts with every other.

Landau theory

Lev Landau generalised the mean-field idea in 1937 into a theory that applies to any transition, by writing the free energy as a function of the order parameter and expanding it in powers of mm near the transition, keeping only terms allowed by the symmetry of the problem. For the Ising magnet, flipping every spin leaves the energy unchanged when h=0h = 0, so only even powers can appear:

The figure plots this free energy. For the continuous transition, as the temperature passes TcT_c the single minimum at m=0m = 0 flattens and splits into two symmetric minima that move apart continuously; a small field tilts the curve and selects one. The predicted magnetisation grows as (Tc−T)1/2(T_c - T)^{1/2} below the transition. Switch to the first-order form: now, over a range of temperatures, the free energy has three minima, one at m=0m = 0 and two at large ±m\pm m. The equilibrium state jumps from one to the other when their depths cross, which is the discontinuous transition, while the shallower minimum remains as a metastable state that the system can be trapped in. That is the origin of supercooling, superheating and hysteresis, and escaping a metastable minimum requires crossing a free-energy barrier, which is what nucleation of a new phase means.

Landau free-energy curves

Loading the interactive figure…

The free energy as a function of the order parameter. Teal: the global minimum (equilibrium). Orange: metastable minima. Compare how the minimum moves through the continuous transition with how it jumps in the first-order one.

Critical phenomena and universality

Near a continuous transition, many quantities follow power laws in the distance from the critical temperature, t=(T−Tc)/Tct = (T - T_c)/T_c, characterised by critical exponents: the order parameter vanishes as m∝(−t)βm \propto (-t)^\beta, the susceptibility diverges as χ∝∣t∣−γ\chi \propto |t|^{-\gamma}, the heat capacity as C∝∣t∣−αC \propto |t|^{-\alpha}, and the correlation length ξ\xi, the typical size of correlated regions, diverges as ξ∝∣t∣−ν\xi \propto |t|^{-\nu}. The divergence of ξ\xi is the heart of the matter: at the critical point fluctuations are correlated over all length scales, which is what the simulation shows as clusters of every size.

exponentmean field / Landau2D Ising (exact)3D Ising (numerical)
order parameter β\beta1/21/80.326
susceptibility γ\gamma17/41.237
correlation length ν\nu1/210.630

Mean-field theory gets the exponents wrong in two and three dimensions because it neglects exactly these long-range fluctuations. The most striking discovery about critical exponents is universality: they do not depend on the details of a system, only on its dimension and the symmetry of its order parameter. The liquid–gas critical point of carbon dioxide, the critical point of a binary liquid mixture and the Curie point of a uniaxial magnet all have the exponents of the 3D Ising model, even though the forces involved are completely different. The explanation came from the renormalisation group developed by Kenneth Wilson in the early 1970s, for which he received the 1982 Nobel Prize in Physics: near a critical point, as the system is viewed on longer and longer length scales, microscopic details become irrelevant and only symmetry and dimension survive.

Phase transitions in simulations

Simulations of phase transitions must contend with the finite size of the simulated system. A box of NN particles cannot show true singularities, so transitions are rounded and shifted, and the critical properties of the infinite system are obtained by finite-size scaling: repeating the simulation for several sizes and extrapolating using the known way in which quantities scale with L/ξL/\xi. A practical tool is the Binder cumulant of the order parameter, whose curves for different system sizes cross near TcT_c.

First-order transitions pose the opposite problem. The two phases are separated by a free-energy barrier that grows with system size, so a simulation started in one phase can remain there far beyond the true transition temperature: a simulated crystal heated at constant rate often melts well above its melting point, because there is no surface from which melting can start. Locating first-order transitions reliably therefore requires free-energy calculations that compare the two phases directly, coexistence simulations in which both phases share a box with an interface, or biased sampling methods that drive the system over the barrier, described in the subject on enhanced sampling.

Check yourself

  1. Why does the one-dimensional Ising chain have no phase transition at T > 0?
  2. Mean-field theory predicts T_c = 4J/k_B for the square lattice; the exact value is 2.269J/k_B. Why the overestimate?
  3. In a Landau free energy with three minima, the system is in the minimum at m = 0 while a deeper minimum exists at m = 0.9. The m = 0 state is…
  4. The liquid–gas critical point of CO₂ and the Curie point of a uniaxial magnet share critical exponents because…
  5. A simulated crystal heated steadily melts 20 % above its experimental melting point. The most likely reason is…

References and further reading

  1. E. Ising, “Beitrag zur Theorie des Ferromagnetismus”, Zeitschrift für Physik 31, 253–258 (1925).
  2. L. Onsager, “Crystal statistics. I. A two-dimensional model with an order-disorder transition”, Physical Review 65, 117–149 (1944).
  3. C. N. Yang, “The spontaneous magnetization of a two-dimensional Ising model”, Physical Review 85, 808–816 (1952).
  4. K. G. Wilson, “Renormalization group and critical phenomena. I”, Physical Review B 4, 3174–3183 (1971).
  5. N. Goldenfeld, Lectures on Phase Transitions and the Renormalization Group, Addison-Wesley (1992).
  6. J. M. Yeomans, Statistical Mechanics of Phase Transitions, Oxford University Press (1992).
  7. D. P. Landau and K. Binder, A Guide to Monte Carlo Simulations in Statistical Physics, 5th ed., Cambridge University Press (2021).
  8. U. Wolff, “Collective Monte Carlo updating for spin systems”, Physical Review Letters 62, 361–364 (1989).

8The structure of liquids

How disordered matter is described statistically: the radial distribution function and what its peaks mean, coordination numbers, energy, pressure and compressibility from g(r), the potential of mean force and why it differs from the pair potential, the structure factor measured by X-ray and neutron scattering, the hard-sphere picture of liquids, and how g(r) is computed correctly from simulations.

about 14 min readBuilds on Phase transitions and the Ising model, Fluctuations and response

Order without a lattice

A crystal is easy to describe: give the lattice and the contents of one unit cell, and every atomic position follows. A gas is easy too: the atoms are almost independent. Liquids, glasses, amorphous solids and dense fluids lie in between. They have no long-range order, yet they are far from random: each atom is surrounded by a well-defined first shell of neighbours at nearly fixed distance, a less sharply defined second shell, and so on, with order fading over a few molecular diameters. The theory of liquids, developed from the 1930s by John Kirkwood, Joseph Mayer, Jean-Pierre Hansen, John Barker, Douglas Henderson and many others, and tested at every stage by computer simulation, describes this statistical order with a few correlation functions. The most important is the radial distribution function.

The radial distribution function

The radial distribution function g(r)g(r) measures how the density of particles around a given particle varies with distance, relative to the average density:

The figure runs a two-dimensional Lennard-Jones fluid by molecular dynamics and accumulates g(r)g(r) as it goes. At low density, g(r)g(r) shows a single weak peak just beyond the repulsive core, reflecting the attraction of neighbouring pairs, and is otherwise close to 1. In the liquid, it develops a strong first peak at about one particle diameter, a minimum, a second peak and weaker oscillations that decay within a few diameters. Compress further and the peaks sharpen and split as the system crystallises into a triangular lattice. The tagged atom (rose) and its first-shell neighbours (teal) show the shell that the first peak counts.

Structure of a Lennard-Jones fluid

Loading the interactive figure…

Left: the fluid, with a tagged atom (rose) and its first-shell neighbours (teal) inside the dashed circle at the first minimum of g(r). Right: g(r) (teal) and the running coordination number (violet), or, in the second view, the potential of mean force against the pair potential. Vary density and temperature to move between gas, liquid and solid.

Coordination numbers and thermodynamics from g(r)

Integrating ρg(r)\rho g(r) over the first peak gives the coordination number, the average number of nearest neighbours,

n1=ρ∫0rmin⁡g(r) 4πr2 dr, n_1 = \rho\int_0^{r_{\min}} g(r)\,4\pi r^2\,\mathrm dr ,

with the integral stopped at the first minimum rmin⁡r_{\min}. Simple liquids near their triple point have about 12 neighbours in three dimensions, close to the 12 of a close-packed crystal, which is why melting changes the density of simple substances by only around 10 %; water has only about 4.5 neighbours, the signature of its open, hydrogen-bonded network. In two dimensions, as in the figure, the dense liquid has close to 6 neighbours.

For particles interacting through a pair potential u(r)u(r), g(r)g(r) determines the thermodynamics. The average potential energy per particle and the pressure are

and the isothermal compressibility follows from the compressibility route, ρkBTκT=1+ρ∫0∞[g(r)−1] 4πr2 dr\rho k_BT\kappa_T = 1 + \rho\int_0^\infty [g(r) - 1]\,4\pi r^2\,\mathrm dr, which links g(r)g(r) to the density fluctuations of the chapter on fluctuations. Because these routes are exact only for the exact g(r)g(r), comparing them is a sensitive test of approximate theories such as the Percus–Yevick and hypernetted-chain integral equations.

The potential of mean force

The probability of finding two particles at distance rr, relative to an ideal gas, defines a free energy as a function of their separation:

Switch the figure to the potential of mean force. At low density the orange curve follows the blue pair potential. At liquid density it develops extra minima at the second and third neighbour distances and a barrier between the first two: there is no direct interaction at those distances, but the surrounding particles make some separations more probable than others. This is the same idea as the free-energy profiles of the chapter on ensembles, applied to a distance. It is important in practice: the potential of mean force between two ions in water shows a contact minimum and a solvent-separated minimum, with a barrier between them corresponding to a water molecule entering or leaving the gap, and its depth determines ion pairing and the stability of colloids and nanoparticles in solution. Coarse-grained models are often built by matching potentials of mean force, by iterative Boltzmann inversion for example.

Scattering and the structure factor

g(r)g(r) is not only a simulation concept; it is measured. X-rays and neutrons scattered by a liquid produce an intensity pattern whose variation with the scattering vector qq is the static structure factor, related to g(r)g(r) by a Fourier transform:

Comparing simulated and measured structure factors is one of the main tests of force fields and MLIPs for liquids, glasses and amorphous materials. For multicomponent systems there are partial structure factors and partial gαβ(r)g_{\alpha\beta}(r) for each pair of species, and X-ray and neutron experiments, which weight the species differently, together constrain them; for water, the oxygen–oxygen g(r)g(r) from X-ray diffraction is the standard benchmark.

Hard spheres and the van der Waals picture

The structure of simple dense liquids is dominated by repulsion. Simulations of hard spheres by Berni Alder and Thomas Wainwright (1957) and by William Wood and J. D. Jacobson showed that even particles with no attraction at all crystallise at high density, an entropy-driven transition, and that their liquid g(r)g(r) looks remarkably like that of real simple liquids. This led to the modern van der Waals picture of liquids, developed by John Weeks, David Chandler and Hans Andersen (1971) and by Barker and Henderson: the structure is fixed by packing of the repulsive cores, and the attraction mainly provides a uniform cohesive background that holds the liquid together. Perturbation theories built on this idea predict liquid thermodynamics accurately and underlie much of the theory of fluids.

Computing g(r) in a simulation

The recipe is simple, and the figure follows it: for every pair of particles compute the distance, applying the minimum-image convention in a periodic box; histogram the distances into bins of width Δr\Delta r; average over many frames; and normalise each bin by the number of pairs an ideal gas would have in that shell, 12Nρ⋅4πr2Δr\tfrac12 N\rho\cdot 4\pi r^2\Delta r (counting each pair once) or Nρ⋅4πr2ΔrN\rho\cdot 4\pi r^2\Delta r (counting both orders). Distances beyond half the box length are unreliable, because shells there are cut off by the periodic boundary. Bins must be fine enough to resolve the first peak but coarse enough to collect statistics, and the result should be averaged over frames separated by more than the correlation time. Analysis libraries such as MDAnalysis, MDTraj and OVITO compute g(r)g(r), coordination numbers and structure factors directly from trajectories, as the chapter on trajectory analysis describes.

Check yourself

  1. What is g(r) at very large distances in a liquid?
  2. The potential of mean force between two ions in water has two minima. What does the second represent?
  3. What does S(q → 0) measure?

References and further reading

  1. J.-P. Hansen and I. R. McDonald, Theory of Simple Liquids: with Applications to Soft Matter, 4th ed., Academic Press (2013), chapters 2–5.
  2. J. G. Kirkwood, “Statistical mechanics of fluid mixtures”, Journal of Chemical Physics 3, 300–313 (1935).
  3. B. J. Alder and T. E. Wainwright, “Phase transition for a hard sphere system”, Journal of Chemical Physics 27, 1208–1209 (1957).
  4. J. D. Weeks, D. Chandler and H. C. Andersen, “Role of repulsive forces in determining the equilibrium structure of simple liquids”, Journal of Chemical Physics 54, 5237–5247 (1971).
  5. J. A. Barker and D. Henderson, “What is ’liquid’? Understanding the states of matter”, Reviews of Modern Physics 48, 587–671 (1976).
  6. D. Chandler, Introduction to Modern Statistical Mechanics, Oxford University Press (1987), chapter 7.
  7. L. B. Skinner et al., “Benchmark oxygen–oxygen pair-distribution function of ambient water from x-ray diffraction measurements with a wide Q-range”, Journal of Chemical Physics 138, 074506 (2013).