mdtraj.formats.LH5TrajectoryFile¶
-
class
mdtraj.formats.
LH5TrajectoryFile
(filename, mode='r', force_overwrite=True)¶ Interface for reading and writing to a MSMBuilder2 “LH5” molecular dynamics trajectory file, a deprecated format.
- Parameters
- filenamestr
Path to the file to open
- mode{‘r, ‘w’}
Mode in which to open the file. ‘r’ is for reading and ‘w’ is for writing
- force_overwritebool
In mode=’w’, how do you want to behave if a file by the name of filename already exists? if force_overwrite=True, it will be overwritten.
- Attributes
topology
Get the topology out from the file
Methods
close
(self)Close the HDF5 file handle
flush
(self)Write all buffered data in the to the disk file.
read
(self[, n_frames, stride, atom_indices])Read one or more frames of data from the file
read_as_traj
(self[, n_frames, stride, …])Read a trajectory from the LH5 file
seek
(self, offset[, whence])Move to a new file position
tell
(self)Current file position
write
(self, coordinates)Write one or more frames of data to the file
-
__init__
(self, filename, mode='r', force_overwrite=True)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
(self, filename[, mode, force_overwrite])Initialize self.
close
(self)Close the HDF5 file handle
flush
(self)Write all buffered data in the to the disk file.
read
(self[, n_frames, stride, atom_indices])Read one or more frames of data from the file
read_as_traj
(self[, n_frames, stride, …])Read a trajectory from the LH5 file
seek
(self, offset[, whence])Move to a new file position
tell
(self)Current file position
write
(self, coordinates)Write one or more frames of data to the file
Attributes
distance_unit
Get the topology out from the file
-
close
(self)¶ Close the HDF5 file handle
-
flush
(self)¶ Write all buffered data in the to the disk file.
-
read
(self, n_frames=None, stride=None, atom_indices=None)¶ Read one or more frames of data from the file
- Parameters
- n_frames{int, None}
The number of frames to read. If not supplied, all of the remaining frames will be read.
- stride{int, None}
By default all of the frames will be read, but you can pass this flag to read a subset of of the data by grabbing only every stride-th frame from disk.
- atom_indices{int, None}
By default all of the atom will be read, but you can pass this flag to read only a subsets of the atoms for the coordinates and velocities fields. Note that you will have to carefully manage the indices and the offsets, since the i-th atom in the topology will not necessarily correspond to the i-th atom in your subset.
- Returns
- xyznp.ndarray, shape=(n_frames, n_atoms, 3), dtype=np.float32
The cartesian coordinates, in nanometers
-
read_as_traj
(self, n_frames=None, stride=None, atom_indices=None)¶ Read a trajectory from the LH5 file
- Parameters
- n_frames{int, None}
The number of frames to read. If not supplied, all of the remaining frames will be read.
- stride{int, None}
By default all of the frames will be read, but you can pass this flag to read a subset of of the data by grabbing only every stride-th frame from disk.
- atom_indices{int, None}
By default all of the atom will be read, but you can pass this flag to read only a subsets of the atoms for the coordinates and velocities fields. Note that you will have to carefully manage the indices and the offsets, since the i-th atom in the topology will not necessarily correspond to the i-th atom in your subset.
- Returns
- trajectoryTrajectory
A trajectory object containing the loaded portion of the file.
-
seek
(self, offset, whence=0)¶ Move to a new file position
- Parameters
- offsetint
A number of frames.
- whence{0, 1, 2}
0: offset from start of file, offset should be >=0. 1: move relative to the current position, positive or negative 2: move relative to the end of file, offset should be <= 0. Seeking beyond the end of a file is not supported
-
tell
(self)¶ Current file position
- Returns
- offsetint
The current frame in the file.
-
property
topology
¶ Get the topology out from the file
- Returns
- topologymdtraj.Topology
A topology object
-
write
(self, coordinates)¶ Write one or more frames of data to the file
- Parameters
- coordinatesnp.ndarray, dtype=np.float32, shape=(n_frames, n_atoms, 3)
The cartesian coordinates of the atoms in every frame, in nanometers.