The Elk Code
bandstr.f90
Go to the documentation of this file.
1 
2 ! Copyright (C) 2002-2005 J. K. Dewhurst, S. Sharma and C. Ambrosch-Draxl.
3 ! This file is distributed under the terms of the GNU General Public License.
4 ! See the file COPYING for license details.
5 
6 !BOP
7 ! !ROUTINE: bandstr
8 ! !INTERFACE:
9 subroutine bandstr
10 ! !USES:
11 use modmain
12 use modomp
13 ! !DESCRIPTION:
14 ! Produces a band structure along the path in reciprocal space which connects
15 ! the vertices in the array {\tt vvlp1d}. The band structure is obtained from
16 ! the second-variational eigenvalues and is written to the file {\tt BAND.OUT}
17 ! with the Fermi energy set to zero. If required, band structures are plotted
18 ! to files {\tt BAND\_Sss\_Aaaaa.OUT} for atom {\tt aaaa} of species {\tt ss},
19 ! which include the band characters for each $l$ component of that atom in
20 ! columns 4 onwards. Column 3 contains the sum over $l$ of the characters.
21 ! Vertex location lines are written to {\tt BANDLINES.OUT}.
22 !
23 ! !REVISION HISTORY:
24 ! Created June 2003 (JKD)
25 !EOP
26 !BOC
27 implicit none
28 ! local variables
29 logical tspndg,tlmdg,tsqaz
30 integer ik,ist,ispn,idm
31 integer is,ia,ias,nthd
32 integer l,m,lm,iv
33 real(8) emin,emax,sm
34 real(8) v(ndmag),t1,t2
35 character(256) fname
36 complex(8) su2(2,2),z1
37 ! allocatable arrays
38 real(8), allocatable :: evalfv(:,:)
39 ! low precision for band character array saves memory
40 real(4), allocatable :: bc(:,:,:,:),elm(:,:)
41 complex(8), allocatable :: ulm(:,:,:),dmat(:,:,:,:,:)
42 complex(8), allocatable :: apwalm(:,:,:,:,:),evecfv(:,:,:),evecsv(:,:)
43 ! initialise universal variables
44 call init0
45 call init1
46 ! calculate only the diagonal parts of the density matrices by default
47 tspndg=.true.
48 tlmdg=.true.
49 ! spin-quantisation axis in +z direction by default
50 tsqaz=.true.
51 select case(task)
52 case(21)
53  allocate(bc(0:lmaxdb,natmtot,nstsv,nkpt))
54 case(22)
55  allocate(bc(lmmaxdb,natmtot,nstsv,nkpt))
56 ! generate unitary matrices which convert the Yₗₘ basis into the irreducible
57 ! representation basis of the symmetry group at each atomic site
58  if (lmirep) then
59  allocate(elm(lmmaxdb,natmtot),ulm(lmmaxdb,lmmaxdb,natmtot))
60  call genlmirep(elm,ulm)
61 ! write the eigenvalues of a pseudorandom matrix symmetrised by the site
62 ! symmetries in the Yₗₘ basis
63  call writeelmirep('.OUT',elm)
64 ! require full density matrix in (l,m) degrees of freedom
65  tlmdg=.false.
66  end if
67 case(23)
68  if (.not.spinpol) goto 10
69  allocate(bc(nspinor,natmtot,nstsv,nkpt))
70 ! compute the SU(2) operator used for rotating the density matrix to the
71 ! desired spin-quantisation axis; if axis is not z then the full matrix in
72 ! spin degrees of freedom is required
73  call sqasu2(sqaxis,tsqaz,su2)
74  tspndg=tsqaz
75 case(24)
76  if (.not.spinpol) goto 10
77  allocate(bc(ndmag,natmtot,nstsv,nkpt))
78  tspndg=.not.ncmag
79 end select
80 ! read density and potentials from file
81 call readstate
82 ! Fourier transform Kohn-Sham potential to G-space
83 call genvsig
84 ! find the new linearisation energies
85 call linengy
86 ! generate the APW and local-orbital radial functions and integrals
87 call genapwlofr
88 ! generate the spin-orbit coupling radial functions
89 call gensocfr
90 ! begin parallel loop over k-points
91 call holdthd(nkpt,nthd)
92 !$OMP PARALLEL DEFAULT(SHARED) &
93 !$OMP PRIVATE(evalfv,evecfv,evecsv) &
94 !$OMP PRIVATE(dmat,apwalm,ispn,ias,ist) &
95 !$OMP PRIVATE(l,m,lm,sm,v,t1,t2,z1) &
96 !$OMP NUM_THREADS(nthd)
97 allocate(evalfv(nstfv,nspnfv))
98 allocate(evecfv(nmatmax,nstfv,nspnfv),evecsv(nstsv,nstsv))
99 if (task >= 21) then
100  allocate(dmat(lmmaxdb,nspinor,lmmaxdb,nspinor,nstsv))
101  allocate(apwalm(ngkmax,apwordmax,lmmaxapw,natmtot,nspnfv))
102 end if
103 !$OMP DO SCHEDULE(DYNAMIC)
104 do ik=1,nkpt
105 !$OMP CRITICAL(bandstr_)
106  write(*,'("Info(bandstr): ",I0," of ",I0," k-points")') ik,nkpt
107 !$OMP END CRITICAL(bandstr_)
108 ! solve the first- and second-variational eigenvalue equations
109  call eveqn(ik,evalfv,evecfv,evecsv)
110 ! compute the band characters if required
111  if (task >= 21) then
112 ! find the matching coefficients
113  do ispn=1,nspnfv
114  call match(ngk(ispn,ik),vgkc(:,:,ispn,ik),gkc(:,ispn,ik), &
115  sfacgk(:,:,ispn,ik),apwalm(:,:,:,:,ispn))
116  end do
117 ! average band character over spin and m for all atoms
118  do ias=1,natmtot
119 ! generate the density matrix
120  call gendmatk(tspndg,tlmdg,0,lmaxdb,ias,nstsv,[0],ngk(:,ik),apwalm, &
121  evecfv,evecsv,lmmaxdb,dmat)
122 ! convert (l,m) part to an irreducible representation if required
123  if (.not.tlmdg) call dmatulm(ulm(:,:,ias),dmat)
124 ! spin rotate the density matrices to desired spin-quantisation axis if required
125  if (.not.tsqaz) call dmatsu2(lmmaxdb,su2,dmat)
126  do ist=1,nstsv
127  select case(task)
128  case(21)
129 ! l character of band
130  lm=0
131  do l=0,lmaxdb
132  sm=0.d0
133  do m=-l,l
134  lm=lm+1
135  do ispn=1,nspinor
136  sm=sm+dble(dmat(lm,ispn,lm,ispn,ist))
137  end do
138  end do
139  bc(l,ias,ist,ik)=sm
140  end do
141  case(22)
142 ! (l,m) character of band
143  do lm=1,lmmaxdb
144  sm=0.d0
145  do ispn=1,nspinor
146  sm=sm+dble(dmat(lm,ispn,lm,ispn,ist))
147  end do
148  bc(lm,ias,ist,ik)=sm
149  end do
150  case(23)
151 ! spin character of band
152  do ispn=1,nspinor
153  sm=0.d0
154  do lm=1,lmmaxdb
155  sm=sm+dble(dmat(lm,ispn,lm,ispn,ist))
156  end do
157  bc(ispn,ias,ist,ik)=sm
158  end do
159  case(24)
160 ! magnetic moment character of band
161  v(1:ndmag)=0.d0
162  do lm=1,lmmaxdb
163  t1=dble(dmat(lm,1,lm,1,ist))
164  t2=dble(dmat(lm,2,lm,2,ist))
165  v(ndmag)=v(ndmag)+t1-t2
166  if (ncmag) then
167  z1=2.d0*dmat(lm,1,lm,2,ist)
168  v(1)=v(1)+z1%re
169  v(2)=v(2)-z1%im
170  end if
171  end do
172  bc(1:ndmag,ias,ist,ik)=v(1:ndmag)
173  end select
174  end do
175  end do
176  end if
177 ! end loop over k-points
178 end do
179 !$OMP END DO
180 deallocate(evalfv,evecfv,evecsv)
181 if (task >= 21) deallocate(dmat,apwalm)
182 !$OMP END PARALLEL
183 call freethd(nthd)
184 ! subtract the Fermi energy
186 ! find the minimum and maximum eigenvalues
187 emin=minval(evalsv(1:nstsv,1:nkpt))
188 emax=maxval(evalsv(1:nstsv,1:nkpt))
189 t1=(emax-emin)*0.5d0
190 emin=emin-t1
191 emax=emax+t1
192 ! output the band structure
193 if (task == 20) then
194  open(50,file='BAND.OUT',form='FORMATTED',action='WRITE')
195  do ist=1,nstsv
196  do ik=1,nkpt
197  write(50,'(2G18.10)') dpp1d(ik),evalsv(ist,ik)
198  end do
199  write(50,*)
200  end do
201  close(50)
202  write(*,*)
203  write(*,'("Info(bandstr):")')
204  write(*,'(" Band structure plot written to BAND.OUT")')
205 else
206  do ias=1,natmtot
207  is=idxis(ias)
208  ia=idxia(ias)
209  write(fname,'("BAND_S",I2.2,"_A",I4.4,".OUT")') is,ia
210  open(50,file=trim(fname),form='FORMATTED',action='WRITE')
211  do ist=1,nstsv
212  do ik=1,nkpt
213  select case(task)
214  case(21)
215 ! sum band character over l to find total atomic character
216  sm=sum(bc(0:lmaxdb,ias,ist,ik))
217  write(50,'(2G18.10,F12.6)',advance='NO') dpp1d(ik),evalsv(ist,ik),sm
218  do l=0,lmaxdb
219  write(50,'(F12.6)',advance='NO') bc(l,ias,ist,ik)
220  end do
221  write(50,*)
222  case(22)
223  write(50,'(2G18.10)',advance='NO') dpp1d(ik),evalsv(ist,ik)
224  do lm=1,lmmaxdb
225  write(50,'(F12.6)',advance='NO') bc(lm,ias,ist,ik)
226  end do
227  write(50,*)
228  case(23)
229  write(50,'(2G18.10,2F12.6)') dpp1d(ik),evalsv(ist,ik), &
230  (bc(ispn,ias,ist,ik),ispn=1,nspinor)
231  case(24)
232  write(50,'(2G18.10,3F12.6)') dpp1d(ik),evalsv(ist,ik), &
233  (bc(idm,ias,ist,ik),idm=1,ndmag)
234  end select
235  end do
236  write(50,*)
237  end do
238  close(50)
239  end do
240  write(*,*)
241  write(*,'("Info(bandstr):")')
242  write(*,'(" Band structure plot written to BAND_Sss_Aaaaa.OUT")')
243  write(*,'(" for all species and atoms")')
244  write(*,*)
245  write(*,'(" Columns in the file are :")')
246  select case(task)
247  case(21)
248  write(*,'(" distance, eigenvalue, total atomic character, l character &
249  &(l = 0...",I0,")")') lmaxdb
250  case(22)
251  write(*,'(" distance, eigenvalue, (l,m) character &
252  &(l = 0...",I0,", m = -l...l)")') lmaxdb
253  if (lmirep) then
254  write(*,*)
255  write(*,'(" Eigenvalues of a random matrix symmetrised with the site")')
256  write(*,'(" symmetries in the Yₗₘ basis written to ELMIREP.OUT for all")')
257  write(*,'(" species and atoms. Degenerate eigenvalues correspond to")')
258  write(*,'(" irreducible representations of each site symmetry group")')
259  end if
260  case(23)
261  write(*,'(" distance, eigenvalue, spin-up and spin-down characters")')
262  write(*,*)
263  write(*,'(" Spin-quantisation axis : ",3G18.10)') sqaxis(:)
264  case(24)
265  write(*,'(" distance, eigenvalue, moment character")')
266  end select
267 end if
268 write(*,*)
269 write(*,'(" Fermi energy is at zero in plot")')
270 ! output the vertex location lines
271 open(50,file='BANDLINES.OUT',form='FORMATTED',action='WRITE')
272 do iv=1,nvp1d
273  write(50,'(2G18.10)') dvp1d(iv),emin
274  write(50,'(2G18.10)') dvp1d(iv),emax
275  write(50,*)
276 end do
277 close(50)
278 write(*,*)
279 write(*,'(" Vertex location lines written to BANDLINES.OUT")')
280 if (task >= 21) deallocate(bc)
281 if ((task == 22).and.lmirep) deallocate(elm,ulm)
282 return
283 10 continue
284 write(*,*)
285 write(*,'("Error(bandstr): spin-unpolarised calculation")')
286 write(*,*)
287 stop
288 end subroutine
289 !EOC
290 
integer nmatmax
Definition: modmain.f90:849
real(8) efermi
Definition: modmain.f90:898
real(8), dimension(:,:), allocatable evalsv
Definition: modmain.f90:910
integer task
Definition: modmain.f90:1286
logical spinpol
Definition: modmain.f90:228
integer lmmaxapw
Definition: modmain.f90:199
integer nkpt
Definition: modmain.f90:461
integer ngkmax
Definition: modmain.f90:499
real(8), dimension(:), allocatable dpp1d
Definition: modmain.f90:1113
subroutine match(ngp, vgpc, gpc, sfacgp, apwalm)
Definition: match.f90:10
Definition: modomp.f90:6
subroutine dmatulm(ulm, dmat)
Definition: dmatulm.f90:10
subroutine sqasu2(sqaxis, tsqaz, su2)
Definition: sqasu2.f90:7
subroutine bandstr
Definition: bandstr.f90:10
subroutine genvsig
Definition: genvsig.f90:10
subroutine genapwlofr
Definition: genapwlofr.f90:7
subroutine gensocfr
Definition: gensocfr.f90:10
complex(8), dimension(:,:,:,:), allocatable sfacgk
Definition: modmain.f90:509
subroutine linengy
Definition: linengy.f90:10
subroutine genlmirep(elm, ulm)
Definition: genlmirep.f90:10
integer lmmaxdb
Definition: modmain.f90:1070
integer nstsv
Definition: modmain.f90:880
integer, dimension(:,:), allocatable ngk
Definition: modmain.f90:497
real(8), dimension(:), allocatable dvp1d
Definition: modmain.f90:1109
logical lmirep
Definition: modmain.f90:1087
real(8), dimension(3) sqaxis
Definition: modmain.f90:1090
subroutine eveqn(ik, evalfv, evecfv, evecsv)
Definition: eveqn.f90:10
integer lmaxdb
Definition: modmain.f90:1070
integer nspinor
Definition: modmain.f90:267
real(8), dimension(:,:,:,:), allocatable vgkc
Definition: modmain.f90:505
subroutine init1
Definition: init1.f90:10
subroutine gendmatk(tspndg, tlmdg, lmin, lmax, ias, nst, idx, ngp, apwalm, evecfv, evecsv, ld, dmat)
Definition: gendmatk.f90:8
integer apwordmax
Definition: modmain.f90:758
integer, dimension(maxatoms *maxspecies) idxis
Definition: modmain.f90:44
real(8), dimension(:,:,:), allocatable gkc
Definition: modmain.f90:507
subroutine writeelmirep(fext, elm)
Definition: writeelmirep.f90:7
subroutine readstate
Definition: readstate.f90:10
subroutine freethd(nthd)
Definition: modomp.f90:112
subroutine holdthd(nloop, nthd)
Definition: modomp.f90:78
integer, dimension(maxatoms *maxspecies) idxia
Definition: modmain.f90:45
subroutine init0
Definition: init0.f90:10
integer natmtot
Definition: modmain.f90:40
logical ncmag
Definition: modmain.f90:240
subroutine dmatsu2(lmmax, su2, dmat)
Definition: dmatsu2.f90:10
integer nvp1d
Definition: modmain.f90:1103
integer nstfv
Definition: modmain.f90:878
integer nspnfv
Definition: modmain.f90:289