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
459 """The Selection object ":1-70" contains the res ':1'."""
460
461
462 obj = mol_res_spin.Selection(":1-70")
463
464
465 self.assert_(':1' in obj)
466
467
469 """The Selection object ":1-70" does not contain the res ':71'."""
470
471
472 obj = mol_res_spin.Selection(":1-70")
473
474
475 self.assert_(':71' not in obj)
476
477
479 """The Selection object ":1-70" contains the spin ':1@N'."""
480
481
482 obj = mol_res_spin.Selection(":1-70")
483
484
485 self.assert_(':1@N' in obj)
486
487
489 """The Selection object ":1-70" does not contain the spin ':71@C'."""
490
491
492 obj = mol_res_spin.Selection(":1-70")
493
494
495 self.assert_(':71@C' not in obj)
496
497
509
510
512 """Test that the number of spins (zero) can be properly counted.
513
514 The function tested is generic_fns.mol_res_spin.count_spins().
515 """
516
517
518 reset()
519
520
521 ds.add(pipe_name='orig', pipe_type='mf')
522
523
524 self.assertEqual(mol_res_spin.count_spins(), 0)
525
526
528 """Test that the counting of the number of spins raises an error when no pipe exists.
529
530 The function tested is generic_fns.mol_res_spin.count_spins().
531 """
532
533
534 reset()
535
536
537 self.assertRaises(RelaxNoPipeError, mol_res_spin.count_spins)
538
539
541 """Test the function for determining if molecule-residue-spin data exists.
542
543 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
544 """
545
546
547 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
548
549
551 """Determine if molecule-residue-spin data exists (with data for a single molecule).
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].name = 'TOM40'
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 residue 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].name = 'Lys'
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 residue 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].num = 1
605
606
607 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
608
609
611 """Determine if molecule-residue-spin data exists (when a single spin is named).
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 dp = pipes.get_pipe('orig')
622
623
624 dp.mol[0].res[0].spin[0].name = 'NH'
625
626
627 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
628
629
631 """Determine if molecule-residue-spin data exists (when a single spin is numbered).
632
633 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
634 """
635
636
637 reset()
638
639
640 ds.add(pipe_name='orig', pipe_type='mf')
641 dp = pipes.get_pipe('orig')
642
643
644 dp.mol[0].res[0].spin[0].num = 234
645
646
647 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
648
649
651 """Determine if molecule-residue-spin data exists when no data exists.
652
653 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
654 """
655
656
657 reset()
658
659
660 ds.add(pipe_name='orig', pipe_type='mf')
661
662
663 self.failIf(mol_res_spin.exists_mol_res_spin_data())
664
665
677
678
680 """First test of the spin ID generation function.
681
682 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
683 """
684
685
686 data = ['1', 'GLY']
687
688
689 id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2)
690
691
692 self.assertEqual(id, ':1')
693
694
696 """Second test of the spin ID generation function.
697
698 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
699 """
700
701
702 data = ['1', 'GLY', '234', 'NH']
703
704
705 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)
706
707
708 self.assertEqual(id, ':1@234')
709
710
712 """Third test of the spin ID generation function.
713
714 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
715 """
716
717
718 data = ['Ap4Aase', '234', 'NH']
719
720
721 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)
722
723
724 self.assertEqual(id, '#Ap4Aase@234')
725
726
728 """Fourth test of the spin ID generation function.
729
730 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
731 """
732
733
734 data = ['Ap4Aase', '1', 'GLY']
735
736
737 id = mol_res_spin.generate_spin_id_data_array(data, mol_name_col=1, res_num_col=2, res_name_col=3)
738
739
740 self.assertEqual(id, '#Ap4Aase:1')
741
742
744 """Fifth test of the spin ID generation function.
745
746 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
747 """
748
749
750 data = ['Ap4Aase', '1', 'GLY', '234', 'NH']
751
752
753 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)
754
755
756 self.assertEqual(id, '#Ap4Aase:1@234')
757
758
760 """Sixth test of the spin ID generation function.
761
762 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
763 """
764
765
766 data = ['1', 'GLY', None, None]
767
768
769 id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2)
770
771
772 self.assertEqual(id, ':1')
773
774
776 """Test the proper operation of the molecule loop with molecule selection.
777
778 The function tested is generic_fns.mol_res_spin.molecule_loop().
779 """
780
781
782 for mol in mol_res_spin.molecule_loop('#RNA'):
783
784 self.assertEqual(mol.name, 'RNA')
785
786
787 self.assertEqual(len(list(mol_res_spin.molecule_loop('#RNA'))), 1)
788
789
791 """Test the proper operation of the molecule loop when no data is present.
792
793 The function tested is generic_fns.mol_res_spin.molecule_loop().
794 """
795
796
797 reset()
798
799
800 ds.add(pipe_name='orig', pipe_type='mf')
801
802
803 i = 0
804 for molecule in mol_res_spin.molecule_loop():
805 i = i + 1
806
807
808 self.assertEqual(i, 0)
809
810
812 """Test the proper operation of the molecule loop when no data pipe is present.
813
814 The function tested is generic_fns.mol_res_spin.molecule_loop().
815 """
816
817
818 reset()
819
820
821 def fail_test():
822 for molecule in mol_res_spin.molecule_loop():
823 pass
824
825
826 self.assertRaises(RelaxNoPipeError, fail_test)
827
828
830 """Test the proper operation of the molecule loop when no selection is present.
831
832 The function tested is generic_fns.mol_res_spin.molecule_loop().
833 """
834
835
836 name = ['Ap4Aase', 'RNA']
837
838
839 i = 0
840 for mol in mol_res_spin.molecule_loop():
841
842 self.assertEqual(mol.name, name[i])
843
844
845 i = i + 1
846
847
848 self.assertEqual(len(list(mol_res_spin.molecule_loop())), 2)
849
850
851
853 """Test the generic_fns.mol_res_spin.parse_token() function on the string '1'."""
854
855
856 list = mol_res_spin.parse_token('1')
857
858
859 self.assertEqual(len(list), 1)
860 self.assertEqual(list[0], 1)
861
862
864 """Test the generic_fns.mol_res_spin.parse_token() function on the string '-4'."""
865
866
867 list = mol_res_spin.parse_token('-4')
868
869
870 self.assertEqual(len(list), 1)
871 self.assertEqual(list[0], -4)
872
873
875 """Test the generic_fns.mol_res_spin.parse_token() function on the string 'G'."""
876
877
878 list = mol_res_spin.parse_token('G')
879
880
881 self.assertEqual(len(list), 1)
882 self.assertEqual(list[0], 'G')
883
884
886 """Test the generic_fns.mol_res_spin.parse_token() function on the string 'N*'."""
887
888
889 list = mol_res_spin.parse_token('N*')
890
891
892 self.assertEqual(len(list), 1)
893 self.assertEqual(list[0], 'N*')
894
895
897 """Test the generic_fns.mol_res_spin.parse_token() function on the string '1-10'."""
898
899
900 list = mol_res_spin.parse_token('1-10')
901
902
903 self.assertEqual(len(list), 10)
904 for i in range(1, 11):
905 self.assertEqual(list[i-1], i)
906
907
909 """Test the generic_fns.mol_res_spin.parse_token() function on the string '-10--1'."""
910
911
912 list = mol_res_spin.parse_token('-10--1')
913
914
915 self.assertEqual(len(list), 10)
916 j = 0
917 for i in range(-10, -2):
918 self.assertEqual(list[j], i)
919 j = j + 1
920
921
923 """Test the generic_fns.mol_res_spin.parse_token() function on the string '-2, 1'."""
924
925
926 list = mol_res_spin.parse_token('-2, 1')
927
928
929 self.assertEqual(len(list), 2)
930 self.assertEqual(list[0], -2)
931 self.assertEqual(list[1], 1)
932
933
935 """Test the generic_fns.mol_res_spin.parse_token() function on the string 'N,CA'."""
936
937
938 list = mol_res_spin.parse_token('N,CA')
939
940
941 self.assertEqual(len(list), 2)
942 self.assertEqual(list[0], 'N')
943 self.assertEqual(list[1], 'CA')
944
945
947 """Test the generic_fns.mol_res_spin.parse_token() function on the string '76,Ala'."""
948
949
950 list = mol_res_spin.parse_token('76,Ala')
951
952
953 self.assertEqual(len(list), 2)
954 self.assertEqual(list[0], 76)
955 self.assertEqual(list[1], 'Ala')
956
957
959 """Test the generic_fns.mol_res_spin.parse_token() function on the string '1,3-5'."""
960
961
962 list = mol_res_spin.parse_token('1,3-5')
963
964
965 self.assertEqual(len(list), 4)
966 self.assertEqual(list[0], 1)
967 self.assertEqual(list[1], 3)
968 self.assertEqual(list[2], 4)
969 self.assertEqual(list[3], 5)
970
971
973 """Test the generic_fns.mol_res_spin.parse_token() function on the string '3-5,NH'."""
974
975
976 list = mol_res_spin.parse_token('3-5,NH')
977
978
979 self.assertEqual(len(list), 4)
980 self.assertEqual(list[0], 3)
981 self.assertEqual(list[1], 4)
982 self.assertEqual(list[2], 5)
983 self.assertEqual(list[3], 'NH')
984
985
987 """Test the generic_fns.mol_res_spin.parse_token() function on the string '3-6, 8, Gly'."""
988
989
990 list = mol_res_spin.parse_token('3-6, 8, Gly')
991
992
993 self.assertEqual(len(list), 6)
994 self.assertEqual(list[0], 3)
995 self.assertEqual(list[1], 4)
996 self.assertEqual(list[2], 5)
997 self.assertEqual(list[3], 6)
998 self.assertEqual(list[4], 8)
999 self.assertEqual(list[5], 'Gly')
1000
1001
1003 """Test the proper operation of the residue loop with residue selection.
1004
1005 The function tested is generic_fns.mol_res_spin.residue_loop().
1006 """
1007
1008
1009 for res in mol_res_spin.residue_loop('#Ap4Aase:Glu'):
1010
1011 self.assertEqual(res.num, 2)
1012
1013
1014 self.assertEqual(len(list(mol_res_spin.residue_loop('#Ap4Aase:Glu'))), 1)
1015
1016
1018 """Test the proper operation of the residue loop when no data is present.
1019
1020 The function tested is generic_fns.mol_res_spin.residue_loop().
1021 """
1022
1023
1024 reset()
1025
1026
1027 ds.add(pipe_name='orig', pipe_type='mf')
1028
1029
1030 i = 0
1031 for residue in mol_res_spin.residue_loop():
1032 i = i + 1
1033
1034
1035 self.assertEqual(i, 0)
1036
1037
1039 """Test the proper operation of the residue loop when no data pipe is present.
1040
1041 The function tested is generic_fns.mol_res_spin.residue_loop().
1042 """
1043
1044
1045 reset()
1046
1047
1048 def fail_test():
1049 for residue in mol_res_spin.residue_loop():
1050 pass
1051
1052
1053 self.assertRaises(RelaxNoPipeError, fail_test)
1054
1055
1057 """Test the proper operation of the residue loop when no selection is present.
1058
1059 The function tested is generic_fns.mol_res_spin.residue_loop().
1060 """
1061
1062
1063 num = [1, 2, 4, -5, -4]
1064 name = [None, 'Glu', 'Pro', None, None]
1065
1066
1067 i = 0
1068 for res in mol_res_spin.residue_loop():
1069
1070 self.assertEqual(res.num, num[i])
1071
1072
1073 self.assertEqual(res.name, name[i])
1074
1075
1076 i = i + 1
1077
1078
1079 self.assertEqual(i, 5)
1080
1081
1083 """Test the function for returning the desired molecule data container.
1084
1085 The function tested is generic_fns.mol_res_spin.return_molecule().
1086 """
1087
1088
1089 mol1 = mol_res_spin.return_molecule('#Ap4Aase')
1090 mol2 = mol_res_spin.return_molecule(selection='#RNA', pipe='orig')
1091
1092
1093 self.assertEqual(mol1.name, 'Ap4Aase')
1094
1095
1096 self.assertEqual(mol2.name, 'RNA')
1097
1098
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_residue().
1114 """
1115
1116
1117 res1 = mol_res_spin.return_residue(':1')
1118 res2 = mol_res_spin.return_residue(selection=':2')
1119 res4 = mol_res_spin.return_residue(selection=':4', pipe='orig')
1120 res5 = mol_res_spin.return_residue(selection='#RNA:-5', pipe='orig')
1121
1122
1123 self.assertEqual(res1.num, 1)
1124 self.assertEqual(res1.name, None)
1125
1126
1127 self.assertEqual(res2.num, 2)
1128 self.assertEqual(res2.name, 'Glu')
1129
1130
1131 self.assertEqual(res4.num, 4)
1132 self.assertEqual(res4.name, 'Pro')
1133
1134
1135 self.assertEqual(res5.num, -5)
1136 self.assertEqual(res5.name, None)
1137 self.assertEqual(res5.spin[1].name, 'N5')
1138
1139
1141 """Test the failure of the function for returning the desired residue data container.
1142
1143 The function tested is generic_fns.mol_res_spin.return_residue().
1144 """
1145
1146
1147 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_residue, selection=':2', pipe='new')
1148
1149
1151 """Test the function for returning the desired residue data container.
1152
1153 The function tested is generic_fns.mol_res_spin.return_single_residue_info().
1154 """
1155
1156
1157 res1 = mol_res_spin.return_single_residue_info('1')
1158 res2 = mol_res_spin.return_single_residue_info('2,Glu')
1159 res4 = mol_res_spin.return_single_residue_info('Pro,4')
1160 res5 = mol_res_spin.return_single_residue_info('-5')
1161
1162
1163 self.assertEqual(res1, (1, None))
1164
1165
1166 self.assertEqual(res2, (2, 'Glu'))
1167
1168
1169 self.assertEqual(res4, (4, 'Pro'))
1170
1171
1172 self.assertEqual(res5, (-5, None))
1173
1174
1176 """Test the failure of the function for returning the desired residue data container.
1177
1178 The function tested is generic_fns.mol_res_spin.return_single_residue_info().
1179 """
1180
1181
1182 self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,2')
1183 self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,Glu,Pro')
1184 self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,2,Glu,Pro')
1185
1186
1188 """Test the function for returning the desired spin data container.
1189
1190 The function tested is generic_fns.mol_res_spin.return_spin().
1191 """
1192
1193
1194 spin1 = mol_res_spin.return_spin('#Ap4Aase:1')
1195 spin2 = mol_res_spin.return_spin(spin_id='#Ap4Aase:2')
1196 spin3 = mol_res_spin.return_spin(spin_id='#Ap4Aase:4', pipe='orig')
1197 spin4 = mol_res_spin.return_spin(spin_id='#RNA:-5@N5', pipe='orig')
1198 spin5 = mol_res_spin.return_spin(spin_id='#RNA:-4@2H', pipe='orig')
1199
1200
1201 self.assertNotEqual(spin1, None)
1202 self.assertEqual(spin1.num, 60)
1203 self.assertEqual(spin1.name, 'NH')
1204
1205
1206 self.assertNotEqual(spin2, None)
1207 self.assertEqual(spin2.num, 63)
1208 self.assertEqual(spin2.name, 'NH')
1209
1210
1211 self.assertNotEqual(spin3, None)
1212 self.assertEqual(spin3.num, None)
1213 self.assertEqual(spin3.name, None)
1214
1215
1216 self.assertNotEqual(spin4, None)
1217 self.assertEqual(spin4.num, None)
1218 self.assertEqual(spin4.name, 'N5')
1219
1220
1221 self.assertNotEqual(spin5, None)
1222 self.assertEqual(spin5.num, 132)
1223 self.assertEqual(spin5.name, '2H')
1224
1225
1227 """Test the failure of the function for returning the desired spin data container.
1228
1229 The function tested is generic_fns.mol_res_spin.return_spin().
1230 """
1231
1232
1233 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_spin, spin_id=':2', pipe='new')
1234
1235
1237 """Test the proper operation of the spin loop with spin selection.
1238
1239 The function tested is generic_fns.mol_res_spin.spin_loop().
1240 """
1241
1242
1243 select = [1, 0]
1244
1245
1246 i = 0
1247 for spin in mol_res_spin.spin_loop('@N5'):
1248
1249 self.assertEqual(spin.select, select[i])
1250
1251
1252 self.assertEqual(spin.name, 'N5')
1253
1254
1255 i = i + 1
1256
1257
1258 self.assertEqual(i, 2)
1259
1260
1262 """Test the operation of the spin loop with the selection "#Ap4Aase:Glu | #RNA@C8".
1263
1264 The function tested is generic_fns.mol_res_spin.spin_loop().
1265 """
1266
1267
1268 select = [1, 0, 1]
1269 name = ['NH', 'C8', 'C8']
1270 num = [63, None, None]
1271
1272
1273 i = 0
1274 for spin in mol_res_spin.spin_loop("#Ap4Aase:Glu | #RNA@C8"):
1275
1276 self.assertEqual([spin.select, spin.name, spin.num], [select[i], name[i], num[i]])
1277
1278
1279 i = i + 1
1280
1281
1282 self.assertEqual(i, 3)
1283
1284
1286 """Test the proper operation of the spin loop with spin selection '@NH|@N5'.
1287
1288 The function tested is generic_fns.mol_res_spin.spin_loop().
1289 """
1290
1291
1292 select = [0, 1, 1, 0]
1293 name = ['NH', 'NH', 'N5', 'N5']
1294
1295
1296 i = 0
1297 for spin in mol_res_spin.spin_loop('@NH|@N5'):
1298
1299 self.assertEqual(spin.select, select[i])
1300
1301
1302 self.assertEqual(spin.name, name[i])
1303
1304
1305 i = i + 1
1306
1307
1308 self.assertEqual(i, 4)
1309
1310
1312 """Test the proper operation of the spin loop when no data is present.
1313
1314 The function tested is generic_fns.mol_res_spin.spin_loop().
1315 """
1316
1317
1318 reset()
1319
1320
1321 ds.add(pipe_name='orig', pipe_type='mf')
1322
1323
1324 i = 0
1325 for spin in mol_res_spin.spin_loop():
1326 i = i + 1
1327
1328
1329 self.assertEqual(i, 0)
1330
1331
1333 """Test the proper operation of the spin loop when no data pipe is present.
1334
1335 The function tested is generic_fns.mol_res_spin.spin_loop().
1336 """
1337
1338
1339 reset()
1340
1341
1342 def fail_test():
1343 for spin in mol_res_spin.spin_loop():
1344 pass
1345
1346
1347 self.assertRaises(RelaxNoPipeError, fail_test)
1348
1349
1351 """Test the proper operation of the spin loop when no selection is present.
1352
1353 The function tested is generic_fns.mol_res_spin.spin_loop().
1354 """
1355
1356
1357 select = [0, 1, 0, 0, 1, 1, 0, 1]
1358 name = ['NH', 'NH', None, 'C8', 'N5', 'C8', 'N5', '2H']
1359
1360
1361 i = 0
1362 for spin in mol_res_spin.spin_loop():
1363
1364 self.assertEqual(spin.select, select[i])
1365
1366
1367 self.assertEqual(spin.name, name[i])
1368
1369
1370 i = i + 1
1371
1372
1373 self.assertEqual(i, 8)
1374
1375
1377 """Test the operation of the spin loop with the single spin selection '#Ap4Aase:Glu@63'.
1378
1379 The function tested is generic_fns.mol_res_spin.spin_loop().
1380 """
1381
1382
1383 i = 0
1384 for spin in mol_res_spin.spin_loop('#Ap4Aase:Glu@63'):
1385
1386 self.assertEqual(spin.select, 1)
1387
1388
1389 self.assertEqual(spin.name, 'NH')
1390
1391
1392 self.assertEqual(spin.num, 63)
1393
1394
1395 i = i + 1
1396
1397
1398 self.assertEqual(i, 1)
1399
1400
1402 """Test the proper operation of the spin loop with wildcard spin selection '@N*'.
1403
1404 The function tested is generic_fns.mol_res_spin.spin_loop().
1405 """
1406
1407
1408 select = [0, 1, 1, 0]
1409 name = ['NH', 'NH', 'N5', 'N5']
1410
1411
1412 i = 0
1413 for spin in mol_res_spin.spin_loop('@N*'):
1414
1415 self.assertEqual(spin.select, select[i])
1416
1417
1418 self.assertEqual(spin.name, name[i])
1419
1420
1421 i = i + 1
1422
1423
1424 self.assertEqual(i, 4)
1425
1426
1428 """Test the generic_fns.mol_res_spin.tokenise() function on the string '@1'."""
1429
1430
1431 mol_token, res_token, spin_token = mol_res_spin.tokenise('@1')
1432
1433
1434 self.assertEqual(mol_token, None)
1435 self.assertEqual(res_token, None)
1436 self.assertEqual(spin_token, '1')
1437
1438
1440 """Test the generic_fns.mol_res_spin.tokenise() function on the string ':-4'."""
1441
1442
1443 mol_token, res_token, spin_token = mol_res_spin.tokenise(':-4')
1444
1445
1446 self.assertEqual(mol_token, None)
1447 self.assertEqual(res_token, '-4')
1448 self.assertEqual(spin_token, None)
1449
1450
1452 """Test the generic_fns.mol_res_spin.tokenise() function on the string '#CaM'."""
1453
1454
1455 mol_token, res_token, spin_token = mol_res_spin.tokenise('#CaM')
1456
1457
1458 self.assertEqual(mol_token, 'CaM')
1459 self.assertEqual(res_token, None)
1460 self.assertEqual(spin_token, None)
1461
1462
1464 """Test the generic_fns.mol_res_spin.tokenise() function on the string ':G@N3'."""
1465
1466
1467 mol_token, res_token, spin_token = mol_res_spin.tokenise(':G@N3')
1468
1469
1470 self.assertEqual(mol_token, None)
1471 self.assertEqual(res_token, 'G')
1472 self.assertEqual(spin_token, 'N3')
1473
1474
1476 """Test the generic_fns.mol_res_spin.tokenise() function on the string '#OMP@NH'."""
1477
1478
1479 mol_token, res_token, spin_token = mol_res_spin.tokenise('#OMP@NH')
1480
1481
1482 self.assertEqual(mol_token, 'OMP')
1483 self.assertEqual(res_token, None)
1484 self.assertEqual(spin_token, 'NH')
1485
1486
1488 """Test the generic_fns.mol_res_spin.tokenise() function on the string '#Lyso:20-50'."""
1489
1490
1491 mol_token, res_token, spin_token = mol_res_spin.tokenise('#Lyso:20-50')
1492
1493
1494 self.assertEqual(mol_token, 'Lyso')
1495 self.assertEqual(res_token, '20-50')
1496 self.assertEqual(spin_token, None)
1497
1498
1500 """Test the generic_fns.mol_res_spin.tokenise() function on the string '#Ap4Aase:*@N,CA'."""
1501
1502
1503 mol_token, res_token, spin_token = mol_res_spin.tokenise('#Ap4Aase:*@N,CA')
1504
1505
1506 self.assertEqual(mol_token, 'Ap4Aase')
1507 self.assertEqual(res_token, '*')
1508 self.assertEqual(spin_token, 'N,CA')
1509
1510
1512 """Test the generic_fns.mol_res_spin.tokenise() function on the string '@N*'."""
1513
1514
1515 mol_token, res_token, spin_token = mol_res_spin.tokenise('@N*')
1516
1517
1518 self.assertEqual(mol_token, None)
1519 self.assertEqual(res_token, None)
1520 self.assertEqual(spin_token, 'N*')
1521
1522
1524 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@N@1'.
1525
1526 This tests for a duplicated atom identifier.
1527 """
1528
1529
1530 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@N@1')
1531
1532
1534 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ':*@N@1'.
1535
1536 This tests for a duplicated atom identifier.
1537 """
1538
1539
1540 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':*@N@1')
1541
1542
1544 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@N:*@1'.
1545
1546 This tests for a duplicated atom identifier.
1547 """
1548
1549
1550 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@N:*@1')
1551
1552
1554 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ':1:2'.
1555
1556 This tests for a duplicated residue identifier.
1557 """
1558
1559
1560 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':1:2')
1561
1562
1564 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '#None:1:Ala'.
1565
1566 This tests for a duplicated residue identifier.
1567 """
1568
1569
1570 self.assertRaises(RelaxError, mol_res_spin.tokenise, '#None:1:Ala')
1571
1572
1574 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ':1:Ala@N'.
1575
1576 This tests for a duplicated residue identifier.
1577 """
1578
1579
1580 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':1:Ala@N')
1581
1582
1584 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '#A#B'.
1585
1586 This tests for a duplicated molecule identifier.
1587 """
1588
1589
1590 self.assertRaises(RelaxError, mol_res_spin.tokenise, '#A#B')
1591
1592
1594 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '#A#B:Leu'.
1595
1596 This tests for a duplicated molecule identifier.
1597 """
1598
1599
1600 self.assertRaises(RelaxError, mol_res_spin.tokenise, '#A#B:Leu')
1601
1602
1604 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '#A#C@CA'.
1605
1606 This tests for a duplicated molecule identifier.
1607 """
1608
1609
1610 self.assertRaises(RelaxError, mol_res_spin.tokenise, '#A#C@CA')
1611
1612
1614 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@CA#A'.
1615
1616 This tests for an out of order '@' identifier.
1617 """
1618
1619
1620 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@CA#A')
1621
1622
1624 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@CA:Pro'.
1625
1626 This tests for an out of order '@' identifier.
1627 """
1628
1629
1630 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@CA:Pro')
1631
1632
1634 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@CA#Z:Pro'.
1635
1636 This tests for an out of order '@' identifier.
1637 """
1638
1639
1640 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@CA#Z:Pro')
1641
1642
1644 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@CA:Pro'.
1645
1646 This tests for an out of order ':' identifier.
1647 """
1648
1649
1650 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@CA:Pro')
1651
1652
1654 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ':Glu#X'.
1655
1656 This tests for an out of order ':' identifier.
1657 """
1658
1659
1660 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':Glu#X')
1661
1662
1664 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '#1@12423:Glu'.
1665
1666 This tests for an out of order ':' identifier.
1667 """
1668
1669
1670 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':Glu#X')
1671
1672
1674 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ':1-160#A'.
1675
1676 This tests for an out of order '#' identifier.
1677 """
1678
1679
1680 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':1-160#A')
1681
1682
1684 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@N,CA#A'.
1685
1686 This tests for an out of order '#' identifier.
1687 """
1688
1689
1690 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@N,CA#A')
1691
1692
1694 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@N:-10#Zip'.
1695
1696 This tests for an out of order '#' identifier.
1697 """
1698
1699
1700 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@N:-10#Zip')
1701
1702
1704 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '13'.
1705
1706 This tests for an improper selection string.
1707 """
1708
1709
1710 self.assertRaises(RelaxError, mol_res_spin.tokenise, '13')
1711
1712
1714 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string 'XXX'.
1715
1716 This tests for an improper selection string.
1717 """
1718
1719
1720 self.assertRaises(RelaxError, mol_res_spin.tokenise, 'XXX')
1721
1722
1724 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ''.
1725
1726 This tests for an improper selection string.
1727 """
1728
1729
1730 self.assertRaises(RelaxError, mol_res_spin.tokenise, '')
1731
1732
1734 """Test boolean and in mol-res-spin selections."""
1735
1736
1737 sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro"))
1738
1739
1740 self.assertEqual(len(sel), 1)
1741 for res in sel:
1742 self.assert_(res.name == "Pro" and res.num == 4)
1743
1744
1746 """Test complex boolean mol-res-spin selections."""
1747
1748
1749 sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro | #RNA"))
1750
1751
1752 names = ['Pro', None, None]
1753 numbers = [4, -5, -4]
1754
1755
1756 self.assertEqual(len(sel), 3)
1757 for i in range(3):
1758 self.assertEqual(sel[i].name, names[i])
1759 self.assertEqual(sel[i].num, numbers[i])
1760
1761
1762
1763
1764
1766 """Test complex boolean mol-res-spin selections with parenthesis."""
1767
1768
1769 sel = list(mol_res_spin.residue_loop("(#Ap4Aase & :Pro) | (#RNA & :-4)"))
1770
1771
1772 self.assertEqual(len(sel), 2)
1773 for res in sel:
1774 self.assert_(res.num in [-4, 4])
1775