1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 from copy import deepcopy
25 import inspect
26 from numpy import ndarray
27 from os import sep
28 from re import search
29 from tempfile import mktemp
30
31
32 from base_classes import SystemTestCase
33 from data import Relax_data_store; ds = Relax_data_store()
34 import dep_check
35 from status import Status; status = Status()
36
37
38 -class Bmrb(SystemTestCase):
39 """TestCase class for functional tests of the reading and writing of BMRB STAR formatted files."""
40
41 - def __init__(self, methodName='runTest'):
42 """Skip the tests if bmrblib is not installed.
43
44 @keyword methodName: The name of the test.
45 @type methodName: str
46 """
47
48
49 if not dep_check.bmrblib_module:
50
51 status.skipped_tests.append([methodName, 'Bmrblib', self._skip_type])
52
53
54 super(Bmrb, self).__init__(methodName)
55
56
58 """Common set up for these system tests."""
59
60
61 ds.tmpfile = mktemp()
62
63
64 - def data_check(self, old_pipe_name='results', new_pipe_name='new', version=None):
65 """Check that all data has been successfully restored from the BMRB files."""
66
67
68 print("\n\nComparing data pipe contents:")
69
70
71 blacklist_spin = ['attached_proton', 'fixed', 'nucleus', 'proton_type', 'relax_sim_data', 'select', 'xh_vect'] + ['r_err', 'csa_err'] + ['chi2_sim', 'f_count', 'g_count', 'h_count', 'iter', 'warning'] + ['frq', 'frq_labels', 'noe_r1_table', 'remap_table', 'ri_labels', 'relax_data', 'relax_error']
72 if version == '3.0':
73 blacklist_spin = blacklist_spin + ['r', 'local_tm', 'local_tm_err']
74 blacklist_diff = []
75 blacklist_global = ['diff_tensor', 'exp_info', 'hybrid_pipes', 'mol', 'sim_number', 'sim_state'] + ['ri_ids', 'frq', 'ri_type'] + ['result_files']
76
77
78 old_pipe = ds[old_pipe_name]
79 new_pipe = ds[new_pipe_name]
80
81
82 self.assertEqual(len(old_pipe.mol), len(new_pipe.mol))
83 for i in range(len(old_pipe.mol)):
84
85 self.assertEqual(old_pipe.mol[i].name, old_pipe.mol[i].name)
86 self.assertEqual(old_pipe.mol[i].type, old_pipe.mol[i].type)
87
88
89 self.assertEqual(len(old_pipe.mol[i].res), len(new_pipe.mol[i].res))
90 for j in range(len(old_pipe.mol[i].res)):
91
92 self.assertEqual(old_pipe.mol[i].res[j].name, old_pipe.mol[i].res[j].name)
93 self.assertEqual(old_pipe.mol[i].res[j].num, old_pipe.mol[i].res[j].num)
94
95
96 self.assertEqual(len(old_pipe.mol[i].res[j].spin), len(new_pipe.mol[i].res[j].spin))
97 for k in range(len(old_pipe.mol[i].res[j].spin)):
98
99 if not old_pipe.mol[i].res[j].spin[k].select:
100 continue
101
102
103 self.data_cont_comp(label='Spin', cont_old=old_pipe.mol[i].res[j].spin[k], cont_new=new_pipe.mol[i].res[j].spin[k], blacklist=blacklist_spin)
104 if hasattr(old_pipe.mol[i].res[j].spin[k], 'ri_labels'):
105 self.data_ri_comp_spin(cont_old=old_pipe.mol[i].res[j].spin[k], cont_new=new_pipe.mol[i].res[j].spin[k])
106
107
108 if version != '3.0':
109 self.assert_(hasattr(new_pipe, 'diff_tensor'))
110 self.data_cont_comp(label='Diff tensor', cont_old=old_pipe.diff_tensor, cont_new=new_pipe.diff_tensor, prec=4, blacklist=blacklist_diff)
111
112
113 self.data_cont_comp(label='Global', cont_old=old_pipe, cont_new=new_pipe, blacklist=blacklist_global)
114 if hasattr(old_pipe, 'ri_ids'):
115 self.data_ri_comp_pipe(cont_old=old_pipe, cont_new=new_pipe)
116
117
118 - def data_cont_comp(self, label=None, cont_old=None, cont_new=None, prec=7, blacklist=[]):
119 """Compare the contents of the two data containers."""
120
121
122 print('')
123
124
125 names = dir(cont_old)
126 for name in names:
127
128 if search('^__', name):
129 continue
130
131
132 if name in list(cont_old.__class__.__dict__.keys()):
133 continue
134
135
136 if search('_sim$', name):
137 continue
138
139
140 if name in blacklist:
141 continue
142
143
144 print("%s object: '%s'" % (label, name))
145
146
147 obj_old = getattr(cont_old, name)
148 obj_new = getattr(cont_new, name)
149
150
151 if inspect.isfunction(obj_old) or inspect.ismethod(obj_old):
152 continue
153
154
155 self.assert_(hasattr(cont_new, name))
156
157
158 if (isinstance(obj_old, list) or isinstance(obj_old, ndarray)):
159 self.assertEqual(len(obj_old), len(obj_new))
160
161
162 if (isinstance(obj_old[0], list) or isinstance(obj_old[0], ndarray)):
163 for i in range(len(obj_old)):
164 for j in range(len(obj_old[i])):
165 if isinstance(obj_old[i][j], float):
166 self.assertAlmostEqual(obj_old[i][j], obj_new[i][j], prec)
167 else:
168 self.assertEqual(obj_old[i][j], obj_new[i][j])
169
170
171 else:
172 for i in range(len(obj_old)):
173 if isinstance(obj_old[i], float):
174 self.assertAlmostEqual(obj_old[i], obj_new[i], prec)
175 else:
176 self.assertEqual(obj_old[i], obj_new[i])
177
178
179 elif isinstance(obj_old, float):
180 self.assertAlmostEqual(obj_old, obj_new, prec)
181
182
183 else:
184 self.assertEqual(obj_old, obj_new)
185
186
188 """Compare the contents of the two pipe data containers."""
189
190
191 for name in ['frq', 'ri_ids', 'ri_type']:
192 self.assert_(hasattr(cont_new, name))
193
194
195 old_ids = deepcopy(cont_old.ri_ids)
196 new_ids = deepcopy(cont_new.ri_ids)
197 old_ids.sort()
198 new_ids.sort()
199 self.assertEqual(old_ids, new_ids)
200
201
202 for ri_id in old_ids:
203 self.assertEqual(cont_old.frq[ri_id], cont_new.frq[ri_id])
204 self.assertEqual(cont_old.ri_type[ri_id], cont_new.ri_type[ri_id])
205
206
208 """Compare the contents of the two spin data containers."""
209
210
211 for name in ['ri_data', 'ri_data_err']:
212 self.assert_(hasattr(cont_new, name))
213
214
215 old_ids = cont_old.ri_data.keys()
216 new_ids = cont_new.ri_data.keys()
217 old_ids.sort()
218 new_ids.sort()
219 self.assertEqual(old_ids, new_ids)
220
221
222 for ri_id in old_ids:
223 self.assertEqual(cont_old.ri_data[ri_id], cont_new.ri_data[ri_id])
224 self.assertEqual(cont_old.ri_data_err[ri_id], cont_new.ri_data_err[ri_id])
225
226
228 """Write and then read a BRMB STAR formatted file containing model-free results."""
229
230
231 ds.version = '3.0'
232
233
234 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'bmrb_rw.py')
235
236
237 self.data_check(version='3.0')
238
239
241 """Write and then read a BRMB STAR formatted file containing model-free results."""
242
243
244 ds.version = '3.1'
245
246
247 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'bmrb_rw.py')
248
249
250 self.data_check(version='3.1')
251