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   
316   
317   
319          """First test of the spin ID generation function. 
320   
321          The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array(). 
322          """ 
323   
324           
325          data = ['1', 'GLY'] 
326   
327           
328          id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2) 
329   
330           
331          self.assertEqual(id, ':1') 
 332   
333   
335          """Second test of the spin ID generation function. 
336   
337          The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array(). 
338          """ 
339   
340           
341          data = ['1', 'GLY', '234', 'NH'] 
342   
343           
344          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) 
345   
346           
347          self.assertEqual(id, ':1@234') 
 348   
349   
351          """Third test of the spin ID generation function. 
352   
353          The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array(). 
354          """ 
355   
356           
357          data = ['Ap4Aase', '234', 'NH'] 
358   
359           
360          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) 
361   
362           
363          self.assertEqual(id, '#Ap4Aase@234') 
 364   
365   
367          """Fourth test of the spin ID generation function. 
368   
369          The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array(). 
370          """ 
371   
372           
373          data = ['Ap4Aase', '1', 'GLY'] 
374   
375           
376          id = mol_res_spin.generate_spin_id_data_array(data, mol_name_col=1, res_num_col=2, res_name_col=3) 
377   
378           
379          self.assertEqual(id, '#Ap4Aase:1') 
 380   
381   
383          """Fifth test of the spin ID generation function. 
384   
385          The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array(). 
386          """ 
387   
388           
389          data = ['Ap4Aase', '1', 'GLY', '234', 'NH'] 
390   
391           
392          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) 
393   
394           
395          self.assertEqual(id, '#Ap4Aase:1@234') 
 396   
397   
399          """Sixth test of the spin ID generation function. 
400   
401          The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array(). 
402          """ 
403   
404           
405          data = ['1', 'GLY', None, None] 
406   
407           
408          id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2) 
409   
410           
411          self.assertEqual(id, ':1') 
 412   
413   
415          """Test the proper operation of the molecule loop with molecule selection. 
416   
417          The function tested is pipe_control.mol_res_spin.molecule_loop(). 
418          """ 
419   
420           
421          for mol in mol_res_spin.molecule_loop('#RNA'): 
422               
423              self.assertEqual(mol.name, 'RNA') 
424   
425           
426          self.assertEqual(len(list(mol_res_spin.molecule_loop('#RNA'))), 1) 
 427   
428   
430          """Test the proper operation of the molecule loop when no data is present. 
431   
432          The function tested is pipe_control.mol_res_spin.molecule_loop(). 
433          """ 
434   
435           
436          reset() 
437   
438           
439          ds.add(pipe_name='orig', pipe_type='mf') 
440   
441           
442          i = 0 
443          for molecule in mol_res_spin.molecule_loop(): 
444              i = i + 1 
445   
446           
447          self.assertEqual(i, 0) 
 448   
449   
451          """Test the proper operation of the molecule loop when no data pipe is present. 
452   
453          The function tested is pipe_control.mol_res_spin.molecule_loop(). 
454          """ 
455   
456           
457          reset() 
458   
459           
460          def fail_test(): 
461              for molecule in mol_res_spin.molecule_loop(): 
462                  pass 
 463   
464           
465          self.assertRaises(RelaxNoPipeError, fail_test) 
 466   
467   
469          """Test the proper operation of the molecule loop when no selection is present. 
470   
471          The function tested is pipe_control.mol_res_spin.molecule_loop(). 
472          """ 
473   
474           
475          name = ['Ap4Aase', 'RNA'] 
476   
477           
478          i = 0 
479          for mol in mol_res_spin.molecule_loop(): 
480               
481              self.assertEqual(mol.name, name[i]) 
482   
483               
484              i = i + 1 
485   
486           
487          self.assertEqual(len(list(mol_res_spin.molecule_loop())), 2) 
 488   
489   
491          """Test the proper operation of the residue loop with residue selection. 
492   
493          The function tested is pipe_control.mol_res_spin.residue_loop(). 
494          """ 
495   
496           
497          for res in mol_res_spin.residue_loop('#Ap4Aase:Glu'): 
498               
499              self.assertEqual(res.num, 2) 
500   
501           
502          self.assertEqual(len(list(mol_res_spin.residue_loop('#Ap4Aase:Glu'))), 1) 
 503   
504   
506          """Test the proper operation of the residue loop when no data is present. 
507   
508          The function tested is pipe_control.mol_res_spin.residue_loop(). 
509          """ 
510   
511           
512          reset() 
513   
514           
515          ds.add(pipe_name='orig', pipe_type='mf') 
516   
517           
518          i = 0 
519          for residue in mol_res_spin.residue_loop(): 
520              i = i + 1 
521   
522           
523          self.assertEqual(i, 0) 
 524   
525   
527          """Test the proper operation of the residue loop when no data pipe is present. 
528   
529          The function tested is pipe_control.mol_res_spin.residue_loop(). 
530          """ 
531   
532           
533          reset() 
534   
535           
536          def fail_test(): 
537              for residue in mol_res_spin.residue_loop(): 
538                  pass 
 539   
540           
541          self.assertRaises(RelaxNoPipeError, fail_test) 
542   
543   
545          """Test the proper operation of the residue loop when no selection is present. 
546   
547          The function tested is pipe_control.mol_res_spin.residue_loop(). 
548          """ 
549   
550           
551          num = [1, 2, 4, -5, -4] 
552          name = [None, 'Glu', 'Pro', None, None] 
553   
554           
555          i = 0 
556          for res in mol_res_spin.residue_loop(): 
557               
558              self.assertEqual(res.num, num[i]) 
559   
560               
561              self.assertEqual(res.name, name[i]) 
562   
563               
564              i = i + 1 
565   
566           
567          self.assertEqual(i, 5) 
 568   
569   
571          """Test the function for returning the desired molecule data container. 
572   
573          The function tested is pipe_control.mol_res_spin.return_molecule(). 
574          """ 
575   
576           
577          mol1 = mol_res_spin.return_molecule('#Ap4Aase') 
578          mol2 = mol_res_spin.return_molecule(selection='#RNA', pipe='orig') 
579   
580           
581          self.assertEqual(mol1.name, 'Ap4Aase') 
582   
583           
584          self.assertEqual(mol2.name, 'RNA') 
 585   
586   
596   
597   
599          """Test the function for returning the desired residue data container. 
600   
601          The function tested is pipe_control.mol_res_spin.return_residue(). 
602          """ 
603   
604           
605          res1 = mol_res_spin.return_residue(':1') 
606          res2 = mol_res_spin.return_residue(selection=':2') 
607          res4 = mol_res_spin.return_residue(selection=':4', pipe='orig') 
608          res5 = mol_res_spin.return_residue(selection='#RNA:-5', pipe='orig') 
609   
610           
611          self.assertEqual(res1.num, 1) 
612          self.assertEqual(res1.name, None) 
613   
614           
615          self.assertEqual(res2.num, 2) 
616          self.assertEqual(res2.name, 'Glu') 
617   
618           
619          self.assertEqual(res4.num, 4) 
620          self.assertEqual(res4.name, 'Pro') 
621   
622           
623          self.assertEqual(res5.num, -5) 
624          self.assertEqual(res5.name, None) 
625          self.assertEqual(res5.spin[1].name, 'N5') 
 626   
627   
629          """Test the failure of the function for returning the desired residue data container. 
630   
631          The function tested is pipe_control.mol_res_spin.return_residue(). 
632          """ 
633   
634           
635          self.assertRaises(RelaxNoPipeError, mol_res_spin.return_residue, selection=':2', pipe='new') 
 636   
637   
639          """Test the function for returning the desired residue data container. 
640   
641          The function tested is pipe_control.mol_res_spin.return_single_residue_info(). 
642          """ 
643   
644           
645          res1 = mol_res_spin.return_single_residue_info('1') 
646          res2 = mol_res_spin.return_single_residue_info('2,Glu') 
647          res4 = mol_res_spin.return_single_residue_info('Pro,4') 
648          res5 = mol_res_spin.return_single_residue_info('-5') 
649   
650           
651          self.assertEqual(res1, (1, None)) 
652   
653           
654          self.assertEqual(res2, (2, 'Glu')) 
655   
656           
657          self.assertEqual(res4, (4, 'Pro')) 
658   
659           
660          self.assertEqual(res5, (-5, None)) 
 661   
662   
664          """Test the failure of the function for returning the desired residue data container. 
665   
666          The function tested is pipe_control.mol_res_spin.return_single_residue_info(). 
667          """ 
668   
669           
670          self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,2') 
671          self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,Glu,Pro') 
672          self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,2,Glu,Pro') 
 673   
674   
676          """Test the function for returning the desired spin data container. 
677   
678          The function tested is pipe_control.mol_res_spin.return_spin(). 
679          """ 
680   
681           
682          spin1 = mol_res_spin.return_spin('#Ap4Aase:1') 
683          spin2 = mol_res_spin.return_spin(spin_id='#Ap4Aase:2') 
684          spin3 = mol_res_spin.return_spin(spin_id='#Ap4Aase:4', pipe='orig') 
685          spin4 = mol_res_spin.return_spin(spin_id='#RNA:-5@N5', pipe='orig') 
686          spin5 = mol_res_spin.return_spin(spin_id='#RNA:-4@2H', pipe='orig') 
687   
688           
689          self.assertNotEqual(spin1, None) 
690          self.assertEqual(spin1.num, 60) 
691          self.assertEqual(spin1.name, 'NH') 
692   
693           
694          self.assertNotEqual(spin2, None) 
695          self.assertEqual(spin2.num, 63) 
696          self.assertEqual(spin2.name, 'NH') 
697   
698           
699          self.assertNotEqual(spin3, None) 
700          self.assertEqual(spin3.num, None) 
701          self.assertEqual(spin3.name, None) 
702   
703           
704          self.assertNotEqual(spin4, None) 
705          self.assertEqual(spin4.num, None) 
706          self.assertEqual(spin4.name, 'N5') 
707   
708           
709          self.assertNotEqual(spin5, None) 
710          self.assertEqual(spin5.num, 132) 
711          self.assertEqual(spin5.name, '2H') 
 712   
713   
715          """Test the failure of the function for returning the desired spin data container. 
716   
717          The function tested is pipe_control.mol_res_spin.return_spin(). 
718          """ 
719   
720           
721          self.assertRaises(RelaxNoPipeError, mol_res_spin.return_spin, spin_id=':2', pipe='new') 
 722   
723   
725          """Test the proper operation of the spin loop with spin selection. 
726   
727          The function tested is pipe_control.mol_res_spin.spin_loop(). 
728          """ 
729   
730           
731          select = [1, 0] 
732   
733           
734          i = 0 
735          for spin in mol_res_spin.spin_loop('@N5'): 
736               
737              self.assertEqual(spin.select, select[i]) 
738   
739               
740              self.assertEqual(spin.name, 'N5') 
741   
742               
743              i = i + 1 
744   
745           
746          self.assertEqual(i, 2) 
 747   
748   
750          """Test the operation of the spin loop with the selection "#Ap4Aase:Glu | #RNA@C8". 
751   
752          The function tested is pipe_control.mol_res_spin.spin_loop(). 
753          """ 
754   
755           
756          select = [1, 0, 1] 
757          name = ['NH', 'C8', 'C8'] 
758          num = [63, None, None] 
759   
760           
761          i = 0 
762          for spin in mol_res_spin.spin_loop("#Ap4Aase:Glu | #RNA@C8"): 
763               
764              self.assertEqual([spin.select, spin.name, spin.num], [select[i], name[i], num[i]]) 
765   
766               
767              i = i + 1 
768   
769           
770          self.assertEqual(i, 3) 
 771   
772   
774          """Test the proper operation of the spin loop with spin selection '@NH|@N5'. 
775   
776          The function tested is pipe_control.mol_res_spin.spin_loop(). 
777          """ 
778   
779           
780          select = [0, 1, 1, 0] 
781          name = ['NH', 'NH', 'N5', 'N5'] 
782   
783           
784          i = 0 
785          for spin in mol_res_spin.spin_loop('@NH|@N5'): 
786               
787              self.assertEqual(spin.select, select[i]) 
788   
789               
790              self.assertEqual(spin.name, name[i]) 
791   
792               
793              i = i + 1 
794   
795           
796          self.assertEqual(i, 4) 
 797   
798   
800          """Test the proper operation of the spin loop when no data is present. 
801   
802          The function tested is pipe_control.mol_res_spin.spin_loop(). 
803          """ 
804   
805           
806          reset() 
807   
808           
809          ds.add(pipe_name='orig', pipe_type='mf') 
810   
811           
812          i = 0 
813          for spin in mol_res_spin.spin_loop(): 
814              i = i + 1 
815   
816           
817          self.assertEqual(i, 0) 
 818   
819   
821          """Test the proper operation of the spin loop when no data pipe is present. 
822   
823          The function tested is pipe_control.mol_res_spin.spin_loop(). 
824          """ 
825   
826           
827          reset() 
828   
829           
830          def fail_test(): 
831              for spin in mol_res_spin.spin_loop(): 
832                  pass 
 833   
834           
835          self.assertRaises(RelaxNoPipeError, fail_test) 
836   
837   
839          """Test the proper operation of the spin loop when no selection is present. 
840   
841          The function tested is pipe_control.mol_res_spin.spin_loop(). 
842          """ 
843   
844           
845          select = [0, 1, 0, 0, 1, 1, 0, 1] 
846          name = ['NH', 'NH', None, 'C8', 'N5', 'C8', 'N5', '2H'] 
847   
848           
849          i = 0 
850          for spin in mol_res_spin.spin_loop(): 
851               
852              self.assertEqual(spin.select, select[i]) 
853   
854               
855              self.assertEqual(spin.name, name[i]) 
856   
857               
858              i = i + 1 
859   
860           
861          self.assertEqual(i, 8) 
 862   
863   
865          """Test the operation of the spin loop with the single spin selection '#Ap4Aase:Glu@63'. 
866   
867          The function tested is pipe_control.mol_res_spin.spin_loop(). 
868          """ 
869   
870           
871          i = 0 
872          for spin in mol_res_spin.spin_loop('#Ap4Aase:Glu@63'): 
873               
874              self.assertEqual(spin.select, 1) 
875   
876               
877              self.assertEqual(spin.name, 'NH') 
878   
879               
880              self.assertEqual(spin.num, 63) 
881   
882               
883              i = i + 1 
884   
885           
886          self.assertEqual(i, 1) 
 887   
888   
890          """Test the proper operation of the spin loop with wildcard spin selection '@N*'. 
891   
892          The function tested is pipe_control.mol_res_spin.spin_loop(). 
893          """ 
894   
895           
896          select = [0, 1, 1, 0] 
897          name = ['NH', 'NH', 'N5', 'N5'] 
898   
899           
900          i = 0 
901          for spin in mol_res_spin.spin_loop('@N*'): 
902               
903              self.assertEqual(spin.select, select[i]) 
904   
905               
906              self.assertEqual(spin.name, name[i]) 
907   
908               
909              i = i + 1 
910   
911           
912          self.assertEqual(i, 4) 
 913   
914   
916          """Test boolean and in mol-res-spin selections.""" 
917   
918           
919          sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro")) 
920   
921           
922          self.assertEqual(len(sel), 1) 
923          for res in sel: 
924              self.assert_(res.name == "Pro" and res.num == 4) 
 925   
926   
928          """Test complex boolean mol-res-spin selections.""" 
929   
930           
931          sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro | #RNA")) 
932   
933           
934          names = ['Pro', None, None] 
935          numbers = [4, -5, -4] 
936   
937           
938          self.assertEqual(len(sel), 3) 
939          for i in range(3): 
940              self.assertEqual(sel[i].name, names[i]) 
941              self.assertEqual(sel[i].num, numbers[i]) 
 942   
943   
944       
945       
946       
948          """Test complex boolean mol-res-spin selections with parenthesis.""" 
949   
950           
951          sel = list(mol_res_spin.residue_loop("(#Ap4Aase & :Pro) | (#RNA & :-4)")) 
952   
953           
954          self.assertEqual(len(sel), 2) 
955          for res in sel: 
956              self.assert_(res.num in [-4, 4]) 
 957