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:

filename : str

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_overwrite : bool

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.

__init__(filename, mode='r', force_overwrite=True)

Methods

__init__(filename[, mode, force_overwrite])
close() Close the HDF5 file handle
flush() Write all buffered data in the to the disk file.
read(*args, **kwargs) Read one or more frames of data from the file
seek(*args, **kwargs) Move to a new file position
tell() Current file position
write(*args, **kwargs) Write one or more frames of data to the file

Attributes

distance_unit
topology Get the topology out from the file
close()

Close the HDF5 file handle

flush()

Write all buffered data in the to the disk file.

read(*args, **kwargs)

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:

xyz : np.ndarray, shape=(n_frames, n_atoms, 3), dtype=np.float32

The cartesian coordinates, in nanometers

seek(*args, **kwargs)

Move to a new file position

Parameters:

offset : int

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()

Current file position

Returns:

offset : int

The current frame in the file.

topology

Get the topology out from the file

Returns:

topology : mdtraj.Topology

A topology object

write(*args, **kwargs)

Write one or more frames of data to the file

Parameters:

coordinates : np.ndarray, dtype=np.float32, shape=(n_frames, n_atoms, 3)

The cartesian coordinates of the atoms in every frame, in nanometers.

Versions