Potentials, MLIPs & Bonded Terms
API reference for native-Julia GPU external potentials and MLIPs, custom short-range GPU pair potentials, typed bonded force descriptors, low-level parameter containers, and physical helpers. See Interactions and Bonds, minimization and pressure for usage guides.
External potentials and GPU MLIP protocol
ParticleDynamics.SimulationCore.AbstractExternalPotential Type
AbstractExternalPotentialSupertype for external potential and native-Julia GPU force providers.
Minimal host-synced provider (100% backward-compatible):
- Implement
external_forces!(pot, st, compute_energy).
Extended trait hooks for native-Julia GPU MLIPs and additive external fields:
external_force_mode(pot) -> :replace | :additive(default:replace)provides_virial(pot) -> Bool(defaultfalse)is_device_capturable(pot) -> Bool(defaultfalse)enqueue_external_forces!(pot, run, energy::Bool, virial::Bool)needs_neighbor_list(pot) -> Bool(defaultfalse)external_energy(pot, st) -> Float64external_fingerprint(pot)
Activate with attach_external_potential! and remove with detach_external_potential!.
ParticleDynamics.SimulationCore.external_forces! Function
external_forces!(pot, st::SimulationState, compute_energy::Bool)
external_forces!(pot, st::SimulationState, compute_energy::Bool, compute_virial::Bool)Host-dispatched external force evaluation hook.
In
:replacemode, overwritest.fx,st.fy(andst.fzin 3D), and whencompute_energyis true overwritest.Epot.In
:additivemode, accumulate (+=) ontost.fx,st.fy(st.fz), and whencompute_energyis true accumulate ontost.Epot.When
compute_virialis true (provides_virial(pot) == true), write (:replace) or accumulate (:additive) virials intost.virial_nonbondedorst.virial_global.
The 4-argument default method delegates to the 3-argument method and zeroes st.virial_nonbonded only when external_force_mode(pot) === :replace && !provides_virial(pot).
ParticleDynamics.SimulationCore.attach_external_potential! Function
attach_external_potential!(st, pot::AbstractExternalPotential) -> stAttach pot to st.
When
external_force_mode(pot) === :replace, internal nonbonded/bonded/mesh terms are disallowed andspatial_reorder=falseis required;RigidWaterandConstraintClustersare permitted whenis_device_capturable(pot) == true.When
external_force_mode(pot) === :additive,potcomposes freely with nonbonded pairs (including:cluster), bonds, typed bonded families, electrostatics, dispersion, rigid water, and constraint clusters.
Use detach_external_potential! to remove the provider.
ParticleDynamics.SimulationCore.detach_external_potential! Function
detach_external_potential!(st) -> stRemove the external provider and restore the internal force path.
ParticleDynamics.SimulationCore.external_force_mode Function
external_force_mode(pot::AbstractExternalPotential) -> SymbolForce composition mode of pot:
:replace(default): replaces internal nonbonded and bonded force terms.:additive: accumulates forces, energies, and virials on top of internal nonbonded, bonded, electrostatics, dispersion, and constraint forces.
ParticleDynamics.SimulationCore.provides_virial Function
provides_virial(pot::AbstractExternalPotential) -> BoolReturn true if pot writes (in :replace mode) or accumulates (in :additive mode) configurational virials into run.virial / st.virial_nonbonded (per-particle N × ncomp) or run.virial_global / st.virial_global (ncomp global tensor) when virial=true. Enables DeviceCRescale NPT, mechanical_pressure, and virial_tensor. Default: false.
ParticleDynamics.SimulationCore.is_device_capturable Function
is_device_capturable(pot::AbstractExternalPotential) -> BoolReturn true if pot implements enqueue_external_forces!(pot, run, energy, virial) using only CUDA-graph-capturable device launches (zero host syncs or allocations). When true, DeviceEngine captures pot directly inside its step CUDA graphs with full step_many! batching, thermostats, constraints, and barostats. Default: false.
ParticleDynamics.SimulationCore.enqueue_external_forces! Function
enqueue_external_forces!(pot::AbstractExternalPotential, run, energy::Bool, virial::Bool)CUDA-graph-capturable device force hook called by DeviceEngine when is_device_capturable(pot) == true.
run exposes device buffers run.r, run.f, run.energy, run.virial (st.virial_nonbonded), run.virial_global (st.virial_global), and run.neighbors (run.neighbors.geom, run.neighbors.list, run.neighbors.state). Must launch only GPU kernels with zero host synchronizations.
ParticleDynamics.SimulationCore.needs_neighbor_list Function
needs_neighbor_list(pot::AbstractExternalPotential) -> BoolReturn true if pot reads DeviceEngine's GPU neighbor list (run.neighbors, ELL neighbors_flat/counts and dynamic NPT box run.neighbors.geom). Keeps the neighbor list maintained across drifts, barostat box moves, and minimization. Default: false.
ParticleDynamics.SimulationCore.external_energy Function
external_energy(pot::AbstractExternalPotential, st) -> Float64Optional fast energy-only evaluation hook, enabling MonteCarloBarostatSpec and MonteCarloVolumeMove NPT without requiring force evaluation on rejected trials. The default delegates to external_forces!(pot, st, true, false) or total_potential_energy(st).
ParticleDynamics.SimulationCore.external_fingerprint Function
external_fingerprint(pot::AbstractExternalPotential)Value hashed into DeviceEngine's StateEngine fingerprint to detect parameter or provider changes. Default: (typeof(pot), objectid(pot)).
Custom short-range GPU pair potentials
ParticleDynamics.SimulationCore.AbstractPairPotential Type
AbstractPairPotentialSupertype for user-defined short-range GPU pair potentials executed inside DeviceEngine's 2D & 3D cooperative warp traversal (:ell backend).
Required traits:
pair_cutoff(pot) -> Real: maximum interaction radiusr_c > 0.@inlinepair_eval(pot, data, ctx, j, r2::T) -> (inside::Bool, f_over_r::T, u::T): device-inlined pair evaluation returning(inside, (-dU/dr)/r, U(r)).
Optional traits:
pair_data(pot, st) -> Tuple: extra device arrays/scalars passed to kernels.sorted_particle_arrays(pot, st) -> Tuple: per-particleCuArrays owned bypotthatDeviceEnginemust permute during spatial reordering.@inlinepair_context(pot, data, i): per-atom value hoisted out of the neighbor loop.@inlinepair_self_energy(pot, data, i, ::Type{T}) -> T: per-atom self energy.pair_fingerprint(pot): host value hashed intoStateEnginefingerprint.
Attach via build_simulation(...; pair_potential=pot) or attach_pair_potential!.
ParticleDynamics.SimulationCore.pair_cutoff Function
Maximum cutoff radius r_c > 0 of a custom AbstractPairPotential.
ParticleDynamics.SimulationCore.pair_data Function
Tuple of extra device arrays/scalars forwarded to pair_context and pair_eval.
ParticleDynamics.SimulationCore.sorted_particle_arrays Function
Tuple of per-particle CuArrays owned by pot to permute under spatial reordering.
ParticleDynamics.SimulationCore.pair_context Function
Per-atom context hoisted outside the neighbor loop on GPU (default: nothing).
ParticleDynamics.SimulationCore.pair_eval Function
Device-inlined pair evaluation returning (inside::Bool, (-dU/dr)/r, U(r)).
ParticleDynamics.SimulationCore.pair_self_energy Function
Optional per-particle self-energy added once per atom on energy evaluations (default: zero(T)).
ParticleDynamics.SimulationCore.pair_fingerprint Function
Host fingerprint value hashed into StateEngine to detect custom pair potential changes.
ParticleDynamics.SimulationCore.attach_pair_potential! Function
attach_pair_potential!(st, pot::AbstractPairPotential) -> stReplace the short-range nonbonded pair interaction of st with pot on the :ell backend. Per-particle arrays returned by sorted_particle_arrays are registered with DeviceEngine's OrderingWorkspace so spatial reordering stays consistent. Use detach_pair_potential! to restore the previous nonbonded pair setting.
ParticleDynamics.SimulationCore.detach_pair_potential! Function
detach_pair_potential!(st) -> stDetach the custom AbstractPairPotential and restore the prior nonbonded setting.
ParticleDynamics.SimulationCore.MorsePotential Type
MorsePotential(; D0, alpha, r0, rcut, shift=true, T=Float64)Short-range Morse pair potential: U(r) = D0 * (exp(-2α(r - r0)) - 2 exp(-α(r - r0))) - U_shift, with optional potential shift to zero at r = rcut.
ParticleDynamics.SimulationCore.YukawaPotential Type
YukawaPotential(; A=1.0, kappa, rcut, charges=nothing, shift=true, T=...)Screened Coulomb (Yukawa / DLVO) short-range pair potential: U(r) = A * q_i * q_j * (exp(-κr)/r - u_shift) (q_i = 1 when charges === nothing). When charges is supplied, the per-particle effective charge vector is stored on GPU and automatically registered via sorted_particle_arrays so spatial_reorder=true permutes it in lockstep with particle coordinates.
Workflow bonded force descriptors
ParticleDynamics.Workflow.HarmonicBondForce Type
HarmonicBondForce(; k, r0, type=:default)Workflow harmonic bond force descriptor.
ParticleDynamics.Workflow.FENEBondForce Type
FENEBondForce(; k, R0, type=:default)Workflow FENE bond force descriptor.
ParticleDynamics.Workflow.HarmonicAngleForce Type
HarmonicAngleForce(; k, theta0, type=:default)U = k(θ-θ0)²/2 on topology.angles (vertex = middle atom). θ0 = π (linear equilibrium) is handled exactly at collinear geometry; any other θ0 reports collinear geometry as a domain error.
ParticleDynamics.Workflow.CosineSquaredAngleForce Type
CosineSquaredAngleForce(; k, theta0, type=:default)U = k(cosθ - cosθ0)²/2 on topology.angles.
ParticleDynamics.Workflow.UreyBradleyAngleForce Type
UreyBradleyAngleForce(; k_theta, theta0, k_r, r13, type=:default)U = kθ(θ-θ0)²/2 + k_r(r13 - r13⁰)²/2 on topology.angles; the 1–3 distance term is part of this force and is not also counted as a bond.
ParticleDynamics.Workflow.PeriodicDihedralForce Type
PeriodicDihedralForce(; k, n, phase, type=:default)U = Σ_m k_m[1 + cos(n_m φ - δ_m)] on topology.dihedrals, with the IUPAC signed dihedral φ of the ordered quartet. k, n, phase are scalars or equal-length vectors (one Fourier term each); n_m are positive integers.
ParticleDynamics.Workflow.OPLSDihedralForce Type
OPLSDihedralForce(; K1, K2, K3, K4=0, type=:default)U = ½[K1(1+cosφ) + K2(1-cos2φ) + K3(1+cos3φ) + K4(1-cos4φ)] (LAMMPS opls convention), compiled into the Fourier evaluator.
ParticleDynamics.Workflow.RyckaertBellemansDihedralForce Type
RyckaertBellemansDihedralForce(; C, type=:default)U = Σ_{n=0}^{5} C_n cos(ψ)^n with ψ = φ - π (polymer convention: trans is ψ = 0). C holds six coefficients C0..C5.
ParticleDynamics.Workflow.HarmonicImproperForce Type
HarmonicImproperForce(; k, chi0, type=:default)U = k d²/2, d = wrap(χ - χ0) into (-π, π], where χ is the signed dihedral of the ordered improper quartet (torsion-style improper). Import adapters must map their central-atom convention onto this order.
ParticleDynamics.Workflow.PeriodicImproperForce Type
PeriodicImproperForce(; k, n, phase, type=:default)Fourier form of PeriodicDihedralForce applied to topology.impropers.
Parameter structs and physical helpers
ParticleDynamics.Definitions.LJParams Type
LJParams{T}(ϵ, σ, rcut)Lennard-Jones parameters used by the nonbonded force kernels.
Arguments
ϵ: Depth of the LJ well (energy scale).σ: Particle diameter (sets the zero of the LJ potential).rcut: Pairwise cutoff distance. For the WCA branch this is set to2^(1/6)σ.
Examples
params = LJParams(Float32(10), Float32(1), Float32(2^(1/6)))
st = build_simulation(N=256, box=(80f0, 80f0), cutoff=params.rcut,
skin=0.4f0, cap=Int32(64),
neigh_interval=10, use_neighborlist=false,
epsilon=params.ϵ, sigma=params.σ,
gamma=50f0, temperature=1f0,
nonbonded=:wca, precision=:f32)ParticleDynamics.Definitions.SoftRepulsiveParams Type
SoftRepulsiveParams{T}(ϵ, σ)Parameters for the truncated harmonic repulsion (e.g. σ = 1.0, ϵ = 1e9). The cutoff equals σ.
ParticleDynamics.Definitions.HarmonicBondParams Type
HarmonicBondParams{T}(k, r0)Parameters for harmonic bonds U(r) = ½ k (r - r₀)². For bead–spring chains, k = 300 and r0 = 1.0 keep bead spacings near a single diameter (examples/2D_polymer_bonded.jl).
ParticleDynamics.Definitions.FENEParams Type
FENEParams{T}(k, R0)Finite-extensible nonlinear elastic parameters, with potential U(r) = -½kR₀² log(1 - (r/R₀)²). examples/2D_polymer_bonded.jl uses k = 300, R0 = 1.5. Force evaluation requires finite k ≥ 0, a finite positive representable R0², and finite bond lengths r < R0. Overstretched bonds throw DomainError; force and energy are never clamped.
ParticleDynamics.Definitions.BondPotential Type
BondPotentialAbstract supertype for bonded potentials so SimulationState can store either HarmonicBond or FENEBond and dispatch bond kernels accordingly.
ParticleDynamics.Definitions.HarmonicBond Type
HarmonicBond(params)Concrete wrapper storing HarmonicBondParams. Construct via harmonic_bond so the element type matches the simulation precision.
ParticleDynamics.Definitions.FENEBond Type
FENEBond(params)Concrete wrapper storing FENEParams. Use fene_bond to create instances whose parameter type (Float32/Float64) matches the simulation.
ParticleDynamics.Definitions.harmonic_bond Function
harmonic_bond(; k=100.0, r0=1.0)Convenience constructor that promotes the supplied spring constant and equilibrium distance to the simulation precision. The polymer demos use harmonic_bond(k=300, r0=1.0) for bead–spring chains.
ParticleDynamics.Definitions.fene_bond Function
fene_bond(; k=300.0, r0=1.5)Convenience constructor for FENEBond. The 2D/3D FENE polymer examples draw directly from this helper with the default parameters.
ParticleDynamics.Definitions.StokesFrictionCoefficient Function
StokesFrictionCoefficient(η, R)Return the Stokes drag γ = 6π η R for a spherical particle of radius R embedded in fluid with viscosity η. Handy when translating experimental values into the gamma input of Langevin or Brownian.
ParticleDynamics.Definitions.SphereMass Function
SphereMass(ρ, R)Mass of a solid sphere with density ρ and radius R: m = (4/3)π R³ ρ.
ParticleDynamics.Definitions.InertialTime Function
InertialTime(m, γ)Return the inertial relaxation time τᵢ = m / γ. Useful for picking dt relative to the physical time scales probed in the examples.
ParticleDynamics.Definitions.DiffusiveTime Function
DiffusiveTime(R, γ, d; kT=1.0)Estimate the time required for a particle to diffuse its own diameter under isothermal conditions. Uses the relation τ_D = 4 R² γ / (2 d kT) with kT = 1.0 by default in reduced units.
Low-level bonded forces
ParticleDynamics.BondedForces Module
Bonded interactions: the uniform harmonic and FENE bond kernels, and typed bonded families (bonds, angles, dihedrals, impropers) with their interaction tables.
ParticleDynamics.BondedForces.BondList Type
BondListGPU adjacency list describing bead connectivity in build-time particle-id order. Construct it with build_bondlist. Each bond is stored at both endpoints; index gives each particle's zero-based starting offset in flat, and counts its degree.
ParticleDynamics.BondedForces.build_bondlist Function
build_bondlist(N, bonds) -> BondListConstruct a GPU-ready bond list from a collection of (i, j) tuples (1-based). examples/2D_polymer_bonded.jl builds its chains via:
chain = collect(zip(1:(n-1), 2:n))
bond_list = build_bondlist(n, chain)ParticleDynamics.SimulationCore.attach_bonded_terms! Function
attach_bonded_terms!(st, terms) -> stAttach typed bonded families (BondedForces.BondedTerms). They are evaluated in addition to the uniform bonds given at build time (bonding=, bonds=). Interaction tables hold particle ids; states with spatial reordering map them to storage slots through st.tag.
ParticleDynamics.SimulationCore.detach_bonded_terms! Function
detach_bonded_terms!(st) -> stRemove the typed bonded families attached with attach_bonded_terms!. Uniform bonds given at build time (bonding=, bonds=) stay. Forces are invalidated.
ParticleDynamics.SimulationCore.bonded_energy_components Function
bonded_energy_components(st) -> Vector{Pair{Symbol,Float64}}Energy of each typed bonded family at the current coordinates (e.g. :angles_HarmonicAngleKind => 3.2). Uniform bonds (bonding=) are part of Epot only and are not listed.
ParticleDynamics.BondedForces.BondedFamily Type
BondedFamilyOne concrete potential kind with its interaction table, coefficient arrays (a tuple of device vectors indexed by parameter id) and preallocated scratch.
ParticleDynamics.BondedForces.BondedTerms Type
BondedTermsAll typed bonded families of a simulation plus a reusable device status vector (first invalid interaction per family).
ParticleDynamics.BondedForces.InteractionTable Type
InteractionTable{K}Unique K-body interactions on the device: atom columns atoms[a][t], parameter ids ptype[t], and a CSR particle incidence (offsets, entries) whose entries e = (t-1)*K + a address the interaction-local force slots. Atom order is preserved exactly as given (it defines angle/torsion signs).
ParticleDynamics.BondedForces.bonded_status Function
bonded_status(terms) -> Union{Nothing,Tuple{Symbol,Int}}First invalid interaction of the last evaluation as (family, topology index).
ParticleDynamics.BondedForces.build_interaction_table Function
build_interaction_table(N, tuples, ptype) -> InteractionTable{K}Validate and upload tuples::Vector{NTuple{K,<:Integer}} (1-based) with their 1-based parameter ids. Rejects out-of-range or repeated atoms within a tuple and index overflow.
ParticleDynamics.BondedForces.evaluate_bonded! Function
evaluate_bonded!(terms, rx, ry, rz, box, fx, fy, fz, E, V, compute_ev; check=true)Add all typed bonded families onto the force buffers (and, with compute_ev, onto the per-particle energy and virial buffers). In 2D pass rz/fz as any same-typed placeholder. With check=true an invalid geometry raises DomainError naming the family and topology index.
ParticleDynamics.BondedForces.fene_forces_soa! Function
fene_forces_soa!(rx, ry[, rz], fx, fy[, fz], E, bonds, box, params)Finite extensible nonlinear elastic bonds, e.g. the fene_bond(k=300, r0=1.5) configuration.
ParticleDynamics.BondedForces.fene_forces_soa_noE! Function
fene_forces_soa_noE!(rx, ry[, rz], fx, fy[, fz], bonds, box, params)FENE bonds without per-particle energy accumulation.
ParticleDynamics.BondedForces.harmonic_forces_soa! Function
harmonic_forces_soa!(rx, ry[, rz], fx, fy[, fz], E, bonds, box, params)Evaluate harmonic bond forces and per-particle energies for a bond list from build_bondlist.
ParticleDynamics.BondedForces.harmonic_forces_soa_noE! Function
harmonic_forces_soa_noE!(rx, ry[, rz], fx, fy[, fz], bonds, box, params)Force-only harmonic bonds. Handy for warmup segments when energies are not recorded.