Skip to content

Interactions ​

Describe interactions with Force objects (or a ForceField) and pass them to Integrator(...; forces=...). All parameters use the same consistent unit system as your particle configuration.

Pair and long-range interactions ​

ForceModelExample
LennardJonesAttraction and short-range repulsionLennardJones(epsilon=1.0, sigma=1.0, cutoff=2.5)
WCAPurely repulsive Lennard-Jones interactionWCA(epsilon=1.0, sigma=1.0)
SoftRepulsiveSoft repulsive particlesSoftRepulsive(epsilon=1.0, sigma=1.0, cutoff=1.0)
PME, PPPM, ESPLong-range 3D periodic Coulomb interactionsSee Electrostatics
DispersionESP, DispersionPMELong-range 1/r⁶ lattice dispersion (LJPME)See Electrostatics
ExternalPotentialForceNative-Julia GPU MLIPs & external fieldsSee External potentials and GPU MLIPs
MorsePotential, YukawaPotential, custom AbstractPairPotentialCustom short-range GPU pair potentialsSee Custom short-range pair potentials
julia
force = LennardJones(
    epsilon=1.0, sigma=1.0, cutoff=2.5,
    pairs=:neighborlist,
    neighborlist=CellList(buffer=0.5, capacity=256, rebuild_interval=10),
)

For small examples, pairs=:all avoids neighbor-list setup at quadratic cost; use neighbor lists (pairs=:neighborlist) for production systems.

Choose a neighbor list ​

ParticleDynamics supports two GPU nonbonded neighbor backends:

  • CellList (:ell backend): slot-major ELL neighbor rows, one thread/warp traversal per particle. Supports 2D and 3D Lennard-Jones, WCA, soft repulsion, and custom AbstractPairPotential models. Set spatial_reorder=true (or :auto) with reorder_interval to enable Hilbert/cell spatial sorting on runs that do not require fixed particle storage order.

  • ClusterPairList (:cluster backend): 3D Newton-3 8×8 particle cluster tiles in a single fused kernel evaluating Lennard-Jones (uniform or PairTable) together with real-space Coulomb and lattice dispersion (with exclusions and 1–4 scaling bit masks). Charged systems select :cluster automatically; uncharged 3D LJ/WCA systems can opt in explicitly:

julia
# Automatic displacement-triggered pruning & rebuilding
cpl = ClusterPairList(buffer=0.2, prune_buffer=0.1, force_accumulation=:fixed64)

# Fixed-interval GROMACS-style dual pair list: rebuild every 40 steps, prune every 10
cpl_fixed = ClusterPairList(buffer=0.3, prune_buffer=0.1, list_intervals=(40, 10))

Key ClusterPairList options:

  • buffer: outer list skin beyond the largest active interaction cutoff.

  • prune_buffer: inner pruned-list buffer (defaults to buffer / 2).

  • list_intervals=(nstlist, nstprune): opt-in fixed-interval rebuild/prune schedule (nstlist >= 1, 0 <= nstprune <= nstlist; nstprune = 0 prunes only on rebuilds). Ensure buffer and prune_buffer are sized conservatively for particle motion over those intervals.

  • force_accumulation: :float32 (default) or :fixed64 (accumulates pair forces per slot in 64-bit signed fixed point at 2⁻³⁰ resolution before converting back to Float32, eliminating atomic summation order noise and making forces bitwise reproducible across launches).

For CellList, choose capacity for the densest configuration the run will visit (especially under pressure control): overflow stops the simulation with ParticleDynamics.NeighborLists.NeighborCapacityError instead of silently truncating neighbors.

Lennard-Jones energy at the cutoff ​

Choose the cutoff treatment explicitly via vdw_modifier (or low-level set_vdw_modifier!):

  • vdw_modifier=:none (default): truncates the potential and force at the cutoff.

  • vdw_modifier=:potential_shift: subtracts u(r_c) from each interacting pair's energy (forces inside the cutoff are unchanged; matches GROMACS default).

  • vdw_modifier=:force_switch: applies the Steinbach–Brooks / GROMACS C² force switch between switch_distance (default 0.85 * cutoff) and cutoff.

  • vdw_modifier=:potential_switch: multiplies the pair potential by a quintic Hermite C² taper on [switch_distance, cutoff].

julia
LennardJones(epsilon=1.0, sigma=1.0, cutoff=2.5,
             vdw_modifier=:force_switch, switch_distance=2.1)

All four modifiers work on both :ell and :cluster backends. To include the full periodic −c6/r⁶ tail without truncating at a short cutoff, pair LennardJones with DispersionESP or DispersionPME (both are subtypes of DispersionForce; see Lattice dispersion).

Per-pair 1–4 LJ and Coulomb scaling ​

Biomolecular force fields (AMBER, CHARMM, OPLS) exclude 1–2 and 1–3 nonbonded pairs and scale 1–4 Lennard-Jones and Coulomb interactions independently. On the :cluster backend, supply 4-tuples (i, j, coul_scale, lj_scale) to attach_electrostatics! (or call set_lj_exceptions! / pass scaled_pairs on LennardJones for uncharged systems):

julia
# Exclude 1-2/1-3 pairs and apply AMBER 1-4 scaling (1/1.2 Coulomb, 0.5 LJ)
exceptions = [
    (Int32(1), Int32(2), 0.0, 0.0),
    (Int32(1), Int32(4), 1.0 / 1.2, 0.5),
]
attach_electrostatics!(st, espec; exceptions=exceptions)

All four vdw_modifier modes, DispersionESP out-of-list cancellation, and GSD round-trip serialization preserve exact per-pair lj_scale factors. Set exclude_bonded_pairs=false on LennardJones, WCA, or SoftRepulsive for polymer models such as Kremer–Grest (FENE + WCA) where nonbonded repulsion also acts between bonded beads.

External potentials and GPU MLIPs ​

AbstractExternalPotential provides a direct protocol for both machine-learned interatomic potentials (MLIPs) and custom external fields (confining walls, optical traps, biasing potentials, electric fields). Attach one inside any workflow integrator with ExternalPotentialForce, or on a low-level state via attach_external_potential!:

julia
integrator = Integrator(
    dt=1.0e-3,
    scheme=BAOAB(),
    forces=[ExternalPotentialForce(my_mlip)],
    methods=[Langevin(all; gamma=1.0, kT=1.0)],
)

Protocol traits and CUDA-graph capture ​

HookDefaultRole
external_force_mode(pot):replace:replace replaces internal forces (MLIPs); :additive adds on top of internal pair, bonded, mesh, and constraint forces
is_device_capturable(pot)falseReturn true when enqueue_external_forces! launches only CUDA-graph-capturable GPU kernels with zero host syncs
enqueue_external_forces!(pot, run, energy, virial)throws MethodErrorDevice-side kernel entry point captured directly into DeviceEngine CUDA graphs (step_many!, barostats, constraints, minimization)
external_forces!(pot, st, compute_energy[, compute_virial])required for host-synced providersHost-dispatched force evaluation (used when is_device_capturable(pot) == false, e.g. Python/PyTorch bridges like examples/mace/ and examples/orb/)
provides_virial(pot)falseReturn true when pot writes/accumulates virials into run.virial (st.virial_nonbonded) or run.virial_global (st.virial_global), enabling StochasticCellRescaling NPT, PressureObservable, and virial_tensor
needs_neighbor_list(pot)falseReturn true to keep DeviceEngine's GPU neighbor list (run.neighbors) maintained for pot across drifts, barostat box moves, and minimization
external_energy(pot, st)delegates to forcesOptional energy-only hook for fast MonteCarloBarostat rejection without force evaluation
external_fingerprint(pot)(typeof(pot), objectid(pot))Value hashed into StateEngine to detect parameter changes

Minimal native-Julia GPU additive external field ​

julia
using CUDA, ParticleDynamics

struct HarmonicTrap3D{T} <: AbstractExternalPotential
    k::T
end

ParticleDynamics.external_force_mode(::HarmonicTrap3D) = :additive
ParticleDynamics.is_device_capturable(::HarmonicTrap3D) = true
ParticleDynamics.provides_virial(::HarmonicTrap3D) = false

function _trap_kernel!(fx, fy, fz, Epot, rx, ry, rz, k, do_e::Bool)
    i = (blockIdx().x - 1) * blockDim().x + threadIdx().x
    if i <= length(rx)
        @inbounds begin
            x, y, z = rx[i], ry[i], rz[i]
            fx[i] -= k * x; fy[i] -= k * y; fz[i] -= k * z
            if do_e
                Epot[i] += typeof(x)(0.5) * k * (x*x + y*y + z*z)
            end
        end
    end
    return nothing
end

function ParticleDynamics.enqueue_external_forces!(pot::HarmonicTrap3D, run, energy::Bool, virial::Bool)
    rx, ry, rz = run.r
    fx, fy, fz = run.f
    n = length(rx)
    CUDA.@cuda threads=256 blocks=cld(n, 256) _trap_kernel!(
        fx, fy, fz, run.energy, rx, ry, rz, eltype(rx)(pot.k), energy)
    return nothing
end

Because external_force_mode is :additive and is_device_capturable is true, HarmonicTrap3D composes directly with LennardJones, ClusterPairList, ESP, bonded terms, RigidWaterConstraint, and FIRE/SteepestDescent minimization inside captured CUDA graphs with zero host synchronizations.

Custom short-range pair potentials ​

For user-defined short-range radial interactions (such as Buckingham, Mie, tabulated splines, or custom coarse-grained models), subtype AbstractPairPotential to run directly inside DeviceEngine's 2D & 3D cooperative warp traversal (:ell backend) with automatic virials, NPT barostats, bonded exclusions, spatial reordering, minimization, and CUDA graphs.

ParticleDynamics ships two built-in reference implementations ready to attach via build_simulation(...; pair_potential=pot) or attach_pair_potential!:

  • MorsePotential(; D0, alpha, r0, rcut, shift=true): U(r) = D0 * (exp(-2α(r - r0)) - 2 exp(-α(r - r0))) - U_shift.

  • YukawaPotential(; A=1.0, kappa, rcut, charges=nothing, shift=true): screened Coulomb / DLVO potential U(r) = A q_i q_j (exp(-κr)/r - u_shift). Per-particle charges are registered automatically via sorted_particle_arrays so spatial_reorder=true permutes them in lockstep with particle coordinates.

To write your own pair potential, implement pair_cutoff(pot) and @inlinepair_eval(pot, data, ctx, j, r2::T) -> (inside::Bool, f_over_r::T, u::T), plus optional pair_data, sorted_particle_arrays, pair_context, pair_self_energy, and pair_fingerprint.

Bonded models and mixtures ​

Use Topology to supply connectivity and combine pair forces with HarmonicBondForce, FENEBondForce, angle, dihedral, or improper descriptors (see Bonds, minimization and pressure). For type-dependent nonbonded parameters, supply a PairTable with per-type vectors (Lorentz–Berthelot mixing) or explicit ntypes × ntypes matrices.

FENE domain ​

FENE requires finite k ≥ 0, positive finite R0 with a representable positive finite square, and finite minimum-image bond lengths strictly below R0. Evaluation throws DomainError identifying an incident particle if a bond reaches or exceeds R0. The potential and force are not clamped or continued beyond the physical domain; choose the timestep and initial configuration accordingly.

Physical helpers ​

Helper constructors convert between common colloidal/Stokes parameters and characteristic timescales (StokesFrictionCoefficient, SphereMass, InertialTime, DiffusiveTime). Keep their inputs consistent with your chosen unit system.

Full API signatures live in the Potentials, MLIPs & Bonded Terms and Electrostatics, Dispersion & Pair Lists reference pages.

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