The Elk Code
projkw90.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2026 J. K. Dewhurst and S. Sharma.
3 ! This file is distributed under the terms of the GNU General Public License.
4 ! See the file COPYING for license details.
5 
6 subroutine projkw90(ik,amn)
7 use modmain
8 use modw90
9 implicit none
10 ! arguments
11 integer, intent(in) :: ik
12 complex(8), intent(out) :: amn(num_bands,num_wann)
13 ! local variables
14 integer ispn,ist,is,ias
15 integer nrc,nrci,irco
16 integer l,m,lm,i,j
17 integer npci,ni,no
18 real(8) sm,t0,t1
19 complex(8) f(-3:3),g(7),zsm
20 ! allocatable arrays
21 complex(8), allocatable :: apwalm(:,:,:,:,:),evecfv(:,:,:),evecsv(:,:)
22 complex(8), allocatable :: wfmt(:,:,:)
23 ! allocate local arrays
24 allocate(apwalm(ngkmax,apwordmax,lmmaxapw,natmtot,nspnfv))
25 allocate(evecfv(nmatmax,nstfv,nspnfv),evecsv(nstsv,nstsv))
26 allocate(wfmt(npcmtmax,nspinor,num_bands))
27 ! find the matching coefficients
28 do ispn=1,nspnfv
29  call match(ngk(ispn,ik),vgkc(:,:,ispn,ik),gkc(:,ispn,ik),sfacgk(:,:,ispn,ik),&
30  apwalm(:,:,:,:,ispn))
31 end do
32 ! get the eigenvectors from file
33 call getevecfv(filext,0,vkl(:,ik),vgkl(:,:,:,ik),evecfv)
34 call getevecsv(filext,0,vkl(:,ik),evecsv)
35 ! loop over atoms
36 do ias=1,natmtot
37  is=idxis(ias)
38  nrc=nrcmt(is)
39  nrci=nrcmti(is)
40  irco=nrci+1
41  npci=npcmti(is)
42  ni=npci-1
43  no=npcmt(is)-npci-1
44 ! normalisation prefactor
45  t0=1.d0/sqrt((fourpi/3.d0)*rmt(is)**3)
46 ! generate the second-variational muffin-tin wavefunctions at k
47  call wfmtsv(.true.,lradstp,is,ias,num_bands,idxw90,ngk(:,ik),apwalm,evecfv, &
48  evecsv,npcmtmax,wfmt)
49  do ist=1,num_bands
50  do ispn=1,nspinor
51  lm=0
52  do l=0,lprojw90(is)
53  do m=-l,l
54  lm=lm+1
55  if (l <= lmaxi) then
56  sm=sum(abs(wfmt(lm:lm+ni:lmmaxi,ispn,ist))*wr2cmt(1:nrci,is))
57  zsm=sum(wfmt(lm:lm+ni:lmmaxi,ispn,ist)*wr2cmt(1:nrci,is))
58  else
59  sm=0.d0
60  zsm=0.d0
61  end if
62  i=npci+lm
63  sm=sm+sum(abs(wfmt(i:i+no:lmmaxo,ispn,ist))*wr2cmt(irco:nrc,is))
64  zsm=zsm+sum(wfmt(i:i+no:lmmaxo,ispn,ist)*wr2cmt(irco:nrc,is))
65 ! use sm as the magnitude and zsm as the phase of the projector
66  t1=abs(zsm)
67  if (t1 > 1.d-12) then
68  f(m)=t0*sm*zsm/t1
69  else
70  f(m)=t0*sm
71  end if
72  end do
73 ! convert to cubic harmonics in the Wannier90 convention
74  call ftogw90(l,f,g)
75 ! store in the output matrix
76  i=prjwn(ispn,l,ias)
77  do j=1,2*l+1
78  amn(ist,i)=g(j)
79  i=i+nspinor
80  end do
81  end do
82  end do
83  end do
84 end do
85 deallocate(apwalm,evecfv,evecsv,wfmt)
86 
87 contains
88 
89 pure subroutine ftogw90(l,f,g)
90 implicit none
91 ! arguments
92 integer, intent(in) :: l
93 complex(8), intent(in) :: f(-3:3)
94 complex(8), intent(out) :: g(7)
95 ! real constant 1/√2
96 real(8), parameter :: c1=0.7071067811865475244d0
97 ! s, pz, dz2, fz3
98 g(1)=f(0)
99 if (l == 0) return
100 ! px, dxz, fxz2
101 g(2)=c1*(f(-1)-f(1))
102 ! py, dyz, fyz2
103 g(3)=-c1*zi*(f(-1)+f(1))
104 if (l == 1) return
105 ! dx2-y2, fz(x2-y2)
106 g(4)=c1*(f(-2)+f(2))
107 ! dxy, fxyz
108 g(5)=c1*zi*(f(2)-f(-2))
109 if (l == 2) return
110 ! fx(x2-3y2)
111 g(6)=c1*(f(-3)-f(3))
112 ! fy(3x2-y2)
113 g(7)=-c1*zi*(f(-3)+f(3))
114 end subroutine
115 
116 end subroutine
117 
integer nmatmax
Definition: modmain.f90:849
integer, dimension(maxspecies) npcmt
Definition: modmain.f90:214
subroutine getevecsv(fext, ikp, vpl, evecsv)
Definition: getevecsv.f90:7
integer npcmtmax
Definition: modmain.f90:216
character(256) filext
Definition: modmain.f90:1293
integer lmmaxo
Definition: modmain.f90:203
integer lmmaxapw
Definition: modmain.f90:199
integer ngkmax
Definition: modmain.f90:499
subroutine getevecfv(fext, ikp, vpl, vgpl, evecfv)
Definition: getevecfv.f90:10
subroutine match(ngp, vgpc, gpc, sfacgp, apwalm)
Definition: match.f90:10
complex(8), dimension(:,:,:,:), allocatable sfacgk
Definition: modmain.f90:509
integer nstsv
Definition: modmain.f90:883
integer, dimension(:,:), allocatable ngk
Definition: modmain.f90:497
Definition: modw90.f90:6
real(8), dimension(:,:,:,:), allocatable vgkl
Definition: modmain.f90:503
integer, dimension(:), allocatable idxw90
Definition: modw90.f90:24
integer lradstp
Definition: modmain.f90:171
integer nspinor
Definition: modmain.f90:267
real(8), dimension(maxspecies) rmt
Definition: modmain.f90:162
integer, dimension(:,:,:), allocatable prjwn
Definition: modw90.f90:30
real(8), dimension(:,:,:,:), allocatable vgkc
Definition: modmain.f90:505
real(8), dimension(:,:), allocatable vkl
Definition: modmain.f90:471
integer apwordmax
Definition: modmain.f90:758
real(8), dimension(:,:), allocatable wr2cmt
Definition: modmain.f90:189
integer, dimension(maxspecies) npcmti
Definition: modmain.f90:214
integer, dimension(maxatoms *maxspecies) idxis
Definition: modmain.f90:44
integer lmmaxi
Definition: modmain.f90:207
real(8), dimension(:,:,:), allocatable gkc
Definition: modmain.f90:507
complex(8), parameter zi
Definition: modmain.f90:1232
real(8), parameter fourpi
Definition: modmain.f90:1226
integer natmtot
Definition: modmain.f90:40
subroutine projkw90(ik, amn)
Definition: projkw90.f90:7
integer, dimension(maxspecies) nrcmt
Definition: modmain.f90:173
integer, dimension(maxspecies) nrcmti
Definition: modmain.f90:211
subroutine wfmtsv(tsh, lrstp, is, ias, nst, idx, ngp, apwalm, evecfv, evecsv, ld, wfmt)
Definition: wfmtsv.f90:7
integer, dimension(maxspecies) lprojw90
Definition: modw90.f90:28
integer nstfv
Definition: modmain.f90:881
integer nspnfv
Definition: modmain.f90:289
pure subroutine ftogw90(l, f, g)
Definition: projkw90.f90:90
integer lmaxi
Definition: modmain.f90:205