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-2015 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   
  27  # relax module imports. 
  28  from data_store import Relax_data_store; ds = Relax_data_store() 
  29  from pipe_control.pipes import get_pipe 
  30  from pipe_control.reset import reset 
  31  from lib.geometry.coord_transform import spherical_to_cartesian 
  32  from lib.geometry.rotations import axis_angle_to_R, euler_to_R_zyz, two_vect_to_R 
  33  from lib.io import delete 
  34  from status import Status; status = Status() 
  35  from tempfile import mktemp 
  36  from test_suite.system_tests.base_classes import SystemTestCase 
  37   
  38   
39 -class Diffusion_tensor(SystemTestCase):
40 """Class for testing various aspects specific to the diffusion tensor.""" 41
42 - def setUp(self):
43 """Function for initialising a spherical, spheroidal, and ellipsoidal diffusion tensor.""" 44 45 # The status object. 46 status = Status() 47 48 # Create three data pipes for spherical, spheroidal, and ellipsoidal diffusion. 49 self.interpreter.pipe.create('sphere', 'mf') 50 self.interpreter.pipe.create('spheroid', 'mf') 51 self.interpreter.pipe.create('ellipsoid', 'mf') 52 53 # Sphere tensor initialization. 54 self.interpreter.pipe.switch('sphere') 55 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) 56 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) 57 self.interpreter.diffusion_tensor.init(10e-9, fixed=True) 58 self.tmpfile_sphere = mktemp() 59 60 # Spheroid tensor initialization. 61 self.interpreter.pipe.switch('spheroid') 62 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) 63 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) 64 self.interpreter.diffusion_tensor.init((5e-09, -10000000., 1.6, 2.7), angle_units='rad', spheroid_type='oblate', fixed=True) 65 self.tmpfile_spheroid = mktemp() 66 67 # Ellipsoid tensor initialization. 68 self.interpreter.pipe.switch('ellipsoid') 69 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) 70 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) 71 self.interpreter.diffusion_tensor.init((9e-8, 5e6, 0.3, 60+360, 290, 100), fixed=False) 72 self.tmpfile_ellipsoid = mktemp() 73 74 75 # Some fake MC simulations (for the sphere). 76 self.interpreter.pipe.switch('sphere') 77 cdp.diff_tensor.set(param='tm', value=10e-11, category='err') 78 cdp.diff_tensor.set_sim_num(5) 79 tm_sim = [8.98e-8, 8.99e-8, 9.00e-7, 9.01e-8, 9.02e-8] 80 for i in range(5): 81 cdp.diff_tensor.set(param='tm', value=tm_sim[i], category='sim', sim_index=i) 82 83 # Reset some values. 84 cdp.diff_tensor.set(param='tm', value=9.00e-8, category='sim', sim_index=0) 85 86 87 # Some fake MC simulations (for the spheroid). 88 self.interpreter.pipe.switch('spheroid') 89 90 # Set some errors. 91 cdp.diff_tensor.set(param='Da', value=1000000, category='err') 92 cdp.diff_tensor.set(param='theta', value=0.01, category='err') 93 cdp.diff_tensor.set(param='tm', value=1e-11, category='err') 94 cdp.diff_tensor.set(param='phi', value=0.01, category='err') 95 96 # The sim data. 97 cdp.diff_tensor.set_sim_num(5) 98 Da_sim = [-12000000., -11000000., -10000000., -9000000., -8000000.] 99 theta_sim = [1.70, 1.65, 1.6, 1.55, 1.50] 100 tm_sim = [5.4e-09, 4.8e-09, 5e-09, 5.4e-09, 5.8e-09] 101 phi_sim = [2.5, 2.6, 2.7, 2.8, 100] 102 for i in range(5): 103 cdp.diff_tensor.set(param='Da', value=Da_sim[i], category='sim', sim_index=i) 104 cdp.diff_tensor.set(param='theta', value=theta_sim[i], category='sim', sim_index=i) 105 cdp.diff_tensor.set(param='tm', value=tm_sim[i], category='sim', sim_index=i) 106 cdp.diff_tensor.set(param='phi', value=phi_sim[i], category='sim', sim_index=i) 107 108 # Reset some values. 109 cdp.diff_tensor.set(param='tm', value=4.4e-9, category='sim', sim_index=0) 110 cdp.diff_tensor.set(param='phi', value=2.9, category='sim', sim_index=4) 111 112 113 # Some fake MC simulations (for the ellipsoid). 114 self.interpreter.pipe.switch('ellipsoid') 115 116 # The sim data. 117 cdp.diff_tensor.set_sim_num(5) 118 Dr_sim = [0.28, 0.29, 0.3, 0.31, 0.32] 119 tm_sim = [8.97e-8, 8.99e-8, 9.00e-8, 9.01e-8, 9.02e-8] 120 Da_sim = [5.02e6, 5.01e6, 5.00e6, 4.99e6, 4.98e6] 121 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] 122 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] 123 gamma_sim = [102.0/360*2*pi, 101.0/360*2*pi, 0, 99.0/360*2*pi, 98.0/360*2*pi] 124 for i in range(5): 125 cdp.diff_tensor.set(param='Dr', value=Dr_sim[i], category='sim', sim_index=i) 126 cdp.diff_tensor.set(param='tm', value=tm_sim[i], category='sim', sim_index=i) 127 cdp.diff_tensor.set(param='Da', value=Da_sim[i], category='sim', sim_index=i) 128 cdp.diff_tensor.set(param='alpha', value=alpha_sim[i], category='sim', sim_index=i) 129 cdp.diff_tensor.set(param='beta', value=beta_sim[i], category='sim', sim_index=i) 130 cdp.diff_tensor.set(param='gamma', value=gamma_sim[i], category='sim', sim_index=i) 131 132 # Reset some values. 133 cdp.diff_tensor.set(param='tm', value=8.98e-8, category='sim', sim_index=0) 134 cdp.diff_tensor.set(param='gamma', value=100.0/360*2*pi, category='sim', sim_index=2)
135 136
137 - def tearDown(self):
138 """Reset the relax data storage object.""" 139 140 # Reset relax. 141 reset() 142 143 # Delete the temporary files. 144 delete(self.tmpfile_sphere, fail=False) 145 delete(self.tmpfile_spheroid, fail=False) 146 delete(self.tmpfile_ellipsoid, fail=False)
147 148
149 - def check_ellipsoid(self, Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R):
150 """Check if the ellipsoid in the cdp has the same values as given.""" 151 152 # Print outs. 153 print("The relax data store diffusion tensor:\n\n%s\n\n" % cdp.diff_tensor) 154 print("\nThe real tensor:\n%s" % D) 155 print("\nThe tensor in relax:\n%s" % cdp.diff_tensor.tensor) 156 print("\nThe real tensor (in eig frame):\n%s" % D_prime) 157 print("\nThe tensor in relax (in eig frame):\n%s" % cdp.diff_tensor.tensor_diag) 158 159 # Check the Euler angles. 160 self.assertAlmostEqual(Dx * 1e-7, cdp.diff_tensor.Dx * 1e-7) 161 self.assertAlmostEqual(Dy * 1e-7, cdp.diff_tensor.Dy * 1e-7) 162 self.assertAlmostEqual(Dz * 1e-7, cdp.diff_tensor.Dz * 1e-7) 163 self.assertAlmostEqual(Diso * 1e-7, cdp.diff_tensor.Diso * 1e-7) 164 self.assertAlmostEqual(Da * 1e-7, cdp.diff_tensor.Da * 1e-7) 165 self.assertAlmostEqual(Dr * 1e-7, cdp.diff_tensor.Dr * 1e-7) 166 self.assertAlmostEqual(alpha, cdp.diff_tensor.alpha) 167 self.assertAlmostEqual(beta, cdp.diff_tensor.beta) 168 self.assertAlmostEqual(gamma, cdp.diff_tensor.gamma) 169 170 # Check the elements. 171 for i in range(3): 172 for j in range(3): 173 self.assertAlmostEqual(cdp.diff_tensor.tensor[i, j] * 1e-7, D[i, j] * 1e-7) 174 self.assertAlmostEqual(cdp.diff_tensor.tensor_diag[i, j] * 1e-7, D_prime[i, j] * 1e-7) 175 self.assertAlmostEqual(cdp.diff_tensor.rotation[i, j], R[i, j])
176 177
178 - def check_spheroid(self, tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type=None):
179 """Check if the spheroid in the cdp has the same values as given.""" 180 181 # Print outs. 182 print("The relax data store diffusion tensor:\n\n%s\n\n" % cdp.diff_tensor) 183 print("\nThe real tensor:\n%s" % D) 184 print("\nThe tensor in relax:\n%s" % cdp.diff_tensor.tensor) 185 print("\nThe real tensor (in eig frame):\n%s" % D_prime) 186 print("\nThe tensor in relax (in eig frame):\n%s" % cdp.diff_tensor.tensor_diag) 187 print("\nThe real rotation matrix:\n%s" % R) 188 print("\nThe rotation matrix in relax:\n%s" % cdp.diff_tensor.rotation) 189 190 # Check the Euler angles. 191 self.assertAlmostEqual(tm * 1e8, cdp.diff_tensor.tm * 1e8) 192 self.assertAlmostEqual(Dpar * 1e-7, cdp.diff_tensor.Dpar * 1e-7) 193 self.assertAlmostEqual(Dper * 1e-7, cdp.diff_tensor.Dper * 1e-7) 194 self.assertAlmostEqual(Diso * 1e-7, cdp.diff_tensor.Diso * 1e-7) 195 self.assertAlmostEqual(Da * 1e-7, cdp.diff_tensor.Da * 1e-7) 196 self.assertAlmostEqual(Dratio, cdp.diff_tensor.Dratio) 197 self.assertAlmostEqual(theta, cdp.diff_tensor.theta) 198 self.assertAlmostEqual(phi, cdp.diff_tensor.phi) 199 200 # Check the diagonalised tensor. 201 for i in range(3): 202 for j in range(3): 203 self.assertAlmostEqual(cdp.diff_tensor.tensor_diag[i, j] * 1e-7, D_prime[i, j] * 1e-7) 204 205 # Check the orientation. 206 vects = [] 207 vects.append([1, 0, 0]) 208 vects.append([0, 1, 0]) 209 vects.append([0, 0, 1]) 210 vects = array(vects) 211 for vect in vects: 212 # The projections. 213 proj1 = dot(vect, dot(cdp.diff_tensor.tensor, vect)) 214 proj2 = dot(vect, dot(D, vect)) 215 216 # Compare projections. 217 self.assertAlmostEqual(proj1, proj2) 218 219 # Check the type. 220 if spheroid_type: 221 self.assertEqual(spheroid_type, cdp.diff_tensor.spheroid_type)
222 223
224 - def check_spheroid_as_ellipsoid(self, tm, Dx, Dy, Dz, Diso, Da, D, D_prime, R):
225 """Check if the ellipsoid in the cdp has the same values as given spheroid.""" 226 227 # Print outs. 228 print("The relax data store diffusion tensor:\n\n%s\n\n" % cdp.diff_tensor) 229 print("\nThe real tensor:\n%s" % D) 230 print("\nThe tensor in relax:\n%s" % cdp.diff_tensor.tensor) 231 print("\nThe real tensor (in eig frame):\n%s" % D_prime) 232 print("\nThe tensor in relax (in eig frame):\n%s" % cdp.diff_tensor.tensor_diag) 233 print("\nThe real rotation matrix:\n%s" % R) 234 print("\nThe rotation matrix in relax:\n%s" % cdp.diff_tensor.rotation) 235 236 # Check the Euler angles. 237 self.assertAlmostEqual(tm * 1e8, cdp.diff_tensor.tm * 1e8) 238 self.assertAlmostEqual(Dx * 1e-7, cdp.diff_tensor.Dx * 1e-7) 239 self.assertAlmostEqual(Dy * 1e-7, cdp.diff_tensor.Dy * 1e-7) 240 self.assertAlmostEqual(Dz * 1e-7, cdp.diff_tensor.Dz * 1e-7) 241 self.assertAlmostEqual(Diso * 1e-7, cdp.diff_tensor.Diso * 1e-7) 242 243 # Check the diagonalised tensor. 244 for i in range(3): 245 for j in range(3): 246 self.assertAlmostEqual(cdp.diff_tensor.tensor_diag[i, j] * 1e-7, D_prime[i, j] * 1e-7) 247 248 # Check the orientation. 249 vects = [] 250 vects.append([1, 0, 0]) 251 vects.append([0, 1, 0]) 252 vects.append([0, 0, 1]) 253 vects = array(vects) 254 for vect in vects: 255 # The projections. 256 proj1 = dot(vect, dot(cdp.diff_tensor.tensor, vect)) 257 proj2 = dot(vect, dot(D, vect)) 258 259 # Print out. 260 print("\nVector: %s" % vect) 261 print("Real proj: %s" % proj1) 262 print("Proj in relax: %s" % proj2) 263 264 # Compare projections. 265 self.assertAlmostEqual(proj1, proj2)
266 267
268 - def get_ellipsoid(self):
269 """Return all the diffusion tensor info about the {Dx, Dy, Dz, alpha, beta, gamma} = {1e7, 2e7, 3e7, 1, 2, 0.5} ellipsoid tensor.""" 270 271 # The tensor info. 272 Dx = 1e7 273 Dy = 2e7 274 Dz = 3e7 275 Diso = 2e7 276 Da = 1.5e7 277 Dr = 1.0/3.0 278 alpha = 1.0 279 beta = 2.0 280 gamma = 0.5 281 282 # The actual tensor in the PDB frame. 283 D = array([[ 22758858.4088357, -7267400.1700938, 6272205.75829415], 284 [ -7267400.1700938, 17923072.3436445, 1284270.53726401], 285 [ 6272205.75829415, 1284270.53726401, 19318069.2475198 ]], float64) 286 287 # The tensor in the eigenframe. 288 D_prime = zeros((3, 3), float64) 289 D_prime[0, 0] = Dx 290 D_prime[1, 1] = Dy 291 D_prime[2, 2] = Dz 292 293 # The rotation matrix. 294 R = zeros((3, 3), float64) 295 euler_to_R_zyz(gamma, beta, alpha, R) 296 R = transpose(R) 297 298 # Return the data. 299 return Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R
300 301
302 - def get_spheroid(self, Dpar=None, Dper=None, theta=None, phi=None):
303 """Return all the diffusion tensor info about the given spheroid tensor.""" 304 305 # The tensor info. 306 Diso = (Dpar + 2*Dper) / 3.0 307 tm = 1.0/(6.0 * Diso) 308 Da = Dpar - Dper 309 Dratio = Dpar / Dper 310 311 # The eigenvalues and unique axis in the eigenframe. 312 if Dpar > Dper: 313 Dx, Dy, Dz = Dper, Dper, Dpar 314 axis = array([0, 0, 1], float64) 315 else: 316 Dx, Dy, Dz = Dpar, Dper, Dper 317 axis = array([1, 0, 0], float64) 318 319 # The actual tensor in the PDB frame. 320 R = zeros((3, 3), float64) 321 spher_vect = array([1, theta, phi], float64) 322 diff_axis = zeros(3, float64) 323 spherical_to_cartesian(spher_vect, diff_axis) 324 two_vect_to_R(diff_axis, axis, R) 325 326 # The tensor in the eigenframe. 327 D_prime = zeros((3, 3), float64) 328 D_prime[0, 0] = Dx 329 D_prime[1, 1] = Dy 330 D_prime[2, 2] = Dz 331 332 # Rotate a little about the unique axis! 333 twist = zeros((3, 3), float64) 334 axis_angle_to_R(axis, 0.3, twist) 335 D = dot(twist, dot(D_prime, transpose(twist))) 336 337 # The tensor in the PDB frame. 338 D = dot(R, dot(D, transpose(R))) 339 340 # Return the data. 341 return tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R
342 343
344 - def test_back_calc_ellipsoid(self):
345 """Check the back-calculation of relaxation data for the spherical diffusion tensor.""" 346 347 # Reset relax. 348 reset() 349 350 # The diffusion type (used by the script). 351 ds.diff_dir = 'ellipsoid' 352 ds.diff_type = 'ellipsoid' 353 354 # Execute the script. 355 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'ri_back_calc.py') 356 357 # Loop over all spins. 358 for i in range(len(cdp.mol[0].res)): 359 # Alias. 360 spin = cdp.mol[0].res[i].spin[0] 361 362 # Check the values. 363 for ri_id in cdp.ri_ids: 364 self.assertAlmostEqual(spin.ri_data_bc[ri_id], spin.ri_data[ri_id])
365 366
367 - def test_back_calc_sphere(self):
368 """Check the back-calculation of relaxation data for the spherical diffusion tensor.""" 369 370 # Reset relax. 371 reset() 372 373 # The diffusion type (used by the script). 374 ds.diff_dir = 'sphere' 375 ds.diff_type = 'sphere' 376 377 # Execute the script. 378 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'ri_back_calc.py') 379 380 # Loop over all spins. 381 for i in range(len(cdp.mol[0].res)): 382 # Alias. 383 spin = cdp.mol[0].res[i].spin[0] 384 385 # Check the values. 386 for ri_id in cdp.ri_ids: 387 self.assertAlmostEqual(spin.ri_data_bc[ri_id], spin.ri_data[ri_id])
388 389
390 - def test_back_calc_spheroid(self):
391 """Check the back-calculation of relaxation data for the spherical diffusion tensor.""" 392 393 # Reset relax. 394 reset() 395 396 # The diffusion type (used by the script). 397 ds.diff_dir = 'spheroid_prolate' 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
414 """Catch U{bug #21561<https://web.archive.org/web/https://gna.org/bugs/?21561>} reported by Martin Ballaschk, the failure of the diffusion tensor PDB creation when Monte Carlo simulations are not present.""" 415 416 # Create a data pipe. 417 self.interpreter.pipe.create('diff PDB', 'mf') 418 419 # Initialise a diffusion tensor. 420 self.interpreter.diffusion_tensor.init((2e-8, 1.3, 60, 290), spheroid_type='prolate', param_types=2, fixed=True) 421 422 # Load a random protein structure. 423 path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'structures' 424 self.interpreter.structure.read_pdb('Ap4Aase_res1-12.pdb', dir=path) 425 426 # Generate the tensor PDB without MC sims. 427 self.interpreter.structure.create_diff_tensor_pdb(file=self.tmpfile_spheroid)
428 429
430 - def test_copy(self):
431 """The user function diffusion_tensor.copy().""" 432 433 # Create three additional data pipes for copying the spherical, spheroidal, and ellipsoidal diffusion data. 434 self.interpreter.pipe.create('sphere2', 'mf') 435 self.interpreter.pipe.create('spheroid2', 'mf') 436 self.interpreter.pipe.create('ellipsoid2', 'mf') 437 438 # Copy the data. 439 self.interpreter.diffusion_tensor.copy('sphere', 'sphere2') 440 self.interpreter.diffusion_tensor.copy('spheroid', 'spheroid2') 441 self.interpreter.diffusion_tensor.copy('ellipsoid', 'ellipsoid2') 442 443 # Get the data pipes. 444 sphere_pipe = get_pipe('sphere') 445 sphere2_pipe = get_pipe('sphere2') 446 447 # Check that this is indeed a copy. 448 self.assertEqual(sphere2_pipe.diff_tensor.tm_sim[4], 9.02e-8) 449 self.assertEqual(sphere2_pipe.diff_tensor.Diso_sim[4], 1/(6*9.02e-8)) 450 sphere_pipe.diff_tensor.set(param='tm', value=8.88e-8, category='sim', sim_index=4) 451 self.assertEqual(sphere_pipe.diff_tensor.tm_sim[4], 8.88e-8) 452 self.assertEqual(sphere_pipe.diff_tensor.Diso_sim[4], 1/(6*8.88e-8)) 453 self.assertEqual(sphere2_pipe.diff_tensor.tm_sim[4], 9.02e-8) 454 self.assertEqual(sphere2_pipe.diff_tensor.Diso_sim[4], 1/(6*9.02e-8))
455 456
457 - def test_delete(self):
458 """The user function diffusion_tensor.delete().""" 459 460 # Delete the data. 461 self.interpreter.pipe.switch('sphere') 462 self.interpreter.diffusion_tensor.delete() 463 self.interpreter.pipe.switch('spheroid') 464 self.interpreter.diffusion_tensor.delete() 465 self.interpreter.pipe.switch('ellipsoid') 466 self.interpreter.diffusion_tensor.delete()
467 468
469 - def test_display(self):
470 """The user function diffusion_tensor.display().""" 471 472 # Display the data. 473 self.interpreter.pipe.switch('sphere') 474 self.interpreter.diffusion_tensor.display() 475 self.interpreter.pipe.switch('spheroid') 476 self.interpreter.diffusion_tensor.display() 477 self.interpreter.pipe.switch('ellipsoid') 478 self.interpreter.diffusion_tensor.display()
479 480
482 """Test the user function structure.create_diff_tensor_pdb() for the ellipsoid.""" 483 484 # First copy the data (a more vigorous copy test!). 485 self.interpreter.pipe.copy('ellipsoid', 'ellipsoid2') 486 self.interpreter.pipe.switch('ellipsoid2') 487 self.interpreter.diffusion_tensor.delete() 488 self.interpreter.diffusion_tensor.copy('ellipsoid', 'ellipsoid2') 489 490 # Create the diffusion tensor objects. 491 self.interpreter.structure.create_diff_tensor_pdb(file=self.tmpfile_ellipsoid, scale=1e-05) 492 493 # Open the temp file. 494 file = open(self.tmpfile_ellipsoid) 495 new_data = file.readlines() 496 file.close() 497 498 # Open the real file. 499 file = open(status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'structures'+sep+'diff_tensors'+sep+'ellipsoid.pdb') 500 real_data = file.readlines() 501 file.close() 502 503 # Strip out all remark lines. 504 new_data_stripped = [] 505 for line in new_data: 506 if line[:6] != 'REMARK': 507 new_data_stripped.append(line) 508 real_data_stripped = [] 509 for line in real_data: 510 if line[:6] != 'REMARK': 511 real_data_stripped.append(line) 512 513 # Check the data. 514 self.assertEqual(len(real_data_stripped), len(new_data_stripped)) 515 for i in range(len(real_data_stripped)): 516 # Print the PDB line, for debugging. 517 print(real_data_stripped[i][0:-1]) 518 519 # Check the line. 520 self.assertEqual(real_data_stripped[i], new_data_stripped[i])
521 522
524 """Test the user function structure.create_diff_tensor_pdb() for the sphere.""" 525 526 # First copy the data (a more vigorous copy test!). 527 self.interpreter.pipe.copy('sphere', 'sphere2') 528 self.interpreter.pipe.switch('sphere2') 529 self.interpreter.diffusion_tensor.delete() 530 self.interpreter.diffusion_tensor.copy('sphere', 'sphere2') 531 532 # Create the diffusion tensor objects. 533 self.interpreter.structure.create_diff_tensor_pdb(file=self.tmpfile_sphere) 534 535 # Open the temp file. 536 file = open(self.tmpfile_sphere) 537 new_data = file.readlines() 538 file.close() 539 540 # Open the real file. 541 file = open(status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'structures'+sep+'diff_tensors'+sep+'sphere.pdb') 542 real_data = file.readlines() 543 file.close() 544 545 # Strip out all remark lines. 546 new_data_stripped = [] 547 for line in new_data: 548 if line[:6] != 'REMARK': 549 new_data_stripped.append(line) 550 real_data_stripped = [] 551 for line in real_data: 552 if line[:6] != 'REMARK': 553 real_data_stripped.append(line) 554 555 # Check the data. 556 self.assertEqual(len(real_data_stripped), len(new_data_stripped)) 557 for i in range(len(real_data_stripped)): 558 # Print the PDB line, for debugging. 559 print(real_data_stripped[i][0:-1]) 560 561 # Check the line. 562 self.assertEqual(real_data_stripped[i], new_data_stripped[i])
563 564
566 """Test the user function structure.create_diff_tensor_pdb() for the spheroid.""" 567 568 # First copy the data (a more vigorous copy test!). 569 self.interpreter.pipe.copy('spheroid', 'spheroid2') 570 self.interpreter.pipe.switch('spheroid2') 571 self.interpreter.diffusion_tensor.delete() 572 self.interpreter.diffusion_tensor.copy('spheroid', 'spheroid2') 573 574 # Create the diffusion tensor objects. 575 self.interpreter.structure.create_diff_tensor_pdb(file=self.tmpfile_spheroid) 576 577 # Open the temp file. 578 file = open(self.tmpfile_spheroid) 579 new_data = file.readlines() 580 file.close() 581 582 # Open the real file. 583 file = open(status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'structures'+sep+'diff_tensors'+sep+'spheroid.pdb') 584 real_data = file.readlines() 585 file.close() 586 587 # Strip out all remark lines. 588 new_data_stripped = [] 589 for line in new_data: 590 if line[:6] != 'REMARK': 591 new_data_stripped.append(line) 592 real_data_stripped = [] 593 for line in real_data: 594 if line[:6] != 'REMARK': 595 real_data_stripped.append(line) 596 597 # Check the data. 598 self.assertEqual(len(real_data_stripped), len(new_data_stripped)) 599 for i in range(len(real_data_stripped)): 600 # Print the PDB line, for debugging. 601 print(real_data_stripped[i][0:-1]) 602 603 # Check the line. 604 self.assertEqual(real_data_stripped[i], new_data_stripped[i])
605 606
608 """Test the initialisation of the ellipsoid diffusion tensor using parameter set 0.""" 609 610 # Get the ellipsoid data. 611 Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid() 612 613 # Create a new data pipe. 614 self.interpreter.pipe.create('ellipsoid2', 'mf') 615 616 # Tensor initialization. 617 self.interpreter.diffusion_tensor.init((1/(6.0*Diso), Da, Dr, alpha, beta, gamma), param_types=0, angle_units='rad') 618 619 # Check the ellipsoid. 620 self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
621 622
624 """Test the initialisation of the ellipsoid diffusion tensor using parameter set 0.""" 625 626 # Get the ellipsoid data. 627 Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid() 628 629 # Create a new data pipe. 630 self.interpreter.pipe.create('ellipsoid2', 'mf') 631 632 # Tensor initialization. 633 self.interpreter.diffusion_tensor.init((Diso, Da, Dr, alpha, beta, gamma), param_types=1, angle_units='rad') 634 635 # Check the ellipsoid. 636 self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
637 638
640 """Test the initialisation of the ellipsoid diffusion tensor using parameter set 0.""" 641 642 # Get the ellipsoid data. 643 Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid() 644 645 # Create a new data pipe. 646 self.interpreter.pipe.create('ellipsoid2', 'mf') 647 648 # Tensor initialization. 649 self.interpreter.diffusion_tensor.init((Dx, Dy, Dz, alpha, beta, gamma), param_types=2, angle_units='rad') 650 651 # Check the ellipsoid. 652 self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
653 654
656 """Test the initialisation of the ellipsoid diffusion tensor using parameter set 0.""" 657 658 # Get the ellipsoid data. 659 Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid() 660 661 # Create a new data pipe. 662 self.interpreter.pipe.create('ellipsoid2', 'mf') 663 664 # Tensor initialization. 665 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) 666 667 # Check the ellipsoid. 668 self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
669 670
672 """Test the initialisation of the spheroid diffusion tensor using parameter set 4.""" 673 674 # Get the spheroid data. 675 Dpar, Dper, theta, phi = 1e7, 4e7, pi/4.0, 0.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((D[0, 0], D[1, 1], D[2, 2], D[0, 1], D[0, 2], D[1, 2]), param_types=3) 683 684 # Check the ellipsoid. 685 self.check_spheroid_as_ellipsoid(tm, Dx, Dy, Dz, Diso, Da, D, D_prime, R)
686 687
689 """Test the initialisation of the oblate spheroid diffusion tensor using parameter set 0.""" 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((tm, Da, theta, phi), param_types=0, angle_units='rad') 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 1.""" 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((Diso, Da, theta, phi), param_types=1, 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 1, and angles in deg.""" 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((Diso, Da, theta/2.0/pi*360.0, phi/2.0/pi*360.0), param_types=1, angle_units='deg') 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 2.""" 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((tm, Dratio, theta, phi), param_types=2, 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 oblate spheroid diffusion tensor using parameter set 3.""" 758 759 # Get the spheroid data. 760 Dpar, Dper, theta, phi = 1e7, 4e7, 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((Dpar, Dper, theta, phi), param_types=3, angle_units='rad') 768 769 # Check the spheroid. 770 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='oblate')
771 772
774 """Test the initialisation of the oblate spheroid diffusion tensor using parameter set 4.""" 775 776 # Get the spheroid data. 777 Dpar, Dper, theta, phi = 1e7, 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((Diso, Dratio, theta, phi), param_types=4, 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='oblate')
788 789
791 """Test the initialisation of the spheroid diffusion tensor using parameter set 4.""" 792 793 # Get the spheroid data. 794 Dpar, Dper, theta, phi = 4e7, 2e7, 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((D[0, 0], D[1, 1], D[2, 2], D[0, 1], D[0, 2], D[1, 2]), param_types=3) 802 803 # Check the ellipsoid. 804 self.check_spheroid_as_ellipsoid(tm, Dx, Dy, Dz, Diso, Da, D, D_prime, R)
805 806
808 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 0.""" 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((tm, Da, theta, phi), spheroid_type='prolate', param_types=0, 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 0.""" 826 827 # Get the spheroid data. 828 Dpar, Dper, theta, phi = 8e7, 8e7, 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((tm, Da, theta, phi), spheroid_type='prolate', param_types=0, angle_units='rad') 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 1.""" 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((Diso, Da, theta, phi), param_types=1, 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 1, and angles in deg.""" 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((Diso, Da, theta/2.0/pi*360.0, phi/2.0/pi*360.0), param_types=1, angle_units='deg') 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 2.""" 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((tm, Dratio, theta, phi), param_types=2, 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
893 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 3.""" 894 895 # Get the spheroid data. 896 Dpar, Dper, theta, phi = 8e7, 4e7, 0.5, 1.0 897 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 898 899 # Create a new data pipe. 900 self.interpreter.pipe.create('spheroid2', 'mf') 901 902 # Tensor initialization. 903 self.interpreter.diffusion_tensor.init((Dpar, Dper, theta, phi), param_types=3, angle_units='rad') 904 905 # Check the spheroid. 906 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
907 908
910 """Test the initialisation of the prolate spheroid diffusion tensor using parameter set 4.""" 911 912 # Get the spheroid data. 913 Dpar, Dper, theta, phi = 8e7, 4e7, 0.5, 1.0 914 tm, Dx, Dy, Dz, Diso, Da, Dratio, D, D_prime, R = self.get_spheroid(Dpar=Dpar, Dper=Dper, theta=theta, phi=phi) 915 916 # Create a new data pipe. 917 self.interpreter.pipe.create('spheroid2', 'mf') 918 919 # Tensor initialization. 920 self.interpreter.diffusion_tensor.init((Diso, Dratio, theta, phi), param_types=4, angle_units='rad') 921 922 # Check the spheroid. 923 self.check_spheroid(tm, Dpar, Dper, Diso, Da, Dratio, theta, phi, D, D_prime, R, spheroid_type='prolate')
924 925
926 - def test_opt_ellipsoid(self):
927 """Check that the ellipsoid diffusion tensor optimisation functions correctly.""" 928 929 # Reset relax. 930 reset() 931 932 # The diffusion type (used by the script). 933 ds.diff_dir = 'ellipsoid' 934 ds.diff_type = 'ellipsoid' 935 936 # Execute the script. 937 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'tensor_opt.py') 938 939 # Print out. 940 print(cdp.diff_tensor) 941 942 # The real data. 943 Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R = self.get_ellipsoid() 944 945 # Check the values. 946 self.assertAlmostEqual(cdp.chi2, 0.0) 947 self.assertEqual(cdp.diff_tensor.fixed, False) 948 self.assertEqual(cdp.diff_tensor.type, 'ellipsoid') 949 950 # Check the ellipsoid. 951 self.check_ellipsoid(Dx, Dy, Dz, Diso, Da, Dr, alpha, beta, gamma, D, D_prime, R)
952 953
954 - def test_opt_sphere(self):
955 """Check that the sphere diffusion tensor optimisation functions correctly.""" 956 957 # Reset relax. 958 reset() 959 960 # The diffusion type (used by the script). 961 ds.diff_dir = 'sphere' 962 ds.diff_type = 'sphere' 963 964 # Execute the script. 965 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'tensor_opt.py') 966 967 # Check the values. 968 self.assertAlmostEqual(cdp.chi2, 0.0) 969 self.assertEqual(cdp.diff_tensor.fixed, False) 970 self.assertEqual(cdp.diff_tensor.type, 'sphere') 971 self.assertAlmostEqual(cdp.diff_tensor.tm * 1e9, 1.0/(6.0*2e7) * 1e9) 972 self.assertEqual(cdp.diff_tensor.rotation[0, 0], 1.0) 973 self.assertEqual(cdp.diff_tensor.rotation[1, 1], 1.0) 974 self.assertEqual(cdp.diff_tensor.rotation[2, 2], 1.0) 975 self.assertEqual(cdp.diff_tensor.rotation[0, 1], 0.0) 976 self.assertEqual(cdp.diff_tensor.rotation[0, 2], 0.0) 977 self.assertEqual(cdp.diff_tensor.rotation[1, 2], 0.0) 978 self.assertEqual(cdp.diff_tensor.rotation[1, 0], 0.0) 979 self.assertEqual(cdp.diff_tensor.rotation[2, 0], 0.0) 980 self.assertEqual(cdp.diff_tensor.rotation[2, 1], 0.0)
981 982
983 - def test_opt_spheroid(self):
984 """Check that the spheroid diffusion tensor optimisation functions correctly.""" 985 986 # Reset relax. 987 reset() 988 989 # The diffusion type (used by the script). 990 ds.diff_dir = 'spheroid_prolate' 991 ds.diff_type = 'spheroid' 992 993 # Execute the script. 994 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'diff_tensor'+sep+'tensor_opt.py') 995 996 # Check the values. 997 self.assertAlmostEqual(cdp.chi2, 0.0) 998 self.assertEqual(cdp.diff_tensor.fixed, False) 999 self.assertEqual(cdp.diff_tensor.type, 'spheroid') 1000 self.assertAlmostEqual(cdp.diff_tensor.tm * 1e9, 1.0/(6.0*7e7/3.0) * 1e9) 1001 self.assertAlmostEqual(cdp.diff_tensor.Da * 1e-7, 1.0) 1002 self.assertAlmostEqual(cdp.diff_tensor.theta, 2.0) 1003 self.assertAlmostEqual(cdp.diff_tensor.phi, pi-0.5)
1004