Lab 6.7 · 40 min

Lab: analysis by hand

A trajectory is only a long list of positions; every number we report comes from analysing it. We compute the radial distribution function, the mean squared displacement, the velocity autocorrelation, the van Hove function, the conductivity, the Onsager coefficients and the Haven ratio from trajectories small enough to do by hand. The numbers show what each recipe really averages over, why some quantities converge fast and others very slowly, and how to turn simulation units into S/m.

The setup

Two systems. Part A (steps 1–4) uses the 9-atom 2D Lennard-Jones box of Labs 2 and 3 (reduced units, T = 0.72, a gentle Bussi thermostat so the dynamics are realistic), plus a few made-up numbers small enough to do by hand. Part B (steps 5–7) uses 2 cations and 2 anions moving in 1D (nm, ps), and a Brownian model of 100 ions.

quantity what it averages g(r) pairs at distance r, over frames MSD(t) displacement², over atoms and origins VACF(t) v(0)·v(t), over atoms and origins G_s(r, t) histogram of displacements σ (conductivity) (Σ q Δr)², the whole system as one Haven ratio σ_NE / σ (self vs collective)

All positions used for displacements must be unwrapped: the atom is followed across the periodic walls instead of being put back in the box (step 2 shows why).

Step 1

Radial distribution function: counting pairs

Why: g(r) tells how the density around an atom differs from the average: g = 1 means "as in an ideal gas", a peak means a shell of neighbours. It is the bridge to X-ray and neutron scattering, and its first peak gives the coordination number. The recipe is counting, plus one division.

one frame: the lattice of Lab 2, ρ = 9/3.6² = 0.6944 36 pairs (minimum image): 18 at r = 1.200, 18 at 1.697 bin [1.10, 1.30]: neighbours per atom = 2 × 18 / 9 = 4.000 ideal gas expects ρ × 2πr × dr = 0.6944 × 2π × 1.2 × 0.2 = 1.0472 g = 4.000 / 1.0472 = 3.82 bin [1.60, 1.80]: 4.000 / 1.4809 = 2.70 everything else: 0
moving liquid, 4000 frames, bins of 0.05: first peak g = 2.71 at r = 1.125; g = 0 below 0.85 one single frame, bins in the peak region: 0.0 1.0 1.0 3.8 2.7 0.9 1.7 1.6 coordination number (neighbours closer than 1.45) = 4.36

What the numbers say: The factor 2 counts each pair for both atoms; the ideal-gas count 2πr·dr·ρ grows with r, which is why g → 1 at large distance even though there are more and more neighbours. A single frame is useless (36 pairs over 36 bins: mostly 0 or 3), so g(r) is always averaged over many frames, and it converges quickly because every frame contributes N(N−1)/2 pairs. Limitations: only r < L/2 is meaningful (here 1.8), and the bin width trades resolution against noise. In 3D the shell volume is 4πr²dr.

Step 2

Mean squared displacement: all time origins

Why: The diffusion coefficient D follows from how far atoms wander: in d dimensions MSD = 2dDt at long times (Einstein). A trajectory of n frames gives many displacements for each time lag, if we use every frame as a possible starting point (time origin).

x (nm) at t = 0, 1, 2, 3, 4, 5 ps: 0.00 0.30 0.10 0.60 0.80 1.20 lag 1: 0.3, −0.2, 0.5, 0.2, 0.4 squares 0.09, 0.04, 0.25, 0.04, 0.16 MSD = 0.1160 (5 samples; origin t=0 only: 0.0900) lag 2: 0.1, 0.3, 0.7, 0.6 MSD = 0.2375 (4 samples; t=0 only: 0.0100) lag 3: MSD = 0.6067 (3 samples; t=0 only: 0.3600) lag 4: MSD = 0.7250 (2 samples) lag 5: MSD = 1.4400 (1 sample) slope over lags 1–3 = 0.2453 nm²/ps 1D: D = slope / 2 = 0.1227 nm²/ps = 1.23×10⁻⁷ m²/s wrapped in a box L = 1 nm: 0.00 0.30 0.10 0.60 0.80 0.20 lag-5 MSD would be 0.04 instead of 1.44
9-atom LJ (2D): MSD at t = 1, 2, 5, 10: 0.227, 0.462, 1.183, 2.370 D = slope(t = 2–10) / 4 = 0.0598

What the numbers say: All origins turn one trajectory into many samples, so lags 1–3 already give a steady slope, while the single-origin MSD jumps around (0.09, 0.01, 0.36). The price is the long-lag end: lag 5 has a single sample, so the last part of any MSD curve is noise and must not be fitted. Also fit only the straight (diffusive) part, after the short-time ballistic region. With wrapped coordinates the MSD falls from 1.44 to 0.04 the moment the atom crosses a wall: always unwrap (LAMMPS dumps xu yu zu, GROMACS -pbc nojump).

Step 3

Velocity autocorrelation: the same D a second way

Why: Displacement is the time integral of velocity, so D can also come from how long an atom remembers its velocity: D = (1/d) ∫ ⟨v(0)·v(t)⟩ dt (Green–Kubo). Getting the same D from MSD and VACF is a strong check of the analysis.

v (nm/ps) at t = 0..5 ps: 1.0 0.7 0.5 0.4 0.1 0.2 lag 0: (1 + 0.49 + 0.25 + 0.16 + 0.01 + 0.04)/6 = 0.3250 lag 1: (0.70 + 0.35 + 0.20 + 0.04 + 0.02)/5 = 0.2620 lag 2: (0.50 + 0.28 + 0.05 + 0.08)/4 = 0.2275 lag 3: (0.40 + 0.07 + 0.10)/3 = 0.1900 lag 4: (0.10 + 0.14)/2 = 0.1200 1D trapezoid, lags 0–4, dt = 1 ps: D = ½(0.3250) + 0.2620 + 0.2275 + 0.1900 + ½(0.1200) = 0.902 nm²/ps
9-atom LJ: C(0) = ⟨v·v⟩ = N_f T / N = 1.278 C(t) turns negative at t = 0.25, minimum −0.11 C(0) at 0.35 D = ½ ∫ C dt up to t = 1: 0.0591 2: 0.0587 5: 0.0605 D from the MSD (step 2): 0.0598

What the numbers say: For the liquid, the two routes agree within 1–2 % (0.059–0.061 vs 0.0598): the analysis is consistent. The VACF also shows physics the MSD hides: it goes negative after 0.25 time units, the atom bouncing back from its cage of neighbours. Limitations: the integral must be stopped somewhere, and the noisy tail makes the answer drift (0.0587 → 0.0605); and velocities must be saved very often (here every 10 steps). The toy series shows the other danger: its VACF has not decayed by lag 4, so its "D" is not yet meaningful.

Step 4

Van Hove function: how displacements are distributed

Why: The MSD is just one number per time lag, the average of r². The self part of the van Hove function, G_s(r, t), is the whole histogram of displacements. If every atom diffuses the same way it is a Gaussian; if some atoms jump while others are stuck, it grows tails. The non-Gaussian parameter measures that with two averages.

10 displacements after time t (1D, nm): −0.5 −0.2 −0.1 0.0 0.1 0.1 0.2 0.3 0.9 −1.1 ⟨x²⟩ = 0.2470 ⟨x⁴⟩ = 0.21943 Gaussian would have ⟨x⁴⟩ = 3⟨x²⟩² = 0.18303 α₂ = ⟨x⁴⟩ / (3⟨x²⟩²) − 1 = 0.20 (in 3D: α₂ = 3⟨r⁴⟩ / (5⟨r²⟩²) − 1; in 2D: ⟨r⁴⟩/(2⟨r²⟩²) − 1) without the two jumps (0.9, −1.1): ⟨x²⟩ = 0.0563, α₂ = −0.02
9-atom LJ, t0.251520
α₂0.0380.0330.0420.030

What the numbers say: Two "hoppers" out of ten carry 80 % of ⟨x²⟩ and push α₂ from about 0 to 0.20. The MSD alone cannot tell this situation (a few fast ions, many stuck) from uniform diffusion; G_s and α₂ can. Our simple LJ fluid stays nearly Gaussian (α₂ ≈ 0.03–0.04). In ionic liquids and glassy electrolytes, α₂ peaks at intermediate times, which is the signature of cages and hopping. The distinct part G_d(r, t), where a different atom is found at time t, is the time-dependent g(r) and shows how neighbours replace each other. Limitation: the tails are rare events, so G_s and α₂ need many more samples than the MSD.

Step 5

Conductivity, Onsager coefficients and the Haven ratio: 2 + 2 ions

Why: Conductivity is a collective property: it depends on how the total charge moves, ΣqΔx, not on how far each ion goes. If a cation and an anion travel together, they carry no current, even though both diffuse. The Nernst–Einstein estimate σ_NE uses only the self terms; the Haven ratio σ_NE/σ measures how much correlations change the result.

x (nm) at t = 0..4 ps; c1 and a1 move together c1 (+1) 0.0 0.2 0.5 0.6 0.9 a1 (−1) 0.4 0.6 0.9 1.0 1.3 c2 (+1) 2.0 1.8 2.1 2.3 2.2 a2 (−1) 3.0 3.3 3.1 3.0 3.4 lag-1 displacements (4 origins), mean square: c1 0.2 0.3 0.1 0.3 0.0575 a1 0.2 0.3 0.1 0.3 0.0575 c2 −0.2 0.3 0.2 −0.1 0.0450 a2 0.3 −0.2 −0.1 0.4 0.0750 self sum (-> σ_NE) 0.2350 charge displacement ΔM = Σ q Δx: −0.5 0.5 0.3 −0.5 ⟨ΔM²⟩ = 0.2100 (-> σ) Haven ratio = σ_NE / σ = 0.2350 / 0.2100 = 1.12 Onsager-type sums (cations P, anions M): L₊₊ ~ ⟨P²⟩ = 0.1225 L₋₋ ~ ⟨M²⟩ = 0.1875 L₊₋ ~ ⟨P M⟩ = 0.0500 L₊₊ + L₋₋ − 2L₊₋ = 0.2100 (= ⟨ΔM²⟩) t₊ = (L₊₊ − L₊₋)/(L₊₊ + L₋₋ − 2L₊₋) = 0.345 t₊ from self diffusion only: 0.1025/0.2350 = 0.436

What the numbers say: The pair c1–a1 adds 0.115 to the self sum and exactly 0 to ΔM: a neutral pair diffuses but carries no current, so σ is lower than σ_NE and the Haven ratio is above 1. The Onsager decomposition shows where it comes from: L₊₋ > 0 means cations and anions tend to move the same way. It also changes the transference number, from 0.436 (self diffusion only) to 0.345 (with correlations), which matters for battery electrolytes. These are lag-1 numbers for illustration; in practice σ and the L's come from the long-time slopes, exactly as D comes from the MSD slope. The identity L₊₊ + L₋₋ − 2L₊₋ = ⟨ΔM²⟩ is a good check of any implementation.

Step 6

Units: from nm²/ps to S/m

Why: Simulation output comes in nm, ps and e; experiments report S/m or mS/cm. A unit slip here gives errors of factors of 10⁶, so it is worth one careful calculation.

Nernst–Einstein (3D): σ_NE = e²/(k_B T) × n × (D₊ + D₋) n = 2.5 ion pairs/nm³ = 2.5×10²⁷ /m³ D₊ = 2.0×10⁻¹¹, D₋ = 1.5×10⁻¹¹ m²/s, T = 300 K e²/(k_B T) = 2.5670×10⁻³⁸ / 4.1419×10⁻²¹ = 6.1975×10⁻¹⁸ σ_NE = 6.1975×10⁻¹⁸ × 2.5×10²⁷ × 3.5×10⁻¹¹ = 0.542 S/m = 5.42 mS/cm Haven ratio 1.5: σ = 0.542/1.5 = 0.362 S/m = 3.62 mS/cm from a simulation: σ = e² / (6 V k_B T) × slope of ⟨|Σ q Δr|²⟩ V = 125 nm³: this σ needs a slope of 4.375×10⁻⁸ m²/s = 0.0437 e² nm²/ps conversion: 1 m²/s = 10¹⁸ nm² / 10¹² ps = 10⁶ nm²/ps D₊ = 2.0×10⁻¹¹ m²/s = 2.0×10⁻⁵ nm²/ps

What the numbers say: Every factor is visible: the charge squared, the thermal energy, the ion density and the sum of diffusion coefficients. Typical ionic-liquid numbers (D ~ 10⁻¹¹ m²/s, a few ion pairs per nm³) give a few mS/cm, as measured. Remember the conversion 1 m²/s = 10⁶ nm²/ps, and that σ (from ⟨|ΣqΔr|²⟩) has a 6 (3D) in the denominator just like D from the MSD. Here n counts ion pairs, so each species has density n; for a salt like Li₂X the charges and densities must be counted species by species.

Step 7

Statistics: why collective quantities converge so slowly

Why: D is an average over every ion; σ comes from one quantity per time origin, the total charge displacement of the whole box. With N ions, the self average has about N times more independent samples. How much noisier is σ in practice?

Brownian model: 50 cations + 50 anions in 1D, D = 1 each 34 of the 100 ions are in neutral pairs (move together) expected: D_self = 1 D_σ (per ion) = 1 − 0.34 = 0.66 Haven = 1 / 0.66 = 1.515 40 independent runs of 2000 steps: D_self = 1.003 ± 0.024 (2.4 %) D_σ = 0.665 ± 0.171 (25.8 %) Haven = 1.61 ± 0.43 (range 0.91 to 3.05) noise ratio collective / self = 10.8 (√100 = 10)

What the numbers say: The same runs give D to 2.4 % but σ only to 26 %, about √N = 10 times worse, and a single run can report a Haven ratio anywhere from 0.91 to 3.05 when the true value is 1.52. To make σ as precise as D you need about N times more sampling (longer runs or several independent runs; a bigger box does not help σ, because ΔM is still one number per time origin). That is why conductivities and Onsager coefficients from short simulations often scatter, and why papers should report error bars from independent runs or block averaging. The self quantities (D, t₊ from self diffusion) are the cheap ones; the collective ones carry the correlations but cost far more.

Summary

quantitymerit (number)limitation (number)
g(r)converges fast: N(N−1)/2 pairs per frame; CN = 4.36only r < L/2; one frame useless
MSD, all originsD = 0.0598 from a short runlong lags have few samples; unwrap (1.44 vs 0.04)
VACF / Green–KuboD = 0.059–0.061, shows the cagewhere to stop the integral; frequent output
G_s, α₂sees hoppers MSD cannot (α₂ 0.20 vs −0.02)tails need many samples
σ, Onsager L'sinclude correlations (t₊ 0.345 vs 0.436)~√N noisier: 26 % vs 2.4 %
Haven ratio σ_NE/σmeasures ion pairing (1.12, 1.52)single runs range 0.91–3.05