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-2008,2011-2012,2014 Edward d'Auvergne                    # 
  4  # Copyright (C) 2007 Chris MacRaild                                           # 
  5  #                                                                             # 
  6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  7  #                                                                             # 
  8  # This program is free software: you can redistribute it and/or modify        # 
  9  # it under the terms of the GNU General Public License as published by        # 
 10  # the Free Software Foundation, either version 3 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # This program is distributed in the hope that it will be useful,             # 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 16  # GNU General Public License for more details.                                # 
 17  #                                                                             # 
 18  # You should have received a copy of the GNU General Public License           # 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # relax module imports. 
 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   
31 -class Test_mol_res_spin(UnitTestCase):
32 """Unit tests for the functions of the 'pipe_control.mol_res_spin' module.""" 33
34 - def setUp(self):
35 """Set up some molecules, residues, and spins for testing.""" 36 37 # Add a data pipe to the data store. 38 ds.add(pipe_name='orig', pipe_type='mf') 39 40 # Name the first molecule. 41 cdp.mol[0].name = 'Ap4Aase' 42 43 # Add a second molecule to the system. 44 cdp.mol.add_item(mol_name='RNA') 45 46 # Add two more residues to the first molecule (and set the residue number of the first). 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 # Add some spin info to this molecule. 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 # Add one more residue to the second molecule (and set the residue number of the first). 58 cdp.mol[1].res[0].num = -5 59 cdp.mol[1].res.add_item(res_num=-4) 60 61 # Add a second set of spins to the second molecule (naming the first set first). 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 # Deselect a number of spins. 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 # Update the metadata. 75 mol_res_spin.metadata_update()
76 77
78 - def test_count_spins(self):
79 """Test that the number of spins can be properly counted. 80 81 The function tested is pipe_control.mol_res_spin.count_spins(). 82 """ 83 84 # Test the number of spins counted. 85 self.assertEqual(mol_res_spin.count_spins(), 4) 86 self.assertEqual(mol_res_spin.count_spins(skip_desel=False), 8) 87 self.assertEqual(mol_res_spin.count_spins(selection='@N5'), 1) 88 self.assertEqual(mol_res_spin.count_spins(selection='@N5', skip_desel=False), 2)
89 90
91 - def test_count_no_spins(self):
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 # Reset relax. 98 reset() 99 100 # Add a data pipe to the data store. 101 ds.add(pipe_name='orig', pipe_type='mf') 102 103 # Test the number of spins counted. 104 self.assertEqual(mol_res_spin.count_spins(), 0)
105 106
107 - def test_count_spins_no_pipe(self):
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 # Reset relax. 114 reset() 115 116 # Test for the error. 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 # This should be True. 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 # Reset relax. 137 reset() 138 139 # Add a data pipe to the data store. 140 ds.add(pipe_name='orig', pipe_type='mf') 141 dp = pipes.get_pipe('orig') 142 143 # Name the first molecule. 144 dp.mol[0].name = 'TOM40' 145 146 # This should be True. 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 # Reset relax. 157 reset() 158 159 # Add a data pipe to the data store. 160 ds.add(pipe_name='orig', pipe_type='mf') 161 dp = pipes.get_pipe('orig') 162 163 # Name the first residue. 164 dp.mol[0].res[0].name = 'Lys' 165 166 # This should be True. 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 # Reset relax. 177 reset() 178 179 # Add a data pipe to the data store. 180 ds.add(pipe_name='orig', pipe_type='mf') 181 dp = pipes.get_pipe('orig') 182 183 # Number the first residue. 184 dp.mol[0].res[0].num = 1 185 186 # This should be True. 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 # Reset relax. 197 reset() 198 199 # Add a data pipe to the data store. 200 ds.add(pipe_name='orig', pipe_type='mf') 201 dp = pipes.get_pipe('orig') 202 203 # Name the first spin. 204 dp.mol[0].res[0].spin[0].name = 'NH' 205 206 # This should be True. 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 # Reset relax. 217 reset() 218 219 # Add a data pipe to the data store. 220 ds.add(pipe_name='orig', pipe_type='mf') 221 dp = pipes.get_pipe('orig') 222 223 # Number the first spin. 224 dp.mol[0].res[0].spin[0].num = 234 225 226 # This should be True. 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 # Reset relax. 237 reset() 238 239 # Add a data pipe to the data store. 240 ds.add(pipe_name='orig', pipe_type='mf') 241 242 # This should be False. 243 self.failIf(mol_res_spin.exists_mol_res_spin_data())
244 245
247 """Determine if molecule-residue-spin data exists when no data pipe exists. 248 249 The function tested is pipe_control.mol_res_spin.exists_mol_res_spin_data(). 250 """ 251 252 # Reset relax. 253 reset() 254 255 # This should fail. 256 self.assertRaises(RelaxNoPipeError, mol_res_spin.exists_mol_res_spin_data)
257 258
259 - def test_format_info_full1(self):
260 """Test the format_info_full() function for all combinations of input.""" 261 262 # The spin info and expected string - covering all possible combinations. 263 info = [ 264 # 5 bits of info. 265 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': 10, 'spin_name': 'N', 'spin_num': 200, 'string': "Molecule Ubi, residue Ala 10, spin N 200"}, 266 267 # 4 bits of info. 268 {'mol_name': None, 'res_name': 'Ala', 'res_num': 10, 'spin_name': 'N', 'spin_num': 200, 'string': "Residue Ala 10, spin N 200"}, 269 {'mol_name': 'Ubi', 'res_name': None, 'res_num': 10, 'spin_name': 'N', 'spin_num': 200, 'string': "Molecule Ubi, residue 10, spin N 200"}, 270 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': None, 'spin_name': 'N', 'spin_num': 200, 'string': "Molecule Ubi, residue Ala, spin N 200"}, 271 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': 10, 'spin_name': None, 'spin_num': 200, 'string': "Molecule Ubi, residue Ala 10, spin 200"}, 272 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': 10, 'spin_name': 'N', 'spin_num': None, 'string': "Molecule Ubi, residue Ala 10, spin N"}, 273 274 # 3 bits of info. 275 {'mol_name': None, 'res_name': None, 'res_num': 10, 'spin_name': 'N', 'spin_num': 200, 'string': "Residue 10, spin N 200"}, 276 {'mol_name': None, 'res_name': 'Ala', 'res_num': None, 'spin_name': 'N', 'spin_num': 200, 'string': "Residue Ala, spin N 200"}, 277 {'mol_name': None, 'res_name': 'Ala', 'res_num': 10, 'spin_name': None, 'spin_num': 200, 'string': "Residue Ala 10, spin 200"}, 278 {'mol_name': None, 'res_name': 'Ala', 'res_num': 10, 'spin_name': 'N', 'spin_num': None, 'string': "Residue Ala 10, spin N"}, 279 {'mol_name': 'Ubi', 'res_name': None, 'res_num': None, 'spin_name': 'N', 'spin_num': 200, 'string': "Molecule Ubi, spin N 200"}, 280 {'mol_name': 'Ubi', 'res_name': None, 'res_num': 10, 'spin_name': None, 'spin_num': 200, 'string': "Molecule Ubi, residue 10, spin 200"}, 281 {'mol_name': 'Ubi', 'res_name': None, 'res_num': 10, 'spin_name': 'N', 'spin_num': None, 'string': "Molecule Ubi, residue 10, spin N"}, 282 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': None, 'spin_name': None, 'spin_num': 200, 'string': "Molecule Ubi, residue Ala, spin 200"}, 283 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': None, 'spin_name': 'N', 'spin_num': None, 'string': "Molecule Ubi, residue Ala, spin N"}, 284 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': 10, 'spin_name': None, 'spin_num': None, 'string': "Molecule Ubi, residue Ala 10"}, 285 286 # 2 bits of info. 287 {'mol_name': None, 'res_name': None, 'res_num': None, 'spin_name': 'N', 'spin_num': 200, 'string': "Spin N 200"}, 288 {'mol_name': None, 'res_name': None, 'res_num': 10, 'spin_name': None, 'spin_num': 200, 'string': "Residue 10, spin 200"}, 289 {'mol_name': None, 'res_name': None, 'res_num': 10, 'spin_name': 'N', 'spin_num': None, 'string': "Residue 10, spin N"}, 290 {'mol_name': None, 'res_name': 'Ala', 'res_num': None, 'spin_name': None, 'spin_num': 200, 'string': "Residue Ala, spin 200"}, 291 {'mol_name': None, 'res_name': 'Ala', 'res_num': None, 'spin_name': 'N', 'spin_num': None, 'string': "Residue Ala, spin N"}, 292 {'mol_name': None, 'res_name': 'Ala', 'res_num': 10, 'spin_name': None, 'spin_num': None, 'string': "Residue Ala 10"}, 293 {'mol_name': 'Ubi', 'res_name': None, 'res_num': None, 'spin_name': None, 'spin_num': 200, 'string': "Molecule Ubi, spin 200"}, 294 {'mol_name': 'Ubi', 'res_name': None, 'res_num': None, 'spin_name': 'N', 'spin_num': None, 'string': "Molecule Ubi, spin N"}, 295 {'mol_name': 'Ubi', 'res_name': None, 'res_num': 10, 'spin_name': None, 'spin_num': None, 'string': "Molecule Ubi, residue 10"}, 296 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': None, 'spin_name': None, 'spin_num': None, 'string': "Molecule Ubi, residue Ala"}, 297 298 # 1 bit of info. 299 {'mol_name': None, 'res_name': None, 'res_num': None, 'spin_name': None, 'spin_num': 200, 'string': "Spin 200"}, 300 {'mol_name': None, 'res_name': None, 'res_num': None, 'spin_name': 'N', 'spin_num': None, 'string': "Spin N"}, 301 {'mol_name': None, 'res_name': None, 'res_num': 10, 'spin_name': None, 'spin_num': None, 'string': "Residue 10"}, 302 {'mol_name': None, 'res_name': 'Ala', 'res_num': None, 'spin_name': None, 'spin_num': None, 'string': "Residue Ala"}, 303 {'mol_name': 'Ubi', 'res_name': None, 'res_num': None, 'spin_name': None, 'spin_num': None, 'string': "Molecule Ubi"}, 304 305 # 0 bits of info. 306 {'mol_name': None, 'res_name': None, 'res_num': None, 'spin_name': None, 'spin_num': None, 'string': ""}, 307 ] 308 309 # Printout. 310 print("Checking %s combinations." % len(info)) 311 312 # Create and check each string. 313 for i in range(len(info)): 314 print(" Checking %s" % info[i]) 315 string = mol_res_spin.format_info_full(mol_name=info[i]['mol_name'], res_name=info[i]['res_name'], res_num=info[i]['res_num'], spin_name=info[i]['spin_name'], spin_num=info[i]['spin_num']) 316 self.assertEqual(string, info[i]['string'])
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 # The data. 326 data = ['1', 'GLY'] 327 328 # The ID. 329 id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2) 330 331 # Test the string. 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 # The data. 342 data = ['1', 'GLY', '234', 'NH'] 343 344 # The ID. 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 # Test the string. 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 # The data. 358 data = ['Ap4Aase', '234', 'NH'] 359 360 # The ID. 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 # Test the string. 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 # The data. 374 data = ['Ap4Aase', '1', 'GLY'] 375 376 # The ID. 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 # Test the string. 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 # The data. 390 data = ['Ap4Aase', '1', 'GLY', '234', 'NH'] 391 392 # The ID. 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 # Test the string. 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 # The data. 406 data = ['1', 'GLY', None, None] 407 408 # The ID. 409 id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2) 410 411 # Test the string. 412 self.assertEqual(id, ':1')
413 414
415 - def test_molecule_loop(self):
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 # Loop over the molecules. 422 for mol in mol_res_spin.molecule_loop('#RNA'): 423 # Test the molecule name. 424 self.assertEqual(mol.name, 'RNA') 425 426 # Test loop length. 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 # Reset relax. 437 reset() 438 439 # Add a data pipe to the data store. 440 ds.add(pipe_name='orig', pipe_type='mf') 441 442 # Loop over the molecules. 443 i = 0 444 for molecule in mol_res_spin.molecule_loop(): 445 i = i + 1 446 447 # Test loop length. 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 # Reset relax. 458 reset() 459 460 # Function for the problem of catching an error in a generator function. 461 def fail_test(): 462 for molecule in mol_res_spin.molecule_loop(): 463 pass
464 465 # Test for the no pipe error. 466 self.assertRaises(RelaxNoPipeError, fail_test)
467 468
469 - def test_molecule_loop_no_selection(self):
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 # Molecule data. 476 name = ['Ap4Aase', 'RNA'] 477 478 # Loop over the molecules. 479 i = 0 480 for mol in mol_res_spin.molecule_loop(): 481 # Test the molecule names. 482 self.assertEqual(mol.name, name[i]) 483 484 # Increment i. 485 i = i + 1 486 487 # Test loop length. 488 self.assertEqual(len(list(mol_res_spin.molecule_loop())), 2)
489 490
491 - def test_residue_loop(self):
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 # Loop over the residues. 498 for res in mol_res_spin.residue_loop('#Ap4Aase:Glu'): 499 # Test the selection. 500 self.assertEqual(res.num, 2) 501 502 # Test loop length. 503 self.assertEqual(len(list(mol_res_spin.residue_loop('#Ap4Aase:Glu'))), 1)
504 505
506 - def test_residue_loop_no_data(self):
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 # Reset relax. 513 reset() 514 515 # Add a data pipe to the data store. 516 ds.add(pipe_name='orig', pipe_type='mf') 517 518 # Loop over the residues. 519 i = 0 520 for residue in mol_res_spin.residue_loop(): 521 i = i + 1 522 523 # Test loop length. 524 self.assertEqual(i, 0)
525 526
527 - def test_residue_loop_no_pipe(self):
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 # Reset relax. 534 reset() 535 536 # Function for the problem of catching an error in a generator function. 537 def fail_test(): 538 for residue in mol_res_spin.residue_loop(): 539 pass
540 541 # Test for the no pipe error. 542 self.assertRaises(RelaxNoPipeError, fail_test) 543 544
545 - def test_residue_loop_no_selection(self):
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 # Spin data. 552 num = [1, 2, 4, -5, -4] 553 name = [None, 'Glu', 'Pro', None, None] 554 555 # Loop over the residues. 556 i = 0 557 for res in mol_res_spin.residue_loop(): 558 # Test the residue numbers. 559 self.assertEqual(res.num, num[i]) 560 561 # Test the residue names. 562 self.assertEqual(res.name, name[i]) 563 564 # Increment i. 565 i = i + 1 566 567 # Test loop length. 568 self.assertEqual(i, 5)
569 570
571 - def test_return_molecule(self):
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 # Ask for a few molecules. 578 mol1 = mol_res_spin.return_molecule('#Ap4Aase') 579 mol2 = mol_res_spin.return_molecule(selection='#RNA', pipe='orig') 580 581 # Test the data of molecule 1. 582 self.assertEqual(mol1.name, 'Ap4Aase') 583 584 # Test the data of molecule 2. 585 self.assertEqual(mol2.name, 'RNA')
586 587
588 - def test_return_molecule_pipe_fail(self):
589 """Test the failure of the function for returning the desired molecule data container. 590 591 The function tested is pipe_control.mol_res_spin.return_molecule(). 592 """ 593 594 # Try to get a molecule from a missing data pipe. 595 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_molecule, selection='#Ap4Aase', pipe='new') 596 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_molecule, selection='#RNA', pipe='new')
597 598
599 - def test_return_residue(self):
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 # Ask for a few residues. 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 # Test the data of residue 1. 612 self.assertEqual(res1.num, 1) 613 self.assertEqual(res1.name, None) 614 615 # Test the data of residue 2. 616 self.assertEqual(res2.num, 2) 617 self.assertEqual(res2.name, 'Glu') 618 619 # Test the data of residue 4. 620 self.assertEqual(res4.num, 4) 621 self.assertEqual(res4.name, 'Pro') 622 623 # Test the data of the RNA residue -5. 624 self.assertEqual(res5.num, -5) 625 self.assertEqual(res5.name, None) 626 self.assertEqual(res5.spin[1].name, 'N5')
627 628
629 - def test_return_residue_pipe_fail(self):
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 # Try to get a residue from a missing data pipe. 636 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_residue, selection=':2', pipe='new')
637 638
639 - def test_return_single_residue_info(self):
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 # Ask for a few residues. 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 # Test the data of residue 1. 652 self.assertEqual(res1, (1, None)) 653 654 # Test the data of residue 2. 655 self.assertEqual(res2, (2, 'Glu')) 656 657 # Test the data of residue 4. 658 self.assertEqual(res4, (4, 'Pro')) 659 660 # Test the data of the RNA residue -5. 661 self.assertEqual(res5, (-5, None))
662 663
664 - def test_return_single_residue_info_fail(self):
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 # Ask for a few residues. 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
676 - def test_return_spin(self):
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 # Ask for a few spins. 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 # Test the data of spin 1. 690 self.assertNotEqual(spin1, None) 691 self.assertEqual(spin1.num, 60) 692 self.assertEqual(spin1.name, 'NH') 693 694 # Test the data of spin 2. 695 self.assertNotEqual(spin2, None) 696 self.assertEqual(spin2.num, 63) 697 self.assertEqual(spin2.name, 'NH') 698 699 # Test the data of spin 3. 700 self.assertNotEqual(spin3, None) 701 self.assertEqual(spin3.num, None) 702 self.assertEqual(spin3.name, None) 703 704 # Test the data of the RNA res -5, spin N5. 705 self.assertNotEqual(spin4, None) 706 self.assertEqual(spin4.num, None) 707 self.assertEqual(spin4.name, 'N5') 708 709 # Test the data of the RNA res -4, spin 2H. 710 self.assertNotEqual(spin5, None) 711 self.assertEqual(spin5.num, 132) 712 self.assertEqual(spin5.name, '2H')
713 714
715 - def test_return_spin_pipe_fail(self):
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 # Try to get a spin from a missing data pipe. 722 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_spin, spin_id=':2', pipe='new')
723 724
725 - def test_spin_loop(self):
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 # Spin data. 732 select = [1, 0] 733 734 # Loop over the spins. 735 i = 0 736 for spin in mol_res_spin.spin_loop('@N5'): 737 # Test the selection. 738 self.assertEqual(spin.select, select[i]) 739 740 # Test the spin names. 741 self.assertEqual(spin.name, 'N5') 742 743 # Increment i. 744 i = i + 1 745 746 # Test loop length. 747 self.assertEqual(i, 2)
748 749
750 - def test_spin_loop_boolean_or(self):
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 # Selection, and spin name and number. 757 select = [1, 0, 1] 758 name = ['NH', 'C8', 'C8'] 759 num = [63, None, None] 760 761 # Loop over the spins. 762 i = 0 763 for spin in mol_res_spin.spin_loop("#Ap4Aase:Glu | #RNA@C8"): 764 # Test the spin. 765 self.assertEqual([spin.select, spin.name, spin.num], [select[i], name[i], num[i]]) 766 767 # Increment i. 768 i = i + 1 769 770 # Test loop length. 771 self.assertEqual(i, 3)
772 773
774 - def test_spin_loop_multiatom(self):
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 # Spin data. 781 select = [0, 1, 1, 0] 782 name = ['NH', 'NH', 'N5', 'N5'] 783 784 # Loop over the spins. 785 i = 0 786 for spin in mol_res_spin.spin_loop('@NH|@N5'): 787 # Test the selection. 788 self.assertEqual(spin.select, select[i]) 789 790 # Test the spin names. 791 self.assertEqual(spin.name, name[i]) 792 793 # Increment i. 794 i = i + 1 795 796 # Test loop length. 797 self.assertEqual(i, 4)
798 799
800 - def test_spin_loop_no_data(self):
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 # Reset relax. 807 reset() 808 809 # Add a data pipe to the data store. 810 ds.add(pipe_name='orig', pipe_type='mf') 811 812 # Loop over the spins. 813 i = 0 814 for spin in mol_res_spin.spin_loop(): 815 i = i + 1 816 817 # Test loop length. 818 self.assertEqual(i, 0)
819 820
821 - def test_spin_loop_no_pipe(self):
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 # Reset relax. 828 reset() 829 830 # Function for the problem of catching an error in a generator function. 831 def fail_test(): 832 for spin in mol_res_spin.spin_loop(): 833 pass
834 835 # Test for the no pipe error. 836 self.assertRaises(RelaxNoPipeError, fail_test) 837 838
839 - def test_spin_loop_no_selection(self):
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 # Spin data. 846 select = [0, 1, 0, 0, 1, 1, 0, 1] 847 name = ['NH', 'NH', None, 'C8', 'N5', 'C8', 'N5', '2H'] 848 849 # Loop over the spins. 850 i = 0 851 for spin in mol_res_spin.spin_loop(): 852 # Test the selection. 853 self.assertEqual(spin.select, select[i]) 854 855 # Test the spin names. 856 self.assertEqual(spin.name, name[i]) 857 858 # Increment i. 859 i = i + 1 860 861 # Test loop length. 862 self.assertEqual(i, 8)
863 864
865 - def test_spin_loop_single_spin(self):
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 # Loop over the spins. 872 i = 0 873 for spin in mol_res_spin.spin_loop('#Ap4Aase:Glu@63'): 874 # Test the selection. 875 self.assertEqual(spin.select, 1) 876 877 # Test the spin name. 878 self.assertEqual(spin.name, 'NH') 879 880 # Test the spin number. 881 self.assertEqual(spin.num, 63) 882 883 # Increment i. 884 i = i + 1 885 886 # Test loop length. 887 self.assertEqual(i, 1)
888 889
890 - def test_spin_loop_wildcard(self):
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 # Spin data. 897 select = [0, 1, 1, 0] 898 name = ['NH', 'NH', 'N5', 'N5'] 899 900 # Loop over the spins. 901 i = 0 902 for spin in mol_res_spin.spin_loop('@N*'): 903 # Test the selection. 904 self.assertEqual(spin.select, select[i]) 905 906 # Test the spin names. 907 self.assertEqual(spin.name, name[i]) 908 909 # Increment i. 910 i = i + 1 911 912 # Test loop length. 913 self.assertEqual(i, 4)
914 915
916 - def test_boolean_and_selection(self):
917 """Test boolean and in mol-res-spin selections.""" 918 919 # The selection loop: 920 sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro")) 921 922 # Test: 923 self.assertEqual(len(sel), 1) 924 for res in sel: 925 self.assert_(res.name == "Pro" and res.num == 4)
926 927
928 - def test_boolean_complex_selection(self):
929 """Test complex boolean mol-res-spin selections.""" 930 931 # The residue selection loop. 932 sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro | #RNA")) 933 934 # Residue names and numbers. 935 names = ['Pro', None, None] 936 numbers = [4, -5, -4] 937 938 # The residues. 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 # Test disabled until this functionality is enabled. # 947 ######################################################
948 - def fixme_test_boolean_parenthesis_selection(self):
949 """Test complex boolean mol-res-spin selections with parenthesis.""" 950 951 # The selection loop: 952 sel = list(mol_res_spin.residue_loop("(#Ap4Aase & :Pro) | (#RNA & :-4)")) 953 954 # Test: 955 self.assertEqual(len(sel), 2) 956 for res in sel: 957 self.assert_(res.num in [-4, 4])
958