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