# mdtraj.formats.DTRTrajectoryFile¶

class mdtraj.formats.DTRTrajectoryFile(filename, mode='r', force_overwrite=True)

Interface for reading and writing to a DESMOND dtr file. 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 conventional units in the dtr file are angstroms and degrees. The format supports saving coordinates and unit cell parameters (lengths and angles)

Parameters
filenamestring

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.

mdtraj.load_dtr

High-level wrapper that returns a md.Trajectory

Examples

>>> # read a single frame, and then read the remaining frames
>>> f = DTRTrajectoryFile('mytrajectory.dtr', 'r')
>>> f.close()

>>> # read all of the data with automatic closing of the file
>>> with DTRTrajectoryFile('mytrajectory.dtr') as f:
>>>    xyz, cell_lengths, cell_angles = f.read()

>>> # write some xyz coordinates to a new file
>>> with DTRTrajectoryFile('mytrajectory2.dtr. 'w') as f:
>>>     f.write(np.random.randn(10,3,3))

>>> # write frames one at a time
>>> with DTRTrajectoryFile('mytrajectory2.dtr. 'w') as f:
>>>     n_frames, n_atoms = 5, 10
>>>     for i in range(n_frames):
>>>         f.write(np.random.randn(n_atoms, 3))

Attributes
distance_unit

Methods

 close() Close the dtr file handle get_times() Reading chemical times associated with all frames. read([n_frames, stride, atom_indices]) Read the data from a DTR file read_as_traj(topology[, n_frames, stride, …]) Read a trajectory from a DTR file seek(offset[, whence]) Move to a new file position tell() Current file position write(xyz[, cell_lengths, cell_angles, times]) Write one or more frames of data to the dtr file
__init__(self, /, \*args, \*\*kwargs)

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

Methods

 __init__(self, /, \*args, \*\*kwargs) Initialize self. close() Close the dtr file handle get_times() Reading chemical times associated with all frames. read([n_frames, stride, atom_indices]) Read the data from a DTR file read_as_traj(topology[, n_frames, stride, …]) Read a trajectory from a DTR file seek(offset[, whence]) Move to a new file position tell() Current file position write(xyz[, cell_lengths, cell_angles, times]) Write one or more frames of data to the dtr file

Attributes

 distance_unit