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