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