Skip to content

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 ​

julia
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 every n steps.

  • AtSteps([0, 100, 1_000]): sample at exact step indices.

  • Between(first, last; every=500): sample within a step window.

julia
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:

julia
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 reusing

Supported 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 TableWriter and GSDWriter with mode=:replace replace the target file once when the simulation writer session first opens it. Subsequent stages in the same Simulation append to that session, even though file handles close cleanly at stage boundaries. Calling prepare! again with the same writer preserves the session.

  • A new Simulation starts a new session; pass mode=:append to 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:

Full writer and low-level I/O signatures are listed in the I/O & Initial Configurations API reference.

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