1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Module for the handling of Frame Order."""
24
25
26 from math import cos, pi, sqrt
27 try:
28 from scipy.integrate import dblquad
29 except ImportError:
30 pass
31
32
33 from lib.frame_order.matrix_ops import pcs_pivot_motion_torsionless, pcs_pivot_motion_torsionless_qrint, rotate_daeg
34
35
37 """Generate the rotated 2nd degree Frame Order matrix for the torsionless isotropic cone.
38
39 The cone axis is assumed to be parallel to the z-axis in the eigenframe.
40
41
42 @param matrix: The Frame Order matrix, 2nd degree to be populated.
43 @type matrix: numpy 9D, rank-2 array
44 @param Rx2_eigen: The Kronecker product of the eigenframe rotation matrix with itself.
45 @type Rx2_eigen: numpy 9D, rank-2 array
46 @param cone_theta: The cone opening angle.
47 @type cone_theta: float
48 """
49
50
51 for i in range(9):
52 for j in range(9):
53 matrix[i, j] = 0.0
54
55
56 cos_tmax = cos(cone_theta)
57 cos_tmax2 = cos_tmax**2
58
59
60 matrix[0, 0] = (3.0*cos_tmax2 + 6.0*cos_tmax + 15.0) / 24.0
61 matrix[1, 1] = (cos_tmax2 + 10.0*cos_tmax + 13.0) / 24.0
62 matrix[2, 2] = (4.0*cos_tmax2 + 10.0*cos_tmax + 10.0) / 24.0
63 matrix[3, 3] = matrix[1, 1]
64 matrix[4, 4] = matrix[0, 0]
65 matrix[5, 5] = matrix[2, 2]
66 matrix[6, 6] = matrix[2, 2]
67 matrix[7, 7] = matrix[2, 2]
68 matrix[8, 8] = (cos_tmax2 + cos_tmax + 1.0) / 3.0
69
70
71 matrix[0, 4] = matrix[4, 0] = (cos_tmax2 - 2.0*cos_tmax + 1.0) / 24.0
72 matrix[0, 8] = matrix[8, 0] = -(cos_tmax2 + cos_tmax - 2.0) / 6.0
73 matrix[4, 8] = matrix[8, 4] = matrix[0, 8]
74
75
76 matrix[1, 3] = matrix[3, 1] = matrix[0, 4]
77 matrix[2, 6] = matrix[6, 2] = -matrix[0, 8]
78 matrix[5, 7] = matrix[7, 5] = -matrix[0, 8]
79
80
81 return rotate_daeg(matrix, Rx2_eigen)
82
83
85 """Determine the averaged PCS value via numerical integration.
86
87 @keyword theta_max: The half cone angle.
88 @type theta_max: float
89 @keyword c: The PCS constant (without the interatomic distance and in Angstrom units).
90 @type c: float
91 @keyword r_pivot_atom: The pivot point to atom vector.
92 @type r_pivot_atom: numpy rank-1, 3D array
93 @keyword r_ln_pivot: The lanthanide position to pivot point vector.
94 @type r_ln_pivot: numpy rank-1, 3D array
95 @keyword A: The full alignment tensor of the non-moving domain.
96 @type A: numpy rank-2, 3D array
97 @keyword R_eigen: The eigenframe rotation matrix.
98 @type R_eigen: numpy rank-2, 3D array
99 @keyword RT_eigen: The transpose of the eigenframe rotation matrix (for faster calculations).
100 @type RT_eigen: numpy rank-2, 3D array
101 @keyword Ri_prime: The empty rotation matrix for the in-frame isotropic cone motion, used to calculate the PCS for each state i in the numerical integration.
102 @type Ri_prime: numpy rank-2, 3D array
103 @return: The averaged PCS value.
104 @rtype: float
105 """
106
107
108 result = dblquad(pcs_pivot_motion_torsionless, -pi, pi, lambda phi: 0.0, lambda phi: theta_max, args=(r_pivot_atom, r_ln_pivot, A, R_eigen, RT_eigen, Ri_prime))
109
110
111 SA = 2.0 * pi * (1.0 - cos(theta_max))
112
113
114 return c * result[0] / SA
115
116
117 -def pcs_numeric_int_iso_cone_torsionless_qrint(points=None, theta_max=None, c=None, full_in_ref_frame=None, r_pivot_atom=None, r_pivot_atom_rev=None, r_ln_pivot=None, A=None, R_eigen=None, RT_eigen=None, Ri_prime=None, pcs_theta=None, pcs_theta_err=None, missing_pcs=None, error_flag=False):
118 """Determine the averaged PCS value via numerical integration.
119
120 @keyword points: The Sobol points in the torsion-tilt angle space.
121 @type points: numpy rank-2, 3D array
122 @keyword theta_max: The half cone angle.
123 @type theta_max: float
124 @keyword c: The PCS constant (without the interatomic distance and in Angstrom units).
125 @type c: numpy rank-1 array
126 @keyword full_in_ref_frame: An array of flags specifying if the tensor in the reference frame is the full or reduced tensor.
127 @type full_in_ref_frame: numpy rank-1 array
128 @keyword r_pivot_atom: The pivot point to atom vector.
129 @type r_pivot_atom: numpy rank-2, 3D array
130 @keyword r_pivot_atom_rev: The reversed pivot point to atom vector.
131 @type r_pivot_atom_rev: numpy rank-2, 3D array
132 @keyword r_ln_pivot: The lanthanide position to pivot point vector.
133 @type r_ln_pivot: numpy rank-2, 3D array
134 @keyword A: The full alignment tensor of the non-moving domain.
135 @type A: numpy rank-2, 3D array
136 @keyword R_eigen: The eigenframe rotation matrix.
137 @type R_eigen: numpy rank-2, 3D array
138 @keyword RT_eigen: The transpose of the eigenframe rotation matrix (for faster calculations).
139 @type RT_eigen: numpy rank-2, 3D array
140 @keyword Ri_prime: The empty rotation matrix for the in-frame isotropic cone motion, used to calculate the PCS for each state i in the numerical integration.
141 @type Ri_prime: numpy rank-2, 3D array
142 @keyword pcs_theta: The storage structure for the back-calculated PCS values.
143 @type pcs_theta: numpy rank-2 array
144 @keyword pcs_theta_err: The storage structure for the back-calculated PCS errors.
145 @type pcs_theta_err: numpy rank-2 array
146 @keyword missing_pcs: A structure used to indicate which PCS values are missing.
147 @type missing_pcs: numpy rank-2 array
148 @keyword error_flag: A flag which if True will cause the PCS errors to be estimated and stored in pcs_theta_err.
149 @type error_flag: bool
150 """
151
152
153 for i in range(len(pcs_theta)):
154 for j in range(len(pcs_theta[i])):
155 pcs_theta[i, j] = 0.0
156 pcs_theta_err[i, j] = 0.0
157
158
159 num = 0
160 for i in range(len(points)):
161
162 theta, phi = points[i]
163
164
165 if theta > theta_max:
166 continue
167
168
169 pcs_pivot_motion_torsionless_qrint(theta_i=theta, phi_i=phi, full_in_ref_frame=full_in_ref_frame, r_pivot_atom=r_pivot_atom, r_pivot_atom_rev=r_pivot_atom_rev, r_ln_pivot=r_ln_pivot, A=A, R_eigen=R_eigen, RT_eigen=RT_eigen, Ri_prime=Ri_prime, pcs_theta=pcs_theta, pcs_theta_err=pcs_theta_err, missing_pcs=missing_pcs)
170
171
172 num += 1
173
174
175 for i in range(len(pcs_theta)):
176 for j in range(len(pcs_theta[i])):
177
178 pcs_theta[i, j] = c[i] * pcs_theta[i, j] / float(num)
179
180
181 if error_flag:
182 pcs_theta_err[i, j] = abs(pcs_theta_err[i, j] / float(num) - pcs_theta[i, j]**2) / float(num)
183 pcs_theta_err[i, j] = c[i] * sqrt(pcs_theta_err[i, j])
184 print("%8.3f +/- %-8.3f" % (pcs_theta[i, j]*1e6, pcs_theta_err[i, j]*1e6))
185