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