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