Skip to content

2D Diffusion & Mean Squared Displacement (MSD) Analysis ​

Introduction ​

Diffusion is the spontaneous net movement of particles from regions of higher concentration to regions of lower concentration driven by microscopic thermal fluctuations (Brownian motion). In cellular and molecular biophysics, single-particle tracking (SPT) microscopy enables researchers to trace coordinate trajectories of fluorescently tagged molecules, vesicles, and bacteria over time.

To extract the macroscopic diffusion coefficient (D) from discrete coordinate timeseries without continuous calculus approximations, we implement a discrete sliding-window Mean Squared Displacement (MSD) analysis.


Theoretical Framework ​

Trajectory Coordinates ​

Consider a particle tracked across N discrete time slices at uniform sampling intervals Δt=5.0 seconds. The recorded trajectory is represented as a sequence of spatial coordinates:

{(xi,yi)}i=1N,ti=i⋅Δt

Mean Squared Displacement (MSD) ​

For an integer lag window n∈{1,2,…,N−1}, the elapsed time lag is τ=n⋅Δt. The time-averaged Mean Squared Displacement across all non-overlapping or overlapping intervals of duration τ is defined as:

MSD(τ)=1N−n∑i=1N−n[(xi+n−xi)2+(yi+n−yi)2]

Extracting the Diffusion Coefficient (D) ​

In two-dimensional isotropic Brownian diffusion, Einstein's diffusion relation dictates:

MSD(τ)=4Dτ

Plotting MSD(τ) against time lag τ yields a linear relationship whose slope m satisfies:

m=4D⟹D=m4

NOTE

The "Max Window" Statistical Anomaly:
As the lag window n approaches N, the number of available independent displacement pairs (N−n) diminishes rapidly. At n=N−1, only a single displacement pair is evaluated, causing statistical variance to diverge sharply. Standard biophysical protocol restricts linear regression to the initial 10%--25% of the MSD curve to ensure robust parameter estimation.


Empirical Trajectory Dataset ​

The experimental trajectory consists of 65 sequential time slices (Δt=5 s, total duration 325 seconds):

Time SliceTime t (s)X CoordinateY Coordinate
158815
2108716
3158518
4208121
5258021
10506725
201005011
301504620
402004821
502505019
603004014
653254418

(Full timeseries of 65 coordinate pairs archived in lab/projects/diffusion-coefficient/msd.py)


Computational Methodology ​

The MSD pipeline is implemented in Python using NumPy and Pandas:

python
def calculate_msd(data, dt=5.0):
    N = len(data)
    lags = np.arange(1, N)
    msd_values = []

    for lag in lags:
        dx = data['x'].diff(periods=lag).dropna()
        dy = data['y'].diff(periods=lag).dropna()
        squared_displacement = dx**2 + dy**2
        msd_values.append(squared_displacement.mean())

    tau_values = lags * dt
    return tau_values, np.array(msd_values)

Linear regression over the initial 25% data cutoff (τ≤80 s) yields the slope m and empirical 2D diffusion coefficient D:

D=slope(MSD vs τ)4

Interactive Marimo Notebook Pipeline (Future Integration) ​

The reactive computation script lab/projects/diffusion-coefficient/msd.py is configured with PEP 723 metadata:

python
# /// script
# requires-python = ">=3.13"
# dependencies = [
#     "marimo>=0.20.2",
#     "matplotlib==3.10.8",
#     "numpy==2.4.2",
#     "pandas==3.0.1",
# ]
# ///

Note: Per portfolio architecture specifications, full client-side WebAssembly (WASM) marimo runtime integration is scheduled for subsequent releases, with the analytical mathematical models and empirical timeseries preserved in native Markdown.


References ​

  1. Einstein, A. (1905). Über die von der molekularkinetischen Theorie der Wärme geforderte Bewegung von in ruhenden Flüssigkeiten suspendierten Teilchen. Annalen der Physik, 322(8), pp. 549–560.
  2. Qian, H., Sheetz, M.P. and Elson, E.L. (1991). Single particle tracking: analysis of diffusion and flow in two-dimensional systems. Biophysical Journal, 60(4), pp. 910–921.
  3. Michalet, X. (2010). Mean square displacement analysis of single-particle trajectories with localization error: Brownian motion in an isotropic medium. Physical Review E, 82(4), 041914.