Chemistry · Statistical Mechanics · Monte Carlo
📅 July 2026 ⏱ ≈ 10 min read 🎯 Intermediate · Last updated: 9 July 2026

Monte Carlo in Statistical Mechanics: The Metropolis Algorithm

In 1953, Nicholas Metropolis, Arianna and Marshall Rosenbluth, and Augusta and Edward Teller published an algorithm — designed for the MANIAC computer at Los Alamos — that solved a problem no brute-force computation could touch: how to sample the overwhelmingly vast configuration space of a many-particle system so that the configurations you actually see are precisely the ones that matter physically. Seventy years later, the Metropolis algorithm remains the default engine of computational statistical mechanics.

1. The Sampling Problem

Statistical mechanics says that a system in thermal equilibrium at temperature T visits configuration (microstate) i with probability given by the Boltzmann distribution:

P(i) = exp(−Eᵢ / k_BT) / Z

Z = Σᵢ exp(−Eᵢ / k_BT) (the partition function, summed over ALL microstates)

For anything beyond a toy system, Z is an astronomically large sum — a lattice of just 20×20 Ising spins already has 2⁴⁰⁰ ≈ 10¹²⁰ microstates, more than there are atoms in the observable universe. Computing thermodynamic averages by literally summing over every microstate is therefore impossible. Ordinary Monte Carlo — sampling configurations uniformly at random and weighting by their Boltzmann factor — is also hopeless: at low temperature, overwhelmingly the random samples land on high-energy states with essentially zero weight, wasting almost all computational effort.

The key idea: instead of sampling configurations uniformly and weighting them, generate configurations directly with probability proportional to their Boltzmann weight — importance sampling. If you succeed, a simple unweighted average over the samples you generate already equals the correct thermodynamic average.

2. The Metropolis Algorithm

The Metropolis algorithm builds a Markov chain — a sequence of configurations where each one depends only on the previous one — whose long-run visiting frequency converges to the Boltzmann distribution. Each step:

1. Start from configuration i (current state) 2. Propose a trial move to a new configuration j (e.g. flip one spin, displace one particle) 3. Compute the energy change: ΔE = Eⱼ − Eᵢ 4. If ΔE ≤ 0: ACCEPT the move unconditionally If ΔE > 0: ACCEPT with probability p = exp(−ΔE / k_BT) (draw a random number r ∈ [0,1); accept if r < p) 5. If rejected, the chain stays at configuration i (count it again for the average) 6. Repeat from step 2 for the new current configuration

The acceptance rule always accepts moves that lower the energy, and accepts energy-raising moves only occasionally, with probability falling exponentially with ΔE — exactly the balance needed to spend most computational effort near the thermodynamically important, low-energy configurations while still occasionally exploring higher-energy states (which is what allows the system to escape local minima and correctly sample thermal fluctuations).

3. Detailed Balance and Why It Works

The algorithm's correctness rests on detailed balance: at equilibrium, the flow of probability from state i to state j must exactly equal the reverse flow from j to i:

P(i)·T(i→j) = P(j)·T(j→i)

where T(i→j) is the transition probability of the Markov chain

Splitting the transition probability into a proposal probability g(i→j) (chosen to be symmetric, g(i→j) = g(j→i), for a simple proposal such as flipping a random spin) and an acceptance probability A(i→j), detailed balance requires:

A(i→j) / A(j→i) = P(j) / P(i) = exp[−(Eⱼ − Eᵢ) / k_BT]

The Metropolis choice A(i→j) = min[1, exp(−ΔE/k_BT)] is one valid solution to this ratio (among several possible acceptance rules — the Glauber/heat-bath rule A = 1/(1+exp(ΔE/k_BT)) is another). Metropolis's choice is preferred in practice because it maximises the acceptance rate subject to satisfying detailed balance, making the Markov chain explore configuration space as efficiently as possible.

Ergodicity matters too: detailed balance alone guarantees the Boltzmann distribution is a stationary distribution of the chain, but the chain must also be able to reach every relevant configuration from any starting point (ergodicity) for it to actually converge there. Poorly chosen proposal moves — for example, ones that can never flip more than one spin at a time near a frozen glassy state — can make convergence prohibitively slow even though detailed balance holds.

4. Practical Considerations

5. Worked Example: The Ising Model

The 2D Ising model — a grid of spins sᵢ = ±1 with energy E = −J·Σ⟨ij⟩ sᵢsⱼ over nearest-neighbour pairs — is the canonical Metropolis test case. Flipping a single spin sₖ changes the energy by a purely local amount:

ΔE = 2J·sₖ·Σ_neighbours s_neighbour

Because ΔE depends only on the four (or six, or eight, depending on lattice geometry) neighbours of the flipped spin, evaluating the acceptance criterion costs O(1) regardless of system size — this locality is what makes Metropolis Monte Carlo for lattice models like Ising extremely fast per step, even though many millions of steps may be needed to reach equilibrium near the critical temperature.

Ising Model Simulation

Watch Metropolis Monte Carlo drive a spin lattice through the ferromagnetic phase transition in real time.

Open Simulation →

6. Beyond Physics

Computational Chemistry and Molecular Simulation

Monte Carlo methods complement molecular dynamics (see our companion article on the Lennard-Jones potential) whenever the quantity of interest is a thermodynamic average rather than a time-dependent property. Metropolis moves — displacing a molecule, rotating it, or attempting to insert/delete one (grand-canonical Monte Carlo) — are the workhorse of simulating phase equilibria, adsorption, and solvation free energies.

Bayesian Statistics and Machine Learning

The Metropolis-Hastings generalisation (allowing asymmetric proposals) underlies Markov chain Monte Carlo (MCMC) methods used throughout Bayesian statistics to sample posterior distributions that have no closed form — from cosmological parameter estimation to Bayesian neural network inference.

Combinatorial Optimisation

Simulated annealing — gradually lowering an artificial "temperature" parameter in a Metropolis loop applied to a cost function rather than a physical energy — is a general-purpose optimisation heuristic for problems like the travelling salesman problem, circuit layout, and protein structure prediction, where the Metropolis acceptance rule allows uphill moves early on to escape poor local optima.

Frequently Asked Questions

Why does the algorithm sometimes accept moves that increase energy?

Accepting only energy-lowering moves would make the simulation a pure minimisation, converging to the ground state (T=0) and never sampling the thermal fluctuations that define a system at finite temperature T. Occasionally accepting energy-raising moves, with probability falling off as exp(−ΔE/k_BT), is precisely what reproduces the Boltzmann distribution — it lets the system visit higher-energy configurations with the correct (small but nonzero) frequency, matching real thermal behaviour.

How many Monte Carlo steps are needed for a reliable result?

There is no universal number — it depends on the system size, temperature, and proximity to a phase transition. A practical approach is to run the simulation for progressively longer, tracking whether measured averages (energy, magnetisation, etc.) stabilise and whether the estimated error bars (accounting for autocorrelation between samples) shrink as expected with more independent samples. Near a critical point, the required number of steps can grow as a power law of the system size — a phenomenon called critical slowing down.

Is Metropolis Monte Carlo the same as molecular dynamics?

No. Molecular dynamics (see our companion article) integrates Newton's equations of motion to produce a genuine time trajectory, useful for dynamic properties like diffusion and viscosity. Metropolis Monte Carlo generates a sequence of configurations with no physical time associated with the moves — it is designed purely to sample the correct equilibrium distribution as efficiently as possible, and is often faster than MD for computing purely thermodynamic quantities when dynamics themselves are not of interest.

Who were Metropolis, Rosenbluth, and Teller?

Nicholas Metropolis led the computing group at Los Alamos National Laboratory and built the MANIAC computer used for the original simulation. Arianna and Marshall Rosenbluth, and Augusta and Edward Teller, co-authored the landmark 1953 paper "Equation of State Calculations by Fast Computing Machines" in the Journal of Chemical Physics, which described the algorithm for a hard-sphere fluid. Historical accounts differ on the exact division of intellectual credit among the five authors, but the algorithm has carried Metropolis's name ever since.

What is Metropolis-Hastings and how does it differ from the original algorithm?

W. Keith Hastings generalised the Metropolis algorithm in 1970 to allow asymmetric proposal distributions g(i→j) ≠ g(j→i). The acceptance probability becomes A(i→j) = min[1, (P(j)·g(j→i)) / (P(i)·g(i→j))], reducing to the original Metropolis rule when the proposal is symmetric. This generalisation is essential for sampling continuous, non-lattice distributions in Bayesian statistics, where symmetric proposals are often inefficient or impossible to construct.

What is a cluster algorithm and why is it needed?

Near a continuous phase transition, single-spin-flip Metropolis dynamics suffers from critical slowing down: correlated regions of spins ("clusters") grow to the size of the system, but single-spin flips can only change one site at a time, making it exponentially slow to flip an entire correlated region. The Wolff (1989) and Swendsen-Wang (1987) algorithms instead identify and flip entire clusters of correlated spins in a single Monte Carlo move, satisfying detailed balance while dramatically reducing the autocorrelation time near the critical point.

Can the Metropolis algorithm get stuck in a local minimum?

In principle no — because it can (rarely) accept energy-increasing moves, a properly ergodic Metropolis chain will eventually escape any local minimum given enough steps. In practice, "eventually" can mean an astronomically long time if the energy barrier is large compared to k_BT (the escape rate falls exponentially with barrier height, per the Arrhenius-like activation picture), which is exactly the challenge that simulated annealing and cluster algorithms are designed to mitigate.

What's the difference between canonical (NVT) and grand-canonical Monte Carlo?

Canonical Monte Carlo, as described above, samples configurations at fixed particle number N, volume V, and temperature T, using moves that rearrange existing particles (spin flips, displacements). Grand-canonical Monte Carlo additionally allows the particle number to fluctuate by proposing particle insertion and deletion moves, each accepted with a modified Metropolis criterion that includes the chemical potential — essential for simulating adsorption, phase coexistence, and open systems exchanging particles with a reservoir.

Sources