3.2 Replica Exchange and the Melting of a Cluster#
Notebook overview#
A single molecular-dynamics trajectory has a blind spot. On a rugged landscape, with deep minima separated by high barriers, a low-temperature run never has the energy to climb out of the basin it starts in, so its averages depend on where it began. The previous notebook met this as the trapping of an optimization; here it becomes the central problem of sampling. The fix is elegant: run many copies of the system at different temperatures at once, and let them trade configurations. The hot copies cross barriers freely, the cold copies inherit those crossings through the swaps, and the whole set samples the landscape far better than any one of them could alone. This is replica exchange, or parallel tempering.
This is the exercise from Lecture 12, and we take it in two steps. First we build the algorithm on a system simple enough to see exactly what it does: a double well, where a single chain stays stuck on one side and parallel tempering visits both. Then we turn to the course’s real result. The original ran a 38-atom argon cluster in LAMMPS with twelve replicas spanning 2 to 40 K, and from the committed output we reconstruct the caloric curve and the heat-capacity peak that pin down the cluster’s melting temperature.
Provenance. This notebook develops Lecture 12 of the course (replica exchange / parallel tempering, ensembles, and the heat capacity), an exercise designed by the author (Raymond Amador). The original ran a LAMMPS parallel-tempering simulation (the
replica-exchange.lammpsscript shown in Exercise 3) on the Euler cluster and committed its output; the caloric curve in Exercises 4 and 5 is reconstructed from those twelve real replica logs by pooling each processor’s potential energy by the reference temperature it occupied. The algorithm itself is reproduced in Python. The full course credit is in the footer.
Reading a validation. Each exercise closes with a check against something independent: an exact Boltzmann population, the monotonicity of a caloric curve, the known melting range of the cluster. A ✗ flags a mismatch to track down, not a verdict; a ✓ is strong evidence, not proof.
Units and scope. The double-well demo uses dimensionless energy and temperature. The cluster data is from a real argon run, so energies are in eV and temperature in kelvin; with the deck’s \(\varepsilon=0.01042\,\)eV \(=120.9\,k_B\)K the reduced temperature is \(T^\ast=T/120.9\). For methods see Allen & Tildesley [AT17] and Frenkel & Smit [FS02]; each replica runs constant-temperature dynamics under a Nosé-Hoover thermostat (
fix nvtin the Exercise 3 deck).
Theory in brief#
The sampling problem#
A Monte Carlo or molecular-dynamics simulation at temperature \(T\) samples the Boltzmann distribution \(P(\mathbf x)\propto e^{-E(\mathbf x)/k_BT}\). To cross a barrier of height \(\Delta E\) it must wait a time \(\sim e^{\Delta E/k_BT}\), which at low temperature is astronomically long. The simulation is then non-ergodic on any practical timescale: it explores only the basin it started in, and its averages are wrong.
Parallel tempering#
Replica exchange runs \(M\) copies of the system at temperatures \(T_1<T_2<\dots<T_M\) simultaneously. Each evolves under ordinary dynamics, and periodically two replicas at adjacent temperatures attempt to swap configurations. The swap is accepted with a Metropolis criterion that preserves detailed balance for the joint ensemble:
A configuration that wandered over a barrier at high temperature can then descend, swap by swap, to low temperature, so each replica samples its Boltzmann distribution while drawing on the barrier-crossing power of the hot ones. The temperatures are spaced (often geometrically) so that neighbouring energy distributions overlap and swaps are accepted often enough.
Thermodynamics from the temperatures#
Running every temperature at once hands us a thermodynamic sweep for free. The average energy as a function of temperature is the caloric curve \(\langle E\rangle(T)\), and its slope is the heat capacity
A finite cluster melts over a narrow temperature range where the energy rises steeply, so \(C_v\) shows a peak there: the cluster’s melting temperature, read straight off the curve.
Setup#
The Setup below holds this notebook’s data and instruments — nothing you are asked to build. It is collapsed so the building stays yours; expand it whenever you want the details.
Exercise 1 — The trapping problem#
Take the symmetric double well \(U(x)=a(x^2-1)^2\) with \(a=5\), two basins at \(x=\pm1\) split by a barrier of height \(5\). At a low temperature \(T=0.25\) the Boltzmann distribution is symmetric, so a correct sampler should spend half its time in each basin. A single Metropolis chain started in the right basin does not: crossing the barrier costs \(e^{5/0.25}=e^{20}\), so it stays put for the entire run, and its sampled distribution is wrong by a factor of two.
Part a) Implement a Metropolis chain mc_chain.
Part b) Run it cold from the right basin and confirm it is trapped.
Fig. 33 The double well \(U(x)=5(x^2-1)^2\) (navy) and the distribution sampled by a single Metropolis chain at \(T=0.25\) started in the right basin (amber histogram). The chain never crosses the barrier of height 5, so it samples only the right well: a non-ergodic, and wrong, result, since the symmetric potential should populate both wells equally.#
Validation 1 — the single chain is non-ergodic#
Started in the right basin (\(x>0\)), the cold chain must spend essentially all its time there: a fraction near one, not the correct one-half.
✓ a single cold Metropolis chain stays trapped in one well [fraction with x>0 = 1.000]
True
Exercise 2 — Parallel tempering escapes the barrier#
Now run several replicas at once, from a cold \(T_1=0.25\) up to a hot \(T_M=4\) where the barrier is easily crossed, and attempt swaps between adjacent temperatures with the criterion Eq. 33. A configuration that crosses the barrier in a hot replica can be swapped down to the cold one, so the cold replica, the one we care about, finally samples both wells. Because the potential is symmetric, the exact Boltzmann answer is one-half in each, and parallel tempering recovers it.
Part a) Implement parallel_tempering, returning the cold replica’s samples.
Part b) Confirm the cold replica now populates both wells equally.
Fig. 34 Distribution of the cold (\(T=0.25\)) replica under parallel tempering across eight temperatures from 0.25 to 4 (amber), against the exact Boltzmann distribution \(P(x)\propto e^{-U(x)/T}\) (navy). The swaps carry barrier crossings down from the hot replicas, so the cold replica now samples both wells with the correct equal weight: the non-ergodicity of Exercise 1 is cured.#
Validation 2 — the cold replica now samples both wells equally#
With the swaps in place, the cold replica must populate the two symmetric wells with equal weight, the exact Boltzmann result: a fraction near one-half.
✓ parallel tempering recovers the exact symmetric Boltzmann populations [got 0.4975 vs expected 0.5 (rtol=1e-06, atol=0.12)]
True
Part c) The swap rule Eq. 33 only accepts when the two replicas’ energies are comparable, so parallel tempering works exactly when adjacent rungs overlap in energy. Measure that overlap directly: histogram each rung’s energies on a common grid and integrate the pointwise minimum of adjacent pairs, which is the standard overlap coefficient and equals 1 for identical distributions and 0 for disjoint ones. Report the acceptance rate alongside it — the two numbers are the same statement seen from opposite sides.
Part d) Track where each configuration goes. Rewrite the sampler as
pt_traced, carrying an integer label array alongside the positions and swapping
labels whenever configurations swap, so the rung occupied by each original replica
can be reconstructed. A configuration that starts cold should climb the ladder,
cross the barrier while hot, and come back down: those round trips are the
real efficiency measure of parallel tempering, far more informative than the
acceptance rate alone.
Write this one yourself — the implementation is the lesson.
swap acceptance = 0.863
adjacent energy overlap: min 0.872, mean 0.908
round trips of the initially-cold replica = 25
replicas visiting BOTH ends of the ladder = 8/8