Skip to content

Tutorial T05: Hydrodynamic Finite-Size Scaling of Self-Diffusion in Periodic Boxes ​

This tutorial validates the ParticleDynamics rigid-water, smooth long-range electrostatics, and unwrapped-trajectory transport stack by reproducing the periodic-box hydrodynamic finite-size scaling relation of Yeh & Hummer (2004) (J. Phys. Chem. B 108, 15873–15879) for TIP3P and SPC/E liquid water at   across four cubic periodic box sizes ( ,  ):

  1. Linear Hydrodynamic Scaling: Demonstrates that periodic boundary conditions suppress translational self-diffusion linearly in (  for SPC/E, for TIP3P) via long-range Oseen hydrodynamic image coupling, collapsing a finite-size suppression at   onto the infinite-system limit .

  2. Simultaneous Extraction of and Shear Viscosity : Recovers both the thermodynamic-limit self-diffusion coefficient and the bulk shear viscosity from the intercept and slope of vs. :

    • TIP3P reproduces the actual Yeh & Hummer (2004) TIP3P benchmark (  ,    ) within :     (   , ) and     (    , ; Green–Kubo reference from González & Abascal (2010):  ,     , ).

    • SPC/E (which Yeh & Hummer 2004 did not simulate) yields    , consistent with the 298 K scaling ( ) of the independent SPC/E study by Tazi et al. (2012) (   at and ), and     ( statistical uncertainty), consistent with the Green–Kubo value   of González & Abascal (2010) (    , ).

  3. UnwrapFeature & Offline GSD Software Parity Check: Verifies frame-by-frame agreement (1.35e-9 nm²) between online GPU MSDObservable and offline trajectory analysis via GSDWriter(...; write_unwrapped=true) + read_gsd_frame!, contrasting continuous unwrapped trajectories against wrapped-coordinate periodic jump artifacts, and quantifying system center-of-mass (COM) drift (2.24e-3 nm over 20 ps).

  4. Hydrodynamic Momentum Conservation (NVE vs. Weak CSVR): Compares momentum-conserving weak CSVR ( ) against microcanonical NVE at SPC/E   (    , ), while noting the   higher mean full-step temperature in the short weak-CSVR run.

Trajectory Visualization ​

Studio Fresnel snapshot of the four periodic water box sizes in the Yeh-Hummer finite-size scaling sweep

Path-traced Fresnel studio snapshot (tutorials/render_snapshots.py --targets T05) displaying the four scaled cubic periodic boxes ( ) used to extract the infinite-box self-diffusion and shear viscosity via linear Yeh–Hummer scaling.

What You Will Learn ​

  • Running multi-box-size rigid-water GPU sweeps with step_many!, ClusterPairList(force_accumulation=:fixed64), and PairTable zero-LJ hydrogen segregation.

  • Sharing a single power-of-2 ESP(continuity=:c2, mesh=(32, 32, 32)) CompactFFT plan across all box sizes and water models so GPU PTX kernels compile once and run at 9,016–14,560 steps/s.

  • Enforcing analytical rigid-water geometry with RigidWaterConstraint(settle_mode=:df64) (SETTLE,    in Float32, zero NaNs).

  • Equilibrating rigid water with CSVR and transitioning to microcanonical ConstantVolume (VelocityVerlet()) NVE for momentum-conserving transport properties.

  • Recording continuous unwrapped coordinates with GSDWriter(...; write_unwrapped=true) and cross-checking offline read_gsd_frame! MSDs (oxygen sites and molecular centers of mass) against online MSDObservable.

Running the Tutorial ​

All scripts live in tutorials/T05_yeh_hummer_diffusion/:

bash
# 1. Fast GPU smoke verification (4 SPC/E boxes, ~13.4 s warm GPU compute + GSD parity)
TUTORIAL_FAST=1 julia --project tutorials/T05_yeh_hummer_diffusion/run.jl
TUTORIAL_FAST=1 julia --project tutorials/T05_yeh_hummer_diffusion/analyze.jl

# 2. Full production validation (SPC/E + TIP3P x 4 NVE boxes + weak-CSVR parity)
julia --project tutorials/T05_yeh_hummer_diffusion/run.jl
julia --project tutorials/T05_yeh_hummer_diffusion/analyze.jl

# 3. Regenerate 300-DPI documentation figures
python3 tutorials/T05_yeh_hummer_diffusion/plot.py

Physics Background ​

Hydrodynamic Finite-Size Scaling in Periodic Cubic Boxes ​

In a momentum-conserving molecular dynamics simulation inside a cubic periodic box of side length , the velocity field generated by a diffusing molecule decays slowly as (the Stokeslet / Oseen tensor). Periodic boundary conditions couple every diffusing molecule to its own infinite periodic lattice of hydrodynamic images. Dünweg & Kremer (1993) and Yeh & Hummer (2004) solved the periodic Stokes equation via Ewald summation of the Oseen tensor, showing that the apparent self-diffusion coefficient underestimates the infinite-system limit by a leading term governed by the bulk shear viscosity :

where is the Madelung-like Wigner self-interaction constant of a simple cubic periodic lattice. Fitting linearly against across multiple cubic box sizes yields two transport properties simultaneously:

  1. Thermodynamic-limit self-diffusion from the   intercept.

  2. Bulk shear viscosity from the negative slope    :

and combining gives the effective Stokes–Einstein hydrodynamic radius   (for rigid water at ,   under stick boundary conditions, reflecting slip-like molecular friction).

Why Momentum Conservation Matters: NVE and Weak CSVR vs. Langevin ​

The Yeh–Hummer law relies on local momentum conservation (Navier–Stokes hydrodynamics):

  • Microcanonical NVE conserves momentum (up to finite-precision force residuals, audited below) and eliminates canonical energy fluctuations, reducing block-to-block variance in .

  • Weak global velocity-rescaling (CSVR,  ) applies a uniform global scalar rescaling factor to velocities while preserving zero center-of-mass momentum and spatial shear-mode structure, yielding diffusion coefficients consistent with NVE at the same thermodynamic temperature.

  • Strong local Langevin friction (BAOAB / Langevin) injects independent stochastic kicks into each particle, screening long-range hydrodynamic momentum transport over a screening length   and suppressing the physical Yeh–Hummer scaling. Equilibrating with a thermostat and switching to microcanonical NVE (or weak CSVR with  ) preserves hydrodynamic scaling.

Rigid Water Models, NVT Density Choice, and Temperature-Control Caveats ​

We benchmark two 3-site rigid water force fields in GROMACS units (nm, kJ·mol⁻¹, u, ps, e,   ,  ) at  ,  , and real-space cutoff  :

Model (nm) (kJ/mol) () () (nm)Fixed NVT (g/cm³)
SPC/E (Berendsen et al. 1987)
TIP3P (Jorgensen et al. 1983)

Two methodological choices in the recorded production dataset warrant explicit disclosure:

  1. Fixed experimental-like NVT densities vs. model NPT densities: To match the fixed-density setup of Yeh & Hummer (2004) for TIP3P ( ) and standard ambient SPC/E ( ), these runs hold density fixed rather than using the 1-bar NPT densities of the truncated-LJ models measured in Tutorial T04. For TIP3P, compresses the fluid by relative to Tutorial T04's 1-bar NPT density (), corresponding to roughly excess pressure (at   ). This modest compression slightly reduces and increases relative to 1-bar NPT TIP3P (for SPC/E, lies close to full-dispersion SPC/E bulk density , though above truncated-LJ rc = 0.90 nm NPT density).

  2. Half-step CSVR vs. full-step Velocity-Verlet temperature and box-to-box scatter: CSVR in ParticleDynamics rescales the leapfrog half-step velocity   to  . Because rigid-water librational modes ( ) have a finite shadow-temperature offset at  , the full-step Velocity-Verlet kinetic temperature sits roughly below . In the recorded production runs below, both SPC/E and softer-librating TIP3P were locked to a single hardcoded value   (an unverified equal-offset assumption across two models with different librational frequencies). In addition, the realized across the eight NVE runs spanned 0.98 K (295.18–296.16 K), including a +0.93 K upward ramp across the TIP3P box sizes (295.18 ± 0.41 K at   to 296.11 ± 0.23 K at  ), and the csvr_weak   run averaged +2.21 K hotter (297.47 ± 1.24 K) than its nve counterpart (295.26 ± 0.35 K). Because water self-diffusion varies by near , a systematic temperature ramp across can shift the apparent slope at the same scale as a few-percent change in (and partially accounts for csvr_weak sitting above nve). tutorials/T05_yeh_hummer_diffusion/run.jl measures directly per model during CSVR equilibration (initializing from the lowest-variance   box) rather than hardcoding 296.0 K; for higher-precision transport studies, a   or configurational-temperature control is recommended to verify the shadow-temperature offset directly.


Workflow API Walkthrough ​

1. Rigid-Water Force Field, ClusterPairList(:fixed64), and Shared CompactFFT Mesh ​

tutorials/T05_yeh_hummer_diffusion/run.jl initializes cavity-free cubic lattices ( FCC for  , SC for  , BCC for  , SC for  ) with every water molecule intact inside   so UnwrapFeature starts with zero split bonds. Zero-LJ hydrogens are segregated automatically via PairTable, forces are accumulated in fixed-point 64-bit integers (force_accumulation=:fixed64) for deterministic Float32 summation, and a shared (32, 32, 32) mesh lets CompactFFT compile its CUDA PTX kernels once for all four box sizes.

For the -continuous prolate ESP(real_cutoff = 0.90 nm, tolerance = 5e-4), the automatic mesh spacing is h_auto = 0.1762 nm (which resolves to a 30³ automatic mesh in the largest  ,   box). The shared 32³ mesh therefore gives   , which is 12% finer than the automatic mesh even at   (h = 0.1554 nm for SPC/E and 0.1559 nm for TIP3P), consistent with the NVE energy drift |ΔE/E|_rms being tightest at   (Table 2):

julia
using ParticleDynamics

tbl = PairTable(
    sigma=[model.sigma_O, 0.0],
    epsilon=[model.eps_O, 0.0],
    cutoff=[0.90, 0.0],
    type_names=[:O, :H],
)
lj = LennardJones(
    pair_table=tbl,
    vdw_modifier=:potential_shift,
    pairs=:neighborlist,
    neighborlist=ClusterPairList(buffer=cpl_buffer, force_accumulation=:fixed64),
)
es = ESP(
    coulomb_prefactor=138.93545764498226,
    real_cutoff=0.90,
    tolerance=5.0e-4,
    continuity=:c2,
    mesh=(32, 32, 32),   # shared CompactFFT plan; h <= 0.156 nm (12% finer than h_auto = 0.1762 nm)
)
rw = RigidWaterConstraint(triples; oh=model.oh, hh=model.hh, settle_mode=:df64)

2. Two-Stage CSVR Equilibration to Microcanonical NVE via step_many! ​

Each box melts from the crystal under fast CSVR ( , 5 ps), relaxes its hydrogen-bond network under gentle CSVR ( , 10 ps) while measuring the model's equilibrium full-step kinetic temperature , removes center-of-mass momentum with RATTLE velocity projection, and switches to microcanonical ConstantVolume(all_grp) (VelocityVerlet()) on the same GPU state:

julia
all_grp = Group(:all, AllSelection())
oxy_grp = Group(:O, TypeSelection(:O))
msd_obs = MSDObservable(oxy_grp; name=:msd)

sim = Simulation(
    sys;
    groups=Groups(all_grp, oxy_grp),
    integrator=Integrator(
        dt=0.002,
        scheme=VelocityVerlet(),
        forces=[lj, es],
        methods=[ConstantVolume(all_grp; thermostat=CSVR(kT=KB_KJ * 298.0, tau=0.1, interval=1))],
        constraints=[rw],
    ),
    observables=[ThermodynamicObservable(all_grp; name=:thermo), msd_obs],
    precision=Float32,
    seed=seed,
)
prepare!(sim)
step_many!(state(sim), sim.lowlevel_integrator, 0.002, 2_500; compute_energy=false)

# After gentle CSVR (tau = 0.5 ps) and COM removal, switch to microcanonical NVE:
sim.integrator = Integrator(
    dt=0.002,
    scheme=VelocityVerlet(),
    forces=[lj, es],
    methods=[ConstantVolume(all_grp)],
    constraints=[rw],
)
prepare!(sim)

3. Simultaneous Online MSDObservable + Offline GSDWriter(write_unwrapped=true) Audit ​

At SPC/E  , run.jl runs a dedicated 20-ps software-parity stage (41 frames at 0.5 ps cadence) attaching both InMemoryWriter (recording GPU-side MSDObservable) and GSDWriter(...; write_unwrapped=true) (exporting particles/position_unwrapped maintained by UnwrapFeature):

julia
mem_v = InMemoryWriter(
    schedule=Between(0, 10_000; every=250),
    observables=[msd_obs => [:msd, :elapsed_time]],
    write_start=false,
)
gw_v = GSDWriter(
    gsd_path;
    schedule=Between(0, 10_000; every=250),
    write_start=false,
    mode=:replace,
    write_unwrapped=true,
    sync_on_write=false,
)
sim.writers = Writer[mem_v, gw_v]
prepare!(sim)
run!(sim, Stage(:gsd_verify, steps=10_000; reset_step=0, reset_observables=true))

In analyze.jl, every GSD frame is read back with read_gsd_frame!(gsd_path; frame=k) as a software check (verify_check) verifying frame-by-frame agreement with the online MSDObservable, comparing oxygen-site MSD against mass-weighted molecular COM MSD, confirming unwrapped O–H bond continuity, measuring system COM drift, and contrasting unwrapped diffusion against naive wrapped-coordinate jumps.

4. Multi-Origin Sliding-Window Production and COM-Drift Subtraction ​

During multi-block production ( independent microcanonical NVE blocks per box, totaling per box), run.jl advances the GPU in 500-step (1.0 ps) batches via step_many!, reads continuous unwrapped oxygen coordinates from state(sim).{rx,ry,rz}_unwrap, logs the maximum block COM displacement, subtracts the instantaneous frame-wise oxygen center of mass, and evaluates the multi-origin sliding-window Einstein MSD over lags  .

In Float32 PME/ESP + SETTLE dynamics, small non-zero net force residuals from reciprocal-mesh interpolation and floating-point constraint arithmetic produce a slow drift of the total center of mass, measured as 2.24 × 10⁻³ nm over 20 ps in the SPC/E   GSD audit (a negligible   vs. MSD over 20 ps, though cumulative over longer un-rezeroed trajectories). Re-zeroing COM velocity between blocks and subtracting the instantaneous frame-wise COM before differencing prevents residual COM drift from biasing diffusive slopes; run.jl and analyze.jl log and report per-block COM drift across all production NVE blocks on fresh runs. Since ParticleDynamics v1.2.0, UnwrapFeature accumulates unwrapped coordinates in Float64 even when running Float32 states, preventing Float32 displacement stagnation on long trajectories, and CSVR removes center-of-mass momentum every nstcomm = 100 steps by default during canonical runs. Fitting the diffusive slope over   (past liquid water's cage/VACF relaxation and invariant vs. ) limits Qian–Sheetz–Elson finite-block slope variance ().


Results & Literature Validation ​

Part A: 1/L Hydrodynamic Scaling, Finite-Size Collapse & Extracted Viscosity ​

Hydrodynamic finite-size scaling of rigid SPC/E and TIP3P water self-diffusion vs literature

Panel (a) shows linear scaling across   for both rigid water models (  for SPC/E, for TIP3P; inverse-variance WLS   and ). Extrapolating   yields:

  • TIP3P (direct Yeh & Hummer 2004 benchmark):     vs. Yeh & Hummer (2004)   (   , ), and     ( relative SE) vs. Yeh & Hummer (2004)    (    , ) and González & Abascal (2010) Green–Kubo   (    , ). This recovers TIP3P's well-known   excessive self-diffusion and   underestimated viscosity relative to experimental water ( ,  ).

  • SPC/E (González & Abascal 2010 & Tazi et al. 2012 benchmarks):    , consistent with the 298 K scaling ( ) of Tazi et al. (2012) (   at and ), and     ( relative statistical uncertainty), consistent with the Green–Kubo viscosity   of González & Abascal (2010) (    , ). Note that an uncorrected 512-molecule box yields    , a finite-size artifact that can masquerade as closer agreement with experimental water ( ) if left uncorrected.

Panel (b) shows that adding the Yeh–Hummer hydrodynamic correction   removes the (SPC/E) and (TIP3P) drag at  , collapsing all box sizes onto  . Panel (c) compares the viscosities extracted from the diffusion slope against the Green–Kubo values of González & Abascal (2010), Yeh & Hummer (2004) for TIP3P, and experimental water.

Table 1: WLS 1/L Extrapolation at T = 298 K vs. Primary Literature ​

Water Model GPU () Literature () (z-score) GPU ( ) Literature ( ) (z-score) (nm)
SPC/E  at 298 K (Tazi et al. 2012:   at 300 K)  ()  (González & Abascal 2010, GK)  ()0.9826
TIP3P  (Yeh & Hummer 2004)  ()   (YH 2004); (G&A 2010, GK)  ( vs. YH);   ( vs. G&A)0.9866

Experimental water at 298 K:    (Holz et al. 2000),   . Note that the SPC/E viscosity from a 4-point slope carries a statistical uncertainty (±0.075 mPa·s), so the close central value (0.738 vs. 0.729 mPa·s) reflects statistical consistency (0.12σ) rather than 1% precision.

Table 2: Per-Box Production Summary, Finite-Size Collapse, Stability & GPU Throughput ​

Run (model / ens) (nm) ()Prod. (ns) (K) ()Drag () (nm)GPU Speed
spce / nve2561.97310.50681.26     14,126 steps/s
spce / nve5122.48590.40231.02     13,912 steps/s
spce / nve10243.13210.31930.80     9,606 steps/s
spce / nve40964.97190.20110.55     9,016 steps/s
tip3p / nve2561.98040.50501.26     14,560 steps/s
tip3p / nve5122.49510.40081.02     13,912 steps/s
tip3p / nve10243.14370.31810.80     9,850 steps/s
tip3p / nve40964.99030.20040.55     9,057 steps/s
spce / csvr_weak5122.48590.40230.45  ——NVT ( ) 13,073 steps/s

All 9 runs executed with compact_fft=true, rw_fast_path=true, 0 NaNs, per-box Einstein MSD linearity   across , and SETTLE bond errors    (software check ). Notice that is tightest at   where the shared mesh (h = 0.155–0.156 nm) remains 12% finer than the automatic -ESP spacing (h_auto = 0.1762 nm).


Part B: Diffusive MSD Convergence, GSDWriter(write_unwrapped=true) Software Check & Weak-CSVR Comparison ​

Mean-squared displacement convergence and online vs offline GSD unwrapped trajectory parity

Panel (a) displays the block-averaged multi-origin oxygen MSD curves (with uncertainty ribbons) for the smallest ( ) and largest ( ) boxes of both models, showing entry into the linear diffusive regime inside the shaded fit window and resolving the hydrodynamic slope widening from   to  .

Panel (b) audits UnwrapFeature on the 20-ps (41-frame) SPC/E   verification trajectory, separating software/API checks from physical diagnostics:

CategoryMetricProduction ResultReference / Interpretation
Software checkOnline MSDObservable vs. Offline read_gsd_frame! (O) Frame-by-frame numerical parity (< 1e-6 nm², Float32 rounding)
Software checkUnwrapped O–H intramolecular integrity Zero periodic box tears (< 1e-3 nm; box length  )
DiagnosticSystem COM drift over 20-ps GSD check Finite-precision Float32 PME/SETTLE force residual; removed via frame-wise COM subtraction
DiagnosticOffline Oxygen MSD vs. Molecular COM MSD Constant rotational lever-arm offset ( of MSD)
DiagnosticWrapped vs. Unwrapped MSD at   vs. Wrapped coordinates overstate MSD by   via box-edge jumps
Physics checkWeak CSVR ( ) vs. Pure NVE ( )     ()Consistent (+3.10% ± 2.69%), with csvr_weak   warmer

Files ​

  • tutorials/T05_yeh_hummer_diffusion/run.jl: GPU multi-box rigid-water driver (SPC/E + TIP3P microcanonical NVE sweep with per-model <T_full> calibration and per-block COM-drift logging, weak CSVR parity run, and simultaneous online MSDObservable + GSDWriter(write_unwrapped=true) audit).

  • tutorials/T05_yeh_hummer_diffusion/analyze.jl: Offline read_gsd_frame! software audit, block-averaged Einstein diffusion analysis, inverse-variance WLS Yeh–Hummer regression for , and separated software checks, diagnostics, and physical consistency tests.

  • tutorials/T05_yeh_hummer_diffusion/plot.py: 300-DPI Matplotlib figure generator.

References ​

  1. I.-C. Yeh and G. Hummer, "System-size dependence of diffusion coefficients and viscosities from molecular dynamics simulations with periodic boundary conditions," J. Phys. Chem. B 108(40), 15873–15879 (2004). DOI: 10.1021/jp0477147

  2. M. A. González and J. L. F. Abascal, "The shear viscosity of rigid water models," J. Chem. Phys. 132(9), 096101 (2010). DOI: 10.1063/1.3330544

  3. S. Tazi, A. Boţan, M. Salanne, V. Marry, P. Turq, and B. Rotenberg, "Diffusion coefficient and shear viscosity of rigid water models," J. Phys.: Condens. Matter 24(28), 284117 (2012). DOI: 10.1088/0953-8984/24/28/284117

  4. B. Dünweg and K. Kremer, "Molecular dynamics simulation of a polymer chain in solution," J. Chem. Phys. 99(9), 6983–6997 (1993). DOI: 10.1063/1.465445

  5. H. J. C. Berendsen, J. R. Grigera, and T. P. Straatsma, "The missing term in effective pair potentials," J. Phys. Chem. 91(24), 6269–6271 (1987). DOI: 10.1021/j100308a038

  6. W. L. Jorgensen, J. Chandrasekhar, J. D. Madura, R. W. Impey, and M. L. Klein, "Comparison of simple potential functions for simulating liquid water," J. Chem. Phys. 79(2), 926–935 (1983). DOI: 10.1063/1.445869

  7. G. Bussi, D. Donadio, and M. Parrinello, "Canonical sampling through velocity rescaling," J. Chem. Phys. 126(1), 014101 (2007). DOI: 10.1063/1.2408420

  8. M. Holz, S. R. Heil, and A. Sacco, "Temperature-dependent self-diffusion coefficients of water and six selected molecular liquids for calibration in accurate NMR PFG measurements," Phys. Chem. Chem. Phys. 2(20), 4740–4742 (2000). DOI: 10.1039/b005319h

  9. S. Miyamoto and P. A. Kollman, "SETTLE: An analytical version of the SHAKE and RATTLE algorithm for rigid water models," J. Comput. Chem. 13(8), 952–962 (1992). DOI: 10.1002/jcc.540130805

ParticleDynamics v1.2.0 · GPU-native molecular dynamics in pure Julia · MIT License