Skip to content

Commit 3b0bccf

Browse files
authored
Merge pull request #60 from MDAnalysis/ccp4-int-57
fix reading of nrstart and ncstart in CCP4 format
2 parents ecd4d01 + 5f7d522 commit 3b0bccf

5 files changed

Lines changed: 58 additions & 3 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The rules for this file:
2323
* Fixed reading in DX files containing scientific notation (PR #52)
2424
* Added missing floordivision to Grid (PR #53)
2525
* fix test on ARM (#51)
26+
* fix incorrect reading of ncstart and nrstart in CCP4 (#57)
2627

2728
Changes (do not affect user)
2829

gridData/CCP4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class CCP4(object):
177177
3: 'Transform of Complex Integer*2',
178178
4: 'Transform of Complex Reals',
179179
5: '0',
180-
}), Record('ncstart', 'I'), Record('nrstart', 'I'),
180+
}), Record('ncstart', 'i'), Record('nrstart', 'i'),
181181
Record('nsstart', 'I'), Record('nx', 'I'), # Number of gridpoints.
182182
Record('ny', 'I'), Record('nz', 'I'), Record('xlen', 'f'), # Angstroms.
183183
Record('ylen', 'f'), Record('zlen', 'f'), Record('alpha', 'f'), # Degrees.

gridData/tests/datafiles/1jzv.ccp4

1.95 MB
Binary file not shown.

gridData/tests/datafiles/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
DX = resource_filename(__name__, 'test.dx')
88
CCP4 = resource_filename(__name__, 'test.ccp4')
9+
# from http://www.ebi.ac.uk/pdbe/coordinates/files/1jzv.ccp4
10+
# (see issue #57)
11+
CCP4_1JZV = resource_filename(__name__, '1jzv.ccp4')
912
# water density around M2 TM helices of nAChR from MD simulations
1013
# [O. Beckstein and M. S. P. Sansom. Physical Biology 3(2):147-159, 2006]
1114
gOpenMol = resource_filename(__name__, 'nAChR_M2_water.plt')

gridData/tests/test_ccp4.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import absolute_import, division
22

3+
import pytest
4+
35
import numpy as np
46
from numpy.testing import (assert_almost_equal,
57
assert_equal)
@@ -8,14 +10,63 @@
810

911
from . import datafiles
1012

11-
def test_ccp4():
12-
g = Grid(datafiles.CCP4)
13+
@pytest.fixture(scope="module")
14+
def g():
15+
return Grid(datafiles.CCP4)
16+
17+
def test_ccp4(g):
1318
POINTS = 192
1419
assert_equal(g.grid.flat, np.arange(1, POINTS+1))
1520
assert_equal(g.grid.size, POINTS)
1621
assert_almost_equal(g.delta, [3./4, .5, 2./3])
1722
assert_equal(g.origin, np.zeros(3))
1823

24+
25+
@pytest.fixture(scope="module")
26+
def ccp4data():
27+
return CCP4.CCP4(datafiles.CCP4_1JZV)
28+
29+
@pytest.mark.parametrize('name,value', [
30+
('nc', 96),
31+
('nr', 76),
32+
('ns', 70),
33+
('mode', 2),
34+
('ncstart', -4),
35+
('nrstart', -23),
36+
('nsstart', 102),
37+
('nx', 84),
38+
('ny', 84),
39+
('nz', 160),
40+
('xlen', 45.79999923706055),
41+
('ylen', 45.79999923706055),
42+
('zlen', 89.6500015258789),
43+
('alpha', 90.0),
44+
('beta', 90.0),
45+
('gamma', 90.0),
46+
('mapc', 2),
47+
('mapr', 1),
48+
('maps', 3),
49+
('amin', -0.9930942058563232),
50+
('amax', 9.050403594970703),
51+
('amean', -0.0005801090155728161),
52+
('ispg', 92),
53+
('nsymbt', 640),
54+
('lskflg', 0),
55+
('bsaflag', '@'),
56+
('skwmat', None),
57+
('skwtrn', None),
58+
('endianness', 'little'),
59+
('arms', 0.4034915268421173),
60+
('nlabl', 1),
61+
('label', ' Map from fft '),
62+
])
63+
def test_ccp4_integer_reading(ccp4data, name, value):
64+
if type(value) is float:
65+
assert_almost_equal(ccp4data.header[name], value, decimal=6)
66+
else:
67+
assert_equal(ccp4data.header[name], value)
68+
69+
1970
def test_byteorder():
2071
with open(datafiles.CCP4, 'rb') as ccp4file:
2172
flag = CCP4.CCP4._detect_byteorder(ccp4file)

0 commit comments

Comments
 (0)