mdtraj.formats.TRRTrajectoryFile

class mdtraj.formats.TRRTrajectoryFile(filename, mode='r', force_overwrite=True, **kwargs)

Interface for reading and writing to a GROMACS TRR file. This is a file-like objec that supports both reading and writing. It also supports the context manager protocol, so you can use it with the python ‘with’ statement.

The conventional units in the TRR file are nanometers and picoseconds. The format only supports saving coordinates, the time, the md step, and the unit cell parametrs (box vectors)

Parameters
filenamestr

The filename to open. A path to a file on disk.

mode{‘r’, ‘w’}

The mode in which to open the file, either ‘r’ for read or ‘w’ for write.

force_overwritebool

If opened in write mode, and a file by the name of filename already exists on disk, should we overwrite it?

Other Parameters
min_chunk_sizeint, default=100

In read mode, we need to allocate a buffer in which to store the data without knowing how many frames are in the file. This parameter is the minimum size of the buffer to allocate.

chunk_size_multiplier, int, default=1.5

In read mode, we need to allocate a buffer in which to store the data without knowing how many frames are in the file. We can guess this information based on the size of the file on disk, but it’s not perfect. This parameter inflates the guess by a multiplicative factor.

See also

mdtraj.load_trr

High-level wrapper that returns a md.Trajectory

Examples

>>> # load up the data from a trr
>>> with TRRTrajectoryFile('traj.trr') as f:
>>>    xyz, time, step, box, lambdas = f.read()
Attributes
distance_unit
offsets

get byte offsets from current xtc file

Methods

close()

Close the TRR file

read([n_frames, stride, atom_indices])

Read data from a TRR file

read_as_traj(topology[, n_frames, stride, …])

Read a trajectory from an XTC file

seek(offset[, whence])

Move to a new file position

tell()

Current file position

write(xyz[, time, step, box, lambd])

Write data to a TRR file

__init__(self, /, \*args, \*\*kwargs)

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

Methods

__init__(self, /, \*args, \*\*kwargs)

Initialize self.

close()

Close the TRR file

read([n_frames, stride, atom_indices])

Read data from a TRR file

read_as_traj(topology[, n_frames, stride, …])

Read a trajectory from an XTC file

seek(offset[, whence])

Move to a new file position

tell()

Current file position

write(xyz[, time, step, box, lambd])

Write data to a TRR file

Attributes

distance_unit

offsets

get byte offsets from current xtc file See Also ——– set_offsets