BaseTrajectoryReader

class mdcraft.io.base.BaseTrajectoryReader(filename: str | Path, /, *, n_workers: int | None = 1)[source]

Bases: BaseReader

Base class for trajectory readers.

Subclasses must set values for

  • the _FORMAT and _EXTENSIONS attributes, which specify the format and standard extension(s) of the trajectory file, respectively,

  • the _PARALLELIZABLE attribute, which specifies whether the reader can process a file in parallel,

  • the _units attribute, which specifies the base units (charge, energy, length, mass, temperature, and time) used by the simulation software that generated the trajectory file,

  • the _reduced attribute, which specifies whether the data is in reduced units,

  • the dt() and time_step() properties, which specify the time step size between timesteps and the time step between frames, respectively,

  • the times() and timesteps() properties, which specify the simulation times and timesteps found in the trajectory, and

  • the n_atoms() and n_frames() properties, which specify the number of frames in the trajectory and the number of atoms in each frame, respectively,

and implement

  • the __repr__() method to provide a string representation of the reader that can be used to recreate it,

  • the _parse_frame() method to read and parse data from a single frame in the trajectory file, and

  • the open() and close() methods to handle the opening and closing of the file.

Parameters:
filenamestr or pathlib.Path, positional-only

Filename or path to the trajectory file.

n_workersint, keyword-only, default: 1

Number of threads to use when reading the file. If None, the number of available logical threads is used.

Methods

close

Closes the topology or trajectory file and deletes the handle.

open

Opens the topology or trajectory file and stores a handle to it.

read_frames

Reads data from one or more frames from the trajectory file.

abstractmethod close() None

Closes the topology or trajectory file and deletes the handle.

abstract property dt: float | None

Time step size between timesteps in the trajectory. If None, the time step size is not constant across frames or could not be determined from the trajectory.

Reference unit: \(\mathrm{ps}\).

abstract property n_atoms: int | None

Number of atoms in each frame. If None, the number of atoms is not constant across frames.

abstract property n_frames: int

Number of frames in the trajectory.

abstractmethod open() None

Opens the topology or trajectory file and stores a handle to it.

read_frames(frame_indices: int | slice | Iterable[int], /, *, _convert_units: bool = True) dict[str, Any] | list[dict[str, Any]][source]

Reads data from one or more frames from the trajectory file.

Parameters:
frame_indicesint, slice, or array-like, positional-only

Indices of frames to read.

Returns:
datadict or list

Data from the frame(s).

abstract property time_step: float | None

Time step between frames in the trajectory. If None, the time step is not constant across frames.

Reference unit: \(\mathrm{ps}\).

abstract property times: ndarray[float64]

Simulation times found in the trajectory.

Reference unit: \(\mathrm{ps}\).

abstract property timesteps: ndarray[uint32] | None

Simulation timesteps found in the trajectory. If None, the timesteps could not be determined from the trajectory.