Lesson 6.2 · 14 min

Mean squared displacement and diffusion

The mean squared displacement (MSD) measures how far atoms wander. At long times it grows linearly, MSD = 6Dt, and its slope gives the self-diffusion coefficient D, one of the most common numbers reported from MD and directly comparable with NMR experiments.

The idea

Follow each atom from time 0 to time t and measure how far it has moved, r(t) − r(0). The average of the square of this displacement over all atoms is the mean squared displacement:

MSD(t) = ⟨ |r(t) − r(0)|² ⟩

Because every moment in an equilibrium run is an equally good starting point, we also average over all time origins. This makes the MSD much smoother than using t = 0 only.

Two regimes (code tab, Part 2):

In between, a dense liquid shows a "cage" region where atoms rattle among their neighbours. In a solid the MSD stops growing (D = 0); in glasses and polymer electrolytes the cage can last nanoseconds.

Getting D. Fit a straight line to the MSD in the region where the log–log slope is 1, and divide the slope by 6 (by 4 in 2D, by 2 in 1D). For the LJ liquid at ρ* = 0.8442, T* = 0.722 this gives D* ≈ 0.03 (for argon, about 1.6 × 10⁻⁵ cm²/s).

Three classic mistakes:

For ionic liquids and battery electrolytes, the MSD can stay sub-diffusive for many nanoseconds, so check the log–log slope before trusting a D. Self-diffusion is what pulsed-field-gradient NMR measures.

Key idea. MSD(t) = ⟨|r(t) − r(0)|²⟩, from unwrapped coordinates and averaged over atoms and time origins. Where the log–log slope is 1, D = slope / 6. Add the finite-size correction for small boxes.

The algorithm

save unwrapped positions every n steps (or unwrap: add L each time an atom crosses the box)
for each lag k = 1 ... K:
    MSD[k] = mean over atoms i and origins t0 of |r_i(t0 + k) - r_i(t0)|²
check the log-log slope; pick t1..t2 where it is ≈ 1
D = slope of a linear fit of MSD(t) on [t1, t2] / 6
error: split the run into blocks (or use x, y, z separately) -> D ± std / sqrt(n_blocks)
finite size: D_inf = D(L) + 2.837297 k_B T / (6 π η L)   (cubic box; η = shear viscosity)
  1. Remove centre-of-mass drift (or check it is zero) before computing the MSD.
  2. The lag time should not exceed about a third of the run; long lags have few independent origins.
  3. For mixtures compute one MSD per species (Li⁺, anion, solvent). Cross terms and collective motion belong to conductivity (Lesson 6.5).
  4. Fast all-origin MSD uses FFTs (cost N_frames log N_frames), as in MDAnalysis EinsteinMSD(fft=True). Other tools: GROMACS gmx msd, LAMMPS compute msd (single origin!), TRAVIS.