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

Source Code for Module test_suite.unit_tests._maths_fns.test_frame_order_matrix_ops

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2010-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, eye, float64, zeros 
 25  from unittest import TestCase 
 26   
 27  # relax module imports. 
 28  from generic_fns.frame_order import print_frame_order_2nd_degree 
 29  from maths_fns.coord_transform import cartesian_to_spherical 
 30  from maths_fns.frame_order_matrix_ops import * 
 31  from maths_fns.kronecker_product import transpose_23 
 32  from maths_fns.order_parameters import iso_cone_theta_to_S 
 33  from status import Status; status = Status() 
 34   
 35   
36 -class Test_frame_order_matrix_ops(TestCase):
37 """Unit tests for the maths_fns.frame_order_matrix_ops relax module.""" 38
39 - def __init__(self, methodName='runTest'):
40 """Skip the tests if scipy is not installed. 41 42 @keyword methodName: The name of the test. 43 @type methodName: str 44 """ 45 46 # Missing module. 47 if not dep_check.scipy_module: 48 # Store in the status object. 49 status.skipped_tests.append([methodName, 'Scipy', 'unit']) 50 51 # Execute the base class method. 52 super(Test_frame_order_matrix_ops, self).__init__(methodName)
53 54
55 - def setUp(self):
56 """Initialise a few data structures for the tests.""" 57 58 # Temp storage. 59 self.f2_temp = zeros((9, 9), float64) 60 self.R_temp = zeros((3, 3), float64) 61 self.z_axis = array([0, 0, 1], float64) 62 self.cone_axis = zeros(3, float64) 63 64 # Set up the identity matrices. 65 self.setup_identity() 66 67 # Set up the identity matrices for free rotors. 68 self.setup_identity_free_rotor() 69 70 # Out of frame Euler angles. 71 self.out_of_frame_alpha = 1.10714871779 72 self.out_of_frame_beta = 0.841068670568 73 self.out_of_frame_gamma = 5.81953769818
74 75
76 - def setup_identity(self):
77 """Set up a few identity matrices.""" 78 79 # The order identity matrix. 80 self.I_order = zeros((9, 9), float64) 81 for i in range(9): 82 self.I_order[i, i] = 1.0 83 84 # The disorder identity matrix. 85 data = [[0, 0, 1.0/3.0], 86 [4, 4, 1.0/3.0], 87 [8, 8, 1.0/3.0], 88 [0, 4, 1.0/3.0], 89 [4, 0, 1.0/3.0], 90 [0, 8, 1.0/3.0], 91 [8, 0, 1.0/3.0], 92 [4, 8, 1.0/3.0], 93 [8, 4, 1.0/3.0]] 94 self.I_disorder = zeros((9, 9), float64) 95 for i, j, val in data: 96 self.I_disorder[i, j] = val 97 98 # The half cone matrix. 99 data = [[0, 0, 1.0/3.0], 100 [4, 4, 1.0/3.0], 101 [8, 8, 1.0/3.0], 102 [0, 4, 1.0/3.0], 103 [4, 0, 1.0/3.0], 104 [0, 8, 1.0/3.0], 105 [8, 0, 1.0/3.0], 106 [4, 8, 1.0/3.0], 107 [8, 4, 1.0/3.0], 108 [1, 3, -0.25], 109 [3, 1, -0.25], 110 [1, 1, 0.25], 111 [3, 3, 0.25]] 112 self.f2_half_cone = zeros((9, 9), float64) 113 for i, j, val in data: 114 self.f2_half_cone[i, j] = val 115 116 # The half cone matrix rotated 90 degrees about y. 117 data = [[0, 0, 1.0/3.0], 118 [4, 4, 1.0/3.0], 119 [8, 8, 1.0/3.0], 120 [0, 4, 1.0/3.0], 121 [4, 0, 1.0/3.0], 122 [0, 8, 1.0/3.0], 123 [8, 0, 1.0/3.0], 124 [4, 8, 1.0/3.0], 125 [8, 4, 1.0/3.0], 126 [5, 7, -0.25], 127 [7, 5, -0.25], 128 [7, 7, 0.25], 129 [5, 5, 0.25]] 130 self.f2_half_cone_90_y = zeros((9, 9), float64) 131 for i, j, val in data: 132 self.f2_half_cone_90_y[i, j] = val
133 134
136 """Set up a few identity matrices.""" 137 138 # The order identity matrix for the free rotors. 139 data = [[0, 0, 0.5], 140 [1, 1, 0.5], 141 [3, 3, 0.5], 142 [4, 4, 0.5], 143 [0, 4, 0.5], 144 [4, 0, 0.5], 145 [1, 3, -0.5], 146 [3, 1, -0.5], 147 [8, 8, 1.0]] 148 self.I_order_free_rotor = zeros((9, 9), float64) 149 for i, j, val in data: 150 self.I_order_free_rotor[i, j] = val 151 152 # The disorder identity matrix for the free rotors. 153 data = [[0, 0, 0.25], 154 [1, 1, 0.125], 155 [3, 3, 0.125], 156 [4, 4, 0.25], 157 [0, 4, 0.25], 158 [4, 0, 0.25], 159 [1, 3, -0.125], 160 [3, 1, -0.125], 161 [0, 8, 0.5], 162 [8, 0, 0.5], 163 [4, 8, 0.5], 164 [8, 4, 0.5]] 165 self.I_disorder_free_rotor = zeros((9, 9), float64) 166 for i, j, val in data: 167 self.I_disorder_free_rotor[i, j] = val
168 169
171 """Check the operation of the compile_2nd_matrix_free_rotor() function.""" 172 173 # The simulated in frame free rotor 2nd degree frame order matrix (1e6 ensembles). 174 real = array( 175 [[ 0.5001, 0.0001, 0, 0.0001, 0.4999, 0, 0, 0, 0], 176 [ -0.0001, 0.5001, 0, -0.4999, 0.0001, 0, 0, 0, 0], 177 [ 0, 0, 0.0006, 0, 0, -0.0005, 0, 0, 0], 178 [ -0.0001, -0.4999, 0, 0.5001, 0.0001, 0, 0, 0, 0], 179 [ 0.4999, -0.0001, 0, -0.0001, 0.5001, 0, 0, 0, 0], 180 [ 0, 0, 0.0005, 0, 0, 0.0006, 0, 0, 0], 181 [ 0, 0, 0, 0, 0, 0, 0.0006, -0.0005, 0], 182 [ 0, 0, 0, 0, 0, 0, 0.0005, 0.0006, 0], 183 [ 0, 0, 0, 0, 0, 0, 0, 0, 1.0000]]) 184 185 # Calculate the matrix. 186 f2 = compile_2nd_matrix_free_rotor(self.f2_temp, self.R_temp, self.z_axis, self.cone_axis, 0, 0) 187 188 # Print out. 189 print_frame_order_2nd_degree(real, "real") 190 print_frame_order_2nd_degree(f2, "calculated") 191 print_frame_order_2nd_degree(real-f2, "difference") 192 193 # Check the values. 194 for i in range(9): 195 for j in range(9): 196 print("Element %s, %s; diff %s." % (i, j, f2[i, j] - real[i, j])) 197 self.assert_(abs(f2[i, j] - real[i, j]) < 1e-3)
198 199
201 """Check the operation of the compile_2nd_matrix_free_rotor() function.""" 202 203 # The simulated free rotor 2nd degree frame order matrix (1e6 ensembles, axis=[2,1,3]). 204 real = array( 205 [[ 0.3367, -0.0100, -0.0307, -0.0100, 0.3521, -0.0152, -0.0307, -0.0152, 0.3112], 206 [ -0.0104, 0.3520, -0.0152, -0.2908, -0.0559, 0.2602, 0.1989, -0.1685, 0.0664], 207 [ -0.0306, -0.0155, 0.3112, 0.1991, -0.1683, 0.0666, 0.2399, 0.2092, 0.1989], 208 [ -0.0104, -0.2908, 0.1989, 0.3520, -0.0559, -0.1685, -0.0152, 0.2602, 0.0664], 209 [ 0.3520, -0.0563, -0.1684, -0.0563, 0.4362, -0.0841, -0.1684, -0.0841, 0.2118], 210 [ -0.0153, 0.2602, 0.0661, -0.1684, -0.0844, 0.2117, 0.2093, -0.0740, 0.0997], 211 [ -0.0306, 0.1991, 0.2399, -0.0155, -0.1683, 0.2092, 0.3112, 0.0666, 0.1989], 212 [ -0.0153, -0.1684, 0.2093, 0.2602, -0.0844, -0.0740, 0.0661, 0.2117, 0.0997], 213 [ 0.3113, 0.0663, 0.1991, 0.0663, 0.2117, 0.0993, 0.1991, 0.0993, 0.4770]]) 214 215 # The cone axis. 216 r, theta, phi = cartesian_to_spherical([2, 1, 3]) 217 218 # Calculate the matrix. 219 f2 = compile_2nd_matrix_free_rotor(self.f2_temp, self.R_temp, self.z_axis, self.cone_axis, theta, phi) 220 221 # Print out. 222 print_frame_order_2nd_degree(real, "real") 223 print_frame_order_2nd_degree(f2, "calculated") 224 print_frame_order_2nd_degree(real-f2, "difference") 225 226 # Check the values. 227 for i in range(9): 228 for j in range(9): 229 print("Element %s, %s; diff %s." % (i, j, f2[i, j] - real[i, j])) 230 self.assert_(abs(f2[i, j] - real[i, j]) < 1e-3)
231 232
234 """Check if compile_2nd_matrix_iso_cone() can return the identity matrix for disorder.""" 235 236 # Calculate the frame order matrix. 237 f2 = compile_2nd_matrix_iso_cone(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi, pi) 238 239 # Print outs. 240 print_frame_order_2nd_degree(self.I_disorder, "Identity for disorder") 241 print_frame_order_2nd_degree(f2, "Compiled frame order") 242 243 # Check the values. 244 for i in range(9): 245 for j in range(9): 246 print("Element %s, %s." % (i, j)) 247 self.assertAlmostEqual(f2[i, j], self.I_disorder[i, j])
248 249
251 """Check if compile_2nd_matrix_iso_cone() can return the matrix for a half cone.""" 252 253 # Calculate the frame order matrix. 254 f2 = compile_2nd_matrix_iso_cone(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi/2.0, pi) 255 256 # Print outs. 257 print_frame_order_2nd_degree(self.f2_half_cone, "The half cone frame order matrix") 258 print_frame_order_2nd_degree(f2, "Compiled frame order") 259 260 # Check the values. 261 for i in range(9): 262 for j in range(9): 263 print("Element %s, %s." % (i, j)) 264 self.assertAlmostEqual(f2[i, j], self.f2_half_cone[i, j])
265 266
268 """Check if compile_2nd_matrix_iso_cone() can return the matrix for a half cone rotated 90 degrees about y.""" 269 270 # Calculate the frame order matrix. 271 f2 = compile_2nd_matrix_iso_cone(self.f2_temp, self.R_temp, 0.0, pi/2.0, 0.0, pi/2.0, pi) 272 273 # Print outs. 274 print_frame_order_2nd_degree(self.f2_half_cone_90_y, "The half cone frame order matrix") 275 print_frame_order_2nd_degree(f2, "Compiled frame order") 276 277 # Check the values. 278 for i in range(9): 279 for j in range(9): 280 print("Element %s, %s." % (i, j)) 281 self.assertAlmostEqual(f2[i, j], self.f2_half_cone_90_y[i, j])
282 283
285 """Check if compile_2nd_matrix_iso_cone() can return the identity matrix for order.""" 286 287 # Calculate the frame order matrix. 288 f2 = compile_2nd_matrix_iso_cone(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, 1e-5, 1e-10) 289 290 # Print outs. 291 print_frame_order_2nd_degree(self.I_order, "Identity for order") 292 print_frame_order_2nd_degree(f2, "Compiled frame order") 293 294 # Check the values. 295 for i in range(9): 296 for j in range(9): 297 print("Element %s, %s." % (i, j)) 298 self.assertAlmostEqual(f2[i, j], self.I_order[i, j])
299 300
302 """2nd check if compile_2nd_matrix_iso_cone() can return the identity matrix for order.""" 303 304 # Calculate the frame order matrix. 305 f2 = compile_2nd_matrix_iso_cone(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, 0.0, 0.0) 306 307 # Print outs. 308 print_frame_order_2nd_degree(self.I_order, "Identity for order") 309 print_frame_order_2nd_degree(f2, "Compiled frame order") 310 311 # Check the values. 312 for i in range(9): 313 for j in range(9): 314 print("Element %s, %s." % (i, j)) 315 self.assertAlmostEqual(f2[i, j], self.I_order[i, j])
316 317
319 """Check if compile_2nd_matrix_iso_cone() can approximate compile_2nd_matrix_iso_cone_free_rotor().""" 320 321 # Calculate the frame order matrix. 322 f2a = compile_2nd_matrix_iso_cone(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi/4.6, pi) 323 f2b = compile_2nd_matrix_iso_cone_free_rotor(self.f2_temp, self.R_temp, self.z_axis, self.cone_axis, 0.0, 1.0, iso_cone_theta_to_S(pi/4.6)) 324 325 # Print outs. 326 print_frame_order_2nd_degree(f2a, "Isotropic cone frame order") 327 print_frame_order_2nd_degree(f2b, "Free rotor isotropic cone frame order") 328 print_frame_order_2nd_degree(f2b-f2a, "difference") 329 330 # Check the values. 331 for i in range(9): 332 for j in range(9): 333 print("Element %s, %s." % (i, j)) 334 self.assertAlmostEqual(f2a[i, j], f2b[i, j])
335 336
338 """Check if compile_2nd_matrix_iso_cone() can approximate compile_2nd_matrix_iso_cone_torsionless().""" 339 340 # Calculate the frame order matrix. 341 f2a = compile_2nd_matrix_iso_cone(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi/4.6, 0) 342 f2b = compile_2nd_matrix_iso_cone_torsionless(self.f2_temp, self.R_temp, self.z_axis, self.cone_axis, 0.0, 0.0, pi/4.6) 343 344 # Print outs. 345 print_frame_order_2nd_degree(f2a, "Isotropic cone frame order") 346 print_frame_order_2nd_degree(f2b, "Torsionless isotropic cone frame order") 347 print_frame_order_2nd_degree(f2b-f2a, "difference") 348 349 # Check the values. 350 for i in range(9): 351 for j in range(9): 352 print("Element %s, %s." % (i, j)) 353 self.assertAlmostEqual(f2a[i, j], f2b[i, j])
354 355
357 """Check if compile_2nd_matrix_iso_cone_free_rotor() can return the identity matrix for disorder.""" 358 359 360 # Calculate the frame order matrix. 361 f2 = compile_2nd_matrix_iso_cone_free_rotor(self.f2_temp, self.R_temp, self.z_axis, self.cone_axis, 0.0, 1.0, 0.0) 362 363 # Cannot differentiate full disorder from the half cone in this model! 364 f2_ref = self.f2_half_cone 365 366 # Print outs. 367 print_frame_order_2nd_degree(self.I_disorder, "Identity for disorder") 368 print_frame_order_2nd_degree(f2_ref, "The half cone frame order matrix") 369 print_frame_order_2nd_degree(f2, "Compiled frame order") 370 371 # Check the values. 372 for i in range(9): 373 for j in range(9): 374 print("Element %s, %s." % (i, j)) 375 self.assertAlmostEqual(f2[i, j], f2_ref[i, j])
376 377
379 """Check if compile_2nd_matrix_iso_cone() can return the matrix for a half cone.""" 380 381 # Calculate the frame order matrix. 382 f2 = compile_2nd_matrix_iso_cone_free_rotor(self.f2_temp, self.R_temp, self.z_axis, self.cone_axis, 0.0, 1.0, 0.0) 383 384 # Print outs. 385 print_frame_order_2nd_degree(self.f2_half_cone, "The half cone frame order matrix") 386 print_frame_order_2nd_degree(f2, "Compiled frame order") 387 388 # Check the values. 389 for i in range(9): 390 for j in range(9): 391 print("Element %s, %s." % (i, j)) 392 self.assertAlmostEqual(f2[i, j], self.f2_half_cone[i, j])
393 394
396 """Check if compile_2nd_matrix_iso_cone() can return the matrix for a half cone rotated 90 degrees about y.""" 397 398 # Init. 399 z_axis = array([1, 0, 0], float64) 400 401 # Calculate the frame order matrix. 402 f2 = compile_2nd_matrix_iso_cone_free_rotor(self.f2_temp, self.R_temp, z_axis, self.cone_axis, 0.0, 1.0, 0.0) 403 404 # Print outs. 405 print_frame_order_2nd_degree(self.f2_half_cone_90_y, "The half cone frame order matrix") 406 print_frame_order_2nd_degree(f2, "Compiled frame order") 407 408 # Check the values. 409 for i in range(9): 410 for j in range(9): 411 print("Element %s, %s." % (i, j)) 412 self.assertAlmostEqual(f2[i, j], self.f2_half_cone_90_y[i, j])
413 414
416 """Check if compile_2nd_matrix_iso_cone_free_rotor() can return the identity matrix for order.""" 417 418 # Calculate the frame order matrix. 419 f2 = compile_2nd_matrix_iso_cone_free_rotor(self.f2_temp, self.R_temp, self.z_axis, self.cone_axis, 0.0, 1.0, 1.0) 420 421 # Print outs. 422 print_frame_order_2nd_degree(self.I_order_free_rotor, "Free rotor identity for order") 423 print_frame_order_2nd_degree(f2, "Compiled frame order") 424 425 # Check the values. 426 for i in range(9): 427 for j in range(9): 428 print("Element %s, %s." % (i, j)) 429 self.assertAlmostEqual(f2[i, j], self.I_order_free_rotor[i, j])
430 431
433 """Check the operation of the compile_2nd_matrix_pseudo_ellipse() function.""" 434 435 # The simulated in frame pseudo-ellipse 2nd degree frame order matrix. 436 real = array( 437 [[ 0.7901, 0, 0, 0, 0.7118, 0, 0, 0, 0.6851], 438 [ 0, 0.0816, 0, -0.0606, 0, 0, 0, 0, 0], 439 [ 0, 0, 0.1282, 0, 0, 0, -0.1224, 0, 0], 440 [ 0, -0.0606, 0, 0.0708, 0, 0, 0, 0, 0], 441 [ 0.7118, 0, 0, 0, 0.6756, 0, 0, 0, 0.6429], 442 [ 0, 0, 0, 0, 0, 0.2536, 0, -0.2421, 0], 443 [ 0, 0, -0.1224, 0, 0, 0, 0.1391, 0, 0], 444 [ 0, 0, 0, 0, 0, -0.2421, 0, 0.2427, 0], 445 [ 0.6851, 0, 0, 0, 0.6429, 0, 0, 0, 0.6182]], float64) 446 transpose_23(real) 447 448 # Init. 449 x = pi/4.0 450 y = 3.0*pi/8.0 451 z = pi/6.0 452 453 # Calculate the matrix. 454 f2 = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, 0, 0, 0, x, y, z) 455 456 # Print out. 457 print_frame_order_2nd_degree(real, "real") 458 print_frame_order_2nd_degree(f2, "calculated") 459 print_frame_order_2nd_degree(real-f2, "difference") 460 461 # Check the values. 462 for i in range(9): 463 for j in range(9): 464 print("Element %s, %s; diff %s." % (i, j, f2[i, j] - real[i, j])) 465 self.assert_(abs(f2[i, j] - real[i, j]) < 1e-4)
466 467
469 """Check the operation of the compile_2nd_matrix_pseudo_ellipse() function.""" 470 471 # The simulated in frame pseudo-ellipse 2nd degree frame order matrix (1e6 ensembles). 472 real = array( 473 [[ 0.7379, 0, 0, 0, 0.1338, 0, 0, 0, 0.1284], 474 [ 0, 0.6637, 0, -0.1085, 0, 0, 0, 0, 0], 475 [ 0, 0, 0.6603, 0, 0, 0, -0.1181, 0, 0], 476 [ 0, -0.1085, 0, 0.6637, 0, 0, 0, 0, 0], 477 [ 0.1154, 0, 0, 0, 0.6309, 0, 0, 0, 0.2536], 478 [ 0, 0, 0, 0, 0, 0.6196, 0, -0.2336, 0], 479 [ 0, 0, -0.1181, 0, 0, 0, 0.6603, 0, 0], 480 [ 0, 0, 0, 0, 0, -0.2336, 0, 0.6196, 0], 481 [ 0.1467, 0, 0, 0, 0.2353, 0, 0, 0, 0.6180]], float64) 482 483 # Init. 484 x = pi/4.0 485 y = 3.0*pi/8.0 486 z = 40.0 / 360.0 * 2.0 * pi 487 488 # Calculate the matrix. 489 f2 = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, 0, 0, 0, x, y, z) 490 491 # Print out. 492 print_frame_order_2nd_degree(real, "real") 493 print_frame_order_2nd_degree(f2, "calculated") 494 print_frame_order_2nd_degree(real-f2, "difference") 495 496 # Check the values. 497 for i in range(9): 498 for j in range(9): 499 print("Element %s, %s; diff %s." % (i, j, f2[i, j] - real[i, j])) 500 self.assert_(abs(f2[i, j] - real[i, j]) < 1e-3)
501 502
504 """Check the operation of the compile_2nd_matrix_pseudo_ellipse() function.""" 505 506 # The simulated out of frame pseudo-ellipse 2nd degree frame order matrix (1e6 ensembles). 507 real = array( 508 [[ 0.6314, 0.0232, -0.0344, 0.0232, 0.1558, -0.0222, -0.0344, -0.0222, 0.2128], 509 [ 0.0220, 0.6366, 0.0069, -0.1352, 0.0243, -0.0722, 0.0206, -0.0277, -0.0464], 510 [ -0.0332, 0.0097, 0.6137, 0.0222, 0.0668, 0.0173, -0.1967, 0.0489, -0.0336], 511 [ 0.0220, -0.1352, 0.0206, 0.6366, 0.0243, -0.0277, 0.0069, -0.0722, -0.0464], 512 [ 0.1554, 0.0233, 0.0669, 0.0233, 0.6775, 0.0113, 0.0669, 0.0113, 0.1671], 513 [ -0.0222, -0.0738, 0.0188, -0.0286, 0.0113, 0.6310, 0.0507, -0.1502, 0.0109], 514 [ -0.0332, 0.0222, -0.1967, 0.0097, 0.0668, 0.0489, 0.6137, 0.0173, -0.0336], 515 [ -0.0222, -0.0286, 0.0507, -0.0738, 0.0113, -0.1502, 0.0188, 0.6310, 0.0109], 516 [ 0.2132, -0.0465, -0.0324, -0.0465, 0.1667, 0.0110, -0.0324, 0.0110, 0.6201]], float64) 517 518 # Init. 519 x = 60.0 / 360.0 * 2.0 * pi 520 y = 3.0 * pi / 8.0 521 z = pi / 6.0 522 523 # Calculate the matrix. 524 f2 = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, self.out_of_frame_alpha, self.out_of_frame_beta, self.out_of_frame_gamma, x, y, z) 525 526 # Print out. 527 print_frame_order_2nd_degree(real, "real") 528 print_frame_order_2nd_degree(f2, "calculated") 529 print_frame_order_2nd_degree(real-f2, "difference") 530 531 # Check the values. 532 for i in range(9): 533 for j in range(9): 534 print("Element %s, %s; diff %s." % (i, j, f2[i, j] - real[i, j])) 535 self.assert_(abs(f2[i, j] - real[i, j]) < 1e-3)
536 537
539 """Check if compile_2nd_matrix_pseudo_ellipse() can return the identity matrix for disorder.""" 540 541 # Calculate the frame order matrix. 542 f2 = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi, pi, pi) 543 544 # Print outs. 545 print_frame_order_2nd_degree(self.I_disorder, "Identity for disorder") 546 print_frame_order_2nd_degree(f2, "Compiled frame order") 547 548 # Check the values. 549 for i in range(9): 550 for j in range(9): 551 print("Element %s, %s." % (i, j)) 552 self.assertAlmostEqual(f2[i, j], self.I_disorder[i, j])
553 554
556 """Check if compile_2nd_matrix_pseudo_ellipse() can return the matrix for a half cone.""" 557 558 # Calculate the frame order matrix. 559 f2 = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi/2.0, pi/2.0, pi) 560 561 # Print outs. 562 print_frame_order_2nd_degree(self.f2_half_cone, "The half cone frame order matrix") 563 print_frame_order_2nd_degree(f2, "Compiled frame order") 564 565 # Check the values. 566 for i in range(9): 567 for j in range(9): 568 print("Element %s, %s." % (i, j)) 569 self.assertAlmostEqual(f2[i, j], self.f2_half_cone[i, j])
570 571
573 """Check if compile_2nd_matrix_pseudo_ellipse() can return the matrix for a half cone rotated 90 degrees about y.""" 574 575 # Calculate the frame order matrix. 576 f2 = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, 0.0, pi/2.0, 0.0, pi/2.0, pi/2.0, pi) 577 578 # Print outs. 579 print_frame_order_2nd_degree(self.f2_half_cone_90_y, "The half cone frame order matrix") 580 print_frame_order_2nd_degree(f2, "Compiled frame order") 581 582 # Check the values. 583 for i in range(9): 584 for j in range(9): 585 print("Element %s, %s." % (i, j)) 586 self.assertAlmostEqual(f2[i, j], self.f2_half_cone_90_y[i, j])
587 588
590 """Check if compile_2nd_matrix_pseudo_ellipse() can return the identity matrix for order.""" 591 592 # Calculate the frame order matrix. 593 f2 = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, 1e-2, 1e-2, 1e-10) 594 595 # Print outs. 596 print_frame_order_2nd_degree(self.I_order, "Identity for order") 597 print_frame_order_2nd_degree(f2, "Compiled frame order") 598 print_frame_order_2nd_degree(f2-self.I_order, "difference") 599 600 # Check the values. 601 for i in range(9): 602 for j in range(9): 603 print("Element %s, %s." % (i, j)) 604 self.assertAlmostEqual(f2[i, j], self.I_order[i, j], 4)
605 606
608 """Check if compile_2nd_matrix_pseudo_ellipse() can approximate compile_2nd_matrix_pseudo_ellipse_free_rotor().""" 609 610 # Calculate the frame order matrix. 611 f2a = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi/1.6, pi/5.8, pi) 612 f2b = compile_2nd_matrix_pseudo_ellipse_free_rotor(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi/1.6, pi/5.8) 613 614 # Print outs. 615 print_frame_order_2nd_degree(f2a, "Pseudo-ellipse frame order") 616 print_frame_order_2nd_degree(f2b, "Free rotor pseudo-ellipse frame order") 617 print_frame_order_2nd_degree(f2b-f2a, "difference") 618 619 # Check the values. 620 for i in range(9): 621 for j in range(9): 622 print("Element %s, %s." % (i, j)) 623 self.assertAlmostEqual(f2a[i, j], f2b[i, j])
624 625
627 """Check if compile_2nd_matrix_pseudo_ellipse() can approximate a pi/2 rotated compile_2nd_matrix_pseudo_ellipse_free_rotor().""" 628 629 # Calculate the frame order matrix. 630 f2a = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi/1.6, pi/5.8, pi) 631 f2b = compile_2nd_matrix_pseudo_ellipse_free_rotor(self.f2_temp, self.R_temp, pi/2, 0.0, 0.0, pi/5.8, pi/1.6) 632 633 # Print outs. 634 print_frame_order_2nd_degree(f2a, "Pseudo-ellipse frame order") 635 print_frame_order_2nd_degree(f2b, "pi/2 rotated free rotor pseudo-ellipse frame order") 636 print_frame_order_2nd_degree(f2b-f2a, "difference") 637 638 # Check the values. 639 for i in range(9): 640 for j in range(9): 641 print("Element %s, %s." % (i, j)) 642 self.assertAlmostEqual(f2a[i, j], f2b[i, j])
643 644
646 """Check if compile_2nd_matrix_pseudo_ellipse() can approximate compile_2nd_matrix_pseudo_ellipse_torsionless().""" 647 648 # Calculate the frame order matrix. 649 f2a = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi/2.1, pi/4.6, 0) 650 f2b = compile_2nd_matrix_pseudo_ellipse_torsionless(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi/2.1, pi/4.6) 651 652 # Print outs. 653 print_frame_order_2nd_degree(f2a, "Pseudo-ellipse frame order") 654 print_frame_order_2nd_degree(f2b, "Torsionless pseudo-ellipse frame order") 655 print_frame_order_2nd_degree(f2b-f2a, "difference") 656 657 # Check the values. 658 for i in range(9): 659 for j in range(9): 660 print("Element %s, %s; diff %s." % (i, j, f2b[i, j] - f2a[i, j])) 661 self.assertAlmostEqual(f2a[i, j], f2b[i, j])
662 663
665 """Check if compile_2nd_matrix_pseudo_ellipse() can approximate compile_2nd_matrix_iso_cone().""" 666 667 # Calculate the frame order matrix. 668 f2a = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi/4.6, pi/4.6, 0.2) 669 f2b = compile_2nd_matrix_iso_cone(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi/4.6, 0.2) 670 671 # Print outs. 672 print_frame_order_2nd_degree(f2a, "Pseudo-ellipse frame order") 673 print_frame_order_2nd_degree(f2b, "Isotropic cone frame order") 674 print_frame_order_2nd_degree(f2b-f2a, "difference") 675 676 # Check the values. 677 for i in range(9): 678 for j in range(9): 679 print("Element %s, %s." % (i, j)) 680 self.assertAlmostEqual(f2a[i, j], f2b[i, j])
681 682
684 """Check if compile_2nd_matrix_pseudo_ellipse() can approximate compile_2nd_matrix_iso_cone_free_rotor().""" 685 686 # Calculate the frame order matrix. 687 f2a = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi/4.6, pi/4.6, pi) 688 f2b = compile_2nd_matrix_iso_cone_free_rotor(self.f2_temp, self.R_temp, self.z_axis, self.cone_axis, 0.0, 1.0, iso_cone_theta_to_S(pi/4.6)) 689 690 # Print outs. 691 print_frame_order_2nd_degree(f2a, "Pseudo-ellipse frame order") 692 print_frame_order_2nd_degree(f2b, "Free rotor isotropic cone frame order") 693 print_frame_order_2nd_degree(f2b-f2a, "difference") 694 695 # Check the values. 696 for i in range(9): 697 for j in range(9): 698 print("Element %s, %s." % (i, j)) 699 self.assertAlmostEqual(f2a[i, j], f2b[i, j])
700 701
703 """Check if compile_2nd_matrix_pseudo_ellipse() can approximate compile_2nd_matrix_iso_cone_torsionless().""" 704 705 # Calculate the frame order matrix. 706 f2a = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi/8.6, pi/8.6, 0) 707 f2b = compile_2nd_matrix_iso_cone_torsionless(self.f2_temp, self.R_temp, self.z_axis, self.cone_axis, 0.0, 0.0, pi/8.6) 708 709 # Print outs. 710 print_frame_order_2nd_degree(f2a, "Pseudo-ellipse frame order") 711 print_frame_order_2nd_degree(f2b, "Torsionless isotropic cone frame order") 712 print_frame_order_2nd_degree(f2b-f2a, "difference") 713 714 # Check the values. 715 for i in range(9): 716 for j in range(9): 717 print("Element %s, %s." % (i, j)) 718 self.assertAlmostEqual(f2a[i, j], f2b[i, j])
719 720
722 """Check if compile_2nd_matrix_pseudo_ellipse_free_rotor() can return the identity matrix for disorder.""" 723 724 # Calculate the frame order matrix. 725 f2 = compile_2nd_matrix_pseudo_ellipse_free_rotor(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi, pi) 726 727 # Print outs. 728 print_frame_order_2nd_degree(self.I_disorder, "Identity for disorder") 729 print_frame_order_2nd_degree(f2, "Compiled frame order") 730 731 # Check the values. 732 for i in range(9): 733 for j in range(9): 734 print("Element %s, %s." % (i, j)) 735 self.assertAlmostEqual(f2[i, j], self.I_disorder[i, j])
736 737
739 """Check if compile_2nd_matrix_pseudo_ellipse() can return the matrix for a half cone.""" 740 741 # Calculate the frame order matrix (rotated about z by 2pi). 742 f2 = compile_2nd_matrix_pseudo_ellipse_free_rotor(self.f2_temp, self.R_temp, pi, 0.0, pi, pi/2.0, pi/2.0) 743 744 # Print outs. 745 print_frame_order_2nd_degree(self.f2_half_cone, "The half cone frame order matrix") 746 print_frame_order_2nd_degree(f2, "Compiled frame order") 747 748 # Check the values. 749 for i in range(9): 750 for j in range(9): 751 print("Element %s, %s." % (i, j)) 752 self.assertAlmostEqual(f2[i, j], self.f2_half_cone[i, j])
753 754
756 """Check if compile_2nd_matrix_pseudo_ellipse() can return the matrix for a half cone rotated 90 degrees about y.""" 757 758 # Calculate the frame order matrix (rotated about z by 2pi). 759 f2 = compile_2nd_matrix_pseudo_ellipse_free_rotor(self.f2_temp, self.R_temp, pi, pi/2.0, pi, pi/2.0, pi/2.0) 760 761 # Print outs. 762 print_frame_order_2nd_degree(self.f2_half_cone_90_y, "The half cone frame order matrix") 763 print_frame_order_2nd_degree(f2, "Compiled frame order") 764 765 # Check the values. 766 for i in range(9): 767 for j in range(9): 768 print("Element %s, %s." % (i, j)) 769 self.assertAlmostEqual(f2[i, j], self.f2_half_cone_90_y[i, j])
770 771
773 """Check if compile_2nd_matrix_pseudo_ellipse_free_rotor() can return the identity matrix for order.""" 774 775 # Calculate the frame order matrix. 776 f2 = compile_2nd_matrix_pseudo_ellipse_free_rotor(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, 1e-10, 1e-10) 777 778 # Print outs. 779 print_frame_order_2nd_degree(self.I_order_free_rotor, "Free rotor identity for order") 780 print_frame_order_2nd_degree(f2, "Compiled frame order") 781 782 # Check the values. 783 for i in range(9): 784 for j in range(9): 785 print("Element %s, %s." % (i, j)) 786 self.assertAlmostEqual(f2[i, j], self.I_order_free_rotor[i, j])
787 788
790 """Check the operation of the compile_2nd_matrix_pseudo_ellipse_free_rotor() function.""" 791 792 # The simulated out of frame free rotor pseudo-ellipse 2nd degree frame order matrix (1e6 ensembles). 793 real = array( 794 [[ 0.3428, -0.0193, 0.0389, -0.0193, 0.3137, -0.0194, 0.0389, -0.0194, 0.3435], 795 [ -0.0225, 0.2313, 0.0034, -0.1413, 0.0449, 0.2309, -0.1830, -0.1412, -0.0224], 796 [ 0.0417, 0.0091, 0.2142, -0.1767, -0.0838, 0.0092, 0.1211, -0.1770, 0.0421], 797 [ -0.0225, -0.1413, -0.1830, 0.2313, 0.0449, -0.1412, 0.0034, 0.2309, -0.0224], 798 [ 0.3124, 0.0418, -0.0840, 0.0418, 0.3758, 0.0418, -0.0840, 0.0418, 0.3118], 799 [ -0.0193, 0.2251, 0.0151, -0.1476, 0.0389, 0.2251, -0.1706, -0.1468, -0.0196], 800 [ 0.0417, -0.1767, 0.1211, 0.0091, -0.0838, -0.1770, 0.2142, 0.0092, 0.0421], 801 [ -0.0193, -0.1476, -0.1706, 0.2251, 0.0389, -0.1468, 0.0151, 0.2251, -0.0196], 802 [ 0.3448, -0.0225, 0.0450, -0.0225, 0.3104, -0.0224, 0.0450, -0.0224, 0.3447]], float64) 803 804 # Init. 805 x = pi/4.0 806 y = 50.0 / 360.0 * 2.0 * pi 807 808 # Calculate the matrix. 809 f2 = compile_2nd_matrix_pseudo_ellipse_free_rotor(self.f2_temp, self.R_temp, self.out_of_frame_alpha, self.out_of_frame_beta, self.out_of_frame_gamma, x, y) 810 811 # Print out. 812 print_frame_order_2nd_degree(real, "real") 813 print_frame_order_2nd_degree(f2, "calculated") 814 print_frame_order_2nd_degree(real-f2, "difference") 815 816 # Check the values. 817 for i in range(9): 818 for j in range(9): 819 print("Element %s, %s." % (i, j)) 820 self.assert_(abs(f2[i, j] - real[i, j]) < 1e-3)
821 822
824 """Check the operation of the compile_2nd_matrix_pseudo_ellipse_free_rotor() function.""" 825 826 # The simulated out of frame free rotor pseudo-ellipse 2nd degree frame order matrix (1e6 ensembles). 827 real = array( 828 [[ 0.3251, 0.0163, -0.0324, 0.0163, 0.3493, 0.0164, -0.0324, 0.0164, 0.3256], 829 [ -0.0248, 0.1481, -0.0480, -0.0500, 0.0492, 0.1475, -0.1472, -0.0500, -0.0244], 830 [ 0.0079, 0.0328, 0.0572, -0.0661, -0.0163, 0.0331, 0.0074, -0.0662, 0.0084], 831 [ -0.0248, -0.0500, -0.1472, 0.1481, 0.0492, -0.0500, -0.0480, 0.1475, -0.0244], 832 [ 0.3289, 0.0081, -0.0167, 0.0081, 0.3426, 0.0080, -0.0167, 0.0080, 0.3285], 833 [ 0.0163, 0.0669, 0.1139, -0.1322, -0.0324, 0.0662, 0.0157, -0.1307, 0.0161], 834 [ 0.0079, -0.0661, 0.0074, 0.0328, -0.0163, -0.0662, 0.0572, 0.0331, 0.0084], 835 [ 0.0163, -0.1322, 0.0157, 0.0669, -0.0324, -0.1307, 0.1139, 0.0662, 0.0161], 836 [ 0.3459, -0.0245, 0.0491, -0.0245, 0.3081, -0.0244, 0.0491, -0.0244, 0.3460]], float64) 837 838 # Init. 839 x = pi / 4.0 840 y = 150.0 / 360.0 * 2.0 * pi 841 842 # Calculate the matrix. 843 f2 = compile_2nd_matrix_pseudo_ellipse_free_rotor(self.f2_temp, self.R_temp, self.out_of_frame_alpha, self.out_of_frame_beta, self.out_of_frame_gamma, x, y) 844 845 # Print out. 846 print_frame_order_2nd_degree(real, "real") 847 print_frame_order_2nd_degree(f2, "calculated") 848 print_frame_order_2nd_degree(real-f2, "difference") 849 850 # Check the values. 851 for i in range(9): 852 for j in range(9): 853 print("Element %s, %s." % (i, j)) 854 self.assert_(abs(f2[i, j] - real[i, j]) < 1e-2)
855 856
858 """Check if compile_2nd_matrix_pseudo_ellipse_free_rotor() can approximate compile_2nd_matrix_iso_cone_free_rotor().""" 859 860 # Calculate the frame order matrix. 861 f2a = compile_2nd_matrix_pseudo_ellipse_free_rotor(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi/4.6, pi/4.6) 862 f2b = compile_2nd_matrix_iso_cone_free_rotor(self.f2_temp, self.R_temp, self.z_axis, self.cone_axis, 0.0, 1.0, iso_cone_theta_to_S(pi/4.6)) 863 864 # Print outs. 865 print_frame_order_2nd_degree(f2a, "Free rotor pseudo-ellipse frame order") 866 print_frame_order_2nd_degree(f2b, "Free rotor isotropic cone frame order") 867 print_frame_order_2nd_degree(f2b-f2a, "difference") 868 869 # Check the values. 870 for i in range(9): 871 for j in range(9): 872 print("Element %s, %s." % (i, j)) 873 self.assertAlmostEqual(f2a[i, j], f2b[i, j])
874 875
877 """Check if compile_2nd_matrix_pseudo_ellipse_torsionless() can approximate compile_2nd_matrix_iso_cone_torsionless().""" 878 879 # Calculate the frame order matrix. 880 f2a = compile_2nd_matrix_pseudo_ellipse_torsionless(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi/4.6, pi/4.6) 881 f2b = compile_2nd_matrix_iso_cone_torsionless(self.f2_temp, self.R_temp, self.z_axis, self.cone_axis, 0.0, 0.0, pi/4.6) 882 883 # Print outs. 884 print_frame_order_2nd_degree(f2a, "Torsionless pseudo-ellipse frame order") 885 print_frame_order_2nd_degree(f2b, "Torsionless isotropic cone frame order") 886 print_frame_order_2nd_degree(f2b-f2a, "difference") 887 888 # Check the values. 889 for i in range(9): 890 for j in range(9): 891 print("Element %s, %s." % (i, j)) 892 self.assertAlmostEqual(f2a[i, j], f2b[i, j])
893 894
896 """Check the operation of the compile_2nd_matrix_rotor() function.""" 897 898 # The simulated in frame rotor 2nd degree frame order matrix (1e7 ensembles). 899 real = array( 900 [[ 7.06775425e-01, 1.36710179e-04, 0.00000000e+00, 1.36710179e-04, 2.93224575e-01, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], 901 [ -1.36710179e-04, 7.06775425e-01, 0.00000000e+00, -2.93224575e-01, 1.36710179e-04, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], 902 [ 0.00000000e+00, 0.00000000e+00, 8.27014112e-01, 0.00000000e+00, 0.00000000e+00, 2.19539417e-04, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], 903 [ -1.36710179e-04, -2.93224575e-01, 0.00000000e+00, 7.06775425e-01, 1.36710179e-04, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], 904 [ 2.93224575e-01, -1.36710179e-04, 0.00000000e+00, -1.36710179e-04, 7.06775425e-01, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], 905 [ 0.00000000e+00, 0.00000000e+00, -2.19539417e-04, 0.00000000e+00, 0.00000000e+00, 8.27014112e-01, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], 906 [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 8.27014112e-01, 2.19539417e-04, 0.00000000e+00], 907 [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, -2.19539417e-04, 8.27014112e-01, 0.00000000e+00], 908 [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.00000000e+00]]) 909 910 # Init. 911 sigma_max = 60.0 / 180.0 * pi 912 913 # Calculate the matrix. 914 f2 = compile_2nd_matrix_rotor(self.f2_temp, self.R_temp, self.z_axis, self.cone_axis, 0.0, 0.0, sigma_max) 915 916 # Print out. 917 print_frame_order_2nd_degree(real, "real") 918 print_frame_order_2nd_degree(f2, "calculated") 919 print_frame_order_2nd_degree(real-f2, "difference") 920 921 # Check the values. 922 for i in range(9): 923 for j in range(9): 924 print("Element %s, %s." % (i, j)) 925 self.assert_(abs(f2[i, j] - real[i, j]) < 1e-3)
926 927
929 """Test the alignment tensor reduction for the order identity matrix.""" 930 931 # The tensors. 932 A = array([1, 2, 3, 4, 5], float64) 933 red = zeros(5, float64) 934 935 # Reduce. 936 reduce_alignment_tensor(self.I_order, A, red) 937 938 # Check. 939 for i in range(5): 940 self.assertEqual(A[i], red[i])
941 942
944 """Test the alignment tensor reduction for the order identity matrix.""" 945 946 # The tensors. 947 A = array([1, 2, 3, 4, 5], float64) 948 red = zeros(5, float64) 949 950 # Reduce. 951 reduce_alignment_tensor(self.I_disorder, A, red) 952 953 # Check. 954 for i in range(5): 955 self.assertEqual(red[i], 0.0)
956 957
959 """Test the alignment tensor reduction for the order identity matrix.""" 960 961 # The tensors. 962 A = array([1, 2, 3, 4, 5], float64) 963 red = zeros(5, float64) 964 965 # Reduce. 966 reduce_alignment_tensor(self.f2_half_cone, A, red) 967 968 # Check. 969 for i in range(5): 970 self.assertEqual(red[i], 0.0)
971