1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from data import Relax_data_store; ds = Relax_data_store()
24 from generic_fns import mol_res_spin, pipes
25 from generic_fns.reset import reset
26 from relax_errors import RelaxError, RelaxNoPipeError
27 from test_suite.unit_tests.base_classes import UnitTestCase
28
29
31 """Unit tests for the functions of the 'generic_fns.mol_res_spin' module."""
32
34 """Set up some molecules, residues, and spins for testing."""
35
36
37 ds.add(pipe_name='orig', pipe_type='mf')
38
39
40 cdp.mol[0].name = 'Ap4Aase'
41
42
43 cdp.mol.add_item(mol_name='RNA')
44
45
46 cdp.mol[0].res[0].num = 1
47 cdp.mol[0].res.add_item(res_num=2, res_name='Glu')
48 cdp.mol[0].res.add_item(res_num=4, res_name='Pro')
49
50
51 cdp.mol[0].res[0].spin[0].name = 'NH'
52 cdp.mol[0].res[0].spin[0].num = 60
53 cdp.mol[0].res[1].spin[0].name = 'NH'
54 cdp.mol[0].res[1].spin[0].num = 63
55
56
57 cdp.mol[1].res[0].num = -5
58 cdp.mol[1].res.add_item(res_num=-4)
59
60
61 cdp.mol[1].res[0].spin[0].name = 'C8'
62 cdp.mol[1].res[1].spin[0].name = 'C8'
63 cdp.mol[1].res[0].spin.add_item(spin_name='N5')
64 cdp.mol[1].res[1].spin.add_item(spin_name='N5')
65 cdp.mol[1].res[1].spin.add_item(spin_name='2H', spin_num=132)
66
67
68 cdp.mol[0].res[0].spin[0].select = 0
69 cdp.mol[0].res[2].spin[0].select = 0
70 cdp.mol[1].res[0].spin[0].select = 0
71 cdp.mol[1].res[1].spin[1].select = 0
72
73
74 mol_res_spin.metadata_update()
75
76
78 """Test the Selection object for boolean '&' mol-res-spin selections."""
79
80
81 obj = mol_res_spin.Selection("#Ap4Aase:4 & :Pro@Ca")
82
83
84 self.assertEqual(obj._union, None)
85 self.assertNotEqual(obj._intersect, None)
86 self.assertEqual(obj.molecules, [])
87 self.assertEqual(obj.residues, [])
88 self.assertEqual(obj.spins, [])
89
90
91 self.assertEqual(obj._intersect[0]._union, None)
92 self.assertEqual(obj._intersect[0]._intersect, None)
93 self.assertEqual(obj._intersect[0].molecules, ['Ap4Aase'])
94 self.assertEqual(obj._intersect[0].residues, [4])
95 self.assertEqual(obj._intersect[0].spins, [])
96
97
98 self.assertEqual(obj._intersect[1]._union, None)
99 self.assertEqual(obj._intersect[1]._intersect, None)
100 self.assertEqual(obj._intersect[1].molecules, [])
101 self.assertEqual(obj._intersect[1].residues, ['Pro'])
102 self.assertEqual(obj._intersect[1].spins, ['Ca'])
103
104
106 """Test the Selection object for boolean '|' mol-res-spin selections."""
107
108
109 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
110
111
112 self.assertNotEqual(obj._union, None)
113 self.assertEqual(obj._intersect, None)
114 self.assertEqual(obj.molecules, [])
115 self.assertEqual(obj.residues, [])
116 self.assertEqual(obj.spins, [])
117
118
119 self.assertEqual(obj._union[0]._union, None)
120 self.assertEqual(obj._union[0]._intersect, None)
121 self.assertEqual(obj._union[0].molecules, ['Ap4Aase'])
122 self.assertEqual(obj._union[0].residues, ['Glu'])
123 self.assertEqual(obj._union[0].spins, [])
124
125
126 self.assertEqual(obj._union[1]._union, None)
127 self.assertEqual(obj._union[1]._intersect, None)
128 self.assertEqual(obj._union[1].molecules, ['RNA'])
129 self.assertEqual(obj._union[1].residues, [])
130 self.assertEqual(obj._union[1].spins, ['C8'])
131
132
134 """Test the Selection object for complex boolean mol-res-spin selections."""
135
136
137 obj = mol_res_spin.Selection("#Ap4Aase:4 & :Pro | #RNA")
138
139
140 self.assertNotEqual(obj._union, None)
141 self.assertEqual(obj._intersect, None)
142 self.assertEqual(obj.molecules, [])
143 self.assertEqual(obj.residues, [])
144 self.assertEqual(obj.spins, [])
145
146
147 self.assertEqual(obj._union[0]._union, None)
148 self.assertNotEqual(obj._union[0]._intersect, None)
149 self.assertEqual(obj._union[0].molecules, [])
150 self.assertEqual(obj._union[0].residues, [])
151 self.assertEqual(obj._union[0].spins, [])
152
153
154 self.assertEqual(obj._union[1]._union, None)
155 self.assertEqual(obj._union[1]._intersect, None)
156 self.assertEqual(obj._union[1].molecules, ['RNA'])
157 self.assertEqual(obj._union[1].residues, [])
158 self.assertEqual(obj._union[1].spins, [])
159
160
161 self.assertEqual(obj._union[0]._intersect[0]._union, None)
162 self.assertEqual(obj._union[0]._intersect[0]._intersect, None)
163 self.assertEqual(obj._union[0]._intersect[0].molecules, ['Ap4Aase'])
164 self.assertEqual(obj._union[0]._intersect[0].residues, [4])
165 self.assertEqual(obj._union[0]._intersect[0].spins, [])
166
167
168 self.assertEqual(obj._union[0]._intersect[1]._union, None)
169 self.assertEqual(obj._union[0]._intersect[1]._intersect, None)
170 self.assertEqual(obj._union[0]._intersect[1].molecules, [])
171 self.assertEqual(obj._union[0]._intersect[1].residues, ['Pro'])
172 self.assertEqual(obj._union[0]._intersect[1].spins, [])
173
174
176 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the molecule 'RNA'."""
177
178
179 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
180
181
182 self.assert_(obj.contains_mol('RNA'))
183
184
186 """The Selection object "#Ap4Aase:Glu & #RNA@C8" does not contain the molecule 'RNA'."""
187
188
189 obj = mol_res_spin.Selection("#Ap4Aase:Glu & #RNA@C8")
190
191
192 self.assert_(not obj.contains_mol('RNA'))
193
194
196 """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the molecule 'XXX'."""
197
198
199 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
200
201
202 self.assert_(not obj.contains_mol('XXX'))
203
204
206 """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the molecule None."""
207
208
209 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
210
211
212 self.assert_(not obj.contains_mol())
213
214
223
224
226 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the molecule 'R*'."""
227
228
229 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
230
231
232 self.assert_(obj.contains_mol('R*'))
233
234
236 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the molecule '*R*'."""
237
238
239 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
240
241
242 self.assert_(obj.contains_mol('*R*'))
243
244
246 """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the res 'Glu' (without the mol name)."""
247
248
249 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
250
251
252 self.assert_(not obj.contains_res(res_name='Glu'))
253
254
256 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the res 'Glu' of the mol 'Ap4Aase'."""
257
258
259 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
260
261
262 self.assert_(obj.contains_res(res_name='Glu', mol='Ap4Aase'))
263
264
266 """The Selection object "#Ap4Aase:Glu & #RNA@C8" does not contain the res 'Glu'."""
267
268
269 obj = mol_res_spin.Selection("#Ap4Aase:Glu & #RNA@C8")
270
271
272 self.assert_(not obj.contains_res(res_name='Glu'))
273
274
276 """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the res 'Ala'."""
277
278
279 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
280
281
282 self.assert_(not obj.contains_res(res_name='Ala'))
283
284
286 """The Selection object "#Ap4Aase:Glu | #RNA:14@C8" does not contain the res None."""
287
288
289 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA:14@C8")
290
291
292 self.assert_(not obj.contains_res())
293
294
296 """The Selection object "#Ap4Aase" does contains the res None."""
297
298
299 obj = mol_res_spin.Selection("#Ap4Aase")
300
301
302 self.assert_(obj.contains_res(mol='Ap4Aase'))
303
304
306 """The Selection object "#Ap4Aase" does not contain the res None of the mol 'RNA'."""
307
308
309 obj = mol_res_spin.Selection("#Ap4Aase")
310
311
312 self.assert_(not obj.contains_res(mol='RNA'))
313
314
316 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the res 'G*' of the mol 'Ap4Aase'."""
317
318
319 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
320
321
322 self.assert_(obj.contains_res(res_name='G*', mol='Ap4Aase'))
323
324
326 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the res '*G*' of the mol 'Ap4Aase'."""
327
328
329 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
330
331
332 self.assert_(obj.contains_res(res_name='*G*', mol='Ap4Aase'))
333
334
336 """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the spin 'C8' (without the mol name)."""
337
338
339 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
340
341
342 self.assert_(not obj.contains_spin(spin_name='C8'))
343
344
346 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the spin 'C8' of the mol 'RNA'."""
347
348
349 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
350
351
352 self.assert_(obj.contains_spin(spin_name='C8', mol='RNA'))
353
354
356 """The Selection object "#Ap4Aase:Glu & #RNA@C8" does not contain the spin 'C8'."""
357
358
359 obj = mol_res_spin.Selection("#Ap4Aase:Glu & #RNA@C8")
360
361
362 self.assert_(not obj.contains_spin(spin_name='C8'))
363
364
366 """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the spin 'N3'."""
367
368
369 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
370
371
372 self.assert_(not obj.contains_spin(spin_name='N3'))
373
374
376 """The Selection object "#Ap4Aase:Glu | #RNA:14@C8" does not contain the spin None."""
377
378
379 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA:14@C8")
380
381
382 self.assert_(not obj.contains_spin())
383
384
386 """The Selection object "#Ap4Aase" does contains the spin None."""
387
388
389 obj = mol_res_spin.Selection("#Ap4Aase")
390
391
392 self.assert_(obj.contains_spin(mol='Ap4Aase'))
393
394
396 """The Selection object "#Ap4Aase" does not contain the spin None of the mol 'RNA'."""
397
398
399 obj = mol_res_spin.Selection("#Ap4Aase")
400
401
402 self.assert_(not obj.contains_spin(mol='RNA'))
403
404
406 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the spin 'C*' of the mol 'RNA'."""
407
408
409 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
410
411
412 self.assert_(obj.contains_spin(spin_name='C*', mol='RNA'))
413
414
416 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the spin '*C*' of the mol 'RNA'."""
417
418
419 obj = mol_res_spin.Selection("#Ap4Aase:Glu | #RNA@C8")
420
421
422 self.assert_(obj.contains_spin(spin_name='*C*', mol='RNA'))
423
424
426 """Test the Selection object for the single spin identifier '#Ap4Aase:2@63'."""
427
428
429 obj = mol_res_spin.Selection("#Ap4Aase:2@63")
430
431
432 self.assert_((cdp.mol[0], cdp.mol[0].res[0], cdp.mol[0].res[0].spin[0]) not in obj)
433 self.assert_((cdp.mol[0], cdp.mol[0].res[1], cdp.mol[0].res[1].spin[0]) in obj)
434 self.assert_((cdp.mol[0], cdp.mol[0].res[2], cdp.mol[0].res[2].spin[0]) not in obj)
435 self.assert_((cdp.mol[1], cdp.mol[1].res[0], cdp.mol[1].res[0].spin[0]) not in obj)
436 self.assert_((cdp.mol[1], cdp.mol[1].res[0], cdp.mol[1].res[0].spin[1]) not in obj)
437 self.assert_((cdp.mol[1], cdp.mol[1].res[1], cdp.mol[1].res[1].spin[0]) not in obj)
438 self.assert_((cdp.mol[1], cdp.mol[1].res[1], cdp.mol[1].res[1].spin[1]) not in obj)
439
440
442 """Test that the Selection object has no memory of previous selections."""
443
444
445 obj = mol_res_spin.Selection(":1@16")
446
447
448 obj = mol_res_spin.Selection(":13")
449
450
451 self.assertEqual(obj._union, None)
452 self.assertEqual(obj._intersect, None)
453 self.assertEqual(obj.molecules, [])
454 self.assertEqual(obj.residues, [13])
455 self.assertEqual(obj.spins, [])
456
457
469
470
472 """Test that the number of spins (zero) can be properly counted.
473
474 The function tested is generic_fns.mol_res_spin.count_spins().
475 """
476
477
478 reset()
479
480
481 ds.add(pipe_name='orig', pipe_type='mf')
482
483
484 self.assertEqual(mol_res_spin.count_spins(), 0)
485
486
488 """Test that the counting of the number of spins raises an error when no pipe exists.
489
490 The function tested is generic_fns.mol_res_spin.count_spins().
491 """
492
493
494 reset()
495
496
497 self.assertRaises(RelaxNoPipeError, mol_res_spin.count_spins)
498
499
501 """Test the function for determining if molecule-residue-spin data exists.
502
503 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
504 """
505
506
507 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
508
509
511 """Determine if molecule-residue-spin data exists (with data for a single molecule).
512
513 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
514 """
515
516
517 reset()
518
519
520 ds.add(pipe_name='orig', pipe_type='mf')
521 dp = pipes.get_pipe('orig')
522
523
524 dp.mol[0].name = 'TOM40'
525
526
527 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
528
529
531 """Determine if molecule-residue-spin data exists (when a single residue is named).
532
533 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
534 """
535
536
537 reset()
538
539
540 ds.add(pipe_name='orig', pipe_type='mf')
541 dp = pipes.get_pipe('orig')
542
543
544 dp.mol[0].res[0].name = 'Lys'
545
546
547 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
548
549
551 """Determine if molecule-residue-spin data exists (when a single residue is numbered).
552
553 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
554 """
555
556
557 reset()
558
559
560 ds.add(pipe_name='orig', pipe_type='mf')
561 dp = pipes.get_pipe('orig')
562
563
564 dp.mol[0].res[0].num = 1
565
566
567 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
568
569
571 """Determine if molecule-residue-spin data exists (when a single spin is named).
572
573 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
574 """
575
576
577 reset()
578
579
580 ds.add(pipe_name='orig', pipe_type='mf')
581 dp = pipes.get_pipe('orig')
582
583
584 dp.mol[0].res[0].spin[0].name = 'NH'
585
586
587 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
588
589
591 """Determine if molecule-residue-spin data exists (when a single spin is numbered).
592
593 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
594 """
595
596
597 reset()
598
599
600 ds.add(pipe_name='orig', pipe_type='mf')
601 dp = pipes.get_pipe('orig')
602
603
604 dp.mol[0].res[0].spin[0].num = 234
605
606
607 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
608
609
611 """Determine if molecule-residue-spin data exists when no data exists.
612
613 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
614 """
615
616
617 reset()
618
619
620 ds.add(pipe_name='orig', pipe_type='mf')
621
622
623 self.failIf(mol_res_spin.exists_mol_res_spin_data())
624
625
637
638
640 """First test of the spin ID generation function.
641
642 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
643 """
644
645
646 data = ['1', 'GLY']
647
648
649 id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2)
650
651
652 self.assertEqual(id, ':1')
653
654
656 """Second test of the spin ID generation function.
657
658 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
659 """
660
661
662 data = ['1', 'GLY', '234', 'NH']
663
664
665 id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2, spin_num_col=3, spin_name_col=4)
666
667
668 self.assertEqual(id, ':1@234')
669
670
672 """Third test of the spin ID generation function.
673
674 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
675 """
676
677
678 data = ['Ap4Aase', '234', 'NH']
679
680
681 id = mol_res_spin.generate_spin_id_data_array(data, mol_name_col=1, res_num_col=None, res_name_col=None, spin_num_col=2, spin_name_col=3)
682
683
684 self.assertEqual(id, '#Ap4Aase@234')
685
686
688 """Fourth test of the spin ID generation function.
689
690 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
691 """
692
693
694 data = ['Ap4Aase', '1', 'GLY']
695
696
697 id = mol_res_spin.generate_spin_id_data_array(data, mol_name_col=1, res_num_col=2, res_name_col=3)
698
699
700 self.assertEqual(id, '#Ap4Aase:1')
701
702
704 """Fifth test of the spin ID generation function.
705
706 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
707 """
708
709
710 data = ['Ap4Aase', '1', 'GLY', '234', 'NH']
711
712
713 id = mol_res_spin.generate_spin_id_data_array(data, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5)
714
715
716 self.assertEqual(id, '#Ap4Aase:1@234')
717
718
720 """Sixth test of the spin ID generation function.
721
722 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
723 """
724
725
726 data = ['1', 'GLY', None, None]
727
728
729 id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2)
730
731
732 self.assertEqual(id, ':1')
733
734
736 """Test the proper operation of the molecule loop with molecule selection.
737
738 The function tested is generic_fns.mol_res_spin.molecule_loop().
739 """
740
741
742 for mol in mol_res_spin.molecule_loop('#RNA'):
743
744 self.assertEqual(mol.name, 'RNA')
745
746
747 self.assertEqual(len(list(mol_res_spin.molecule_loop('#RNA'))), 1)
748
749
751 """Test the proper operation of the molecule loop when no data is present.
752
753 The function tested is generic_fns.mol_res_spin.molecule_loop().
754 """
755
756
757 reset()
758
759
760 ds.add(pipe_name='orig', pipe_type='mf')
761
762
763 i = 0
764 for molecule in mol_res_spin.molecule_loop():
765 i = i + 1
766
767
768 self.assertEqual(i, 0)
769
770
772 """Test the proper operation of the molecule loop when no data pipe is present.
773
774 The function tested is generic_fns.mol_res_spin.molecule_loop().
775 """
776
777
778 reset()
779
780
781 def fail_test():
782 for molecule in mol_res_spin.molecule_loop():
783 pass
784
785
786 self.assertRaises(RelaxNoPipeError, fail_test)
787
788
790 """Test the proper operation of the molecule loop when no selection is present.
791
792 The function tested is generic_fns.mol_res_spin.molecule_loop().
793 """
794
795
796 name = ['Ap4Aase', 'RNA']
797
798
799 i = 0
800 for mol in mol_res_spin.molecule_loop():
801
802 self.assertEqual(mol.name, name[i])
803
804
805 i = i + 1
806
807
808 self.assertEqual(len(list(mol_res_spin.molecule_loop())), 2)
809
810
811
813 """Test the generic_fns.mol_res_spin.parse_token() function on the string '1'."""
814
815
816 list = mol_res_spin.parse_token('1')
817
818
819 self.assertEqual(len(list), 1)
820 self.assertEqual(list[0], 1)
821
822
824 """Test the generic_fns.mol_res_spin.parse_token() function on the string '-4'."""
825
826
827 list = mol_res_spin.parse_token('-4')
828
829
830 self.assertEqual(len(list), 1)
831 self.assertEqual(list[0], -4)
832
833
835 """Test the generic_fns.mol_res_spin.parse_token() function on the string 'G'."""
836
837
838 list = mol_res_spin.parse_token('G')
839
840
841 self.assertEqual(len(list), 1)
842 self.assertEqual(list[0], 'G')
843
844
846 """Test the generic_fns.mol_res_spin.parse_token() function on the string 'N*'."""
847
848
849 list = mol_res_spin.parse_token('N*')
850
851
852 self.assertEqual(len(list), 1)
853 self.assertEqual(list[0], 'N*')
854
855
857 """Test the generic_fns.mol_res_spin.parse_token() function on the string '1-10'."""
858
859
860 list = mol_res_spin.parse_token('1-10')
861
862
863 self.assertEqual(len(list), 10)
864 for i in range(1, 11):
865 self.assertEqual(list[i-1], i)
866
867
869 """Test the generic_fns.mol_res_spin.parse_token() function on the string '-10--1'."""
870
871
872 list = mol_res_spin.parse_token('-10--1')
873
874
875 self.assertEqual(len(list), 10)
876 j = 0
877 for i in range(-10, -2):
878 self.assertEqual(list[j], i)
879 j = j + 1
880
881
883 """Test the generic_fns.mol_res_spin.parse_token() function on the string '-2, 1'."""
884
885
886 list = mol_res_spin.parse_token('-2, 1')
887
888
889 self.assertEqual(len(list), 2)
890 self.assertEqual(list[0], -2)
891 self.assertEqual(list[1], 1)
892
893
895 """Test the generic_fns.mol_res_spin.parse_token() function on the string 'N,CA'."""
896
897
898 list = mol_res_spin.parse_token('N,CA')
899
900
901 self.assertEqual(len(list), 2)
902 self.assertEqual(list[0], 'N')
903 self.assertEqual(list[1], 'CA')
904
905
907 """Test the generic_fns.mol_res_spin.parse_token() function on the string '76,Ala'."""
908
909
910 list = mol_res_spin.parse_token('76,Ala')
911
912
913 self.assertEqual(len(list), 2)
914 self.assertEqual(list[0], 76)
915 self.assertEqual(list[1], 'Ala')
916
917
919 """Test the generic_fns.mol_res_spin.parse_token() function on the string '1,3-5'."""
920
921
922 list = mol_res_spin.parse_token('1,3-5')
923
924
925 self.assertEqual(len(list), 4)
926 self.assertEqual(list[0], 1)
927 self.assertEqual(list[1], 3)
928 self.assertEqual(list[2], 4)
929 self.assertEqual(list[3], 5)
930
931
933 """Test the generic_fns.mol_res_spin.parse_token() function on the string '3-5,NH'."""
934
935
936 list = mol_res_spin.parse_token('3-5,NH')
937
938
939 self.assertEqual(len(list), 4)
940 self.assertEqual(list[0], 3)
941 self.assertEqual(list[1], 4)
942 self.assertEqual(list[2], 5)
943 self.assertEqual(list[3], 'NH')
944
945
947 """Test the generic_fns.mol_res_spin.parse_token() function on the string '3-6, 8, Gly'."""
948
949
950 list = mol_res_spin.parse_token('3-6, 8, Gly')
951
952
953 self.assertEqual(len(list), 6)
954 self.assertEqual(list[0], 3)
955 self.assertEqual(list[1], 4)
956 self.assertEqual(list[2], 5)
957 self.assertEqual(list[3], 6)
958 self.assertEqual(list[4], 8)
959 self.assertEqual(list[5], 'Gly')
960
961
963 """Test the proper operation of the residue loop with residue selection.
964
965 The function tested is generic_fns.mol_res_spin.residue_loop().
966 """
967
968
969 for res in mol_res_spin.residue_loop('#Ap4Aase:Glu'):
970
971 self.assertEqual(res.num, 2)
972
973
974 self.assertEqual(len(list(mol_res_spin.residue_loop('#Ap4Aase:Glu'))), 1)
975
976
978 """Test the proper operation of the residue loop when no data is present.
979
980 The function tested is generic_fns.mol_res_spin.residue_loop().
981 """
982
983
984 reset()
985
986
987 ds.add(pipe_name='orig', pipe_type='mf')
988
989
990 i = 0
991 for residue in mol_res_spin.residue_loop():
992 i = i + 1
993
994
995 self.assertEqual(i, 0)
996
997
999 """Test the proper operation of the residue loop when no data pipe is present.
1000
1001 The function tested is generic_fns.mol_res_spin.residue_loop().
1002 """
1003
1004
1005 reset()
1006
1007
1008 def fail_test():
1009 for residue in mol_res_spin.residue_loop():
1010 pass
1011
1012
1013 self.assertRaises(RelaxNoPipeError, fail_test)
1014
1015
1017 """Test the proper operation of the residue loop when no selection is present.
1018
1019 The function tested is generic_fns.mol_res_spin.residue_loop().
1020 """
1021
1022
1023 num = [1, 2, 4, -5, -4]
1024 name = [None, 'Glu', 'Pro', None, None]
1025
1026
1027 i = 0
1028 for res in mol_res_spin.residue_loop():
1029
1030 self.assertEqual(res.num, num[i])
1031
1032
1033 self.assertEqual(res.name, name[i])
1034
1035
1036 i = i + 1
1037
1038
1039 self.assertEqual(i, 5)
1040
1041
1043 """Test the function for returning the desired molecule data container.
1044
1045 The function tested is generic_fns.mol_res_spin.return_molecule().
1046 """
1047
1048
1049 mol1 = mol_res_spin.return_molecule('#Ap4Aase')
1050 mol2 = mol_res_spin.return_molecule(selection='#RNA', pipe='orig')
1051
1052
1053 self.assertEqual(mol1.name, 'Ap4Aase')
1054
1055
1056 self.assertEqual(mol2.name, 'RNA')
1057
1058
1068
1069
1071 """Test the function for returning the desired residue data container.
1072
1073 The function tested is generic_fns.mol_res_spin.return_residue().
1074 """
1075
1076
1077 res1 = mol_res_spin.return_residue(':1')
1078 res2 = mol_res_spin.return_residue(selection=':2')
1079 res4 = mol_res_spin.return_residue(selection=':4', pipe='orig')
1080 res5 = mol_res_spin.return_residue(selection='#RNA:-5', pipe='orig')
1081
1082
1083 self.assertEqual(res1.num, 1)
1084 self.assertEqual(res1.name, None)
1085
1086
1087 self.assertEqual(res2.num, 2)
1088 self.assertEqual(res2.name, 'Glu')
1089
1090
1091 self.assertEqual(res4.num, 4)
1092 self.assertEqual(res4.name, 'Pro')
1093
1094
1095 self.assertEqual(res5.num, -5)
1096 self.assertEqual(res5.name, None)
1097 self.assertEqual(res5.spin[1].name, 'N5')
1098
1099
1101 """Test the failure of the function for returning the desired residue data container.
1102
1103 The function tested is generic_fns.mol_res_spin.return_residue().
1104 """
1105
1106
1107 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_residue, selection=':2', pipe='new')
1108
1109
1111 """Test the function for returning the desired residue data container.
1112
1113 The function tested is generic_fns.mol_res_spin.return_single_residue_info().
1114 """
1115
1116
1117 res1 = mol_res_spin.return_single_residue_info('1')
1118 res2 = mol_res_spin.return_single_residue_info('2,Glu')
1119 res4 = mol_res_spin.return_single_residue_info('Pro,4')
1120 res5 = mol_res_spin.return_single_residue_info('-5')
1121
1122
1123 self.assertEqual(res1, (1, None))
1124
1125
1126 self.assertEqual(res2, (2, 'Glu'))
1127
1128
1129 self.assertEqual(res4, (4, 'Pro'))
1130
1131
1132 self.assertEqual(res5, (-5, None))
1133
1134
1136 """Test the failure of the function for returning the desired residue data container.
1137
1138 The function tested is generic_fns.mol_res_spin.return_single_residue_info().
1139 """
1140
1141
1142 self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,2')
1143 self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,Glu,Pro')
1144 self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,2,Glu,Pro')
1145
1146
1148 """Test the function for returning the desired spin data container.
1149
1150 The function tested is generic_fns.mol_res_spin.return_spin().
1151 """
1152
1153
1154 spin1 = mol_res_spin.return_spin('#Ap4Aase:1')
1155 spin2 = mol_res_spin.return_spin(spin_id='#Ap4Aase:2')
1156 spin3 = mol_res_spin.return_spin(spin_id='#Ap4Aase:4', pipe='orig')
1157 spin4 = mol_res_spin.return_spin(spin_id='#RNA:-5@N5', pipe='orig')
1158 spin5 = mol_res_spin.return_spin(spin_id='#RNA:-4@2H', pipe='orig')
1159
1160
1161 self.assertNotEqual(spin1, None)
1162 self.assertEqual(spin1.num, 60)
1163 self.assertEqual(spin1.name, 'NH')
1164
1165
1166 self.assertNotEqual(spin2, None)
1167 self.assertEqual(spin2.num, 63)
1168 self.assertEqual(spin2.name, 'NH')
1169
1170
1171 self.assertNotEqual(spin3, None)
1172 self.assertEqual(spin3.num, None)
1173 self.assertEqual(spin3.name, None)
1174
1175
1176 self.assertNotEqual(spin4, None)
1177 self.assertEqual(spin4.num, None)
1178 self.assertEqual(spin4.name, 'N5')
1179
1180
1181 self.assertNotEqual(spin5, None)
1182 self.assertEqual(spin5.num, 132)
1183 self.assertEqual(spin5.name, '2H')
1184
1185
1187 """Test the failure of the function for returning the desired spin data container.
1188
1189 The function tested is generic_fns.mol_res_spin.return_spin().
1190 """
1191
1192
1193 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_spin, spin_id=':2', pipe='new')
1194
1195
1197 """Test the proper operation of the spin loop with spin selection.
1198
1199 The function tested is generic_fns.mol_res_spin.spin_loop().
1200 """
1201
1202
1203 select = [1, 0]
1204
1205
1206 i = 0
1207 for spin in mol_res_spin.spin_loop('@N5'):
1208
1209 self.assertEqual(spin.select, select[i])
1210
1211
1212 self.assertEqual(spin.name, 'N5')
1213
1214
1215 i = i + 1
1216
1217
1218 self.assertEqual(i, 2)
1219
1220
1222 """Test the operation of the spin loop with the selection "#Ap4Aase:Glu | #RNA@C8".
1223
1224 The function tested is generic_fns.mol_res_spin.spin_loop().
1225 """
1226
1227
1228 select = [1, 0, 1]
1229 name = ['NH', 'C8', 'C8']
1230 num = [63, None, None]
1231
1232
1233 i = 0
1234 for spin in mol_res_spin.spin_loop("#Ap4Aase:Glu | #RNA@C8"):
1235
1236 self.assertEqual([spin.select, spin.name, spin.num], [select[i], name[i], num[i]])
1237
1238
1239 i = i + 1
1240
1241
1242 self.assertEqual(i, 3)
1243
1244
1246 """Test the proper operation of the spin loop with spin selection '@NH|@N5'.
1247
1248 The function tested is generic_fns.mol_res_spin.spin_loop().
1249 """
1250
1251
1252 select = [0, 1, 1, 0]
1253 name = ['NH', 'NH', 'N5', 'N5']
1254
1255
1256 i = 0
1257 for spin in mol_res_spin.spin_loop('@NH|@N5'):
1258
1259 self.assertEqual(spin.select, select[i])
1260
1261
1262 self.assertEqual(spin.name, name[i])
1263
1264
1265 i = i + 1
1266
1267
1268 self.assertEqual(i, 4)
1269
1270
1272 """Test the proper operation of the spin loop when no data is present.
1273
1274 The function tested is generic_fns.mol_res_spin.spin_loop().
1275 """
1276
1277
1278 reset()
1279
1280
1281 ds.add(pipe_name='orig', pipe_type='mf')
1282
1283
1284 i = 0
1285 for spin in mol_res_spin.spin_loop():
1286 i = i + 1
1287
1288
1289 self.assertEqual(i, 0)
1290
1291
1293 """Test the proper operation of the spin loop when no data pipe is present.
1294
1295 The function tested is generic_fns.mol_res_spin.spin_loop().
1296 """
1297
1298
1299 reset()
1300
1301
1302 def fail_test():
1303 for spin in mol_res_spin.spin_loop():
1304 pass
1305
1306
1307 self.assertRaises(RelaxNoPipeError, fail_test)
1308
1309
1311 """Test the proper operation of the spin loop when no selection is present.
1312
1313 The function tested is generic_fns.mol_res_spin.spin_loop().
1314 """
1315
1316
1317 select = [0, 1, 0, 0, 1, 1, 0, 1]
1318 name = ['NH', 'NH', None, 'C8', 'N5', 'C8', 'N5', '2H']
1319
1320
1321 i = 0
1322 for spin in mol_res_spin.spin_loop():
1323
1324 self.assertEqual(spin.select, select[i])
1325
1326
1327 self.assertEqual(spin.name, name[i])
1328
1329
1330 i = i + 1
1331
1332
1333 self.assertEqual(i, 8)
1334
1335
1337 """Test the operation of the spin loop with the single spin selection '#Ap4Aase:Glu@63'.
1338
1339 The function tested is generic_fns.mol_res_spin.spin_loop().
1340 """
1341
1342
1343 i = 0
1344 for spin in mol_res_spin.spin_loop('#Ap4Aase:Glu@63'):
1345
1346 self.assertEqual(spin.select, 1)
1347
1348
1349 self.assertEqual(spin.name, 'NH')
1350
1351
1352 self.assertEqual(spin.num, 63)
1353
1354
1355 i = i + 1
1356
1357
1358 self.assertEqual(i, 1)
1359
1360
1362 """Test the proper operation of the spin loop with wildcard spin selection '@N*'.
1363
1364 The function tested is generic_fns.mol_res_spin.spin_loop().
1365 """
1366
1367
1368 select = [0, 1, 1, 0]
1369 name = ['NH', 'NH', 'N5', 'N5']
1370
1371
1372 i = 0
1373 for spin in mol_res_spin.spin_loop('@N*'):
1374
1375 self.assertEqual(spin.select, select[i])
1376
1377
1378 self.assertEqual(spin.name, name[i])
1379
1380
1381 i = i + 1
1382
1383
1384 self.assertEqual(i, 4)
1385
1386
1388 """Test the generic_fns.mol_res_spin.tokenise() function on the string '@1'."""
1389
1390
1391 mol_token, res_token, spin_token = mol_res_spin.tokenise('@1')
1392
1393
1394 self.assertEqual(mol_token, None)
1395 self.assertEqual(res_token, None)
1396 self.assertEqual(spin_token, '1')
1397
1398
1400 """Test the generic_fns.mol_res_spin.tokenise() function on the string ':-4'."""
1401
1402
1403 mol_token, res_token, spin_token = mol_res_spin.tokenise(':-4')
1404
1405
1406 self.assertEqual(mol_token, None)
1407 self.assertEqual(res_token, '-4')
1408 self.assertEqual(spin_token, None)
1409
1410
1412 """Test the generic_fns.mol_res_spin.tokenise() function on the string '#CaM'."""
1413
1414
1415 mol_token, res_token, spin_token = mol_res_spin.tokenise('#CaM')
1416
1417
1418 self.assertEqual(mol_token, 'CaM')
1419 self.assertEqual(res_token, None)
1420 self.assertEqual(spin_token, None)
1421
1422
1424 """Test the generic_fns.mol_res_spin.tokenise() function on the string ':G@N3'."""
1425
1426
1427 mol_token, res_token, spin_token = mol_res_spin.tokenise(':G@N3')
1428
1429
1430 self.assertEqual(mol_token, None)
1431 self.assertEqual(res_token, 'G')
1432 self.assertEqual(spin_token, 'N3')
1433
1434
1436 """Test the generic_fns.mol_res_spin.tokenise() function on the string '#OMP@NH'."""
1437
1438
1439 mol_token, res_token, spin_token = mol_res_spin.tokenise('#OMP@NH')
1440
1441
1442 self.assertEqual(mol_token, 'OMP')
1443 self.assertEqual(res_token, None)
1444 self.assertEqual(spin_token, 'NH')
1445
1446
1448 """Test the generic_fns.mol_res_spin.tokenise() function on the string '#Lyso:20-50'."""
1449
1450
1451 mol_token, res_token, spin_token = mol_res_spin.tokenise('#Lyso:20-50')
1452
1453
1454 self.assertEqual(mol_token, 'Lyso')
1455 self.assertEqual(res_token, '20-50')
1456 self.assertEqual(spin_token, None)
1457
1458
1460 """Test the generic_fns.mol_res_spin.tokenise() function on the string '#Ap4Aase:*@N,CA'."""
1461
1462
1463 mol_token, res_token, spin_token = mol_res_spin.tokenise('#Ap4Aase:*@N,CA')
1464
1465
1466 self.assertEqual(mol_token, 'Ap4Aase')
1467 self.assertEqual(res_token, '*')
1468 self.assertEqual(spin_token, 'N,CA')
1469
1470
1472 """Test the generic_fns.mol_res_spin.tokenise() function on the string '@N*'."""
1473
1474
1475 mol_token, res_token, spin_token = mol_res_spin.tokenise('@N*')
1476
1477
1478 self.assertEqual(mol_token, None)
1479 self.assertEqual(res_token, None)
1480 self.assertEqual(spin_token, 'N*')
1481
1482
1484 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@N@1'.
1485
1486 This tests for a duplicated atom identifier.
1487 """
1488
1489
1490 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@N@1')
1491
1492
1494 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ':*@N@1'.
1495
1496 This tests for a duplicated atom identifier.
1497 """
1498
1499
1500 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':*@N@1')
1501
1502
1504 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@N:*@1'.
1505
1506 This tests for a duplicated atom identifier.
1507 """
1508
1509
1510 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@N:*@1')
1511
1512
1514 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ':1:2'.
1515
1516 This tests for a duplicated residue identifier.
1517 """
1518
1519
1520 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':1:2')
1521
1522
1524 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '#None:1:Ala'.
1525
1526 This tests for a duplicated residue identifier.
1527 """
1528
1529
1530 self.assertRaises(RelaxError, mol_res_spin.tokenise, '#None:1:Ala')
1531
1532
1534 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ':1:Ala@N'.
1535
1536 This tests for a duplicated residue identifier.
1537 """
1538
1539
1540 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':1:Ala@N')
1541
1542
1544 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '#A#B'.
1545
1546 This tests for a duplicated molecule identifier.
1547 """
1548
1549
1550 self.assertRaises(RelaxError, mol_res_spin.tokenise, '#A#B')
1551
1552
1554 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '#A#B:Leu'.
1555
1556 This tests for a duplicated molecule identifier.
1557 """
1558
1559
1560 self.assertRaises(RelaxError, mol_res_spin.tokenise, '#A#B:Leu')
1561
1562
1564 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '#A#C@CA'.
1565
1566 This tests for a duplicated molecule identifier.
1567 """
1568
1569
1570 self.assertRaises(RelaxError, mol_res_spin.tokenise, '#A#C@CA')
1571
1572
1574 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@CA#A'.
1575
1576 This tests for an out of order '@' identifier.
1577 """
1578
1579
1580 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@CA#A')
1581
1582
1584 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@CA:Pro'.
1585
1586 This tests for an out of order '@' identifier.
1587 """
1588
1589
1590 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@CA:Pro')
1591
1592
1594 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@CA#Z:Pro'.
1595
1596 This tests for an out of order '@' identifier.
1597 """
1598
1599
1600 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@CA#Z:Pro')
1601
1602
1604 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@CA:Pro'.
1605
1606 This tests for an out of order ':' identifier.
1607 """
1608
1609
1610 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@CA:Pro')
1611
1612
1614 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ':Glu#X'.
1615
1616 This tests for an out of order ':' identifier.
1617 """
1618
1619
1620 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':Glu#X')
1621
1622
1624 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '#1@12423:Glu'.
1625
1626 This tests for an out of order ':' identifier.
1627 """
1628
1629
1630 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':Glu#X')
1631
1632
1634 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ':1-160#A'.
1635
1636 This tests for an out of order '#' identifier.
1637 """
1638
1639
1640 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':1-160#A')
1641
1642
1644 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@N,CA#A'.
1645
1646 This tests for an out of order '#' identifier.
1647 """
1648
1649
1650 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@N,CA#A')
1651
1652
1654 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@N:-10#Zip'.
1655
1656 This tests for an out of order '#' identifier.
1657 """
1658
1659
1660 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@N:-10#Zip')
1661
1662
1664 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '13'.
1665
1666 This tests for an improper selection string.
1667 """
1668
1669
1670 self.assertRaises(RelaxError, mol_res_spin.tokenise, '13')
1671
1672
1674 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string 'XXX'.
1675
1676 This tests for an improper selection string.
1677 """
1678
1679
1680 self.assertRaises(RelaxError, mol_res_spin.tokenise, 'XXX')
1681
1682
1684 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ''.
1685
1686 This tests for an improper selection string.
1687 """
1688
1689
1690 self.assertRaises(RelaxError, mol_res_spin.tokenise, '')
1691
1692
1694 """Test boolean and in mol-res-spin selections."""
1695
1696
1697 sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro"))
1698
1699
1700 self.assertEqual(len(sel), 1)
1701 for res in sel:
1702 self.assert_(res.name == "Pro" and res.num == 4)
1703
1704
1706 """Test complex boolean mol-res-spin selections."""
1707
1708
1709 sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro | #RNA"))
1710
1711
1712 names = ['Pro', None, None]
1713 numbers = [4, -5, -4]
1714
1715
1716 self.assertEqual(len(sel), 3)
1717 for i in range(3):
1718 self.assertEqual(sel[i].name, names[i])
1719 self.assertEqual(sel[i].num, numbers[i])
1720
1721
1722
1723
1724
1726 """Test complex boolean mol-res-spin selections with parenthesis."""
1727
1728
1729 sel = list(mol_res_spin.residue_loop("(#Ap4Aase & :Pro) | (#RNA & :-4)"))
1730
1731
1732 self.assertEqual(len(sel), 2)
1733 for res in sel:
1734 self.assert_(res.num in [-4, 4])
1735