-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest_ccp4.py
81 lines (70 loc) · 2.2 KB
/
test_ccp4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from __future__ import absolute_import, division
import pytest
import numpy as np
from numpy.testing import (assert_almost_equal,
assert_equal)
from gridData import Grid, CCP4
from . import datafiles
@pytest.fixture(scope="module")
def g():
with pytest.warns(DeprecationWarning,
match="CCP4.CCP4 is being replaced by mrc.MRC and will be removed"):
ccp4 = CCP4.CCP4()
ccp4.read(datafiles.CCP4)
grid, edges = ccp4.histogramdd()
return Grid(grid=grid, edges=edges)
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():
with pytest.warns(DeprecationWarning,
match="CCP4.CCP4 is being replaced by mrc.MRC and will be removed"):
ccp4 = CCP4.CCP4(datafiles.CCP4_1JZV)
return ccp4
@pytest.mark.parametrize('name,value', [
('nc', 96),
('nr', 76),
('ns', 70),
('mode', 2),
('ncstart', -4),
('nrstart', -23),
('nsstart', 102),
('nx', 84),
('ny', 84),
('nz', 160),
('xlen', 45.79999923706055),
('ylen', 45.79999923706055),
('zlen', 89.6500015258789),
('alpha', 90.0),
('beta', 90.0),
('gamma', 90.0),
('mapc', 2),
('mapr', 1),
('maps', 3),
('amin', -0.9930942058563232),
('amax', 9.050403594970703),
('amean', -0.0005801090155728161),
('ispg', 92),
('nsymbt', 640),
('lskflg', 0),
('bsaflag', '@'),
('skwmat', None),
('skwtrn', None),
('endianness', 'little'),
('arms', 0.4034915268421173),
('nlabl', 1),
('label', ' Map from fft '),
])
def test_ccp4_read_header(ccp4data, name, value):
if type(value) is float:
assert_almost_equal(ccp4data.header[name], value, decimal=6)
else:
assert_equal(ccp4data.header[name], value)
def test_byteorder():
with open(datafiles.CCP4, 'rb') as ccp4file:
flag = CCP4.CCP4._detect_byteorder(ccp4file)
assert flag in ("@", "=", "<"), "flag {} is not '<'".format(flag)