Lab 2.8 · 35 min
Lab: packing and equilibrating a liquid
Lab 2.7 started from a neat lattice of 9 atoms. A real project starts from a target density and a few hundred or thousand molecules that must be put in a box without overlapping, relaxed, heated and equilibrated before anything is measured. We do every stage for 256 Lennard-Jones atoms (liquid argon): box size from the density, random insertion and why it fails, steepest descent by hand, NVT and NPT, and three tests that tell you when the system is ready.
- Turn a target density into a box size, and see why random positions blow up the simulation
- Do steepest-descent minimization by hand and see what it fixes and what it does not
- Run NVT and NPT from different starts and decide, with numbers, when the system is equilibrated
The setup
The recipe used by every real setup (Packmol, gmx insert-molecules, LAMMPS create_atoms random):
System: N = 256 LJ atoms, cutoff 2.5σ, k_BT = 0.722 and ρ* = 0.8442 (the liquid near the triple point, the classic test state). Bussi thermostat (τ = 0.5), C-rescale barostat, Δt = 0.005. Argon: σ = 3.405 Å, ε = 0.996 kJ/mol.
Step 1
Box size from the target density
Why: Experiments give density in g/cm³; a simulation needs a number of molecules and a box length. The conversion is one line, but getting it wrong by a few percent shifts every property you compute (pressure most of all).
What the numbers say: Pure liquids with a known density can be built at the right size directly. For a solution, a mixture or a new force field, the density is part of the answer: build at a guess, then let NPT (Step 4) find it. Our test state ρ* = 0.8442 is the same liquid as argon at 1.42 g/cm³.
Step 2
Random positions: why they fail, and why a tolerance only partly helps
Why: The obvious way to fill a box is to put each atom at a random point. In a dense liquid, that makes many atoms land almost on top of each other, and the LJ repulsion grows as r⁻¹².
Insertion with a tolerance: a new atom is refused if it is closer than d to any placed atom (give up after 20 000 refusals in a row).
| d (σ) | placed | trials | ρ* reached | packing of d-spheres |
|---|---|---|---|---|
| 0.8 | 256 | 1 621 | 0.844 | 0.226 |
| 0.9 | 256 | 20 736 | 0.844 | 0.322 |
| 1.0 | 203 | 119 624 | 0.669 | 0.351 |
| 1.1 | 144 | 67 746 | 0.475 | 0.331 |
What the numbers say: Fully random positions give forces 10¹⁵ times too large and the first step sends atoms flying. A tolerance removes the worst clashes, but a tolerance equal to the atom size cannot reach a liquid density: random filling jams long before. That is why Packmol uses a tolerance smaller than the molecules (2 Å) and why a minimization always follows. A lattice start (Lab 2.7) avoids the problem entirely, at the price of having to melt it.
Step 3
Steepest descent by hand
Why: Minimization moves every atom downhill along its force until no force is large. GROMACS uses a simple, robust rule: move the atom with the largest force by a step h, others in proportion; grow h when the energy falls, cut it hard when it rises.
The random 256-atom box, stopped at the GROMACS default emtol = 10 kJ/mol/nm = 10/(0.996/0.3405) = 3.42 ε/σ:
| iteration | U/N | |F|max | h |
|---|---|---|---|
| 0 | 3.9×10¹¹ | 1.6×10¹⁶ | 0.010 |
| 5 | 2.1×10⁷ | 5.7×10¹⁰ | 0.025 |
| 20 | 134 | 1.1×10⁵ | 0.38 |
| 50 | −4.97 | 81 | 0.070 |
| 100 | −5.78 | 31 | 0.082 |
| 160 (done) | −6.00 | 2.2 |
What the numbers say: Steepest descent removed every clash in 160 iterations; the start that exploded now conserves energy. But a minimized structure is not an equilibrium liquid: it sits at T = 0, at an energy (−6.00) far below the liquid at T = 0.722 (−5.20), and velocities given at T lose about half their energy to the potential. That is why minimization is always followed by a thermostatted run, not by a measurement.
Step 4
NVT from two starts, then NPT to find the density
Why: The thermostat brings the temperature to the target within a few τ. Whether the structure follows depends on the start: a lattice has to melt, a minimized random box is already disordered. The FCC order parameter (1 on the lattice, about 1/N in a liquid) shows how far along the melting is.
| t | FCC: U/N | T | FCC order | random: U/N | T |
|---|---|---|---|---|---|
| 0 | −6.331 | 0.717 | 0.999 | −5.993 | 0.723 |
| 1 | −5.583 | 0.552 | 0.528 | −5.350 | 0.700 |
| 2 | −5.480 | 0.629 | 0.450 | −5.232 | 0.682 |
| 5 | −5.386 | 0.732 | 0.411 | −5.142 | 0.708 |
| 10 | −5.155 | 0.737 | 0.124 | −5.270 | 0.696 |
| 20 | −5.258 | 0.703 | 0.009 | −5.175 | 0.751 |
| 40 | −5.153 | 0.749 | 0.009 | −5.198 | 0.717 |
What the numbers say: The temperature is right after t ≈ 1 in both runs, but the lattice start keeps crystal order until t ≈ 10: temperature alone says nothing about whether the structure has relaxed. NPT started 17% too dilute and found the density to 0.25% (1 error bar) within t ≈ 10. This is how the density of the NaCl solution in Step 1 would be found.
Step 5
When is it equilibrated? Three tests
Why: Everything before equilibrium must be thrown away, and everything after kept. Throwing away too little biases the average; too much wastes data. The tests below replace “it looks flat”.
(i) Choose t₀ to maximize the number of independent samples after it: N_eff = (n − n₀)/g, with g the statistical inefficiency of the data after t₀ (Lab 6.8).
| series | t₀ | g after t₀ | N_eff |
|---|---|---|---|
| U/N, FCC start | 8.0 | 15.2 | 42 |
| U/N, random start | 2.0 | 16.6 | 46 |
| FCC order, FCC start | 10.0 | 21.9 | 27 |
| ρ*, NPT from 0.70 | 11.3 | 18.2 | 43 |
(ii) Half-split: compare the means of the first and second halves of what is kept.
(iii) Independent replicas (different starts and seeds), t > 12 kept:
| start | U/N | P* |
|---|---|---|
| FCC | −5.192 ± 0.009 | 0.89 ± 0.05 |
| random + minimized | −5.200 ± 0.009 | 0.87 ± 0.05 |
| FCC, seed 2 | −5.202 ± 0.016 | 0.84 ± 0.09 |
| random + minimized, seed 2 | −5.204 ± 0.010 | 0.83 ± 0.06 |
What the numbers say: Different quantities equilibrate at different times: the energy of the lattice start at t₀ ≈ 8, its structure at t₀ ≈ 10, the random start already at 2. Discard by the slowest quantity you care about. The half-split test can be fooled by the very trend it is meant to detect, so look at the trace as well. Replicas from different starts are the strongest test: if they agree within their error bars, no memory of the start is left.
Summary
| stage | what goes wrong without it | number |
|---|---|---|
| box from density | wrong pressure, wrong everything | L = 22.98 Å for 256 argon |
| careful insertion | overlaps: forces 10¹⁶, T = 10²⁴ after 1 step | 231 pairs closer than 0.8σ |
| tolerance d | d ≥ σ jams below liquid density | d = 1.0 stops at ρ* = 0.67 |
| minimization | explosion; it does not equilibrate | 160 iterations, U/N −6.00 (T = 0) |
| NVT | T right in t ≈ 1, structure in t ≈ 10 | FCC order 0.999 → 0.009 |
| NPT | unknown density stays wrong | 0.70 → 0.8421 ± 0.0019 (true 0.8442) |
| equilibration tests | biased averages | t₀ = 2–11; replicas agree to 0.005 |