-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathberry.f90
executable file
·275 lines (221 loc) · 8.69 KB
/
berry.f90
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
subroutine berryphase
!> Subroutine for calculating Berry phase for a giving path
!
! Comments:
!
! At present, you have to define the k path that you want
! in kpoints
!
! Author : QuanSheng Wu ([email protected])
!
! 31 Mar 2016
!
! Copyright (c) 2010 QuanSheng Wu. All rights reserved.
use para
use wmpi
implicit none
integer :: i, j, it, ik, Nk_seg, NK_Berry_tot
!> k points in kx-ky plane
real(dp), allocatable :: kpoints(:, :)
!> hamiltonian for each k point
!> and also the eigenvector of hamiltonian after eigensystem_c
complex(dp), allocatable :: uk(:, :), uk_dag(:, :)
!> eigenvector for each kx
complex(dp), allocatable :: Eigenvector(:, :, :)
real (dp), allocatable :: eigenvalue(:)
complex(dp), allocatable :: phase(:)
real(dp) :: br
real(dp) :: k(3), b(3)
complex(dp) :: overlap, ratio
! number of k points in each segment
Nk_seg= Nk
! total number of k points in the loop for Berry phase calculation
NK_Berry_tot= (NK_Berry-1)*Nk_seg
allocate(kpoints(3, NK_Berry_tot))
kpoints= 0d0
allocate(uk(Num_wann, Num_wann), uk_dag(Num_wann, Num_wann))
allocate(Eigenvector(Num_wann, Num_wann, NK_Berry_tot), eigenvalue(Num_wann))
allocate(phase(Num_wann))
uk=0d0
eigenvalue=0d0
Eigenvector=0d0
!> set k path for berry phase calculation
!> kpoints, k3points_Berry are in fractional/direct coordinates
it = 0
do ik=1, NK_Berry- 1
do i= 1, Nk_seg
it= it+ 1
kpoints(:, it)= k3points_Berry(:, ik)+ &
(k3points_Berry(:, ik+1)- k3points_Berry(:, ik))*(i-1d0)/(Nk_seg-1d0)
enddo ! i
enddo ! ik
!> for each ky, we can get wanniercenter
do ik=1, NK_Berry_tot
k= kpoints(:, ik)
if (index(KPorTB, 'KP')/=0)then
call ham_bulk_kp (k, uk)
else
call ham_bulk_latticegauge(k, uk)
endif
!> diagonal uk
call eigensystem_c('V', 'U', Num_wann, uk, eigenvalue)
Eigenvector(:, :, ik)= uk
enddo
!> sum over k to get berry phase
phase= 1d0
do ik= 1, NK_Berry_tot-1
uk= Eigenvector(:, :, ik)
uk_dag= conjg(transpose(uk))
if (ik==NK_Berry_tot-1) then
uk= Eigenvector(:, :, 1)
else
uk= Eigenvector(:, :, ik+ 1)
endif
b= kpoints(:, ik+1)- kpoints(:, ik)
!> <u_k|u_k+1>
do i=1, Num_wann
overlap= 0d0
do j=1, Num_wann
br= b(1)*Origin_cell%wannier_centers_direct(1, j)+ &
b(2)*Origin_cell%wannier_centers_direct(2, j)+ &
b(3)*Origin_cell%wannier_centers_direct(3, j)
ratio= cos(2d0*pi*br)- zi*sin(2d0*pi*br)
overlap= overlap+ uk_dag(i, j)* uk(j, i)* ratio
enddo
phase(i)= overlap*phase(i)
enddo
enddo !< ik
if (cpuid==0)write(stdout, *) ">> WARNING: Please increase NK1 until Berry phase is converged!"
if (cpuid==0)write(stdout, *) ">> WARNING: The starting point and the ending point should be different by a reciprocal lattice vector"
if (cpuid==0)write(stdout, *) 'Berry phase for the loop you chose: in unit of \pi'
if (cpuid==0) write(stdout, '(f18.6)') mod(sum(aimag(log(phase(1:NumOccupied)))/pi), 2d0)
outfileindex= outfileindex+ 1
if (cpuid==0) then
open(unit= outfileindex, file="kpath_berry.txt")
write(outfileindex, '("#",a11, 5a12, a, f12.6, a)')"kx", "ky", "kz", &
"k1", "k2", "k3", " Berry phase= ", &
mod(sum(aimag(log(phase(1:NumOccupied)))/pi), 2d0), ' pi'
do ik=1, NK_Berry_tot
b= kpoints(1, ik)*Origin_cell%Kua+ kpoints(2, ik)*Origin_cell%Kub+ kpoints(3, ik)*Origin_cell%Kuc
write(outfileindex, '(6f12.6)')b, kpoints(:, ik)
enddo
endif
deallocate(kpoints)
deallocate(uk,uk_dag)
deallocate(Eigenvector,eigenvalue)
deallocate(phase)
return
end subroutine berryphase
subroutine berryphase_atomic
!> Subroutine for calculating Berry phase for a giving path
!
! Comments:
!
! At present, you have to define the k path that you want
! in kpoints
!
! Author : QuanSheng Wu ([email protected])
!
! 31 Mar 2016
!
! Copyright (c) 2010 QuanSheng Wu. All rights reserved.
use para
use wmpi
implicit none
integer :: i, j, it, ik, Nk_seg, NK_Berry_tot
!> k points in kx-ky plane
real(dp), allocatable :: kpoints(:, :)
!> hamiltonian for each k point
!> and also the eigenvector of hamiltonian after eigensystem_c
complex(dp), allocatable :: uk(:, :), uk_dag(:, :)
!> eigenvector for each kx
complex(dp), allocatable :: Eigenvector(:, :, :)
real (dp), allocatable :: eigenvalue(:)
complex(dp), allocatable :: phase(:), mat1(:, :), mat2(:, :)
real(dp) :: br
real(dp) :: k(3), b(3)
complex(dp) :: overlap, ratio
! number of k points in each segment
Nk_seg= Nk
! total number of k points in the loop for Berry phase calculation
NK_Berry_tot= (NK_Berry-1)*Nk_seg
allocate(kpoints(3, NK_Berry_tot))
kpoints= 0d0
allocate(mat1(Num_wann, Num_wann), mat2(Num_wann, Num_wann))
allocate(uk(Num_wann, Num_wann), uk_dag(Num_wann, Num_wann))
allocate(Eigenvector(Num_wann, Num_wann, NK_Berry_tot), eigenvalue(Num_wann))
allocate(phase(Num_wann))
uk=0d0
eigenvalue=0d0
Eigenvector=0d0
!> set k path for berry phase calculation
!> kpoints, k3points_Berry are in fractional/direct coordinates
it = 0
do ik=1, NK_Berry- 1
do i= 1, Nk_seg
it= it+ 1
kpoints(:, it)= k3points_Berry(:, ik)+ &
(k3points_Berry(:, ik+1)- k3points_Berry(:, ik))*(i-1d0)/(Nk_seg-1d0)
enddo ! i
enddo ! ik
!> for each ky, we can get wanniercenter
do ik=1, NK_Berry_tot
k= kpoints(:, ik)
if (index(KPorTB, 'KP')/=0)then
call ham_bulk_kp (k, uk)
else
call ham_bulk_atomicgauge(k, uk)
endif
!> diagonal uk
call eigensystem_c('V', 'U', Num_wann, uk, eigenvalue)
Eigenvector(:, :, ik)= uk
enddo
!> sum over k to get berry phase
phase= 1d0
do ik= 1, NK_Berry_tot-1
uk= Eigenvector(:, :, ik)
uk_dag= conjg(transpose(uk))
if (ik==NK_Berry_tot-1) then
b=-kpoints(:, 1)+ kpoints(:, NK_Berry_tot)
uk= Eigenvector(:, :, 1)
else
uk= Eigenvector(:, :, ik+ 1)
endif
!> <u_k|u_k+1>
do i=1, Num_wann
overlap= 0d0
do j=1, Num_wann
if (ik==NK_Berry_tot-1) then
br= b(1)*Origin_cell%wannier_centers_direct(1, j)+ &
b(2)*Origin_cell%wannier_centers_direct(2, j)+ &
b(3)*Origin_cell%wannier_centers_direct(3, j)
ratio= cos(2d0*pi*br)- zi*sin(2d0*pi*br)
else
ratio=1d0
endif
overlap= overlap+ uk_dag(i, j)* uk(j, i)* ratio
enddo
phase(i)= overlap*phase(i)
enddo
enddo !< ik
if (cpuid==0)write(stdout, *) ">> WARNING: Please increase NK1 until Berry phase is converged!"
if (cpuid==0)write(stdout, *) ">> WARNING: The starting point and the ending point should be different by a reciprocal lattice vector"
if (cpuid==0)write(stdout, *) 'Berry phase for the loop you chose: in unit of \pi'
if (cpuid==0) write(stdout, '(f18.6)') mod(sum(aimag(log(phase(1:NumOccupied)))/pi), 2d0)
outfileindex= outfileindex+ 1
if (cpuid==0) then
open(unit= outfileindex, file="kpath_berry.txt")
write(outfileindex, '("#",a11, 5a12, a, f12.6, a)')"kx", "ky", "kz", &
"k1", "k2", "k3", " Berry phase= ", &
mod(sum(aimag(log(phase(1:NumOccupied)))/pi), 2d0), ' pi'
do ik=1, NK_Berry_tot
b= kpoints(1, ik)*Origin_cell%Kua+ kpoints(2, ik)*Origin_cell%Kub+ kpoints(3, ik)*Origin_cell%Kuc
write(outfileindex, '(6f12.6)')b, kpoints(:, ik)
enddo
endif
deallocate(kpoints)
deallocate(mat1,mat2,uk,uk_dag)
deallocate(Eigenvector,eigenvalue)
deallocate(phase)
return
end subroutine berryphase_atomic