parmed.amber.netcdffiles module

This module contains classes for reading and writing Amber NetCDF-style files, including both restarts and trajectories. The NetCDF engine used here is pulled from the scipy distribution, and depends only on numpy. It is available through parmed.utils.netcdf.

This module contains objects relevant to Amber NetCDF files. The use() function is responsible for selecting the API based on a default choice or user-selection (the latter is really only helpful for development to ensure that all packages work correctly—there is no difference from a user perspective). ALL NetCDF-file manipulation that the parmed/amber package does should be contained in this module.

class parmed.amber.netcdffiles.NetCDFRestart(fname, mode='r')[source]

Bases: object

Class to read or write NetCDF restart files

Attributes
box
cell_angles
cell_lengths
coordinates
remd_dimtype
remd_indices
temp0
time
velocities

Methods

id_format(filename)

Identifies the file type as an Amber NetCDF restart file

open_new(fname, natom, box, vels[, title, …])

Opens a new NetCDF file and sets the attributes

open_old(fname)

Opens the NetCDF file and sets the global attributes that the file sets

parse(fname)

Opens the NetCDF file and sets the global attributes that the file sets

close

flush

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

Identifies the file type as an Amber NetCDF restart file

Parameters
filenamestr

Name of the file to check format for

Returns
is_fmtbool

True if it is an Amber NetCDF restart file. False otherwise

Notes

Remote NetCDF files cannot be loaded

classmethod open_new(fname, natom, box, vels, title='', remd=None, temp=None, remd_dimtypes=None)[source]

Opens a new NetCDF file and sets the attributes

Parameters
fnamestr

Name of the new file to open (overwritten)

natomint

The number of atoms in the system

boxbool

Whether unit cell information is written or not

velsbool

Whether velocity information is written or not

titlestr=’’

The title to write to the NetCDF restart file

remdstr=None

None – No REMD information is written ‘T[emperature]’ – target temperature (or pH) will be written ‘M[ulti-D]’ – remd_dimtypes will be written

remd_dimtypesiterable of int=None

Array of exchange types for each group. The length will be the REMD dimension (if remd above is “M[ulti-D]”)

Notes

remd is case-insensitive, and done based on first-letter matching

classmethod open_old(fname)[source]

Opens the NetCDF file and sets the global attributes that the file sets

Parameters
fnamestr

Name of the file to read

classmethod parse(fname)

Opens the NetCDF file and sets the global attributes that the file sets

Parameters
fnamestr

Name of the file to read

property remd_dimtype
property remd_indices
property temp0
property time
property velocities
class parmed.amber.netcdffiles.NetCDFTraj(fname, mode='r')[source]

Bases: object

Class to read or write NetCDF restart files

Parameters
fnamestr

Name of the file to open

modestr
Mode to open in:
  • ‘w’ means write-mode

  • ‘r’ means read-mode

Notes

You should use the open_new and open_old alternative constructors instead of the default constructor

Attributes
box
cell_lengths_angles
coordinates
forces
remd_dimtype
remd_indices
temp0
time
velocities

Methods

add_box(lengths[, angles])

Adds a new cell length and angle frame to the end of a NetCDF trajectory.

add_cell_lengths_angles(lengths[, angles])

Adds a new cell length and angle frame to the end of a NetCDF trajectory.

add_coordinates(stuff)

Adds a new coordinate frame to the end of a NetCDF trajectory.

add_forces(stuff)

Adds a new coordinate frame to the end of a NetCDF trajectory.

add_remd_indices(stuff)

Add REMD indices to the current frame of the NetCDF file

add_temp0(stuff)

The temperature to add to the current frame of the NetCDF file

add_time(stuff)

Adds the time to the current frame of the NetCDF file

add_velocities(stuff)

Adds a new velocities frame to the end of a NetCDF trajectory.

close()

Closes the NetCDF file

id_format(filename)

Identifies the file type as an Amber NetCDF trajectory file

open_new(fname, natom, box[, crds, vels, …])

Opens a new NetCDF file and sets the attributes

open_old(fname)

Opens the NetCDF file and sets the global attributes that the file sets

flush

add_box(lengths, angles=None)

Adds a new cell length and angle frame to the end of a NetCDF trajectory. This should only be called on objects created with the “open_new” constructor.

Parameters
lengthsarray of 3 (or 6) floats (or Quantities)

This should be a 1-D array of 3 or 6 elements. If 6 elements, angles should be None (below) and the first 3 elements are the box lengths (angstroms) and the last 3 are the box angles (degrees).

angles3-item iterable = None

These are the box angles (if lengths contains only 3 elements) in degrees. Must be a 1-D array of 3 elements or None if lengths includes angles as well.

add_cell_lengths_angles(lengths, angles=None)[source]

Adds a new cell length and angle frame to the end of a NetCDF trajectory. This should only be called on objects created with the “open_new” constructor.

Parameters
lengthsarray of 3 (or 6) floats (or Quantities)

This should be a 1-D array of 3 or 6 elements. If 6 elements, angles should be None (below) and the first 3 elements are the box lengths (angstroms) and the last 3 are the box angles (degrees).

angles3-item iterable = None

These are the box angles (if lengths contains only 3 elements) in degrees. Must be a 1-D array of 3 elements or None if lengths includes angles as well.

add_coordinates(stuff)[source]

Adds a new coordinate frame to the end of a NetCDF trajectory. This should only be called on objects created with the “open_new” constructor.

Parameters
stuffiterable of floats or distance Quantity

This array of floats is converted into a numpy array of shape (natom, 3). It can be passed either in the 2-D format of [ [x1, y1, z1], [x2, y2, z2], … ] or in the 1-D format of [x1, y1, z1, x2, y2, z2, … ].

add_forces(stuff)[source]

Adds a new coordinate frame to the end of a NetCDF trajectory. This should only be called on objects created with the “open_new” constructor.

Parameters
stuffiterable of floats or energy/distance Quantity

This array of floats is converted into a numpy array of shape (natom, 3). It can be passed either in the 2-D format of [ [x1, y1, z1], [x2, y2, z2], … ] or in the 1-D format of [x1, y1, z1, x2, y2, z2, … ].

add_remd_indices(stuff)[source]

Add REMD indices to the current frame of the NetCDF file

Parameters
stuffiterable of int

The indices in each REMD dimension

add_temp0(stuff)[source]

The temperature to add to the current frame of the NetCDF file

Parameters
stufffloat or temperature Quantity

The temperature to add to the current NetCDF file

add_time(stuff)[source]

Adds the time to the current frame of the NetCDF file

Parameters
stufffloat or time-dimension Quantity

The time to add to the current frame

add_velocities(stuff)[source]

Adds a new velocities frame to the end of a NetCDF trajectory. This should only be called on objects created with the “open_new” constructor.

Parameters
stuffiterable of floats or distance/time Quantity

This array of floats is converted into a numpy array of shape (natom, 3). It can be passed either in the 2-D format of [ [x1, y1, z1], [x2, y2, z2], … ] or in the 1-D format of [x1, y1, z1, x2, y2, z2, … ].

property box
property cell_lengths_angles
close()[source]

Closes the NetCDF file

property coordinates
flush()[source]
property forces
static id_format(filename)[source]

Identifies the file type as an Amber NetCDF trajectory file

Parameters
filenamestr

Name of the file to check format for

Returns
is_fmtbool

True if it is an Amber NetCDF trajectory file. False otherwise

Notes

Remote NetCDF files cannot be loaded

classmethod open_new(fname, natom, box, crds=True, vels=False, frcs=False, remd=None, remd_dimension=None, title='')[source]

Opens a new NetCDF file and sets the attributes

Parameters
fnamestr

Name of the new file to open (overwritten)

natomint

Number of atoms in the restart

boxbool

Indicates if cell lengths and angles are written to the NetCDF file

crdsbool=True

Indicates if coordinates are written to the NetCDF file

velsbool=False

Indicates if velocities are written to the NetCDF file

frcsbool=False

Indicates if forces are written to the NetCDF file

remdstr=None

‘T[emperature]’ if replica temperature is written ‘M[ulti]’ if Multi-D REMD information is written None if no REMD information is written

remd_dimensionint=None

If remd above is ‘M[ulti]’, this is how many REMD dimensions exist

titlestr=’’

The title of the NetCDF trajectory file

classmethod open_old(fname)[source]

Opens the NetCDF file and sets the global attributes that the file sets

Parameters
fnamestr

File name of the trajectory to open. It must exist

property remd_dimtype
property remd_indices
property temp0
property time
property velocities