mdtraj.formats.HDF5TrajectoryFile

class mdtraj.formats.HDF5TrajectoryFile(filename, mode='r', force_overwrite=True, compression='zlib')

Interface for reading and writing to a MDTraj HDF5 molecular dynamics trajectory file, whose format is described here.

This is a file-like object, that both reading or writing depending on the mode flag. It implements the context manager protocol, so you can also use it with the python ‘with’ statement.

The format is extremely flexible and high performance. It can hold a wide variety of information about a trajectory, including fields like the temperature and energies. Because it’s built on the fantastic HDF5 library, it’s easily extensible too.

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.

compression{‘zlib’, None}

Apply compression to the file? This will save space, and does not cost too many cpu cycles, so it’s recommended.

See also

mdtraj.load_hdf5

High-level wrapper that returns a md.Trajectory

Attributes
root

Direct access to the root group of the underlying Tables HDF5 file handle.

title

User-defined title for the data represented in the file

application

Suite of programs that created the file

topology

Get the topology out from the file

randomState

State of the creators internal random number generator at the start of the simulation

forcefield

Description of the hamiltonian used.

reference

A published reference that documents the program or parameters used to generate the data

constraints

Constraints applied to the bond lengths

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 HDF5 file

seek(self, offset[, whence])

Move to a new file position

tell(self)

Current file position

write(self, coordinates[, time, …])

Write one or more frames of data to the file

__init__(self, filename, mode='r', force_overwrite=True, compression='zlib')

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(self, filename[, mode, …])

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 HDF5 file

seek(self, offset[, whence])

Move to a new file position

tell(self)

Current file position

write(self, coordinates[, time, …])

Write one or more frames of data to the file

Attributes

application

Suite of programs that created the file

constraints

Constraints applied to the bond lengths

distance_unit

forcefield

Description of the hamiltonian used.

randomState

State of the creators internal random number generator at the start of the simulation

reference

A published reference that documents the program or parameters used to generate the data

root

Direct access to the root group of the underlying Tables HDF5 file handle.

title

User-defined title for the data represented in the file

topology

Get the topology out from the file