Skip to content

Commit

Permalink
addressed comments by @IAlibay and @tluchko
Browse files Browse the repository at this point in the history
- add versionchanged noting use of MRC instead of CCP4
- add undocumented Grid._mrc_header for storing the MRC header
- add tests (for _mrc_header and generally checking that a correct
  Grid object is built from the MRC data)
- code/doc cleanup
  • Loading branch information
orbeckst committed Feb 19, 2022
1 parent a6b2519 commit 51ed84b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions gridData/CCP4.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class CCP4(object):
* index ordering besides standard column-major and row-major
* non-standard fields, such any in filed in future use block
.. deprecated:: 0.7.0
Use :class:`gridData.mrc.MRC` instead. This class will be removed in 0.8.0.
"""
Expand Down
7 changes: 7 additions & 0 deletions gridData/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ def __init__(self, grid=None, edges=None, origin=None, delta=None,
.. versionchanged:: 0.5.0
New *file_format* keyword argument.
.. versionchanged:: 0.7.0
CCP4 files are now read with :class:`gridData.mrc.MRC` and not anymore
with the deprecated/buggy `ccp4.CCP4`
"""
# file formats are guess from extension == lower case key
self._exporters = {
Expand Down Expand Up @@ -477,6 +481,9 @@ def _load_mrc(self, filename):
mrcfile = mrc.MRC(filename)
grid, edges = mrcfile.histogramdd()
self._load(grid=grid, edges=edges, metadata=self.metadata)
# Store header for access from Grid object (undocumented)
# https://github.com/MDAnalysis/GridDataFormats/pull/100#discussion_r782604833
self._mrc_header = mrcfile.header.copy()

def _load_dx(self, filename):
"""Initializes Grid from a OpenDX file."""
Expand Down
2 changes: 0 additions & 2 deletions gridData/mrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
from __future__ import absolute_import
from six.moves import range

import warnings

import numpy as np
import mrcfile

Expand Down
20 changes: 20 additions & 0 deletions gridData/tests/test_mrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,23 @@ def test_triclinic_ValueError():
"supported, not"):
Grid(datafiles.MRC_EMD3001, file_format="MRC")

class TestGridMRC():
@pytest.fixture(scope="class")
def grid(self):
return Grid(datafiles.CCP4_1JZV)

def test_shape(self, grid, ccp4data):
assert_equal(grid.grid.shape, ccp4data.shape)

def test_mrc_header(self, grid, ccp4data):
# undocumented MRC header in Grid
assert grid._mrc_header == ccp4data.header

def test_delta(self, grid, ccp4data):
assert_almost_equal(grid.delta, np.diag(ccp4data.delta))

def test_origin(self, grid, ccp4data):
assert_almost_equal(grid.origin, ccp4data.origin)

def test_data(self, grid, ccp4data):
assert_almost_equal(grid.grid, ccp4data.array)

0 comments on commit 51ed84b

Please sign in to comment.