Package test_suite :: Package unit_tests :: Package _pipe_control :: Module test_mol_res_spin
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._pipe_control.test_mol_res_spin

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2007-2013 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # relax module imports. 
 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   
30 -class Test_mol_res_spin(UnitTestCase):
31 """Unit tests for the functions of the 'pipe_control.mol_res_spin' module.""" 32
33 - def setUp(self):
34 """Set up some molecules, residues, and spins for testing.""" 35 36 # Add a data pipe to the data store. 37 ds.add(pipe_name='orig', pipe_type='mf') 38 39 # Name the first molecule. 40 cdp.mol[0].name = 'Ap4Aase' 41 42 # Add a second molecule to the system. 43 cdp.mol.add_item(mol_name='RNA') 44 45 # Add two more residues to the first molecule (and set the residue number of the first). 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 # Add some spin info to this molecule. 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 # Add one more residue to the second molecule (and set the residue number of the first). 57 cdp.mol[1].res[0].num = -5 58 cdp.mol[1].res.add_item(res_num=-4) 59 60 # Add a second set of spins to the second molecule (naming the first set first). 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 # Deselect a number of spins. 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 # Update the metadata. 74 mol_res_spin.metadata_update()
75 76
77 - def test_count_spins(self):
78 """Test that the number of spins can be properly counted. 79 80 The function tested is pipe_control.mol_res_spin.count_spins(). 81 """ 82 83 # Test the number of spins counted. 84 self.assertEqual(mol_res_spin.count_spins(), 4) 85 self.assertEqual(mol_res_spin.count_spins(skip_desel=False), 8) 86 self.assertEqual(mol_res_spin.count_spins(selection='@N5'), 1) 87 self.assertEqual(mol_res_spin.count_spins(selection='@N5', skip_desel=False), 2)
88 89
90 - def test_count_no_spins(self):
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 # Reset relax. 97 reset() 98 99 # Add a data pipe to the data store. 100 ds.add(pipe_name='orig', pipe_type='mf') 101 102 # Test the number of spins counted. 103 self.assertEqual(mol_res_spin.count_spins(), 0)
104 105
106 - def test_count_spins_no_pipe(self):
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 # Reset relax. 113 reset() 114 115 # Test for the error. 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 # This should be True. 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 # Reset relax. 136 reset() 137 138 # Add a data pipe to the data store. 139 ds.add(pipe_name='orig', pipe_type='mf') 140 dp = pipes.get_pipe('orig') 141 142 # Name the first molecule. 143 dp.mol[0].name = 'TOM40' 144 145 # This should be True. 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 # Reset relax. 156 reset() 157 158 # Add a data pipe to the data store. 159 ds.add(pipe_name='orig', pipe_type='mf') 160 dp = pipes.get_pipe('orig') 161 162 # Name the first residue. 163 dp.mol[0].res[0].name = 'Lys' 164 165 # This should be True. 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 # Reset relax. 176 reset() 177 178 # Add a data pipe to the data store. 179 ds.add(pipe_name='orig', pipe_type='mf') 180 dp = pipes.get_pipe('orig') 181 182 # Number the first residue. 183 dp.mol[0].res[0].num = 1 184 185 # This should be True. 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 # Reset relax. 196 reset() 197 198 # Add a data pipe to the data store. 199 ds.add(pipe_name='orig', pipe_type='mf') 200 dp = pipes.get_pipe('orig') 201 202 # Name the first spin. 203 dp.mol[0].res[0].spin[0].name = 'NH' 204 205 # This should be True. 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 # Reset relax. 216 reset() 217 218 # Add a data pipe to the data store. 219 ds.add(pipe_name='orig', pipe_type='mf') 220 dp = pipes.get_pipe('orig') 221 222 # Number the first spin. 223 dp.mol[0].res[0].spin[0].num = 234 224 225 # This should be True. 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 # Reset relax. 236 reset() 237 238 # Add a data pipe to the data store. 239 ds.add(pipe_name='orig', pipe_type='mf') 240 241 # This should be False. 242 self.failIf(mol_res_spin.exists_mol_res_spin_data())
243 244
246 """Determine if molecule-residue-spin data exists when no data pipe exists. 247 248 The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data(). 249 """ 250 251 # Reset relax. 252 reset() 253 254 # This should fail. 255 self.assertRaises(RelaxNoPipeError, mol_res_spin.exists_mol_res_spin_data)
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 # The data. 265 data = ['1', 'GLY'] 266 267 # The ID. 268 id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2) 269 270 # Test the string. 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 # The data. 281 data = ['1', 'GLY', '234', 'NH'] 282 283 # The ID. 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 # Test the string. 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 # The data. 297 data = ['Ap4Aase', '234', 'NH'] 298 299 # The ID. 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 # Test the string. 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 # The data. 313 data = ['Ap4Aase', '1', 'GLY'] 314 315 # The ID. 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 # Test the string. 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 # The data. 329 data = ['Ap4Aase', '1', 'GLY', '234', 'NH'] 330 331 # The ID. 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 # Test the string. 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 # The data. 345 data = ['1', 'GLY', None, None] 346 347 # The ID. 348 id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2) 349 350 # Test the string. 351 self.assertEqual(id, ':1')
352 353
354 - def test_molecule_loop(self):
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 # Loop over the molecules. 361 for mol in mol_res_spin.molecule_loop('#RNA'): 362 # Test the molecule name. 363 self.assertEqual(mol.name, 'RNA') 364 365 # Test loop length. 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 # Reset relax. 376 reset() 377 378 # Add a data pipe to the data store. 379 ds.add(pipe_name='orig', pipe_type='mf') 380 381 # Loop over the molecules. 382 i = 0 383 for molecule in mol_res_spin.molecule_loop(): 384 i = i + 1 385 386 # Test loop length. 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 # Reset relax. 397 reset() 398 399 # Function for the problem of catching an error in a generator function. 400 def fail_test(): 401 for molecule in mol_res_spin.molecule_loop(): 402 pass
403 404 # Test for the no pipe error. 405 self.assertRaises(RelaxNoPipeError, fail_test)
406 407
408 - def test_molecule_loop_no_selection(self):
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 # Molecule data. 415 name = ['Ap4Aase', 'RNA'] 416 417 # Loop over the molecules. 418 i = 0 419 for mol in mol_res_spin.molecule_loop(): 420 # Test the molecule names. 421 self.assertEqual(mol.name, name[i]) 422 423 # Increment i. 424 i = i + 1 425 426 # Test loop length. 427 self.assertEqual(len(list(mol_res_spin.molecule_loop())), 2)
428 429
430 - def test_residue_loop(self):
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 # Loop over the residues. 437 for res in mol_res_spin.residue_loop('#Ap4Aase:Glu'): 438 # Test the selection. 439 self.assertEqual(res.num, 2) 440 441 # Test loop length. 442 self.assertEqual(len(list(mol_res_spin.residue_loop('#Ap4Aase:Glu'))), 1)
443 444
445 - def test_residue_loop_no_data(self):
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 # Reset relax. 452 reset() 453 454 # Add a data pipe to the data store. 455 ds.add(pipe_name='orig', pipe_type='mf') 456 457 # Loop over the residues. 458 i = 0 459 for residue in mol_res_spin.residue_loop(): 460 i = i + 1 461 462 # Test loop length. 463 self.assertEqual(i, 0)
464 465
466 - def test_residue_loop_no_pipe(self):
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 # Reset relax. 473 reset() 474 475 # Function for the problem of catching an error in a generator function. 476 def fail_test(): 477 for residue in mol_res_spin.residue_loop(): 478 pass
479 480 # Test for the no pipe error. 481 self.assertRaises(RelaxNoPipeError, fail_test) 482 483
484 - def test_residue_loop_no_selection(self):
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 # Spin data. 491 num = [1, 2, 4, -5, -4] 492 name = [None, 'Glu', 'Pro', None, None] 493 494 # Loop over the residues. 495 i = 0 496 for res in mol_res_spin.residue_loop(): 497 # Test the residue numbers. 498 self.assertEqual(res.num, num[i]) 499 500 # Test the residue names. 501 self.assertEqual(res.name, name[i]) 502 503 # Increment i. 504 i = i + 1 505 506 # Test loop length. 507 self.assertEqual(i, 5)
508 509
510 - def test_return_molecule(self):
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 # Ask for a few molecules. 517 mol1 = mol_res_spin.return_molecule('#Ap4Aase') 518 mol2 = mol_res_spin.return_molecule(selection='#RNA', pipe='orig') 519 520 # Test the data of molecule 1. 521 self.assertEqual(mol1.name, 'Ap4Aase') 522 523 # Test the data of molecule 2. 524 self.assertEqual(mol2.name, 'RNA')
525 526
527 - def test_return_molecule_pipe_fail(self):
528 """Test the failure of the function for returning the desired molecule data container. 529 530 The function tested is pipe_control.mol_res_spin.return_molecule(). 531 """ 532 533 # Try to get a molecule from a missing data pipe. 534 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_molecule, selection='#Ap4Aase', pipe='new') 535 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_molecule, selection='#RNA', pipe='new')
536 537
538 - def test_return_residue(self):
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 # Ask for a few residues. 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 # Test the data of residue 1. 551 self.assertEqual(res1.num, 1) 552 self.assertEqual(res1.name, None) 553 554 # Test the data of residue 2. 555 self.assertEqual(res2.num, 2) 556 self.assertEqual(res2.name, 'Glu') 557 558 # Test the data of residue 4. 559 self.assertEqual(res4.num, 4) 560 self.assertEqual(res4.name, 'Pro') 561 562 # Test the data of the RNA residue -5. 563 self.assertEqual(res5.num, -5) 564 self.assertEqual(res5.name, None) 565 self.assertEqual(res5.spin[1].name, 'N5')
566 567
568 - def test_return_residue_pipe_fail(self):
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 # Try to get a residue from a missing data pipe. 575 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_residue, selection=':2', pipe='new')
576 577
578 - def test_return_single_residue_info(self):
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 # Ask for a few residues. 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 # Test the data of residue 1. 591 self.assertEqual(res1, (1, None)) 592 593 # Test the data of residue 2. 594 self.assertEqual(res2, (2, 'Glu')) 595 596 # Test the data of residue 4. 597 self.assertEqual(res4, (4, 'Pro')) 598 599 # Test the data of the RNA residue -5. 600 self.assertEqual(res5, (-5, None))
601 602
603 - def test_return_single_residue_info_fail(self):
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 # Ask for a few residues. 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
615 - def test_return_spin(self):
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 # Ask for a few spins. 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 # Test the data of spin 1. 629 self.assertNotEqual(spin1, None) 630 self.assertEqual(spin1.num, 60) 631 self.assertEqual(spin1.name, 'NH') 632 633 # Test the data of spin 2. 634 self.assertNotEqual(spin2, None) 635 self.assertEqual(spin2.num, 63) 636 self.assertEqual(spin2.name, 'NH') 637 638 # Test the data of spin 3. 639 self.assertNotEqual(spin3, None) 640 self.assertEqual(spin3.num, None) 641 self.assertEqual(spin3.name, None) 642 643 # Test the data of the RNA res -5, spin N5. 644 self.assertNotEqual(spin4, None) 645 self.assertEqual(spin4.num, None) 646 self.assertEqual(spin4.name, 'N5') 647 648 # Test the data of the RNA res -4, spin 2H. 649 self.assertNotEqual(spin5, None) 650 self.assertEqual(spin5.num, 132) 651 self.assertEqual(spin5.name, '2H')
652 653
654 - def test_return_spin_pipe_fail(self):
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 # Try to get a spin from a missing data pipe. 661 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_spin, spin_id=':2', pipe='new')
662 663
664 - def test_spin_loop(self):
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 # Spin data. 671 select = [1, 0] 672 673 # Loop over the spins. 674 i = 0 675 for spin in mol_res_spin.spin_loop('@N5'): 676 # Test the selection. 677 self.assertEqual(spin.select, select[i]) 678 679 # Test the spin names. 680 self.assertEqual(spin.name, 'N5') 681 682 # Increment i. 683 i = i + 1 684 685 # Test loop length. 686 self.assertEqual(i, 2)
687 688
689 - def test_spin_loop_boolean_or(self):
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 # Selection, and spin name and number. 696 select = [1, 0, 1] 697 name = ['NH', 'C8', 'C8'] 698 num = [63, None, None] 699 700 # Loop over the spins. 701 i = 0 702 for spin in mol_res_spin.spin_loop("#Ap4Aase:Glu | #RNA@C8"): 703 # Test the spin. 704 self.assertEqual([spin.select, spin.name, spin.num], [select[i], name[i], num[i]]) 705 706 # Increment i. 707 i = i + 1 708 709 # Test loop length. 710 self.assertEqual(i, 3)
711 712
713 - def test_spin_loop_multiatom(self):
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 # Spin data. 720 select = [0, 1, 1, 0] 721 name = ['NH', 'NH', 'N5', 'N5'] 722 723 # Loop over the spins. 724 i = 0 725 for spin in mol_res_spin.spin_loop('@NH|@N5'): 726 # Test the selection. 727 self.assertEqual(spin.select, select[i]) 728 729 # Test the spin names. 730 self.assertEqual(spin.name, name[i]) 731 732 # Increment i. 733 i = i + 1 734 735 # Test loop length. 736 self.assertEqual(i, 4)
737 738
739 - def test_spin_loop_no_data(self):
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 # Reset relax. 746 reset() 747 748 # Add a data pipe to the data store. 749 ds.add(pipe_name='orig', pipe_type='mf') 750 751 # Loop over the spins. 752 i = 0 753 for spin in mol_res_spin.spin_loop(): 754 i = i + 1 755 756 # Test loop length. 757 self.assertEqual(i, 0)
758 759
760 - def test_spin_loop_no_pipe(self):
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 # Reset relax. 767 reset() 768 769 # Function for the problem of catching an error in a generator function. 770 def fail_test(): 771 for spin in mol_res_spin.spin_loop(): 772 pass
773 774 # Test for the no pipe error. 775 self.assertRaises(RelaxNoPipeError, fail_test) 776 777
778 - def test_spin_loop_no_selection(self):
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 # Spin data. 785 select = [0, 1, 0, 0, 1, 1, 0, 1] 786 name = ['NH', 'NH', None, 'C8', 'N5', 'C8', 'N5', '2H'] 787 788 # Loop over the spins. 789 i = 0 790 for spin in mol_res_spin.spin_loop(): 791 # Test the selection. 792 self.assertEqual(spin.select, select[i]) 793 794 # Test the spin names. 795 self.assertEqual(spin.name, name[i]) 796 797 # Increment i. 798 i = i + 1 799 800 # Test loop length. 801 self.assertEqual(i, 8)
802 803
804 - def test_spin_loop_single_spin(self):
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 # Loop over the spins. 811 i = 0 812 for spin in mol_res_spin.spin_loop('#Ap4Aase:Glu@63'): 813 # Test the selection. 814 self.assertEqual(spin.select, 1) 815 816 # Test the spin name. 817 self.assertEqual(spin.name, 'NH') 818 819 # Test the spin number. 820 self.assertEqual(spin.num, 63) 821 822 # Increment i. 823 i = i + 1 824 825 # Test loop length. 826 self.assertEqual(i, 1)
827 828
829 - def test_spin_loop_wildcard(self):
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 # Spin data. 836 select = [0, 1, 1, 0] 837 name = ['NH', 'NH', 'N5', 'N5'] 838 839 # Loop over the spins. 840 i = 0 841 for spin in mol_res_spin.spin_loop('@N*'): 842 # Test the selection. 843 self.assertEqual(spin.select, select[i]) 844 845 # Test the spin names. 846 self.assertEqual(spin.name, name[i]) 847 848 # Increment i. 849 i = i + 1 850 851 # Test loop length. 852 self.assertEqual(i, 4)
853 854
855 - def test_boolean_and_selection(self):
856 """Test boolean and in mol-res-spin selections.""" 857 858 # The selection loop: 859 sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro")) 860 861 # Test: 862 self.assertEqual(len(sel), 1) 863 for res in sel: 864 self.assert_(res.name == "Pro" and res.num == 4)
865 866
867 - def test_boolean_complex_selection(self):
868 """Test complex boolean mol-res-spin selections.""" 869 870 # The residue selection loop. 871 sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro | #RNA")) 872 873 # Residue names and numbers. 874 names = ['Pro', None, None] 875 numbers = [4, -5, -4] 876 877 # The residues. 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 # Test disabled until this functionality is enabled. # 886 ######################################################
887 - def fixme_test_boolean_parenthesis_selection(self):
888 """Test complex boolean mol-res-spin selections with parenthesis.""" 889 890 # The selection loop: 891 sel = list(mol_res_spin.residue_loop("(#Ap4Aase & :Pro) | (#RNA & :-4)")) 892 893 # Test: 894 self.assertEqual(len(sel), 2) 895 for res in sel: 896 self.assert_(res.num in [-4, 4])
897