-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsheet.py
200 lines (162 loc) · 6.74 KB
/
sheet.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
from calc import *
import xyz
from param import param
from units import *
class sheet:
def __init__(self,H_B0,xyz_sheet=None,S=None,do_cache=False):
assert type(H_B0) is dict
assert (0,0) in H_B0
assert type(H_B0[0,0]) is matrix
self.N_orbitals = H_B0[0,0].shape[0]
self.imax = 0
for i0,i1 in H_B0:
assert type(i0) is int
assert type(i1) is int
assert i0 >= 0
assert i0 > 0 or i1 >= 0
self.imax = max(self.imax,i0,i1,-i1)
assert type(H_B0[i0,i1]) is matrix
assert H_B0[i0,i1].shape == (self.N_orbitals,self.N_orbitals)
assert H_B0[i0,i1].dtype == H_B0[0,0].dtype
self.H_B0 = H_B0
self.H = H_B0
if S is not None:
assert type(S) is dict
assert S.keys() == H_B0.keys()
for k in S:
assert type(S[k]) is matrix
assert S[k].shape == (self.N_orbitals,self.N_orbitals)
assert S[k].dtype == S[0,0].dtype
self.S = S
if xyz_sheet is not None:
assert isinstance(xyz_sheet,xyz.sheet)
self.xyz = xyz_sheet
self.latticecoords = None
self.bfield = array((0,0,0))
self.area = cross(self.xyz.period[0],self.xyz.period[1])[2]
self.phase = None
def set_bfield(self,bfield):
import bfield as bf
from copy import deepcopy
assert hasattr(self,'xyz')
bfield = asarray(bfield)
flux = self.area*bfield[2]
Nflux = round(flux/Phi0)
bfield[2] = Nflux * Phi0 / self.area
if any(bfield != self.bfield):
self.bfield = bfield
if sum(array(bfield)**2) == 0:
self.H = self.H_B0
else:
if self.latticecoords is None:
self.latticecoords = [ (dot(at.pos,self.xyz.rzp[0]) , dot(at.pos,self.xyz.rzp[1]) ) for at in self.xyz.atoms ]
self.H = deepcopy(self.H_B0)
assert all(bfield[:2] == 0.) # bfield perpendicular to sheet
assert self.xyz.period[0][2] == 0.
assert self.xyz.period[1][2] == 0.
def phase(s,d,shift):
# linear gauge:
# Aavg = (dx + sx) * .5
# phase = (dy - sy) * Aavg
sx,sy = s
dx,dy = d
dx += shift[0]
dy += shift[1]
# periodic gauge:
if dx == sx:
phase = (dy - sy) * (dx % 1)
else:
si = int(sx // 1)
sr = sx % 1
di = int(dx // 1)
dr = dx % 1
# first the part "forced" to be periodic
Aavg = .5 * (di - si + dr**2 - sr**2) / (dx - sx)
phase = (dy - sy) * Aavg
# then the correction
if di > si:
for x in range(si+1,di+1):
phase -= x * (dy-sy)/(dx-sx) + (dx*sy-sx*dy)/(dx-sx)
elif di < si:
for x in range(di+1,si+1):
phase += x * (dy-sy)/(dx-sx) + (dx*sy-sx*dy)/(dx-sx)
return phase%1
if self.phase is None:
self.phase = {}
for i0,i1 in self.H:
self.phase[i0,i1] = zeros(self.H[i0,i1].shape)
for n,m in array(asarray(self.H[i0,i1]).nonzero()).transpose():
self.phase[i0,i1][n,m] = phase(self.latticecoords[n],self.latticecoords[m],(i0,i1))
for i0,i1 in self.H:
for n,m in array(asarray(self.H[i0,i1]).nonzero()).transpose():
self.H[i0,i1][n,m] *= exp(1j*2*pi*self.phase[i0,i1][n,m]*Nflux)
def H_eff(self,ka):
res = self.H[0,0] + 0.0
def adjsum(a):
return a + a.H
for i0,i1 in self.H:
if (i0,i1) != (0,0):
res += adjsum(exp(1j*dot(ka,[i0,i1]))*self.H[i0,i1])
return res
def S_eff(self,ka):
if not hasattr(self,'S'):
return None
res = self.S[0,0].copy()
def adjsum(a):
return a + a.H
for i0,i1 in self.S:
if (i0,i1) != (0,0):
res += adjsum(exp(1j*dot(ka,[i0,i1]))*self.S[i0,i1])
return res
def band_energies(self,ka):
if hasattr(self,'S'):
return array(sorted(list(real(scipy.linalg.eigvals(self.H_eff(ka),self.S_eff(ka))))))
else:
return array(sorted(list(real(eigvalsh(self.H_eff(ka))))))
def multiply(self,N0,N1):
xyz = None
N_orb = self.N_orbitals
if hasattr(self,'xyz'):
xyz = self.xyz.multiply(N0,N1)
H = {}
H[0,0] = matrix(zeros((N0*N1*N_orb,N0*N1*N_orb),self.H[0,0].dtype))
for n0 in range(N0):
for n1 in range(N1):
H[0,0][
(n0*N1+n1)*N_orb:(n0*N1+n1+1)*N_orb,
(n0*N1+n1)*N_orb:(n0*N1+n1+1)*N_orb,
] = self.H[0,0]
for i0,i1 in self.H:
if (i0,i1) == (0,0):
continue
i0n = (n0+i0) // N0
i1n = (n1+i1) // N1
if i0n > 0 or (i0n == 0 and i1n >= 0):
if (i0n,i1n) not in H:
H[i0n,i1n] = matrix(zeros((N0*N1*N_orb,N0*N1*N_orb),self.H[0,0].dtype))
H[i0n,i1n][
(n0*N1+n1)*N_orb:(n0*N1+n1+1)*N_orb,
((n0+i0)%N0*N1+(n1+i1)%N1)*N_orb:((n0+i0)%N0*N1+(n1+i1)%N1+1)*N_orb,
] = self.H[i0,i1]
i0n = (n0-i0) // N0
i1n = (n1-i1) // N1
if i0n > 0 or (i0n == 0 and i1n >= 0):
if (i0n,i1n) not in H:
H[i0n,i1n] = matrix(zeros((N0*N1*N_orb,N0*N1*N_orb),self.H[0,0].dtype))
H[i0n,i1n][
(n0*N1+n1)*N_orb:(n0*N1+n1+1)*N_orb,
((n0-i0)%N0*N1+(n1-i1)%N1)*N_orb:((n0-i0)%N0*N1+(n1-i1)%N1+1)*N_orb,
] = self.H[i0,i1].H
return sheet(H,xyz)
def square_lattice(gamma):
H = {}
H[0,0] = matrix([[0j]])
H[0,1] = matrix([[-gamma + 0j]])
H[1,0] = matrix([[-gamma + 0j]])
return sheet(H)
def graphene(gamma):
H = {}
H[0,0] = matrix([[0j,-gamma],[-gamma,0j]])
H[0,1] = matrix([[0j,-gamma],[0j,0j]])
H[1,0] = matrix([[0j,0j],[0j,-gamma]])
return sheet(H)