DimSpin 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dimspin/Adaptive_Grid_Method.py +212 -0
- dimspin/AutoSim.py +113 -0
- dimspin/Class_Spec.py +270 -0
- dimspin/Class_Spin.py +462 -0
- dimspin/Crystal_Rotation.py +74 -0
- dimspin/ETeam_Hyperfine.py +25 -0
- dimspin/ETeam_ZFS.py +24 -0
- dimspin/ETeam_Zeeman.py +27 -0
- dimspin/Eigenfield_Method.py +114 -0
- dimspin/Eular2Rot.py +52 -0
- dimspin/Fibonacci_Orientation.py +19 -0
- dimspin/High_Field_Method.py +133 -0
- dimspin/Levels_Plot.py +119 -0
- dimspin/Line_Broadening.py +178 -0
- dimspin/Orientation_Switch.py +27 -0
- dimspin/Parallel.py +92 -0
- dimspin/Pointsnum_Optimise.py +17 -0
- dimspin/Powder.py +118 -0
- dimspin/Rodrigues_Rotation.py +11 -0
- dimspin/Root_Finder.py +220 -0
- dimspin/Show_Spectra.py +48 -0
- dimspin/Space_Group.py +6451 -0
- dimspin/Space_Group_Expand.py +140 -0
- dimspin/Space_Group_L.py +135 -0
- dimspin/Spec_Oneside.py +68 -0
- dimspin/Spin_Operators.py +89 -0
- dimspin/Steven_Operator.py +161 -0
- dimspin/Team_Hyperfine.py +23 -0
- dimspin/Team_ZFS.py +24 -0
- dimspin/Team_ZFS_HighOrder.py +48 -0
- dimspin/Team_Zeeman.py +22 -0
- dimspin/Tensor.py +71 -0
- dimspin/Truncate_Observable.py +34 -0
- dimspin/Vec_normalize.py +9 -0
- dimspin/__init__.py +28 -0
- dimspin-0.1.0.dist-info/METADATA +142 -0
- dimspin-0.1.0.dist-info/RECORD +40 -0
- dimspin-0.1.0.dist-info/WHEEL +5 -0
- dimspin-0.1.0.dist-info/licenses/LICENSE +21 -0
- dimspin-0.1.0.dist-info/top_level.txt +1 -0
dimspin/Class_Spin.py
ADDED
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
"""Spin centre: tensors, Hamiltonian assembly and modulation.
|
|
2
|
+
|
|
3
|
+
The Spin object stores the g, D and A tensors, the spin-electric coupling
|
|
4
|
+
tensors T, R and F, the high-order zero-field coefficients B2/B4/B6, and the
|
|
5
|
+
parameter-modulation amplitudes dg/dD/dA. :meth:`Spin.identity_tensor`
|
|
6
|
+
validates and normalizes them; :meth:`Spin.update_Btensor` and
|
|
7
|
+
:meth:`Spin.update_H_initial` prepare the crystal-frame tensors and the
|
|
8
|
+
field-independent Hamiltonian; the ``modulate_*`` methods set ``H_total`` for
|
|
9
|
+
a given field and modulation sign.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import logging
|
|
13
|
+
|
|
14
|
+
import numpy as np
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _array_any(value):
|
|
18
|
+
"""
|
|
19
|
+
Inputs: tensor-like value.
|
|
20
|
+
|
|
21
|
+
Returns: True when the value contains a nonzero entry.
|
|
22
|
+
|
|
23
|
+
Notes: unreadable values count as nonzero so that the caller still warns.
|
|
24
|
+
"""
|
|
25
|
+
try:
|
|
26
|
+
return bool(np.asarray(value).any())
|
|
27
|
+
except (TypeError, ValueError):
|
|
28
|
+
return True
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _as_matrix(value, name, allow_scalar=False, scalar_factory=None,
|
|
32
|
+
vector_factory=None, base_factory=None, two_factory=None):
|
|
33
|
+
"""
|
|
34
|
+
Inputs: tensor-like value; tensor name; conversion callables for a scalar,
|
|
35
|
+
a length-2 pair and a 3-vector.
|
|
36
|
+
|
|
37
|
+
Returns: a 3x3 float array.
|
|
38
|
+
|
|
39
|
+
Notes: None or an empty value gives zeros. An unrecognized shape raises
|
|
40
|
+
ValueError.
|
|
41
|
+
"""
|
|
42
|
+
if value is None:
|
|
43
|
+
return np.zeros((3, 3))
|
|
44
|
+
arr = np.asarray(value, dtype=float)
|
|
45
|
+
if arr.size == 0:
|
|
46
|
+
return np.zeros((3, 3))
|
|
47
|
+
if arr.shape == () and allow_scalar and scalar_factory is not None:
|
|
48
|
+
result = scalar_factory(arr.item())
|
|
49
|
+
elif arr.shape == (2,) and two_factory is not None:
|
|
50
|
+
result = two_factory(arr)
|
|
51
|
+
elif arr.shape == (3,) and vector_factory is not None:
|
|
52
|
+
result = vector_factory(arr)
|
|
53
|
+
elif arr.shape == (3, 3) and base_factory is not None:
|
|
54
|
+
result = base_factory(arr)
|
|
55
|
+
else:
|
|
56
|
+
raise ValueError(f'The {name} tensor has an unrecognized shape {arr.shape}.')
|
|
57
|
+
result = np.asarray(result, dtype=float)
|
|
58
|
+
if not np.all(np.isfinite(result)):
|
|
59
|
+
raise ValueError(f'The {name} tensor contains non-finite values.')
|
|
60
|
+
return result
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _as_sec_tensor(value, name, allow_short=False):
|
|
64
|
+
"""
|
|
65
|
+
Inputs: packed tensor-like value; tensor name; whether the 3x5 layout is
|
|
66
|
+
accepted.
|
|
67
|
+
|
|
68
|
+
Returns: a (3, 3, 3) float array.
|
|
69
|
+
|
|
70
|
+
Notes: None or an empty value gives zeros. A 3x6 input uses the columns
|
|
71
|
+
(xx, yy, zz, yz, xz, xy); a 3x5 input uses (D, E, yz, xz, xy) with the
|
|
72
|
+
traceless diagonal block; an already unpacked (3, 3, 3) stack is accepted
|
|
73
|
+
unchanged, which keeps the method idempotent. Any other shape or
|
|
74
|
+
non-finite values raise ValueError.
|
|
75
|
+
"""
|
|
76
|
+
from .Tensor import unpack_tensor_3x5, unpack_tensor_3x6
|
|
77
|
+
if value is None:
|
|
78
|
+
return np.zeros((3, 3, 3))
|
|
79
|
+
arr = np.asarray(value, dtype=float)
|
|
80
|
+
if arr.size == 0:
|
|
81
|
+
return np.zeros((3, 3, 3))
|
|
82
|
+
if arr.shape == (3, 3, 3):
|
|
83
|
+
stack = arr
|
|
84
|
+
elif arr.shape == (3, 6):
|
|
85
|
+
stack = unpack_tensor_3x6(arr)
|
|
86
|
+
elif allow_short and arr.shape == (3, 5):
|
|
87
|
+
stack = unpack_tensor_3x5(arr)
|
|
88
|
+
else:
|
|
89
|
+
expected = '(3, 6) or (3, 5)' if allow_short else '(3, 6)'
|
|
90
|
+
raise ValueError(f'{name} must have shape {expected}.')
|
|
91
|
+
if not np.all(np.isfinite(stack)):
|
|
92
|
+
raise ValueError(f'{name} contains non-finite values.')
|
|
93
|
+
return stack
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class Spin:
|
|
97
|
+
"""A spin centre with its tensors and Hamiltonian state."""
|
|
98
|
+
|
|
99
|
+
def __init__(self, S, I):
|
|
100
|
+
self.name = 'Spin'
|
|
101
|
+
self.S = S
|
|
102
|
+
self.I = I
|
|
103
|
+
self.g = np.zeros(3)
|
|
104
|
+
self.D = np.zeros((3, 3))
|
|
105
|
+
self.A = np.zeros(3)
|
|
106
|
+
self.dg = np.zeros(3)
|
|
107
|
+
self.dD = np.zeros((3, 3))
|
|
108
|
+
self.dA = np.zeros(3)
|
|
109
|
+
self.B2 = np.zeros(5)
|
|
110
|
+
self.B4 = np.zeros(9)
|
|
111
|
+
self.B6 = np.zeros(13)
|
|
112
|
+
self.g1 = np.zeros((3, 3))
|
|
113
|
+
self.D1 = np.zeros((3, 3))
|
|
114
|
+
self.A1 = np.zeros((3, 3))
|
|
115
|
+
self.dg1 = np.zeros((3, 3))
|
|
116
|
+
self.dD1 = np.zeros((3, 3))
|
|
117
|
+
self.dA1 = np.zeros((3, 3))
|
|
118
|
+
self.T = np.zeros((3, 6))
|
|
119
|
+
self.R = np.zeros((3, 6))
|
|
120
|
+
self.F = np.zeros((3, 6))
|
|
121
|
+
self.Tx = np.zeros((3, 3))
|
|
122
|
+
self.Ty = np.zeros((3, 3))
|
|
123
|
+
self.Tz = np.zeros((3, 3))
|
|
124
|
+
self.Rx = np.zeros((3, 3))
|
|
125
|
+
self.Ry = np.zeros((3, 3))
|
|
126
|
+
self.Rz = np.zeros((3, 3))
|
|
127
|
+
self.Fx = np.zeros((3, 3))
|
|
128
|
+
self.Fy = np.zeros((3, 3))
|
|
129
|
+
self.Fz = np.zeros((3, 3))
|
|
130
|
+
self.Tx1 = np.zeros((3, 3))
|
|
131
|
+
self.Ty1 = np.zeros((3, 3))
|
|
132
|
+
self.Tz1 = np.zeros((3, 3))
|
|
133
|
+
self.Rx1 = np.zeros((3, 3))
|
|
134
|
+
self.Ry1 = np.zeros((3, 3))
|
|
135
|
+
self.Rz1 = np.zeros((3, 3))
|
|
136
|
+
self.Fx1 = np.zeros((3, 3))
|
|
137
|
+
self.Fy1 = np.zeros((3, 3))
|
|
138
|
+
self.Fz1 = np.zeros((3, 3))
|
|
139
|
+
self.total_Level = int((2 * self.S + 1) * (2 * self.I + 1))
|
|
140
|
+
self.H_initial = np.zeros((self.total_Level, self.total_Level))
|
|
141
|
+
self.H_Einitial = np.zeros((self.total_Level, self.total_Level))
|
|
142
|
+
self.H_total = np.zeros((self.total_Level, self.total_Level))
|
|
143
|
+
self.H_g_grad = None
|
|
144
|
+
self.H_T_grad = None
|
|
145
|
+
self.H_dg_grad = None
|
|
146
|
+
self.H_delta_const = None
|
|
147
|
+
|
|
148
|
+
self.tensor_orientation = None
|
|
149
|
+
self.Etensor_orientation = None
|
|
150
|
+
self.R_tf2lf = np.eye(3)
|
|
151
|
+
self.R_tf2lf_rotated = np.eye(3)
|
|
152
|
+
self.R_etf2lf = np.eye(3)
|
|
153
|
+
self.R_etf2lf_rotated = np.eye(3)
|
|
154
|
+
|
|
155
|
+
def clone(self):
|
|
156
|
+
"""
|
|
157
|
+
Inputs: none.
|
|
158
|
+
|
|
159
|
+
Returns: a deep copy, used by parallel tasks to isolate mutable state.
|
|
160
|
+
"""
|
|
161
|
+
from copy import deepcopy
|
|
162
|
+
return deepcopy(self)
|
|
163
|
+
|
|
164
|
+
def identity_tensor(self, crystal_orientation=np.eye(3), molecular_orientation=np.eye(3)):
|
|
165
|
+
"""
|
|
166
|
+
Inputs: crystal orientation and molecular orientation.
|
|
167
|
+
|
|
168
|
+
Returns: nothing; g, D, A, the coupling tensors and their orientations
|
|
169
|
+
are validated and normalized in place.
|
|
170
|
+
|
|
171
|
+
Notes: a scalar, 3-vector or 3x3 tensor is accepted for g, A and the
|
|
172
|
+
modulation amplitudes. A scalar D is treated as the axial case
|
|
173
|
+
(D, E = 0); a (D, E) pair, a 3-vector or a 3x3 tensor is also accepted.
|
|
174
|
+
D is cleared for S = 1/2 and A for I = 0. T and F accept the 3x6
|
|
175
|
+
packed layout (or are empty). R accepts the 3x6 layout or a 3x5 layout
|
|
176
|
+
whose columns are (D, E, yz, xz, xy) for the three electric-field
|
|
177
|
+
directions, with the traceless diagonal block
|
|
178
|
+
(-D/3 + E, -D/3 - E, 2D/3). T, R and F are stored as (3, 3, 3) stacks
|
|
179
|
+
and the component matrices Tx..Fz must be 3x3.
|
|
180
|
+
B2^0/B2^2 duplicate the D tensor and cannot be given together with a
|
|
181
|
+
nonzero D. Unrecognized shapes raise ValueError instead of being
|
|
182
|
+
silently dropped.
|
|
183
|
+
"""
|
|
184
|
+
from .Tensor import Dtensor
|
|
185
|
+
if not np.isscalar(self.S) or self.S <= 0:
|
|
186
|
+
raise ValueError("S must be a positive spin quantum number.")
|
|
187
|
+
if not np.isscalar(self.I) or self.I < 0:
|
|
188
|
+
raise ValueError("I must be a non-negative spin quantum number.")
|
|
189
|
+
|
|
190
|
+
self.B2 = np.asarray(self.B2, dtype=float)
|
|
191
|
+
self.B4 = np.asarray(self.B4, dtype=float)
|
|
192
|
+
self.B6 = np.asarray(self.B6, dtype=float)
|
|
193
|
+
if self.B2.size != 5:
|
|
194
|
+
raise ValueError("B2 must contain exactly 5 elements (q = -2 ... 2).")
|
|
195
|
+
if self.B4.size != 9:
|
|
196
|
+
raise ValueError("B4 must contain exactly 9 elements (q = -4 ... 4).")
|
|
197
|
+
if self.B6.size != 13:
|
|
198
|
+
raise ValueError("B6 must contain exactly 13 elements (q = -6 ... 6).")
|
|
199
|
+
|
|
200
|
+
self.g = _as_matrix(self.g, 'g', allow_scalar=True,
|
|
201
|
+
scalar_factory=lambda x: x * np.eye(3),
|
|
202
|
+
vector_factory=np.diag,
|
|
203
|
+
base_factory=lambda x: x)
|
|
204
|
+
|
|
205
|
+
self.T = _as_sec_tensor(self.T, 'T')
|
|
206
|
+
self.R = _as_sec_tensor(self.R, 'R', allow_short=True)
|
|
207
|
+
self.F = _as_sec_tensor(self.F, 'F')
|
|
208
|
+
if self.T.any():
|
|
209
|
+
self.Tx, self.Ty, self.Tz = self.T[0], self.T[1], self.T[2]
|
|
210
|
+
if self.R.any():
|
|
211
|
+
self.Rx, self.Ry, self.Rz = self.R[0], self.R[1], self.R[2]
|
|
212
|
+
if self.F.any():
|
|
213
|
+
self.Fx, self.Fy, self.Fz = self.F[0], self.F[1], self.F[2]
|
|
214
|
+
|
|
215
|
+
for name in ('Tx', 'Ty', 'Tz', 'Rx', 'Ry', 'Rz', 'Fx', 'Fy', 'Fz'):
|
|
216
|
+
value = np.asarray(getattr(self, name), dtype=float)
|
|
217
|
+
if value.shape != (3, 3):
|
|
218
|
+
raise ValueError(f'{name} must be a 3x3 matrix.')
|
|
219
|
+
setattr(self, name, value)
|
|
220
|
+
|
|
221
|
+
if self.S == 1 / 2:
|
|
222
|
+
had_zfs = any(_array_any(value) for value in
|
|
223
|
+
(self.D, self.Rx, self.Ry, self.Rz,
|
|
224
|
+
self.B2, self.B4, self.B6))
|
|
225
|
+
self.D = np.zeros((3, 3))
|
|
226
|
+
self.Rx = np.zeros((3, 3))
|
|
227
|
+
self.Ry = np.zeros((3, 3))
|
|
228
|
+
self.Rz = np.zeros((3, 3))
|
|
229
|
+
self.B2 = np.zeros(5)
|
|
230
|
+
self.B4 = np.zeros(9)
|
|
231
|
+
self.B6 = np.zeros(13)
|
|
232
|
+
if had_zfs:
|
|
233
|
+
logging.warning('S = 1/2: zero-field splitting is not applicable and has been cleared.')
|
|
234
|
+
else:
|
|
235
|
+
self.D = _as_matrix(self.D, 'D', allow_scalar=True,
|
|
236
|
+
scalar_factory=lambda x: Dtensor(x, 0.0),
|
|
237
|
+
vector_factory=np.diag,
|
|
238
|
+
base_factory=lambda x: x,
|
|
239
|
+
two_factory=lambda x: Dtensor(x[0], x[1]))
|
|
240
|
+
|
|
241
|
+
if not (self.Tx.any() or self.Ty.any() or self.Tz.any()
|
|
242
|
+
or self.Rx.any() or self.Ry.any() or self.Rz.any()
|
|
243
|
+
or self.Fx.any() or self.Fy.any() or self.Fz.any()):
|
|
244
|
+
logging.debug('No electric-field coupling tensor is set.')
|
|
245
|
+
|
|
246
|
+
if self.D.any():
|
|
247
|
+
conflicts = []
|
|
248
|
+
if self.B2[2] != 0:
|
|
249
|
+
conflicts.append('B2[2] (B2^0)')
|
|
250
|
+
if self.B2[4] != 0:
|
|
251
|
+
conflicts.append('B2[4] (B2^2)')
|
|
252
|
+
if conflicts:
|
|
253
|
+
raise ValueError('B2^0/B2^2 are equivalent to the D tensor, and cannot be '
|
|
254
|
+
'defined together with a non-zero D: ' + ', '.join(conflicts) + '.')
|
|
255
|
+
|
|
256
|
+
if self.I == 0:
|
|
257
|
+
had_hyperfine = any(_array_any(value) for value in
|
|
258
|
+
(self.A, self.Fx, self.Fy, self.Fz))
|
|
259
|
+
self.A = np.zeros((3, 3))
|
|
260
|
+
self.Fx = np.zeros((3, 3))
|
|
261
|
+
self.Fy = np.zeros((3, 3))
|
|
262
|
+
self.Fz = np.zeros((3, 3))
|
|
263
|
+
if had_hyperfine:
|
|
264
|
+
logging.warning('I = 0: hyperfine coupling is not applicable and has been cleared.')
|
|
265
|
+
else:
|
|
266
|
+
self.A = _as_matrix(self.A, 'A', allow_scalar=True,
|
|
267
|
+
scalar_factory=lambda x: x * np.eye(3),
|
|
268
|
+
vector_factory=np.diag,
|
|
269
|
+
base_factory=lambda x: x)
|
|
270
|
+
|
|
271
|
+
self.dg = _as_matrix(self.dg, 'Delta g', allow_scalar=True,
|
|
272
|
+
scalar_factory=lambda x: x * np.eye(3),
|
|
273
|
+
vector_factory=np.diag,
|
|
274
|
+
base_factory=lambda x: x)
|
|
275
|
+
if self.S == 1 / 2:
|
|
276
|
+
self.dD = np.zeros((3, 3))
|
|
277
|
+
else:
|
|
278
|
+
self.dD = _as_matrix(self.dD, 'Delta D', allow_scalar=True,
|
|
279
|
+
scalar_factory=lambda x: Dtensor(x, 0.0),
|
|
280
|
+
vector_factory=np.diag,
|
|
281
|
+
base_factory=lambda x: x,
|
|
282
|
+
two_factory=lambda x: Dtensor(x[0], x[1]))
|
|
283
|
+
if self.I == 0:
|
|
284
|
+
self.dA = np.zeros((3, 3))
|
|
285
|
+
else:
|
|
286
|
+
self.dA = _as_matrix(self.dA, 'Delta A', allow_scalar=True,
|
|
287
|
+
scalar_factory=lambda x: x * np.eye(3),
|
|
288
|
+
vector_factory=np.diag,
|
|
289
|
+
base_factory=lambda x: x)
|
|
290
|
+
|
|
291
|
+
from .Eular2Rot import resolve_orientation
|
|
292
|
+
R_sf2lf = resolve_orientation(crystal_orientation)
|
|
293
|
+
R_mf2sf = resolve_orientation(molecular_orientation)
|
|
294
|
+
R_tf2mf = resolve_orientation(self.tensor_orientation)
|
|
295
|
+
if self.Etensor_orientation is None:
|
|
296
|
+
R_etf2mf = R_tf2mf
|
|
297
|
+
else:
|
|
298
|
+
R_etf2mf = resolve_orientation(self.Etensor_orientation)
|
|
299
|
+
|
|
300
|
+
self.R_tf2lf = R_sf2lf @ (R_mf2sf @ R_tf2mf)
|
|
301
|
+
self.R_etf2lf = R_sf2lf @ (R_mf2sf @ R_etf2mf)
|
|
302
|
+
self.R_tf2lf_rotated = self.R_tf2lf
|
|
303
|
+
self.R_etf2lf_rotated = self.R_etf2lf
|
|
304
|
+
|
|
305
|
+
def update_Btensor(self):
|
|
306
|
+
"""
|
|
307
|
+
Inputs: none.
|
|
308
|
+
|
|
309
|
+
Returns: nothing; the rotated tensors and field gradients are updated.
|
|
310
|
+
|
|
311
|
+
Notes: call this before assembling a Hamiltonian. For the first angle
|
|
312
|
+
or a single-crystal one-side simulation the rotation is the identity.
|
|
313
|
+
"""
|
|
314
|
+
R = self.R_tf2lf_rotated
|
|
315
|
+
self.g1 = R @ self.g @ R.T
|
|
316
|
+
self.D1 = R @ self.D @ R.T
|
|
317
|
+
self.A1 = R @ self.A @ R.T
|
|
318
|
+
self.dg1 = R @ self.dg @ R.T
|
|
319
|
+
self.dD1 = R @ self.dD @ R.T
|
|
320
|
+
self.dA1 = R @ self.dA @ R.T
|
|
321
|
+
|
|
322
|
+
from .Team_Zeeman import H_Zeeman
|
|
323
|
+
self.H_g_grad = H_Zeeman(1.0, self.g1, self.S, self.I)
|
|
324
|
+
self.H_dg_grad = H_Zeeman(1.0, self.dg1, self.S, self.I)
|
|
325
|
+
self.H_delta_const = np.zeros((self.total_Level, self.total_Level))
|
|
326
|
+
if self.dD1.any():
|
|
327
|
+
from .Team_ZFS import H_ZFS
|
|
328
|
+
self.H_delta_const = self.H_delta_const + H_ZFS(self.dD1, self.S, self.I)
|
|
329
|
+
if self.dA1.any():
|
|
330
|
+
from .Team_Hyperfine import H_Hyperfine
|
|
331
|
+
self.H_delta_const = self.H_delta_const + H_Hyperfine(self.dA1, self.S, self.I)
|
|
332
|
+
|
|
333
|
+
def update_H_initial(self):
|
|
334
|
+
"""
|
|
335
|
+
Inputs: none.
|
|
336
|
+
|
|
337
|
+
Returns: nothing; the field-independent Hamiltonian is stored in
|
|
338
|
+
``H_initial``.
|
|
339
|
+
"""
|
|
340
|
+
self.H_initial = np.zeros((self.total_Level, self.total_Level))
|
|
341
|
+
if self.A1.any():
|
|
342
|
+
from .Team_Hyperfine import H_Hyperfine
|
|
343
|
+
self.H_initial = self.H_initial + H_Hyperfine(self.A1, self.S, self.I)
|
|
344
|
+
if self.D1.any():
|
|
345
|
+
from .Team_ZFS import H_ZFS
|
|
346
|
+
self.H_initial = self.H_initial + H_ZFS(self.D1, self.S, self.I)
|
|
347
|
+
if self.B2.any() or self.B4.any() or self.B6.any():
|
|
348
|
+
from .Team_ZFS_HighOrder import B_arrays_to_dict, H_ZFS_HighOrder
|
|
349
|
+
B = B_arrays_to_dict(self.B2, self.B4, self.B6)
|
|
350
|
+
self.H_initial = self.H_initial + H_ZFS_HighOrder(B, self.S, self.I, R=self.R_tf2lf_rotated.T)
|
|
351
|
+
|
|
352
|
+
def modulate_B(self, Bz, Bmod, modulation_symbol='positive'):
|
|
353
|
+
"""
|
|
354
|
+
Inputs: swept field Bz (G); modulation amplitude Bmod (G);
|
|
355
|
+
modulation_symbol ("positive" or "negative").
|
|
356
|
+
|
|
357
|
+
Returns: nothing; ``H_total`` is set.
|
|
358
|
+
|
|
359
|
+
Notes: the Hamiltonian is linear in the field, so the Zeeman term is
|
|
360
|
+
built from the cached gradient ``H_g_grad``.
|
|
361
|
+
"""
|
|
362
|
+
if Bmod == 0:
|
|
363
|
+
raise ValueError("The modulated magnetic field is zero, the procedure will be closed!")
|
|
364
|
+
if modulation_symbol == 'negative':
|
|
365
|
+
self.H_total = self.H_initial + (Bz - Bmod) * self.H_g_grad
|
|
366
|
+
elif modulation_symbol == 'positive':
|
|
367
|
+
self.H_total = self.H_initial + (Bz + Bmod) * self.H_g_grad
|
|
368
|
+
else:
|
|
369
|
+
raise ValueError('An unknown error has occurred. The modulated magnetic field '
|
|
370
|
+
'is neither positive nor negative.')
|
|
371
|
+
|
|
372
|
+
def modulate_param(self, Bz, modulation_symbol='positive'):
|
|
373
|
+
"""
|
|
374
|
+
Inputs: swept field Bz (G); modulation_symbol ("positive" or
|
|
375
|
+
"negative").
|
|
376
|
+
|
|
377
|
+
Returns: nothing; ``H_total`` is set.
|
|
378
|
+
|
|
379
|
+
Notes: dg/dD/dA are added as the modulation term; only nonzero parts
|
|
380
|
+
contribute.
|
|
381
|
+
"""
|
|
382
|
+
if modulation_symbol == 'positive':
|
|
383
|
+
sign = 1
|
|
384
|
+
elif modulation_symbol == 'negative':
|
|
385
|
+
sign = -1
|
|
386
|
+
else:
|
|
387
|
+
raise ValueError('An unknown error has occurred. The modulated parameter is neither positive nor negative.')
|
|
388
|
+
self.H_total = (self.H_initial + sign * self.H_delta_const
|
|
389
|
+
+ Bz * self.H_g_grad + sign * Bz * self.H_dg_grad)
|
|
390
|
+
|
|
391
|
+
def update_Etensor(self, E):
|
|
392
|
+
"""
|
|
393
|
+
Inputs: electric-field vector E.
|
|
394
|
+
|
|
395
|
+
Returns: nothing; the frame-rotated coupling tensors and the T-term
|
|
396
|
+
field gradient are updated.
|
|
397
|
+
"""
|
|
398
|
+
Rrot_etf2lf = self.R_etf2lf_rotated
|
|
399
|
+
|
|
400
|
+
RRR = np.einsum('ip,jq,kr,pqr->ijk', Rrot_etf2lf, Rrot_etf2lf, Rrot_etf2lf,
|
|
401
|
+
[self.Rx, self.Ry, self.Rz])
|
|
402
|
+
self.Rx1 = E[0] * RRR[0][:][:]
|
|
403
|
+
self.Ry1 = E[1] * RRR[1][:][:]
|
|
404
|
+
self.Rz1 = E[2] * RRR[2][:][:]
|
|
405
|
+
|
|
406
|
+
FFF = np.einsum('ip,jq,kr,pqr->ijk', Rrot_etf2lf, Rrot_etf2lf, Rrot_etf2lf,
|
|
407
|
+
[self.Fx, self.Fy, self.Fz])
|
|
408
|
+
self.Fx1 = E[0] * FFF[0][:][:]
|
|
409
|
+
self.Fy1 = E[1] * FFF[1][:][:]
|
|
410
|
+
self.Fz1 = E[2] * FFF[2][:][:]
|
|
411
|
+
|
|
412
|
+
TTT = np.einsum('ip,jq,kr,pqr->ijk', Rrot_etf2lf, Rrot_etf2lf, Rrot_etf2lf,
|
|
413
|
+
[self.Tx, self.Ty, self.Tz])
|
|
414
|
+
self.Tx1 = E[0] * TTT[0][:][:]
|
|
415
|
+
self.Ty1 = E[1] * TTT[1][:][:]
|
|
416
|
+
self.Tz1 = E[2] * TTT[2][:][:]
|
|
417
|
+
|
|
418
|
+
from .ETeam_Zeeman import H_EMod_T
|
|
419
|
+
self.H_T_grad = H_EMod_T(1.0, self.Tx1, self.Ty1, self.Tz1, self.S, self.I)
|
|
420
|
+
|
|
421
|
+
def modulate_E_initial(self, E1):
|
|
422
|
+
"""
|
|
423
|
+
Inputs: electric-field vector E1.
|
|
424
|
+
|
|
425
|
+
Returns: nothing; the field-independent electric modulation term is
|
|
426
|
+
stored in ``H_Einitial``.
|
|
427
|
+
"""
|
|
428
|
+
from .ETeam_Hyperfine import H_EMod_F
|
|
429
|
+
from .ETeam_ZFS import H_EMod_R
|
|
430
|
+
self.H_Einitial = np.zeros((self.total_Level, self.total_Level))
|
|
431
|
+
|
|
432
|
+
found = False
|
|
433
|
+
if self.Rx1.any() or self.Ry1.any() or self.Rz1.any():
|
|
434
|
+
self.H_Einitial = self.H_Einitial + H_EMod_R(self.Rx1, self.Ry1, self.Rz1, self.S, self.I)
|
|
435
|
+
found = True
|
|
436
|
+
if self.Fx1.any() or self.Fy1.any() or self.Fz1.any():
|
|
437
|
+
self.H_Einitial = self.H_Einitial + H_EMod_F(self.Fx1, self.Fy1, self.Fz1, self.S, self.I)
|
|
438
|
+
found = True
|
|
439
|
+
if self.Tx1.any() or self.Ty1.any() or self.Tz1.any():
|
|
440
|
+
found = True
|
|
441
|
+
if not found:
|
|
442
|
+
logging.error("Electric field parameter(T,R,F) not found, please reconfirm entry!")
|
|
443
|
+
|
|
444
|
+
def modulate_E_T(self, Bz, E, modulation_symbol='positive'):
|
|
445
|
+
"""
|
|
446
|
+
Inputs: swept field Bz (G); electric-field vector E;
|
|
447
|
+
modulation_symbol ("positive" or "negative").
|
|
448
|
+
|
|
449
|
+
Returns: nothing; ``H_total`` is set.
|
|
450
|
+
"""
|
|
451
|
+
if E[0] == 0 and E[1] == 0 and E[2] == 0:
|
|
452
|
+
raise ValueError("The modulated electric field is zero, the procedure will be closed!")
|
|
453
|
+
|
|
454
|
+
if modulation_symbol == 'negative':
|
|
455
|
+
self.H_total = (self.H_initial - self.H_Einitial
|
|
456
|
+
+ Bz * self.H_g_grad - Bz * self.H_T_grad)
|
|
457
|
+
elif modulation_symbol == 'positive':
|
|
458
|
+
self.H_total = (self.H_initial + self.H_Einitial
|
|
459
|
+
+ Bz * self.H_g_grad + Bz * self.H_T_grad)
|
|
460
|
+
else:
|
|
461
|
+
raise ValueError('An unknown error has occurred. The modulated electric field '
|
|
462
|
+
'is neither positive nor negative.')
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Single-crystal rotation spectra.
|
|
2
|
+
|
|
3
|
+
The crystal is turned about the laboratory x axis; the initial orientation is
|
|
4
|
+
given by the spin's crystal orientation. Each angle is an independent
|
|
5
|
+
spectrum, computed in parallel over (spin index, angle) tasks.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from math import pi
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
|
|
12
|
+
from .Parallel import parallel_map
|
|
13
|
+
from .Rodrigues_Rotation import rotation_matrix
|
|
14
|
+
from .Spec_Oneside import spec_oneside
|
|
15
|
+
|
|
16
|
+
_worker_spins = None
|
|
17
|
+
_worker_spec = None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _init_worker(spins, spec):
|
|
21
|
+
global _worker_spins, _worker_spec
|
|
22
|
+
_worker_spins = spins
|
|
23
|
+
_worker_spec = spec
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _angle_task(spin_angle):
|
|
27
|
+
spin_idx, angle = spin_angle
|
|
28
|
+
return _one_angle(_worker_spins[spin_idx], _worker_spec, angle)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _one_angle(spin, spec, angle):
|
|
32
|
+
"""
|
|
33
|
+
Inputs: Spin and Spec objects; rotation angle in degrees.
|
|
34
|
+
|
|
35
|
+
Returns: the spectrum at that angle.
|
|
36
|
+
|
|
37
|
+
Notes: spin and spec are copied so that parallel workers never share
|
|
38
|
+
mutable state.
|
|
39
|
+
"""
|
|
40
|
+
spin = spin.clone()
|
|
41
|
+
spec = spec.clone()
|
|
42
|
+
radian = angle * pi / 180
|
|
43
|
+
axis = np.array([1, 0, 0])
|
|
44
|
+
Rotangle = rotation_matrix(axis, radian)
|
|
45
|
+
spin.R_tf2lf_rotated = Rotangle @ spin.R_tf2lf
|
|
46
|
+
spin.R_etf2lf_rotated = Rotangle @ spin.R_etf2lf
|
|
47
|
+
if spec.modtype == 'Emod':
|
|
48
|
+
spec.E1 = spec.Emod * np.dot(Rotangle, spec.Edirection)
|
|
49
|
+
return spec_oneside(spin, spec)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def crystal_rotation(spins, spec, angnum, parallel=True):
|
|
53
|
+
"""
|
|
54
|
+
Inputs: list of Spin objects; Spec object; number of angles; whether to
|
|
55
|
+
use a process pool.
|
|
56
|
+
|
|
57
|
+
Returns: an array of shape (len(spins), angnum, specpoints).
|
|
58
|
+
|
|
59
|
+
Notes: tasks are (spin index, angle) pairs, so the parallel load does not
|
|
60
|
+
depend on the number of spins. The angles are evenly spaced over
|
|
61
|
+
``spec.anglerange``.
|
|
62
|
+
"""
|
|
63
|
+
n_spins = len(spins)
|
|
64
|
+
anglerange = np.linspace(spec.anglerange[0], spec.anglerange[1], angnum)
|
|
65
|
+
tasks = [(si, angle) for si in range(n_spins) for angle in anglerange]
|
|
66
|
+
if parallel:
|
|
67
|
+
rows = parallel_map(_angle_task, tasks, initializer=_init_worker,
|
|
68
|
+
initargs=(spins, spec), max_workers=spec.max_workers)
|
|
69
|
+
else:
|
|
70
|
+
rows = (_one_angle(spins[si], spec, angle) for si, angle in tasks)
|
|
71
|
+
spectra = np.zeros((n_spins, angnum, spec.specpoints))
|
|
72
|
+
for k, ((si, angle), row) in enumerate(zip(tasks, rows)):
|
|
73
|
+
spectra[si, k % angnum, :] = row
|
|
74
|
+
return spectra
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Electric-field modulation of the hyperfine term through an F tensor."""
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
from .Spin_Operators import Ix_get, Iy_get, Iz_get, Sx_get, Sy_get, Sz_get
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def H_EMod_F(Fx, Fy, Fz, S, I):
|
|
9
|
+
"""
|
|
10
|
+
Inputs: 3x3 tensors Fx, Fy, Fz, the derivatives of A with respect to the
|
|
11
|
+
electric-field components along x, y, z; electron spin S; nuclear spin I.
|
|
12
|
+
|
|
13
|
+
Returns: the F-tensor part of the electric-field modulated hyperfine term.
|
|
14
|
+
"""
|
|
15
|
+
S_ops = (Sx_get(S, I), Sy_get(S, I), Sz_get(S, I))
|
|
16
|
+
I_ops = (Ix_get(S, I), Iy_get(S, I), Iz_get(S, I))
|
|
17
|
+
tensors = (np.asarray(Fx, dtype=float), np.asarray(Fy, dtype=float), np.asarray(Fz, dtype=float))
|
|
18
|
+
|
|
19
|
+
H = np.zeros_like(S_ops[0])
|
|
20
|
+
for F in tensors:
|
|
21
|
+
for i in range(3):
|
|
22
|
+
for j in range(3):
|
|
23
|
+
if F[i, j] != 0.0:
|
|
24
|
+
H = H + F[i, j] * (S_ops[i] @ I_ops[j])
|
|
25
|
+
return H
|
dimspin/ETeam_ZFS.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Electric-field modulation of the zero-field splitting term through an R tensor."""
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
from .Spin_Operators import Sx_get, Sy_get, Sz_get
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def H_EMod_R(Rx, Ry, Rz, S, I):
|
|
9
|
+
"""
|
|
10
|
+
Inputs: 3x3 tensors Rx, Ry, Rz, the derivatives of D with respect to the
|
|
11
|
+
electric-field components along x, y, z; electron spin S; nuclear spin I.
|
|
12
|
+
|
|
13
|
+
Returns: the R-tensor part of the electric-field modulated ZFS term.
|
|
14
|
+
"""
|
|
15
|
+
S_ops = (Sx_get(S, I), Sy_get(S, I), Sz_get(S, I))
|
|
16
|
+
tensors = (np.asarray(Rx, dtype=float), np.asarray(Ry, dtype=float), np.asarray(Rz, dtype=float))
|
|
17
|
+
|
|
18
|
+
H = np.zeros_like(S_ops[0])
|
|
19
|
+
for R in tensors:
|
|
20
|
+
for i in range(3):
|
|
21
|
+
for j in range(3):
|
|
22
|
+
if R[i, j] != 0.0:
|
|
23
|
+
H = H + R[i, j] * (S_ops[i] @ S_ops[j])
|
|
24
|
+
return H
|
dimspin/ETeam_Zeeman.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Electric-field modulation of the Zeeman term through a T tensor."""
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
from .Spin_Operators import Sx_get, Sy_get, Sz_get
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def H_EMod_T(Bz, Tx, Ty, Tz, S, I):
|
|
9
|
+
"""
|
|
10
|
+
Inputs: field Bz (G); 3x3 tensors Tx, Ty, Tz, the derivatives of g with
|
|
11
|
+
respect to the electric-field components along x, y, z; electron spin S;
|
|
12
|
+
nuclear spin I.
|
|
13
|
+
|
|
14
|
+
Returns: the T-tensor part of the electric-field modulated Zeeman term.
|
|
15
|
+
|
|
16
|
+
Notes: the magnetic field is along z only, so the third column of each
|
|
17
|
+
tensor enters and the other columns do not contribute.
|
|
18
|
+
"""
|
|
19
|
+
S_ops = (Sx_get(S, I), Sy_get(S, I), Sz_get(S, I))
|
|
20
|
+
tensors = (np.asarray(Tx, dtype=float), np.asarray(Ty, dtype=float), np.asarray(Tz, dtype=float))
|
|
21
|
+
|
|
22
|
+
H = np.zeros_like(S_ops[0])
|
|
23
|
+
for T in tensors:
|
|
24
|
+
for i in range(3):
|
|
25
|
+
if T[i, 2] != 0.0:
|
|
26
|
+
H = H + T[i, 2] * S_ops[i]
|
|
27
|
+
return Bz * H
|