1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from copy import deepcopy
24 import inspect
25 from numpy import ndarray
26 from os import sep
27 from re import search
28 from tempfile import mktemp
29
30
31 from data_store import Relax_data_store; ds = Relax_data_store()
32 import dep_check
33 from lib.errors import RelaxError
34 from status import Status; status = Status()
35 from test_suite.system_tests.base_classes import SystemTestCase
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 super(Bmrb, self).__init__(methodName)
50
51
52 if not dep_check.bmrblib_module:
53
54 status.skipped_tests.append([methodName, 'Bmrblib', self._skip_type])
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'] + ['_spin_index']
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', 'interatomic', 'sim_number', 'sim_state'] + ['ri_ids', 'spectrometer_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 k_new = k
104 if i == 0 and j == 0:
105 if k == 1:
106 k_new = 2
107 elif k == 2:
108 k_new = 1
109
110
111 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_new], blacklist=blacklist_spin)
112 if hasattr(old_pipe.mol[i].res[j].spin[k], 'ri_labels'):
113 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_new])
114
115
116 if version != '3.0':
117 self.assert_(hasattr(new_pipe, 'diff_tensor'))
118 self.data_cont_comp(label='Diff tensor', cont_old=old_pipe.diff_tensor, cont_new=new_pipe.diff_tensor, prec=4, blacklist=blacklist_diff)
119
120
121 self.data_cont_comp(label='Global', cont_old=old_pipe, cont_new=new_pipe, blacklist=blacklist_global)
122 if hasattr(old_pipe, 'ri_ids'):
123 self.data_ri_comp_pipe(cont_old=old_pipe, cont_new=new_pipe)
124
125
126 - def data_cont_comp(self, label=None, cont_old=None, cont_new=None, prec=7, blacklist=[]):
127 """Compare the contents of the two data containers."""
128
129
130 print('')
131
132
133 names = dir(cont_old)
134 for name in names:
135
136 if search('^__', name):
137 continue
138
139
140 if name in list(cont_old.__class__.__dict__.keys()):
141 continue
142
143
144 if search('_sim$', name):
145 continue
146
147
148 if name in blacklist:
149 continue
150
151
152 print("%s object: '%s'" % (label, name))
153
154
155 obj_old = getattr(cont_old, name)
156 obj_new = getattr(cont_new, name)
157
158
159 if inspect.isfunction(obj_old) or inspect.ismethod(obj_old):
160 continue
161
162
163 self.assert_(hasattr(cont_new, name))
164
165
166 if (isinstance(obj_old, list) or isinstance(obj_old, ndarray)):
167 self.assertEqual(len(obj_old), len(obj_new))
168
169
170 if (isinstance(obj_old[0], list) or isinstance(obj_old[0], ndarray)):
171 for i in range(len(obj_old)):
172 for j in range(len(obj_old[i])):
173 if isinstance(obj_old[i][j], float):
174 self.assertAlmostEqual(obj_old[i][j], obj_new[i][j], prec)
175 else:
176 self.assertEqual(obj_old[i][j], obj_new[i][j])
177
178
179 else:
180 for i in range(len(obj_old)):
181 if isinstance(obj_old[i], float):
182 self.assertAlmostEqual(obj_old[i], obj_new[i], prec)
183 else:
184 self.assertEqual(obj_old[i], obj_new[i])
185
186
187 elif isinstance(obj_old, float):
188 self.assertAlmostEqual(obj_old, obj_new, prec)
189
190
191 else:
192 self.assertEqual(obj_old, obj_new)
193
194
196 """Compare the contents of the two pipe data containers."""
197
198
199 for name in ['spectrometer_frq', 'ri_ids', 'ri_type']:
200 self.assert_(hasattr(cont_new, name))
201
202
203 old_ids = deepcopy(cont_old.ri_ids)
204 new_ids = deepcopy(cont_new.ri_ids)
205 old_ids.sort()
206 new_ids.sort()
207 self.assertEqual(old_ids, new_ids)
208
209
210 for ri_id in old_ids:
211 self.assertEqual(cont_old.spectrometer_frq[ri_id], cont_new.spectrometer_frq[ri_id])
212 self.assertEqual(cont_old.ri_type[ri_id], cont_new.ri_type[ri_id])
213
214
216 """Compare the contents of the two spin data containers."""
217
218
219 for name in ['ri_data', 'ri_data_err']:
220 self.assert_(hasattr(cont_new, name))
221
222
223 old_ids = cont_old.ri_data.keys()
224 new_ids = cont_new.ri_data.keys()
225 old_ids.sort()
226 new_ids.sort()
227 self.assertEqual(old_ids, new_ids)
228
229
230 for ri_id in old_ids:
231 self.assertEqual(cont_old.ri_data[ri_id], cont_new.ri_data[ri_id])
232 self.assertEqual(cont_old.ri_data_err[ri_id], cont_new.ri_data_err[ri_id])
233
234
236 """Catch U{bug #20471<https://web.archive.org/web/https://gna.org/bugs/?20471>}, with structural data present prior to a bmrb.read call."""
237
238
239 self.interpreter.pipe.create('test', 'mf')
240
241
242 path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'structures'
243 self.interpreter.structure.read_pdb(file='1RTE_H_trunc.pdb', dir=path, read_mol=None, set_mol_name=None, read_model=None, set_model_num=None, alt_loc='A')
244
245
246 self.interpreter.structure.load_spins(spin_id='@N', ave_pos=True)
247 self.interpreter.structure.load_spins(spin_id='@H', ave_pos=True)
248 self.interpreter.spin.isotope(isotope='15N', spin_id='@N', force=False)
249 self.interpreter.spin.isotope(isotope='1H', spin_id='@H', force=False)
250
251
252 path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'bmrb'
253 self.assertRaises(RelaxError, self.interpreter.bmrb.read, file='17226.txt', dir=path, version=None, sample_conditions=None)
254
255
257 """Write and then read a BRMB STAR formatted file containing model-free results."""
258
259
260 ds.version = '3.0'
261
262
263 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'bmrb_rw.py')
264
265
266 self.data_check(version='3.0')
267
268
270 """Write and then read a BRMB STAR formatted file containing model-free results."""
271
272
273 ds.version = '3.1'
274
275
276 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'bmrb_rw.py')
277
278
279 self.data_check(version='3.1')
280