evaldos.f90 19.8 KB
Newer Older
1 2
      MODULE m_evaldos
      CONTAINS
3
      SUBROUTINE evaldos(eig_id,input,banddos,vacuum,kpts,atoms,sym,noco,oneD,cell,results,dos,&
4
                         dimension,efermiarg,bandgap,l_mcd,mcd,slab,orbcomp)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
!----------------------------------------------------------------------
!
!     vk: k-vectors
!     wk weight of k-point (not used)
!     nevk no of eigenvalues
!     ev eigenvalue
!     qal partial charges
!             partial charge interstitial: qal(lmax*ntype+1...
!             partial charge vacuum      : qal(lmax*ntype+2...
!     qlay,qstar read in vacuum charges
!     qval partial charges in the vacuum
!             qval(m*nstars,neigd,nkptd):charge in m'th layer
!             qval(m*nstars+nstars,... ):star-resolved charge of that layer
!             qval(layers*nstars+....  ):same for second vacuum
!     ntb=max(nevk)
!
!----------------------------------------------------------------------
      USE m_triang
      USE m_maketetra
      USE m_tetrados
      USE m_dosbin
      USE m_ptdos
      USE m_smooth
      USE m_types
29 30
      USE m_constants
      USE m_cdn_io
31
      IMPLICIT NONE
32
      INTEGER,INTENT(IN)             :: eig_id
33 34 35 36 37 38 39 40
      TYPE(t_dimension),INTENT(IN)   :: dimension
      TYPE(t_oneD),INTENT(IN)        :: oneD
      TYPE(t_banddos),INTENT(IN)     :: banddos
      TYPE(t_input),INTENT(IN)       :: input
      TYPE(t_vacuum),INTENT(IN)      :: vacuum
      TYPE(t_noco),INTENT(IN)        :: noco
      TYPE(t_sym),INTENT(IN)         :: sym
      TYPE(t_cell),INTENT(IN)        :: cell
41 42
      TYPE(t_results),INTENT(IN)     :: results
      TYPE(t_dos),INTENT(IN)         :: dos
Gregor Michalicek's avatar
Gregor Michalicek committed
43
      TYPE(t_mcd),INTENT(IN)         :: mcd
44
      TYPE(t_slab),INTENT(IN)        :: slab
45
      TYPE(t_orbcomp),INTENT(IN)     :: orbcomp
46 47 48
      TYPE(t_kpts),INTENT(IN)        :: kpts
      TYPE(t_atoms),INTENT(IN)       :: atoms

49
      REAL,    INTENT(IN) :: efermiarg, bandgap
50
      LOGICAL, INTENT(IN) :: l_mcd 
Gregor Michalicek's avatar
Gregor Michalicek committed
51
 
52 53 54
!    locals
      INTEGER, PARAMETER ::  lmax= 4, ned = 1301
      INTEGER  i,s,v,index,jspin,k,l,l1,l2,ln,n,nl,ntb,ntria,ntetra
55
      INTEGER  icore,qdim,n_orb,ncored,jsp
56 57 58
      REAL     as,de,efermi,emax,emin,qmt,sigma,totdos,efermiPrev
      REAL     e_up,e_lo,e_test1,e_test2,fac,sumwei,dk,eFermiCorrection
      LOGICAL  l_tria,l_orbcomp,l_error
59

60
      INTEGER  itria(3,2*kpts%nkpt),itetra(4,6*kpts%nkpt)
61
      REAL     voltet(6*kpts%nkpt),kx(kpts%nkpt),vkr(3,kpts%nkpt)
Daniel Wortmann's avatar
Daniel Wortmann committed
62 63
      REAL     ev(dimension%neigd,kpts%nkpt),e(ned),gpart(ned,atoms%ntype),atr(2*kpts%nkpt)
      REAL     e_grid(ned+1),spect(ned,3*atoms%ntype),ferwe(dimension%neigd,kpts%nkpt)
64
      REAL,    ALLOCATABLE :: qal(:,:,:),qval(:,:,:),qlay(:,:,:),g(:,:)
65
      REAL,    ALLOCATABLE :: mcd_local(:,:,:)
66
      REAL,    ALLOCATABLE :: qvac(:,:)
67 68 69 70
      CHARACTER(len=2) :: spin12(2),ch_mcd(3)
      CHARACTER(len=8) :: chntype*2,chform*19
      DATA spin12/'.1' , '.2'/
      DATA ch_mcd/'.+' , '.-' , '.0'/
71

Gregor Michalicek's avatar
Gregor Michalicek committed
72
      ncored =  MAX(0,MAXVAL(mcd%ncore))
Daniel Wortmann's avatar
Daniel Wortmann committed
73 74 75
      qdim = lmax*atoms%ntype+3
      l_orbcomp = banddos%l_orb
      IF (banddos%ndir.EQ.-3) THEN
76
        qdim = 2*slab%nsld 
77
        n_orb = 0
Daniel Wortmann's avatar
Daniel Wortmann committed
78 79 80 81 82
        IF (banddos%l_orb) THEN
           n_orb = banddos%orbCompAtom
           WRITE (*,*) 'DOS: orbcomp',n_orb
           qdim = 23
        END IF
83
      ENDIF
Daniel Wortmann's avatar
Daniel Wortmann committed
84 85
      ALLOCATE( qal(qdim,dimension%neigd,kpts%nkpt),&
     &          qval(vacuum%nstars*vacuum%layers*vacuum%nvac,dimension%neigd,kpts%nkpt),&
86
     &          qlay(dimension%neigd,vacuum%layerd,2))
87
      IF (l_mcd) THEN 
Gregor Michalicek's avatar
Gregor Michalicek committed
88
         ALLOCATE(mcd_local(3*atoms%ntype*ncored,dimension%neigd,kpts%nkpt) )
89
      ELSE
Gregor Michalicek's avatar
Gregor Michalicek committed
90
         ALLOCATE(mcd_local(0,0,0))
91
      ENDIF
92 93
!
! scale energies
94 95 96 97
      sigma = banddos%sig_dos*hartree_to_ev_const
      emin =min(banddos%e1_dos*hartree_to_ev_const,banddos%e2_dos*hartree_to_ev_const)
      emax =max(banddos%e1_dos*hartree_to_ev_const,banddos%e2_dos*hartree_to_ev_const)
      efermi = efermiarg*hartree_to_ev_const
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
 
      WRITE (6,'(a)') 'DOS-Output is generated!'

      IF ( NINT((emax - emin)/sigma) > ned ) THEN
        WRITE(6,*) 'sig_dos too small for DOS smoothing:'   
        WRITE(6,*) 'Reduce energy window or enlarge banddos%sig_dos!'
        WRITE(6,*) 'For now: setting sigma to zero !'
        sigma = 0.0
      ENDIF

      WRITE (6,*) 'sigma=   ' , sigma
      WRITE (6,*) 'emax=   ' , emax
      WRITE (6,*) 'emin=   ' , emin
      WRITE (6,*) 'ef_inp=   ' , efermi
!
!     create energy grid
      emax = emax - efermi
      emin = emin - efermi
      de = (emax-emin)/(ned-1)
      DO i=1,ned
         e(i) = emin + (i-1)*de
      ENDDO
 
      IF ( l_mcd ) THEN ! create an energy grid for mcd-spectra
Matthias Redies's avatar
Matthias Redies committed
122 123
        e_lo =  9.9*10.0**9 
        e_up = -9.9*10.0**9     
124 125
        DO jspin = 1,input%jspins
          DO n = 1,atoms%ntype
Gregor Michalicek's avatar
Gregor Michalicek committed
126 127 128
            DO icore = 1 , mcd%ncore(n)
              e_lo = min(mcd%e_mcd(n,jspin,icore),e_lo)
              e_up = max(mcd%e_mcd(n,jspin,icore),e_up)
129 130 131
            ENDDO
          ENDDO
        ENDDO
132 133
        e_lo = e_lo*hartree_to_ev_const - efermi - emax 
        e_up = e_up*hartree_to_ev_const - efermi
134 135 136 137 138 139 140 141 142 143 144
        de = (e_up-e_lo)/(ned-1)
        DO i=1,ned
          e_grid(i) = e_lo + (i-1)*de
          spect(i,:) = 0.0
        ENDDO
        e_grid(ned+1) = e_lo + ned*de
      ENDIF

      DO jspin = 1,input%jspins
         ntb = 0
         DO k = 1,kpts%nkpt
Gregor Michalicek's avatar
Gregor Michalicek committed
145

146 147 148
            qal(:,:,k) = 0.0
            qval(:,:,k) = 0.0

149 150
            jsp = MERGE(1,jspin,noco%l_noco)
            ntb = max(ntb,results%neig(k,jsp))
Gregor Michalicek's avatar
Gregor Michalicek committed
151
            IF (l_mcd) mcd_local(:,:,k) = RESHAPE(mcd%mcd(:,1:ncored,:,k,jspin),(/3*atoms%ntype*ncored,dimension%neigd/))
Daniel Wortmann's avatar
Daniel Wortmann committed
152
            IF (.NOT.l_orbcomp) THEN
153 154 155 156
               qal(1:lmax*atoms%ntype,:,k)=reshape(dos%qal(0:,:,:,k,jspin),(/lmax*atoms%ntype,size(dos%qal,3)/))
               qal(lmax*atoms%ntype+2,:,k)=dos%qvac(:,1,k,jspin) ! vacuum 1
               qal(lmax*atoms%ntype+3,:,k)=dos%qvac(:,2,k,jspin) ! vacuum 2
               qal(lmax*atoms%ntype+1,:,k)=dos%qis(:,k,jspin)    ! interstitial
Daniel Wortmann's avatar
Daniel Wortmann committed
157
            ELSE
158
               IF (n_orb == 0) THEN
159 160
                  qal(1:slab%nsld,:,k)             = slab%qintsl(:,:,k,jspin)
                  qal(slab%nsld+1:2*slab%nsld,:,k) = slab%qmtsl(:,:,k,jspin)
161
               ELSE
162
                  DO i = 1, 23
163
                     DO l = 1, results%neig(k,jsp)
164
                        qal(i,l,k) = orbcomp%comp(l,i,n_orb,k,jspin)*orbcomp%qmtp(l,n_orb,k,jspin)/10000.
Daniel Wortmann's avatar
Daniel Wortmann committed
165
                     END DO
166
                     DO l = results%neig(k,jsp)+1, dimension%neigd
167
                        qal(i,l,k) = 0.0
Daniel Wortmann's avatar
Daniel Wortmann committed
168 169 170 171
                     END DO
                  END DO
               END IF
            END IF
172 173 174 175 176 177 178 179 180 181
!
!     set vacuum partial charge zero, if bulk calculation
!     otherwise, write vacuum charge in correct arrays
!
            IF ((.NOT.input%film).AND.(banddos%ndir.NE.-3)) THEN
               DO n = 1,dimension%neigd
                  qal(lmax*atoms%ntype+2,n,k) = 0.0
                  qal(lmax*atoms%ntype+3,n,k) = 0.0
               ENDDO
            ELSEIF ( banddos%vacdos .and. input%film ) THEN
182
               DO i = 1,results%neig(k,jsp)
183 184 185 186 187
                  DO v = 1,vacuum%nvac
                     DO l = 1,vacuum%layers
                        index = (l-1)*vacuum%nstars + (v-1)*(vacuum%nstars*vacuum%layers) + 1
                        qval(index,i,k) = qlay(i,l,v)
                        DO s = 1,vacuum%nstars - 1
188
                           qval(index+s,i,k) = real(dos%qstars(s,i,l,v,k,jspin))
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
                        ENDDO
                     ENDDO
                  ENDDO
               ENDDO
            ENDIF
!
!     calculate interstitial dos if not noco
!     in the noco case, qis has been calculated in pwden and is read in from tmp_dos
!
            IF ((.NOT.noco%l_noco).AND.(banddos%ndir.NE.-3)) THEN
               DO i = 1 , dimension%neigd
                  qal(lmax*atoms%ntype+1,i,k) = 1.
                  DO nl = 1 , atoms%ntype
                     l1 = lmax*(nl-1) + 1
                     l2 = lmax*nl
                     qmt=0.0
                     DO l = l1 , l2
                        qmt = qmt + qal(l,i,k)*atoms%neq(nl)
                     ENDDO
                     qal(lmax*atoms%ntype+1,i,k) = qal(lmax*atoms%ntype+1,i,k) - qmt
                  ENDDO
                  qal(lmax*atoms%ntype+1,i,k) = qal(lmax*atoms%ntype+1,i,k)&
                       -qal(lmax*atoms%ntype+2,i,k)*(3-vacuum%nvac) -qal(lmax*atoms%ntype+3,i,k)*(vacuum%nvac-1) 
               ENDDO
            ENDIF
!
!---- >     convert eigenvalues to ev and shift them by efermi
!
217 218
            DO i = 1 , results%neig(k,jsp)
               ev(i,k) = results%eig(i,k,jsp)*hartree_to_ev_const - efermi
219
            ENDDO
220
            DO i = results%neig(k,jsp) + 1, dimension%neigd
221 222 223 224 225 226 227 228
               ev(i,k) = 9.9e+99
            ENDDO
!
!
         ENDDO                                                 ! end of k-point loop
!
!     calculate the triangles!
!
Henning Janssen's avatar
Henning Janssen committed
229
         IF ( jspin.EQ.1 ) THEN
230 231
           l_tria=.true.
           IF (input%film .AND. .NOT.oneD%odi%d1) THEN
232
             CALL triang(kpts%bk,kpts%nkpt,itria,ntria,atr,as,l_tria)
233 234 235 236 237 238 239 240
             IF (sym%invs) THEN
               IF (abs(sym%nop2*as-0.5).GT.0.000001) l_tria=.false.
             ELSE
               IF (abs(sym%nop2*as-1.0).GT.0.000001) l_tria=.false.
             ENDIF
             write(*,*) as,sym%nop2,l_tria
!             l_tria=.true.
           ELSE
Gregor Michalicek's avatar
Gregor Michalicek committed
241 242 243 244 245 246 247 248 249 250 251 252 253
             IF (input%l_inpXML) THEN
                IF (input%tria) THEN
                   ntetra = kpts%ntet
                   DO i = 1, ntetra
                      itetra(1:4,i) = kpts%ntetra(1:4,i)
                      voltet(i) = kpts%voltet(i) / ntetra
                   END DO
                   l_tria = input%tria
                   GOTO 67
                ELSE
                   GOTO 66
                END IF
             END IF
254 255 256 257 258 259 260 261 262 263 264 265
             OPEN (41,file='kpts',FORM='formatted',STATUS='old')
             DO i = 1, kpts%nkpt+1
                READ (41,*,END=66,ERR=66)
             ENDDO
             READ (41,'(i5)',END=66,ERR=66) ntetra
             READ (41,'(4(4i6,4x))') ((itetra(i,k),i=1,4),k=1,ntetra)
             READ (41,'(4f20.13)') (voltet(k),k=1,ntetra)
             CLOSE(41)
             voltet(1:ntetra) = voltet(1:ntetra) / ntetra
             l_tria=.true.
             GOTO 67
 66          CONTINUE                       ! no tetrahedron-information of file
266
             CALL triang(kpts%bk,kpts%nkpt,itria,ntria,atr,as,l_tria)
267 268 269 270 271 272 273 274 275 276
             l_tria=.true.
! YM: tetrahedrons is not the way in 1D
             IF (oneD%odi%d1) as = 0.0         
             IF (sym%invs) THEN
               IF (abs(sym%nop2*as-1.0).GT.0.000001) l_tria=.false.
             ELSE
               IF (abs(sym%nop2*as-0.5).GT.0.000001) l_tria=.false.
             ENDIF

             IF (l_tria) THEN
277
               CALL make_tetra(kpts%nkpt,kpts%bk,ntria,itria,atr,&
278 279 280 281 282 283 284 285
                    ntetra,itetra,voltet)
             ELSE
               WRITE (6,*) 'no tetrahedron method with these k-points!'
               WRITE (6,*) sym%nop2,as
             ENDIF
 67          CONTINUE                       ! tetrahedron-information read or created
           ENDIF
         ENDIF
286

287 288 289 290
!
        IF ( .not.l_mcd ) THEN
         ALLOCATE (g(ned,qdim))
        ELSE
Daniel Wortmann's avatar
Daniel Wortmann committed
291
         ALLOCATE (g(ned,3*atoms%ntype*ncored))
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
        ENDIF
!
         IF ( l_tria.and.(.not.l_mcd).and.(banddos%ndir.NE.-3) ) THEN
!
!     DOS calculation: use triangular method!!
!
            IF ( input%film ) THEN
!             CALL ptdos(
!    >                  emin,emax,jspins,ned,qdim,neigd,
!    >                  ntria,as,atr,2*nkpt,itria,nkpt,ev,qal,e,
!    <                  g)
              CALL ptdos(emin,emax,input%jspins,ned,qdim,ntb,ntria,as,&
                        atr,2*kpts%nkpt,itria,kpts%nkpt,ev(1:ntb,1:kpts%nkpt),&
                        qal(:,1:ntb,1:kpts%nkpt),e, g)
            ELSE
              write(*,*) efermi
              CALL tetra_dos(lmax,atoms%ntype,dimension%neigd,ned,ntetra,kpts%nkpt,&
309
                            itetra,efermi,voltet,e,results%neig(:,jsp), ev,qal, g)
310 311 312 313 314 315 316 317
              IF (input%jspins.EQ.1) g(:,:) = 2 * g(:,:)
            ENDIF
         ELSE
!
!     DOS calculation: use histogram method
!
            IF ( .not.l_mcd ) THEN
            CALL dos_bin(input%jspins,qdim,ned,emin,emax,dimension%neigd,kpts%nkpt,&
318
                 results%neig(:,jsp),kpts%wtkpt(1:kpts%nkpt),ev,qal, g)
319
            ELSE
Daniel Wortmann's avatar
Daniel Wortmann committed
320
            CALL dos_bin(input%jspins,3*atoms%ntype*ncored,ned,emin,emax,ntb,kpts%nkpt,&
321
                 results%neig(:,jsp),kpts%wtkpt(1:kpts%nkpt),ev(1:ntb,1:kpts%nkpt), mcd_local(1:3*atoms%ntype*ncored,1:ntb,1:kpts%nkpt), g)
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
            ENDIF
         ENDIF
!
!---- >     smoothening
!
         IF ( .not.l_mcd ) THEN
            IF ( sigma.GT.0.0 ) THEN
              DO ln = 1 , qdim
                CALL smooth(e,g(1,ln),sigma,ned)
              ENDDO
            ENDIF
 
!*** sum up for all atoms
 
         IF (banddos%ndir.NE.-3) THEN
            DO l = 1 , atoms%ntype
               l1 = lmax*(l-1) + 1
               l2 = lmax*l
               DO i = 1 , ned
                  gpart(i,l) = 0.0
                  DO nl = l1 , l2
                     gpart(i,l) = gpart(i,l) + g(i,nl)
                  ENDDO
               ENDDO
            ENDDO
         ELSEIF (n_orb == 0) THEN
348 349
            DO l = 1, slab%nsld
               nl = slab%nsld+l
350 351 352 353 354 355 356 357
               DO i = 1 , ned
                  gpart(i,l) = g(i,l) + g(i,nl)
               ENDDO
            ENDDO
         ENDIF
    
!**** write out DOS
         OPEN (18,FILE='DOS'//spin12(jspin))
358
         IF (atoms%ntype >= 20.AND.banddos%projdos.NE.0) OPEN (1337,FILE="PROJDOS"//spin12(jspin))
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374

         DO i = 1 , ned
           totdos = 0.0
           IF (banddos%ndir.NE.-3) THEN
             DO nl = 1 , atoms%ntype
                totdos = totdos + gpart(i,nl)*atoms%neq(nl)
             ENDDO
             totdos = totdos + g(i,lmax*atoms%ntype+1) + g(i,lmax*atoms%ntype+2) *&
                  (3 - vacuum%nvac) + g(i,lmax*atoms%ntype+3)*(vacuum%nvac - 1)
             IF (atoms%ntype < 20) THEN
                WRITE (18,99001)  e(i),totdos,g(i,lmax*atoms%ntype+1), &
                     g(i,lmax*atoms%ntype+2),g(i,lmax*atoms%ntype+3),&
                     (gpart(i,l),l=1,atoms%ntype), (g(i,l),l=1,atoms%ntype*lmax)
             ELSE
             WRITE (18,99001)  e(i),totdos,g(i,lmax*atoms%ntype+1), &
                  g(i,lmax*atoms%ntype+2),g(i,lmax*atoms%ntype+3), (gpart(i,l),l=1,atoms%ntype)
Henning Janssen's avatar
Henning Janssen committed
375
             IF(banddos%projdos.NE.0) WRITE (1337,99001)  e(i),(g(i,l),l=lmax*(banddos%projdos-1)+1,lmax*banddos%projdos)
376 377
          ENDIF
       ELSEIF (n_orb == 0) THEN
378
          DO nl = 1, slab%nsld
379 380
             totdos = totdos + gpart(i,nl)
          ENDDO
381
          WRITE (18,99001)  e(i),totdos,(gpart(i,nl),nl=1,slab%nsld), (g(i,l),l=1,2*slab%nsld)
382 383 384 385 386 387 388 389
           ELSE
             DO nl = 1 , 23
                totdos = totdos + g(i,nl)
             ENDDO
             WRITE (18,99001)  e(i),totdos,(g(i,l),l=1,23)
           ENDIF
         ENDDO
         CLOSE (18)
390
         IF (atoms%ntype >= 20.AND.banddos%projdos.NE.0) CLOSE (1337)
391 392

         ELSE
Gregor Michalicek's avatar
Gregor Michalicek committed
393
           write(*,'(4f15.8)') ((mcd%e_mcd(n,jspin,i),n=1,atoms%ntype),i=1,ncored)
394 395 396
           write(*,*)
           write(*,'(4f15.8)') (g(800,n),n=1,3*atoms%ntype*ncored)
           write(*,*)
Gregor Michalicek's avatar
Gregor Michalicek committed
397
           write(*,'(4f15.8)') (mcd_local(n,10,8),n=1,3*atoms%ntype*ncored)
398 399
           DO n = 1,atoms%ntype
             DO l = 1 , ned
Gregor Michalicek's avatar
Gregor Michalicek committed
400
               DO icore = 1 , mcd%ncore(n)
401 402
                 DO i = 1 , ned-1
                   IF (e(i).GT.0) THEN     ! take unoccupied part only
Gregor Michalicek's avatar
Gregor Michalicek committed
403 404
                   e_test1 = -e(i) - efermi +mcd%e_mcd(n,jspin,icore)*hartree_to_ev_const
                   e_test2 = -e(i+1)-efermi +mcd%e_mcd(n,jspin,icore)*hartree_to_ev_const
405 406 407
                   IF ((e_test2.LE.e_grid(l)).AND. (e_test1.GT.e_grid(l))) THEN
                     fac = (e_grid(l)-e_test1)/(e_test2-e_test1)
                     DO k = 3*(n-1)+1,3*(n-1)+3
Daniel Wortmann's avatar
Daniel Wortmann committed
408 409
                       spect(l,k) = spect(l,k)+ g(i,3*atoms%ntype*(icore-1)+k)&
                           *(1.-fac) + fac * g(i+1,3*atoms%ntype*(icore-1)+k)
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
                     ENDDO
                   ENDIF
                   ENDIF
                 ENDDO
               ENDDO
             ENDDO
           ENDDO
           CLOSE (18) 
         ENDIF
         DEALLOCATE (g)
!         
!------------------------------------------------------------------------------
!     now calculate the VACOS
!------------------------------------------------------------------------------
            
         IF ( banddos%vacdos .and. input%film ) THEN
            ALLOCATE(g(ned,vacuum%nstars*vacuum%layers*vacuum%nvac))
!            CALL ptdos(
!     >                 emin,emax,jspins,ned,nstars*nvac*layers,neigd,
!     >                 ntria,as,atr,2*nkpt,itria,nkptd,ev,qval,e,
!     <                 g)
            CALL ptdos(emin,emax,input%jspins,ned,vacuum%nstars*vacuum%nvac*vacuum%layers,ntb,ntria&
Daniel Wortmann's avatar
Daniel Wortmann committed
432
                ,as,atr,2*kpts%nkpt,itria,kpts%nkpt,ev(1:ntb,1:kpts%nkpt), qval(:,1:ntb,1:kpts%nkpt),e,g)
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
            
!---- >     smoothening
            IF ( sigma.GT.0.0 ) THEN
               DO ln = 1 , vacuum%nstars*vacuum%nvac*vacuum%layers
                  CALL smooth(e,g(1,ln),sigma,ned)
               ENDDO
            ENDIF
            
!     write VACDOS
            
            OPEN (18,FILE='VACDOS'//spin12(jspin))
!            WRITE (18,'(i2,25(2x,i3))') Layers , (Zlay(l),l=1,Layers)
            DO i = 1 , ned
             WRITE (18,99001) e(i) , (g(i,l),l=1,vacuum%Layers*vacuum%Nstars*vacuum%Nvac)
            ENDDO
            CLOSE (18)
            DEALLOCATE(g)
         ENDIF
!
!------------------------------------------------------------------------------
!     for bandstructures
!------------------------------------------------------------------------------

         IF (banddos%ndir == -4) THEN
Gregor Michalicek's avatar
Gregor Michalicek committed
457
            eFermiCorrection = 0.0
458 459 460 461 462 463 464 465 466 467 468 469 470
            IF(bandgap.LT.(8.0*input%tkb*hartree_to_ev_const)) THEN
               CALL readPrevEFermi(eFermiPrev,l_error)
               IF(.NOT.l_error) THEN
                  WRITE(*,*) 'Fermi energy is automatically corrected in bands.* files.'
                  WRITE(*,*) 'It is consistent with last calculated density!'
                  WRITE(*,*) 'No manual correction (e.g. in band.gnu file) required.'
                  eFermiCorrection = (eFermiPrev-efermiarg)*hartree_to_ev_const
               ELSE
                  WRITE(*,*) 'Fermi energy in bands.* files may not be consistent with last density.'
                  WRITE(*,*) 'Please correct it manually (e.g. in band.gnu file).'
               END IF
            END IF

471
            OPEN (18,FILE='bands'//spin12(jspin))
472
            ntb = minval(results%neig(:,jspin))    
473
            kx(1) = 0.0
474
            vkr(:,1)=matmul(kpts%bk(:,1),cell%bmat)
475 476
            DO k = 2, kpts%nkpt
              
477
               vkr(:,k)=matmul(kpts%bk(:,k),cell%bmat)
478 479 480
               dk = (vkr(1,k)-vkr(1,k-1))**2 + (vkr(2,k)-vkr(2,k-1) )**2 + &
                    (vkr(3,k)-vkr(3,k-1))**2
               kx(k) = kx(k-1) + sqrt(dk)
481 482
            ENDDO
            DO i = 1, ntb
483
               DO k = 1, kpts%nkpt
484
                  write(18,'(2f15.9)') kx(k),ev(i,k)-eFermiCorrection
485
               ENDDO
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
            ENDDO
            CLOSE (18)
         ENDIF

      ENDDO
!         
!------------------------------------------------------------------------------
!     for MCD calculations ...
!------------------------------------------------------------------------------

      IF (l_mcd) THEN
        WRITE (chntype,'(i2)') atoms%ntype+1
        chform = '('//chntype//'f15.8)'
        IF ( sigma.GT.0.0 ) THEN
           IF ( l_mcd ) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
501
             DO ln = 1 , 3*atoms%ntype
502 503 504 505 506 507 508 509 510 511 512 513 514
               CALL smooth(e_grid,spect(1,ln),sigma,ned)
             ENDDO
           ENDIF
        ENDIF
        DO l = 1,3
          OPEN (18,FILE='MCD_SPEC'//ch_mcd(l))
          DO i = 1 , ned
          WRITE (18,FMT=chform) e_grid(i),(spect(i,3*(n-1)+l),n=1,atoms%ntype)
          ENDDO
          CLOSE (18)
        ENDDO
      ENDIF

515
      DEALLOCATE(qal,qval,qlay)
Gregor Michalicek's avatar
Gregor Michalicek committed
516
      IF (l_mcd) DEALLOCATE( mcd_local )
517
99001 FORMAT (f10.5,110(1x,e10.3))
518 519 520

      END SUBROUTINE evaldos
      END MODULE m_evaldos