Skip to content

Observables ​

Choose the physical quantities you want to measure with Observable descriptors, then attach them to a TableWriter, GSDWriter, or InMemoryWriter on any sampling schedule.

Temperature, energy, pressure and box geometry ​

julia
all = Group(:all, AllSelection())
thermo = ThermodynamicObservable(all; name=:thermo)
press  = PressureObservable(name=:press)
boxobs = BoxObservable(name=:box)

writer = TableWriter("npt_obs.csv";
    every=100,
    observables=[
        thermo => [:temperature, :kinetic_energy, :potential_energy, :total_energy],
        press  => [:pressure, :surface_tension],
        boxobs => [:volume, :density, :Lx, :Ly, :Lz],
    ],
    mode=:replace,
)

Pass observables=[thermo, press, boxobs] and writers=[writer] to Simulation. Because BoxObservable reads only the periodic cell geometry, sampling it alone incurs zero energy or virial evaluation overhead.

Available observables ​

ObservableSupported fieldsUse it for
ThermodynamicObservable(group):temperature, :kinetic_energy, :potential_energy, :total_energy, :virial, *_accumulatedEquilibration, group temperatures, and energy conservation
PressureObservable():pressure, :volume, :density, :box, :Lx, :Ly, :Lz, :pressure_tensor, :virial_tensor, :surface_tensionNPT mechanical pressure, full symmetric P_{αβ}/W_{αβ} tensors, and 3D slab surface tension γ = ½ Lz (Pzz − ½(Pxx + Pyy))
BoxObservable():volume, :density, :box, :Lx, :Ly, :LzLightweight cell-geometry tracking without energy/virial evaluation
VirialObservable(group):virial, :virial_accumulatedScalar virial diagnostics
MSDObservable(group):msd, :elapsed_timeMean-squared displacement and diffusion
VACFObservable(group):vacf, :elapsed_timeVelocity autocorrelation function
CollisionObservable():counts, :rate, :pair_counts, :pair_ratesEncounters between particle types
BathExchangeObservable():heat, :entropy, :entropy_production_rate, :temperature_error, :extended_hamiltonianHeat/entropy exchange with stochastic baths and conserved NHC/CSVR extended Hamiltonian

Notes on specific measurements:

  • Pressure and tensor fields: :pressure_tensor returns (Pxx, Pyy, Pxy) in 2D or (Pxx, Pyy, Pzz, Pxy, Pxz, Pyz) in 3D with P_{αβ} = (K_{αβ} + W_{αβ}) / V; :virial_tensor returns the corresponding configurational virial components W_{αβ}. When capturing tensor or :box NamedTuple fields in memory for direct Julia analysis, attach them to an InMemoryWriter(; observables=[press => [:pressure, :pressure_tensor, :virial_tensor, :surface_tension]]).

  • Constrained & charged systems: when electrostatics, lattice dispersion, or holonomic constraints are active, request virial and pressure observables on the full system (reciprocal-space and constraint virials are global quantities).

  • Collisions: follow the cutoff setup in the two-temperature example or configure pair cutoffs via set_collision_pair_cutoffs!.

Start a production interval ​

julia
run!(sim, Stage(:equilibrate, steps=1_000))
reset_observables!(sim)
run!(sim, Stage(:production, steps=10_000))

reset_observables! clears accumulated measurements and sets a fresh reference configuration for MSD and VACF without erasing output already written to disk. Use writers to control how and when data is saved.

For low-level step diagnostics on a SimulationState, see collect_step_observables, virial_tensor, virial_components, mechanical_pressure, and the Workflow API and SimulationCore references.

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