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-2014 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
258 - def test_format_info_full1(self):
259 """Test the format_info_full() function for all combinations of input.""" 260 261 # The spin info and expected string - covering all possible combinations. 262 info = [ 263 # 5 bits of info. 264 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': 10, 'spin_name': 'N', 'spin_num': 200, 'string': "Molecule Ubi, residue Ala 10, spin N 200"}, 265 266 # 4 bits of info. 267 {'mol_name': None, 'res_name': 'Ala', 'res_num': 10, 'spin_name': 'N', 'spin_num': 200, 'string': "Residue Ala 10, spin N 200"}, 268 {'mol_name': 'Ubi', 'res_name': None, 'res_num': 10, 'spin_name': 'N', 'spin_num': 200, 'string': "Molecule Ubi, residue 10, spin N 200"}, 269 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': None, 'spin_name': 'N', 'spin_num': 200, 'string': "Molecule Ubi, residue Ala, spin N 200"}, 270 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': 10, 'spin_name': None, 'spin_num': 200, 'string': "Molecule Ubi, residue Ala 10, spin 200"}, 271 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': 10, 'spin_name': 'N', 'spin_num': None, 'string': "Molecule Ubi, residue Ala 10, spin N"}, 272 273 # 3 bits of info. 274 {'mol_name': None, 'res_name': None, 'res_num': 10, 'spin_name': 'N', 'spin_num': 200, 'string': "Residue 10, spin N 200"}, 275 {'mol_name': None, 'res_name': 'Ala', 'res_num': None, 'spin_name': 'N', 'spin_num': 200, 'string': "Residue Ala, spin N 200"}, 276 {'mol_name': None, 'res_name': 'Ala', 'res_num': 10, 'spin_name': None, 'spin_num': 200, 'string': "Residue Ala 10, spin 200"}, 277 {'mol_name': None, 'res_name': 'Ala', 'res_num': 10, 'spin_name': 'N', 'spin_num': None, 'string': "Residue Ala 10, spin N"}, 278 {'mol_name': 'Ubi', 'res_name': None, 'res_num': None, 'spin_name': 'N', 'spin_num': 200, 'string': "Molecule Ubi, spin N 200"}, 279 {'mol_name': 'Ubi', 'res_name': None, 'res_num': 10, 'spin_name': None, 'spin_num': 200, 'string': "Molecule Ubi, residue 10, spin 200"}, 280 {'mol_name': 'Ubi', 'res_name': None, 'res_num': 10, 'spin_name': 'N', 'spin_num': None, 'string': "Molecule Ubi, residue 10, spin N"}, 281 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': None, 'spin_name': None, 'spin_num': 200, 'string': "Molecule Ubi, residue Ala, spin 200"}, 282 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': None, 'spin_name': 'N', 'spin_num': None, 'string': "Molecule Ubi, residue Ala, spin N"}, 283 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': 10, 'spin_name': None, 'spin_num': None, 'string': "Molecule Ubi, residue Ala 10"}, 284 285 # 2 bits of info. 286 {'mol_name': None, 'res_name': None, 'res_num': None, 'spin_name': 'N', 'spin_num': 200, 'string': "Spin N 200"}, 287 {'mol_name': None, 'res_name': None, 'res_num': 10, 'spin_name': None, 'spin_num': 200, 'string': "Residue 10, spin 200"}, 288 {'mol_name': None, 'res_name': None, 'res_num': 10, 'spin_name': 'N', 'spin_num': None, 'string': "Residue 10, spin N"}, 289 {'mol_name': None, 'res_name': 'Ala', 'res_num': None, 'spin_name': None, 'spin_num': 200, 'string': "Residue Ala, spin 200"}, 290 {'mol_name': None, 'res_name': 'Ala', 'res_num': None, 'spin_name': 'N', 'spin_num': None, 'string': "Residue Ala, spin N"}, 291 {'mol_name': None, 'res_name': 'Ala', 'res_num': 10, 'spin_name': None, 'spin_num': None, 'string': "Residue Ala 10"}, 292 {'mol_name': 'Ubi', 'res_name': None, 'res_num': None, 'spin_name': None, 'spin_num': 200, 'string': "Molecule Ubi, spin 200"}, 293 {'mol_name': 'Ubi', 'res_name': None, 'res_num': None, 'spin_name': 'N', 'spin_num': None, 'string': "Molecule Ubi, spin N"}, 294 {'mol_name': 'Ubi', 'res_name': None, 'res_num': 10, 'spin_name': None, 'spin_num': None, 'string': "Molecule Ubi, residue 10"}, 295 {'mol_name': 'Ubi', 'res_name': 'Ala', 'res_num': None, 'spin_name': None, 'spin_num': None, 'string': "Molecule Ubi, residue Ala"}, 296 297 # 1 bit of info. 298 {'mol_name': None, 'res_name': None, 'res_num': None, 'spin_name': None, 'spin_num': 200, 'string': "Spin 200"}, 299 {'mol_name': None, 'res_name': None, 'res_num': None, 'spin_name': 'N', 'spin_num': None, 'string': "Spin N"}, 300 {'mol_name': None, 'res_name': None, 'res_num': 10, 'spin_name': None, 'spin_num': None, 'string': "Residue 10"}, 301 {'mol_name': None, 'res_name': 'Ala', 'res_num': None, 'spin_name': None, 'spin_num': None, 'string': "Residue Ala"}, 302 {'mol_name': 'Ubi', 'res_name': None, 'res_num': None, 'spin_name': None, 'spin_num': None, 'string': "Molecule Ubi"}, 303 304 # 0 bits of info. 305 {'mol_name': None, 'res_name': None, 'res_num': None, 'spin_name': None, 'spin_num': None, 'string': ""}, 306 ] 307 308 # Printout. 309 print("Checking %s combinations." % len(info)) 310 311 # Create and check each string. 312 for i in range(len(info)): 313 print(" Checking %s" % info[i]) 314 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']) 315 self.assertEqual(string, info[i]['string'])
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 # The data. 325 data = ['1', 'GLY'] 326 327 # The ID. 328 id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2) 329 330 # Test the string. 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 # The data. 341 data = ['1', 'GLY', '234', 'NH'] 342 343 # The ID. 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 # Test the string. 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 # The data. 357 data = ['Ap4Aase', '234', 'NH'] 358 359 # The ID. 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 # Test the string. 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 # The data. 373 data = ['Ap4Aase', '1', 'GLY'] 374 375 # The ID. 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 # Test the string. 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 # The data. 389 data = ['Ap4Aase', '1', 'GLY', '234', 'NH'] 390 391 # The ID. 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 # Test the string. 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 # The data. 405 data = ['1', 'GLY', None, None] 406 407 # The ID. 408 id = mol_res_spin.generate_spin_id_data_array(data, res_num_col=1, res_name_col=2) 409 410 # Test the string. 411 self.assertEqual(id, ':1')
412 413
414 - def test_molecule_loop(self):
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 # Loop over the molecules. 421 for mol in mol_res_spin.molecule_loop('#RNA'): 422 # Test the molecule name. 423 self.assertEqual(mol.name, 'RNA') 424 425 # Test loop length. 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 # Reset relax. 436 reset() 437 438 # Add a data pipe to the data store. 439 ds.add(pipe_name='orig', pipe_type='mf') 440 441 # Loop over the molecules. 442 i = 0 443 for molecule in mol_res_spin.molecule_loop(): 444 i = i + 1 445 446 # Test loop length. 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 # Reset relax. 457 reset() 458 459 # Function for the problem of catching an error in a generator function. 460 def fail_test(): 461 for molecule in mol_res_spin.molecule_loop(): 462 pass
463 464 # Test for the no pipe error. 465 self.assertRaises(RelaxNoPipeError, fail_test)
466 467
468 - def test_molecule_loop_no_selection(self):
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 # Molecule data. 475 name = ['Ap4Aase', 'RNA'] 476 477 # Loop over the molecules. 478 i = 0 479 for mol in mol_res_spin.molecule_loop(): 480 # Test the molecule names. 481 self.assertEqual(mol.name, name[i]) 482 483 # Increment i. 484 i = i + 1 485 486 # Test loop length. 487 self.assertEqual(len(list(mol_res_spin.molecule_loop())), 2)
488 489
490 - def test_residue_loop(self):
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 # Loop over the residues. 497 for res in mol_res_spin.residue_loop('#Ap4Aase:Glu'): 498 # Test the selection. 499 self.assertEqual(res.num, 2) 500 501 # Test loop length. 502 self.assertEqual(len(list(mol_res_spin.residue_loop('#Ap4Aase:Glu'))), 1)
503 504
505 - def test_residue_loop_no_data(self):
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 # Reset relax. 512 reset() 513 514 # Add a data pipe to the data store. 515 ds.add(pipe_name='orig', pipe_type='mf') 516 517 # Loop over the residues. 518 i = 0 519 for residue in mol_res_spin.residue_loop(): 520 i = i + 1 521 522 # Test loop length. 523 self.assertEqual(i, 0)
524 525
526 - def test_residue_loop_no_pipe(self):
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 # Reset relax. 533 reset() 534 535 # Function for the problem of catching an error in a generator function. 536 def fail_test(): 537 for residue in mol_res_spin.residue_loop(): 538 pass
539 540 # Test for the no pipe error. 541 self.assertRaises(RelaxNoPipeError, fail_test) 542 543
544 - def test_residue_loop_no_selection(self):
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 # Spin data. 551 num = [1, 2, 4, -5, -4] 552 name = [None, 'Glu', 'Pro', None, None] 553 554 # Loop over the residues. 555 i = 0 556 for res in mol_res_spin.residue_loop(): 557 # Test the residue numbers. 558 self.assertEqual(res.num, num[i]) 559 560 # Test the residue names. 561 self.assertEqual(res.name, name[i]) 562 563 # Increment i. 564 i = i + 1 565 566 # Test loop length. 567 self.assertEqual(i, 5)
568 569
570 - def test_return_molecule(self):
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 # Ask for a few molecules. 577 mol1 = mol_res_spin.return_molecule('#Ap4Aase') 578 mol2 = mol_res_spin.return_molecule(selection='#RNA', pipe='orig') 579 580 # Test the data of molecule 1. 581 self.assertEqual(mol1.name, 'Ap4Aase') 582 583 # Test the data of molecule 2. 584 self.assertEqual(mol2.name, 'RNA')
585 586
587 - def test_return_molecule_pipe_fail(self):
588 """Test the failure of the function for returning the desired molecule data container. 589 590 The function tested is pipe_control.mol_res_spin.return_molecule(). 591 """ 592 593 # Try to get a molecule from a missing data pipe. 594 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_molecule, selection='#Ap4Aase', pipe='new') 595 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_molecule, selection='#RNA', pipe='new')
596 597
598 - def test_return_residue(self):
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 # Ask for a few residues. 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 # Test the data of residue 1. 611 self.assertEqual(res1.num, 1) 612 self.assertEqual(res1.name, None) 613 614 # Test the data of residue 2. 615 self.assertEqual(res2.num, 2) 616 self.assertEqual(res2.name, 'Glu') 617 618 # Test the data of residue 4. 619 self.assertEqual(res4.num, 4) 620 self.assertEqual(res4.name, 'Pro') 621 622 # Test the data of the RNA residue -5. 623 self.assertEqual(res5.num, -5) 624 self.assertEqual(res5.name, None) 625 self.assertEqual(res5.spin[1].name, 'N5')
626 627
628 - def test_return_residue_pipe_fail(self):
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 # Try to get a residue from a missing data pipe. 635 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_residue, selection=':2', pipe='new')
636 637
638 - def test_return_single_residue_info(self):
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 # Ask for a few residues. 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 # Test the data of residue 1. 651 self.assertEqual(res1, (1, None)) 652 653 # Test the data of residue 2. 654 self.assertEqual(res2, (2, 'Glu')) 655 656 # Test the data of residue 4. 657 self.assertEqual(res4, (4, 'Pro')) 658 659 # Test the data of the RNA residue -5. 660 self.assertEqual(res5, (-5, None))
661 662
663 - def test_return_single_residue_info_fail(self):
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 # Ask for a few residues. 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
675 - def test_return_spin(self):
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 # Ask for a few spins. 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 # Test the data of spin 1. 689 self.assertNotEqual(spin1, None) 690 self.assertEqual(spin1.num, 60) 691 self.assertEqual(spin1.name, 'NH') 692 693 # Test the data of spin 2. 694 self.assertNotEqual(spin2, None) 695 self.assertEqual(spin2.num, 63) 696 self.assertEqual(spin2.name, 'NH') 697 698 # Test the data of spin 3. 699 self.assertNotEqual(spin3, None) 700 self.assertEqual(spin3.num, None) 701 self.assertEqual(spin3.name, None) 702 703 # Test the data of the RNA res -5, spin N5. 704 self.assertNotEqual(spin4, None) 705 self.assertEqual(spin4.num, None) 706 self.assertEqual(spin4.name, 'N5') 707 708 # Test the data of the RNA res -4, spin 2H. 709 self.assertNotEqual(spin5, None) 710 self.assertEqual(spin5.num, 132) 711 self.assertEqual(spin5.name, '2H')
712 713
714 - def test_return_spin_pipe_fail(self):
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 # Try to get a spin from a missing data pipe. 721 self.assertRaises(RelaxNoPipeError, mol_res_spin.return_spin, spin_id=':2', pipe='new')
722 723
724 - def test_spin_loop(self):
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 # Spin data. 731 select = [1, 0] 732 733 # Loop over the spins. 734 i = 0 735 for spin in mol_res_spin.spin_loop('@N5'): 736 # Test the selection. 737 self.assertEqual(spin.select, select[i]) 738 739 # Test the spin names. 740 self.assertEqual(spin.name, 'N5') 741 742 # Increment i. 743 i = i + 1 744 745 # Test loop length. 746 self.assertEqual(i, 2)
747 748
749 - def test_spin_loop_boolean_or(self):
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 # Selection, and spin name and number. 756 select = [1, 0, 1] 757 name = ['NH', 'C8', 'C8'] 758 num = [63, None, None] 759 760 # Loop over the spins. 761 i = 0 762 for spin in mol_res_spin.spin_loop("#Ap4Aase:Glu | #RNA@C8"): 763 # Test the spin. 764 self.assertEqual([spin.select, spin.name, spin.num], [select[i], name[i], num[i]]) 765 766 # Increment i. 767 i = i + 1 768 769 # Test loop length. 770 self.assertEqual(i, 3)
771 772
773 - def test_spin_loop_multiatom(self):
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 # Spin data. 780 select = [0, 1, 1, 0] 781 name = ['NH', 'NH', 'N5', 'N5'] 782 783 # Loop over the spins. 784 i = 0 785 for spin in mol_res_spin.spin_loop('@NH|@N5'): 786 # Test the selection. 787 self.assertEqual(spin.select, select[i]) 788 789 # Test the spin names. 790 self.assertEqual(spin.name, name[i]) 791 792 # Increment i. 793 i = i + 1 794 795 # Test loop length. 796 self.assertEqual(i, 4)
797 798
799 - def test_spin_loop_no_data(self):
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 # Reset relax. 806 reset() 807 808 # Add a data pipe to the data store. 809 ds.add(pipe_name='orig', pipe_type='mf') 810 811 # Loop over the spins. 812 i = 0 813 for spin in mol_res_spin.spin_loop(): 814 i = i + 1 815 816 # Test loop length. 817 self.assertEqual(i, 0)
818 819
820 - def test_spin_loop_no_pipe(self):
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 # Reset relax. 827 reset() 828 829 # Function for the problem of catching an error in a generator function. 830 def fail_test(): 831 for spin in mol_res_spin.spin_loop(): 832 pass
833 834 # Test for the no pipe error. 835 self.assertRaises(RelaxNoPipeError, fail_test) 836 837
838 - def test_spin_loop_no_selection(self):
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 # Spin data. 845 select = [0, 1, 0, 0, 1, 1, 0, 1] 846 name = ['NH', 'NH', None, 'C8', 'N5', 'C8', 'N5', '2H'] 847 848 # Loop over the spins. 849 i = 0 850 for spin in mol_res_spin.spin_loop(): 851 # Test the selection. 852 self.assertEqual(spin.select, select[i]) 853 854 # Test the spin names. 855 self.assertEqual(spin.name, name[i]) 856 857 # Increment i. 858 i = i + 1 859 860 # Test loop length. 861 self.assertEqual(i, 8)
862 863
864 - def test_spin_loop_single_spin(self):
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 # Loop over the spins. 871 i = 0 872 for spin in mol_res_spin.spin_loop('#Ap4Aase:Glu@63'): 873 # Test the selection. 874 self.assertEqual(spin.select, 1) 875 876 # Test the spin name. 877 self.assertEqual(spin.name, 'NH') 878 879 # Test the spin number. 880 self.assertEqual(spin.num, 63) 881 882 # Increment i. 883 i = i + 1 884 885 # Test loop length. 886 self.assertEqual(i, 1)
887 888
889 - def test_spin_loop_wildcard(self):
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 # Spin data. 896 select = [0, 1, 1, 0] 897 name = ['NH', 'NH', 'N5', 'N5'] 898 899 # Loop over the spins. 900 i = 0 901 for spin in mol_res_spin.spin_loop('@N*'): 902 # Test the selection. 903 self.assertEqual(spin.select, select[i]) 904 905 # Test the spin names. 906 self.assertEqual(spin.name, name[i]) 907 908 # Increment i. 909 i = i + 1 910 911 # Test loop length. 912 self.assertEqual(i, 4)
913 914
915 - def test_boolean_and_selection(self):
916 """Test boolean and in mol-res-spin selections.""" 917 918 # The selection loop: 919 sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro")) 920 921 # Test: 922 self.assertEqual(len(sel), 1) 923 for res in sel: 924 self.assert_(res.name == "Pro" and res.num == 4)
925 926
927 - def test_boolean_complex_selection(self):
928 """Test complex boolean mol-res-spin selections.""" 929 930 # The residue selection loop. 931 sel = list(mol_res_spin.residue_loop("#Ap4Aase:4 & :Pro | #RNA")) 932 933 # Residue names and numbers. 934 names = ['Pro', None, None] 935 numbers = [4, -5, -4] 936 937 # The residues. 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 # Test disabled until this functionality is enabled. # 946 ######################################################
947 - def fixme_test_boolean_parenthesis_selection(self):
948 """Test complex boolean mol-res-spin selections with parenthesis.""" 949 950 # The selection loop: 951 sel = list(mol_res_spin.residue_loop("(#Ap4Aase & :Pro) | (#RNA & :-4)")) 952 953 # Test: 954 self.assertEqual(len(sel), 2) 955 for res in sel: 956 self.assert_(res.num in [-4, 4])
957