Learn

Analyzing trajectories

A trajectory is just a list of positions over time. Everything that we report from a simulation comes from counting and averaging these positions in a careful way. This page shows how the usual quantities are computed in practice.

    Radial distribution function g(r)

    g(r) tells you how likely you are to find a particle at distance r from another one, compared with an ideal gas at the same density. The peaks are the neighbor shells, and g goes to 1 far away.

    To compute it, loop over all pairs, put each distance into a histogram bin of width dr, average over frames, and divide by what an ideal gas would give in that shell.

    g(r) = n(r) / (N ρ · 2πr dr) in 2D
    g(r) = n(r) / (N ρ · 4πr2 dr) in 3D

    Try: lower T to see sharper shells as the liquid gets more structured, or heat it up toward a gas.

    Mean squared displacement and diffusion

    The MSD is the average of |r(t) − r(0)|2 over particles (and over time origins in a real analysis). At very short times, particles fly freely, and the MSD grows as t2. After collisions randomize the direction, it grows linearly, and the slope gives the diffusion coefficient.

    MSD(t) = 2d D t for long t, d = number of dimensions
    D = slope / 4 in 2D, slope / 6 in 3D

    Always fit D only in the linear part. On a log-log plot, this is where the slope is 1.

    Try: change the friction and watch where the crossover from slope 2 to slope 1 moves.

    Density profiles near a surface

    Near a wall, liquids form layers. To see them, cut the box into thin slabs parallel to the surface, count particles in each slab over many frames, and divide by the slab volume. The same recipe gives the water density above a silica surface, or the composition across a polymer film.

    ρ(z) = ⟨ N in [z, z + dz] ⟩ / (A dz)

    Try: increase the wall attraction for a sharper first layer, or raise T to wash the layers out.

    Structure next to a surface

    If you put a solid slab in the middle of a periodic box, the liquid has two very different regions. One is the layers that touch the surface, and the other is the liquid far away, which looks like the bulk. You analyze them separately.

    The density profile is now measured as a function of the distance z from the surface, adding both sides of the slab. For g(r), you pick the reference particles by region. Inside the first layer, you only count neighbors in the same layer, and the ideal gas reference is that of the layer itself (a line here, and a plane in 3D). Far from the surface, you use the normal bulk g(r).

    layer, 2D box: g(r) = n(r) / (Nlayer λ · 2 dr) with λ = particles per length
    layer, 3D box: g(r) = n(r) / (Nlayer σA · 2πr dr) with σA = particles per area

    The layer g(r) has sharper and longer-ranged peaks, because the surface squeezes the particles into an almost crystal-like order, while the far g(r) matches the free liquid.

    Try: push the surface attraction up, and watch the first density peak grow and the layer g(r) become solid-like. If you lower it, the two g(r) curves get closer.

    Diffusion along and across a surface

    Near a surface, the MSD has to be split by direction. Along the surface (lateral), particles can still diffuse, often more slowly because the surface holds them. Across the surface (normal), they are blocked, so the normal MSD flattens out instead of growing forever.

    Group the particles by where they are at each time origin, and then average the x and y displacements separately. In 3D, the lateral part has two directions, so D = slope / 4 for the lateral MSD, and slope / 2 for one direction, as here.

    MSDx(t) = ⟨(x(t0+t) − x(t0))2⟩group, t0 → 2 D∥ t

    There are two practical points. First, use unwrapped coordinates, because otherwise a jump across the periodic boundary looks like a huge step. Second, particles leave the layer over time, so for long lags, the "layer" curve slowly turns into a bulk curve. Better analyses use survival probabilities for this, but the idea is the same.

    Try: compare the solid orange and blue curves to see the lateral slowdown at the surface. Then, raise the attraction and see the gap grow. The dashed orange line shows the confinement in z.

    Hydration shell and coordination number

    The RDF between a solute and the solvent tells you how the solvent packs around it. The first peak is the first solvation shell, and the first minimum after it is its outer edge. For water around an ion, this is the hydration shell.

    If you integrate the RDF up to that minimum, you get the coordination number, which is the average number of solvent molecules in the first shell.

    n(r) = ρ ∫0r g(r') 2πr' dr' in 2D, 4πr'2 in 3D
    coordination number = n(rmin)

    For Na+ in water this gives about 5 to 6, and for Cl−, about 6 to 7. The same recipe works for water around a silica surface group or around a polymer bead.

    Try: grow the solute, and the shell holds more neighbors. Raise the attraction, and the first peak gets taller and sharper, which is what a strongly hydrated ion looks like.

    Hydrogen bonds in water

    In most force fields, a hydrogen bond is not a separate force, but it emerges from the charges and the LJ interactions. Analysis tools count a hydrogen bond with a geometric rule. In a common rule, the oxygen-oxygen distance is below 3.5 Å, and the angle between the donor O-H bond and the donor-acceptor O···O line is below 30°.

    From this rule, you get the number of hydrogen bonds per molecule, their lifetimes (how long a pair stays bonded), and how a surface changes the water network. This last point is what my analysis of surface water looks at.

    Try: drag the second molecule and turn it. Then, change the cutoffs and see how much the count depends on the definition.

    How big is a polymer chain?

    There are two standard measures, which are the end-to-end distance Ree and the radius of gyration Rg (the RMS distance of the monomers from the center of the chain). Both grow as a power of the chain length N.

    R ~ Nν
    ν = 1/2 ideal chain (random walk, theta solvent)
    ν = 3/4 self-avoiding in 2D, about 0.588 in 3D (good solvent)

    Fitting log R against log N gives ν, which tells you the solvent quality.

    Try: switch between ideal and self-avoiding walks and watch the fitted exponent move.

    Order parameters

    An order parameter is a single number that is zero in the disordered phase and nonzero in the ordered one. For rod-like molecules, such as liquid crystals, tilted SAM chains, and stretched polymers, the nematic order parameter measures how well they are aligned, regardless of which end points where.

    2D: S = | ⟨ e2iθ ⟩ |
    3D: S = ⟨ (3cos2θ − 1)/2 ⟩, θ measured from the director

    Try: cool slowly from high T and watch S rise as the domains align. The rods in orange are far from the average direction.

    Is this atom crystal or liquid?

    To find out which atoms are in a crystal, describe each atom by a few numbers about its neighbors, and then group similar atoms. Here, the features are the number of neighbors n and the bond-orientational order ψ6, which is 1 for a perfect hexagon. Tools such as OVITO do the same with common neighbor analysis or Steinhardt parameters.

    ψ6 = | (1/n) Σj e6iθij |

    Then, k-means with two clusters splits the atoms into crystal-like and liquid-like groups. Project 3 uses the same idea on MD trajectories of a small peptide.

    Try: raise the hot-side temperature and watch the liquid region grow and its cloud move in the feature plot.