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_store import Relax_data_store; ds = Relax_data_store()
24 from pipe_control import mol_res_spin, pipes
25 from pipe_control.reset import reset
26 from lib.errors import RelaxError, RelaxNoPipeError
27 from test_suite.unit_tests.base_classes import UnitTestCase
28
29
31 """Unit tests for the functions of the 'pipe_control.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
88
89
91 """Test that the number of spins (zero) can be properly counted.
92
93 The function tested is pipe_control.mol_res_spin.count_spins().
94 """
95
96
97 reset()
98
99
100 ds.add(pipe_name='orig', pipe_type='mf')
101
102
103 self.assertEqual(mol_res_spin.count_spins(), 0)
104
105
107 """Test that the counting of the number of spins raises an error when no pipe exists.
108
109 The function tested is pipe_control.mol_res_spin.count_spins().
110 """
111
112
113 reset()
114
115
116 self.assertRaises(RelaxNoPipeError, mol_res_spin.count_spins)
117
118
120 """Test the function for determining if molecule-residue-spin data exists.
121
122 The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data().
123 """
124
125
126 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
127
128
130 """Determine if molecule-residue-spin data exists (with data for a single molecule).
131
132 The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data().
133 """
134
135
136 reset()
137
138
139 ds.add(pipe_name='orig', pipe_type='mf')
140 dp = pipes.get_pipe('orig')
141
142
143 dp.mol[0].name = 'TOM40'
144
145
146 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
147
148
150 """Determine if molecule-residue-spin data exists (when a single residue is named).
151
152 The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data().
153 """
154
155
156 reset()
157
158
159 ds.add(pipe_name='orig', pipe_type='mf')
160 dp = pipes.get_pipe('orig')
161
162
163 dp.mol[0].res[0].name = 'Lys'
164
165
166 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
167
168
170 """Determine if molecule-residue-spin data exists (when a single residue is numbered).
171
172 The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data().
173 """
174
175
176 reset()
177
178
179 ds.add(pipe_name='orig', pipe_type='mf')
180 dp = pipes.get_pipe('orig')
181
182
183 dp.mol[0].res[0].num = 1
184
185
186 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
187
188
190 """Determine if molecule-residue-spin data exists (when a single spin is named).
191
192 The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data().
193 """
194
195
196 reset()
197
198
199 ds.add(pipe_name='orig', pipe_type='mf')
200 dp = pipes.get_pipe('orig')
201
202
203 dp.mol[0].res[0].spin[0].name = 'NH'
204
205
206 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
207
208
210 """Determine if molecule-residue-spin data exists (when a single spin is numbered).
211
212 The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data().
213 """
214
215
216 reset()
217
218
219 ds.add(pipe_name='orig', pipe_type='mf')
220 dp = pipes.get_pipe('orig')
221
222
223 dp.mol[0].res[0].spin[0].num = 234
224
225
226 self.failUnless(mol_res_spin.exists_mol_res_spin_data())
227
228
230 """Determine if molecule-residue-spin data exists when no data exists.
231
232 The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data().
233 """
234
235
236 reset()
237
238
239 ds.add(pipe_name='orig', pipe_type='mf')
240
241
242 self.failIf(mol_res_spin.exists_mol_res_spin_data())
243
244
256
257
259 """First test of the spin ID generation function.
260
261 The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array().
262 """
263
264
265 data = ['1', 'GLY']
266
267
268 id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2)
269
270
271 self.assertEqual(id, ':1')
272
273
275 """Second test of the spin ID generation function.
276
277 The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array().
278 """
279
280
281 data = ['1', 'GLY', '234', 'NH']
282
283
284 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)
285
286
287 self.assertEqual(id, ':1@234')
288
289
291 """Third test of the spin ID generation function.
292
293 The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array().
294 """
295
296
297 data = ['Ap4Aase', '234', 'NH']
298
299
300 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)
301
302
303 self.assertEqual(id, '#Ap4Aase@234')
304
305
307 """Fourth test of the spin ID generation function.
308
309 The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array().
310 """
311
312
313 data = ['Ap4Aase', '1', 'GLY']
314
315
316 id = mol_res_spin.generate_spin_id_data_array(data, mol_name_col=1, res_num_col=2, res_name_col=3)
317
318
319 self.assertEqual(id, '#Ap4Aase:1')
320
321
323 """Fifth test of the spin ID generation function.
324
325 The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array().
326 """
327
328
329 data = ['Ap4Aase', '1', 'GLY', '234', 'NH']
330
331
332 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)
333
334
335 self.assertEqual(id, '#Ap4Aase:1@234')
336
337
339 """Sixth test of the spin ID generation function.
340
341 The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array().
342 """
343
344
345 data = ['1', 'GLY', None, None]
346
347
348 id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2)
349
350
351 self.assertEqual(id, ':1')
352
353
355 """Test the proper operation of the molecule loop with molecule selection.
356
357 The function tested is pipe_control.mol_res_spin.molecule_loop().
358 """
359
360
361 for mol in mol_res_spin.molecule_loop('#RNA'):
362
363 self.assertEqual(mol.name, 'RNA')
364
365
366 self.assertEqual(len(list(mol_res_spin.molecule_loop('#RNA'))), 1)
367
368
370 """Test the proper operation of the molecule loop when no data is present.
371
372 The function tested is pipe_control.mol_res_spin.molecule_loop().
373 """
374
375
376 reset()
377
378
379 ds.add(pipe_name='orig', pipe_type='mf')
380
381
382 i = 0
383 for molecule in mol_res_spin.molecule_loop():
384 i = i + 1
385
386
387 self.assertEqual(i, 0)
388
389
391 """Test the proper operation of the molecule loop when no data pipe is present.
392
393 The function tested is pipe_control.mol_res_spin.molecule_loop().
394 """
395
396
397 reset()
398
399
400 def fail_test():
401 for molecule in mol_res_spin.molecule_loop():
402 pass
403
404
405 self.assertRaises(RelaxNoPipeError, fail_test)
406
407
409 """Test the proper operation of the molecule loop when no selection is present.
410
411 The function tested is pipe_control.mol_res_spin.molecule_loop().
412 """
413
414
415 name = ['Ap4Aase', 'RNA']
416
417
418 i = 0
419 for mol in mol_res_spin.molecule_loop():
420
421 self.assertEqual(mol.name, name[i])
422
423
424 i = i + 1
425
426
427 self.assertEqual(len(list(mol_res_spin.molecule_loop())), 2)
428
429
431 """Test the proper operation of the residue loop with residue selection.
432
433 The function tested is pipe_control.mol_res_spin.residue_loop().
434 """
435
436
437 for res in mol_res_spin.residue_loop('#Ap4Aase:Glu'):
438
439 self.assertEqual(res.num, 2)
440
441
442 self.assertEqual(len(list(mol_res_spin.residue_loop('#Ap4Aase:Glu'))), 1)
443
444
446 """Test the proper operation of the residue loop when no data is present.
447
448 The function tested is pipe_control.mol_res_spin.residue_loop().
449 """
450
451
452 reset()
453
454
455 ds.add(pipe_name='orig', pipe_type='mf')
456
457
458 i = 0
459 for residue in mol_res_spin.residue_loop():
460 i = i + 1
461
462
463 self.assertEqual(i, 0)
464
465
467 """Test the proper operation of the residue loop when no data pipe is present.
468
469 The function tested is pipe_control.mol_res_spin.residue_loop().
470 """
471
472
473 reset()
474
475
476 def fail_test():
477 for residue in mol_res_spin.residue_loop():
478 pass
479
480
481 self.assertRaises(RelaxNoPipeError, fail_test)
482
483
485 """Test the proper operation of the residue loop when no selection is present.
486
487 The function tested is pipe_control.mol_res_spin.residue_loop().
488 """
489
490
491 num = [1, 2, 4, -5, -4]
492 name = [None, 'Glu', 'Pro', None, None]
493
494
495 i = 0
496 for res in mol_res_spin.residue_loop():
497
498 self.assertEqual(res.num, num[i])
499
500
501 self.assertEqual(res.name, name[i])
502
503
504 i = i + 1
505
506
507 self.assertEqual(i, 5)
508
509
511 """Test the function for returning the desired molecule data container.
512
513 The function tested is pipe_control.mol_res_spin.return_molecule().
514 """
515
516
517 mol1 = mol_res_spin.return_molecule('#Ap4Aase')
518 mol2 = mol_res_spin.return_molecule(selection='#RNA', pipe='orig')
519
520
521 self.assertEqual(mol1.name, 'Ap4Aase')
522
523
524 self.assertEqual(mol2.name, 'RNA')
525
526
536
537
539 """Test the function for returning the desired residue data container.
540
541 The function tested is pipe_control.mol_res_spin.return_residue().
542 """
543
544
545 res1 = mol_res_spin.return_residue(':1')
546 res2 = mol_res_spin.return_residue(selection=':2')
547 res4 = mol_res_spin.return_residue(selection=':4', pipe='orig')
548 res5 = mol_res_spin.return_residue(selection='#RNA:-5', pipe='orig')
549
550
551 self.assertEqual(res1.num, 1)
552 self.assertEqual(res1.name, None)
553
554
555 self.assertEqual(res2.num, 2)
556 self.assertEqual(res2.name, 'Glu')
557
558
559 self.assertEqual(res4.num, 4)
560 self.assertEqual(res4.name, 'Pro')
561
562
563 self.assertEqual(res5.num, -5)
564 self.assertEqual(res5.name, None)
565 self.assertEqual(res5.spin[1].name, 'N5')
566
567
569 """Test the failure of the function for returning the desired residue data container.
570
571 The function tested is pipe_control.mol_res_spin.return_residue().
572 """
573
574
575 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_residue, selection=':2', pipe='new')
576
577
579 """Test the function for returning the desired residue data container.
580
581 The function tested is pipe_control.mol_res_spin.return_single_residue_info().
582 """
583
584
585 res1 = mol_res_spin.return_single_residue_info('1')
586 res2 = mol_res_spin.return_single_residue_info('2,Glu')
587 res4 = mol_res_spin.return_single_residue_info('Pro,4')
588 res5 = mol_res_spin.return_single_residue_info('-5')
589
590
591 self.assertEqual(res1, (1, None))
592
593
594 self.assertEqual(res2, (2, 'Glu'))
595
596
597 self.assertEqual(res4, (4, 'Pro'))
598
599
600 self.assertEqual(res5, (-5, None))
601
602
604 """Test the failure of the function for returning the desired residue data container.
605
606 The function tested is pipe_control.mol_res_spin.return_single_residue_info().
607 """
608
609
610 self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,2')
611 self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,Glu,Pro')
612 self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,2,Glu,Pro')
613
614
616 """Test the function for returning the desired spin data container.
617
618 The function tested is pipe_control.mol_res_spin.return_spin().
619 """
620
621
622 spin1 = mol_res_spin.return_spin('#Ap4Aase:1')
623 spin2 = mol_res_spin.return_spin(spin_id='#Ap4Aase:2')
624 spin3 = mol_res_spin.return_spin(spin_id='#Ap4Aase:4', pipe='orig')
625 spin4 = mol_res_spin.return_spin(spin_id='#RNA:-5@N5', pipe='orig')
626 spin5 = mol_res_spin.return_spin(spin_id='#RNA:-4@2H', pipe='orig')
627
628
629 self.assertNotEqual(spin1, None)
630 self.assertEqual(spin1.num, 60)
631 self.assertEqual(spin1.name, 'NH')
632
633
634 self.assertNotEqual(spin2, None)
635 self.assertEqual(spin2.num, 63)
636 self.assertEqual(spin2.name, 'NH')
637
638
639 self.assertNotEqual(spin3, None)
640 self.assertEqual(spin3.num, None)
641 self.assertEqual(spin3.name, None)
642
643
644 self.assertNotEqual(spin4, None)
645 self.assertEqual(spin4.num, None)
646 self.assertEqual(spin4.name, 'N5')
647
648
649 self.assertNotEqual(spin5, None)
650 self.assertEqual(spin5.num, 132)
651 self.assertEqual(spin5.name, '2H')
652
653
655 """Test the failure of the function for returning the desired spin data container.
656
657 The function tested is pipe_control.mol_res_spin.return_spin().
658 """
659
660
661 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_spin, spin_id=':2', pipe='new')
662
663
665 """Test the proper operation of the spin loop with spin selection.
666
667 The function tested is pipe_control.mol_res_spin.spin_loop().
668 """
669
670
671 select = [1, 0]
672
673
674 i = 0
675 for spin in mol_res_spin.spin_loop('@N5'):
676
677 self.assertEqual(spin.select, select[i])
678
679
680 self.assertEqual(spin.name, 'N5')
681
682
683 i = i + 1
684
685
686 self.assertEqual(i, 2)
687
688
690 """Test the operation of the spin loop with the selection "#Ap4Aase:Glu | #RNA@C8".
691
692 The function tested is pipe_control.mol_res_spin.spin_loop().
693 """
694
695
696 select = [1, 0, 1]
697 name = ['NH', 'C8', 'C8']
698 num = [63, None, None]
699
700
701 i = 0
702 for spin in mol_res_spin.spin_loop("#Ap4Aase:Glu | #RNA@C8"):
703
704 self.assertEqual([spin.select, spin.name, spin.num], [select[i], name[i], num[i]])
705
706
707 i = i + 1
708
709
710 self.assertEqual(i, 3)
711
712
714 """Test the proper operation of the spin loop with spin selection '@NH|@N5'.
715
716 The function tested is pipe_control.mol_res_spin.spin_loop().
717 """
718
719
720 select = [0, 1, 1, 0]
721 name = ['NH', 'NH', 'N5', 'N5']
722
723
724 i = 0
725 for spin in mol_res_spin.spin_loop('@NH|@N5'):
726
727 self.assertEqual(spin.select, select[i])
728
729
730 self.assertEqual(spin.name, name[i])
731
732
733 i = i + 1
734
735
736 self.assertEqual(i, 4)
737
738
740 """Test the proper operation of the spin loop when no data is present.
741
742 The function tested is pipe_control.mol_res_spin.spin_loop().
743 """
744
745
746 reset()
747
748
749 ds.add(pipe_name='orig', pipe_type='mf')
750
751
752 i = 0
753 for spin in mol_res_spin.spin_loop():
754 i = i + 1
755
756
757 self.assertEqual(i, 0)
758
759
761 """Test the proper operation of the spin loop when no data pipe is present.
762
763 The function tested is pipe_control.mol_res_spin.spin_loop().
764 """
765
766
767 reset()
768
769
770 def fail_test():
771 for spin in mol_res_spin.spin_loop():
772 pass
773
774
775 self.assertRaises(RelaxNoPipeError, fail_test)
776
777
779 """Test the proper operation of the spin loop when no selection is present.
780
781 The function tested is pipe_control.mol_res_spin.spin_loop().
782 """
783
784
785 select = [0, 1, 0, 0, 1, 1, 0, 1]
786 name = ['NH', 'NH', None, 'C8', 'N5', 'C8', 'N5', '2H']
787
788
789 i = 0
790 for spin in mol_res_spin.spin_loop():
791
792 self.assertEqual(spin.select, select[i])
793
794
795 self.assertEqual(spin.name, name[i])
796
797
798 i = i + 1
799
800
801 self.assertEqual(i, 8)
802
803
805 """Test the operation of the spin loop with the single spin selection '#Ap4Aase:Glu@63'.
806
807 The function tested is pipe_control.mol_res_spin.spin_loop().
808 """
809
810
811 i = 0
812 for spin in mol_res_spin.spin_loop('#Ap4Aase:Glu@63'):
813
814 self.assertEqual(spin.select, 1)
815
816
817 self.assertEqual(spin.name, 'NH')
818
819
820 self.assertEqual(spin.num, 63)
821
822
823 i = i + 1
824
825
826 self.assertEqual(i, 1)
827
828
830 """Test the proper operation of the spin loop with wildcard spin selection '@N*'.
831
832 The function tested is pipe_control.mol_res_spin.spin_loop().
833 """
834
835
836 select = [0, 1, 1, 0]
837 name = ['NH', 'NH', 'N5', 'N5']
838
839
840 i = 0
841 for spin in mol_res_spin.spin_loop('@N*'):
842
843 self.assertEqual(spin.select, select[i])
844
845
846 self.assertEqual(spin.name, name[i])
847
848
849 i = i + 1
850
851
852 self.assertEqual(i, 4)
853
854
856 """Test boolean and in mol-res-spin selections."""
857
858
859 sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro"))
860
861
862 self.assertEqual(len(sel), 1)
863 for res in sel:
864 self.assert_(res.name == "Pro" and res.num == 4)
865
866
868 """Test complex boolean mol-res-spin selections."""
869
870
871 sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro | #RNA"))
872
873
874 names = ['Pro', None, None]
875 numbers = [4, -5, -4]
876
877
878 self.assertEqual(len(sel), 3)
879 for i in range(3):
880 self.assertEqual(sel[i].name, names[i])
881 self.assertEqual(sel[i].num, numbers[i])
882
883
884
885
886
888 """Test complex boolean mol-res-spin selections with parenthesis."""
889
890
891 sel = list(mol_res_spin.residue_loop("(#Ap4Aase & :Pro) | (#RNA & :-4)"))
892
893
894 self.assertEqual(len(sel), 2)
895 for res in sel:
896 self.assert_(res.num in [-4, 4])
897