forked from golddoushi/mcsolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WannierKit.py
177 lines (155 loc) · 6.92 KB
/
WannierKit.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
'''
Created on 2018 12 8
@author: Andrew
'''
import numpy as np
import re
import matplotlib.figure as fig
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D
class TBmodel(object):
Ham=[]
Ham_k=[]
lattice=[]
reci_lattice=[]
norbital=0
orbital_coor=[]
onsite_energy=[]
nhoppings=0
hopping=[]
kpath=[]
kmesh=[]
wcc_path=[]
wcc_polar_direction=-1
nelectrons=-1
def __init__(self):
pass
def make_supercell(self,sc_dir0=[1.,1.,0.],sc_dir1=[1.,-1.,0.],sc_dir2=[0.,0.,1.],toHome=True):
'''
construct a supercell model.
often used with slab fun. to get slab model with chosen border.
'''
Tmatrix=np.array([sc_dir0,sc_dir1,sc_dir2]) # sc_lat = T dot lat
invTmatrix=np.linalg.inv(Tmatrix) # lat = invT dot sc_lat
# construct lattice matrix for supercell
sc_lattice=np.dot(Tmatrix,self.lattice)
# construct orbitals for supercell
R0max=int(np.max(abs(Tmatrix[:,0])))
R1max=int(np.max(abs(Tmatrix[:,1])))
R2max=int(np.max(abs(Tmatrix[:,2])))
### find which sub-cell is interior, just check the origins
interior_cell_list=[]
interior_cell_coor=[]
for a0 in range(-R0max,R0max+1):
for a1 in range(-R1max,R1max+1):
for a2 in range(-R2max,R2max+1):
ori_lat=np.array([a0,a1,a2])
ori_sc_lat=np.dot(ori_lat,invTmatrix)
interior=True
for ori_coor in ori_sc_lat:
if(ori_coor<0 or ori_coor>=1):
interior=False
if(interior):
interior_cell_list.append(ori_lat)
interior_cell_coor.append(ori_sc_lat)
### now add every orbs and their attributes
sc_orbital_coor=[]
onsite_energy=[]
norbital=0
hopping=[]
nhoppings=0
for iinter_cell, interior_cell in enumerate(interior_cell_list):
for iorb0, orb0 in enumerate(self.orbital_coor):
# add coordinates
orb_sc=np.dot(orb0+interior_cell,invTmatrix)
sc_orbital_coor.append(orb_sc)
norbital+=1
# add hopping
for hopping_ele in self.hopping:
if(hopping_ele[0]==iorb0):
iorb0_sc=iinter_cell*self.norbital+iorb0
#hopping_orb0=[iorb0_sc]
iorb1, aug_vec, amplify, color, linewidth= hopping_ele[1], hopping_ele[2], hopping_ele[3], hopping_ele[4], hopping_ele[5]
#print('iorb0, iorb1:', iorb0, iorb1, 'aug_vec:',aug_vec)
orb1_cell_ori=interior_cell+aug_vec # the origin coordinates (a1,a2,a3 lattice)
orb1_cell_ori_sc=np.dot(orb1_cell_ori,invTmatrix) # in supercell lattice
orb1_cell_ori_sc_reduced=orb1_cell_ori_sc%1 # reduced by 1
aug_vec_sc=orb1_cell_ori_sc-orb1_cell_ori_sc_reduced # aug vector in supercell frame
# check which level is reached
for iori_coor, ori_coor in enumerate(interior_cell_coor):
if(ori_coor==orb1_cell_ori_sc_reduced).all():
iorb1_sc=iori_coor*self.norbital+iorb1
break
#print('SC: iorb0, iorb1:', iorb0_sc, iorb1_sc, 'aug_vec:',aug_vec_sc)
hopping_orb0=[iorb0_sc, iorb1_sc, aug_vec_sc, amplify, color, linewidth]
hopping.append(hopping_orb0)
nhoppings+=1
self.lattice=sc_lattice
self.orbital_coor=sc_orbital_coor
self.norbital=norbital
self.onsite_energy=onsite_energy
self.nhoppings=nhoppings
self.hopping=hopping
if toHome:
self.toHome()
def toHome(self):
'''move all coordinates to the home cell'''
for iorb, orb in enumerate(self.orbital_coor):
orb_reduced=orb%1
orb_shift=orb_reduced-orb
if (orb_shift).any():
#print(orb,orb_shift)
# update orb
orb%=1
# update the hoppings
for hopping in self.hopping:
# hopping start with orb
if(hopping[0]==iorb):
hopping[2]+=orb_shift
#print(orb_shift)
#print(hopping)
#print()
if(hopping[1]==iorb):
hopping[2]-=orb_shift
#print(orb_shift)
#print(hopping)
#print()
def viewStructure(self):
'''visualize the orbital and bonding's spatial configuration'''
f=fig.Figure(figsize=(4,3))
ax=f.add_subplot(111,projection='3d')
def dragLineWithTwoPoints(pt0, pt1, c='black', linewidth=2):
ax.plot([pt0[0],pt1[0]],[pt0[1],pt1[1]],[pt0[2],pt1[2]],c=c, linewidth=linewidth)
# draw the boder of unit cell
pt0=np.zeros(3)
a1,a2,a3=self.lattice[0],self.lattice[1],self.lattice[2]
ax.text(a1[0],a1[1],a1[2],'$a_1$')
ax.text(a2[0],a2[1],a2[2],'$a_2$')
ax.text(a3[0],a3[1],a3[2],'$a_3$')
#dragLineWithTwoPoints(pt0,a1)
#dragLineWithTwoPoints(a1,a1+a2)
#dragLineWithTwoPoints(a1+a2,a2)
#dragLineWithTwoPoints(pt0,a2)
#dragLineWithTwoPoints(a3,a1+a3)
#dragLineWithTwoPoints(a1+a3,a1+a2+a3)
#dragLineWithTwoPoints(a1+a2+a3,a2+a3)
#dragLineWithTwoPoints(a3,a2+a3)
#dragLineWithTwoPoints(pt0,a3)
#dragLineWithTwoPoints(a1,a1+a3)
#dragLineWithTwoPoints(a2,a2+a3)
#dragLineWithTwoPoints(a1+a2,a1+a2+a3)
for iorb, orb in enumerate(self.orbital_coor):
orb_xyz=np.dot(orb,self.lattice)
ax.scatter(orb_xyz[0],orb_xyz[1],orb_xyz[2],c='red',s=50)
ax.text(orb_xyz[0],orb_xyz[1],orb_xyz[2],str(iorb))
for hopping in self.hopping:
iorb0, iorb1, Rextra, amp, color, linewidth=hopping[0], hopping[1], hopping[2], hopping[3], hopping[4], hopping[5]
orb0_xyz=np.dot(self.orbital_coor[iorb0],self.lattice)
orb1_xyz=np.dot((self.orbital_coor[iorb1]+Rextra),self.lattice)
dragLineWithTwoPoints(orb0_xyz,orb1_xyz,c=color,linewidth=linewidth)
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
ax.grid(False)
ax.axis('off')
return f, ax