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_store import Relax_data_store; ds = Relax_data_store() 
 25  from pipe_control import mol_res_spin, pipes 
 26  from pipe_control.reset import reset 
 27  from lib.errors import RelaxError, RelaxNoPipeError 
 28  from test_suite.unit_tests.base_classes import UnitTestCase 
 29   
 30   
 32      """Unit tests for the functions of the 'pipe_control.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           
 75          mol_res_spin.metadata_update() 
  76   
 77   
 89   
 90   
 92          """Test that the number of spins (zero) can be properly counted. 
 93   
 94          The function tested is pipe_control.mol_res_spin.count_spins(). 
 95          """ 
 96   
 97           
 98          reset() 
 99   
100           
101          ds.add(pipe_name='orig', pipe_type='mf') 
102   
103           
104          self.assertEqual(mol_res_spin.count_spins(), 0) 
 105   
106   
108          """Test that the counting of the number of spins raises an error when no pipe exists. 
109   
110          The function tested is pipe_control.mol_res_spin.count_spins(). 
111          """ 
112   
113           
114          reset() 
115   
116           
117          self.assertRaises(RelaxNoPipeError, mol_res_spin.count_spins) 
 118   
119   
121          """Test the function for determining if molecule-residue-spin data exists. 
122   
123          The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data(). 
124          """ 
125   
126           
127          self.failUnless(mol_res_spin.exists_mol_res_spin_data()) 
 128   
129   
131          """Determine if molecule-residue-spin data exists (with data for a single molecule). 
132   
133          The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data(). 
134          """ 
135   
136           
137          reset() 
138   
139           
140          ds.add(pipe_name='orig', pipe_type='mf') 
141          dp = pipes.get_pipe('orig') 
142   
143           
144          dp.mol[0].name = 'TOM40' 
145   
146           
147          self.failUnless(mol_res_spin.exists_mol_res_spin_data()) 
 148   
149   
151          """Determine if molecule-residue-spin data exists (when a single residue is named). 
152   
153          The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data(). 
154          """ 
155   
156           
157          reset() 
158   
159           
160          ds.add(pipe_name='orig', pipe_type='mf') 
161          dp = pipes.get_pipe('orig') 
162   
163           
164          dp.mol[0].res[0].name = 'Lys' 
165   
166           
167          self.failUnless(mol_res_spin.exists_mol_res_spin_data()) 
 168   
169   
171          """Determine if molecule-residue-spin data exists (when a single residue is numbered). 
172   
173          The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data(). 
174          """ 
175   
176           
177          reset() 
178   
179           
180          ds.add(pipe_name='orig', pipe_type='mf') 
181          dp = pipes.get_pipe('orig') 
182   
183           
184          dp.mol[0].res[0].num = 1 
185   
186           
187          self.failUnless(mol_res_spin.exists_mol_res_spin_data()) 
 188   
189   
191          """Determine if molecule-residue-spin data exists (when a single spin is named). 
192   
193          The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data(). 
194          """ 
195   
196           
197          reset() 
198   
199           
200          ds.add(pipe_name='orig', pipe_type='mf') 
201          dp = pipes.get_pipe('orig') 
202   
203           
204          dp.mol[0].res[0].spin[0].name = 'NH' 
205   
206           
207          self.failUnless(mol_res_spin.exists_mol_res_spin_data()) 
 208   
209   
211          """Determine if molecule-residue-spin data exists (when a single spin is numbered). 
212   
213          The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data(). 
214          """ 
215   
216           
217          reset() 
218   
219           
220          ds.add(pipe_name='orig', pipe_type='mf') 
221          dp = pipes.get_pipe('orig') 
222   
223           
224          dp.mol[0].res[0].spin[0].num = 234 
225   
226           
227          self.failUnless(mol_res_spin.exists_mol_res_spin_data()) 
 228   
229   
231          """Determine if molecule-residue-spin data exists when no data exists. 
232   
233          The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data(). 
234          """ 
235   
236           
237          reset() 
238   
239           
240          ds.add(pipe_name='orig', pipe_type='mf') 
241   
242           
243          self.failIf(mol_res_spin.exists_mol_res_spin_data()) 
 244   
245   
257   
258   
317   
318   
320          """First test of the spin ID generation function. 
321   
322          The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array(). 
323          """ 
324   
325           
326          data = ['1', 'GLY'] 
327   
328           
329          id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2) 
330   
331           
332          self.assertEqual(id, ':1') 
 333   
334   
336          """Second test of the spin ID generation function. 
337   
338          The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array(). 
339          """ 
340   
341           
342          data = ['1', 'GLY', '234', 'NH'] 
343   
344           
345          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) 
346   
347           
348          self.assertEqual(id, ':1@234') 
 349   
350   
352          """Third test of the spin ID generation function. 
353   
354          The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array(). 
355          """ 
356   
357           
358          data = ['Ap4Aase', '234', 'NH'] 
359   
360           
361          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) 
362   
363           
364          self.assertEqual(id, '#Ap4Aase@234') 
 365   
366   
368          """Fourth test of the spin ID generation function. 
369   
370          The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array(). 
371          """ 
372   
373           
374          data = ['Ap4Aase', '1', 'GLY'] 
375   
376           
377          id = mol_res_spin.generate_spin_id_data_array(data, mol_name_col=1, res_num_col=2, res_name_col=3) 
378   
379           
380          self.assertEqual(id, '#Ap4Aase:1') 
 381   
382   
384          """Fifth test of the spin ID generation function. 
385   
386          The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array(). 
387          """ 
388   
389           
390          data = ['Ap4Aase', '1', 'GLY', '234', 'NH'] 
391   
392           
393          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) 
394   
395           
396          self.assertEqual(id, '#Ap4Aase:1@234') 
 397   
398   
400          """Sixth test of the spin ID generation function. 
401   
402          The function tested is pipe_control.mol_res_spin.generate_spin_id_data_array(). 
403          """ 
404   
405           
406          data = ['1', 'GLY', None, None] 
407   
408           
409          id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2) 
410   
411           
412          self.assertEqual(id, ':1') 
 413   
414   
416          """Test the proper operation of the molecule loop with molecule selection. 
417   
418          The function tested is pipe_control.mol_res_spin.molecule_loop(). 
419          """ 
420   
421           
422          for mol in mol_res_spin.molecule_loop('#RNA'): 
423               
424              self.assertEqual(mol.name, 'RNA') 
425   
426           
427          self.assertEqual(len(list(mol_res_spin.molecule_loop('#RNA'))), 1) 
 428   
429   
431          """Test the proper operation of the molecule loop when no data is present. 
432   
433          The function tested is pipe_control.mol_res_spin.molecule_loop(). 
434          """ 
435   
436           
437          reset() 
438   
439           
440          ds.add(pipe_name='orig', pipe_type='mf') 
441   
442           
443          i = 0 
444          for molecule in mol_res_spin.molecule_loop(): 
445              i = i + 1 
446   
447           
448          self.assertEqual(i, 0) 
 449   
450   
452          """Test the proper operation of the molecule loop when no data pipe is present. 
453   
454          The function tested is pipe_control.mol_res_spin.molecule_loop(). 
455          """ 
456   
457           
458          reset() 
459   
460           
461          def fail_test(): 
462              for molecule in mol_res_spin.molecule_loop(): 
463                  pass 
 464   
465           
466          self.assertRaises(RelaxNoPipeError, fail_test) 
 467   
468   
470          """Test the proper operation of the molecule loop when no selection is present. 
471   
472          The function tested is pipe_control.mol_res_spin.molecule_loop(). 
473          """ 
474   
475           
476          name = ['Ap4Aase', 'RNA'] 
477   
478           
479          i = 0 
480          for mol in mol_res_spin.molecule_loop(): 
481               
482              self.assertEqual(mol.name, name[i]) 
483   
484               
485              i = i + 1 
486   
487           
488          self.assertEqual(len(list(mol_res_spin.molecule_loop())), 2) 
 489   
490   
492          """Test the proper operation of the residue loop with residue selection. 
493   
494          The function tested is pipe_control.mol_res_spin.residue_loop(). 
495          """ 
496   
497           
498          for res in mol_res_spin.residue_loop('#Ap4Aase:Glu'): 
499               
500              self.assertEqual(res.num, 2) 
501   
502           
503          self.assertEqual(len(list(mol_res_spin.residue_loop('#Ap4Aase:Glu'))), 1) 
 504   
505   
507          """Test the proper operation of the residue loop when no data is present. 
508   
509          The function tested is pipe_control.mol_res_spin.residue_loop(). 
510          """ 
511   
512           
513          reset() 
514   
515           
516          ds.add(pipe_name='orig', pipe_type='mf') 
517   
518           
519          i = 0 
520          for residue in mol_res_spin.residue_loop(): 
521              i = i + 1 
522   
523           
524          self.assertEqual(i, 0) 
 525   
526   
528          """Test the proper operation of the residue loop when no data pipe is present. 
529   
530          The function tested is pipe_control.mol_res_spin.residue_loop(). 
531          """ 
532   
533           
534          reset() 
535   
536           
537          def fail_test(): 
538              for residue in mol_res_spin.residue_loop(): 
539                  pass 
 540   
541           
542          self.assertRaises(RelaxNoPipeError, fail_test) 
543   
544   
546          """Test the proper operation of the residue loop when no selection is present. 
547   
548          The function tested is pipe_control.mol_res_spin.residue_loop(). 
549          """ 
550   
551           
552          num = [1, 2, 4, -5, -4] 
553          name = [None, 'Glu', 'Pro', None, None] 
554   
555           
556          i = 0 
557          for res in mol_res_spin.residue_loop(): 
558               
559              self.assertEqual(res.num, num[i]) 
560   
561               
562              self.assertEqual(res.name, name[i]) 
563   
564               
565              i = i + 1 
566   
567           
568          self.assertEqual(i, 5) 
 569   
570   
572          """Test the function for returning the desired molecule data container. 
573   
574          The function tested is pipe_control.mol_res_spin.return_molecule(). 
575          """ 
576   
577           
578          mol1 = mol_res_spin.return_molecule('#Ap4Aase') 
579          mol2 = mol_res_spin.return_molecule(selection='#RNA', pipe='orig') 
580   
581           
582          self.assertEqual(mol1.name, 'Ap4Aase') 
583   
584           
585          self.assertEqual(mol2.name, 'RNA') 
 586   
587   
597   
598   
600          """Test the function for returning the desired residue data container. 
601   
602          The function tested is pipe_control.mol_res_spin.return_residue(). 
603          """ 
604   
605           
606          res1 = mol_res_spin.return_residue(':1') 
607          res2 = mol_res_spin.return_residue(selection=':2') 
608          res4 = mol_res_spin.return_residue(selection=':4', pipe='orig') 
609          res5 = mol_res_spin.return_residue(selection='#RNA:-5', pipe='orig') 
610   
611           
612          self.assertEqual(res1.num, 1) 
613          self.assertEqual(res1.name, None) 
614   
615           
616          self.assertEqual(res2.num, 2) 
617          self.assertEqual(res2.name, 'Glu') 
618   
619           
620          self.assertEqual(res4.num, 4) 
621          self.assertEqual(res4.name, 'Pro') 
622   
623           
624          self.assertEqual(res5.num, -5) 
625          self.assertEqual(res5.name, None) 
626          self.assertEqual(res5.spin[1].name, 'N5') 
 627   
628   
630          """Test the failure of the function for returning the desired residue data container. 
631   
632          The function tested is pipe_control.mol_res_spin.return_residue(). 
633          """ 
634   
635           
636          self.assertRaises(RelaxNoPipeError, mol_res_spin.return_residue, selection=':2', pipe='new') 
 637   
638   
640          """Test the function for returning the desired residue data container. 
641   
642          The function tested is pipe_control.mol_res_spin.return_single_residue_info(). 
643          """ 
644   
645           
646          res1 = mol_res_spin.return_single_residue_info('1') 
647          res2 = mol_res_spin.return_single_residue_info('2,Glu') 
648          res4 = mol_res_spin.return_single_residue_info('Pro,4') 
649          res5 = mol_res_spin.return_single_residue_info('-5') 
650   
651           
652          self.assertEqual(res1, (1, None)) 
653   
654           
655          self.assertEqual(res2, (2, 'Glu')) 
656   
657           
658          self.assertEqual(res4, (4, 'Pro')) 
659   
660           
661          self.assertEqual(res5, (-5, None)) 
 662   
663   
665          """Test the failure of the function for returning the desired residue data container. 
666   
667          The function tested is pipe_control.mol_res_spin.return_single_residue_info(). 
668          """ 
669   
670           
671          self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,2') 
672          self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,Glu,Pro') 
673          self.assertRaises(RelaxError, mol_res_spin.return_single_residue_info, '1,2,Glu,Pro') 
 674   
675   
677          """Test the function for returning the desired spin data container. 
678   
679          The function tested is pipe_control.mol_res_spin.return_spin(). 
680          """ 
681   
682           
683          spin1 = mol_res_spin.return_spin('#Ap4Aase:1') 
684          spin2 = mol_res_spin.return_spin(spin_id='#Ap4Aase:2') 
685          spin3 = mol_res_spin.return_spin(spin_id='#Ap4Aase:4', pipe='orig') 
686          spin4 = mol_res_spin.return_spin(spin_id='#RNA:-5@N5', pipe='orig') 
687          spin5 = mol_res_spin.return_spin(spin_id='#RNA:-4@2H', pipe='orig') 
688   
689           
690          self.assertNotEqual(spin1, None) 
691          self.assertEqual(spin1.num, 60) 
692          self.assertEqual(spin1.name, 'NH') 
693   
694           
695          self.assertNotEqual(spin2, None) 
696          self.assertEqual(spin2.num, 63) 
697          self.assertEqual(spin2.name, 'NH') 
698   
699           
700          self.assertNotEqual(spin3, None) 
701          self.assertEqual(spin3.num, None) 
702          self.assertEqual(spin3.name, None) 
703   
704           
705          self.assertNotEqual(spin4, None) 
706          self.assertEqual(spin4.num, None) 
707          self.assertEqual(spin4.name, 'N5') 
708   
709           
710          self.assertNotEqual(spin5, None) 
711          self.assertEqual(spin5.num, 132) 
712          self.assertEqual(spin5.name, '2H') 
 713   
714   
716          """Test the failure of the function for returning the desired spin data container. 
717   
718          The function tested is pipe_control.mol_res_spin.return_spin(). 
719          """ 
720   
721           
722          self.assertRaises(RelaxNoPipeError, mol_res_spin.return_spin, spin_id=':2', pipe='new') 
 723   
724   
726          """Test the proper operation of the spin loop with spin selection. 
727   
728          The function tested is pipe_control.mol_res_spin.spin_loop(). 
729          """ 
730   
731           
732          select = [1, 0] 
733   
734           
735          i = 0 
736          for spin in mol_res_spin.spin_loop('@N5'): 
737               
738              self.assertEqual(spin.select, select[i]) 
739   
740               
741              self.assertEqual(spin.name, 'N5') 
742   
743               
744              i = i + 1 
745   
746           
747          self.assertEqual(i, 2) 
 748   
749   
751          """Test the operation of the spin loop with the selection "#Ap4Aase:Glu | #RNA@C8". 
752   
753          The function tested is pipe_control.mol_res_spin.spin_loop(). 
754          """ 
755   
756           
757          select = [1, 0, 1] 
758          name = ['NH', 'C8', 'C8'] 
759          num = [63, None, None] 
760   
761           
762          i = 0 
763          for spin in mol_res_spin.spin_loop("#Ap4Aase:Glu | #RNA@C8"): 
764               
765              self.assertEqual([spin.select, spin.name, spin.num], [select[i], name[i], num[i]]) 
766   
767               
768              i = i + 1 
769   
770           
771          self.assertEqual(i, 3) 
 772   
773   
775          """Test the proper operation of the spin loop with spin selection '@NH|@N5'. 
776   
777          The function tested is pipe_control.mol_res_spin.spin_loop(). 
778          """ 
779   
780           
781          select = [0, 1, 1, 0] 
782          name = ['NH', 'NH', 'N5', 'N5'] 
783   
784           
785          i = 0 
786          for spin in mol_res_spin.spin_loop('@NH|@N5'): 
787               
788              self.assertEqual(spin.select, select[i]) 
789   
790               
791              self.assertEqual(spin.name, name[i]) 
792   
793               
794              i = i + 1 
795   
796           
797          self.assertEqual(i, 4) 
 798   
799   
801          """Test the proper operation of the spin loop when no data is present. 
802   
803          The function tested is pipe_control.mol_res_spin.spin_loop(). 
804          """ 
805   
806           
807          reset() 
808   
809           
810          ds.add(pipe_name='orig', pipe_type='mf') 
811   
812           
813          i = 0 
814          for spin in mol_res_spin.spin_loop(): 
815              i = i + 1 
816   
817           
818          self.assertEqual(i, 0) 
 819   
820   
822          """Test the proper operation of the spin loop when no data pipe is present. 
823   
824          The function tested is pipe_control.mol_res_spin.spin_loop(). 
825          """ 
826   
827           
828          reset() 
829   
830           
831          def fail_test(): 
832              for spin in mol_res_spin.spin_loop(): 
833                  pass 
 834   
835           
836          self.assertRaises(RelaxNoPipeError, fail_test) 
837   
838   
840          """Test the proper operation of the spin loop when no selection is present. 
841   
842          The function tested is pipe_control.mol_res_spin.spin_loop(). 
843          """ 
844   
845           
846          select = [0, 1, 0, 0, 1, 1, 0, 1] 
847          name = ['NH', 'NH', None, 'C8', 'N5', 'C8', 'N5', '2H'] 
848   
849           
850          i = 0 
851          for spin in mol_res_spin.spin_loop(): 
852               
853              self.assertEqual(spin.select, select[i]) 
854   
855               
856              self.assertEqual(spin.name, name[i]) 
857   
858               
859              i = i + 1 
860   
861           
862          self.assertEqual(i, 8) 
 863   
864   
866          """Test the operation of the spin loop with the single spin selection '#Ap4Aase:Glu@63'. 
867   
868          The function tested is pipe_control.mol_res_spin.spin_loop(). 
869          """ 
870   
871           
872          i = 0 
873          for spin in mol_res_spin.spin_loop('#Ap4Aase:Glu@63'): 
874               
875              self.assertEqual(spin.select, 1) 
876   
877               
878              self.assertEqual(spin.name, 'NH') 
879   
880               
881              self.assertEqual(spin.num, 63) 
882   
883               
884              i = i + 1 
885   
886           
887          self.assertEqual(i, 1) 
 888   
889   
891          """Test the proper operation of the spin loop with wildcard spin selection '@N*'. 
892   
893          The function tested is pipe_control.mol_res_spin.spin_loop(). 
894          """ 
895   
896           
897          select = [0, 1, 1, 0] 
898          name = ['NH', 'NH', 'N5', 'N5'] 
899   
900           
901          i = 0 
902          for spin in mol_res_spin.spin_loop('@N*'): 
903               
904              self.assertEqual(spin.select, select[i]) 
905   
906               
907              self.assertEqual(spin.name, name[i]) 
908   
909               
910              i = i + 1 
911   
912           
913          self.assertEqual(i, 4) 
 914   
915   
917          """Test boolean and in mol-res-spin selections.""" 
918   
919           
920          sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro")) 
921   
922           
923          self.assertEqual(len(sel), 1) 
924          for res in sel: 
925              self.assert_(res.name == "Pro" and res.num == 4) 
 926   
927   
929          """Test complex boolean mol-res-spin selections.""" 
930   
931           
932          sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro | #RNA")) 
933   
934           
935          names = ['Pro', None, None] 
936          numbers = [4, -5, -4] 
937   
938           
939          self.assertEqual(len(sel), 3) 
940          for i in range(3): 
941              self.assertEqual(sel[i].name, names[i]) 
942              self.assertEqual(sel[i].num, numbers[i]) 
 943   
944   
945       
946       
947       
949          """Test complex boolean mol-res-spin selections with parenthesis.""" 
950   
951           
952          sel = list(mol_res_spin.residue_loop("(#Ap4Aase & :Pro) | (#RNA & :-4)")) 
953   
954           
955          self.assertEqual(len(sel), 2) 
956          for res in sel: 
957              self.assert_(res.num in [-4, 4]) 
 958