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