Interface for reading and writing to a CHARMM/NAMD DCD 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 DCD file are angstroms and degrees. The format supports saving coordinates and unit cell parameters (lengths and angles)
Parameters: | filename : string
mode : {‘r’, ‘w’}
force_overwrite : bool
|
---|
See also
Examples
>>> # read a single frame, and then read the remaining frames
>>> f = DCDTrajectoryFile('mytrajectory.dcd', 'r')
>>> f.read(n_frames=1) # read a single frame from the file
>>> xyzf.read() # read all of the remaining frames
>>> f.close()
>>> # read all of the data with automatic closing of the file
>>> with DCDTrajectoryFile('mytrajectory.dcd') as f:
>>> xyz, cell_lengths, cell_angles = f.read()
>>> # write some xyz coordinates to a new file
>>> with DCDTrajectoryFile('mytrajectory2.dcd. 'w') as f:
>>> f.write(np.random.randn(10,3,3))
>>> # write frames one at a time
>>> with DCDTrajectoryFile('mytrajectory2.dcd. 'w') as f:
>>> n_frames, n_atoms = 5, 10
>>> for i in range(n_frames):
>>> f.write(np.random.randn(n_atoms, 3))
x.__init__(...) initializes x; see help(type(x)) for signature
Methods
close | Close the DCD file handle |
read([n_frames, stride, atom_indices]) | Read the data from a DCD 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[, cell_lengths, cell_angles]) | Write one or more frames of data to the DCD file |
Attributes
distance_unit |
Close the DCD file handle
Read the data from a DCD file
Parameters: | n_frames : int, optional
stride : np.ndarray, optional
atom_indices : array_like, optional
|
---|---|
Returns: | xyz : np.ndarray, shape=(n_frames, n_atoms, 3), dtype=float32
cell_lengths : np.ndarray, shape=(n_frames, 3), dtype=float32
cell_angles : np.ndarray, shape=(n_frames, 3), dtype=float32
|
Read a trajectory from an XTC file
Parameters: | topology : Topology
n_frames : int, optional
stride : np.ndarray, optional
atom_indices : array_like, optional
|
---|---|
Returns: | trajectory : Trajectory
|
Move to a new file position
Parameters: | offset : int
whence : {0, 1, 2}
|
---|
Current file position
Returns: | offset : int
|
---|
Write one or more frames of data to the DCD file
Parameters: | xyz : np.ndarray, shape=(n_frames, n_atoms, 3)
cell_lengths : np.ndarray, shape=(n_frames, 3), dtype=float32, optional
cell_angles : np.ndarray, shape=(n_frames, 3), dtype=float32, optional
|
---|