Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two bugs in pw90common_fourier_R_to_k* #273

Merged
merged 12 commits into from
Jul 24, 2019
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# CHANGELOG of Wannier90


### Various improvements and bugfixes

- Fix `pw90common_fourier_R_to_k` subroutines bugs when `use_ws_distance = .true.` [[#273]](https://github.com/wannier-developers/wannier90/pull/273)[[#271]](https://github.com/wannier-developers/wannier90/issues/271)

### New Wannier90 features

- Implementation of the SCDM method in Wannier90 for spinor wavefunctions and added example31 for the tutorial [[#277]](https://github.com/wannier-developers/wannier90/pull/277)


### New postw90 features, optimizations and new post-processing codes

- Calculation of spin Hall conductivity according to the formalism given in Junfeng Qiao, Jiaqi Zhou, Zhe Yuan and Weisheng Zhao, PRB 98, 214402 (2018) + example 29,30 + test suites [[#264]](https://github.com/wannier-developers/wannier90/pull/264)
Expand Down
2 changes: 1 addition & 1 deletion src/plot.F90
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ subroutine plot_interpolate_bands
if (use_ws_distance) then
do j = 1, num_wann
do i = 1, num_wann
do ideg = 1, wdist_ndeg(j, i, irpt)
do ideg = 1, wdist_ndeg(i, j, irpt)
rdotk = twopi*dot_product(plot_kpoint(:, loop_kpt), &
real(irdist_ws(:, ideg, i, j, irpt), dp))
fac = cmplx(cos(rdotk), sin(rdotk), dp)/real(wdist_ndeg(i, j, irpt), dp)
Expand Down
88 changes: 44 additions & 44 deletions src/postw90/postw90_common.F90
Original file line number Diff line number Diff line change
Expand Up @@ -722,15 +722,13 @@ subroutine pw90common_fourier_R_to_k(kpt, OO_R, OO, alpha)
if (use_ws_distance) then
do j = 1, num_wann
do i = 1, num_wann
do ideg = 1, wdist_ndeg(j, i, ir)
do ideg = 1, wdist_ndeg(i, j, ir)
rdotk = twopi*dot_product(kpt(:), real(irdist_ws(:, ideg, i, j, ir), dp))
!phase_fac=cmplx(cos(rdotk),sin(rdotk),dp)/real(ndegen(ir)*wdist_ndeg(i,j,ir),dp)
phase_fac = cmplx(cos(rdotk), sin(rdotk), dp)/real(ndegen(ir)*wdist_ndeg(i, j, ir), dp)
if (alpha == 0) then
OO(i, j) = OO(i, j) + phase_fac*OO_R(i, j, ir)
elseif (alpha == 1 .or. alpha == 2 .or. alpha == 3) then
OO(i, j) = OO(i, j) + cmplx_i*crdist_ws(alpha, ideg, i, j, ir)*phase_fac*OO_R(i, j, ir)
!OO(i,j)=OO(i,j)+cmplx_i*crvec(alpha,ir)*phase_fac*OO_R(i,j,ir)
else
stop 'wrong value of alpha in pw90common_fourier_R_to_k'
endif
Expand Down Expand Up @@ -771,7 +769,7 @@ subroutine pw90common_fourier_R_to_k_new(kpt, OO_R, OO, OO_dx, OO_dy, OO_dz)

use w90_constants, only: dp, cmplx_0, cmplx_i, twopi
use w90_parameters, only: timing_level, num_kpts, kpt_latt, num_wann, use_ws_distance
use w90_ws_distance, only: irdist_ws, wdist_ndeg, ws_translate_dist
use w90_ws_distance, only: irdist_ws, crdist_ws, wdist_ndeg, ws_translate_dist

implicit none

Expand Down Expand Up @@ -799,16 +797,19 @@ subroutine pw90common_fourier_R_to_k_new(kpt, OO_R, OO, OO_dx, OO_dy, OO_dz)
if (use_ws_distance) then
do j = 1, num_wann
do i = 1, num_wann
do ideg = 1, wdist_ndeg(j, i, ir)
do ideg = 1, wdist_ndeg(i, j, ir)
rdotk = twopi*dot_product(kpt(:), real(irdist_ws(:, ideg, i, j, ir), dp))
phase_fac = cmplx(cos(rdotk), sin(rdotk), dp)/real(ndegen(ir)*wdist_ndeg(i, j, ir), dp)
if (present(OO)) OO(i, j) = OO(i, j) + phase_fac*OO_R(i, j, ir)
if (present(OO_dx)) OO_dx(i, j) = OO_dx(i, j) + &
cmplx_i*crvec(1, ir)*phase_fac*OO_R(i, j, ir)
cmplx_i*crdist_ws(1, ideg, i, j, ir)* &
phase_fac*OO_R(i, j, ir)
if (present(OO_dy)) OO_dy(i, j) = OO_dy(i, j) + &
cmplx_i*crvec(2, ir)*phase_fac*OO_R(i, j, ir)
cmplx_i*crdist_ws(2, ideg, i, j, ir)* &
phase_fac*OO_R(i, j, ir)
if (present(OO_dz)) OO_dz(i, j) = OO_dz(i, j) + &
cmplx_i*crvec(3, ir)*phase_fac*OO_R(i, j, ir)
cmplx_i*crdist_ws(3, ideg, i, j, ir)* &
phase_fac*OO_R(i, j, ir)
enddo
enddo
enddo
Expand Down Expand Up @@ -845,7 +846,7 @@ subroutine pw90common_fourier_R_to_k_new_second_d(kpt, OO_R, OO, OO_da, OO_dadb)

use w90_constants, only: dp, cmplx_0, cmplx_i, twopi
use w90_parameters, only: timing_level, num_kpts, kpt_latt, num_wann, use_ws_distance
use w90_ws_distance, only: irdist_ws, wdist_ndeg, ws_translate_dist
use w90_ws_distance, only: irdist_ws, crdist_ws, wdist_ndeg, ws_translate_dist

implicit none

Expand All @@ -871,21 +872,22 @@ subroutine pw90common_fourier_R_to_k_new_second_d(kpt, OO_R, OO, OO_da, OO_dadb)
if (use_ws_distance) then
do j = 1, num_wann
do i = 1, num_wann
do ideg = 1, wdist_ndeg(j, i, ir)
do ideg = 1, wdist_ndeg(i, j, ir)

rdotk = twopi*dot_product(kpt(:), real(irdist_ws(:, ideg, i, j, ir), dp))
phase_fac = cmplx(cos(rdotk), sin(rdotk), dp)/real(ndegen(ir)*wdist_ndeg(i, j, ir), dp)
if (present(OO)) OO(i, j) = OO(i, j) + phase_fac*OO_R(i, j, ir)
if (present(OO_da)) then
do a = 1, 3
OO_da(i, j, a) = OO_da(i, j, a) + cmplx_i*crvec(a, ir)*phase_fac*OO_R(i, j, ir)
OO_da(i, j, a) = OO_da(i, j, a) + cmplx_i*crdist_ws(a, ideg, i, j, ir)* &
phase_fac*OO_R(i, j, ir)
enddo
endif
if (present(OO_dadb)) then
do a = 1, 3
do b = 1, 3
OO_dadb(i, j, a, b) = OO_dadb(i, j, a, b) - &
crvec(a, ir)*crvec(b, ir)*phase_fac*OO_R(i, j, ir)
OO_dadb(i, j, a, b) = OO_dadb(i, j, a, b) - crdist_ws(a, ideg, i, j, ir)* &
crdist_ws(b, ideg, i, j, ir)*phase_fac*OO_R(i, j, ir)
enddo
enddo
end if
Expand Down Expand Up @@ -935,7 +937,7 @@ subroutine pw90common_fourier_R_to_k_new_second_d_TB_conv(kpt, OO_R, oo_a_R, OO,
use w90_constants, only: dp, cmplx_0, cmplx_i, twopi
use w90_parameters, only: timing_level, num_kpts, kpt_latt, num_wann, &
use_ws_distance, wannier_centres, recip_lattice
use w90_ws_distance, only: irdist_ws, wdist_ndeg, ws_translate_dist
use w90_ws_distance, only: irdist_ws, crdist_ws, wdist_ndeg, ws_translate_dist
use w90_utility, only: utility_cart_to_frac

implicit none
Expand Down Expand Up @@ -984,25 +986,27 @@ subroutine pw90common_fourier_R_to_k_new_second_d_TB_conv(kpt, OO_R, oo_a_R, OO,
if (use_ws_distance) then
do j = 1, num_wann
do i = 1, num_wann
do ideg = 1, wdist_ndeg(j, i, ir)
do ideg = 1, wdist_ndeg(i, j, ir)

rdotk = twopi*dot_product(kpt(:), real(irdist_ws(:, ideg, i, j, ir) + &
wannier_centres_frac(:, j) - wannier_centres_frac(:, i), dp))
phase_fac = cmplx(cos(rdotk), sin(rdotk), dp)/real(ndegen(ir)*wdist_ndeg(i, j, ir), dp)
if (present(OO)) OO(i, j) = OO(i, j) + phase_fac*OO_R(i, j, ir)
if (present(OO_da)) then
do a = 1, 3
OO_da(i, j, a) = OO_da(i, j, a) + cmplx_i*(crvec(a, ir) + local_wannier_centres(a, j) - &
local_wannier_centres(a, i))*phase_fac*OO_R(i, j, ir)
OO_da(i, j, a) = OO_da(i, j, a) + cmplx_i* &
(crdist_ws(a, ideg, i, j, ir) + local_wannier_centres(a, j) - &
local_wannier_centres(a, i))*phase_fac*OO_R(i, j, ir)
enddo
endif
if (present(OO_dadb)) then
do a = 1, 3
do b = 1, 3
OO_dadb(i, j, a, b) = OO_dadb(i, j, a, b) - &
(crvec(a, ir) + local_wannier_centres(a, j) - local_wannier_centres(a, i))* &
(crvec(b, ir) + local_wannier_centres(b, j) - local_wannier_centres(b, i))* &
phase_fac*OO_R(i, j, ir)
(crdist_ws(a, ideg, i, j, ir) + local_wannier_centres(a, j) - &
local_wannier_centres(a, i))* &
(crdist_ws(b, ideg, i, j, ir) + local_wannier_centres(b, j) - &
local_wannier_centres(b, i))*phase_fac*OO_R(i, j, ir)
enddo
enddo
end if
Expand All @@ -1020,9 +1024,9 @@ subroutine pw90common_fourier_R_to_k_new_second_d_TB_conv(kpt, OO_R, oo_a_R, OO,
if (present(OO)) OO(i, j) = OO(i, j) + phase_fac*OO_R(i, j, ir)
if (present(OO_da)) then
do a = 1, 3
OO_da(i, j, a) = &
OO_da(i, j, a) + cmplx_i* &
(crvec(a, ir) + local_wannier_centres(a, j) - local_wannier_centres(a, i))*phase_fac*OO_R(i, j, ir)
OO_da(i, j, a) = OO_da(i, j, a) + cmplx_i* &
(crvec(a, ir) + local_wannier_centres(a, j) - &
local_wannier_centres(a, i))*phase_fac*OO_R(i, j, ir)
enddo
endif
if (present(OO_dadb)) then
Expand Down Expand Up @@ -1056,7 +1060,7 @@ subroutine pw90common_fourier_R_to_k_vec(kpt, OO_R, OO_true, OO_pseudo)

use w90_constants, only: dp, cmplx_0, cmplx_i, twopi
use w90_parameters, only: num_kpts, kpt_latt, num_wann, use_ws_distance
use w90_ws_distance, only: irdist_ws, wdist_ndeg, ws_translate_dist
use w90_ws_distance, only: irdist_ws, crdist_ws, wdist_ndeg, ws_translate_dist

implicit none

Expand All @@ -1079,26 +1083,24 @@ subroutine pw90common_fourier_R_to_k_vec(kpt, OO_R, OO_true, OO_pseudo)
if (use_ws_distance) then
do j = 1, num_wann
do i = 1, num_wann
do ideg = 1, wdist_ndeg(j, i, ir)
do ideg = 1, wdist_ndeg(i, j, ir)
rdotk = twopi*dot_product(kpt(:), real(irdist_ws(:, ideg, i, j, ir), dp))
phase_fac = cmplx(cos(rdotk), sin(rdotk), dp)/real(ndegen(ir)*wdist_ndeg(i, j, ir), dp)
rdotk = twopi*dot_product(kpt(:), irvec(:, ir))
phase_fac = cmplx(cos(rdotk), sin(rdotk), dp)/real(ndegen(ir), dp)
if (present(OO_true)) then
OO_true(i, j, 1) = OO_true(i, j, 1) + phase_fac*OO_R(i, j, ir, 1)
OO_true(i, j, 2) = OO_true(i, j, 2) + phase_fac*OO_R(i, j, ir, 2)
OO_true(i, j, 3) = OO_true(i, j, 3) + phase_fac*OO_R(i, j, ir, 3)
endif
if (present(OO_pseudo)) then
OO_pseudo(i, j, 1) = OO_pseudo(i, j, 1) &
+ cmplx_i*crvec(2, ir)*phase_fac*OO_R(i, j, ir, 3) &
- cmplx_i*crvec(3, ir)*phase_fac*OO_R(i, j, ir, 2)
+ cmplx_i*crdist_ws(2, ideg, i, j, ir)*phase_fac*OO_R(i, j, ir, 3) &
- cmplx_i*crdist_ws(3, ideg, i, j, ir)*phase_fac*OO_R(i, j, ir, 2)
OO_pseudo(i, j, 2) = OO_pseudo(i, j, 2) &
+ cmplx_i*crvec(3, ir)*phase_fac*OO_R(i, j, ir, 1) &
- cmplx_i*crvec(1, ir)*phase_fac*OO_R(i, j, ir, 3)
+ cmplx_i*crdist_ws(3, ideg, i, j, ir)*phase_fac*OO_R(i, j, ir, 1) &
- cmplx_i*crdist_ws(1, ideg, i, j, ir)*phase_fac*OO_R(i, j, ir, 3)
OO_pseudo(i, j, 3) = OO_pseudo(i, j, 3) &
+ cmplx_i*crvec(1, ir)*phase_fac*OO_R(i, j, ir, 2) &
- cmplx_i*crvec(2, ir)*phase_fac*OO_R(i, j, ir, 1)
+ cmplx_i*crdist_ws(1, ideg, i, j, ir)*phase_fac*OO_R(i, j, ir, 2) &
- cmplx_i*crdist_ws(2, ideg, i, j, ir)*phase_fac*OO_R(i, j, ir, 1)
endif
enddo
enddo
Expand Down Expand Up @@ -1142,7 +1144,7 @@ subroutine pw90common_fourier_R_to_k_vec_dadb(kpt, OO_R, OO_da, OO_dadb)

use w90_constants, only: dp, cmplx_0, cmplx_i, twopi
use w90_parameters, only: num_kpts, kpt_latt, num_wann, use_ws_distance
use w90_ws_distance, only: irdist_ws, wdist_ndeg, ws_translate_dist
use w90_ws_distance, only: irdist_ws, crdist_ws, wdist_ndeg, ws_translate_dist

implicit none

Expand All @@ -1165,12 +1167,10 @@ subroutine pw90common_fourier_R_to_k_vec_dadb(kpt, OO_R, OO_da, OO_dadb)
if (use_ws_distance) then
do j = 1, num_wann
do i = 1, num_wann
do ideg = 1, wdist_ndeg(j, i, ir)
do ideg = 1, wdist_ndeg(i, j, ir)

rdotk = twopi*dot_product(kpt(:), real(irdist_ws(:, ideg, i, j, ir), dp))
phase_fac = cmplx(cos(rdotk), sin(rdotk), dp)/real(ndegen(ir)*wdist_ndeg(i, j, ir), dp)
rdotk = twopi*dot_product(kpt(:), irvec(:, ir))
phase_fac = cmplx(cos(rdotk), sin(rdotk), dp)/real(ndegen(ir), dp)
if (present(OO_da)) then
OO_da(i, j, 1) = OO_da(i, j, 1) + phase_fac*OO_R(i, j, ir, 1)
OO_da(i, j, 2) = OO_da(i, j, 2) + phase_fac*OO_R(i, j, ir, 2)
Expand All @@ -1179,7 +1179,8 @@ subroutine pw90common_fourier_R_to_k_vec_dadb(kpt, OO_R, OO_da, OO_dadb)
if (present(OO_dadb)) then
do a = 1, 3
do b = 1, 3
OO_dadb(i, j, a, b) = OO_dadb(i, j, a, b) + cmplx_i*crvec(b, ir)*phase_fac*OO_R(i, j, ir, a)
OO_dadb(i, j, a, b) = OO_dadb(i, j, a, b) + &
cmplx_i*crdist_ws(b, ideg, i, j, ir)*phase_fac*OO_R(i, j, ir, a)
enddo
enddo
endif
Expand Down Expand Up @@ -1227,7 +1228,7 @@ subroutine pw90common_fourier_R_to_k_vec_dadb_TB_conv(kpt, OO_R, OO_da, OO_dadb)
use w90_constants, only: dp, cmplx_0, cmplx_i, twopi
use w90_parameters, only: num_kpts, kpt_latt, num_wann, use_ws_distance, &
wannier_centres, recip_lattice
use w90_ws_distance, only: irdist_ws, wdist_ndeg, ws_translate_dist
use w90_ws_distance, only: irdist_ws, crdist_ws, wdist_ndeg, ws_translate_dist
use w90_utility, only: utility_cart_to_frac

implicit none
Expand Down Expand Up @@ -1290,13 +1291,11 @@ subroutine pw90common_fourier_R_to_k_vec_dadb_TB_conv(kpt, OO_R, OO_da, OO_dadb)
if (use_ws_distance) then
do j = 1, num_wann
do i = 1, num_wann
do ideg = 1, wdist_ndeg(j, i, ir)
do ideg = 1, wdist_ndeg(i, j, ir)

rdotk = twopi*dot_product(kpt(:), real(irdist_ws(:, ideg, i, j, ir) + &
wannier_centres_frac(:, j) - wannier_centres_frac(:, i), dp))
phase_fac = cmplx(cos(rdotk), sin(rdotk), dp)/real(ndegen(ir)*wdist_ndeg(i, j, ir), dp)
! rdotk=twopi*dot_product(kpt(:),irvec(:,ir))
! phase_fac=cmplx(cos(rdotk),sin(rdotk),dp)/real(ndegen(ir),dp)
if (present(OO_da)) then
! if we are at the origin and at the same band, then the
! matrix element is zero in this convention
Expand All @@ -1315,8 +1314,9 @@ subroutine pw90common_fourier_R_to_k_vec_dadb_TB_conv(kpt, OO_R, OO_da, OO_dadb)
else
do a = 1, 3
do b = 1, 3
OO_dadb(i, j, a, b) = OO_dadb(i, j, a, b) + cmplx_i*(crvec(b, ir) + local_wannier_centres(b, j) - &
local_wannier_centres(b, i))*phase_fac*OO_R(i, j, ir, a)
OO_dadb(i, j, a, b) = OO_dadb(i, j, a, b) + cmplx_i* &
(crdist_ws(b, ideg, i, j, ir) + local_wannier_centres(b, j) - &
local_wannier_centres(b, i))*phase_fac*OO_R(i, j, ir, a)
enddo
enddo
endif
Expand Down
4 changes: 2 additions & 2 deletions src/ws_distance.F90
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module w90_ws_distance
!! all listed. First index: xyz, second index: number of degenerate shifts,
!! third and fourth indices: i,j; fifth index: index on the R vector.
real(DP), public, save, allocatable :: crdist_ws(:, :, :, :, :)!(3,ndegenx,num_wann,num_wann,nrpts)
!! Cartesian version if irdist_ws, in angstrom
!! Cartesian version of irdist_ws, in angstrom
integer, public, save, allocatable :: wdist_ndeg(:, :, :)!(num_wann,num_wann,nrpts)
!! The number of equivalent vectors for each set of (i,j,R) (that is, loops on
!! the second index of irdist_ws(:,:,i,j,R) go from 1 to wdist_ndeg(i,j,R))
Expand Down Expand Up @@ -120,7 +120,7 @@ subroutine ws_translate_dist(nrpts, irvec, force_recompute)
do jw = 1, num_wann
do iw = 1, num_wann
call utility_frac_to_cart(REAL(irvec(:, ir), kind=dp), irvec_cart, real_lattice)
! function IW translated in the Wigner-Size around function JW
! function JW translated in the Wigner-Seitz around function IW
! and also find its degeneracy, and the integer shifts needed
! to identify it
! Note: the routine outputs R_out, but we don't really need it
Expand Down
Loading