DCD File

This module defines classes for handling trajectory files in DCD format.

class DCDFile(filename, mode='rb', **kwargs)[source]

A class for reading and writing DCD files. DCD header and first frame is parsed at instantiation. Coordinates from the first frame is set as the reference coordinate set. This class has been tested for 32-bit DCD files. 32-bit floating-point coordinate array can be casted automatically to a specified type, such as 64-bit float, using astype keyword argument, i.e. astype=float, using ndarray.astype() method.

Open filename for reading (default, mode="r"), writing (mode="w"), or appending (mode="r+" or mode="a"). Binary mode option will be appended automatically.


Close trajectory file.


Flush the internal output buffer.


Returns associated/selected atoms.


Returns a copy of reference coordinates for (selected) atoms.


Returns coordinate sets at given indices. indices may be an integer, a list of ordered integers or None. None returns all coordinate sets. If a list of indices is given, unique numbers will be selected and sorted. That is, this method will always return unique coordinate sets in the order they appear in the trajectory file. Shape of the coordinate set array is (n_sets, n_atoms, 3).


Returns relative path to the current file. For absolute path, pass absolute=True argument.


Returns first timestep value.


Returns frame at given index.


Returns timesteps between frames.


Returns linked AtomGroup instance, or None if a link is not established.


Returns remarks parsed from DCD file.


Returns timestep size.


Returns title of the ensemble.


Returns a copy of weights of (selected) atoms.


Go to the frame at index n. n=0 will rewind the trajectory to the beginning, same as calling reset() method. n=-1 will go to the last frame. Frame n will not be parsed until one of next() or nextCoordset() methods is called.


Returns True if trajectory has unitcell data.


Returns True if trajectory is linked to an AtomGroup instance.


Yield coordinate sets for (selected) atoms. Reference coordinates are not included. Iteration starts from the next frame in line.

Link, return, or unlink an AtomGroup instance. When a link to ag is established, coordinates of new frames parsed from the trajectory file will be set as the coordinates of ag and this will update coordinates of all selections and atom subsets pointing to it. At link time, if ag does not have any coordinate sets and reference coordinates of the trajectory is set, reference coordinates of the trajectory will be passed to ag. To break an established link, pass None argument, or to return the linked atom group instance, call with no arguments.


Every time a frame is parsed from the trajectory, all coordinate sets present in the linked AtomGroup will be overwritten.


Returns next coordinate set in a Frame instance. Note that when atoms are set for the trajectory, this method will return the same frame instance after updating its coordinates.


Returns next coordinate set.


Returns the index of the next frame.


Returns number of atoms.


Returns number of frames.


Returns number of fixed atoms.


Returns number of frames.


Returns number of selected atoms. A subset of atoms can be selected by passing a selection to setAtoms().


Go to first frame at index 0. First frame will not be parsed until one of next() or nextCoordset() methods is called.


Set atoms or specify a selection of atoms to be considered in calculations and coordinate requests. When a selection is set, corresponding subset of coordinates will be considered in, for example, alignments and RMSD calculations. Setting atoms also allows some functions to access atomic data when needed. For example, Trajectory and Frame instances become suitable arguments for writePDB(). Passing None as atoms argument will deselect atoms. Note that setting atoms does not change the reference coordinates of the trajectory. To change the reference, use setCoords() method.


Set coords as the trajectory reference coordinate set. coords must be an object with getCoords() method, or a Numpy array with suitable data type, shape, and dimensionality.


Set title of the ensemble.


Set atomic weights.


Skip n frames. n must be a positive integer. Skipping some frames will only change the next frame index (nextIndex()) Next frame will not be parsed until one of next() or nextCoordset() methods is called.

write(coords, unitcell=None, **kwargs)[source]

Write coords to a file open in ‘a’ or ‘w’ mode. coords may be a NUmpy array or a ProDy object that stores or points to coordinate data. Note that all coordinate sets of ProDy object will be written. Number of atoms will be determined from the file or based on the size of the first coordinate set written. If unitcell is provided for the first coordinate set, it will be expected for the following coordinate sets as well. If coords is an Atomic or Ensemble all coordinate sets will be written.

Following keywords are used when writing the first coordinate set:

  • timestep – timestep used for integration, default is 1
  • firsttimestep – number of the first timestep, default is 0
  • framefreq – number of timesteps between frames, default is 1
parseDCD(filename, start=None, stop=None, step=None, astype=None)[source]

Parse CHARMM format DCD files (also NAMD 2.1 and later). Returns an Ensemble instance. Conformations in the ensemble will be ordered as they appear in the trajectory file. Use DCDFile class for parsing coordinates of a subset of atoms.

  • filename (str) – DCD filename
  • start (int) – index of first frame to read
  • stop (int) – index of the frame that stops reading
  • step (int) – steps between reading frames, default is 1 meaning every frame
  • astype (type) – cast coordinate array to specified type
writeDCD(filename, trajectory, start=None, stop=None, step=None, align=False)[source]

Write 32-bit CHARMM format DCD file (also NAMD 2.1 and later). trajectory can be an Trajectory, DCDFile, or Ensemble instance. filename is returned upon successful output of file.