mrc — the MRC/CCP4 volumetric data format

Added in version 0.7.0.

Reading of MRC/CCP4 volumetric files (MRC2014 file format) using the mrcfile library [Burnley2017].

References

[Burnley2017]

Burnley T, Palmer C and Winn M (2017) Recent developments in the CCP-EM software suite. Acta Cryst. D73:469-477. doi: 10.1107/S2059798317007859

Classes

class gridData.mrc.MRC(filename=None, assume_volumetric=False)[source]

Represent a MRC/CCP4 file.

Load MRC/CCP4 2014 3D volumetric data with the mrcfile library.

Parameters:
  • filename (str (optional)) – input file (or stream), can be compressed

  • assume_volumetric (bool (optional)) –

    If False (default), check the file header to determine whether the data in grid is a 3D volume. If True, assume grid is volumetric.

    Added in version 1.1.0.

Raises:

ValueError – If the unit cell is not orthorhombic or if the data are not volumetric.

header

Header data from the MRC file as a numpy record array.

Type:

numpy.recarray

array

Data as a 3-dimensional array where axis 0 corresponds to X, axis 1 to Y, and axis 2 to Z. This order is always enforced, regardless of the order in the mrc file.

Type:

numpy.ndarray

delta

Diagonal matrix with the voxel size in X, Y, and Z direction (taken from the mrcfile.mrcfile.voxel_size attribute)

Type:

numpy.ndarray

origin

numpy array with coordinates of the coordinate system origin (computed from header.origin, the offsets header.origin.nxstart, header.origin.nystart, header.origin.nzstart and the spacing delta)

Type:

numpy.ndarray

rank

The integer 3, denoting that only 3D maps are read.

Type:

int

Notes

  • Only volumetric (3D) densities are read.

  • Only orthorhombic unitcells supported (other raise ValueError)

  • Reading and writing are supported.

Added in version 0.7.0.

property edges

Edges of the grid cells, origin at centre of 0,0,0 grid cell.

Only works for regular, orthonormal grids.

classmethod from_grid(grid, **kwargs)[source]

Create MRC object from a Grid.

If the Grid was originally created from an mrcfile (and thus has the Grid._mrc_header attribute), the MRC header will be copied into the returned MRC instance.

Parameters:
  • grid (Grid) – Grid object to convert

  • **kwargs – Additional keyword arguments (currently unused)

Returns:

MRC wrapper object

Return type:

MRC

Added in version 1.2.0.

histogramdd()[source]

Return array data as (edges,grid), i.e. a numpy nD histogram.

property native

Return a native MrcInterpreter object.

The object is MrcObject that is connected to a stream. It is implemented as a managed property and regenerated whenever native is used. In order to re-use the object, assign it to a variable:

mrc = gdfMRC.native

In order to write to a file, open the file and assign it to the _iostream attribute and call the flush() method:

mrc = gdfMRC.native   # important: assign to variable mrc!
with open("new.mrc", "wb") as f:
   mrc._iostream = f
   mrc.flush()
Returns:

  • mrcfile.mrcinterpreter.MrcInterpreter – Native mrcfile object

  • SeeAlso

  • ——-

  • write

Added in version 1.2.0.

read(filename, assume_volumetric=False)[source]

Populate the instance from the MRC/CCP4 file filename.

property shape

Shape of the array

write(filename)[source]

Write grid data to MRC/CCP4 file format.

Parameters:

filename (str) – Output filename for the MRC file

Notes

The data array should be in xyz order (axis 0=X, axis 1=Y, axis 2=Z).

If the MRC object was created by reading an existing file, the original header information (including mapc, mapr, maps ordering) is preserved. Otherwise, standard ordering (mapc=1, mapr=2, maps=3) is used.

Currently, only uncompressed files are supported for writing. (For reading, gzip and bzip2-compressed files are supported.)

Added in version 1.1.0.