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 manipulation of alignment tensors."""
24
25
26 from math import pi
27 from numpy.linalg import eigvals
28
29
30 from lib.physical_constants import g1H, h_bar, kB, mu0, return_gyromagnetic_ratio
31
32
34 """Convert the alignment tensor into the magnetic susceptibility (chi) tensor.
35
36 A can be either the full tensor (3D or 5D), a component Aij of the tensor, Aa, or Ar, anything that can be multiplied by the constants to convert from one to the other.
37
38
39 @param A: The alignment tensor or alignment tensor component.
40 @type A: numpy array or float
41 @param B0: The magnetic field strength in Hz.
42 @type B0: float
43 @param T: The temperature in Kalvin.
44 @type T: float
45 @return: A multiplied by the PCS constant.
46 @rtype: numpy array or float
47 """
48
49
50 B0 = 2.0 * pi * B0 / g1H
51
52
53 conv = 15.0 * mu0 * kB * T / B0**2
54
55
56 return conv * A
57
58
60 """The dAi/dAxx gradient.
61
62 This function will modify the A matrix to be equal to::
63
64 dAi | 1 0 0 |
65 ---- = | 0 0 0 |
66 dAxx | 0 0 -1 |
67
68
69 @param A: The alignment tensor object.
70 @type A: numpy rank-2 3D tensor
71 """
72
73
74 A[0, 0] = 1.0; A[0, 1] = 0.0; A[0, 2] = 0.0
75 A[1, 0] = 0.0; A[1, 1] = 0.0; A[1, 2] = 0.0
76 A[2, 0] = 0.0; A[2, 1] = 0.0; A[2, 2] = -1.0
77
78
80 """The dAi/dAyy gradient.
81
82 This function will modify the A matrix to be equal to::
83
84 dAi | 0 0 0 |
85 ---- = | 0 1 0 |
86 dAyy | 0 0 -1 |
87
88
89 @param A: The alignment tensor object.
90 @type A: numpy rank-2 3D tensor
91 """
92
93
94 A[0, 0] = 0.0; A[0, 1] = 0.0; A[0, 2] = 0.0
95 A[1, 0] = 0.0; A[1, 1] = 1.0; A[1, 2] = 0.0
96 A[2, 0] = 0.0; A[2, 1] = 0.0; A[2, 2] = -1.0
97
98
100 """The dAi/dAxy gradient.
101
102 This function will modify the A matrix to be equal to::
103
104 dAi | 0 1 0 |
105 ---- = | 1 0 0 |
106 dAxy | 0 0 0 |
107
108
109 @param A: The alignment tensor object.
110 @type A: numpy rank-2 3D tensor
111 """
112
113
114 A[0, 0] = 0.0; A[0, 1] = 1.0; A[0, 2] = 0.0
115 A[1, 0] = 1.0; A[1, 1] = 0.0; A[1, 2] = 0.0
116 A[2, 0] = 0.0; A[2, 1] = 0.0; A[2, 2] = 0.0
117
118
120 """The dAi/dAxz gradient.
121
122 This function will modify the A matrix to be equal to::
123
124 dAi | 0 0 1 |
125 ---- = | 0 0 0 |
126 dAxz | 1 0 0 |
127
128
129 @param A: The alignment tensor object.
130 @type A: numpy rank-2 3D tensor
131 """
132
133
134 A[0, 0] = 0.0; A[0, 1] = 0.0; A[0, 2] = 1.0
135 A[1, 0] = 0.0; A[1, 1] = 0.0; A[1, 2] = 0.0
136 A[2, 0] = 1.0; A[2, 1] = 0.0; A[2, 2] = 0.0
137
138
140 """The dAi/dAyz gradient.
141
142 This function will modify the A matrix to be equal to::
143
144 dAi | 0 0 0 |
145 ---- = | 0 0 1 |
146 dAyz | 0 1 0 |
147
148
149 @param A: The alignment tensor object.
150 @type A: numpy rank-2 3D tensor
151 """
152
153
154 A[0, 0] = 0.0; A[0, 1] = 0.0; A[0, 2] = 0.0
155 A[1, 0] = 0.0; A[1, 1] = 0.0; A[1, 2] = 1.0
156 A[2, 0] = 0.0; A[2, 1] = 1.0; A[2, 2] = 0.0
157
158
159 -def kappa(nuc1='15N', nuc2='1H'):
160 """Function for calculating the kappa constant.
161
162 The kappa constant is::
163
164 kappa = -3/(8pi^2).gI.gS.mu0.h_bar,
165
166 where gI and gS are the gyromagnetic ratios of the I and S spins, mu0 is the permeability of
167 free space, and h_bar is Planck's constant divided by 2pi.
168
169 @param nuc1: The first nucleus type.
170 @type nuc1: str
171 @param nuc2: The first nucleus type.
172 @type nuc2: str
173 @return: The kappa constant value.
174 @rtype: float
175 """
176
177
178 gI = return_gyromagnetic_ratio(nuc1)
179 gS = return_gyromagnetic_ratio(nuc2)
180
181
182 return -3.0/(8.0*pi**2) * gI * gS * mu0 * h_bar
183
184
186 """Find the maximal alignment - the Azz component in the alignment frame.
187
188 @param tensor: The alignment tensor object.
189 @type tensor: numpy rank-2 3D tensor
190 @return: The Azz component in the alignment frame.
191 """
192
193
194 return max(abs(eigvals(tensor)))
195
196
197 -def to_5D(vector_5D, tensor):
198 """Convert the rank-2 3D alignment tensor matrix to the 5D vector format.
199
200 @param vector_5D: The 5D vector object to populate. The vector format is {Axx, Ayy, Axy, Axz,
201 Ayz}.
202 @type vector_5D: numpy 5D vector
203 @param tensor: The alignment tensor object.
204 @type tensor: numpy rank-2 3D tensor
205 """
206
207
208 vector_5D[0] = tensor[0, 0]
209 vector_5D[1] = tensor[1, 1]
210 vector_5D[2] = tensor[0, 1]
211 vector_5D[3] = tensor[0, 2]
212 vector_5D[4] = tensor[1, 2]
213
214
216 """Convert the 5D vector alignment tensor form to the rank-2 3D matrix from.
217
218 @param tensor: The alignment tensor object, in matrix format, to populate.
219 @type tensor: numpy rank-2 3D tensor
220 @param vector_5D: The 5D vector object. The vector format is {Axx, Ayy, Axy, Axz, Ayz}.
221 @type vector_5D: numpy 5D vector
222 """
223
224
225 tensor[0, 0] = vector_5D[0]
226 tensor[0, 1] = vector_5D[2]
227 tensor[0, 2] = vector_5D[3]
228 tensor[1, 0] = vector_5D[2]
229 tensor[1, 1] = vector_5D[1]
230 tensor[1, 2] = vector_5D[4]
231 tensor[2, 0] = vector_5D[3]
232 tensor[2, 1] = vector_5D[4]
233 tensor[2, 2] = -vector_5D[0] -vector_5D[1]
234