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

Source Code for Module test_suite.unit_tests.diffusion_tensor_testing_base

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2007-2011 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 import pipes 
 26  from generic_fns.reset import reset 
 27  from relax_errors import RelaxError, RelaxNoPipeError, RelaxNoTensorError 
 28  from test_suite.unit_tests.base_classes import UnitTestCase 
 29   
 30   
31 -class Diffusion_tensor_base_class(UnitTestCase):
32 """Base class for the tests of the diffusion tensor modules. 33 34 This includes both the 'prompt.diffusion_tensor' and 'generic_fns.diffusion_tensor' modules. The base class also contains many shared unit tests. 35 """ 36
37 - def setUp(self):
38 """Set up for all the diffusion tensor 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 test_copy_pull_ellipsoid(self):
51 """Test the copying of an ellipsoid diffusion tensor (pulling the data from another pipe). 52 53 The functions tested are both generic_fns.diffusion_tensor.copy() and 54 prompt.diffusion_tensor.copy(). 55 """ 56 57 # Initialise the tensor. 58 self.diffusion_tensor_fns.init(params=(13.9, 1.8, 0.7, 10.6, -23.3, 0.34), time_scale=1e-9, d_scale=1e7, angle_units='rad', param_types=0, fixed=True) 59 60 # Change the current data pipe. 61 pipes.switch('test') 62 63 # Get the data pipe. 64 dp = pipes.get_pipe('test') 65 66 # Copy the tensor to the test pipe. 67 self.diffusion_tensor_fns.copy(pipe_from='orig') 68 69 # Test the diffusion tensor. 70 self.assertEqual(dp.diff_tensor.type, 'ellipsoid') 71 self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 13.9, 14) 72 self.assertEqual(dp.diff_tensor.Da, 1.8e7) 73 self.assertEqual(dp.diff_tensor.Dr, 0.7) 74 self.assertEqual(dp.diff_tensor.alpha, 1.1752220392306203) 75 self.assertEqual(dp.diff_tensor.beta, 1.8327412287183442) 76 self.assertEqual(dp.diff_tensor.gamma, 0.34) 77 self.assertEqual(dp.diff_tensor.fixed, 1)
78 79
80 - def test_copy_pull_sphere(self):
81 """Test the copying of a spherical diffusion tensor (pulling the data from another pipe). 82 83 The functions tested are both generic_fns.diffusion_tensor.copy() and 84 prompt.diffusion_tensor.copy(). 85 """ 86 87 # Initialise the tensor. 88 self.diffusion_tensor_fns.init(params=1e-9) 89 90 # Change the current data pipe. 91 pipes.switch('test') 92 93 # Get the data pipe. 94 dp = pipes.get_pipe('test') 95 96 # Copy the tensor to the test pipe. 97 self.diffusion_tensor_fns.copy(pipe_from='orig') 98 99 # Test the diffusion tensor 100 self.assertEqual(dp.diff_tensor.type, 'sphere') 101 self.assertEqual(dp.diff_tensor.tm, 1e-9) 102 self.assertEqual(dp.diff_tensor.fixed, 1)
103 104
105 - def test_copy_pull_spheroid(self):
106 """Test the copying of a spheroidal diffusion tensor (pulling the data from another pipe). 107 108 The functions tested are both generic_fns.diffusion_tensor.copy() and 109 prompt.diffusion_tensor.copy(). 110 """ 111 112 # Initialise the tensor. 113 self.diffusion_tensor_fns.init(params=(8.6, 1.3, 600, -20), time_scale=1e-9, d_scale=1e7, angle_units='deg', param_types=2, spheroid_type='prolate', fixed=False) 114 115 # Change the current data pipe. 116 pipes.switch('test') 117 118 # Get the data pipe. 119 dp = pipes.get_pipe('test') 120 121 # Copy the tensor to the test pipe. 122 self.diffusion_tensor_fns.copy(pipe_from='orig', pipe_to='test') 123 124 # Test the diffusion tensor. 125 self.assertEqual(dp.diff_tensor.type, 'spheroid') 126 self.assertEqual(dp.diff_tensor.spheroid_type, 'prolate') 127 self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 8.6, 14) 128 self.assertEqual(dp.diff_tensor.Da, 5.2854122621564493e6) 129 self.assertEqual(dp.diff_tensor.theta, 5.2359877559829879) 130 self.assertEqual(dp.diff_tensor.phi, 2.7925268031909276) 131 self.assertEqual(dp.diff_tensor.fixed, 0)
132 133
134 - def test_copy_push_ellipsoid(self):
135 """Test the copying of an ellipsoid diffusion tensor (pushing the data from another pipe). 136 137 The functions tested are both generic_fns.diffusion_tensor.copy() and 138 prompt.diffusion_tensor.copy(). 139 """ 140 141 # Initialise the tensor. 142 self.diffusion_tensor_fns.init(params=(13.9, 1.8, 0.7, 10.6, -23.3, 0.34), time_scale=1e-9, d_scale=1e7, angle_units='rad', param_types=0, fixed=True) 143 144 # Copy the tensor to the test pipe. 145 self.diffusion_tensor_fns.copy(pipe_to='test') 146 147 # Get the data pipe. 148 dp = pipes.get_pipe('test') 149 150 # Test the diffusion tensor. 151 self.assertEqual(dp.diff_tensor.type, 'ellipsoid') 152 self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 13.9, 14) 153 self.assertEqual(dp.diff_tensor.Da, 1.8e7) 154 self.assertEqual(dp.diff_tensor.Dr, 0.7) 155 self.assertEqual(dp.diff_tensor.alpha, 1.1752220392306203) 156 self.assertEqual(dp.diff_tensor.beta, 1.8327412287183442) 157 self.assertEqual(dp.diff_tensor.gamma, 0.34) 158 self.assertEqual(dp.diff_tensor.fixed, 1)
159 160
161 - def test_copy_push_sphere(self):
162 """Test the copying of a spherical diffusion tensor (pushing the data from another pipe). 163 164 The functions tested are both generic_fns.diffusion_tensor.copy() and 165 prompt.diffusion_tensor.copy(). 166 """ 167 168 # Initialise the tensor. 169 self.diffusion_tensor_fns.init(params=1e-9) 170 171 # Copy the tensor to the test pipe. 172 self.diffusion_tensor_fns.copy(pipe_to='test') 173 174 # Get the data pipe. 175 dp = pipes.get_pipe('test') 176 177 # Test the diffusion tensor 178 self.assertEqual(dp.diff_tensor.type, 'sphere') 179 self.assertEqual(dp.diff_tensor.tm, 1e-9) 180 self.assertEqual(dp.diff_tensor.fixed, 1)
181 182
183 - def test_copy_push_spheroid(self):
184 """Test the copying of a spheroidal diffusion tensor (pushing the data from another pipe). 185 186 The functions tested are both generic_fns.diffusion_tensor.copy() and 187 prompt.diffusion_tensor.copy(). 188 """ 189 190 # Initialise the tensor. 191 self.diffusion_tensor_fns.init(params=(8.6, 1.3, 600, -20), time_scale=1e-9, d_scale=1e7, angle_units='deg', param_types=2, spheroid_type='prolate', fixed=False) 192 193 # Copy the tensor to the test pipe. 194 self.diffusion_tensor_fns.copy(pipe_from='orig', pipe_to='test') 195 196 # Get the data pipe. 197 dp = pipes.get_pipe('test') 198 199 # Test the diffusion tensor. 200 self.assertEqual(dp.diff_tensor.type, 'spheroid') 201 self.assertEqual(dp.diff_tensor.spheroid_type, 'prolate') 202 self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 8.6, 14) 203 self.assertEqual(dp.diff_tensor.Da, 5.2854122621564493e6) 204 self.assertEqual(dp.diff_tensor.theta, 5.2359877559829879) 205 self.assertEqual(dp.diff_tensor.phi, 2.7925268031909276) 206 self.assertEqual(dp.diff_tensor.fixed, 0)
207 208
209 - def test_delete(self):
210 """Test the deletion of the diffusion tensor data structure. 211 212 The functions tested are both generic_fns.diffusion_tensor.delete() and 213 prompt.diffusion_tensor.delete(). 214 """ 215 216 # Initialise the tensor. 217 self.diffusion_tensor_fns.init(params=(8.6, 1.3, 600, -20), time_scale=1e-9, d_scale=1e7, angle_units='deg', param_types=2, spheroid_type='prolate', fixed=False) 218 219 # Delete the tensor data. 220 self.diffusion_tensor_fns.delete() 221 222 # Get the data pipe. 223 dp = pipes.get_pipe('test') 224 225 # Test that the diff_tensor object does not exist. 226 self.failIf(hasattr(dp, 'diff_tensor'))
227 228
229 - def test_delete_fail_no_data(self):
230 """Failure of deletion of the diffusion tensor data structure when there is no data. 231 232 The functions tested are both generic_fns.diffusion_tensor.delete() and 233 prompt.diffusion_tensor.delete(). 234 """ 235 236 # Try to delete the tensor data. 237 self.assertRaises(RelaxNoTensorError, self.diffusion_tensor_fns.delete)
238 239
240 - def test_delete_fail_no_pipe(self):
241 """Failure of deletion of the diffusion tensor data structure when there is no data pipe. 242 243 The functions tested are both generic_fns.diffusion_tensor.delete() and 244 prompt.diffusion_tensor.delete(). 245 """ 246 247 # Reset relax. 248 reset() 249 250 # Try to delete the tensor data. 251 self.assertRaises(RelaxNoPipeError, self.diffusion_tensor_fns.delete)
252 253
254 - def test_display_ellipsoid(self):
255 """Display an ellipsoidal diffusion tensor. 256 257 The functions tested are both generic_fns.diffusion_tensor.display() and 258 prompt.diffusion_tensor.display(). 259 """ 260 261 # Initialise the tensor. 262 self.diffusion_tensor_fns.init(params=(13.9, 1.8, 0.7, 10.6, -23.3, 0.34), time_scale=1e-9, d_scale=1e7, angle_units='rad', param_types=0, fixed=True) 263 264 # Display the diffusion tensor. 265 self.diffusion_tensor_fns.display()
266 267
269 """Failure of the display of the diffusion tensor data structure when there is no data. 270 271 The functions tested are both generic_fns.diffusion_tensor.display() and 272 prompt.diffusion_tensor.display(). 273 """ 274 275 # Try to display the tensor data. 276 self.assertRaises(RelaxNoTensorError, self.diffusion_tensor_fns.display)
277 278
280 """Failure of the display of the diffusion tensor data structure when there is no data pipe. 281 282 The functions tested are both generic_fns.diffusion_tensor.display() and 283 prompt.diffusion_tensor.display(). 284 """ 285 286 # Reset relax. 287 reset() 288 289 # Try to display the tensor data. 290 self.assertRaises(RelaxNoPipeError, self.diffusion_tensor_fns.display)
291 292
293 - def test_display_sphere(self):
294 """Display a spherical diffusion tensor. 295 296 The functions tested are both generic_fns.diffusion_tensor.display() and 297 prompt.diffusion_tensor.display(). 298 """ 299 300 # Initialise the tensor. 301 self.diffusion_tensor_fns.init(params=1e-9) 302 303 # Display the diffusion tensor. 304 self.diffusion_tensor_fns.display()
305 306
307 - def test_display_spheroid(self):
308 """Display a spheroidal diffusion tensor. 309 310 The functions tested are both generic_fns.diffusion_tensor.display() and 311 prompt.diffusion_tensor.display(). 312 """ 313 314 # Initialise the tensor. 315 self.diffusion_tensor_fns.init(params=(8.6, 1.3, 600, -20), time_scale=1e-9, d_scale=1e7, angle_units='deg', param_types=2, spheroid_type='prolate', fixed=False) 316 317 # Display the diffusion tensor. 318 self.diffusion_tensor_fns.display()
319 320 321
323 """Test the failure of setting up a diffusion tensor when angle_units is incorrect. 324 325 The functions tested are both generic_fns.diffusion_tensor.init() and 326 prompt.diffusion_tensor.init(). 327 """ 328 329 # Initialise the tensor. 330 self.assertRaises(RelaxError, self.diffusion_tensor_fns.init, params=1e-9, angle_units='aaa')
331 332
333 - def test_init_ellipsoid(self):
334 """Test the setting up of a ellipsoid diffusion tensor. 335 336 The functions tested are both generic_fns.diffusion_tensor.init() and 337 prompt.diffusion_tensor.init(). 338 """ 339 340 # Get the data pipe. 341 dp = pipes.get_pipe('orig') 342 343 # Initialise the tensor. 344 self.diffusion_tensor_fns.init(params=(13.9, 1.8, 0.7, 10.6, -23.3, 0.34), time_scale=1e-9, d_scale=1e7, angle_units='rad', param_types=0, fixed=True) 345 346 # Test the diffusion tensor. 347 self.assertEqual(dp.diff_tensor.type, 'ellipsoid') 348 self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 13.9, 14) 349 self.assertEqual(dp.diff_tensor.Da, 1.8e7) 350 self.assertEqual(dp.diff_tensor.Dr, 0.7) 351 self.assertEqual(dp.diff_tensor.alpha, 1.1752220392306203) 352 self.assertEqual(dp.diff_tensor.beta, 1.8327412287183442) 353 self.assertEqual(dp.diff_tensor.gamma, 0.34) 354 self.assertEqual(dp.diff_tensor.fixed, 1)
355 356
357 - def test_init_sphere(self):
358 """Test the setting up of a spherical diffusion tensor. 359 360 The functions tested are both generic_fns.diffusion_tensor.init() and 361 prompt.diffusion_tensor.init(). 362 """ 363 364 # Get the data pipe. 365 dp = pipes.get_pipe('orig') 366 367 # Initialise the tensor. 368 self.diffusion_tensor_fns.init(params=1e-9) 369 370 # Test the diffusion tensor 371 self.assertEqual(dp.diff_tensor.type, 'sphere') 372 self.assertEqual(dp.diff_tensor.tm, 1e-9) 373 self.assertEqual(dp.diff_tensor.fixed, 1)
374 375
376 - def test_init_spheroid(self):
377 """Test the setting up of a spheroidal diffusion tensor. 378 379 The functions tested are both generic_fns.diffusion_tensor.init() and 380 prompt.diffusion_tensor.init(). 381 """ 382 383 # Get the data pipe. 384 dp = pipes.get_pipe('orig') 385 386 # Initialise the tensor. 387 self.diffusion_tensor_fns.init(params=(8.6, 1.3, 600, -20), time_scale=1e-9, d_scale=1e7, angle_units='deg', param_types=2, spheroid_type='prolate', fixed=False) 388 389 # Test the diffusion tensor. 390 self.assertEqual(dp.diff_tensor.type, 'spheroid') 391 self.assertEqual(dp.diff_tensor.spheroid_type, 'prolate') 392 self.assertAlmostEqual(dp.diff_tensor.tm * 1e9, 8.6, 14) 393 self.assertEqual(dp.diff_tensor.Da, 5.2854122621564493e6) 394 self.assertEqual(dp.diff_tensor.theta, 5.2359877559829879) 395 self.assertEqual(dp.diff_tensor.phi, 2.7925268031909276) 396 self.assertEqual(dp.diff_tensor.fixed, 0)
397