mdtraj.formats.XYZTrajectoryFile¶
-
class
mdtraj.formats.
XYZTrajectoryFile
(filename, mode='r', force_overwrite=True)¶ Interface for reading and writing to xyz files.
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.
Parameters: filename : str
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_overwrite : bool
If opened in write mode, and a file by the name of filename already exists on disk, should we overwrite it?
Methods
close
()Close the xyz file. read
([n_frames, stride, atom_indices])Read data from a xyz file. read_as_traj
(topology[, n_frames, stride, ...])Read a trajectory from a XYZ file seek
(offset[, whence])Move to a new file position. tell
()Current file position. write
(xyz[, types])Write one or more frames of data to a xyz file. -
__init__
(filename, mode='r', force_overwrite=True)¶ Open a xyz file for reading/writing.
Methods
__init__
(filename[, mode, force_overwrite])Open a xyz file for reading/writing. close
()Close the xyz file. read
([n_frames, stride, atom_indices])Read data from a xyz file. read_as_traj
(topology[, n_frames, stride, ...])Read a trajectory from a XYZ file seek
(offset[, whence])Move to a new file position. tell
()Current file position. write
(xyz[, types])Write one or more frames of data to a xyz file. Attributes
distance_unit
-
close
()¶ Close the xyz file.
-
read
(n_frames=None, stride=None, atom_indices=None)¶ Read data from a xyz file.
Parameters: n_frames : int, None
The number of frames you would like to read from the file. If None, all of the remaining frames will be loaded.
stride : np.ndarray, optional
Read only every stride-th frame.
atom_indices : array_like, optional
If not none, then read only a subset of the atoms coordinates from the file.
Returns: xyz : np.ndarray, shape=(n_frames, n_atoms, 3), dtype=np.float32
-
read_as_traj
(topology, n_frames=None, stride=None, atom_indices=None)¶ Read a trajectory from a XYZ file
Parameters: topology : Topology
The system topology
n_frames : int, optional
If positive, then read only the next n_frames frames. Otherwise read all of the frames in the file.
stride : np.ndarray, optional
Read only every stride-th frame.
atom_indices : array_like, optional
If not none, then read only a subset of the atoms coordinates from the file. This may be slightly slower than the standard read because it required an extra copy, but will save memory.
Returns: trajectory : Trajectory
A trajectory object containing the loaded portion of the file.
-
seek
(offset, whence=0)¶ Move to a new file position.
Parameters: offset : int
A number of frames.
whence : {0, 1, 2}
0: offset from start of file, offset should be >=0. 1: move relative to the current position, positive or negative 2: move relative to the end of file, offset should be <= 0. Seeking beyond the end of a file is not supported
-
tell
()¶ Current file position.
Returns: offset : int
The current frame in the file.
-
write
(xyz, types=None)¶ Write one or more frames of data to a xyz file.
Parameters: xyz : np.ndarray, shape=(n_frames, n_atoms, 3)
The cartesian coordinates of the atoms to write. By convention for this trajectory format, the lengths should be in units of angstroms.
types : np.ndarray, shape(3, )
The type of each particle.
-