Table Of Contents

Previous topic

5.10. PQR file format — MDAnalysis.coordinates.PQR

Next topic

5.12. Gromacs TRR file IO — MDAnalysis.coordinates.TRR

This Page

5.11. AMBER trajectories — MDAnalysis.coordinates.TRJ

AMBER can write ASCII trajectories (“traj”) and binary trajectories (“netcdf”). MDAnalysis supports reading of both formats and writing for the binary trajectories.

Note

Support for AMBER is experimental and feedback and contributions are highly appreciated. Use the Issue Tracker or get in touch on the MDAnalysis mailinglist.

Units

  • lengths in Angstrom (Å)
  • time in ps (but see below)

AMBER trajectory coordinate frames are based on a Timestep object.

class MDAnalysis.coordinates.TRJ.Timestep(arg, **kwargs)[source]

AMBER trajectory Timestep.

The Timestep can be initialized with arg being

  1. an integer (the number of atoms) and an optional keyword argument velocities to allocate space for both coordinates and velocities;
  2. another Timestep instance, in which case a copy is made (If the copied Timestep does not contain velocities but velocities = True is provided, then space for velocities is allocated);
  3. a numpy.ndarray of shape (numatoms, 3) (for positions only) or (numatoms, 6) (for positions and velocities): positions = arg[:,:3], velocities = arg[:,3:6].
_pos

coordinates of the atoms as a numpy.ndarray of shape (numatoms, 3)

_velocities

velocities of the atoms as a numpy.ndarray of shape (numatoms, 3); only available if the trajectory contains velocities or if the velocities = True keyword has been supplied.

dimensions[source]

unitcell dimensions (A, B, C, alpha, beta, gamma)

  • A, B, C are the lengths of the primitive cell vectors e1, e2, e3
  • alpha = angle(e1, e2)
  • beta = angle(e1, e3)
  • gamma = angle(e2, e3)

Note

A ASCII AMBER trajectory only contains box lengths A,B,C; we assume an orthorhombic box and set all angles to 90º.

5.11.1. ASCII TRAJ trajectories

ASCII AMBER TRJ coordinate files (as defined in AMBER TRJ format) are handled by the TRJReader. It is also possible to directly read bzip2 or gzip compressed files.

AMBER ASCII trajectories are recognised by the suffix ‘.trj’ or ‘.mdcrd’ (possibly with an additional ‘.gz’ or ‘.bz2’).

Limitations

  • Periodic boxes are only stored as box lengths A, B, C in an AMBER trajectory; the reader always assumes that these are orthorhombic boxes.
  • The trajectory does not contain time information so we simply set the time step to 1 ps (or the user could provide it as kwarg delta)
  • No direct access of frames is implemented, only iteration through the trajectory.
  • Trajectories with fewer than 4 atoms probably fail to be read (BUG).
  • If the trajectory contains exactly one atom then it is always assumed to be non-periodic (for technical reasons).
class MDAnalysis.coordinates.TRJ.TRJReader(filename, numatoms=None, **kwargs)[source]

AMBER trajectory reader.

Reads the ASCII formatted AMBER TRJ format. Periodic box information is auto-detected.

The number of atoms in a timestep must be provided in the numatoms keyword because it is not stored in the trajectory header and cannot be reliably autodetected. The constructor raises a ValueError if numatoms is left at its default value of None.

The length of a timestep is not stored in the trajectory itself but can be set by passing the delta keyword argument to the constructor; it is assumed to be in ps. The default value is 1 ps.

Functionality is currently limited to simple iteration over the trajectory.

close()[source]

Close trj trajectory file if it was open.

numframes[source]

Number of frames (obtained from reading the whole trajectory).

open_trajectory()[source]

Open the trajectory for reading and load first frame.

rewind()[source]

Reposition at the beginning of the trajectory

5.11.2. Binary NetCDF trajectories

The AMBER netcdf format make use of NetCDF (Network Common Data Form) format. Such binary trajectories are recognized in MDAnalysis by the ‘.ncdf’ suffix and read by the NCDFReader.

Binary trajectories can also contain velocities and can record the exact time step. In principle, the trajectories can be in different units than the AMBER defaults of ångström and picoseconds but at the moment MDAnalysis only supports those and will raise a NotImplementedError if anything else is detected.

class MDAnalysis.coordinates.TRJ.NCDFReader(filename, numatoms=None, **kwargs)[source]

Reader for AMBER NETCDF format (version 1.0).

AMBER binary trajectories are automatically recognised by the file extension ”.ncdf”.

The number of atoms (numatoms) does not have to be provided as it can be read from the trajectory. The trajectory reader can randomly access frames and therefore supports direct indexing (with 0-based frame indices) and full-feature trajectory iteration, including slicing.

Velocities are autodetected and read into the Timestep._velocities attribute.

Periodic unit cell information is detected and used to populate the Timestep.dimensions attribute. (If no unit cell is available in the trajectory, then Timestep.dimensions will return [0,0,0,0,0,0].)

Current limitations:

  • only trajectories with time in ps and lengths in Angstroem are processed
  • scale_factors are not supported (and not checked)

See also

NCDFWriter

__getitem__(frame)[source]

Return the Timestep corresponding to frame.

If frame is a integer then the corresponding frame is returned. Negative numbers are counted from the end.

If frame is a slice then an iterator is returned that allows iteration over that part of the trajectory.

Note

frame is a 0-based frame index.

__iter__()[source]

Iterate over the whole trajectory

Writer(filename, **kwargs)[source]

Returns a NCDFWriter for filename with the same parameters as this NCDF.

All values can be changed through keyword arguments.

Arguments:
filename

filename of the output NCDF trajectory

Keywords:
numatoms

number of atoms

delta

length of one timestep in picoseconds

remarks

string that is stored in the title field

Returns:

NCDFWriter

close()[source]

Close trajectory; any further access will raise an IOError

class MDAnalysis.coordinates.TRJ.NCDFWriter(filename, numatoms, start=0, step=1, delta=1.0, remarks=None, convert_units=None, zlib=False, cmplevel=1)[source]

Writer for AMBER NETCDF format (version 1.0).

AMBER binary trajectories are automatically recognised by the file extension ”.ncdf”.

Velocities are written out if they are detected in the input Timestep. The trajectories are always written with ångström for the lengths and picoseconds for the time (and hence Å/ps for velocities).

Unit cell information is written if available.

See also

NCDFReader

Create a new NCDFWriter

Arguments:
filename

name of output file

numatoms

number of atoms in trajectory file

Keywords:
start

starting timestep

step

skip between subsequent timesteps

delta

timestep

convert_units

True: units are converted to the AMBER base format; None selects the value of MDAnalysis.core.flags [‘convert_lengths’]. (see Flags)

zlib

compress data [False]

cmplevel

compression level (1-9) [1]

is_periodic(ts=None)[source]

Return True if Timestep ts contains a valid simulation box

write_next_timestep(ts=None)[source]

write a new timestep to the trj file

ts is a Timestep instance containing coordinates to be written to trajectory file