Learn

Diffusion

Diffusion is what random motion looks like on average. This page shows how the random walk of single particles turns into Fick's law, how to get a reliable diffusion coefficient out of a simulation, and how ions move when you switch on an electric field.

    From random walks to Fick's law

    Each particle takes random steps. No single path is predictable, but the cloud spreads in a very predictable way. The concentration profile is a Gaussian, and its width grows with the square root of time. This is the solution of Fick's second law for particles that start in one place.

    ∂c/∂t = D ∂2c/∂x2
    c(x, t) = exp(−x2/4Dt) / √(4πDt), ⟨x2⟩ = 2Dt

    Try: double D, and the cloud spreads to the same width in half the time.

    Calculating D from the MSD

    The Einstein relation says that the MSD becomes a straight line at long times, and the slope gives D. In practice, there are three things to get right.

    First, average over time origins, not only over particles. Every frame can be a new starting point, which gives far more statistics for short lags. Second, fit only the linear part. At short times, the motion is still ballistic (MSD ~ t2), and including it biases D. Third, do not fit the longest lags, because they have few independent origins and are noisy.

    MSD(t) = ⟨|r(t0 + t) − r(t0)|2⟩i, t0 → 2d D t
    D = slope / 4 in 2D, slope / 6 in 3D

    In periodic MD, also remember that D depends on the box size (a known 1/L correction from hydrodynamics), and always use unwrapped coordinates.

    Try: set the fit window to start at 0, and see D come out too low. Then, use only 5 particles and watch the fitted value jump around between resets.

    Ion diffusion and conductivity

    Ions diffuse like any other particle, but they also respond to an electric field. For a single ion, the drift velocity follows from D through the Einstein relation for mobility, so diffusion and conductivity are two views of the same motion.

    v = μ q E, μ = D / kT
    Nernst-Einstein: σ = (n+ q+2 D+ + n− q−2 D−) / kT

    In a real electrolyte, cations and anions attract each other and form short-lived pairs. A neutral pair does not carry current, so the measured conductivity is lower than the Nernst-Einstein estimate made from the individual D values. Comparing the two is a standard way to measure ion pairing in simulations of salts and ionic liquids.

    Try: with a Coulomb strength of 0, the dots sit on the dashed ideal lines. If you increase it, ion pairing pulls the drift below the ideal value.

    Many walkers at once

    This is the same idea in 2D, with a straight-line fit through the origin. Real analysis tools, such as MDAnalysis and gmx msd, do exactly this, with time-origin averaging and a fit window that you choose.