Trajectory File¶
This module defines a base class for format specific trajectory classes.
-
class
TrajFile
(filename, mode='r')[source]¶ A base class for trajectory file classes:
Open filename for reading (default,
mode="r"
), writing (mode="w"
), or appending (mode="r+"
ormode="a"
). Binary mode option will be appended automatically.-
getAtoms
()¶ Returns associated/selected atoms.
-
getCoords
()¶ Returns a copy of reference coordinates for (selected) atoms.
-
getCoordsets
(indices=None)[source]¶ 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).
-
getFilename
(absolute=False)[source]¶ Returns relative path to the current file. For absolute path, pass
absolute=True
argument.
-
getTitle
()¶ Returns title of the ensemble.
-
getWeights
()¶ Returns a copy of weights of (selected) atoms.
-
goto
(n)[source]¶ Go to the frame at index n.
n=0
will rewind the trajectory to the beginning, same as callingreset()
method.n=-1
will go to the last frame. Frame n will not be parsed until one ofnext()
ornextCoordset()
methods is called.
-
hasUnitcell
()¶ Returns True if trajectory has unitcell data.
-
iterCoordsets
()¶ Yield coordinate sets for (selected) atoms. Reference coordinates are not included. Iteration starts from the next frame in line.
-
link
(*ag)¶ 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.Warning
Every time a frame is parsed from the trajectory, all coordinate sets present in the linked
AtomGroup
will be overwritten.
-
next
()¶ 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.
-
nextCoordset
()¶ Returns next coordinate set.
-
nextIndex
()¶ Returns the index of the next frame.
-
numAtoms
()¶ Returns number of atoms.
-
numCoordsets
()¶ Returns number of frames.
-
numFrames
()¶ Returns number of frames.
-
numSelected
()¶ Returns number of selected atoms. A subset of atoms can be selected by passing a selection to
setAtoms()
.
-
reset
()[source]¶ Go to first frame at index 0. First frame will not be parsed until one of
next()
ornextCoordset()
methods is called.
-
setAtoms
(atoms)¶ 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
andFrame
instances become suitable arguments forwritePDB()
. 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, usesetCoords()
method.
-
setCoords
(coords)¶ 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.
-
setTitle
(title)¶ Set title of the ensemble.
-
setWeights
(weights)¶ Set atomic weights.
-
skip
(n)[source]¶ 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 ofnext()
ornextCoordset()
methods is called.
-