mod md_engine

module md_engine

Short MD segments through external engines (LAMMPS, GROMACS). Short molecular-dynamics segments through external engines.

Diversity that the sampler’s own move set cannot produce comes from dynamics: a burst of thermostatted MD decorrelates a configuration along the landscape’s own soft modes, crossing the low barriers first, which is the physics an isotropic proposal ignores. In the bridge layer the segments are not merely diversity: umbrella and forward-flux constructions define their crossing statistics over dynamical trajectories, so an MD segment propagator is what makes the recorded flux and the committor surrogate dynamical objects rather than artifacts of a proposal family.

The contract is propagate-and-report: an engine takes flattened coordinates, a step count, a reduced temperature, and a seed, and returns the final coordinates. Every MD step is a force evaluation and must be charged by the caller; nothing here touches any ledger.

LAMMPS is the first-class engine, driven in process through its documented C API (liblammps): one persistent instance per engine, coordinates scattered and gathered in memory, no input files and no subprocess. Enabled by the lammps feature, which links against LAMMPS_LIB_DIR. GROMACS has no embeddable C API (its gmxapi targets workflow orchestration, not in-process propagation), so the GROMACS engine drives the gmx binary as a subprocess with the reduced system mapped onto its unit system: one length unit to one nanometer, one energy unit to one kilojoule per mole, one mass unit to one atomic mass unit, under which the reduced temperature maps through the gas constant to T[K] = T* / 0.00831446 and the reduced time step carries over numerically in picoseconds.

Functions

fn engine_by_name(name: &str, binary: &Path, workdir: &Path) -> Option<Box<dyn SegmentEngine + Send>>

Build an engine from its name. LAMMPS runs in process through liblammps (feature lammps); its binary path is unused and the workdir irrelevant. GROMACS needs the gmx binary path and a scratch directory.

fn gromacs_gro(x: ArrayView1<f64>) -> String

The gro configuration for a one-species reduced cluster, shifted so the cluster sits inside a box wide enough for the cutoff.

fn gromacs_mdp(steps: usize, temperature: f64, seed: u64) -> String

The mdp parameters for a stochastic-dynamics segment.

fn gromacs_topology(atoms: usize) -> String

The reduced Lennard-Jones topology in GROMACS units.

fn parse_gro(text: &str, atoms: usize, shift: [f64; 3]) -> Result<Array1<f64>, EngineError>

Parse a gro file’s positions back to flattened coordinates, undoing the shift applied on the way in.

Traits

trait SegmentEngine

Propagate-and-report: the whole engine contract.

Functions

fn name(&self) -> &'static str

Engine name for traces and manifests.

fn propagate(&self, x: ArrayView1<f64>, steps: usize, temperature: f64, seed: u64) -> Result<Array1<f64>, EngineError>

Advance x (flattened 3N coordinates, reduced units) by steps MD steps at reduced temperature temperature, deterministic in seed, returning the final coordinates.

Implemented for

impl SegmentEngine for LammpsLj

Enums

enum EngineError

Failure of an external MD segment.

Io(std::io::Error)

The engine input could not be written or output read.

Run(String)

The engine reported an error or exited abnormally.

Output(String)

The engine output did not parse back to the input’s shape.

Structs and Unions

struct GromacsLj

GROMACS as a reduced-unit Lennard-Jones segment engine, subprocess driven because no embeddable C API exists.

binary: PathBuf

The gmx binary.

workdir: PathBuf

Scratch directory for segment files.

Implementations

impl GromacsLj

Traits implemented

impl SegmentEngine for GromacsLj
struct LammpsLj

LAMMPS driven in process through its C API, reduced Lennard-Jones units, one persistent instance reused across segments.

Implementations

impl LammpsLj

Functions

fn new() -> Self

An engine with no live instance; the instance boots on the first segment, sized to that segment’s atom count.

Traits implemented

unsafe impl Send for LammpsLj
impl Default for LammpsLj
impl Drop for LammpsLj