5.20. 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.

See also

For trajectory formats: DCDReader, XTCReader, TRRReader, XYZReader. For single frame formats: CRDReader, PDBReader and PrimitivePDBReader, GROReader,

Arguments:
filename

filename of the input trajectory or coordinate file

permissive

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.

MDAnalysis.coordinates.core.writer(filename, n_atoms=None, **kwargs)[source]

Initialize a trajectory writer instance for filename.

Arguments:
filename

Output filename of the trajectory; the extension determines the format.

n_atoms

The number of atoms in the output trajectory; can be ommitted for single-frame writers.

multiframe

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

Keyword arguments for the writer; all trajectory Writers accept at least

start

starting time [0]

step

step size in frames [1]

delta

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.

See also

DCDWriter for DCD trajectories or XTCWriter and TRRWriter for Gromacs.

Changed in version 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.

Automatic detection is disabled when an explicit format is provided.

MDAnalysis.coordinates.core.get_writer_for(filename=None, format='DCD', 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. The default is to return a dcd writer (format = ‘dcd’). If the filename is not provided or if it is something like a cStringIO.StringIO instance then the format argument must be used.

Arguments:
filename

The filename for the trajectory is examined for its extension and the Writer is chosen accordingly.

format

If no filename is supplied then the format can be explicitly set; possible values are “DCD”, “XTC”, “TRR”; “PDB”, “CRD”, “GRO”.

multiframe

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 is None.

Changed in version 0.7.6: Added multiframe keyword; the default None reflects the previous behaviour.