-
Notifications
You must be signed in to change notification settings - Fork 0
/
zaltys_so.py
398 lines (309 loc) · 12.5 KB
/
zaltys_so.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
"""Helper functions pertaining to States and Operators needed to run zaltys.
"""
import numpy as np
from math import sqrt
import scipy.sparse as sps
from scipy.special import genlaguerre
from math import exp
from mpmath import rf as rising_factorial
# Constants
SPIN_UP = 1
SPIN_DOWN = -1
CUTOFF_PRECISION = 1e-6
def generate_states(ee_cutoff):
"""Generate states | nx , ny , spin > up to some energy cutoff.
Args:
ee_cutoff: Energy cutoff up to (and including) which the states are
generated.
Returns:
A list [ nx_list, ny_list, spin_list ] where a state
| nx, ny, spin > is e.g. | nx_list[3], ny_list[3], spin_list[3] >
"""
nx_list = []
ny_list = []
spin_list = []
for ee in range(1, ee_cutoff + 1):
for nx in range(0, ee):
ny = ee - nx - 1
for spin in [SPIN_UP, SPIN_DOWN]:
nx_list.append(nx)
ny_list.append(ny)
spin_list.append(spin)
return [nx_list, ny_list, spin_list]
def state_index(state):
"""Given a state vector [nx, ny, spin] return its index in the array
of states.
Args:
state: The input state vector.
Returns:
An integer index.
"""
ee = state[0] + state[1] + 1
index = ee * (ee - 1) + state[0] * 2
if state[2] == SPIN_DOWN:
index = index + 1
return index
def check_indexing(nx_list, ny_list, spin_list):
"""Check if the indexing is correct.
The ordering is as follows. Lower nx precede higher nx. Spin up
precedes spin down.
This method does not return anything, prints out the result.
Args:
nx_list: List of nx's, principal quantum numbers with respect to the x
direction.
ny_list: List of ny's.
spin_list: List of spins, 1 for up and -1 for down.
"""
if len(nx_list) != len(ny_list) or len(nx_list) != len(spin_list):
print('Error: the lists are of different lengths.')
return
for ii in range(0, len(nx_list)):
if ii != state_index([nx_list[ii], ny_list[ii], spin_list[ii]]):
print('Error: state_index error at index {}.').format(ii)
return
print('State indices are correct.')
def generate_rashba_hamiltonian(v, ee_cutoff, state_list):
"""Construct the Rashba Hamiltonian as a sparse matrix in the Cartesian
harmonic oscillator basis.
Args:
v: Dimensionless Rashba spin-orbit coupling strength in the
Hamiltonian.
ee_cutoff: Energy cutoff up to (and including) which the states were
generated by generate_states.
state_list: List of principal and spin quantum numbers, cf.
generate_states.
Return:
A sparse matrix in the Compressed Sparse Row (CSR) format.
"""
# TODO: checking boundary conditions explicitly for now;
# it is probably possible to optimize that
[nx_list, ny_list, spin_list] = state_list
list_l = [] # left index
list_r = [] # right index
list_e = [] # entry
diag_index = []
diag_ho_ee = [] # entry on the diagonal, which corresponds to the harmonic
# oscillator energy
# left index
for li in range(0, len(nx_list)):
# Filling the diagonal with energies
diag_index.append(li)
ee = nx_list[li] + ny_list[li] + 1
diag_ho_ee.append(ee)
# Filling the SOC part of the Hamiltonian
if li % 2 == 0: # if (lv[2] == spinUp)
if ee < ee_cutoff:
list_l.append(li)
# nx == nx', ny == ny' + 1
ri = state_index([nx_list[li], ny_list[li] + 1, -1])
list_r.append(ri)
list_e.append(-1j * (v / np.sqrt(2)) * sqrt(ny_list[li] + 1))
if ee > 1:
if ny_list[li] >= 1:
list_l.append(li)
# nx == nx', ny == ny' - 1
ri = state_index([nx_list[li], ny_list[li] - 1, -1])
list_r.append(ri)
list_e.append(1j * (v / np.sqrt(2)) * sqrt(ny_list[li]))
if ee < ee_cutoff:
list_l.append(li)
# nx == nx' + 1, ny == ny'
ri = state_index([nx_list[li] + 1, ny_list[li], -1])
list_r.append(ri)
list_e.append((v / np.sqrt(2)) * sqrt(nx_list[li] + 1))
if ee > 1:
if nx_list[li] >= 1:
list_l.append(li)
# nx == nx' -1 , ny == ny'
ri = state_index([nx_list[li] - 1, ny_list[li], -1])
list_r.append(ri)
list_e.append(-(v / np.sqrt(2)) * sqrt(nx_list[li]))
else:
if (nx_list[li] + ny_list[li] + 1) < ee_cutoff:
list_l.append(li)
# nx == nx', ny == ny' + 1
ri = state_index([nx_list[li], ny_list[li] + 1, 1])
list_r.append(ri)
list_e.append(-1j * (v / np.sqrt(2)) * sqrt(ny_list[li] + 1))
if (nx_list[li] + ny_list[li] + 1) > 1:
if ny_list[li] >= 1:
list_l.append(li)
# nx == nx', ny == ny' - 1
ri = state_index([nx_list[li], ny_list[li] - 1, 1])
list_r.append(ri)
list_e.append(1j * (v / np.sqrt(2)) * sqrt(ny_list[li]))
# Changes minus sign as compared to above
if (nx_list[li] + ny_list[li] + 1) < ee_cutoff:
list_l.append(li)
# nx == nx' + 1, ny == ny'
ri = state_index([nx_list[li] + 1, ny_list[li], 1])
list_r.append(ri)
list_e.append(-(v / np.sqrt(2)) * sqrt(nx_list[li] + 1))
if (nx_list[li] + ny_list[li] + 1) > 1:
if nx_list[li] >= 1:
list_l.append(li)
# nx == nx' - 1, ny == ny'
ri = state_index([nx_list[li] - 1, ny_list[li], 1])
list_r.append(ri)
list_e.append((v / np.sqrt(2)) * sqrt(nx_list[li]))
H0 = sps.coo_matrix((diag_ho_ee, (diag_index, diag_index)),
shape=(len(nx_list), len(nx_list)))
list_l = np.array(list_l)
list_r = np.array(list_r)
list_e = np.array(list_e)
HR = sps.coo_matrix((list_e, (list_l, list_r)),
shape=(len(nx_list), len(nx_list)))
# returns the CSR format
return H0 + HR
def _o(x0, m, n):
"""Overlap function between |nx> = m and |nx'> = n under translation in the x
direction with the amplitude x0.
Keeping the name indecently short, as this function should not be called
from outside the module.
Args:
x0: translation amplitude.
m, n: principal quantum numbers for harmonic oscillator states
to compute overlap between. Note that only the relevant numbers
(i.e. the ones in x direction without spin) are considered.
Returns:
The overlap amplitude, which is always real.
"""
x0_ = x0 / np.sqrt(2)
ax02 = abs(x0_)**2
if m >= n:
L = genlaguerre(n, m - n)
return (sqrt(1 / rising_factorial(n + 1, m - n)) * (x0_**(m - n))
* exp(- ax02 / 2) * L(ax02))
else:
L = genlaguerre(m, n - m)
return (sqrt(1 / rising_factorial(m + 1, n - m)) * ((-x0_)**(n - m))
* exp(- ax02 / 2) * L(ax02))
def _overlap_lookup(x0, ee_cutoff):
"""The overlap function _o is quite slow, so we precompute its values here.
Args:
x0: translation amplitude.
ee_cutoff: Energy cutoff up to (and including) which the states were
generated by generate_states.
Returns:
A numpy array with overlaps.
"""
lookup_array = np.zeros((ee_cutoff, ee_cutoff))
for i1 in np.arange(0, ee_cutoff):
for i2 in np.arange(0, ee_cutoff):
nowOverlap = _o(x0, i1, i2)
if abs(nowOverlap) > CUTOFF_PRECISION:
lookup_array[i1][i2] = nowOverlap
return lookup_array
def generate_translation_operator(x0, ee_cutoff, state_list):
"""Construct the translation operator as a sparse matrix in the Cartesian
harmonic oscillator basis.
Args:
x0: translation amplitude.
ee_cutoff: Energy cutoff up to (and including) which the states were
generated by generate_states.
state_list: List of principal and spin quantum numbers, cf.
generate_states.
Return:
A sparse matrix in the Compressed Sparse Row (CSR) format.
"""
[nx_list, ny_list, spin_list] = state_list
list_l = [] # left index
list_r = [] # right index
list_e = [] # entry
# Precomputing the overlap lookup matrix for this translation amplitude
lookup_array = _overlap_lookup(x0, ee_cutoff)
# left index
for li in range(0, len(nx_list), 2): # ,2 implies translation for SPIN_UP
nowNx = nx_list[li]
nowNy = ny_list[li]
for otherNx in range(0, ee_cutoff):
if lookup_array[nowNx][otherNx] != 0:
ri = state_index([otherNx, nowNy, SPIN_UP])
if ri < len(nx_list): # Not exceed the energy cutoff
list_l.append(li)
list_r.append(ri)
list_e.append(lookup_array[nowNx][otherNx])
list_l = np.array(list_l)
list_r = np.array(list_r)
list_e = np.array(list_e)
T = sps.coo_matrix((list_e, (list_l, list_r)),
shape=(len(nx_list), len(nx_list)))
# Same overlaps for SPIN_DOWN
list_lD = [x + 1 for x in list_l]
list_rD = [x + 1 for x in list_r]
T = T + sps.coo_matrix((list_e, (list_lD, list_rD)),
shape=(len(nx_list), len(nx_list)))
return T
def generate_x_operator(state_list):
"""Construct the position operator X as a sparse matrix in the Cartesian
harmonic oscillator basis.
Args:
state_list: List of principal and spin quantum numbers, cf.
generate_states.
Return:
A sparse matrix in the Compressed Sparse Row (CSR) format.
"""
[nx_list, ny_list, spin_list] = state_list
list_l = [] # left index
list_r = [] # right index
list_e = [] # entry
# left index
for li in range(0, len(nx_list), 2): # ,2 -> translation for SPIN_UP only
if nx_list[li] > 0:
ri = state_index([nx_list[li] - 1, ny_list[li], SPIN_UP])
list_l.append(li)
list_r.append(ri)
list_e.append(sqrt(nx_list[li] / 2.))
ri = state_index([nx_list[li] + 1, ny_list[li], SPIN_UP])
if ri < len(nx_list): # Not exceed the energy cutoff -- could optimize
list_l.append(li)
list_r.append(ri)
list_e.append(sqrt((1 + nx_list[li]) / 2.))
list_l = np.array(list_l)
list_r = np.array(list_r)
list_e = np.array(list_e)
X = sps.coo_matrix((list_e, (list_l, list_r)),
shape=(len(nx_list), len(nx_list)))
# Same overlaps for SPIN_DOWN
list_lD = [x + 1 for x in list_l]
list_rD = [x + 1 for x in list_r]
X = X + sps.coo_matrix((list_e, (list_lD, list_rD)),
shape=(len(nx_list), len(nx_list)))
return X
def generate_ysz_operator(state_list):
"""Construct the spin dipole operator YSZ as a sparse matrix in the
Cartesian harmonic oscillator basis.
Args:
state_list: List of principal and spin quantum numbers, cf.
generate_states.
Return:
A sparse matrix in the Compressed Sparse Row (CSR) format.
"""
[nx_list, ny_list, spin_list] = state_list
list_l = [] # left index
list_r = [] # right index
list_e = [] # entry
# left index
for li in range(0, len(nx_list), 2):
if ny_list[li] > 0:
ri = state_index([nx_list[li], ny_list[li] - 1, SPIN_UP])
list_l.append(li)
list_r.append(ri)
list_e.append(sqrt(ny_list[li] / 2.))
ri = state_index([nx_list[li], ny_list[li] + 1, SPIN_UP])
if ri < len(nx_list):
list_l.append(li)
list_r.append(ri)
list_e.append(sqrt((1 + ny_list[li]) / 2.))
list_l = np.array(list_l)
list_r = np.array(list_r)
list_e = np.array(list_e)
YSZ = sps.coo_matrix((list_e, (list_l, list_r)),
shape=(len(nx_list), len(nx_list)))
# Same overlaps for spinDown
list_lD = [x + 1 for x in list_l]
list_rD = [x + 1 for x in list_r]
# Note the flipped sign for spinDown
YSZ = YSZ + sps.coo_matrix((-list_e, (list_lD, list_rD)),
shape=(len(nx_list), len(nx_list)))
return YSZ