1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from math import pi
24 from numpy import array, eye, float64, zeros
25 from unittest import TestCase
26
27
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
37 """Unit tests for the maths_fns.frame_order_matrix_ops relax module."""
38
39 - def __init__(self, methodName='runTest'):
53
54
56 """Initialise a few data structures for the tests."""
57
58
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
65 self.setup_identity()
66
67
68 self.setup_identity_free_rotor()
69
70
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
77 """Set up a few identity matrices."""
78
79
80 self.I_order = zeros((9, 9), float64)
81 for i in range(9):
82 self.I_order[i, i] = 1.0
83
84
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
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
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
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
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
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
186 f2 = compile_2nd_matrix_free_rotor(self.f2_temp, self.R_temp, self.z_axis, self.cone_axis, 0, 0)
187
188
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
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
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
216 r, theta, phi = cartesian_to_spherical([2, 1, 3])
217
218
219 f2 = compile_2nd_matrix_free_rotor(self.f2_temp, self.R_temp, self.z_axis, self.cone_axis, theta, phi)
220
221
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
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
237 f2 = compile_2nd_matrix_iso_cone(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi, pi)
238
239
240 print_frame_order_2nd_degree(self.I_disorder, "Identity for disorder")
241 print_frame_order_2nd_degree(f2, "Compiled frame order")
242
243
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
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
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
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
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
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
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
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
291 print_frame_order_2nd_degree(self.I_order, "Identity for order")
292 print_frame_order_2nd_degree(f2, "Compiled frame order")
293
294
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
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
308 print_frame_order_2nd_degree(self.I_order, "Identity for order")
309 print_frame_order_2nd_degree(f2, "Compiled frame order")
310
311
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
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
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
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
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
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
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
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
364 f2_ref = self.f2_half_cone
365
366
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
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
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
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
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
399 z_axis = array([1, 0, 0], float64)
400
401
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
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
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
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
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
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
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
449 x = pi/4.0
450 y = 3.0*pi/8.0
451 z = pi/6.0
452
453
454 f2 = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, 0, 0, 0, x, y, z)
455
456
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
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
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
484 x = pi/4.0
485 y = 3.0*pi/8.0
486 z = 40.0 / 360.0 * 2.0 * pi
487
488
489 f2 = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, 0, 0, 0, x, y, z)
490
491
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
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
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
519 x = 60.0 / 360.0 * 2.0 * pi
520 y = 3.0 * pi / 8.0
521 z = pi / 6.0
522
523
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
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
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
542 f2 = compile_2nd_matrix_pseudo_ellipse(self.f2_temp, self.R_temp, 0.0, 0.0, 0.0, pi, pi, pi)
543
544
545 print_frame_order_2nd_degree(self.I_disorder, "Identity for disorder")
546 print_frame_order_2nd_degree(f2, "Compiled frame order")
547
548
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
728 print_frame_order_2nd_degree(self.I_disorder, "Identity for disorder")
729 print_frame_order_2nd_degree(f2, "Compiled frame order")
730
731
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
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
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
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
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
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
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
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
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
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
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
805 x = pi/4.0
806 y = 50.0 / 360.0 * 2.0 * pi
807
808
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
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
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
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
839 x = pi / 4.0
840 y = 150.0 / 360.0 * 2.0 * pi
841
842
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
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
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
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
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
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
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
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
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
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
911 sigma_max = 60.0 / 180.0 * pi
912
913
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
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
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
932 A = array([1, 2, 3, 4, 5], float64)
933 red = zeros(5, float64)
934
935
936 reduce_alignment_tensor(self.I_order, A, red)
937
938
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
947 A = array([1, 2, 3, 4, 5], float64)
948 red = zeros(5, float64)
949
950
951 reduce_alignment_tensor(self.I_disorder, A, red)
952
953
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
962 A = array([1, 2, 3, 4, 5], float64)
963 red = zeros(5, float64)
964
965
966 reduce_alignment_tensor(self.f2_half_cone, A, red)
967
968
969 for i in range(5):
970 self.assertEqual(red[i], 0.0)
971