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

Source Code for Module test_suite.unit_tests.molecule_testing_base

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2007-2012 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 import Relax_data_store; ds = Relax_data_store() 
 24  from generic_fns.mol_res_spin import copy_residue, create_residue, metadata_update 
 25  from generic_fns import pipes 
 26  from relax_errors import RelaxError, RelaxMultiMolIDError, RelaxNoPipeError, RelaxResSelectDisallowError, RelaxSpinSelectDisallowError 
 27  from test_suite.unit_tests.base_classes import UnitTestCase 
 28   
 29   
30 -class Molecule_base_class(UnitTestCase):
31 """Testing base class for 'prompt.molecule' and corresponding 'generic_fns.mol_spin_res' fns. 32 33 This base class also contains many shared unit tests. 34 """ 35
36 - def setUp(self):
37 """Set up for all the molecule unit tests.""" 38 39 # Add a data pipe to the data store. 40 ds.add(pipe_name='orig', pipe_type='mf') 41 42 # Add a second data pipe for copying tests. 43 ds.add(pipe_name='test', pipe_type='mf') 44 45 # Set the current data pipe to 'orig'. 46 pipes.switch('orig')
47 48
49 - def setup_data(self):
50 """Function for setting up some data for the unit tests.""" 51 52 # Get the data pipe. 53 dp = pipes.get_pipe('orig') 54 55 # Create the first residue and add some data to its spin container. 56 create_residue(1, 'Ala') 57 dp.mol[0].res[0].spin[0].num = 111 58 dp.mol[0].res[0].spin[0].x = 1 59 dp.mol[0].name = 'Old mol' 60 61 # Create a second molecule. 62 dp.mol.add_item('New mol') 63 64 # Copy the residue to the new molecule. 65 copy_residue(res_from=':1', res_to='#New mol') 66 copy_residue(res_from='#Old mol:1', res_to='#New mol:5') 67 68 # Change the first residue's data. 69 dp.mol[0].res[0].spin[0].num = 222 70 dp.mol[0].res[0].spin[0].x = 2 71 72 # Update the metadata. 73 metadata_update()
74 75
77 """Test the copying of the molecule data between different data pipes. 78 79 The function tested is both generic_fns.mol_res_spin.copy_molecule() and 80 prompt.molecule.copy(). 81 """ 82 83 # Get the data pipes. 84 dp = pipes.get_pipe('orig') 85 dp_test = pipes.get_pipe('test') 86 87 # Create the first molecule and residue and add some data to its spin container. 88 self.molecule_fns.create('Old mol') 89 create_residue(1, 'Ala') 90 dp.mol[0].res[0].spin[0].num = 111 91 dp.mol[0].res[0].spin[0].x = 1 92 93 # Update the metadata. 94 metadata_update() 95 96 # Copy the molecule to the second data pipe. 97 self.molecule_fns.copy(mol_from='#Old mol', pipe_to='test') 98 self.molecule_fns.copy(pipe_from='orig', mol_from='#Old mol', pipe_to='test', mol_to='#New mol') 99 100 # Change the first molecule's data. 101 dp.mol[0].res[0].spin[0].num = 222 102 dp.mol[0].res[0].spin[0].x = 2 103 104 # Update the metadata. 105 metadata_update() 106 107 # Test the original molecule. 108 self.assertEqual(dp.mol[0].name, 'Old mol') 109 self.assertEqual(dp.mol[0].res[0].num, 1) 110 self.assertEqual(dp.mol[0].res[0].name, 'Ala') 111 self.assertEqual(dp.mol[0].res[0].spin[0].num, 222) 112 self.assertEqual(dp.mol[0].res[0].spin[0].x, 2) 113 114 # Test the new molecule. 115 self.assertEqual(dp_test.mol[0].name, 'Old mol') 116 self.assertEqual(dp_test.mol[0].res[0].num, 1) 117 self.assertEqual(dp_test.mol[0].res[0].name, 'Ala') 118 self.assertEqual(dp_test.mol[0].res[0].spin[0].num, 111) 119 self.assertEqual(dp_test.mol[0].res[0].spin[0].x, 1) 120 121 # Test the second new molecule. 122 self.assertEqual(dp_test.mol[1].name, 'New mol') 123 self.assertEqual(dp_test.mol[1].res[0].num, 1) 124 self.assertEqual(dp_test.mol[1].res[0].name, 'Ala') 125 self.assertEqual(dp_test.mol[1].res[0].spin[0].num, 111) 126 self.assertEqual(dp_test.mol[1].res[0].spin[0].x, 1)
127 128
130 """Test the failure of copying of the molecule data between different data pipes. 131 132 The function tested is both generic_fns.mol_res_spin.copy_molecule() and 133 prompt.molecule.copy(). 134 """ 135 136 # Get the data pipe. 137 dp = pipes.get_pipe('orig') 138 139 # Create the first molecule and residue and add some data to its spin container. 140 self.molecule_fns.create('Old mol') 141 create_residue(1, 'Ala') 142 dp.mol[0].res[0].spin[0].num = 111 143 dp.mol[0].res[0].spin[0].x = 1 144 145 # Update the metadata. 146 metadata_update() 147 148 # Copy the molecule to the second data pipe. 149 self.assertRaises(RelaxNoPipeError, self.molecule_fns.copy, mol_from='#Old mol', pipe_to='test2')
150 151
153 """Test the copying of the molecule data within a single data pipe. 154 155 The function tested is both generic_fns.mol_res_spin.copy_molecule() and 156 prompt.molecule.copy(). 157 """ 158 159 # Get the data pipe. 160 dp = pipes.get_pipe('orig') 161 162 # Create the first molecule and residue and add some data to its spin container. 163 self.molecule_fns.create('Old mol') 164 create_residue(1, 'Ala') 165 dp.mol[0].res[0].spin[0].num = 111 166 dp.mol[0].res[0].spin[0].x = 1 167 168 # Update the metadata. 169 metadata_update() 170 171 # Copy the molecule a few times. 172 self.molecule_fns.copy(mol_from='#Old mol', mol_to='#2') 173 self.molecule_fns.copy(mol_from='#Old mol', pipe_to='orig', mol_to='#3') 174 175 # Change the first molecule's data. 176 dp.mol[0].res[0].spin[0].num = 222 177 dp.mol[0].res[0].spin[0].x = 2 178 179 # Update the metadata. 180 metadata_update() 181 182 # Copy the molecule once more. 183 self.molecule_fns.copy(mol_from='#Old mol', mol_to='#4') 184 185 # Test the original molecule. 186 self.assertEqual(dp.mol[0].name, 'Old mol') 187 self.assertEqual(dp.mol[0].res[0].num, 1) 188 self.assertEqual(dp.mol[0].res[0].name, 'Ala') 189 self.assertEqual(dp.mol[0].res[0].spin[0].num, 222) 190 self.assertEqual(dp.mol[0].res[0].spin[0].x, 2) 191 192 # Test the new molecule 2. 193 self.assertEqual(dp.mol[1].name, '2') 194 self.assertEqual(dp.mol[1].res[0].num, 1) 195 self.assertEqual(dp.mol[1].res[0].name, 'Ala') 196 self.assertEqual(dp.mol[1].res[0].spin[0].num, 111) 197 self.assertEqual(dp.mol[1].res[0].spin[0].x, 1) 198 199 # Test the new molecule 3. 200 self.assertEqual(dp.mol[2].name, '3') 201 self.assertEqual(dp.mol[2].res[0].num, 1) 202 self.assertEqual(dp.mol[2].res[0].name, 'Ala') 203 self.assertEqual(dp.mol[2].res[0].spin[0].num, 111) 204 self.assertEqual(dp.mol[2].res[0].spin[0].x, 1) 205 206 # Test the new molecule 4. 207 self.assertEqual(dp.mol[3].name, '4') 208 self.assertEqual(dp.mol[3].res[0].num, 1) 209 self.assertEqual(dp.mol[3].res[0].name, 'Ala') 210 self.assertEqual(dp.mol[3].res[0].spin[0].num, 222) 211 self.assertEqual(dp.mol[3].res[0].spin[0].x, 2)
212 213
215 """Test the failure of the copying of the molecule data within a molecule. 216 217 The function tested is both generic_fns.mol_res_spin.copy_molecule() and 218 prompt.molecule.copy(). 219 """ 220 221 # Create a few molecules. 222 self.molecule_fns.create('GST') 223 self.molecule_fns.create('GB1') 224 225 # Copy a non-existent molecule (MBP). 226 self.assertRaises(RelaxError, self.molecule_fns.copy, mol_from='#MBP', mol_to='#IL4') 227 228 # Copy a molecule to one which already exists. 229 self.assertRaises(RelaxError, self.molecule_fns.copy, mol_from='#GST', mol_to='#GB1')
230 231
232 - def test_create_molecule(self):
233 """Test the creation of a molecule data structure. 234 235 The function tested is both generic_fns.mol_res_spin.create_molecule() and 236 prompt.molecule.create(). 237 """ 238 239 # Get the data pipe. 240 dp = pipes.get_pipe('orig') 241 242 # Create a few new molecules. 243 self.molecule_fns.create('Ap4Aase') 244 self.molecule_fns.create('ATP') 245 self.molecule_fns.create(mol_name='MgF4') 246 247 # Test that the molecule names are correct. 248 self.assertEqual(dp.mol[0].name, 'Ap4Aase') 249 self.assertEqual(dp.mol[1].name, 'ATP') 250 self.assertEqual(dp.mol[2].name, 'MgF4')
251 252
254 """Test the failure of molecule creation by supplying two molecules with the same name. 255 256 The function tested is both generic_fns.mol_res_spin.create_molecule() and 257 prompt.molecule.create(). 258 """ 259 260 # Create the first molecule. 261 self.molecule_fns.create('CaM') 262 263 # Assert that a RelaxError occurs when the next added molecule has the same name as the first. 264 self.assertRaises(RelaxError, self.molecule_fns.create, 'CaM')
265 266
267 - def test_delete_molecule(self):
268 """Test molecule deletion. 269 270 The function tested is both generic_fns.mol_res_spin.delete_molecule() and 271 prompt.molecule.delete(). 272 """ 273 274 # Set up some data. 275 self.setup_data() 276 277 # Get the data pipe. 278 dp = pipes.get_pipe('orig') 279 280 # Delete the first molecule. 281 self.molecule_fns.delete(mol_id='#Old mol') 282 283 # Test that the first molecule is now 'New mol'. 284 self.assertEqual(dp.mol[0].name, 'New mol') 285 self.assertEqual(dp.mol[0].res[0].num, 1) 286 self.assertEqual(dp.mol[0].res[0].name, 'Ala') 287 self.assertEqual(dp.mol[0].res[0].spin[0].num, 111) 288 self.assert_(hasattr(dp.mol[0].res[0].spin[0], 'x')) 289 self.assertEqual(dp.mol[0].res[1].num, 5) 290 self.assertEqual(dp.mol[0].res[1].name, 'Ala') 291 self.assertEqual(dp.mol[0].res[1].spin[0].num, 111) 292 self.assert_(hasattr(dp.mol[0].res[1].spin[0], 'x'))
293 294
295 - def test_delete_molecule_all(self):
296 """Test the deletion of all molecules. 297 298 The function tested is both generic_fns.mol_res_spin.delete_molecule() and 299 prompt.molecule.delete(). 300 """ 301 302 # Get the data pipe. 303 dp = pipes.get_pipe('orig') 304 305 # Set up some data. 306 self.setup_data() 307 308 # Delete all molecules. 309 self.molecule_fns.delete(mol_id='#Old mol') 310 self.molecule_fns.delete(mol_id='#New mol') 311 312 # Test that the first molecule defaults back to the empty container. 313 self.assertEqual(dp.mol[0].name, None) 314 self.assertEqual(dp.mol[0].res[0].num, None) 315 self.assertEqual(dp.mol[0].res[0].name, None) 316 self.assertEqual(dp.mol[0].res[0].spin[0].num, None) 317 self.assertEqual(dp.mol[0].res[0].spin[0].name, None)
318 319
321 """Test the failure of molecule deletion when a residue or spin id is supplied. 322 323 The function tested is both generic_fns.mol_res_spin.delete_molecule() and 324 prompt.molecule.delete(). 325 """ 326 327 # Supply a spin id. 328 self.assertRaises(RelaxSpinSelectDisallowError, self.molecule_fns.delete, mol_id='@2') 329 330 # Supply a residue id. 331 self.assertRaises(RelaxResSelectDisallowError, self.molecule_fns.delete, mol_id=':1')
332 333
334 - def test_display_molecule(self):
335 """Test the display of molecular information. 336 337 The function tested is both generic_fns.mol_res_spin.display_molecule() and 338 prompt.molecule.display(). 339 """ 340 341 # Set up some data. 342 self.setup_data() 343 344 # The following should all work without error. 345 self.molecule_fns.display() 346 self.molecule_fns.display('#Old mol') 347 self.molecule_fns.display(mol_id='#New mol')
348 349
351 """Test the failure of the display of molecule information. 352 353 The function tested is both generic_fns.mol_res_spin.display_molecule() and 354 prompt.molecule.display(). 355 """ 356 357 # Set up some data. 358 self.setup_data() 359 360 # The following should fail. 361 self.assertRaises(RelaxSpinSelectDisallowError, self.molecule_fns.display, '@N') 362 self.assertRaises(RelaxResSelectDisallowError, self.molecule_fns.display, ':1')
363 364
365 - def test_name_molecule(self):
366 """Test the renaming of a molecule. 367 368 The function tested is both generic_fns.mol_res_spin.name_molecule() and 369 prompt.molecule.name(). 370 """ 371 372 # Set up some data. 373 self.setup_data() 374 375 # Get the data pipe. 376 dp = pipes.get_pipe('orig') 377 378 # Rename the molecule. 379 self.molecule_fns.name(mol_id='#New mol', name='K', force=True) 380 381 # Test that the molecule has been renamed. 382 self.assertEqual(dp.mol[1].name, 'K')
383 384
385 - def test_name_molecule_fail(self):
386 """Test the failure of naming a molecule when a residue or spin id is given. 387 388 The function tested is both generic_fns.mol_res_spin.name_molecule() and 389 prompt.molecule.name(). 390 """ 391 392 # Try naming using a spin id. 393 self.assertRaises(RelaxSpinSelectDisallowError, self.molecule_fns.name, mol_id='@111', name='K') 394 395 # Try naming using a residue id. 396 self.assertRaises(RelaxResSelectDisallowError, self.molecule_fns.name, mol_id=':1', name='K')
397 398
400 """Test the failure of the naming of multiple molecules to the same name. 401 402 The function tested is both generic_fns.mol_res_spin.name_molecule() and 403 prompt.molecule.name(). 404 """ 405 406 # Set up some data. 407 self.setup_data() 408 409 # Test for the failure. 410 self.assertRaises(RelaxMultiMolIDError, self.molecule_fns.name, mol_id='#Old mol,New mol', name='K')
411