6.22. XYZ trajectory reader —
Note the following:
- Comments are not allowed in the XYZ file (we neither read nor write them to remain compatible with VMD).
- The atom name (first column) is ignored during reading.
- The coordinates are assumed to be space-delimited rather than fixed width (this may cause issues - see below).
- All fields to the right of the z-coordinate are ignored.
- The unitcell information is all zeros since this is not recorded in the XYZ format.
- Coordinates are in Angstroms.
- The length of a timestep can be set by passing the dt argument, it’s assumed to be in ps (default: 1 ps).
There appears to be no rigid format definition so it is likely users will need to tweak this class.
6.22.1. XYZ File format¶
[ comment line ] !! NOT IMPLEMENTED !! DO NOT INCLUDE [ N ] # of atoms, required by this xyz reader plugin line 1 [ molecule name ] name of molecule (can be blank) line 2 atom1 x y z [optional data] atom name followed by xyz coords line 3 atom2 x y z [ ... ] and (optionally) other data. ... atomN x y z [ ... ] line N+2
- comment lines not implemented (do not include them)
- molecule name: the line is required but the content is ignored at the moment
- optional data (after the coordinates) are presently ignored
Reads from an XYZ file
Timestep object containing coordinates of current frame
return number of frames in xyz
for ts in xyz:
iterate through trajectory
Changed in version 0.11.0: Frames now 0-based instead of 1-based. Added dt and time_offset keywords (passed to
Writer(filename, n_atoms=None, **kwargs)¶
Returns a XYZWriter for filename with the same parameters as this XYZ.
Parameters: Returns: Return type:
XYZWriter(see there for more details)
Close xyz trajectory file if it was open.
number of atoms in a frame
XYZWriter(filename, n_atoms=None, atoms=None, convert_units=True, remark=None, **kwargs)¶
Writes an XYZ file
The XYZ file format is not formally defined. This writer follows the VMD implementation for the molfile xyzplugin.
Initialize the XYZ trajectory writer
- filename (str) – filename of trajectory file. If it ends with “gz” then the file will be gzip-compressed; if it ends with “bz2” it will be bzip2 compressed.
- n_atoms (int (optional)) – Number of atoms in trajectory. By default assume that this is None and that this file is used to store several different models instead of a single trajectory. If a number is provided each written TimeStep has to contain the same number of atoms.
- atoms (str | list (optional)) – Provide atom names: This can be a list of names or an
AtomGroup. If none is provided, atoms will be called ‘X’ in the output. These atom names will be used when a trajectory is written from raw
Timestepobjects which do not contain atom information. If you write a
XYZWriter.write()then atom information is taken at each step and atoms is ignored.
- convert_units (bool (optional)) – convert quantities to default MDAnalysis units of Angstrom upon
- remark (str (optional)) – single line of text (“molecule name”). By default writes MDAnalysis version and frame
- versionchanged: (.) – 1.0.0: Removed
default_remarkvariable (Issue #2692).
Close the trajectory file and finalize the writing
Write object obj at current trajectory frame to file.
Atom elements (or names) in the output are taken from the obj or default to the value of the atoms keyword supplied to the
Parameters: obj (Universe or AtomGroup) – The
Deprecated since version 1.0.0: Deprecated the use of Timestep as arguments to write. Use either an AtomGroup or Universe. To be removed in version 2.0.