Package test_suite :: Package unit_tests :: Package _lib :: Package _frame_order :: Module test_matrix_ops
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._lib._frame_order.test_matrix_ops

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