1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """RDC-based system tests."""
24
25
26
27 from os import sep
28 from tempfile import mkstemp
29
30
31 from data_store import Relax_data_store; ds = Relax_data_store()
32 from pipe_control.interatomic import interatomic_loop
33 from pipe_control.mol_res_spin import count_spins
34 from status import Status; status = Status()
35 from test_suite.system_tests.base_classes import SystemTestCase
36
37
38 -class Rdc(SystemTestCase):
39 """Class for testing RDC operations."""
40
42 """Test the operation of the rdc.calc_q_factors user function when no alignment tensor is present."""
43
44
45 self.interpreter.pipe.create('orig', 'N-state')
46
47
48 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep
49
50
51 self.interpreter.sequence.read(file='tb.txt', dir=dir, spin_id_col=1)
52 self.interpreter.sequence.attach_protons()
53 self.interpreter.sequence.display()
54
55
56 self.interpreter.rdc.read(align_id='tb', file='tb.txt', dir=dir, spin_id1_col=1, spin_id2_col=2, data_col=3, error_col=4)
57 self.interpreter.sequence.display()
58
59
60 for interatom in interatomic_loop():
61 if hasattr(interatom, 'rdc'):
62 if not hasattr(interatom, 'rdc_bc'):
63 interatom.rdc_bc = {}
64 interatom.rdc_bc['tb'] = interatom.rdc['tb'] + 1.0
65
66
67 self.interpreter.rdc.calc_q_factors()
68
69
71 """Test the operation of the rdc.corr_plot user function."""
72
73
74 self.interpreter.pipe.create('orig', 'N-state')
75
76
77 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep
78
79
80 self.interpreter.sequence.read(file='tb.txt', dir=dir, spin_id_col=1)
81 self.interpreter.sequence.attach_protons()
82 self.interpreter.sequence.display()
83
84
85 self.interpreter.rdc.read(align_id='tb', file='tb.txt', dir=dir, spin_id1_col=1, spin_id2_col=2, data_col=3, error_col=4)
86 self.interpreter.sequence.display()
87
88
89 for interatom in interatomic_loop():
90 if hasattr(interatom, 'rdc'):
91 if not hasattr(interatom, 'rdc_bc'):
92 interatom.rdc_bc = {}
93 interatom.rdc_bc['tb'] = interatom.rdc['tb'] + 1.0
94
95
96 ds.tmpfile_handle, ds.tmpfile = mkstemp()
97 self.interpreter.rdc.corr_plot(format='grace', title='Test', subtitle='Test2', file=ds.tmpfile, dir=None, force=True)
98
99
100 real_contents = [
101 "@version 50121",
102 "@page size 842, 595",
103 "@with g0",
104 "@ world -27.0, -27.0, 16.0, 16.0",
105 "@ view 0.15, 0.15, 1.28, 0.85",
106 "@ title \"Test\"",
107 "@ subtitle \"Test2\"",
108 "@ xaxis label \"Back-calculated RDC (Hz)\"",
109 "@ xaxis label char size 1.00",
110 "@ xaxis tick major 10",
111 "@ xaxis tick major size 0.50",
112 "@ xaxis tick major linewidth 0.5",
113 "@ xaxis tick minor ticks 9",
114 "@ xaxis tick minor linewidth 0.5",
115 "@ xaxis tick minor size 0.25",
116 "@ xaxis ticklabel char size 0.70",
117 "@ yaxis label \"Measured RDC (Hz)\"",
118 "@ yaxis label char size 1.00",
119 "@ yaxis tick major 10",
120 "@ yaxis tick major size 0.50",
121 "@ yaxis tick major linewidth 0.5",
122 "@ yaxis tick minor ticks 9",
123 "@ yaxis tick minor linewidth 0.5",
124 "@ yaxis tick minor size 0.25",
125 "@ yaxis ticklabel char size 0.70",
126 "@ legend on",
127 "@ legend 1, 0.5",
128 "@ legend box fill pattern 1",
129 "@ legend char size 1.0",
130 "@ frame linewidth 0.5",
131 "@ s0 symbol 1",
132 "@ s0 symbol size 0.45",
133 "@ s0 symbol linewidth 0.5",
134 "@ s0 errorbar size 0.5",
135 "@ s0 errorbar linewidth 0.5",
136 "@ s0 errorbar riser linewidth 0.5",
137 "@ s0 line linestyle 2",
138 "@ s1 symbol 2",
139 "@ s1 symbol size 0.45",
140 "@ s1 symbol linewidth 0.5",
141 "@ s1 errorbar size 0.5",
142 "@ s1 errorbar linewidth 0.5",
143 "@ s1 errorbar riser linewidth 0.5",
144 "@ s1 line linestyle 0",
145 "@ s1 legend \"tb\"",
146 "@target G0.S0",
147 "@type xydy",
148 " -100.000000000000000 -100.000000000000000 0.000000000000000",
149 " 100.000000000000000 100.000000000000000 0.000000000000000",
150 "&",
151 "@target G0.S1",
152 "@type xydy",
153 " -25.250195862900000 -26.250195862900000 1.000000000000000 \"#CaM:5@N-#CaM:5@H\"",
154 " 10.930817669420000 9.930817669420000 1.000000000000000 \"#CaM:6@N-#CaM:6@H\"",
155 " 8.263176141559999 7.263176141560000 1.000000000000000 \"#CaM:7@N-#CaM:7@H\"",
156 " -0.248405269810000 -1.248405269810000 0.000000000000000 \"#CaM:8@N-#CaM:8@H\"",
157 " 6.318033143340000 5.318033143340000 1.000000000000000 \"#CaM:9@N-#CaM:9@H\"",
158 " 15.036290945599999 14.036290945599999 1.000000000000000 \"#CaM:10@N-#CaM:10@H\"",
159 " 2.336525303970000 1.336525303970000 0.000000000000000 \"#CaM:11@N-#CaM:11@H\"",
160 " -0.602167028100000 -1.602167028100000 0.000000000000000 \"#CaM:12@N-#CaM:12@H\"",
161 "&",
162 ]
163
164
165 print("\nChecking the Grace file contents.")
166 file = open(ds.tmpfile)
167 lines = file.readlines()
168 file.close()
169 print(real_contents)
170 print(lines)
171 self.assertEqual(len(real_contents), len(lines))
172 for i in range(len(lines)):
173 print(lines[i][:-1])
174 self.assertEqual(real_contents[i], lines[i][:-1])
175
176
178 """Test the operation of the rdc.copy user function."""
179
180
181 self.interpreter.pipe.create('orig', 'N-state')
182
183
184 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep
185
186
187 self.interpreter.sequence.read(file='tb.txt', dir=dir, spin_id_col=1)
188 self.interpreter.sequence.attach_protons()
189 self.interpreter.sequence.display()
190
191
192 self.interpreter.rdc.read(align_id='tb', file='tb.txt', dir=dir, spin_id1_col=1, spin_id2_col=2, data_col=3, error_col=4)
193 self.interpreter.sequence.display()
194
195
196 rdcs = [ -26.2501958629, 9.93081766942, 7.26317614156, -1.24840526981, 5.31803314334, 14.0362909456, 1.33652530397, -1.6021670281]
197
198
199 self.interpreter.pipe.copy(pipe_from='orig', pipe_to='new')
200 self.interpreter.pipe.switch(pipe_name='new')
201
202
203 self.interpreter.rdc.delete()
204
205
206 self.interpreter.rdc.copy(pipe_from='orig', align_id='tb')
207
208
209 self.assertTrue(hasattr(cdp, 'align_ids'))
210 self.assertTrue('tb' in cdp.align_ids)
211 self.assertTrue(hasattr(cdp, 'rdc_ids'))
212 self.assertTrue('tb' in cdp.rdc_ids)
213 self.assertEqual(count_spins(), 16)
214 self.assertEqual(len(cdp.interatomic), 8)
215 i = 0
216 for interatom in interatomic_loop():
217 self.assertAlmostEqual(rdcs[i], interatom.rdc['tb'])
218 i += 1
219
220
222 """Test the operation of the rdc.copy user function for two data pipes with different spin system."""
223
224
225 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep
226
227
228 pipes = ['orig', 'new']
229 delete = [':6', ':11']
230 for i in range(2):
231
232 self.interpreter.pipe.create(pipes[i], 'N-state')
233
234
235 self.interpreter.sequence.read(file='tb.txt', dir=dir, spin_id_col=1)
236 self.interpreter.spin.element('N')
237
238
239 self.interpreter.residue.delete(delete[i])
240
241
242 self.interpreter.sequence.attach_protons()
243 self.interpreter.sequence.display()
244
245
246 self.interpreter.interatom.define(spin_id1='@N', spin_id2='@H')
247
248
249 print("\n\nInteratomic data containers for the 'orig' data pipe:")
250 for interatom in interatomic_loop(pipe='orig'):
251 print("'%s' '%s'" % (interatom.spin_id1, interatom.spin_id2))
252 print("\nInteratomic data containers for the 'new' data pipe:")
253 for interatom in interatomic_loop(pipe='new'):
254 print("'%s' '%s'" % (interatom.spin_id1, interatom.spin_id2))
255
256
257 self.interpreter.pipe.switch('orig')
258 self.interpreter.rdc.read(align_id='tb', file='tb.txt', dir=dir, spin_id1_col=1, spin_id2_col=2, data_col=3, error_col=4)
259
260
261 self.interpreter.rdc.copy(pipe_from='orig', pipe_to='new', align_id='tb')
262
263
264 rdcs = [
265 [ -26.2501958629, 7.26317614156, -1.24840526981, 5.31803314334, 14.0362909456, 1.33652530397, -1.6021670281],
266 [ -26.2501958629, 9.93081766942, 7.26317614156, -1.24840526981, 5.31803314334, 14.0362909456, -1.6021670281]
267 ]
268 for i in range(2):
269 print("\nChecking data pipe '%s'." % pipes[i])
270
271
272 self.assertTrue(hasattr(ds[pipes[i]], 'align_ids'))
273 self.assertTrue('tb' in ds[pipes[i]].align_ids)
274 self.assertTrue(hasattr(ds[pipes[i]], 'rdc_ids'))
275 self.assertTrue('tb' in ds[pipes[i]].rdc_ids)
276
277
278 self.assertEqual(count_spins(pipe=pipes[i]), 14)
279 self.assertEqual(len(ds[pipes[i]].interatomic), 7)
280 j = 0
281 for interatom in interatomic_loop(pipe=pipes[i]):
282
283 if i == 1 and j == 1:
284 self.assertTrue(not hasattr(interatom, 'rdc'))
285 self.assertTrue(not hasattr(interatom, 'rdc_data_types'))
286 self.assertTrue(not hasattr(interatom, 'absolute_rdc'))
287 else:
288 self.assertAlmostEqual(rdcs[i][j], interatom.rdc['tb'])
289 self.assertTrue(hasattr(interatom, 'rdc_data_types'))
290 self.assertTrue('tb' in interatom.rdc_data_types)
291 self.assertEqual(interatom.rdc_data_types['tb'], 'D')
292 self.assertTrue(hasattr(interatom, 'absolute_rdc'))
293 self.assertTrue('tb' in interatom.absolute_rdc)
294 self.assertEqual(interatom.absolute_rdc['tb'], False)
295 j += 1
296
297
299 """Test the operation of the rdc.copy user function for back-calculated values."""
300
301
302 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep
303
304
305 pipes = ['orig', 'new']
306 delete = [':6', ':11']
307 for i in range(2):
308
309 self.interpreter.pipe.create(pipes[i], 'N-state')
310
311
312 self.interpreter.sequence.read(file='tb.txt', dir=dir, spin_id_col=1)
313 self.interpreter.spin.element('N')
314
315
316 self.interpreter.residue.delete(delete[i])
317
318
319 self.interpreter.sequence.attach_protons()
320 self.interpreter.sequence.display()
321
322
323 self.interpreter.interatom.define(spin_id1='@N', spin_id2='@H')
324
325
326 print("\n\nInteratomic data containers for the 'orig' data pipe:")
327 for interatom in interatomic_loop(pipe='orig'):
328 print("'%s' '%s'" % (interatom.spin_id1, interatom.spin_id2))
329 print("\nInteratomic data containers for the 'new' data pipe:")
330 for interatom in interatomic_loop(pipe='new'):
331 print("'%s' '%s'" % (interatom.spin_id1, interatom.spin_id2))
332
333
334 self.interpreter.pipe.switch('orig')
335 self.interpreter.rdc.read(align_id='tb', file='tb.txt', dir=dir, spin_id1_col=1, spin_id2_col=2, data_col=3, error_col=4)
336
337
338 for interatom in interatomic_loop():
339 if hasattr(interatom, 'rdc'):
340 if not hasattr(interatom, 'rdc_bc'):
341 interatom.rdc_bc = {}
342 interatom.rdc_bc['tb'] = interatom.rdc['tb'] + 1.0
343
344
345 self.interpreter.rdc.copy(pipe_from='orig', pipe_to='new', align_id='tb', back_calc=True)
346
347
348 rdcs = [
349 [ -26.2501958629, 7.26317614156, -1.24840526981, 5.31803314334, 14.0362909456, 1.33652530397, -1.6021670281],
350 [ -26.2501958629, 9.93081766942, 7.26317614156, -1.24840526981, 5.31803314334, 14.0362909456, -1.6021670281]
351 ]
352 for i in range(2):
353 print("\nChecking data pipe '%s'." % pipes[i])
354
355
356 self.assertTrue(hasattr(ds[pipes[i]], 'align_ids'))
357 self.assertTrue('tb' in ds[pipes[i]].align_ids)
358 self.assertTrue(hasattr(ds[pipes[i]], 'rdc_ids'))
359 self.assertTrue('tb' in ds[pipes[i]].rdc_ids)
360
361
362 self.assertEqual(count_spins(pipe=pipes[i]), 14)
363 self.assertEqual(len(ds[pipes[i]].interatomic), 7)
364 j = 0
365 for interatom in interatomic_loop(pipe=pipes[i]):
366
367 if i == 1 and j == 1:
368 self.assertTrue(not hasattr(interatom, 'rdc'))
369 self.assertTrue(not hasattr(interatom, 'rdc_data_types'))
370 self.assertTrue(not hasattr(interatom, 'absolute_rdc'))
371 else:
372 self.assertAlmostEqual(rdcs[i][j], interatom.rdc['tb'])
373 self.assertAlmostEqual(rdcs[i][j]+1.0, interatom.rdc_bc['tb'])
374 self.assertTrue(hasattr(interatom, 'rdc_data_types'))
375 self.assertTrue('tb' in interatom.rdc_data_types)
376 self.assertEqual(interatom.rdc_data_types['tb'], 'D')
377 self.assertTrue(hasattr(interatom, 'absolute_rdc'))
378 self.assertTrue('tb' in interatom.absolute_rdc)
379 self.assertEqual(interatom.absolute_rdc['tb'], False)
380 j += 1
381
382
384 """Test for the loading of some RDC data with the spin ID format."""
385
386
387 self.interpreter.pipe.create('test', 'N-state')
388
389
390 dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'align_data'+sep
391
392
393 self.interpreter.sequence.read(file='tb.txt', dir=dir, spin_id_col=1)
394 self.interpreter.sequence.attach_protons()
395 self.interpreter.sequence.display()
396
397
398 self.interpreter.rdc.read(align_id='tb', file='tb.txt', dir=dir, spin_id1_col=1, spin_id2_col=2, data_col=3, error_col=4)
399 self.interpreter.sequence.display()
400
401
402 rdcs = [ -26.2501958629, 9.93081766942, 7.26317614156, -1.24840526981, 5.31803314334, 14.0362909456, 1.33652530397, -1.6021670281]
403
404
405 self.assertEqual(count_spins(), 16)
406 self.assertEqual(len(cdp.interatomic), 8)
407 i = 0
408 for interatom in interatomic_loop():
409 self.assertAlmostEqual(rdcs[i], interatom.rdc['tb'])
410 i += 1
411