parmed.amber.asciicrd module

This is a pure-python module for reading and writing ASCII Amber structure files, like trajectories and restarts. Because it is pure-python and formatted-ASCII, parsing and writing these files are expected to be slow. Binary alternatives (like DCD and NetCDF, provided in netcdffiles.py) are strongly encouraged, but these are provided for more complete compatibility and for instances where the prequisites may not be installed.

class parmed.amber.asciicrd.AmberAsciiRestart(fname, mode='r', natom=0, hasbox=None, title=None, time=0.0)[source]

Bases: parmed.amber.asciicrd._AmberAsciiCoordinateFile

Parser for the Amber ASCII inpcrd/restart file format

Parameters
fnamestr

File name to open

modestr={‘r’, ‘w’}

Whether to open this file for ‘r’eading or ‘w’riting

natomint, optional

Number of atoms in the system (necessary when mode=’w’)

hasboxbool, optional

Does the system have PBCs? Necessary when mode=’w’

titlestr, optional

Title to write to a new trajectory (when mode=’w’)

timefloat, optional

The time to write to the restart file in ps. Default is 0.

Attributes
box

Combined cell lengths and cell angles

cell_angles
cell_lengths
coordinates
positions
velocities

Methods

close()

Close the open file handler

id_format(filename)

Identifies the file type as an Amber restart/inpcrd file

parse

CRDS_PER_LINE = 6
DEFAULT_TITLE = 'restart created by ParmEd'
property box

Combined cell lengths and cell angles

property cell_angles
property cell_lengths
property coordinates
static id_format(filename)[source]

Identifies the file type as an Amber restart/inpcrd file

Parameters
filenamestr

Name of the file to check format for

Returns
is_fmtbool

True if it is an Amber restart/inpcrd file. False otherwise

classmethod parse(filename, structure=False)[source]
property velocities
class parmed.amber.asciicrd.AmberMdcrd(fname, natom, hasbox, mode='r', title=None)[source]

Bases: parmed.amber.asciicrd._AmberAsciiCoordinateFile

A class to parse Amber ASCII trajectory files. This is much slower than parsing NetCDF files (or the equivalent parsing done in a compiled language like C or C++). For large trajectories, this may be significant.

Attributes
box
coordinates
frame
positions

Methods

add_box(stuff)

Prints ‘stuff’ (which must be a 3-element list, array.array, tuple, or np.ndarray) as the box lengths for this frame

add_coordinates(stuff)

Prints ‘stuff’ (which must be either an iterable of 3*natom or have an attribute ‘flatten’ that converts it into an iterable of 3*natom) to the open file handler.

close()

Close the open file handler

id_format(filename)

Identifies the file type as an Amber mdcrd file

CRDS_PER_LINE = 10
DEFAULT_TITLE = 'trajectory created by ParmEd'
add_box(stuff)[source]

Prints ‘stuff’ (which must be a 3-element list, array.array, tuple, or np.ndarray) as the box lengths for this frame

Parameters
stuffarray or iterable

This must be an iterable of length 3 with the box lengths

Raises
If the coordinate file is an old one being parsed or if you are
currently expected to provide coordinates, a RuntimeError is raised.
raised. If the provided box lengths are not length 3, a ValueError is
raised.
add_coordinates(stuff)[source]

Prints ‘stuff’ (which must be either an iterable of 3*natom or have an attribute ‘flatten’ that converts it into an iterable of 3*natom) to the open file handler. Can only be called on a ‘new’ mdcrd, and adds these coordinates to the current end of the file.

Parameters
stuffarray or iterable

This must be an iterable of length 3*natom or a numpy array that can be flattened to a 3*natom-length array

Raises
If the coordinate file is an old one being parsed or if you are
currently expected to provide unit cell dimensions, a RuntimeError is
raised. If the provided coordinate data does not have length 3*natom, or
cannot be ``flatten()``ed to create a 3*natom array, a ValueError is
raised.
property box
property coordinates
extra_args = ('natom', 'hasbox')
property frame
static id_format(filename)[source]

Identifies the file type as an Amber mdcrd file

Parameters
filenamestr

Name of the file to check format for

Returns
is_fmtbool

True if it is an Amber mdcrd file. False otherwise