Skip to content

Workflow overview ​

The workflow layer describes a simulation with composable, immutable descriptors: a ParticleSystem, named Groups, forces, an Integrator (with dynamical methods, optional holonomic constraints or freeze restraints, and an optional barostat), observables, and scheduled writers. run! owns the GPU time loop and writer sessions.

Anatomy of a workflow script ​

julia
using ParticleDynamics

# 1. Build or load the initial configuration
cfg = fcc_random_3d(512, 1.0, 0.35; T=Float32)
system = ParticleSystem(cfg; types=[:A], typeids=fill(Int32(1), 512), masses=Dict(:A => 1.0f0))

# 2. Define particle groups
all = Group(:all, AllSelection())
groups = Groups(all)

# 3. Describe forces, dynamics, constraints and optional barostat
integrator = Integrator(
    dt=2.0f-3,
    scheme=BAOABFast(),
    forces=[
        LennardJones(epsilon=1.0f0, sigma=1.0f0, cutoff=2.5f0,
                     pairs=:neighborlist,
                     neighborlist=ClusterPairList(buffer=0.2, force_accumulation=:fixed64)),
    ],
    methods=[Langevin(all; gamma=1.0f0, kT=1.0f0)],
    barostat=StochasticCellRescaling(pressure=1.0, kT=1.0, compressibility=0.1, tau=0.5, interval=10),
)

# 4. Choose observables and scheduled writers
thermo = ThermodynamicObservable(all; name=:thermo)
press = PressureObservable(name=:press)
writers = [
    TableWriter("npt.csv"; every=50,
                observables=[thermo => [:temperature, :potential_energy],
                             press  => [:pressure, :volume, :density]],
                mode=:replace),
    GSDWriter("npt.gsd"; every=500, group=all, write_start=true, mode=:replace),
]

# 5. Assemble and run named stages
sim = Simulation(system; groups=groups, integrator=integrator,
                 observables=[thermo, press], writers=writers, precision=Float32)
run!(sim, Stage(:equilibrate, steps=2_000))
reset_observables!(sim)
reset_step!(sim, 0)
run!(sim, Stage(:production, steps=10_000))

Stages, preparation and state inspection ​

  • prepare!(sim) validates descriptors, allocates the GPU-resident SimulationState, builds neighbor lists, attaches electrostatics, dispersion, constraints, and barostats, and compiles the low-level integrator spec. run! calls prepare! automatically on the first stage; call it explicitly if you modify sim.integrator between stages or want to inspect the state before stepping.

  • state(sim) returns the underlying GPU-resident SimulationState for expert diagnostics or low-level hooks.

  • Stage(name; steps, dt=..., neighbor_rebuild_interval=..., progress=...) runs a named interval with optional timestep or neighbor-rebuild overrides. Across plain un-sampled intervals, run! automatically launches K-step batched CUDA graphs via step_many! with bit-exact parity relative to single-step execution.

  • reset_observables!(sim) clears accumulated interval quantities and resets MSD/VACF references to the current configuration without closing active writer sessions. reset_step!(sim, 0) resets the step counter.

Where to find full API signatures ​

Every exported workflow and low-level symbol is documented in the API Reference:

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