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@63'."""
425
426
427 obj = mol_res_spin.Selection("#Ap4Aase:2@63")
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@16")
444
445
446 obj = mol_res_spin.Selection(":13")
447
448
449 self.assertEqual(obj._union, None)
450 self.assertEqual(obj._intersect, None)
451 self.assertEqual(obj.molecules, [])
452 self.assertEqual(obj.residues, [13])
453 self.assertEqual(obj.spins, [])
454
455
467
468
470 """Test that the number of spins (zero) can be properly counted.
471
472 The function tested is generic_fns.mol_res_spin.count_spins().
473 """
474
475
476 reset()
477
478
479 ds.add(pipe_name='orig', pipe_type='mf')
480
481
482 self.assertEqual(mol_res_spin.count_spins(), 0)
483
484
486 """Test that the counting of the number of spins raises an error when no pipe exists.
487
488 The function tested is generic_fns.mol_res_spin.count_spins().
489 """
490
491
492 reset()
493
494
495 self.assertRaises(RelaxNoPipeError, mol_res_spin.count_spins)
496
497
499 """Test the function for determining if molecule-residue-spin data exists.
500
501 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
502 """
503
504
505 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
506
507
509 """Determine if molecule-residue-spin data exists (with data for a single molecule).
510
511 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
512 """
513
514
515 reset()
516
517
518 ds.add(pipe_name='orig', pipe_type='mf')
519 dp = pipes.get_pipe('orig')
520
521
522 dp.mol[0].name = 'TOM40'
523
524
525 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
526
527
529 """Determine if molecule-residue-spin data exists (when a single residue is named).
530
531 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
532 """
533
534
535 reset()
536
537
538 ds.add(pipe_name='orig', pipe_type='mf')
539 dp = pipes.get_pipe('orig')
540
541
542 dp.mol[0].res[0].name = 'Lys'
543
544
545 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
546
547
549 """Determine if molecule-residue-spin data exists (when a single residue is numbered).
550
551 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
552 """
553
554
555 reset()
556
557
558 ds.add(pipe_name='orig', pipe_type='mf')
559 dp = pipes.get_pipe('orig')
560
561
562 dp.mol[0].res[0].num = 1
563
564
565 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
566
567
569 """Determine if molecule-residue-spin data exists (when a single spin is named).
570
571 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
572 """
573
574
575 reset()
576
577
578 ds.add(pipe_name='orig', pipe_type='mf')
579 dp = pipes.get_pipe('orig')
580
581
582 dp.mol[0].res[0].spin[0].name = 'NH'
583
584
585 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
586
587
589 """Determine if molecule-residue-spin data exists (when a single spin is numbered).
590
591 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
592 """
593
594
595 reset()
596
597
598 ds.add(pipe_name='orig', pipe_type='mf')
599 dp = pipes.get_pipe('orig')
600
601
602 dp.mol[0].res[0].spin[0].num = 234
603
604
605 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
606
607
609 """Determine if molecule-residue-spin data exists when no data exists.
610
611 The function tested is generic_fns.mol_res_spin.exists_mol_res_spin_data().
612 """
613
614
615 reset()
616
617
618 ds.add(pipe_name='orig', pipe_type='mf')
619
620
621 self.failIf(mol_res_spin.exists_mol_res_spin_data())
622
623
635
636
638 """First test of the spin ID generation function.
639
640 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
641 """
642
643
644 data = ['1', 'GLY']
645
646
647 id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2)
648
649
650 self.assertEqual(id, ':1')
651
652
654 """Second test of the spin ID generation function.
655
656 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
657 """
658
659
660 data = ['1', 'GLY', '234', 'NH']
661
662
663 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)
664
665
666 self.assertEqual(id, ':1@234')
667
668
670 """Third test of the spin ID generation function.
671
672 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
673 """
674
675
676 data = ['Ap4Aase', '234', 'NH']
677
678
679 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)
680
681
682 self.assertEqual(id, '#Ap4Aase@234')
683
684
686 """Fourth test of the spin ID generation function.
687
688 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
689 """
690
691
692 data = ['Ap4Aase', '1', 'GLY']
693
694
695 id = mol_res_spin.generate_spin_id_data_array(data, mol_name_col=1, res_num_col=2, res_name_col=3)
696
697
698 self.assertEqual(id, '#Ap4Aase:1')
699
700
702 """Fifth test of the spin ID generation function.
703
704 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
705 """
706
707
708 data = ['Ap4Aase', '1', 'GLY', '234', 'NH']
709
710
711 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)
712
713
714 self.assertEqual(id, '#Ap4Aase:1@234')
715
716
718 """Sixth test of the spin ID generation function.
719
720 The function tested is generic_fns.mol_res_spin.generate_spin_id_data_array().
721 """
722
723
724 data = ['1', 'GLY', None, None]
725
726
727 id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2)
728
729
730 self.assertEqual(id, ':1')
731
732
734 """Test the proper operation of the molecule loop with molecule selection.
735
736 The function tested is generic_fns.mol_res_spin.molecule_loop().
737 """
738
739
740 for mol in mol_res_spin.molecule_loop('#RNA'):
741
742 self.assertEqual(mol.name, 'RNA')
743
744
745 self.assertEqual(len(list(mol_res_spin.molecule_loop('#RNA'))), 1)
746
747
749 """Test the proper operation of the molecule loop when no data is present.
750
751 The function tested is generic_fns.mol_res_spin.molecule_loop().
752 """
753
754
755 reset()
756
757
758 ds.add(pipe_name='orig', pipe_type='mf')
759
760
761 i = 0
762 for molecule in mol_res_spin.molecule_loop():
763 i = i + 1
764
765
766 self.assertEqual(i, 0)
767
768
770 """Test the proper operation of the molecule loop when no data pipe is present.
771
772 The function tested is generic_fns.mol_res_spin.molecule_loop().
773 """
774
775
776 reset()
777
778
779 def fail_test():
780 for molecule in mol_res_spin.molecule_loop():
781 pass
782
783
784 self.assertRaises(RelaxNoPipeError, fail_test)
785
786
788 """Test the proper operation of the molecule loop when no selection is present.
789
790 The function tested is generic_fns.mol_res_spin.molecule_loop().
791 """
792
793
794 name = ['Ap4Aase', 'RNA']
795
796
797 i = 0
798 for mol in mol_res_spin.molecule_loop():
799
800 self.assertEqual(mol.name, name[i])
801
802
803 i = i + 1
804
805
806 self.assertEqual(len(list(mol_res_spin.molecule_loop())), 2)
807
808
809
811 """Test the generic_fns.mol_res_spin.parse_token() function on the string '1'."""
812
813
814 list = mol_res_spin.parse_token('1')
815
816
817 self.assertEqual(len(list), 1)
818 self.assertEqual(list[0], 1)
819
820
822 """Test the generic_fns.mol_res_spin.parse_token() function on the string '-4'."""
823
824
825 list = mol_res_spin.parse_token('-4')
826
827
828 self.assertEqual(len(list), 1)
829 self.assertEqual(list[0], -4)
830
831
833 """Test the generic_fns.mol_res_spin.parse_token() function on the string 'G'."""
834
835
836 list = mol_res_spin.parse_token('G')
837
838
839 self.assertEqual(len(list), 1)
840 self.assertEqual(list[0], 'G')
841
842
844 """Test the generic_fns.mol_res_spin.parse_token() function on the string 'N*'."""
845
846
847 list = mol_res_spin.parse_token('N*')
848
849
850 self.assertEqual(len(list), 1)
851 self.assertEqual(list[0], 'N*')
852
853
855 """Test the generic_fns.mol_res_spin.parse_token() function on the string '1-10'."""
856
857
858 list = mol_res_spin.parse_token('1-10')
859
860
861 self.assertEqual(len(list), 10)
862 for i in range(1, 11):
863 self.assertEqual(list[i-1], i)
864
865
867 """Test the generic_fns.mol_res_spin.parse_token() function on the string '-10--1'."""
868
869
870 list = mol_res_spin.parse_token('-10--1')
871
872
873 self.assertEqual(len(list), 10)
874 j = 0
875 for i in range(-10, -2):
876 self.assertEqual(list[j], i)
877 j = j + 1
878
879
881 """Test the generic_fns.mol_res_spin.parse_token() function on the string '-2, 1'."""
882
883
884 list = mol_res_spin.parse_token('-2, 1')
885
886
887 self.assertEqual(len(list), 2)
888 self.assertEqual(list[0], -2)
889 self.assertEqual(list[1], 1)
890
891
893 """Test the generic_fns.mol_res_spin.parse_token() function on the string 'N,CA'."""
894
895
896 list = mol_res_spin.parse_token('N,CA')
897
898
899 self.assertEqual(len(list), 2)
900 self.assertEqual(list[0], 'CA')
901 self.assertEqual(list[1], 'N')
902
903
905 """Test the generic_fns.mol_res_spin.parse_token() function on the string '76,Ala'."""
906
907
908 list = mol_res_spin.parse_token('76,Ala')
909
910
911 self.assertEqual(len(list), 2)
912 self.assertEqual(list[0], 76)
913 self.assertEqual(list[1], 'Ala')
914
915
917 """Test the generic_fns.mol_res_spin.parse_token() function on the string '1,3-5'."""
918
919
920 list = mol_res_spin.parse_token('1,3-5')
921
922
923 self.assertEqual(len(list), 4)
924 self.assertEqual(list[0], 1)
925 self.assertEqual(list[1], 3)
926 self.assertEqual(list[2], 4)
927 self.assertEqual(list[3], 5)
928
929
931 """Test the generic_fns.mol_res_spin.parse_token() function on the string '3-5,NH'."""
932
933
934 list = mol_res_spin.parse_token('3-5,NH')
935
936
937 self.assertEqual(len(list), 4)
938 self.assertEqual(list[0], 3)
939 self.assertEqual(list[1], 4)
940 self.assertEqual(list[2], 5)
941 self.assertEqual(list[3], 'NH')
942
943
945 """Test the generic_fns.mol_res_spin.parse_token() function on the string '3-6, 8, Gly'."""
946
947
948 list = mol_res_spin.parse_token('3-6, 8, Gly')
949
950
951 self.assertEqual(len(list), 6)
952 self.assertEqual(list[0], 3)
953 self.assertEqual(list[1], 4)
954 self.assertEqual(list[2], 5)
955 self.assertEqual(list[3], 6)
956 self.assertEqual(list[4], 8)
957 self.assertEqual(list[5], 'Gly')
958
959
961 """Test the proper operation of the residue loop with residue selection.
962
963 The function tested is generic_fns.mol_res_spin.residue_loop().
964 """
965
966
967 for res in mol_res_spin.residue_loop('#Ap4Aase:Glu'):
968
969 self.assertEqual(res.num, 2)
970
971
972 self.assertEqual(len(list(mol_res_spin.residue_loop('#Ap4Aase:Glu'))), 1)
973
974
976 """Test the proper operation of the residue loop when no data is present.
977
978 The function tested is generic_fns.mol_res_spin.residue_loop().
979 """
980
981
982 reset()
983
984
985 ds.add(pipe_name='orig', pipe_type='mf')
986
987
988 i = 0
989 for residue in mol_res_spin.residue_loop():
990 i = i + 1
991
992
993 self.assertEqual(i, 0)
994
995
997 """Test the proper operation of the residue loop when no data pipe is present.
998
999 The function tested is generic_fns.mol_res_spin.residue_loop().
1000 """
1001
1002
1003 reset()
1004
1005
1006 def fail_test():
1007 for residue in mol_res_spin.residue_loop():
1008 pass
1009
1010
1011 self.assertRaises(RelaxNoPipeError, fail_test)
1012
1013
1015 """Test the proper operation of the residue loop when no selection is present.
1016
1017 The function tested is generic_fns.mol_res_spin.residue_loop().
1018 """
1019
1020
1021 num = [1, 2, 4, -5, -4]
1022 name = [None, 'Glu', 'Pro', None, None]
1023
1024
1025 i = 0
1026 for res in mol_res_spin.residue_loop():
1027
1028 self.assertEqual(res.num, num[i])
1029
1030
1031 self.assertEqual(res.name, name[i])
1032
1033
1034 i = i + 1
1035
1036
1037 self.assertEqual(i, 5)
1038
1039
1041 """Test the function for returning the desired molecule data container.
1042
1043 The function tested is generic_fns.mol_res_spin.return_molecule().
1044 """
1045
1046
1047 mol1 = mol_res_spin.return_molecule('#Ap4Aase')
1048 mol2 = mol_res_spin.return_molecule(selection='#RNA', pipe='orig')
1049
1050
1051 self.assertEqual(mol1.name, 'Ap4Aase')
1052
1053
1054 self.assertEqual(mol2.name, 'RNA')
1055
1056
1066
1067
1069 """Test the function for returning the desired residue data container.
1070
1071 The function tested is generic_fns.mol_res_spin.return_residue().
1072 """
1073
1074
1075 res1 = mol_res_spin.return_residue(':1')
1076 res2 = mol_res_spin.return_residue(selection=':2')
1077 res4 = mol_res_spin.return_residue(selection=':4', pipe='orig')
1078 res5 = mol_res_spin.return_residue(selection='#RNA:-5', pipe='orig')
1079
1080
1081 self.assertEqual(res1.num, 1)
1082 self.assertEqual(res1.name, None)
1083
1084
1085 self.assertEqual(res2.num, 2)
1086 self.assertEqual(res2.name, 'Glu')
1087
1088
1089 self.assertEqual(res4.num, 4)
1090 self.assertEqual(res4.name, 'Pro')
1091
1092
1093 self.assertEqual(res5.num, -5)
1094 self.assertEqual(res5.name, None)
1095 self.assertEqual(res5.spin[1].name, 'N5')
1096
1097
1099 """Test the failure of the function for returning the desired residue data container.
1100
1101 The function tested is generic_fns.mol_res_spin.return_residue().
1102 """
1103
1104
1105 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_residue, selection=':2', pipe='new')
1106
1107
1109 """Test the function for returning the desired residue data container.
1110
1111 The function tested is generic_fns.mol_res_spin.return_single_residue_info().
1112 """
1113
1114
1115 res1 = mol_res_spin.return_single_residue_info('1')
1116 res2 = mol_res_spin.return_single_residue_info('2,Glu')
1117 res4 = mol_res_spin.return_single_residue_info('Pro,4')
1118 res5 = mol_res_spin.return_single_residue_info('-5')
1119
1120
1121 self.assertEqual(res1, (1, None))
1122
1123
1124 self.assertEqual(res2, (2, 'Glu'))
1125
1126
1127 self.assertEqual(res4, (4, 'Pro'))
1128
1129
1130 self.assertEqual(res5, (-5, None))
1131
1132
1134 """Test the failure of the function for returning the desired residue data container.
1135
1136 The function tested is generic_fns.mol_res_spin.return_single_residue_info().
1137 """
1138
1139
1140 self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,2')
1141 self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,Glu,Pro')
1142 self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,2,Glu,Pro')
1143
1144
1146 """Test the function for returning the desired spin data container.
1147
1148 The function tested is generic_fns.mol_res_spin.return_spin().
1149 """
1150
1151
1152 spin1 = mol_res_spin.return_spin(':1')
1153 spin2 = mol_res_spin.return_spin(selection=':2')
1154 spin3 = mol_res_spin.return_spin(selection=':4', pipe='orig')
1155 spin4 = mol_res_spin.return_spin(selection='#RNA:-5@N5', pipe='orig')
1156 spin5 = mol_res_spin.return_spin(selection=':-4@2H', pipe='orig')
1157
1158
1159 self.assertNotEqual(spin1, None)
1160 self.assertEqual(spin1.num, 60)
1161 self.assertEqual(spin1.name, 'NH')
1162
1163
1164 self.assertNotEqual(spin2, None)
1165 self.assertEqual(spin2.num, 63)
1166 self.assertEqual(spin2.name, 'NH')
1167
1168
1169 self.assertNotEqual(spin3, None)
1170 self.assertEqual(spin3.num, None)
1171 self.assertEqual(spin3.name, None)
1172
1173
1174 self.assertNotEqual(spin4, None)
1175 self.assertEqual(spin4.num, None)
1176 self.assertEqual(spin4.name, 'N5')
1177
1178
1179 self.assertNotEqual(spin5, None)
1180 self.assertEqual(spin5.num, 132)
1181 self.assertEqual(spin5.name, '2H')
1182
1183
1185 """Test the failure of the function for returning the desired spin data container.
1186
1187 The function tested is generic_fns.mol_res_spin.return_spin().
1188 """
1189
1190
1191 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_spin, selection=':2', pipe='new')
1192
1193
1195 """Test the proper operation of the spin loop with spin selection.
1196
1197 The function tested is generic_fns.mol_res_spin.spin_loop().
1198 """
1199
1200
1201 select = [1, 0]
1202
1203
1204 i = 0
1205 for spin in mol_res_spin.spin_loop('@N5'):
1206
1207 self.assertEqual(spin.select, select[i])
1208
1209
1210 self.assertEqual(spin.name, 'N5')
1211
1212
1213 i = i + 1
1214
1215
1216 self.assertEqual(i, 2)
1217
1218
1220 """Test the operation of the spin loop with the selection "#Ap4Aase:Glu | #RNA@C8".
1221
1222 The function tested is generic_fns.mol_res_spin.spin_loop().
1223 """
1224
1225
1226 select = [1, 0, 1]
1227 name = ['NH', 'C8', 'C8']
1228 num = [63, None, None]
1229
1230
1231 i = 0
1232 for spin in mol_res_spin.spin_loop("#Ap4Aase:Glu | #RNA@C8"):
1233
1234 self.assertEqual([spin.select, spin.name, spin.num], [select[i], name[i], num[i]])
1235
1236
1237 i = i + 1
1238
1239
1240 self.assertEqual(i, 3)
1241
1242
1244 """Test the proper operation of the spin loop with spin selection '@NH|@N5'.
1245
1246 The function tested is generic_fns.mol_res_spin.spin_loop().
1247 """
1248
1249
1250 select = [0, 1, 1, 0]
1251 name = ['NH', 'NH', 'N5', 'N5']
1252
1253
1254 i = 0
1255 for spin in mol_res_spin.spin_loop('@NH|@N5'):
1256
1257 self.assertEqual(spin.select, select[i])
1258
1259
1260 self.assertEqual(spin.name, name[i])
1261
1262
1263 i = i + 1
1264
1265
1266 self.assertEqual(i, 4)
1267
1268
1270 """Test the proper operation of the spin loop when no data is present.
1271
1272 The function tested is generic_fns.mol_res_spin.spin_loop().
1273 """
1274
1275
1276 reset()
1277
1278
1279 ds.add(pipe_name='orig', pipe_type='mf')
1280
1281
1282 i = 0
1283 for spin in mol_res_spin.spin_loop():
1284 i = i + 1
1285
1286
1287 self.assertEqual(i, 0)
1288
1289
1291 """Test the proper operation of the spin loop when no data pipe is present.
1292
1293 The function tested is generic_fns.mol_res_spin.spin_loop().
1294 """
1295
1296
1297 reset()
1298
1299
1300 def fail_test():
1301 for spin in mol_res_spin.spin_loop():
1302 pass
1303
1304
1305 self.assertRaises(RelaxNoPipeError, fail_test)
1306
1307
1309 """Test the proper operation of the spin loop when no selection is present.
1310
1311 The function tested is generic_fns.mol_res_spin.spin_loop().
1312 """
1313
1314
1315 select = [0, 1, 0, 0, 1, 1, 0, 1]
1316 name = ['NH', 'NH', None, 'C8', 'N5', 'C8', 'N5', '2H']
1317
1318
1319 i = 0
1320 for spin in mol_res_spin.spin_loop():
1321
1322 self.assertEqual(spin.select, select[i])
1323
1324
1325 self.assertEqual(spin.name, name[i])
1326
1327
1328 i = i + 1
1329
1330
1331 self.assertEqual(i, 8)
1332
1333
1335 """Test the operation of the spin loop with the single spin selection '#Ap4Aase:Glu@63'.
1336
1337 The function tested is generic_fns.mol_res_spin.spin_loop().
1338 """
1339
1340
1341 i = 0
1342 for spin in mol_res_spin.spin_loop('#Ap4Aase:Glu@63'):
1343
1344 self.assertEqual(spin.select, 1)
1345
1346
1347 self.assertEqual(spin.name, 'NH')
1348
1349
1350 self.assertEqual(spin.num, 63)
1351
1352
1353 i = i + 1
1354
1355
1356 self.assertEqual(i, 1)
1357
1358
1360 """Test the proper operation of the spin loop with wildcard spin selection '@N*'.
1361
1362 The function tested is generic_fns.mol_res_spin.spin_loop().
1363 """
1364
1365
1366 select = [0, 1, 1, 0]
1367 name = ['NH', 'NH', 'N5', 'N5']
1368
1369
1370 i = 0
1371 for spin in mol_res_spin.spin_loop('@N*'):
1372
1373 self.assertEqual(spin.select, select[i])
1374
1375
1376 self.assertEqual(spin.name, name[i])
1377
1378
1379 i = i + 1
1380
1381
1382 self.assertEqual(i, 4)
1383
1384
1386 """Test the generic_fns.mol_res_spin.tokenise() function on the string '@1'."""
1387
1388
1389 mol_token, res_token, spin_token = mol_res_spin.tokenise('@1')
1390
1391
1392 self.assertEqual(mol_token, None)
1393 self.assertEqual(res_token, None)
1394 self.assertEqual(spin_token, '1')
1395
1396
1398 """Test the generic_fns.mol_res_spin.tokenise() function on the string ':-4'."""
1399
1400
1401 mol_token, res_token, spin_token = mol_res_spin.tokenise(':-4')
1402
1403
1404 self.assertEqual(mol_token, None)
1405 self.assertEqual(res_token, '-4')
1406 self.assertEqual(spin_token, None)
1407
1408
1410 """Test the generic_fns.mol_res_spin.tokenise() function on the string '#CaM'."""
1411
1412
1413 mol_token, res_token, spin_token = mol_res_spin.tokenise('#CaM')
1414
1415
1416 self.assertEqual(mol_token, 'CaM')
1417 self.assertEqual(res_token, None)
1418 self.assertEqual(spin_token, None)
1419
1420
1422 """Test the generic_fns.mol_res_spin.tokenise() function on the string ':G@N3'."""
1423
1424
1425 mol_token, res_token, spin_token = mol_res_spin.tokenise(':G@N3')
1426
1427
1428 self.assertEqual(mol_token, None)
1429 self.assertEqual(res_token, 'G')
1430 self.assertEqual(spin_token, 'N3')
1431
1432
1434 """Test the generic_fns.mol_res_spin.tokenise() function on the string '#OMP@NH'."""
1435
1436
1437 mol_token, res_token, spin_token = mol_res_spin.tokenise('#OMP@NH')
1438
1439
1440 self.assertEqual(mol_token, 'OMP')
1441 self.assertEqual(res_token, None)
1442 self.assertEqual(spin_token, 'NH')
1443
1444
1446 """Test the generic_fns.mol_res_spin.tokenise() function on the string '#Lyso:20-50'."""
1447
1448
1449 mol_token, res_token, spin_token = mol_res_spin.tokenise('#Lyso:20-50')
1450
1451
1452 self.assertEqual(mol_token, 'Lyso')
1453 self.assertEqual(res_token, '20-50')
1454 self.assertEqual(spin_token, None)
1455
1456
1458 """Test the generic_fns.mol_res_spin.tokenise() function on the string '#Ap4Aase:*@N,CA'."""
1459
1460
1461 mol_token, res_token, spin_token = mol_res_spin.tokenise('#Ap4Aase:*@N,CA')
1462
1463
1464 self.assertEqual(mol_token, 'Ap4Aase')
1465 self.assertEqual(res_token, '*')
1466 self.assertEqual(spin_token, 'N,CA')
1467
1468
1470 """Test the generic_fns.mol_res_spin.tokenise() function on the string '@N*'."""
1471
1472
1473 mol_token, res_token, spin_token = mol_res_spin.tokenise('@N*')
1474
1475
1476 self.assertEqual(mol_token, None)
1477 self.assertEqual(res_token, None)
1478 self.assertEqual(spin_token, 'N*')
1479
1480
1482 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@N@1'.
1483
1484 This tests for a duplicated atom identifier.
1485 """
1486
1487
1488 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@N@1')
1489
1490
1492 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ':*@N@1'.
1493
1494 This tests for a duplicated atom identifier.
1495 """
1496
1497
1498 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':*@N@1')
1499
1500
1502 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@N:*@1'.
1503
1504 This tests for a duplicated atom identifier.
1505 """
1506
1507
1508 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@N:*@1')
1509
1510
1512 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ':1:2'.
1513
1514 This tests for a duplicated residue identifier.
1515 """
1516
1517
1518 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':1:2')
1519
1520
1522 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '#None:1:Ala'.
1523
1524 This tests for a duplicated residue identifier.
1525 """
1526
1527
1528 self.assertRaises(RelaxError, mol_res_spin.tokenise, '#None:1:Ala')
1529
1530
1532 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ':1:Ala@N'.
1533
1534 This tests for a duplicated residue identifier.
1535 """
1536
1537
1538 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':1:Ala@N')
1539
1540
1542 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '#A#B'.
1543
1544 This tests for a duplicated molecule identifier.
1545 """
1546
1547
1548 self.assertRaises(RelaxError, mol_res_spin.tokenise, '#A#B')
1549
1550
1552 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '#A#B:Leu'.
1553
1554 This tests for a duplicated molecule identifier.
1555 """
1556
1557
1558 self.assertRaises(RelaxError, mol_res_spin.tokenise, '#A#B:Leu')
1559
1560
1562 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '#A#C@CA'.
1563
1564 This tests for a duplicated molecule identifier.
1565 """
1566
1567
1568 self.assertRaises(RelaxError, mol_res_spin.tokenise, '#A#C@CA')
1569
1570
1572 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@CA#A'.
1573
1574 This tests for an out of order '@' identifier.
1575 """
1576
1577
1578 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@CA#A')
1579
1580
1582 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@CA:Pro'.
1583
1584 This tests for an out of order '@' identifier.
1585 """
1586
1587
1588 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@CA:Pro')
1589
1590
1592 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@CA#Z:Pro'.
1593
1594 This tests for an out of order '@' identifier.
1595 """
1596
1597
1598 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@CA#Z:Pro')
1599
1600
1602 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@CA:Pro'.
1603
1604 This tests for an out of order ':' identifier.
1605 """
1606
1607
1608 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@CA:Pro')
1609
1610
1612 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ':Glu#X'.
1613
1614 This tests for an out of order ':' identifier.
1615 """
1616
1617
1618 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':Glu#X')
1619
1620
1622 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '#1@12423:Glu'.
1623
1624 This tests for an out of order ':' identifier.
1625 """
1626
1627
1628 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':Glu#X')
1629
1630
1632 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ':1-160#A'.
1633
1634 This tests for an out of order '#' identifier.
1635 """
1636
1637
1638 self.assertRaises(RelaxError, mol_res_spin.tokenise, ':1-160#A')
1639
1640
1642 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@N,CA#A'.
1643
1644 This tests for an out of order '#' identifier.
1645 """
1646
1647
1648 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@N,CA#A')
1649
1650
1652 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '@N:-10#Zip'.
1653
1654 This tests for an out of order '#' identifier.
1655 """
1656
1657
1658 self.assertRaises(RelaxError, mol_res_spin.tokenise, '@N:-10#Zip')
1659
1660
1662 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string '13'.
1663
1664 This tests for an improper selection string.
1665 """
1666
1667
1668 self.assertRaises(RelaxError, mol_res_spin.tokenise, '13')
1669
1670
1672 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string 'XXX'.
1673
1674 This tests for an improper selection string.
1675 """
1676
1677
1678 self.assertRaises(RelaxError, mol_res_spin.tokenise, 'XXX')
1679
1680
1682 """Test failure of the generic_fns.mol_res_spin.tokenise() function on the string ''.
1683
1684 This tests for an improper selection string.
1685 """
1686
1687
1688 self.assertRaises(RelaxError, mol_res_spin.tokenise, '')
1689
1690
1692 """Test boolean and in mol-res-spin selections."""
1693
1694
1695 sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro"))
1696
1697
1698 self.assertEqual(len(sel), 1)
1699 for res in sel:
1700 self.assert_(res.name == "Pro" and res.num == 4)
1701
1702
1704 """Test complex boolean mol-res-spin selections."""
1705
1706
1707 sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro | #RNA"))
1708
1709
1710 names = ['Pro', None, None]
1711 numbers = [4, -5, -4]
1712
1713
1714 self.assertEqual(len(sel), 3)
1715 for i in xrange(3):
1716 self.assertEqual(sel[i].name, names[i])
1717 self.assertEqual(sel[i].num, numbers[i])
1718
1719
1720
1721
1722
1724 """Test complex boolean mol-res-spin selections with parenthesis."""
1725
1726
1727 sel = list(mol_res_spin.residue_loop("(#Ap4Aase & :Pro) | (#RNA & :-4)"))
1728
1729
1730 self.assertEqual(len(sel), 2)
1731 for res in sel:
1732 self.assert_(res.num in [-4, 4])
1733