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

Source Code for Module test_suite.unit_tests.residue_testing_base

  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 pipes 
 25  from lib.errors import RelaxError, RelaxNoPipeError, RelaxSpinSelectDisallowError 
 26  from test_suite.unit_tests.base_classes import UnitTestCase 
 27   
 28   
29 -class Residue_base_class(UnitTestCase):
30 """Testing base class for 'prompt.residue' and corresponding 'pipe_control.mol_res_spin' fns. 31 32 This base class also contains many shared unit tests. 33 """ 34
35 - def setUp(self):
36 """Set up for all the residue unit tests.""" 37 38 # Add a data pipe to the data store. 39 ds.add(pipe_name='orig', pipe_type='mf') 40 41 # Add a second data pipe for copying tests. 42 ds.add(pipe_name='test', pipe_type='mf') 43 44 # Set the current data pipe to 'orig'. 45 pipes.switch('orig')
46 47
48 - def setup_data(self):
49 """Function for setting up some data for the unit tests.""" 50 51 # Get the data pipe. 52 dp = pipes.get_pipe('orig') 53 54 # Create the first residue and add some data to its spin container. 55 self.residue_fns.create(1, 'Ala') 56 dp.mol[0].res[0].spin[0].num = 111 57 dp.mol[0].res[0].spin[0].x = 1 58 dp.mol[0].name = 'Old mol' 59 60 # Create a second molecule. 61 dp.mol.add_item('New mol') 62 63 # Copy the residue to the new molecule. 64 self.residue_fns.copy(res_from=':1', res_to='#New mol') 65 self.residue_fns.copy(res_from='#Old mol:1', res_to='#New mol:5') 66 67 # Change the first residue's data. 68 dp.mol[0].res[0].spin[0].num = 222 69 dp.mol[0].res[0].spin[0].x = 2
70 71
73 """Test the copying of the residue data between different molecules. 74 75 The function tested is both pipe_control.mol_res_spin.copy_residue() and 76 prompt.residue.copy(). 77 """ 78 79 # Set up some data. 80 self.setup_data() 81 82 # Get the data pipe. 83 dp = pipes.get_pipe('orig') 84 85 # Test the original residue. 86 self.assertEqual(dp.mol[0].res[0].num, 1) 87 self.assertEqual(dp.mol[0].res[0].name, 'Ala') 88 self.assertEqual(dp.mol[0].res[0].spin[0].num, 222) 89 self.assertEqual(dp.mol[0].res[0].spin[0].x, 2) 90 91 # Test the new residue 1. 92 self.assertEqual(dp.mol[1].name, 'New mol') 93 self.assertEqual(dp.mol[1].res[0].num, 1) 94 self.assertEqual(dp.mol[1].res[0].name, 'Ala') 95 self.assertEqual(dp.mol[1].res[0].spin[0].num, 111) 96 self.assertEqual(dp.mol[1].res[0].spin[0].x, 1) 97 98 # Test the new residue 5. 99 self.assertEqual(dp.mol[1].res[1].num, 5) 100 self.assertEqual(dp.mol[1].res[1].name, 'Ala') 101 self.assertEqual(dp.mol[1].res[1].spin[0].num, 111) 102 self.assertEqual(dp.mol[1].res[1].spin[0].x, 1)
103 104 105
107 """Test the copying of the residue data between different data pipes. 108 109 The function tested is both pipe_control.mol_res_spin.copy_residue() and 110 prompt.residue.copy(). 111 """ 112 113 # Get the data pipes. 114 dp = pipes.get_pipe('orig') 115 dp_test = pipes.get_pipe('test') 116 117 # Create the first residue and add some data to its spin container. 118 self.residue_fns.create(1, 'Ala') 119 dp.mol[0].res[0].spin[0].num = 111 120 dp.mol[0].res[0].spin[0].x = 1 121 122 # Copy the residue to the second data pipe. 123 self.residue_fns.copy(res_from=':1', pipe_to='test') 124 self.residue_fns.copy(pipe_from='orig', res_from=':1', pipe_to='test', res_to=':5') 125 126 # Change the first residue's data. 127 dp.mol[0].res[0].spin[0].num = 222 128 dp.mol[0].res[0].spin[0].x = 2 129 130 # Test the original residue. 131 self.assertEqual(dp.mol[0].res[0].num, 1) 132 self.assertEqual(dp.mol[0].res[0].name, 'Ala') 133 self.assertEqual(dp.mol[0].res[0].spin[0].num, 222) 134 self.assertEqual(dp.mol[0].res[0].spin[0].x, 2) 135 136 # Test the new residue 1. 137 self.assertEqual(dp_test.mol[0].res[0].num, 1) 138 self.assertEqual(dp_test.mol[0].res[0].name, 'Ala') 139 self.assertEqual(dp_test.mol[0].res[0].spin[0].num, 111) 140 self.assertEqual(dp_test.mol[0].res[0].spin[0].x, 1) 141 142 # Test the new residue 5. 143 self.assertEqual(dp_test.mol[0].res[1].num, 5) 144 self.assertEqual(dp_test.mol[0].res[1].name, 'Ala') 145 self.assertEqual(dp_test.mol[0].res[1].spin[0].num, 111) 146 self.assertEqual(dp_test.mol[0].res[1].spin[0].x, 1)
147 148
150 """Test the copying of the residue data between different data pipes. 151 152 The function tested is both pipe_control.mol_res_spin.copy_residue() and 153 prompt.residue.copy(). 154 """ 155 156 # Get the data pipe. 157 dp = pipes.get_pipe('orig') 158 159 # Create the first residue and add some data to its spin container. 160 self.residue_fns.create(1, 'Ala') 161 dp.mol[0].res[0].spin[0].num = 111 162 dp.mol[0].res[0].spin[0].x = 1 163 164 # Copy the residue to the second data pipe. 165 self.assertRaises(RelaxNoPipeError, self.residue_fns.copy, res_from=':1', pipe_to='test2')
166 167
169 """Test the copying of the residue data within a single molecule. 170 171 The function tested is both pipe_control.mol_res_spin.copy_residue() and 172 prompt.residue.copy(). 173 """ 174 175 # Get the data pipe. 176 dp = pipes.get_pipe('orig') 177 178 # Create the first residue and add some data to its spin container. 179 self.residue_fns.create(1, 'Ala') 180 dp.mol[0].res[0].spin[0].num = 111 181 dp.mol[0].res[0].spin[0].x = 1 182 183 # Copy the residue a few times. 184 self.residue_fns.copy(res_from=':1', res_to=':2') 185 self.residue_fns.copy(res_from=':1', pipe_to='orig', res_to=':3') 186 187 # Change the first residue's data. 188 dp.mol[0].res[0].spin[0].num = 222 189 dp.mol[0].res[0].spin[0].x = 2 190 191 # Copy the residue once more. 192 self.residue_fns.copy(res_from=':1', res_to=':4,Met') 193 194 # Test the original residue. 195 self.assertEqual(dp.mol[0].res[0].num, 1) 196 self.assertEqual(dp.mol[0].res[0].name, 'Ala') 197 self.assertEqual(dp.mol[0].res[0].spin[0].num, 222) 198 self.assertEqual(dp.mol[0].res[0].spin[0].x, 2) 199 200 # Test the new residue 2. 201 self.assertEqual(dp.mol[0].res[1].num, 2) 202 self.assertEqual(dp.mol[0].res[1].name, 'Ala') 203 self.assertEqual(dp.mol[0].res[1].spin[0].num, 111) 204 self.assertEqual(dp.mol[0].res[1].spin[0].x, 1) 205 206 # Test the new residue 3. 207 self.assertEqual(dp.mol[0].res[2].num, 3) 208 self.assertEqual(dp.mol[0].res[2].name, 'Ala') 209 self.assertEqual(dp.mol[0].res[2].spin[0].num, 111) 210 self.assertEqual(dp.mol[0].res[2].spin[0].x, 1) 211 212 # Test the new residue 4. 213 self.assertEqual(dp.mol[0].res[3].num, 4) 214 self.assertEqual(dp.mol[0].res[3].name, 'Met') 215 self.assertEqual(dp.mol[0].res[3].spin[0].num, 222) 216 self.assertEqual(dp.mol[0].res[3].spin[0].x, 2)
217 218
220 """The failure of copying residue data within a molecule of a non-existent residue. 221 222 The function tested is both pipe_control.mol_res_spin.copy_residue() and 223 prompt.residue.copy(). 224 """ 225 226 # Create a few residues. 227 self.residue_fns.create(1, 'Ala') 228 self.residue_fns.create(-1, 'His') 229 230 # Copy a non-existent residue (1 Met). 231 self.assertRaises(RelaxError, self.residue_fns.copy, res_from=':Met', res_to=':2,Gly')
232 233
235 """The failure of copying residue data within a molecule to a residue which already exists. 236 237 The function tested is both pipe_control.mol_res_spin.copy_residue() and 238 prompt.residue.copy(). 239 """ 240 241 # Create a few residues. 242 self.residue_fns.create(1, 'Ala') 243 self.residue_fns.create(-1, 'His') 244 245 # Copy a residue to a number which already exists. 246 self.assertRaises(RelaxError, self.residue_fns.copy, res_from=':1', res_to=':-1,Gly')
247 248
249 - def test_create_residue(self):
250 """Test the creation of a residue. 251 252 The function tested is both pipe_control.mol_res_spin.create_residue() and 253 prompt.residue.create(). 254 """ 255 256 # Get the data pipe. 257 dp = pipes.get_pipe('orig') 258 259 # Create a few new residues. 260 self.residue_fns.create(1, 'Ala') 261 self.residue_fns.create(2, 'Leu') 262 self.residue_fns.create(-3, 'Ser') 263 264 # Test that the residue numbers are correct. 265 self.assertEqual(dp.mol[0].res[0].num, 1) 266 self.assertEqual(dp.mol[0].res[1].num, 2) 267 self.assertEqual(dp.mol[0].res[2].num, -3) 268 269 # Test that the residue names are correct. 270 self.assertEqual(dp.mol[0].res[0].name, 'Ala') 271 self.assertEqual(dp.mol[0].res[1].name, 'Leu') 272 self.assertEqual(dp.mol[0].res[2].name, 'Ser')
273 274
275 - def test_create_residue_fail(self):
276 """Test the failure of residue creation (by supplying two residues with the same number). 277 278 The function tested is both pipe_control.mol_res_spin.create_residue() and 279 prompt.residue.create(). 280 """ 281 282 # Create the first residue. 283 self.residue_fns.create(1, 'Ala') 284 285 # Assert that a RelaxError occurs when the next added residue has the same sequence number as the first. 286 self.assertRaises(RelaxError, self.residue_fns.create, 1, 'Ala')
287 288
289 - def test_delete_residue_name(self):
290 """Test residue deletion using residue name identifiers. 291 292 The function tested is both pipe_control.mol_res_spin.delete_residue() and 293 prompt.residue.delete(). 294 """ 295 296 # Get the data pipe. 297 dp = pipes.get_pipe('orig') 298 299 # Create some residues and add some data to the spin containers. 300 self.residue_fns.create(1, 'Ala') 301 self.residue_fns.create(2, 'Ala') 302 self.residue_fns.create(3, 'Ala') 303 self.residue_fns.create(4, 'Gly') 304 dp.mol[0].res[3].spin[0].num = 111 305 dp.mol[0].res[3].spin[0].x = 1 306 307 # Delete the first residue. 308 self.residue_fns.delete(res_id=':Ala') 309 310 # Test that the first residue is 4 Gly. 311 self.assertEqual(dp.mol[0].res[0].num, 4) 312 self.assertEqual(dp.mol[0].res[0].name, 'Gly') 313 self.assertEqual(dp.mol[0].res[0].spin[0].num, 111) 314 self.assert_(hasattr(dp.mol[0].res[0].spin[0], 'x'))
315 316
317 - def test_delete_residue_num(self):
318 """Test residue deletion using residue number identifiers. 319 320 The function tested is both pipe_control.mol_res_spin.delete_residue() and 321 prompt.residue.delete(). 322 """ 323 324 # Get the data pipe. 325 dp = pipes.get_pipe('orig') 326 327 # Create some residues and add some data to the spin containers. 328 self.residue_fns.create(1, 'Ala') 329 self.residue_fns.create(2, 'Ala') 330 self.residue_fns.create(3, 'Ala') 331 self.residue_fns.create(4, 'Gly') 332 dp.mol[0].res[3].spin[0].num = 111 333 dp.mol[0].res[3].spin[0].x = 1 334 335 # Delete the first residue. 336 self.residue_fns.delete(res_id=':1') 337 338 # Test that the sequence. 339 self.assertEqual(dp.mol[0].res[0].num, 2) 340 self.assertEqual(dp.mol[0].res[0].name, 'Ala') 341 self.assertEqual(dp.mol[0].res[1].num, 3) 342 self.assertEqual(dp.mol[0].res[1].name, 'Ala') 343 self.assertEqual(dp.mol[0].res[2].num, 4) 344 self.assertEqual(dp.mol[0].res[2].name, 'Gly') 345 self.assertEqual(dp.mol[0].res[2].spin[0].num, 111) 346 self.assert_(hasattr(dp.mol[0].res[2].spin[0], 'x'))
347 348
349 - def test_delete_residue_all(self):
350 """Test the deletion of all residues. 351 352 The function tested is both pipe_control.mol_res_spin.delete_residue() and 353 prompt.residue.delete(). 354 """ 355 356 # Get the data pipe. 357 dp = pipes.get_pipe('orig') 358 359 # Create some residues and add some data to the spin containers. 360 self.residue_fns.create(1, 'Ala') 361 self.residue_fns.create(2, 'Ala') 362 self.residue_fns.create(3, 'Ala') 363 self.residue_fns.create(4, 'Ala') 364 dp.mol[0].res[3].spin[0].num = 111 365 dp.mol[0].res[3].spin[0].x = 1 366 367 # Delete all residues. 368 self.residue_fns.delete(res_id=':1-4') 369 370 # Test that the first residue defaults back to the empty residue. 371 self.assertEqual(dp.mol[0].res[0].num, None) 372 self.assertEqual(dp.mol[0].res[0].name, None)
373 374
376 """Test the deletion of multiple residues. 377 378 The function tested is both pipe_control.mol_res_spin.delete_residue() and 379 prompt.residue.delete(). 380 """ 381 382 # Get the data pipe. 383 dp = pipes.get_pipe('orig') 384 385 # Create some residues and add some data to the spin containers. 386 self.residue_fns.create(1, 'Ala') 387 self.residue_fns.create(2, 'Ala') 388 self.residue_fns.create(3, 'Ala') 389 self.residue_fns.create(4, 'Ala') 390 dp.mol[0].res[3].spin[0].num = 111 391 dp.mol[0].res[3].spin[0].x = 1 392 393 # Delete the first and third residues. 394 self.residue_fns.delete(res_id=':1,3') 395 396 # Test that the remaining residues. 397 self.assertEqual(dp.mol[0].res[0].num, 2) 398 self.assertEqual(dp.mol[0].res[1].num, 4) 399 self.assertEqual(dp.mol[0].res[1].spin[0].num, 111) 400 self.assert_(hasattr(dp.mol[0].res[1].spin[0], 'x'))
401 402
403 - def test_delete_residue_fail(self):
404 """Test the failure of residue deletion when an atom id is supplied. 405 406 The function tested is both pipe_control.mol_res_spin.delete_residue() and 407 prompt.residue.delete(). 408 """ 409 410 # Supply an atom id. 411 self.assertRaises(RelaxSpinSelectDisallowError, self.residue_fns.delete, res_id='@2')
412 413
414 - def test_display_residue(self):
415 """Test the display of residue information. 416 417 The function tested is both pipe_control.mol_res_spin.display_residue() and 418 prompt.residue.display(). 419 """ 420 421 # Set up some data. 422 self.setup_data() 423 424 # The following should all work without error. 425 self.residue_fns.display() 426 self.residue_fns.display(':1') 427 self.residue_fns.display('#New mol:5') 428 self.residue_fns.display('#Old mol:1')
429 430
432 """Test the failure of the display of residue information. 433 434 The function tested is both pipe_control.mol_res_spin.display_residue() and 435 prompt.residue.display(). 436 """ 437 438 # Set up some data. 439 self.setup_data() 440 441 # The following should fail. 442 self.assertRaises(RelaxSpinSelectDisallowError, self.residue_fns.display, '@N')
443 444
445 - def test_name_residue(self):
446 """Test the renaming of a residue. 447 448 The function tested is both pipe_control.mol_res_spin.name_residue() and 449 prompt.residue.name(). 450 """ 451 452 # Get the data pipe. 453 dp = pipes.get_pipe('orig') 454 455 # Create the first residue and add some data to its spin container. 456 self.residue_fns.create(-10, 'His') 457 458 # Rename the residue. 459 self.residue_fns.name(res_id=':-10', name='K', force=True) 460 461 # Test that the residue has been renamed. 462 self.assertEqual(dp.mol[0].res[0].name, 'K')
463 464
465 - def test_name_residue_many(self):
466 """Test the renaming of multiple residues. 467 468 The function tested is both pipe_control.mol_res_spin.name_residue() and 469 prompt.residue.name(). 470 """ 471 472 # Get the data pipe. 473 dp = pipes.get_pipe('orig') 474 475 # Create the first residue and add some data to its spin container. 476 self.residue_fns.create(1, 'Ala') 477 dp.mol[0].res[0].spin[0].num = 111 478 479 # Copy the residue a few times. 480 self.residue_fns.copy(res_from=':1', res_to=':2') 481 self.residue_fns.copy(res_from=':1', res_to=':3') 482 483 # Change the first residue's data. 484 dp.mol[0].res[0].name = 'His' 485 486 # Copy the residue once more. 487 self.residue_fns.copy(res_from=':1', res_to=':4,Met') 488 489 # Rename all alanines. 490 self.residue_fns.name(res_id=':Ala', name='Gln', force=True) 491 492 # Test the renaming of alanines. 493 self.assertEqual(dp.mol[0].res[1].name, 'Gln') 494 self.assertEqual(dp.mol[0].res[2].name, 'Gln') 495 496 # Test that the other residues have not changed. 497 self.assertEqual(dp.mol[0].res[0].name, 'His') 498 self.assertEqual(dp.mol[0].res[3].name, 'Met')
499 500
502 """Test the failure of naming a residue when a spin id is given. 503 504 The function tested is both pipe_control.mol_res_spin.name_residue() and 505 prompt.residue.name(). 506 """ 507 508 # Try naming using a atom id. 509 self.assertRaises(RelaxSpinSelectDisallowError, self.residue_fns.name, res_id='@111', name='K')
510 511
512 - def test_number_residue(self):
513 """Test the renumbering of a residue. 514 515 The function tested is both pipe_control.mol_res_spin.number_residue() and 516 prompt.residue.number(). 517 """ 518 519 # Get the data pipe. 520 dp = pipes.get_pipe('orig') 521 522 # Create the first residue and add some data to its spin container. 523 self.residue_fns.create(-10, 'His') 524 525 # Rename the residue. 526 self.residue_fns.number(res_id=':-10', number=10, force=True) 527 528 # Test that the residue has been renumbered. 529 self.assertEqual(dp.mol[0].res[0].num, 10)
530 531
533 """Test the numbering of multiple residues. 534 535 The function tested is both pipe_control.mol_res_spin.number_residue() and 536 prompt.residue.number(). 537 """ 538 539 # Get the data pipe. 540 dp = pipes.get_pipe('orig') 541 542 # Create the first residue and add some data to its spin container. 543 self.residue_fns.create(1, 'Ala') 544 545 # Copy the residue a few times. 546 self.residue_fns.copy(res_from=':1', res_to=':2') 547 self.residue_fns.copy(res_from=':1', res_to=':3') 548 549 # Change the first residue's data. 550 dp.mol[0].res[0].spin[0].name = 'His' 551 552 # Copy the residue once more. 553 self.residue_fns.copy(res_from=':1', res_to=':4,Met') 554 555 # Try numbering all alanines. 556 self.assertRaises(RelaxError, self.residue_fns.number, res_id=':Ala', number=10)
557 558
560 """Test the failure of naming a residue when a spin id is given. 561 562 The function tested is both pipe_control.mol_res_spin.number_residue() and 563 prompt.residue.number(). 564 """ 565 566 # Try naming using a atom id. 567 self.assertRaises(RelaxSpinSelectDisallowError, self.residue_fns.number, res_id='@111', number=10)
568