Skip to content

trajectory_adapters

Optional trajectory adapters for analysis libraries.

These helpers intentionally import MDAnalysis and MDTraj lazily so the core MLX engine remains dependency-light.

import mlx_atomistic.trajectory_adapters

class OptionalTrajectoryDependencyError(RuntimeError)

Raised when an optional trajectory analysis dependency is unavailable.

def load_mdanalysis_universe(topology_path: str | Path, trajectory_path: str | Path | None = None, **kwargs = {})

Load a topology/trajectory pair as an MDAnalysis Universe.

Parameters

NameTypeDefaultDescription
topology_pathstr | Path
trajectory_pathstr | Path | NoneNone
**kwargs{}
def mdanalysis_universe_from_arrays(topology_path: str | Path, positions_angstrom: np.ndarray, *, time_ps: np.ndarray | None = None, dt_ps: float | None = None)

Attach in-memory Angstrom coordinates to an MDAnalysis topology.

Parameters

NameTypeDefaultDescription
topology_pathstr | Path
positions_angstromnp.ndarray
time_psnp.ndarray | NoneNone
dt_psfloat | NoneNone
def trajectory_record_to_mdanalysis(topology_path: str | Path, record: TrajectoryRecord)

Convert a native MLX trajectory record into an MDAnalysis Universe.

Parameters

NameTypeDefaultDescription
topology_pathstr | Path
recordTrajectoryRecord
def trajectory_record_to_mdtraj(topology_path: str | Path, record: TrajectoryRecord)

Convert a native MLX trajectory record into an MDTraj Trajectory.

mlx_atomistic stores coordinates in Angstrom. MDTraj stores coordinates in nanometers, so coordinates are converted by dividing by 10.

Parameters

NameTypeDefaultDescription
topology_pathstr | Path
recordTrajectoryRecord
def write_mdtraj_trajectory(topology_path: str | Path, record: TrajectoryRecord, trajectory_path: str | Path, *, file_format: str | None = None) -> Path

Write a native MLX trajectory record through MDTraj.

Supported first-class runner formats are DCD and XTC. MLX stores coordinates in Angstrom; trajectory_record_to_mdtraj handles MDTraj’s nanometer convention before writing.

Parameters

NameTypeDefaultDescription
topology_pathstr | Path
recordTrajectoryRecord
trajectory_pathstr | Path
file_formatstr | NoneNone

Returns

  • Path