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
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. 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 independentSPC/E study by Tazi et al. (2012) ( atand ), and (statistical uncertainty), consistent with the Green–Kubo value of González & Abascal (2010) ( ,).
UnwrapFeature& Offline GSD Software Parity Check: Verifies frame-by-frame agreement (1.35e-9 nm²) between online GPUMSDObservableand offline trajectory analysis viaGSDWriter(...; 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 nmover20 ps).Hydrodynamic Momentum Conservation (
NVEvs. WeakCSVR): Compares momentum-conserving weakCSVR( ) against microcanonicalNVEat SPC/E ( ,), while noting the higher mean full-step temperature in the short weak-CSVR run.
Trajectory Visualization

Path-traced Fresnel studio snapshot (tutorials/render_snapshots.py --targets T05) displaying the four scaled cubic periodic boxes (
What You Will Learn
Running multi-box-size rigid-water GPU sweeps with
step_many!,ClusterPairList(force_accumulation=:fixed64), andPairTablezero-LJ hydrogen segregation.Sharing a single power-of-2
ESP(continuity=:c2, mesh=(32, 32, 32))CompactFFTplan 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, inFloat32, zero NaNs).Equilibrating rigid water with
CSVRand transitioning to microcanonicalConstantVolume(VelocityVerlet())NVEfor momentum-conserving transport properties.Recording continuous unwrapped coordinates with
GSDWriter(...; write_unwrapped=true)and cross-checking offlineread_gsd_frame!MSDs (oxygen sites and molecularcenters of mass) against online MSDObservable.
Running the Tutorial
All scripts live in tutorials/T05_yeh_hummer_diffusion/:
# 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.pyPhysics Background
Hydrodynamic Finite-Size Scaling in Periodic Cubic Boxes
In a momentum-conserving molecular dynamics simulation inside a cubic periodic box of side length
where
Thermodynamic-limit self-diffusion
from the intercept.Bulk shear viscosity
from the negative slope :
and combining
Why Momentum Conservation Matters: NVE and Weak CSVR vs. Langevin
The
Microcanonical
NVEconserves 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 physicalYeh–Hummer scaling. Equilibrating with a thermostat and switching to microcanonical NVE(or weakCSVRwith ) 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,
| Model | Fixed NVT | ||||||
|---|---|---|---|---|---|---|---|
| SPC/E (Berendsen et al. 1987) | |||||||
| TIP3P (Jorgensen et al. 1983) |
Two methodological choices in the recorded production dataset warrant explicit disclosure:
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 reducesand 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 nmNPT density).Half-step
CSVRvs. full-step Velocity-Verlet temperature and box-to-boxscatter: CSVRinParticleDynamicsrescales the leapfrog half-step velocity to . Because rigid-water librational modes ( ) have a finiteshadow-temperature offset at , the full-step Velocity-Verlet kinetic temperaturesits 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 realizedacross the eight NVE runs spanned 0.98 K(295.18–296.16 K), including a+0.93 Kupward ramp across the TIP3P box sizes (295.18 ± 0.41 Kat to296.11 ± 0.23 Kat ), and thecsvr_weak run averaged+2.21 Khotter (297.47 ± 1.24 K) than itsnvecounterpart (295.26 ± 0.35 K). Because water self-diffusion varies bynear , 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_weaksittingabove nve).tutorials/T05_yeh_hummer_diffusion/run.jlmeasuresdirectly per model during CSVRequilibration (initializing from the lowest-variance box) rather than hardcoding296.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 (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 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 32³ mesh therefore gives 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
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 (CSVR (RATTLE velocity projection, and switches to microcanonical ConstantVolume(all_grp) (VelocityVerlet()) on the same GPU state:
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):
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
4. Multi-Origin Sliding-Window Production and COM-Drift Subtraction
During multi-block production (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 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
Results & Literature Validation
Part A: 1/L Hydrodynamic Scaling, Finite-Size Collapse & Extracted Viscosity

Panel (a) shows linear
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) ( atand ), and (relative statistical uncertainty), consistent with the Green–Kubo viscosity of González & Abascal (2010) ( ,). Note that an uncorrected 512-molecule box yields , afinite-size artifact that can masquerade as closer agreement with experimental water ( ) if left uncorrected.
Panel (b) shows that adding the Yeh–Hummer hydrodynamic correction
Table 1: WLS 1/L Extrapolation at T = 298 K vs. Primary Literature
| Water Model | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| SPC/E | 0.9826 | ||||||||
| TIP3P | 0.9866 |
Experimental water at 298 K: ±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) | Prod. (ns) | Drag | GPU Speed | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
spce / nve | 256 | 1.9731 | 0.5068 | 1.26 | 14,126 steps/s | ||||||
spce / nve | 512 | 2.4859 | 0.4023 | 1.02 | 13,912 steps/s | ||||||
spce / nve | 1024 | 3.1321 | 0.3193 | 0.80 | 9,606 steps/s | ||||||
spce / nve | 4096 | 4.9719 | 0.2011 | 0.55 | 9,016 steps/s | ||||||
tip3p / nve | 256 | 1.9804 | 0.5050 | 1.26 | 14,560 steps/s | ||||||
tip3p / nve | 512 | 2.4951 | 0.4008 | 1.02 | 13,912 steps/s | ||||||
tip3p / nve | 1024 | 3.1437 | 0.3181 | 0.80 | 9,850 steps/s | ||||||
tip3p / nve | 4096 | 4.9903 | 0.2004 | 0.55 | 9,057 steps/s | ||||||
spce / csvr_weak | 512 | 2.4859 | 0.4023 | 0.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 SETTLE bond errors h = 0.155–0.156 nm) remains 12% finer than the automatic h_auto = 0.1762 nm).
Part B: Diffusive MSD Convergence, GSDWriter(write_unwrapped=true) Software Check & Weak-CSVR Comparison

Panel (a) displays the block-averaged multi-origin oxygen MSD curves (with
Panel (b) audits UnwrapFeature on the 20-ps (41-frame) SPC/E
| Category | Metric | Production Result | Reference / Interpretation |
|---|---|---|---|
| Software check | Online MSDObservable vs. Offline read_gsd_frame! (O) | Frame-by-frame numerical parity (< 1e-6 nm², Float32 rounding) | |
| Software check | Unwrapped O–H intramolecular integrity | Zero periodic box tears (< 1e-3 nm; box length | |
| Diagnostic | System COM drift over 20-ps GSD check | Finite-precision Float32 PME/SETTLE force residual; removed via frame-wise COM subtraction | |
| Diagnostic | Offline Oxygen MSD vs. Molecular | Constant rotational lever-arm offset ( | |
| Diagnostic | Wrapped vs. Unwrapped MSD at | Wrapped coordinates overstate MSD by | |
| Physics check | Weak CSVR (NVE ( | Consistent (+3.10% ± 2.69%), with csvr_weak |
Files
tutorials/T05_yeh_hummer_diffusion/run.jl: GPU multi-box rigid-water driver (SPC/E+TIP3PmicrocanonicalNVEsweep with per-model<T_full>calibration and per-block COM-drift logging, weakCSVRparity run, and simultaneous onlineMSDObservable+GSDWriter(write_unwrapped=true)audit).tutorials/T05_yeh_hummer_diffusion/analyze.jl: Offlineread_gsd_frame!software audit, block-averaged Einstein diffusion analysis, inverse-variance WLS Yeh–Hummerregression for , and separated software checks, diagnostics, and physical consistency tests. tutorials/T05_yeh_hummer_diffusion/plot.py: 300-DPI Matplotlib figure generator.
References
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
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
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
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
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
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
G. Bussi, D. Donadio, and M. Parrinello, "Canonical sampling through velocity rescaling," J. Chem. Phys. 126(1), 014101 (2007). DOI: 10.1063/1.2408420
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 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