6.23. 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.23.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, 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.
By default, the XYZ writer will attempt to use the input
elementsrecord to assign atom names in the XYZ file. If the
elementsrecord is missing, then the
namerecord will be used. In the event that neither of these are available, the atoms will all be named
X. Please see, the User Guide for more information on how to add topology attributes if you wish to add your own elements / atom names to a
Changed in version 1.0.0: Use elements attribute instead of names attribute, if present.
Changed in version 2.0.0: Support for passing timestep to the writer was deprecated in 1.0 and has now been removed. As a consequence, custom names can no longer be passed to the writer, these should be added to the
AtomGroupbefore invoking the writer.
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.
- 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
Changed in version 1.0.0: Removed
default_remarkvariable (Issue #2692).
Changed in version 2.0.0: Due to the removal of timestep as an input for writing, the atoms parameter is no longer relevant and has been removed. If passing an empty universe, please use
add_TopologyAttrto add in the required elements or names.
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
Changed in version 2.0.0: Deprecated support for Timestep argument has now been removed. Use AtomGroup or Universe as an input instead.