BaseTrajectoryReader¶
- class mdcraft.io.base.BaseTrajectoryReader(filename: str | Path, /, *, n_workers: int | None = 1)[source]¶
Bases:
BaseReaderBase class for trajectory readers.
Subclasses must set values for
the
_FORMATand_EXTENSIONSattributes, which specify the format and standard extension(s) of the trajectory file, respectively,the
_PARALLELIZABLEattribute, which specifies whether the reader can process a file in parallel,the
_unitsattribute, which specifies the base units (charge, energy, length, mass, temperature, and time) used by the simulation software that generated the trajectory file,the
_reducedattribute, which specifies whether the data is in reduced units,the
dt()andtime_step()properties, which specify the time step size between timesteps and the time step between frames, respectively,the
times()andtimesteps()properties, which specify the simulation times and timesteps found in the trajectory, andthe
n_atoms()andn_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, andthe
open()andclose()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
Closes the topology or trajectory file and deletes the handle.
Opens the topology or trajectory file and stores a handle to it.
Reads data from one or more frames from the trajectory file.
- 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.
- 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}\).