mdtraj.formats.AmberNetCDFRestartFile

class mdtraj.formats.AmberNetCDFRestartFile(filename, mode='r', force_overwrite=False)

Interface for reading and writing AMBER NetCDF files. This is a file-like object, that supports both reading and writing depending on the mode flag. It implements the context manager protocol, so you can also use it with the python ‘with’ statement.

Parameters:

filename : str

The name of the file to open

mode : {‘r’, ‘w’}, default=’r’

The mode in which to open the file. Valid options are ‘r’ or ‘w’ for ‘read’ or ‘write’

force_overwrite : bool, default=False

In write mode, if a file named filename already exists, clobber it and overwrite it

Attributes

n_atoms
n_frames

Methods

close()
flush()
read([atom_indices]) Read data from an AMBER NetCDF restart file
read_as_traj(topology[, atom_indices]) Read an AMBER ASCII restart file as a trajectory.
write(coordinates[, time, cell_lengths, …]) Write one frame of a MD trajectory to disk in the AMBER NetCDF restart file format.
__init__(filename, mode='r', force_overwrite=False)

Methods

__init__(filename[, mode, force_overwrite])
close()
flush()
read([atom_indices]) Read data from an AMBER NetCDF restart file
read_as_traj(topology[, atom_indices]) Read an AMBER ASCII restart file as a trajectory.
write(coordinates[, time, cell_lengths, …]) Write one frame of a MD trajectory to disk in the AMBER NetCDF restart file format.
read(atom_indices=None)

Read data from an AMBER NetCDF restart file

Parameters:

atom_indices : np.ndarray, dtype=int, optional

The specific indices of the atoms you’d like to retrieve. If not supplied, all of the atoms will be retrieved.

Returns:

coordinates : np.ndarray, shape=(1, n_atoms, 3)

The cartesian coordinates of the atoms, in units of angstroms. These files only ever contain 1 frame

time : np.ndarray, None

The time corresponding to the frame, in units of picoseconds, or None if no time information is present

cell_lengths : np.ndarray, None

The lengths (a, b, c) of the unit cell for the frame in angstroms, or None if the information is not present in the file

cell_angles : np.ndarray, None

The angles (lpha, eta, gamma) defining the unit cell for each frame, or None if the information is not present in the file.

Notes

If the file is not a NetCDF file with the appropriate convention, a TypeError is raised. If variables that are needed do not exist or if illegal values are passed in for parameters, ValueError is raised. If I/O errors occur, IOError is raised.

read_as_traj(topology, atom_indices=None)

Read an AMBER ASCII restart file as a trajectory.

Parameters:

topology : Topology

The system topology

atom_indices : array_like, optional

If not none, then read only a subset of the atoms coordinates from the file. This may be slightly slower than the standard read because it required an extra copy, but will save memory.

Returns:

trajectory : Trajectory

A trajectory object with 1 frame created from the file.

write(coordinates, time=None, cell_lengths=None, cell_angles=None)

Write one frame of a MD trajectory to disk in the AMBER NetCDF restart file format.

Parameters:

coordinates : np.ndarray, dtype=np.float32, shape=([1,] n_atoms, 3)

The cartesian coordinates of each atom, in units of angstroms. Must be only a single frame (shape can be (1,N,3) or (N,3) where N is the number of atoms)

time : array-like with 1 element or float, optional

The time corresponding to this frame. If not specified, a place holder of 0 will be written

cell_lengths : np.ndarray, dtype=np.double, shape=([1,] 3)

The lengths (a,b,c) of the unit cell for the frame in Angstroms

cell_angles : np.ndarray, dtype=np.double, shape=([1,] 3)

The angles between the unit cell vectors for the frame in Degrees

Notes

You must only have one frame to write to this file.