Lab 6.9 · 35 min

Lab: finite-size effects by hand

A simulation box holds a few hundred to a few hundred thousand molecules, not 10²³, and it repeats itself periodically. Some results do not care; others depend on the box size in a predictable way and must be corrected. We compute the 1/N offset in g(r) by hand, what it does to Kirkwood–Buff integrals, the Yeh–Hummer correction for diffusion, and then measure D in four box sizes to check the 1/L law, and find where it breaks down.

The setup

Two kinds of finite-size effects appear:

counting effects a fixed number N of particles: averages differ from the infinite system by terms of order 1/N (g(r) tail, integrals) periodic effects every particle interacts with its images: long-range flows and fields feel the box size L (diffusion ~1/L, charged boxes ~1/L)

Systems: an ideal gas (exact answers), the 2D LJ liquid of earlier labs in boxes of 9, 25 and 100 atoms, and a 3D LJ liquid (ρ = 0.8, T = 1.0) with 32 to 500 atoms. For real liquids we use water (η = 0.85 mPa s) and an ionic liquid (η = 50 mPa s).

Step 1

The g(r) tail is 1 − 1/N, not 1

Why: g(r) compares the number of pairs at distance r with an ideal gas of the same density. With a fixed number of particles, each one sees only N − 1 others, while the usual normalization uses the density N/V. That leaves a small offset at large r, even for an ideal gas, where the exact g is 1.

pairs counted: N(N − 1)/2 normalization uses: N²/2 g(tail) = (N − 1)/N = 1 − 1/N N = 10: 0.900 N = 100: 0.990 random positions (ideal gas), g in 5 shells: N = 10: 0.900 0.899 0.900 0.900 0.900 N = 100: 0.992 0.990 0.990 0.990 0.989
2D LJ liquid, ρ = 0.69Lfirst peak gg at first minimum
N = 93.62.620.985
N = 256.02.920.788
N = 10012.02.950.784

What the numbers say: The ideal gas confirms the formula exactly: the tail sits at 1 − 1/N everywhere. In a dense liquid the offset is smaller, about S(0)/N, where S(0) = ρk_BTκ_T is small for a stiff liquid. The first peak and minimum are what usually matter, and they hardly change from 25 to 100 atoms (2.92 vs 2.95). The 9-atom box is too small: its half-width 1.8 cuts right through the first minimum, so its structure is distorted (peak 2.62, minimum 0.985). Rule of thumb: the box must be several times larger than the structure you want to see.

Step 2

Integrals of g(r): Kirkwood–Buff and the Ganguly–van der Vegt correction

Why: Kirkwood–Buff integrals G = ∫(g − 1) dV over all space connect g(r) to compressibilities and partial molar volumes, and running coordination numbers are integrals too. A tiny offset in g(r), multiplied by a large volume, becomes a large error.

ideal gas, N = 100, L = 10 (2D); true G = 0 g − 1 = −1/N = −0.01 everywhere G(R) = −0.01 × πR²: R = 1: −0.0314 R = 2: −0.1257 R = 4: −0.5027 Ganguly–van der Vegt correction at R = 4: V_R/V = πR²/L² = 0.5027 excess neighbours ΔN = ρ G = −0.5027 factor = N(1 − V_R/V) / (N(1 − V_R/V) − ΔN − 1) = 49.735 / (49.735 + 0.503 − 1) = 1.01010 corrected g = 0.99 × 1.01010 = 1.0000 3D: 500 molecules, L = 2.5 nm, integrate to R = 1.2 nm: sphere 7.238 nm³ × 1/500 = 0.0145 nm³ = 8.7 cm³/mol

What the numbers say: The running integral drifts away linearly with the area (or volume) instead of levelling off, and the drift is pure artefact. The Ganguly–van der Vegt factor accounts for the particles that are "missing" because they are already counted within R; for the ideal gas it restores g = 1 exactly. In 3D with 500 molecules, the error in a Kirkwood–Buff integral is about 9 cm³/mol, comparable to the integrals themselves (often tens of cm³/mol). Limitations: the correction assumes the box is large compared with the range of correlations, and integrals still need R well beyond the last peak. Coordination numbers of the first shell are not affected noticeably.

Step 3

Diffusion: the Yeh–Hummer correction by hand

Why: A moving particle drags the surrounding liquid along. In a periodic box, the flow it creates also pushes on its own images, and the periodic flow field slows it down. Hydrodynamics gives the size of the effect: D in the box is lower than the true D by ξk_BT/(6πηL), where η is the viscosity and ξ = 2.837297 for a cubic box.

D_∞ = D_PBC + ξ k_B T / (6π η L) water, 300 K, η = 0.85 mPa s, L = 3 nm: 2.837297 × 4.1419×10⁻²¹ / (6π × 0.00085 × 3×10⁻⁹) = 2.445×10⁻¹⁰ m²/s vs D = 2.3×10⁻⁹: +11 % ionic liquid, 300 K, η = 50 mPa s, L = 5 nm: 2.837297 × 4.1419×10⁻²¹ / (6π × 0.05 × 5×10⁻⁹) = 2.494×10⁻¹² m²/s vs D = 1.0×10⁻¹¹: +25 % same liquid, L = 10 nm: +12 %, L = 20 nm: +6 %

What the numbers say: The correction does not depend on the particle: every species gets the same absolute shift. It falls only as 1/L, so doubling the box (8 times the atoms) only halves it: for the ionic liquid a 20 nm box, about a million atoms, still underestimates D by 6 %. It matters most where it is least expected: the absolute correction is smaller in a viscous liquid, but D is smaller too, so the relative error is larger (25 % vs 11 %). Limitation: it needs the viscosity, ideally computed with the same force field (next lab), and it assumes a cubic box and a simple liquid.

Step 4

Measuring the 1/L law: four box sizes

Why: Is the correction real, and is it the right size? Run the same 3D LJ liquid in boxes of 32, 108, 256 and 500 atoms, measure D in each with the MSD (several independent runs, more for the noisy small boxes), and plot D against 1/L.

NL1/LD (MSD)runs
323.4200.29240.0440 ± 0.001412
1085.1300.19490.0567 ± 0.00106
2566.8400.14620.0596 ± 0.00144
5008.5500.11700.0615 ± 0.00063
straight line through all four boxes: D = 0.0743 − 0.1007 / L -> η = 2.837/(6π × 0.1007) = 1.50 straight line without the 32-atom box: D = 0.0687 − 0.0620 / L -> η = 2.837/(6π × 0.0620) = 2.43 direct Green–Kubo viscosity (next lab): 2.42 ± 0.12 Yeh–Hummer with η = 2.42: ξT/(6πη) = 0.0622 N = 32: 0.0440 + 0.0622/3.420 = 0.0622 (still low) N = 108: 0.0567 + 0.0622/5.130 = 0.0688 N = 256: 0.0596 + 0.0622/6.840 = 0.0687 N = 500: 0.0615 + 0.0622/8.550 = 0.0688

What the numbers say: D grows steadily with box size; even the 500-atom box is 11 % below the infinite-box value 0.0688. The three larger boxes fall on a straight line in 1/L whose slope gives η = 2.43, the same as the viscosity computed directly in the next lab (2.42), and the Yeh–Hummer correction brings all three to 0.0687–0.0688. The 32-atom box (L = 3.4, only about three molecular diameters) does not follow the law: including it in the fit gives a wrong viscosity (1.50) and a wrong extrapolation (0.0743). The hydrodynamic picture needs a box several molecules wide. Practical rule: correct one reasonably sized box with a viscosity computed independently, or extrapolate from several boxes that are all large enough, never from a tiny one.

Step 5

Consequences for conductivity and the Haven ratio

Why: Transport numbers built from self-diffusion inherit the Yeh–Hummer error. The Nernst–Einstein conductivity σ_NE uses D₊ and D₋ directly, and the Haven ratio σ_NE/σ compares it with the collective conductivity.

ionic liquid of Lab 6.7: n = 2.5 /nm³, D₊ = 2.0×10⁻¹¹, D₋ = 1.5×10⁻¹¹ m²/s, 5 nm box, η = 50 mPa s correction per ion 2.49×10⁻¹² m²/s D₊ -> 2.25×10⁻¹¹, D₋ -> 1.75×10⁻¹¹ σ_NE: 0.542 -> 0.620 S/m (+14 %) if σ (collective) = 0.362 S/m needs no correction: Haven ratio 1.50 (box) -> 1.71 (corrected)

What the numbers say: A 14 % change in σ_NE moves the Haven ratio from 1.50 to 1.71, larger than many differences reported between force fields. The collective conductivity is expected to need a much smaller correction, because the hydrodynamic flow carries cations and anions together and largely cancels in the charge current; but this depends on the system (masses, sizes, how the box momentum is handled), so check it by running two box sizes. Either way: state the box size with any D, σ_NE or Haven ratio, and say whether D was corrected.

Step 6

Choosing the box: a checklist with numbers

Why: Box size is a trade-off between cost (N grows as L³) and the size-dependent errors above. Putting the main ones side by side helps choose L before a project starts.

L (nm)largest cutoff L/2smallest k = 2π/LIL: correction to D_PBCone-ion charged-box energy
31.5 nm2.09 /nm+42 %−66 kJ/mol
52.5 nm1.26 /nm+25 %−39 kJ/mol
105.0 nm0.63 /nm+12 %−20 kJ/mol

What the numbers say: Some limits are hard: the cutoff (and any structure you want in g(r)) must stay below L/2, and no wave longer than L exists, so S(k) below 2π/L and slow collective modes are missing. Others are corrections you can calculate: D (Yeh–Hummer), charged boxes (Lab 5.5), long integrals of g(r) (Ganguly–van der Vegt). And some need checking: conductivity, viscosity and anything involving clusters or interfaces. A practical habit: run the key observable in two box sizes; if it changes by more than its error bar, either correct it or go bigger.

Summary

quantitysize dependence (number)what to do
g(r) first peak2.92 (25 atoms) vs 2.95 (100)nothing, if L/2 > the structure
g(r) tail1 − 1/N (0.990 for 100)Ganguly–van der Vegt for integrals
Kirkwood–Buff integrals~9 cm³/mol error for 500 moleculescorrect, and integrate far enough
self-diffusion D−11 % even with 500 atoms; ∝ 1/LYeh–Hummer with an independent η; boxes not too small
σ_NE, Haven ratio+14 % σ_NE, Haven 1.50 -> 1.71correct D; check σ with two boxes
charged box−39 kJ/mol per ion at 5 nmanalytic correction (Lab 5.5)