Package test_suite :: Package system_tests :: Module diffusion_tensor
[hide private]
[frames] | no frames]

Source Code for Module test_suite.system_tests.diffusion_tensor

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2006-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  # Python module imports. 
 24  from math import pi 
 25  from numpy import array, dot, float64, transpose, zeros 
 26  from os import sep 
 27  import sys 
 28   
 29  # relax module imports. 
 30  from base_classes import SystemTestCase 
 31  from data import Relax_data_store; ds = Relax_data_store() 
 32  from data.diff_tensor import DiffTensorSimList 
 33  from generic_fns.mol_res_spin import spin_loop 
 34  from generic_fns.pipes import get_pipe 
 35  from generic_fns.reset import reset 
 36  from maths_fns.coord_transform import spherical_to_cartesian 
 37  from maths_fns.rotation_matrix import axis_angle_to_R, euler_to_R_zyz, two_vect_to_R 
 38  from relax_io import delete 
 39  from status import Status; status = Status() 
 40  from tempfile import mktemp 
 41   
 42   
43 -class Diffusion_tensor(SystemTestCase):
44 """Class for testing various aspects specific to the diffusion tensor.""" 45
46 - def setUp(self):
47 """Function for initialising a spherical, spheroidal, and ellipsoidal diffusion tensor.""" 48 49 # The status object. 50 status = Status() 51 52 # Create three data pipes for spherical, spheroidal, and ellipsoidal diffusion. 53 self.interpreter.pipe.create('sphere', 'mf') 54 self.interpreter.pipe.create('spheroid', 'mf') 55 self.interpreter.pipe.create('ellipsoid', 'mf') 56 57 # Sphere tensor initialization. 58 self.interpreter.pipe.switch('sphere') 59 self.interpreter.structure.read_pdb(file='Ap4Aase_res1-12.pdb', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'structures', read_model=1) 60 self.interpreter.sequence.read(file='Ap4Aase.seq', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep, res_num_col=1, res_name_col=2) 61 self.interpreter.diffusion_tensor.init(10e-9, fixed=True) 62 self.tmpfile_sphere = mktemp() 63 64 # Spheroid tensor initialization. 65 self.interpreter.pipe.switch('spheroid') 66 self.interpreter.structure.read_pdb(file='Ap4Aase_res1-12.pdb', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'structures', read_model=1) 67 self.interpreter.sequence.read(file='Ap4Aase.seq', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep, res_num_col=1, res_name_col=2) 68 self.interpreter.diffusion_tensor.init((5e-09, -10000000., 1.6, 2.7), angle_units='rad', spheroid_type='oblate', fixed=True) 69 self.tmpfile_spheroid = mktemp() 70 71 # Ellipsoid tensor initialization. 72 self.interpreter.pipe.switch('ellipsoid') 73 self.interpreter.structure.read_pdb(file='Ap4Aase_res1-12.pdb', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'structures', read_model=1) 74 self.interpreter.sequence.read(file='Ap4Aase.seq', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep, res_num_col=1, res_name_col=2) 75 self.interpreter.diffusion_tensor.init((9e-8, 5e6, 0.3, 60+360, 290, 100), fixed=False) 76 self.tmpfile_ellipsoid = mktemp() 77 78 79 # Some fake MC simulations (for the sphere). 80 self.interpreter.pipe.switch('sphere') 81 cdp.diff_tensor.tm_err = 10e-11 82 cdp.diff_tensor.tm_sim = DiffTensorSimList('tm', cdp.diff_tensor, elements=5) 83 tm_sim = [8.98e-8, 8.99e-8, 9.00e-7, 9.01e-8, 9.02e-8] 84 for i in range(5): 85 cdp.diff_tensor.tm_sim[i] = tm_sim[i] 86 87 # Reset some values. 88 cdp.diff_tensor.tm_sim[0] = 9.00e-8 89 90 91 # Some fake MC simulations (for the spheroid). 92 self.interpreter.pipe.switch('spheroid') 93 94 # Initialise the data structures. 95 cdp.diff_tensor.tm_sim = DiffTensorSimList('tm', cdp.diff_tensor, elements=5) 96 cdp.diff_tensor.Da_sim = DiffTensorSimList('Da', cdp.diff_tensor, elements=5) 97 cdp.diff_tensor.theta_sim = DiffTensorSimList('theta', cdp.diff_tensor, elements=5) 98 cdp.diff_tensor.phi_sim = DiffTensorSimList('phi', cdp.diff_tensor, elements=5) 99 100 # Set some errors. 101 cdp.diff_tensor.Da_err = 1000000 102 cdp.diff_tensor.theta_err = 0.01 103 cdp.diff_tensor.tm_err = 1e-11 104 cdp.diff_tensor.phi_err = 0.01 105 106 # The sim data. 107 Da_sim = [-12000000., -11000000., -10000000., -9000000., -8000000.] 108 theta_sim = [1.70, 1.65, 1.6, 1.55, 1.50] 109 tm_sim = [5.4e-09, 4.8e-09, 5e-09, 5.4e-09, 5.8e-09] 110 phi_sim = [2.5, 2.6, 2.7, 2.8, 100] 111 for i in range(5): 112 cdp.diff_tensor.Da_sim[i] = Da_sim[i] 113 cdp.diff_tensor.theta_sim[i] = theta_sim[i] 114 cdp.diff_tensor.tm_sim[i] = tm_sim[i] 115 cdp.diff_tensor.phi_sim[i] = phi_sim[i] 116 117 # Reset some values. 118 cdp.diff_tensor.tm_sim[0] = 4.4e-9 119 cdp.diff_tensor.phi_sim[4] = 2.9 120 121 122 # Some fake MC simulations (for the ellipsoid). 123 self.interpreter.pipe.switch('ellipsoid') 124 125 # Initialise the data structures. 126 cdp.diff_tensor.tm_sim = DiffTensorSimList('tm', cdp.diff_tensor, elements=5) 127 cdp.diff_tensor.Da_sim = DiffTensorSimList('Da', cdp.diff_tensor, elements=5) 128 cdp.diff_tensor.Dr_sim = DiffTensorSimList('Dr', cdp.diff_tensor, elements=5) 129 cdp.diff_tensor.alpha_sim = DiffTensorSimList('alpha', cdp.diff_tensor, elements=5) 130 cdp.diff_tensor.beta_sim = DiffTensorSimList('beta', cdp.diff_tensor, elements=5) 131 cdp.diff_tensor.gamma_sim = DiffTensorSimList('gamma', cdp.diff_tensor, elements=5) 132 133 # The sim data. 134 Dr_sim = [0.28, 0.29, 0.3, 0.31, 0.32] 135 tm_sim = [8.97e-8, 8.99e-8, 9.00e-8, 9.01e-8, 9.02e-8] 136 Da_sim = [5.02e6, 5.01e6, 5.00e6, 4.99e6, 4.98e6] 137 alpha_sim = [80.0/360*2*pi, 70.0/360*2*pi, 60.0/360*2*pi, 50.0/360*2*pi, 40.0/360*2*pi] 138 beta_sim = [295.0/360*2*pi, 292.5/360*2*pi, 290.0/360*2*pi, 289.5/360*2*pi, 288.0/360*2*pi] 139 gamma_sim = [102.0/360*2*pi, 101.0/360*2*pi, 0, 99.0/360*2*pi, 98.0/360*2*pi] 140 for i in range(5): 141 cdp.diff_tensor.Dr_sim[i] = Dr_sim[i] 142 cdp.diff_tensor.tm_sim[i] = tm_sim[i] 143 cdp.diff_tensor.Da_sim[i] = Da_sim[i] 144 cdp.diff_tensor.alpha_sim[i] = alpha_sim[i] 145 cdp.diff_tensor.beta_sim[i] = beta_sim[i] 146 cdp.diff_tensor.gamma_sim[i] = gamma_sim[i] 147 148 # Reset some values. 149 cdp.diff_tensor.tm_sim[0] = 8.98e-8 150 cdp.diff_tensor.gamma_sim[2] = 100.0/360*2*pi
151 152
153 - def tearDown(self):
154 """Reset the relax data storage object.""" 155 156 # Reset relax. 157 reset() 158 159 # Delete the temporary files. 160 delete(self.tmpfile_sphere, fail=False) 161 delete(self.tmpfile_spheroid, fail=False) 162 delete(self.tmpfile_ellipsoid, fail=False)
163 164
165 - def check_ellipsoid(self, Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R):
166 """Check if the ellipsoid in the cdp has the same values as given.""" 167 168 # Print outs. 169 print("The relax data store diffusion tensor:\n\n%s\n\n" % cdp.diff_tensor) 170 print("\nThe real tensor:\n%s" % D) 171 print("\nThe tensor in relax:\n%s" % cdp.diff_tensor.tensor) 172 print("\nThe real tensor (in eig frame):\n%s" % D_prime) 173 print("\nThe tensor in relax (in eig frame):\n%s" % cdp.diff_tensor.tensor_diag) 174 175 # Check the Euler angles. 176 self.assertAlmostEqual(Dx * 1e-7, cdp.diff_tensor.Dx * 1e-7) 177 self.assertAlmostEqual(Dy * 1e-7, cdp.diff_tensor.Dy * 1e-7) 178 self.assertAlmostEqual(Dz * 1e-7, cdp.diff_tensor.Dz * 1e-7) 179 self.assertAlmostEqual(Diso * 1e-7, cdp.diff_tensor.Diso * 1e-7) 180 self.assertAlmostEqual(Da * 1e-7, cdp.diff_tensor.Da * 1e-7) 181 self.assertAlmostEqual(Dr * 1e-7, cdp.diff_tensor.Dr * 1e-7) 182 self.assertAlmostEqual(alpha, cdp.diff_tensor.alpha) 183 self.assertAlmostEqual(beta, cdp.diff_tensor.beta) 184 self.assertAlmostEqual(gamma, cdp.diff_tensor.gamma) 185 186 # Check the elements. 187 for i in range(3): 188 for j in range(3): 189 self.assertAlmostEqual(cdp.diff_tensor.tensor[i, j] * 1e-7, D[i, j] * 1e-7) 190 self.assertAlmostEqual(cdp.diff_tensor.tensor_diag[i, j] * 1e-7, D_prime[i, j] * 1e-7) 191 self.assertAlmostEqual(cdp.diff_tensor.rotation[i, j], R[i, j])
192 193
194 - def check_spheroid(self, tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type=None):
195 """Check if the spheroid in the cdp has the same values as given.""" 196 197 # Print outs. 198 print("The relax data store diffusion tensor:\n\n%s\n\n" % cdp.diff_tensor) 199 print("\nThe real tensor:\n%s" % D) 200 print("\nThe tensor in relax:\n%s" % cdp.diff_tensor.tensor) 201 print("\nThe real tensor (in eig frame):\n%s" % D_prime) 202 print("\nThe tensor in relax (in eig frame):\n%s" % cdp.diff_tensor.tensor_diag) 203 print("\nThe real rotation matrix:\n%s" % R) 204 print("\nThe rotation matrix in relax:\n%s" % cdp.diff_tensor.rotation) 205 206 # Check the Euler angles. 207 self.assertAlmostEqual(tm * 1e8, cdp.diff_tensor.tm * 1e8) 208 self.assertAlmostEqual(Dpar * 1e-7, cdp.diff_tensor.Dpar * 1e-7) 209 self.assertAlmostEqual(Dper * 1e-7, cdp.diff_tensor.Dper * 1e-7) 210 self.assertAlmostEqual(Diso * 1e-7, cdp.diff_tensor.Diso * 1e-7) 211 self.assertAlmostEqual(Da * 1e-7, cdp.diff_tensor.Da * 1e-7) 212 self.assertAlmostEqual(Dratio, cdp.diff_tensor.Dratio) 213 self.assertAlmostEqual(theta, cdp.diff_tensor.theta) 214 self.assertAlmostEqual(phi, cdp.diff_tensor.phi) 215 216 # Check the diagonalised tensor. 217 for i in range(3): 218 for j in range(3): 219 self.assertAlmostEqual(cdp.diff_tensor.tensor_diag[i, j] * 1e-7, D_prime[i, j] * 1e-7) 220 221 # Check the orientation. 222 vects = [] 223 vects.append([1, 0, 0]) 224 vects.append([0, 1, 0]) 225 vects.append([0, 0, 1]) 226 vects = array(vects) 227 for vect in vects: 228 # The projections. 229 proj1 = dot(vect, dot(cdp.diff_tensor.tensor, vect)) 230 proj2 = dot(vect, dot(D, vect)) 231 232 # Compare projections. 233 self.assertAlmostEqual(proj1, proj2) 234 235 # Check the type. 236 if spheroid_type: 237 self.assertEqual(spheroid_type, cdp.diff_tensor.spheroid_type)
238 239
240 - def check_spheroid_as_ellipsoid(self, tm, Dx, Dy, Dz, Diso, Da, D, D_prime, R):
241 """Check if the ellipsoid in the cdp has the same values as given spheroid.""" 242 243 # Print outs. 244 print("The relax data store diffusion tensor:\n\n%s\n\n" % cdp.diff_tensor) 245 print("\nThe real tensor:\n%s" % D) 246 print("\nThe tensor in relax:\n%s" % cdp.diff_tensor.tensor) 247 print("\nThe real tensor (in eig frame):\n%s" % D_prime) 248 print("\nThe tensor in relax (in eig frame):\n%s" % cdp.diff_tensor.tensor_diag) 249 print("\nThe real rotation matrix:\n%s" % R) 250 print("\nThe rotation matrix in relax:\n%s" % cdp.diff_tensor.rotation) 251 252 # Check the Euler angles. 253 self.assertAlmostEqual(tm * 1e8, cdp.diff_tensor.tm * 1e8) 254 self.assertAlmostEqual(Dx * 1e-7, cdp.diff_tensor.Dx * 1e-7) 255 self.assertAlmostEqual(Dy * 1e-7, cdp.diff_tensor.Dy * 1e-7) 256 self.assertAlmostEqual(Dz * 1e-7, cdp.diff_tensor.Dz * 1e-7) 257 self.assertAlmostEqual(Diso * 1e-7, cdp.diff_tensor.Diso * 1e-7) 258 259 # Check the diagonalised tensor. 260 for i in range(3): 261 for j in range(3): 262 self.assertAlmostEqual(cdp.diff_tensor.tensor_diag[i, j] * 1e-7, D_prime[i, j] * 1e-7) 263 264 # Check the orientation. 265 vects = [] 266 vects.append([1, 0, 0]) 267 vects.append([0, 1, 0]) 268 vects.append([0, 0, 1]) 269 vects = array(vects) 270 for vect in vects: 271 # The projections. 272 proj1 = dot(vect, dot(cdp.diff_tensor.tensor, vect)) 273 proj2 = dot(vect, dot(D, vect)) 274 275 # Print out. 276 print("\nVector: %s" % vect) 277 print("Real proj: %s" % proj1) 278 print("Proj in relax: %s" % proj2) 279 280 # Compare projections. 281 self.assertAlmostEqual(proj1, proj2)
282 283
284 - def get_ellipsoid(self):
285 """Return all the diffusion tensor info about the {Dx, Dy, Dz, alpha, beta, gamma} = {1e7, 2e7, 3e7, 1, 2, 0.5} ellipsoid tensor.""" 286 287 # The tensor info. 288 Dx = 1e7 289 Dy = 2e7 290 Dz = 3e7 291 Diso = 2e7 292 Da = 1.5e7 293 Dr = 1.0/3.0 294 alpha = 1.0 295 beta = 2.0 296 gamma = 0.5 297 298 # The actual tensor in the PDB frame. 299 D = array([[ 22758858.4088357, -7267400.1700938, 6272205.75829415], 300 [ -7267400.1700938, 17923072.3436445, 1284270.53726401], 301 [ 6272205.75829415, 1284270.53726401, 19318069.2475198 ]], float64) 302 303 # The tensor in the eigenframe. 304 D_prime = zeros((3, 3), float64) 305 D_prime[0, 0] = Dx 306 D_prime[1, 1] = Dy 307 D_prime[2, 2] = Dz 308 309 # The rotation matrix. 310 R = zeros((3, 3), float64) 311 euler_to_R_zyz(gamma, beta, alpha, R) 312 R = transpose(R) 313 314 # Return the data. 315 return Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R
316 317
318 - def get_spheroid(self, Dpar=None, Dper=None, theta=None, phi=None):
319 """Return all the diffusion tensor info about the given spheroid tensor.""" 320 321 # The tensor info. 322 Diso = (Dpar + 2*Dper) / 3.0 323 tm = 1.0/(6.0 * Diso) 324 Da = Dpar - Dper 325 Dratio = Dpar / Dper 326 327 # The eigenvalues and unique axis in the eigenframe. 328 if Dpar > Dper: 329 Dx, Dy, Dz = Dper, Dper, Dpar 330 axis = array([0, 0, 1], float64) 331 else: 332 Dx, Dy, Dz = Dpar, Dper, Dper 333 axis = array([1, 0, 0], float64) 334 335 # The actual tensor in the PDB frame. 336 R = zeros((3, 3), float64) 337 spher_vect = array([1, theta, phi], float64) 338 diff_axis = zeros(3, float64) 339 spherical_to_cartesian(spher_vect, diff_axis) 340 two_vect_to_R(diff_axis, axis, R) 341 342 # The tensor in the eigenframe. 343 D_prime = zeros((3, 3), float64) 344 D_prime[0, 0] = Dx 345 D_prime[1, 1] = Dy 346 D_prime[2, 2] = Dz 347 348 # Rotate a little about the unique axis! 349 twist = zeros((3, 3), float64) 350 axis_angle_to_R(axis, 0.3, twist) 351 D = dot(twist, dot(D_prime, transpose(twist))) 352 353 # The tensor in the PDB frame. 354 D = dot(R, dot(D, transpose(R))) 355 356 # Return the data. 357 return tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R
358 359
360 - def test_back_calc_ellipsoid(self):
361 """Check the back-calculation of relaxation data for the spherical diffusion tensor.""" 362 363 # Reset relax. 364 reset() 365 366 # The diffusion type (used by the script). 367 ds.diff_type = 'ellipsoid' 368 369 # Execute the script. 370 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'ri_back_calc.py') 371 372 # Loop over all spins. 373 for i in range(len(cdp.mol[0].res)): 374 # Alias. 375 spin = cdp.mol[0].res[i].spin[0] 376 377 # Check the values. 378 for ri_id in cdp.ri_ids: 379 self.assertAlmostEqual(spin.ri_data_bc[ri_id], spin.ri_data[ri_id])
380 381
382 - def test_back_calc_sphere(self):
383 """Check the back-calculation of relaxation data for the spherical diffusion tensor.""" 384 385 # Reset relax. 386 reset() 387 388 # The diffusion type (used by the script). 389 ds.diff_type = 'sphere' 390 391 # Execute the script. 392 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'ri_back_calc.py') 393 394 # Loop over all spins. 395 for i in range(len(cdp.mol[0].res)): 396 # Alias. 397 spin = cdp.mol[0].res[i].spin[0] 398 399 # Check the values. 400 for ri_id in cdp.ri_ids: 401 self.assertAlmostEqual(spin.ri_data_bc[ri_id], spin.ri_data[ri_id])
402 403
404 - def test_back_calc_spheroid(self):
405 """Check the back-calculation of relaxation data for the spherical diffusion tensor.""" 406 407 # Reset relax. 408 reset() 409 410 # The diffusion type (used by the script). 411 ds.diff_type = 'spheroid' 412 413 # Execute the script. 414 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'ri_back_calc.py') 415 416 # Loop over all spins. 417 for i in range(len(cdp.mol[0].res)): 418 # Alias. 419 spin = cdp.mol[0].res[i].spin[0] 420 421 # Check the values. 422 for ri_id in cdp.ri_ids: 423 self.assertAlmostEqual(spin.ri_data_bc[ri_id], spin.ri_data[ri_id])
424 425
426 - def test_copy(self):
427 """The user function diffusion_tensor.copy().""" 428 429 # Create three additional data pipes for copying the spherical, spheroidal, and ellipsoidal diffusion data. 430 self.interpreter.pipe.create('sphere2', 'mf') 431 self.interpreter.pipe.create('spheroid2', 'mf') 432 self.interpreter.pipe.create('ellipsoid2', 'mf') 433 434 # Copy the data. 435 self.interpreter.diffusion_tensor.copy('sphere', 'sphere2') 436 self.interpreter.diffusion_tensor.copy('spheroid', 'spheroid2') 437 self.interpreter.diffusion_tensor.copy('ellipsoid', 'ellipsoid2') 438 439 # Get the data pipes. 440 sphere_pipe = get_pipe('sphere') 441 sphere2_pipe = get_pipe('sphere2') 442 443 # Check that this is indeed a copy. 444 self.assertEqual(sphere2_pipe.diff_tensor.tm_sim[4], 9.02e-8) 445 self.assertEqual(sphere2_pipe.diff_tensor.Diso_sim[4], 1/(6*9.02e-8)) 446 sphere_pipe.diff_tensor.tm_sim[4] = 8.88e-8 447 self.assertEqual(sphere_pipe.diff_tensor.tm_sim[4], 8.88e-8) 448 self.assertEqual(sphere_pipe.diff_tensor.Diso_sim[4], 1/(6*8.88e-8)) 449 self.assertEqual(sphere2_pipe.diff_tensor.tm_sim[4], 9.02e-8) 450 self.assertEqual(sphere2_pipe.diff_tensor.Diso_sim[4], 1/(6*9.02e-8))
451 452
453 - def test_delete(self):
454 """The user function diffusion_tensor.delete().""" 455 456 # Delete the data. 457 self.interpreter.pipe.switch('sphere') 458 self.interpreter.diffusion_tensor.delete() 459 self.interpreter.pipe.switch('spheroid') 460 self.interpreter.diffusion_tensor.delete() 461 self.interpreter.pipe.switch('ellipsoid') 462 self.interpreter.diffusion_tensor.delete()
463 464
465 - def test_display(self):
466 """The user function diffusion_tensor.display().""" 467 468 # Display the data. 469 self.interpreter.pipe.switch('sphere') 470 self.interpreter.diffusion_tensor.display() 471 self.interpreter.pipe.switch('spheroid') 472 self.interpreter.diffusion_tensor.display() 473 self.interpreter.pipe.switch('ellipsoid') 474 self.interpreter.diffusion_tensor.display()
475 476
478 """Test the user function structure.create_diff_tensor_pdb() for the ellipsoid.""" 479 480 # First copy the data (a more vigorous copy test!). 481 self.interpreter.pipe.copy('ellipsoid', 'ellipsoid2') 482 self.interpreter.pipe.switch('ellipsoid2') 483 self.interpreter.diffusion_tensor.delete() 484 self.interpreter.diffusion_tensor.copy('ellipsoid', 'ellipsoid2') 485 486 # Create the diffusion tensor objects. 487 self.interpreter.structure.create_diff_tensor_pdb(file=self.tmpfile_ellipsoid, scale=1e-05) 488 489 # Open the temp file. 490 file = open(self.tmpfile_ellipsoid) 491 new_data = file.readlines() 492 file.close() 493 494 # Open the real file. 495 file = open(status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'structures'+sep+'diff_tensors'+sep+'ellipsoid.pdb') 496 real_data = file.readlines() 497 file.close() 498 499 # Check the data. 500 self.assertEqual(len(real_data), len(new_data)) 501 for i in range(len(real_data)): 502 # Print the PDB line, for debugging. 503 print((real_data[i][0:-1])) 504 505 # Check the line. 506 self.assertEqual(real_data[i], new_data[i])
507 508
510 """Test the user function structure.create_diff_tensor_pdb() for the sphere.""" 511 512 # First copy the data (a more vigorous copy test!). 513 self.interpreter.pipe.copy('sphere', 'sphere2') 514 self.interpreter.pipe.switch('sphere2') 515 self.interpreter.diffusion_tensor.delete() 516 self.interpreter.diffusion_tensor.copy('sphere', 'sphere2') 517 518 # Create the diffusion tensor objects. 519 self.interpreter.structure.create_diff_tensor_pdb(file=self.tmpfile_sphere) 520 521 # Open the temp file. 522 file = open(self.tmpfile_sphere) 523 new_data = file.readlines() 524 file.close() 525 526 # Open the real file. 527 file = open(status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'structures'+sep+'diff_tensors'+sep+'sphere.pdb') 528 real_data = file.readlines() 529 file.close() 530 531 # Check the data. 532 self.assertEqual(len(real_data), len(new_data)) 533 for i in range(len(real_data)): 534 # Print the PDB line, for debugging. 535 print((real_data[i][0:-1])) 536 537 # Check the line. 538 self.assertEqual(real_data[i], new_data[i])
539 540
542 """Test the user function structure.create_diff_tensor_pdb() for the spheroid.""" 543 544 # First copy the data (a more vigorous copy test!). 545 self.interpreter.pipe.copy('spheroid', 'spheroid2') 546 self.interpreter.pipe.switch('spheroid2') 547 self.interpreter.diffusion_tensor.delete() 548 self.interpreter.diffusion_tensor.copy('spheroid', 'spheroid2') 549 550 # Create the diffusion tensor objects. 551 self.interpreter.structure.create_diff_tensor_pdb(file=self.tmpfile_spheroid) 552 553 # Open the temp file. 554 file = open(self.tmpfile_spheroid) 555 new_data = file.readlines() 556 file.close() 557 558 # Open the real file. 559 file = open(status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'structures'+sep+'diff_tensors'+sep+'spheroid.pdb') 560 real_data = file.readlines() 561 file.close() 562 563 # Check the data. 564 self.assertEqual(len(real_data), len(new_data)) 565 for i in range(len(real_data)): 566 # Print the PDB line, for debugging. 567 print((real_data[i][0:-1])) 568 569 # Check the line. 570 self.assertEqual(real_data[i], new_data[i])
571 572
574 """Test the initialisation of the ellipsoid diffusion tensor using parameter set 0.""" 575 576 # Get the ellipsoid data. 577 Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid() 578 579 # Create a new data pipe. 580 self.interpreter.pipe.create('ellipsoid2', 'mf') 581 582 # Tensor initialization. 583 self.interpreter.diffusion_tensor.init((1/(6.0*Diso), Da, Dr, alpha, beta, gamma), param_types=0, angle_units='rad') 584 585 # Check the ellipsoid. 586 self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
587 588
590 """Test the initialisation of the ellipsoid diffusion tensor using parameter set 0.""" 591 592 # Get the ellipsoid data. 593 Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid() 594 595 # Create a new data pipe. 596 self.interpreter.pipe.create('ellipsoid2', 'mf') 597 598 # Tensor initialization. 599 self.interpreter.diffusion_tensor.init((Diso, Da, Dr, alpha, beta, gamma), param_types=1, angle_units='rad') 600 601 # Check the ellipsoid. 602 self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
603 604
606 """Test the initialisation of the ellipsoid diffusion tensor using parameter set 0.""" 607 608 # Get the ellipsoid data. 609 Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid() 610 611 # Create a new data pipe. 612 self.interpreter.pipe.create('ellipsoid2', 'mf') 613 614 # Tensor initialization. 615 self.interpreter.diffusion_tensor.init((Dx, Dy, Dz, alpha, beta, gamma), param_types=2, angle_units='rad') 616 617 # Check the ellipsoid. 618 self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
619 620
622 """Test the initialisation of the ellipsoid diffusion tensor using parameter set 0.""" 623 624 # Get the ellipsoid data. 625 Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid() 626 627 # Create a new data pipe. 628 self.interpreter.pipe.create('ellipsoid2', 'mf') 629 630 # Tensor initialization. 631 self.interpreter.diffusion_tensor.init((D[0, 0], D[1, 1], D[2, 2], D[0, 1], D[0, 2], D[1, 2]), param_types=3) 632 633 # Check the ellipsoid. 634 self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
635 636
638 """Test the initialisation of the spheroid diffusion tensor using parameter set 4.""" 639 640 # Get the spheroid data. 641 Dpar, Dper, theta, phi = 1e7, 4e7, pi/4.0, 0.0 642 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 643 644 # Create a new data pipe. 645 self.interpreter.pipe.create('spheroid2', 'mf') 646 647 # Tensor initialization. 648 self.interpreter.diffusion_tensor.init((D[0, 0], D[1, 1], D[2, 2], D[0, 1], D[0, 2], D[1, 2]), param_types=3) 649 650 # Check the ellipsoid. 651 self.check_spheroid_as_ellipsoid(tm, Dx, Dy, Dz, Diso, Da, D, D_prime, R)
652 653
655 """Test the initialisation of the oblate spheroid diffusion tensor using parameter set 0.""" 656 657 # Get the spheroid data. 658 Dpar, Dper, theta, phi = 1e7, 4e7, 0.5, 1.0 659 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 660 661 # Create a new data pipe. 662 self.interpreter.pipe.create('spheroid2', 'mf') 663 664 # Tensor initialization. 665 self.interpreter.diffusion_tensor.init((tm, Da, theta, phi), param_types=0, angle_units='rad') 666 667 # Check the spheroid. 668 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='oblate')
669 670
672 """Test the initialisation of the oblate spheroid diffusion tensor using parameter set 1.""" 673 674 # Get the spheroid data. 675 Dpar, Dper, theta, phi = 1e7, 4e7, 0.5, 1.0 676 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 677 678 # Create a new data pipe. 679 self.interpreter.pipe.create('spheroid2', 'mf') 680 681 # Tensor initialization. 682 self.interpreter.diffusion_tensor.init((Diso, Da, theta, phi), param_types=1, angle_units='rad') 683 684 # Check the spheroid. 685 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='oblate')
686 687
689 """Test the initialisation of the oblate spheroid diffusion tensor using parameter set 1, and angles in deg.""" 690 691 # Get the spheroid data. 692 Dpar, Dper, theta, phi = 1e7, 4e7, 0.5, 1.0 693 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 694 695 # Create a new data pipe. 696 self.interpreter.pipe.create('spheroid2', 'mf') 697 698 # Tensor initialization. 699 self.interpreter.diffusion_tensor.init((Diso, Da, theta/2.0/pi*360.0, phi/2.0/pi*360.0), param_types=1, angle_units='deg') 700 701 # Check the spheroid. 702 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='oblate')
703 704
706 """Test the initialisation of the oblate spheroid diffusion tensor using parameter set 2.""" 707 708 # Get the spheroid data. 709 Dpar, Dper, theta, phi = 1e7, 4e7, 0.5, 1.0 710 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 711 712 # Create a new data pipe. 713 self.interpreter.pipe.create('spheroid2', 'mf') 714 715 # Tensor initialization. 716 self.interpreter.diffusion_tensor.init((tm, Dratio, theta, phi), param_types=2, angle_units='rad') 717 718 # Check the spheroid. 719 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='oblate')
720 721
723 """Test the initialisation of the oblate spheroid diffusion tensor using parameter set 3.""" 724 725 # Get the spheroid data. 726 Dpar, Dper, theta, phi = 1e7, 4e7, 0.5, 1.0 727 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 728 729 # Create a new data pipe. 730 self.interpreter.pipe.create('spheroid2', 'mf') 731 732 # Tensor initialization. 733 self.interpreter.diffusion_tensor.init((Dpar, Dper, theta, phi), param_types=3, angle_units='rad') 734 735 # Check the spheroid. 736 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='oblate')
737 738
740 """Test the initialisation of the oblate spheroid diffusion tensor using parameter set 4.""" 741 742 # Get the spheroid data. 743 Dpar, Dper, theta, phi = 1e7, 4e7, 0.5, 1.0 744 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 745 746 # Create a new data pipe. 747 self.interpreter.pipe.create('spheroid2', 'mf') 748 749 # Tensor initialization. 750 self.interpreter.diffusion_tensor.init((Diso, Dratio, theta, phi), param_types=4, angle_units='rad') 751 752 # Check the spheroid. 753 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='oblate')
754 755
757 """Test the initialisation of the spheroid diffusion tensor using parameter set 4.""" 758 759 # Get the spheroid data. 760 Dpar, Dper, theta, phi = 4e7, 2e7, 0.5, 1.0 761 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 762 763 # Create a new data pipe. 764 self.interpreter.pipe.create('spheroid2', 'mf') 765 766 # Tensor initialization. 767 self.interpreter.diffusion_tensor.init((D[0, 0], D[1, 1], D[2, 2], D[0, 1], D[0, 2], D[1, 2]), param_types=3) 768 769 # Check the ellipsoid. 770 self.check_spheroid_as_ellipsoid(tm, Dx, Dy, Dz, Diso, Da, D, D_prime, R)
771 772
774 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 0.""" 775 776 # Get the spheroid data. 777 Dpar, Dper, theta, phi = 8e7, 4e7, 0.5, 1.0 778 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 779 780 # Create a new data pipe. 781 self.interpreter.pipe.create('spheroid2', 'mf') 782 783 # Tensor initialization. 784 self.interpreter.diffusion_tensor.init((tm, Da, theta, phi), spheroid_type='prolate', param_types=0, angle_units='rad') 785 786 # Check the spheroid. 787 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
788 789
791 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 0.""" 792 793 # Get the spheroid data. 794 Dpar, Dper, theta, phi = 8e7, 8e7, 0.5, 1.0 795 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 796 797 # Create a new data pipe. 798 self.interpreter.pipe.create('spheroid2', 'mf') 799 800 # Tensor initialization. 801 self.interpreter.diffusion_tensor.init((tm, Da, theta, phi), spheroid_type='prolate', param_types=0, angle_units='rad') 802 803 # Check the spheroid. 804 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
805 806
808 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 1.""" 809 810 # Get the spheroid data. 811 Dpar, Dper, theta, phi = 8e7, 4e7, 0.5, 1.0 812 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 813 814 # Create a new data pipe. 815 self.interpreter.pipe.create('spheroid2', 'mf') 816 817 # Tensor initialization. 818 self.interpreter.diffusion_tensor.init((Diso, Da, theta, phi), param_types=1, angle_units='rad') 819 820 # Check the spheroid. 821 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
822 823
825 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 1, and angles in deg.""" 826 827 # Get the spheroid data. 828 Dpar, Dper, theta, phi = 8e7, 4e7, 0.5, 1.0 829 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 830 831 # Create a new data pipe. 832 self.interpreter.pipe.create('spheroid2', 'mf') 833 834 # Tensor initialization. 835 self.interpreter.diffusion_tensor.init((Diso, Da, theta/2.0/pi*360.0, phi/2.0/pi*360.0), param_types=1, angle_units='deg') 836 837 # Check the spheroid. 838 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
839 840
842 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 2.""" 843 844 # Get the spheroid data. 845 Dpar, Dper, theta, phi = 8e7, 4e7, 0.5, 1.0 846 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 847 848 # Create a new data pipe. 849 self.interpreter.pipe.create('spheroid2', 'mf') 850 851 # Tensor initialization. 852 self.interpreter.diffusion_tensor.init((tm, Dratio, theta, phi), param_types=2, angle_units='rad') 853 854 # Check the spheroid. 855 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
856 857
859 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 3.""" 860 861 # Get the spheroid data. 862 Dpar, Dper, theta, phi = 8e7, 4e7, 0.5, 1.0 863 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 864 865 # Create a new data pipe. 866 self.interpreter.pipe.create('spheroid2', 'mf') 867 868 # Tensor initialization. 869 self.interpreter.diffusion_tensor.init((Dpar, Dper, theta, phi), param_types=3, angle_units='rad') 870 871 # Check the spheroid. 872 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
873 874
876 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 4.""" 877 878 # Get the spheroid data. 879 Dpar, Dper, theta, phi = 8e7, 4e7, 0.5, 1.0 880 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 881 882 # Create a new data pipe. 883 self.interpreter.pipe.create('spheroid2', 'mf') 884 885 # Tensor initialization. 886 self.interpreter.diffusion_tensor.init((Diso, Dratio, theta, phi), param_types=4, angle_units='rad') 887 888 # Check the spheroid. 889 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
890 891
892 - def test_opt_ellipsoid(self):
893 """Check that the ellipsoid diffusion tensor optimisation functions correctly.""" 894 895 # Reset relax. 896 reset() 897 898 # The diffusion type (used by the script). 899 ds.diff_type = 'ellipsoid' 900 901 # Execute the script. 902 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'tensor_opt.py') 903 904 # Print out. 905 print cdp.diff_tensor 906 907 # The real data. 908 Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid() 909 910 # Check the values. 911 self.assertAlmostEqual(cdp.chi2, 0.0) 912 self.assertEqual(cdp.diff_tensor.fixed, False) 913 self.assertEqual(cdp.diff_tensor.type, 'ellipsoid') 914 915 # Check the ellipsoid. 916 self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
917 918
919 - def test_opt_sphere(self):
920 """Check that the sphere diffusion tensor optimisation functions correctly.""" 921 922 # Reset relax. 923 reset() 924 925 # The diffusion type (used by the script). 926 ds.diff_type = 'sphere' 927 928 # Execute the script. 929 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'tensor_opt.py') 930 931 # Check the values. 932 self.assertAlmostEqual(cdp.chi2, 0.0) 933 self.assertEqual(cdp.diff_tensor.fixed, False) 934 self.assertEqual(cdp.diff_tensor.type, 'sphere') 935 self.assertAlmostEqual(cdp.diff_tensor.tm * 1e9, 1.0/(6.0*2e7) * 1e9) 936 self.assertEqual(cdp.diff_tensor.rotation[0, 0], 1.0) 937 self.assertEqual(cdp.diff_tensor.rotation[1, 1], 1.0) 938 self.assertEqual(cdp.diff_tensor.rotation[2, 2], 1.0) 939 self.assertEqual(cdp.diff_tensor.rotation[0, 1], 0.0) 940 self.assertEqual(cdp.diff_tensor.rotation[0, 2], 0.0) 941 self.assertEqual(cdp.diff_tensor.rotation[1, 2], 0.0) 942 self.assertEqual(cdp.diff_tensor.rotation[1, 0], 0.0) 943 self.assertEqual(cdp.diff_tensor.rotation[2, 0], 0.0) 944 self.assertEqual(cdp.diff_tensor.rotation[2, 1], 0.0)
945 946
947 - def test_opt_spheroid(self):
948 """Check that the spheroid diffusion tensor optimisation functions correctly.""" 949 950 # Reset relax. 951 reset() 952 953 # The diffusion type (used by the script). 954 ds.diff_type = 'spheroid' 955 956 # Execute the script. 957 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'tensor_opt.py') 958 959 # Check the values. 960 self.assertAlmostEqual(cdp.chi2, 0.0) 961 self.assertEqual(cdp.diff_tensor.fixed, False) 962 self.assertEqual(cdp.diff_tensor.type, 'spheroid') 963 self.assertAlmostEqual(cdp.diff_tensor.tm * 1e9, 1.0/(6.0*7e7/3.0) * 1e9) 964 self.assertAlmostEqual(cdp.diff_tensor.Da * 1e-7, 1.0) 965 self.assertAlmostEqual(cdp.diff_tensor.theta, 2.0) 966 self.assertAlmostEqual(cdp.diff_tensor.phi, pi-0.5)
967