Trajectories and tables
Attach Writer objects to a Simulation to save tabular measurements, GSD trajectories, or host-memory analysis buffers on independent schedules.
Save a table and a trajectory
all = Group(:all, AllSelection())
thermo = ThermodynamicObservable(all; name=:thermo)
press = PressureObservable(name=:press)
writers = [
TableWriter("thermo.csv";
every=100,
observables=[
thermo => [:temperature, :total_energy],
press => [:pressure, :volume, :density],
],
mode=:replace),
GSDWriter("trajectory.gsd";
every=1_000, group=all, write_start=true, mode=:replace),
]
sim = Simulation(system; groups=Groups(all), integrator=integrator,
observables=[thermo, press], writers=writers)
run!(sim, 10_000)TableWriter writes CSV/delimited tables for time-series plotting. GSDWriter writes compact binary HOOMD/GSD frames storing positions, velocities, charges, topology, optional forces/virials, and logged electrostatics, dispersion, and barostat metadata for visualization and continuing a simulation.
Choose when to write
Pass every=n for a regular interval, or supply an explicit schedule:
Every(n): sample everynsteps.AtSteps([0, 100, 1_000]): sample at exact step indices.Between(first, last; every=500): sample within a step window.
TableWriter("selected.csv";
schedule=AtSteps([0, 100, 1_000]),
observables=[thermo => [:temperature]],
)
GSDWriter("production.gsd"; schedule=Between(1_000, 10_000; every=500))In-memory workflow output
InMemoryWriter keeps sampled particle frames and/or workflow observables in host memory for interactive analysis, tests, or post-processing in the same Julia session with zero disk I/O:
press = PressureObservable(name=:press)
mem = InMemoryWriter(
every=100,
fields=[:positions, :forces, :energy, :virial],
observables=[press => [:pressure, :volume, :pressure_tensor, :surface_tension]],
)
sim = Simulation(system; integrator=integrator, observables=[press], writers=[mem])
run!(sim, 10_000)
data = recorded_data(mem)
data.step # step index of each recorded frame
data.positions[:, :, end] # N × D in particle-id order (independent of spatial sorting)
data.potential_energy # Float vector, one value per frame
data.press.pressure # sampled PressureObservable fields keyed by observable name
data.press.surface_tension # 3D slab surface tension per frame
empty!(mem) # drop recorded frames before reusingSupported fields are :positions, :unwrapped_positions, :velocities (inertial dynamics only), :forces, :energy, and :virial. When observables is non-empty and fields is omitted, only the requested observables are recorded. Each recorded frame copies only the requested data from the GPU.
File sessions
Workflow
TableWriterandGSDWriterwithmode=:replacereplace the target file once when the simulation writer session first opens it. Subsequent stages in the sameSimulationappend to that session, even though file handles close cleanly at stage boundaries. Callingprepare!again with the same writer preserves the session.A new
Simulationstarts a new session; passmode=:appendto retain an existing file across separate simulations.GSD writing stays outside the GPU stepping hot path and is the preferred format for trajectories and restarts.
Low-level output helpers
For scripts stepping a low-level SimulationState directly, ParticleDynamics exports standalone file helpers:
write_observables_csv!(path, step; Epot=..., Ekin=..., ...)— append scalar/reduced observable rows to a CSV file.write_xyz!(path, st, step)— append an XYZ snapshot (stages coordinates to host).gsd_open,write_gsd_frame!,gsd_close,read_gsd_frame!, andread_gsd_log— direct GSD file writing and log inspection.
Full writer and low-level I/O signatures are listed in the I/O & Initial Configurations API reference.