1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from lib.selection import Selection, parse_token, tokenise
24 from lib.errors import RelaxError
25 from test_suite.unit_tests.base_classes import UnitTestCase
26
27
29 """Unit tests for the functions of the 'lib.selection' module."""
30
32 """Test the Selection object for boolean '&' mol-res-spin selections."""
33
34
35 obj = Selection("#Ap4Aase:4 & :Pro@Ca")
36
37
38 self.assertEqual(obj._union, None)
39 self.assertNotEqual(obj._intersect, None)
40 self.assertEqual(obj.molecules, [])
41 self.assertEqual(obj.residues, [])
42 self.assertEqual(obj.spins, [])
43
44
45 self.assertEqual(obj._intersect[0]._union, None)
46 self.assertEqual(obj._intersect[0]._intersect, None)
47 self.assertEqual(obj._intersect[0].molecules, ['Ap4Aase'])
48 self.assertEqual(obj._intersect[0].residues, [4])
49 self.assertEqual(obj._intersect[0].spins, [])
50
51
52 self.assertEqual(obj._intersect[1]._union, None)
53 self.assertEqual(obj._intersect[1]._intersect, None)
54 self.assertEqual(obj._intersect[1].molecules, [])
55 self.assertEqual(obj._intersect[1].residues, ['Pro'])
56 self.assertEqual(obj._intersect[1].spins, ['Ca'])
57
58
60 """Test the Selection object for boolean '|' mol-res-spin selections."""
61
62
63 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
64
65
66 self.assertNotEqual(obj._union, None)
67 self.assertEqual(obj._intersect, None)
68 self.assertEqual(obj.molecules, [])
69 self.assertEqual(obj.residues, [])
70 self.assertEqual(obj.spins, [])
71
72
73 self.assertEqual(obj._union[0]._union, None)
74 self.assertEqual(obj._union[0]._intersect, None)
75 self.assertEqual(obj._union[0].molecules, ['Ap4Aase'])
76 self.assertEqual(obj._union[0].residues, ['Glu'])
77 self.assertEqual(obj._union[0].spins, [])
78
79
80 self.assertEqual(obj._union[1]._union, None)
81 self.assertEqual(obj._union[1]._intersect, None)
82 self.assertEqual(obj._union[1].molecules, ['RNA'])
83 self.assertEqual(obj._union[1].residues, [])
84 self.assertEqual(obj._union[1].spins, ['C8'])
85
86
88 """Test the Selection object for complex boolean mol-res-spin selections."""
89
90
91 obj = Selection("#Ap4Aase:4 & :Pro | #RNA")
92
93
94 self.assertNotEqual(obj._union, None)
95 self.assertEqual(obj._intersect, None)
96 self.assertEqual(obj.molecules, [])
97 self.assertEqual(obj.residues, [])
98 self.assertEqual(obj.spins, [])
99
100
101 self.assertEqual(obj._union[0]._union, None)
102 self.assertNotEqual(obj._union[0]._intersect, None)
103 self.assertEqual(obj._union[0].molecules, [])
104 self.assertEqual(obj._union[0].residues, [])
105 self.assertEqual(obj._union[0].spins, [])
106
107
108 self.assertEqual(obj._union[1]._union, None)
109 self.assertEqual(obj._union[1]._intersect, None)
110 self.assertEqual(obj._union[1].molecules, ['RNA'])
111 self.assertEqual(obj._union[1].residues, [])
112 self.assertEqual(obj._union[1].spins, [])
113
114
115 self.assertEqual(obj._union[0]._intersect[0]._union, None)
116 self.assertEqual(obj._union[0]._intersect[0]._intersect, None)
117 self.assertEqual(obj._union[0]._intersect[0].molecules, ['Ap4Aase'])
118 self.assertEqual(obj._union[0]._intersect[0].residues, [4])
119 self.assertEqual(obj._union[0]._intersect[0].spins, [])
120
121
122 self.assertEqual(obj._union[0]._intersect[1]._union, None)
123 self.assertEqual(obj._union[0]._intersect[1]._intersect, None)
124 self.assertEqual(obj._union[0]._intersect[1].molecules, [])
125 self.assertEqual(obj._union[0]._intersect[1].residues, ['Pro'])
126 self.assertEqual(obj._union[0]._intersect[1].spins, [])
127
128
130 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the molecule 'RNA'."""
131
132
133 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
134
135
136 self.assert_(obj.contains_mol('RNA'))
137
138
140 """The Selection object "#Ap4Aase:Glu & #RNA@C8" does not contain the molecule 'RNA'."""
141
142
143 obj = Selection("#Ap4Aase:Glu & #RNA@C8")
144
145
146 self.assert_(not obj.contains_mol('RNA'))
147
148
150 """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the molecule 'XXX'."""
151
152
153 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
154
155
156 self.assert_(not obj.contains_mol('XXX'))
157
158
160 """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the molecule None."""
161
162
163 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
164
165
166 self.assert_(not obj.contains_mol())
167
168
170 """The Selection object ":Glu" does contain the molecule None."""
171
172
173 obj = Selection(":Glu")
174
175
176 self.assert_(obj.contains_mol())
177
178
180 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the molecule 'R*'."""
181
182
183 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
184
185
186 self.assert_(obj.contains_mol('R*'))
187
188
190 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the molecule '*R*'."""
191
192
193 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
194
195
196 self.assert_(obj.contains_mol('*R*'))
197
198
200 """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the res 'Glu' (without the mol name)."""
201
202
203 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
204
205
206 self.assert_(not obj.contains_res(res_name='Glu'))
207
208
210 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the res 'Glu' of the mol 'Ap4Aase'."""
211
212
213 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
214
215
216 self.assert_(obj.contains_res(res_name='Glu', mol='Ap4Aase'))
217
218
220 """The Selection object "#Ap4Aase:Glu & #RNA@C8" does not contain the res 'Glu'."""
221
222
223 obj = Selection("#Ap4Aase:Glu & #RNA@C8")
224
225
226 self.assert_(not obj.contains_res(res_name='Glu'))
227
228
230 """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the res 'Ala'."""
231
232
233 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
234
235
236 self.assert_(not obj.contains_res(res_name='Ala'))
237
238
240 """The Selection object "#Ap4Aase:Glu | #RNA:14@C8" does not contain the res None."""
241
242
243 obj = Selection("#Ap4Aase:Glu | #RNA:14@C8")
244
245
246 self.assert_(not obj.contains_res())
247
248
250 """The Selection object "#Ap4Aase" does contains the res None."""
251
252
253 obj = Selection("#Ap4Aase")
254
255
256 self.assert_(obj.contains_res(mol='Ap4Aase'))
257
258
260 """The Selection object "#Ap4Aase" does not contain the res None of the mol 'RNA'."""
261
262
263 obj = Selection("#Ap4Aase")
264
265
266 self.assert_(not obj.contains_res(mol='RNA'))
267
268
270 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the res 'G*' of the mol 'Ap4Aase'."""
271
272
273 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
274
275
276 self.assert_(obj.contains_res(res_name='G*', mol='Ap4Aase'))
277
278
280 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the res '*G*' of the mol 'Ap4Aase'."""
281
282
283 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
284
285
286 self.assert_(obj.contains_res(res_name='*G*', mol='Ap4Aase'))
287
288
290 """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the spin 'C8' (without the mol name)."""
291
292
293 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
294
295
296 self.assert_(not obj.contains_spin(spin_name='C8'))
297
298
300 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the spin 'C8' of the mol 'RNA'."""
301
302
303 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
304
305
306 self.assert_(obj.contains_spin(spin_name='C8', mol='RNA'))
307
308
310 """The Selection object "#Ap4Aase:Glu & #RNA@C8" does not contain the spin 'C8'."""
311
312
313 obj = Selection("#Ap4Aase:Glu & #RNA@C8")
314
315
316 self.assert_(not obj.contains_spin(spin_name='C8'))
317
318
320 """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the spin 'N3'."""
321
322
323 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
324
325
326 self.assert_(not obj.contains_spin(spin_name='N3'))
327
328
330 """The Selection object "#Ap4Aase:Glu | #RNA:14@C8" does not contain the spin None."""
331
332
333 obj = Selection("#Ap4Aase:Glu | #RNA:14@C8")
334
335
336 self.assert_(not obj.contains_spin())
337
338
340 """The Selection object "#Ap4Aase" does contains the spin None."""
341
342
343 obj = Selection("#Ap4Aase")
344
345
346 self.assert_(obj.contains_spin(mol='Ap4Aase'))
347
348
350 """The Selection object "#Ap4Aase" does not contain the spin None of the mol 'RNA'."""
351
352
353 obj = Selection("#Ap4Aase")
354
355
356 self.assert_(not obj.contains_spin(mol='RNA'))
357
358
360 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the spin 'C*' of the mol 'RNA'."""
361
362
363 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
364
365
366 self.assert_(obj.contains_spin(spin_name='C*', mol='RNA'))
367
368
370 """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the spin '*C*' of the mol 'RNA'."""
371
372
373 obj = Selection("#Ap4Aase:Glu | #RNA@C8")
374
375
376 self.assert_(obj.contains_spin(spin_name='*C*', mol='RNA'))
377
378
380 """Test that the Selection object has no memory of previous selections."""
381
382
383 obj = Selection(":1@16")
384
385
386 obj = Selection(":13")
387
388
389 self.assertEqual(obj._union, None)
390 self.assertEqual(obj._intersect, None)
391 self.assertEqual(obj.molecules, [])
392 self.assertEqual(obj.residues, [13])
393 self.assertEqual(obj.spins, [])
394
395
397 """The Selection object ":1-70" contains the res ':1'."""
398
399
400 obj = Selection(":1-70")
401
402
403 self.assert_(obj.contains_spin_id(':1'))
404
405
407 """The Selection object ":1-70" does not contain the res ':71'."""
408
409
410 obj = Selection(":1-70")
411
412
413 self.assert_(not obj.contains_spin_id(':71'))
414
415
417 """The Selection object ":1-70" contains the spin ':1@N'."""
418
419
420 obj = Selection(":1-70")
421
422
423 self.assert_(obj.contains_spin_id(':1@N'))
424
425
427 """The Selection object ":1-70" does not contain the spin ':71@C'."""
428
429
430 obj = Selection(":1-70")
431
432
433 self.assert_(not obj.contains_spin_id(':71@C'))
434
435
437 """Test the lib.selection.parse_token() function on the string '1'."""
438
439
440 list = parse_token('1')
441
442
443 self.assertEqual(len(list), 1)
444 self.assertEqual(list[0], 1)
445
446
448 """Test the lib.selection.parse_token() function on the string '-4'."""
449
450
451 list = parse_token('-4')
452
453
454 self.assertEqual(len(list), 1)
455 self.assertEqual(list[0], -4)
456
457
459 """Test the lib.selection.parse_token() function on the string 'G'."""
460
461
462 list = parse_token('G')
463
464
465 self.assertEqual(len(list), 1)
466 self.assertEqual(list[0], 'G')
467
468
470 """Test the lib.selection.parse_token() function on the string 'N*'."""
471
472
473 list = parse_token('N*')
474
475
476 self.assertEqual(len(list), 1)
477 self.assertEqual(list[0], 'N*')
478
479
481 """Test the lib.selection.parse_token() function on the string '1-10'."""
482
483
484 list = parse_token('1-10')
485
486
487 self.assertEqual(len(list), 10)
488 for i in range(1, 11):
489 self.assertEqual(list[i-1], i)
490
491
493 """Test the lib.selection.parse_token() function on the string '-10--1'."""
494
495
496 list = parse_token('-10--1')
497
498
499 self.assertEqual(len(list), 10)
500 j = 0
501 for i in range(-10, -2):
502 self.assertEqual(list[j], i)
503 j = j + 1
504
505
507 """Test the lib.selection.parse_token() function on the string '-2, 1'."""
508
509
510 list = parse_token('-2, 1')
511
512
513 self.assertEqual(len(list), 2)
514 self.assertEqual(list[0], -2)
515 self.assertEqual(list[1], 1)
516
517
519 """Test the lib.selection.parse_token() function on the string 'N,CA'."""
520
521
522 list = parse_token('N,CA')
523
524
525 self.assertEqual(len(list), 2)
526 self.assertEqual(list[0], 'N')
527 self.assertEqual(list[1], 'CA')
528
529
531 """Test the lib.selection.parse_token() function on the string '76,Ala'."""
532
533
534 list = parse_token('76,Ala')
535
536
537 self.assertEqual(len(list), 2)
538 self.assertEqual(list[0], 76)
539 self.assertEqual(list[1], 'Ala')
540
541
543 """Test the lib.selection.parse_token() function on the string '1,3-5'."""
544
545
546 list = parse_token('1,3-5')
547
548
549 self.assertEqual(len(list), 4)
550 self.assertEqual(list[0], 1)
551 self.assertEqual(list[1], 3)
552 self.assertEqual(list[2], 4)
553 self.assertEqual(list[3], 5)
554
555
557 """Test the lib.selection.parse_token() function on the string '3-5,NH'."""
558
559
560 list = parse_token('3-5,NH')
561
562
563 self.assertEqual(len(list), 4)
564 self.assertEqual(list[0], 3)
565 self.assertEqual(list[1], 4)
566 self.assertEqual(list[2], 5)
567 self.assertEqual(list[3], 'NH')
568
569
571 """Test the lib.selection.parse_token() function on the string '3-6, 8, Gly'."""
572
573
574 list = parse_token('3-6, 8, Gly')
575
576
577 self.assertEqual(len(list), 6)
578 self.assertEqual(list[0], 3)
579 self.assertEqual(list[1], 4)
580 self.assertEqual(list[2], 5)
581 self.assertEqual(list[3], 6)
582 self.assertEqual(list[4], 8)
583 self.assertEqual(list[5], 'Gly')
584
585
587 """Test the lib.selection.tokenise() function on the string '@1'."""
588
589
590 mol_token, res_token, spin_token = tokenise('@1')
591
592
593 self.assertEqual(mol_token, None)
594 self.assertEqual(res_token, None)
595 self.assertEqual(spin_token, '1')
596
597
599 """Test the lib.selection.tokenise() function on the string ':-4'."""
600
601
602 mol_token, res_token, spin_token = tokenise(':-4')
603
604
605 self.assertEqual(mol_token, None)
606 self.assertEqual(res_token, '-4')
607 self.assertEqual(spin_token, None)
608
609
611 """Test the lib.selection.tokenise() function on the string '#CaM'."""
612
613
614 mol_token, res_token, spin_token = tokenise('#CaM')
615
616
617 self.assertEqual(mol_token, 'CaM')
618 self.assertEqual(res_token, None)
619 self.assertEqual(spin_token, None)
620
621
623 """Test the lib.selection.tokenise() function on the string ':G@N3'."""
624
625
626 mol_token, res_token, spin_token = tokenise(':G@N3')
627
628
629 self.assertEqual(mol_token, None)
630 self.assertEqual(res_token, 'G')
631 self.assertEqual(spin_token, 'N3')
632
633
635 """Test the lib.selection.tokenise() function on the string '#OMP@NH'."""
636
637
638 mol_token, res_token, spin_token = tokenise('#OMP@NH')
639
640
641 self.assertEqual(mol_token, 'OMP')
642 self.assertEqual(res_token, None)
643 self.assertEqual(spin_token, 'NH')
644
645
647 """Test the lib.selection.tokenise() function on the string '#Lyso:20-50'."""
648
649
650 mol_token, res_token, spin_token = tokenise('#Lyso:20-50')
651
652
653 self.assertEqual(mol_token, 'Lyso')
654 self.assertEqual(res_token, '20-50')
655 self.assertEqual(spin_token, None)
656
657
659 """Test the lib.selection.tokenise() function on the string '#Ap4Aase:*@N,CA'."""
660
661
662 mol_token, res_token, spin_token = tokenise('#Ap4Aase:*@N,CA')
663
664
665 self.assertEqual(mol_token, 'Ap4Aase')
666 self.assertEqual(res_token, '*')
667 self.assertEqual(spin_token, 'N,CA')
668
669
671 """Test the lib.selection.tokenise() function on the string '@N*'."""
672
673
674 mol_token, res_token, spin_token = tokenise('@N*')
675
676
677 self.assertEqual(mol_token, None)
678 self.assertEqual(res_token, None)
679 self.assertEqual(spin_token, 'N*')
680
681
683 """Test failure of the lib.selection.tokenise() function on the string '@N@1'.
684
685 This tests for a duplicated atom identifier.
686 """
687
688
689 self.assertRaises(RelaxError, tokenise, '@N@1')
690
691
693 """Test failure of the lib.selection.tokenise() function on the string ':*@N@1'.
694
695 This tests for a duplicated atom identifier.
696 """
697
698
699 self.assertRaises(RelaxError, tokenise, ':*@N@1')
700
701
703 """Test failure of the lib.selection.tokenise() function on the string '@N:*@1'.
704
705 This tests for a duplicated atom identifier.
706 """
707
708
709 self.assertRaises(RelaxError, tokenise, '@N:*@1')
710
711
713 """Test failure of the lib.selection.tokenise() function on the string ':1:2'.
714
715 This tests for a duplicated residue identifier.
716 """
717
718
719 self.assertRaises(RelaxError, tokenise, ':1:2')
720
721
723 """Test failure of the lib.selection.tokenise() function on the string '#None:1:Ala'.
724
725 This tests for a duplicated residue identifier.
726 """
727
728
729 self.assertRaises(RelaxError, tokenise, '#None:1:Ala')
730
731
733 """Test failure of the lib.selection.tokenise() function on the string ':1:Ala@N'.
734
735 This tests for a duplicated residue identifier.
736 """
737
738
739 self.assertRaises(RelaxError, tokenise, ':1:Ala@N')
740
741
743 """Test failure of the lib.selection.tokenise() function on the string '#A#B'.
744
745 This tests for a duplicated molecule identifier.
746 """
747
748
749 self.assertRaises(RelaxError, tokenise, '#A#B')
750
751
753 """Test failure of the lib.selection.tokenise() function on the string '#A#B:Leu'.
754
755 This tests for a duplicated molecule identifier.
756 """
757
758
759 self.assertRaises(RelaxError, tokenise, '#A#B:Leu')
760
761
763 """Test failure of the lib.selection.tokenise() function on the string '#A#C@CA'.
764
765 This tests for a duplicated molecule identifier.
766 """
767
768
769 self.assertRaises(RelaxError, tokenise, '#A#C@CA')
770
771
773 """Test failure of the lib.selection.tokenise() function on the string '@CA#A'.
774
775 This tests for an out of order '@' identifier.
776 """
777
778
779 self.assertRaises(RelaxError, tokenise, '@CA#A')
780
781
783 """Test failure of the lib.selection.tokenise() function on the string '@CA:Pro'.
784
785 This tests for an out of order '@' identifier.
786 """
787
788
789 self.assertRaises(RelaxError, tokenise, '@CA:Pro')
790
791
793 """Test failure of the lib.selection.tokenise() function on the string '@CA#Z:Pro'.
794
795 This tests for an out of order '@' identifier.
796 """
797
798
799 self.assertRaises(RelaxError, tokenise, '@CA#Z:Pro')
800
801
803 """Test failure of the lib.selection.tokenise() function on the string '@CA:Pro'.
804
805 This tests for an out of order ':' identifier.
806 """
807
808
809 self.assertRaises(RelaxError, tokenise, '@CA:Pro')
810
811
813 """Test failure of the lib.selection.tokenise() function on the string ':Glu#X'.
814
815 This tests for an out of order ':' identifier.
816 """
817
818
819 self.assertRaises(RelaxError, tokenise, ':Glu#X')
820
821
823 """Test failure of the lib.selection.tokenise() function on the string '#1@12423:Glu'.
824
825 This tests for an out of order ':' identifier.
826 """
827
828
829 self.assertRaises(RelaxError, tokenise, ':Glu#X')
830
831
833 """Test failure of the lib.selection.tokenise() function on the string ':1-160#A'.
834
835 This tests for an out of order '#' identifier.
836 """
837
838
839 self.assertRaises(RelaxError, tokenise, ':1-160#A')
840
841
843 """Test failure of the lib.selection.tokenise() function on the string '@N,CA#A'.
844
845 This tests for an out of order '#' identifier.
846 """
847
848
849 self.assertRaises(RelaxError, tokenise, '@N,CA#A')
850
851
853 """Test failure of the lib.selection.tokenise() function on the string '@N:-10#Zip'.
854
855 This tests for an out of order '#' identifier.
856 """
857
858
859 self.assertRaises(RelaxError, tokenise, '@N:-10#Zip')
860
861
863 """Test failure of the lib.selection.tokenise() function on the string '13'.
864
865 This tests for an improper selection string.
866 """
867
868
869 self.assertRaises(RelaxError, tokenise, '13')
870
871
873 """Test failure of the lib.selection.tokenise() function on the string 'XXX'.
874
875 This tests for an improper selection string.
876 """
877
878
879 self.assertRaises(RelaxError, tokenise, 'XXX')
880
881
883 """Test failure of the lib.selection.tokenise() function on the string ''.
884
885 This tests for an improper selection string.
886 """
887
888
889 self.assertRaises(RelaxError, tokenise, '')
890