5.18. Common functions for coordinate reading — MDAnalysis.coordinates.core
¶
Important base classes are collected in MDAnalysis.coordinates.base
.
-
MDAnalysis.coordinates.core.
reader
(filename, **kwargs)[source]¶ Provide a trajectory reader instance for filename.
This function guesses the file format from the extension of filename and it will throw a
TypeError
if the extension is not recognized.In most cases, no special keyword arguments are necessary. For PDB readers it might be useful to set the permissive =
True
flag to select a simpler but faster reader.All other keywords are passed on to the underlying Reader classes; see their documentation for details.
Parameters: - filename (str or tuple) – filename (or tuple of filenames) of the input coordinate file
- permissive (bool) – If set to
True
, a reader is selected that is more tolerant of the input (currently only implemented for PDB). [False
] - kwargs – Keyword arguments for the selected Reader class.
Returns: - A Reader object
- .. SeeAlso (: For trajectory formats:
DCDReader
,) –XTCReader
,TRRReader
,XYZReader
. For single frame formats:CRDReader
,PDBReader
andPrimitivePDBReader
,GROReader
,
-
MDAnalysis.coordinates.core.
writer
(filename, n_atoms=None, **kwargs)[source]¶ Initialize a trajectory writer instance for filename.
- filename : str
- Output filename of the trajectory; the extension determines the format.
- n_atoms : int, optional
- The number of atoms in the output trajectory; can be ommitted for single-frame writers.
- multiframe : bool, optional
True
: write a trajectory with multiple frames;False
only write a single frame snapshot;None
first try to get a multiframe writer and then fall back to single frame [None
]- kwargs : optional
Keyword arguments for the writer; all trajectory Writers accept at least
- start
- starting time [0]
- step
- step size in frames [1]
- dt
- length of time between two frames, in ps [1.0]
Some readers accept additional arguments, which need to be looked up in the documentation of the reader.
Returns: - A Writer object
- .. SeeAlso (:
DCDWriter
for DCD) – trajectories orXTCWriter
andTRRWriter
for Gromacs. - .. versionchanged (: 0.7.6) –
Added multiframe keyword. See also
get_writer_for()
.
Helper functions:
-
MDAnalysis.coordinates.core.
get_reader_for
(filename, permissive=False, format=None)[source]¶ Return the appropriate trajectory reader class for filename.
Parameters: Returns: Return type: A Reader object
Notes
Automatic detection is disabled when an explicit format is provided.
-
MDAnalysis.coordinates.core.
get_writer_for
(filename=None, format=None, multiframe=None)[source]¶ Return an appropriate trajectory or frame writer class for filename.
The format is determined by the format argument or the extension of filename. If format is provided, it takes precedence over The extension of filename.
Parameters: - filename (str) – If no format is supplied, then the filename for the trajectory is examined for its extension and the Writer is chosen accordingly.
- format (str) – Explicitly set a format.
- multiframe (bool) –
True
: write multiple frames to the trajectory;False
: only write a single coordinate frame;None
: first try trajectory (multi frame writers), then the single frame ones. Default isNone
.
Returns: Return type: A Writer object
Raises: ValueError
– The format could not be deduced from filename or an unexpected value was provided for the multiframe argument.TypeError
– No writer got found for the required format.- .. versionchanged (: 0.7.6) –
Added multiframe keyword; the default
None
reflects the previous behaviour. - .. versionchanged (: 0.14.0) –
Removed the default value for the format argument. Now, the value
provided with the format parameter takes precedence over the extension
of filename. A
ValueError
is raised if the format cannot be deduced from filename.