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,k
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  do i=1,nprojw90(is)
52  l=lprojw90(i,is)
53  lm=l**2
54  do m=-l,l
55  lm=lm+1
56  if (l <= lmaxi) then
57  sm=sum(abs(wfmt(lm:lm+ni:lmmaxi,ispn,ist))*wr2cmt(1:nrci,is))
58  zsm=sum(wfmt(lm:lm+ni:lmmaxi,ispn,ist)*wr2cmt(1:nrci,is))
59  else
60  sm=0.d0
61  zsm=0.d0
62  end if
63  j=npci+lm
64  sm=sm+sum(abs(wfmt(j:j+no:lmmaxo,ispn,ist))*wr2cmt(irco:nrc,is))
65  zsm=zsm+sum(wfmt(j:j+no:lmmaxo,ispn,ist)*wr2cmt(irco:nrc,is))
66 ! use sm as the magnitude and zsm as the phase of the projector
67  t1=abs(zsm)
68  if (t1 > 1.d-12) then
69  f(m)=t0*sm*zsm/t1
70  else
71  f(m)=t0*sm
72  end if
73  end do
74 ! convert to cubic harmonics in the Wannier90 convention
75  call ftogw90(l,f,g)
76 ! store in the output matrix
77  j=prjwn(ispn,i,ias)
78  do k=1,2*l+1
79  amn(ist,j)=g(k)
80  j=j+nspinor
81  end do
82  end do
83  end do
84  end do
85 end do
86 deallocate(apwalm,evecfv,evecsv,wfmt)
87 
88 contains
89 
90 pure subroutine ftogw90(l,f,g)
91 implicit none
92 ! arguments
93 integer, intent(in) :: l
94 complex(8), intent(in) :: f(-3:3)
95 complex(8), intent(out) :: g(7)
96 ! real constant 1/√2
97 real(8), parameter :: c1=0.7071067811865475244d0
98 ! s, pz, dz2, fz3
99 g(1)=f(0)
100 if (l == 0) return
101 ! px, dxz, fxz2
102 g(2)=c1*(f(-1)-f(1))
103 ! py, dyz, fyz2
104 g(3)=-c1*zi*(f(-1)+f(1))
105 if (l == 1) return
106 ! dx2-y2, fz(x2-y2)
107 g(4)=c1*(f(-2)+f(2))
108 ! dxy, fxyz
109 g(5)=c1*zi*(f(2)-f(-2))
110 if (l == 2) return
111 ! fx(x2-3y2)
112 g(6)=c1*(f(-3)-f(3))
113 ! fy(3x2-y2)
114 g(7)=-c1*zi*(f(-3)+f(3))
115 end subroutine
116 
117 end subroutine
118 
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:1288
integer, dimension(maxspecies) nprojw90
Definition: modw90.f90:30
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:880
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:32
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:1227
real(8), parameter fourpi
Definition: modmain.f90:1221
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 nstfv
Definition: modmain.f90:878
integer nspnfv
Definition: modmain.f90:289
integer, dimension(4, maxspecies) lprojw90
Definition: modw90.f90:28
pure subroutine ftogw90(l, f, g)
Definition: projkw90.f90:91
integer lmaxi
Definition: modmain.f90:205