Skip to content

Commit

Permalink
additional tests for mrc
Browse files Browse the repository at this point in the history
- test mrc ValueError for triclinic boxes with EMD 3001
- test direct file init and read() on empty class
  • Loading branch information
orbeckst committed Dec 30, 2021
1 parent 820e09f commit 4930658
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gridData/mrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def read(self, filename):
if filename is not None:
self.filename = filename
with mrcfile.open(filename) as mrc:
if not mrc.is_volume():
if not mrc.is_volume(): #pragma: no cover
raise ValueError(
"MRC file {} is not a volumetric density.".format(filename))
self.header = h = mrc.header.copy()
Expand Down
Binary file added gridData/tests/datafiles/EMD-3001.map.bz2
Binary file not shown.
2 changes: 2 additions & 0 deletions gridData/tests/datafiles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# from http://www.ebi.ac.uk/pdbe/coordinates/files/1jzv.ccp4
# (see issue #57)
CCP4_1JZV = resource_filename(__name__, '1jzv.ccp4')
# from https://github.com/ccpem/mrcfile/blob/master/tests/test_data/EMD-3001.map.bz2
MRC_EMD3001 = resource_filename(__name__, 'EMD-3001.map.bz2')
# water density around M2 TM helices of nAChR from MD simulations
# [O. Beckstein and M. S. P. Sansom. Physical Biology 3(2):147-159, 2006]
gOpenMol = resource_filename(__name__, 'nAChR_M2_water.plt')
23 changes: 21 additions & 2 deletions gridData/tests/test_mrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,31 @@
from . import datafiles

@pytest.fixture(scope="module")
def g():
def g1():
return Grid(datafiles.CCP4, file_format="MRC")

def test_ccp4(g):
@pytest.fixture(scope="module")
def g2():
data = mrc.MRC()
data.read(datafiles.CCP4)
grid, edges = data.histogramdd()
return Grid(grid=grid, edges=edges)

def test_ccp4_Grid(g1):
_test_ccp4(g1)

def test_ccp4_mrc(g2):
_test_ccp4(g2)

def _test_ccp4(g):
POINTS = 192
assert_equal(g.grid.flat, np.arange(1, POINTS+1))
assert_equal(g.grid.size, POINTS)
assert_almost_equal(g.delta, [3./4, .5, 2./3])
assert_equal(g.origin, np.zeros(3))



@pytest.fixture(scope="module")
def ccp4data():
return mrc.MRC(datafiles.CCP4_1JZV)
Expand Down Expand Up @@ -76,3 +90,8 @@ def test_ccp4_read_header(ccp4data, name, value):
else:
assert_equal(ccp4data.header[name], value)

def test_triclinic_ValueError():
with pytest.raises(ValueError,
match="Only orthorhombic unitcells are currently "
"supported, not"):
Grid(datafiles.MRC_EMD3001, file_format="MRC")

0 comments on commit 4930658

Please sign in to comment.