Electrostatics
ParticleDynamics computes long-range Coulomb and 1/r⁶ lattice dispersion interactions natively on the GPU with particle-mesh solvers that share one mesh engine:
| Descriptor | Method | Split | Assignment | Differentiation | Transforms per force call |
|---|---|---|---|---|---|
PME | smooth particle-mesh Ewald | Gaussian | cardinal B-spline | analytic | 1 forward, 1 inverse |
PPPM(differentiation=:ad) | P3M, optimal influence function | Gaussian | B-spline | analytic | 1 forward, 1 inverse |
PPPM(differentiation=:ik) | P3M, optimal influence function | Gaussian | B-spline | reciprocal-space field | 1 forward, 3 inverse |
ESP | Ewald summation with prolates (continuity=:c0 or :c2) | prolate (PSWF / generalized) | prolate window (P = 4..16) | analytic | 1 forward, 1 inverse |
DispersionESP | C² lattice 1/r⁶ dispersion (LJPME) | C² generalized prolate | C² prolate window | analytic | 1 forward, 1 inverse (fused when co-gridded with ESP) |
DispersionPME | Gaussian (Essmann/Wennberg) 1/r⁶ dispersion | Gaussian 1/r⁶ | B-spline | analytic | 1 forward, 1 inverse |
Every stage of a force evaluation runs on the device: real-space cluster pairs, exception corrections, charge/√c6 spreading, 3D FFTs (CompactFFT or cuFFT), spectral solve (with Float64 energy and virial reductions), and force gather. A warmed force call performs zero device allocations.
Supported scope: 3D orthorhombic periodic boxes, conducting (tin-foil) boundary conditions, uniform relative permittivity, fixed charges, a single GPU, Float32 or Float64. 2D, slab, triclinic and open-boundary electrostatics are rejected at construction.
Choose a solver
PME and PPPM use B-spline assignment; ESP uses a prolate window and can use a substantially smaller FFT grid for a given measured accuracy. The best choice depends on system size, charge distribution, and accuracy target. Use tune_electrostatics(st, force; target, objective=:time) to measure candidate settings through your state's full force path (including vdW and the cluster-pair backend) before committing to production parameters.
Quick example
using ParticleDynamics
n, a = 16, 2.82 # Å
L = n * a
pos = [(a * (i - 0.5) - L / 2, a * (j - 0.5) - L / 2, a * (k - 0.5) - L / 2)
for i in 1:n for j in 1:n for k in 1:n]
typeids = Int32[isodd(i + j + k) ? 1 : 2 for i in 1:n for j in 1:n for k in 1:n]
system = ParticleSystem(pos; box=(L, L, L), types=[:Na, :Cl], typeids=typeids,
masses=Dict(:Na => 22.99, :Cl => 35.45),
charges=Dict(:Na => 1.0, :Cl => -1.0))
all_ions = Group(:all, AllSelection())
sim = Simulation(system;
groups=Groups(all_ions),
integrator=Integrator(
dt=0.1, # in √(amu Ų/eV) ≈ 10.18 fs units
forces=[
LennardJones(epsilon=0.01, sigma=2.8, cutoff=9.0, pairs=:neighborlist,
neighborlist=ClusterPairList(buffer=0.5)),
ESP(coulomb_prefactor=14.399645, # eV·Å/e²
real_cutoff=9.0, tolerance=1e-4, continuity=:c2),
],
methods=[ConstantVolume(all_ions)],
),
observables=[ThermodynamicObservable(all_ions)],
precision=Float32,
)
run!(sim, Stage(:nve, steps=1_000; progress=false))Replace the ESP(...) entry by PME(coulomb_prefactor=14.399645, real_cutoff=9.0, real_space_tolerance=1e-5, mesh_spacing=1.0, order=5) or PPPM(...; differentiation=:ik) to switch methods. The short-range vdW force keeps its own cutoff; the shared cluster neighbor list covers the larger of the vdW, Coulomb, and dispersion real-space cutoffs.
Units and conventions
The engine has no built-in unit system. The pair energy is
and C enters every term (real space, reciprocal space, self energy, exceptions, background, virial) exactly once.
| Quantity | Unit |
|---|---|
positions, box, cutoffs, mesh_spacing | L |
alpha (Gaussian split) | 1/L |
| charges | caller's Q |
coulomb_prefactor | E·L/Q² |
| energy, virial | E |
| forces | E/L |
Common choices: ≈138.935458 for nm, kJ/mol and elementary charges; ≈14.399645 for Å, eV and elementary charges; 1 for reduced units. Thermostat inputs stay kT in energy units. ESP shape parameters (split_shape, window_shape) are dimensionless and distinct from alpha.
Ewald split
For a split kernel χ (dimensionless, ∫χ = 1) with a(t) = ∫₀ᵗ χ, t = r/r_c:
The Gaussian choice gives erfc(αr)/r, ĝ = 4π e^{-k²/4α²}/k² and the self energy −Cα/√π Σqᵢ². The ESP choice uses prolate spheroidal wave functions on [0, 1], so the real-space part vanishes identically at r_c. Its self energy is −(C/2) χ(0)/r_c Σqᵢ².
Mesh
Charges are assigned per node with the window W (B-spline of order P, or prolate window), transformed with an unnormalised forward FFT, multiplied by the influence function G (containing C/V), and transformed back with an unnormalised inverse. The mesh energy is ½ Σ G|b̂|²; analytic-differentiation forces are the exact gradient of this discrete energy. Influence functions:
SPME:
G = (C/V) ĝ(k) Π_d D_d, with SPME's exact discrete B-spline factorD;P3M-AD/ik: Hockney–Eastwood optimal alias sums for the selected derivative;
ESP: optimal AD influence function with alias sums of the prolate window transform (
influence=:optimal, default) or plain deconvolution (influence=:deconvolution).
C²-continuous ESP and CompactFFT
Passing continuity=:c2 to ESP replaces the order-zero prolate split and window with Slepian generalized prolates ((1 − x²)² φ(x) for the radial split and (1 − y²)³ φ(y) for the assignment window), so the real-space split and its first two derivatives vanish identically at real_cutoff and the mesh force and force derivative remain continuous across every grid plane. For tolerance > 2.5e-4, ESP(continuity=:c2) and DispersionESP use an exact P = 4 degree-7 C²(ℝ) partition-of-unity window (W ≥ 0, Σ W ≡ 1) with specialized shared-memory spreading and gathering kernels (tighter tolerances retain P = 5..16).
Compact shared-memory 3D FFT & P = 4 / P = 5 SMEM spreading
On 2–3–5–7 smooth meshes with 4 ≤ K₁, K₂, K₃ ≤ 128 (preferring even smooth dimensions when snapping), the mesh engine automatically replaces cuFFT with a 3-kernel (or 5-kernel pencil on large grids) shared-memory 3D FFT and fused spectral solve (CompactFFT) using orthorhombic octant influence tables (G_oct/Vc_oct) and coalesced posq + slot s6 loads for both single-field and fused dual-mesh (q, √c6) solvers, matching cuFFT to floating-point round-off while eliminating external FFT launch overhead. Both P = 4 and P = 5 use scaled-Int32 shared-memory spreading, and out-of-place NPT-MC uses a dedicated energy-only spectral reduction. Larger or non-smooth grids continue to use cuFFT transparently.
Lattice dispersion
DispersionESP (C² prolate LJPME) and DispersionPME (Gaussian Essmann/Wennberg LJPME) are DispersionForce descriptors that complement LennardJones by splitting the attractive −c6/r⁶ interaction into a smooth short-range pair kernel and a reciprocal mesh (including the mandatory k = 0 term in both energy and diagonal virial, real-space exclusion cancellation, and device-resident barostat support).
Geometric c6 tables are split exactly; non-geometric Lorentz–Berthelot pair tables use the composition-weighted Rank-1 SVD (Perron–Frobenius leading eigenvector of W^{1/2} C6 W^{1/2}, s6_a >= 0) to put −s6ᵢ s6ⱼ Φ₆(r) on the mesh (minimizing long-range residual at zero extra mesh cost) and carry the residual −(c6ᵢⱼ − s6ᵢ s6ⱼ)/r⁶ in real space with a C² quintic switch on [lb_switch_fraction * real_cutoff, real_cutoff].
When ESP(continuity=:c2) and DispersionESP share a mesh and window (automatic in the workflow when neither pins conflicting settings), the GPU cluster backend executes a single fused dual-mesh (q, √c6) pass: one spread, one batched 2-field 3D FFT (CompactFFT for ≤ 128³ smooth grids, or cuFFT), one spectral solve, and one gather. GSD snapshots record dispersion settings in log/dispersion/settings and restore them via dispersion_from_gsd.
Energies, virials and charges
Thermodynamic observables include electrostatic and dispersion energies automatically. Pair energies are shared equally between the two particles; the mesh assigns energy through each particle's interpolated potential.
The reciprocal-space virial belongs to the whole system and has no per-particle decomposition. Request virial and pressure measurements on the full system when electrostatics or lattice dispersion is attached.
On a low-level
SimulationState, callset_charges!(st, q)to replace particle charges (re-checking the net-charge policy),charges(st)to inspect them,electrostatic_energy(st)for(real, self, reciprocal, background, virial)breakdowns, anddispersion_energy(st)for lattice dispersion energy breakdowns.
Exceptions and charged systems
Scaled or excluded pairs (e.g. 1–2/1–3 exclusions, 1–4 scaling) are handled by subtracting (1 − s) C qᵢqⱼ/r at the pair's minimum-image distance, independently of the cutoff. Periodic images keep the full interaction. Workflow descriptors collect exceptions from exclusions=:topology (Topology.exclusions, scale 0), exclude_bonded=true, and scaled_pairs=[(i, j, s), …]. On the :cluster backend, 4-tuples (i, j, coul_scale, lj_scale) scale Coulomb and Lennard-Jones independently (including exact DispersionESP out-of-list cancellation).
net_charge=:error (default) rejects a nonzero total charge. With net_charge=:background, a uniform neutralising background adds −C π Q²/(2α²V) (Gaussian) or −C π r_c² m₂ Q²/V (prolate). It contributes equally to each diagonal virial component and adds no force; under device-resident StochasticCellRescaling NPT, both U_bg(V) and its diagonal virial refresh dynamically on the GPU at every volume update with zero graph recaptures.
Save and continue
GSD output records charges, electrostatics settings, exceptions, and dispersion settings. ParticleSystem.from_gsd(path) restores positions, velocities, charges, and topology; electrostatics_from_gsd(path) and dispersion_from_gsd(path) return the saved force descriptors for your new integrator. See Continue a simulation.
Choosing parameters and tuning
Parameters are explicit; nothing is tuned silently behind the user's back.
PME/PPPM. Choose
real_cutoff, thenalphaorreal_space_tolerance(erfc(α r_c) = tol). Refinemesh/mesh_spacingandorderuntil the measured force error meets your target.ESP.
tolerance = εsets the split shape, window shape, window widthP(P = 4forcontinuity=:c2whenε > 2.5e-4;P = 5..16for tighter targets), andmesh_spacing = π r_c / c. Refining an ESP mesh alone saturates nearε; to tighten accuracy, decreasetolerance.Precision bound. Because the influence function divides by the squared window transform, the window must stay resolved by the state's precision
T:(φ̂(π)/φ̂(0))² ≥ 0.02 eps(T)^(2/3)(4.8e-7inFloat32,7.3e-13inFloat64).Float32forces reach roughly2e-6relative accuracy at best; tighter targets requireprecision=Float64.Analytical and measured accuracy tuners.
verlet_buffer_skincomputes a Páll–Hess (2013) analytical Verlet buffer skin for a given timestep, temperature, mass, rebuild interval, and pair energy-drift tolerance across any unit system.tune_pme_parametersanalytically selects cutoff, Ewald splitting parameter, and smooth mesh dimensions targeting a requested force error.tune_electrostatics(st, force; target)finds the coarsest mesh (PME/PPPM) or tolerance (ESP) whose measured relative RMS force error meetstarget, returning an explicit descriptor (fixedmesh, no hidden retuning on restart). Passobjective=:timeto search order,α/tail orε/width, and mesh for the fastest full force evaluation meetingtarget.tune_dispersion(st, force; target)selects the coarsestDispersionESPtolerance meeting a measured relative RMS dispersion force error target.
Reciprocal-space multiple time stepping (BAOAB-RESPA)
For systems where reciprocal-space FFTs account for a substantial fraction of step time (such as large LJPME dual meshes), opt-in symplectic BAOAB-RESPA / r-RESPA evaluates the smooth reciprocal mesh every mts_mesh_interval = M inner steps with exact outer impulse scaling (f_scale) inside DeviceEngine CUDA graphs:
report = check_respa_stability(; dt=0.004, mts_mesh_interval=2, time_unit=:ps, damped=true)
cfg = respa_engine_config(; dt=0.004, mts_mesh_interval=2, time_unit=:ps, damped=true)
DeviceEngine.with_engine_config(; mts_mesh_interval=cfg.mts_mesh_interval) do
run!(sim, Stage(:production, steps=50_000))
endcheck_respa_stability returns a RespaStabilityReport guarding against outer-step resonance; respa_engine_config validates stability before constructing an EngineConfig. Keep mts_mesh_interval = 1 (the default) whenever zero-MTS single-step reciprocal evaluation is desired.
Measured accuracy against an independent converged Ewald sum (Float64, 120 random charges, r_c = 4):
| Method | Settings | Relative force RMS |
|---|---|---|
| PME | α = 0.9, P = 6, h ≈ 0.30 | 1.3e-5 |
| PME | α = 0.9, P = 8, h ≈ 0.22 | < 1e-6 |
| PPPM-AD | α = 0.9, P = 6, h ≈ 0.30 | 1.3e-5 |
| PPPM-ik | α = 0.9, P = 6, h ≈ 0.30 | 5.9e-7 |
| ESP | ε = 1e-6, P = 8, h ≈ 0.45 | 3.4e-6 |
Cross-engine agreement on a 1,000-ion snapshot (r_c = 1 nm, same Coulomb constant): against GROMACS 2025 double-precision PME (order 10, 72³ grid), PME energy agrees to 6e-13 relative, PPPM-AD/ik to 8e-11, and ESP to 4e-10.
Provenance
The ESP implementation follows Liang, Lu, Barnett, Greengard and Jiang, Accelerating molecular dynamics simulations using fast Ewald summation with prolates, Nat. Commun. 17, 6681 (2026). Prolate functions are computed directly from the Legendre expansion of the prolate differential operator; no source code or coefficient tables from external implementations were used. Additional references: Essmann et al., J. Chem. Phys. 103, 8577 (1995) (SPME); Hockney and Eastwood (1988) and Deserno and Holm, J. Chem. Phys. 109, 7678 (1998) (P3M); Ballenegger, Cerdà and Holm, J. Chem. Theory Comput. 8, 936 (2012) (AD/ik influence functions).
Full workflow and low-level solver signatures live in the Electrostatics, Dispersion & Pair Lists reference.