evaldos.f90 19.9 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)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
!----------------------------------------------------------------------
!
!     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)
!
!----------------------------------------------------------------------
Gregor Michalicek's avatar
Gregor Michalicek committed
22
      USE m_eig66_io,ONLY:read_dos
23 24 25 26 27 28 29
      USE m_triang
      USE m_maketetra
      USE m_tetrados
      USE m_dosbin
      USE m_ptdos
      USE m_smooth
      USE m_types
30 31
      USE m_constants
      USE m_cdn_io
32
      IMPLICIT NONE
33
      INTEGER,INTENT(IN)             :: eig_id
34 35 36 37 38 39 40 41
      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
42 43
      TYPE(t_results),INTENT(IN)     :: results
      TYPE(t_dos),INTENT(IN)         :: dos
Gregor Michalicek's avatar
Gregor Michalicek committed
44
      TYPE(t_mcd),INTENT(IN)         :: mcd
45
      TYPE(t_slab),INTENT(IN)        :: slab
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
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(:,:)
Gregor Michalicek's avatar
Gregor Michalicek committed
65
      REAL,    ALLOCATABLE :: mcd_local(:,:,:),orbcomp(:,:,:),qmtp(:,:)
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 122 123 124 125
 
      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
        e_lo =  9.9d+9 
        e_up = -9.9d+9     
        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 145 146 147 148 149 150 151 152 153 154 155
        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
!
!     initialize arrays
!
            DO n = 1,dimension%neigd
               DO i = 1,qdim
                  qal(i,n,k) = 0.
               ENDDO
               DO i = 1,vacuum%nstars*vacuum%layers*vacuum%nvac
                  qval(i,n,k) = 0.
               ENDDO
            ENDDO
Gregor Michalicek's avatar
Gregor Michalicek committed
156

157
!     read data from file!
Gregor Michalicek's avatar
Gregor Michalicek committed
158
            ntb = max(ntb,results%neig(k,jspin))
159 160 161
            ALLOCATE( orbcomp(dimension%neigd,23,atoms%nat))
            ALLOCATE( qmtp(dimension%neigd,atoms%nat))
            CALL read_dos(eig_id,k,jspin,qmtp,orbcomp)
Gregor Michalicek's avatar
Gregor Michalicek committed
162
            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
163
            IF (.NOT.l_orbcomp) THEN
164 165 166 167
               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
168
            ELSE
169
               IF (n_orb == 0) THEN
170 171
                  qal(1:slab%nsld,:,k)             = slab%qintsl(:,:,k,jspin)
                  qal(slab%nsld+1:2*slab%nsld,:,k) = slab%qmtsl(:,:,k,jspin)
172 173
               ELSE 
                  DO i = 1, 23
174
                     DO l = 1, results%neig(k,jspin)
175
                        qal(i,l,k) = orbcomp(l,i,n_orb)*qmtp(l,n_orb)/10000.
Daniel Wortmann's avatar
Daniel Wortmann committed
176
                     END DO
177
                     DO l = results%neig(k,jspin)+1, dimension%neigd
178
                        qal(i,l,k) = 0.0
Daniel Wortmann's avatar
Daniel Wortmann committed
179 180 181 182
                     END DO
                  END DO
               END IF
            END IF
183
            DEALLOCATE( orbcomp,qmtp)
184 185 186 187 188 189 190 191 192 193
!
!     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
194
               DO i = 1,results%neig(k,jspin)
195 196 197 198 199
                  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
200
                           qval(index+s,i,k) = real(dos%qstars(s,i,l,v,k,jspin))
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
                        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
!
229 230
            DO i = 1 , results%neig(k,jspin)
               ev(i,k) = results%eig(i,k,jspin)*hartree_to_ev_const - efermi
231
            ENDDO
232
            DO i = results%neig(k,jspin) + 1, dimension%neigd
233 234 235 236 237 238 239 240 241 242 243
               ev(i,k) = 9.9e+99
            ENDDO
!
!
         ENDDO                                                 ! end of k-point loop
!
!     calculate the triangles!
!
         IF ( jspin.EQ.1 ) THEN
           l_tria=.true.
           IF (input%film .AND. .NOT.oneD%odi%d1) THEN
244
             CALL triang(kpts%bk,kpts%nkpt,itria,ntria,atr,as,l_tria)
245 246 247 248 249 250 251 252
             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
253 254 255 256 257 258 259 260 261 262 263 264 265
             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
266 267 268 269 270 271 272 273 274 275 276 277
             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
278
             CALL triang(kpts%bk,kpts%nkpt,itria,ntria,atr,as,l_tria)
279 280 281 282 283 284 285 286 287 288
             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
289
               CALL make_tetra(kpts%nkpt,kpts%bk,ntria,itria,atr,&
290 291 292 293 294 295 296 297 298 299 300 301
                    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
!
        IF ( .not.l_mcd ) THEN
         ALLOCATE (g(ned,qdim))
        ELSE
Daniel Wortmann's avatar
Daniel Wortmann committed
302
         ALLOCATE (g(ned,3*atoms%ntype*ncored))
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
        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,&
320
                            itetra,efermi,voltet,e,results%neig(:,jspin), ev,qal, g)
321 322 323 324 325 326 327 328
              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,&
329
                 results%neig(:,jspin),kpts%wtkpt(1:kpts%nkpt),ev,qal, g)
330
            ELSE
Daniel Wortmann's avatar
Daniel Wortmann committed
331
            CALL dos_bin(input%jspins,3*atoms%ntype*ncored,ned,emin,emax,ntb,kpts%nkpt,&
Gregor Michalicek's avatar
Gregor Michalicek committed
332
                 results%neig(:,jspin),kpts%wtkpt(1:kpts%nkpt),ev(1:ntb,1:kpts%nkpt), mcd_local(1:3*atoms%ntype*ncored,1:ntb,1:kpts%nkpt), g)
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
            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
359 360
            DO l = 1, slab%nsld
               nl = slab%nsld+l
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
               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))

         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)
          ENDIF
       ELSEIF (n_orb == 0) THEN
387
          DO nl = 1, slab%nsld
388 389
             totdos = totdos + gpart(i,nl)
          ENDDO
390
          WRITE (18,99001)  e(i),totdos,(gpart(i,nl),nl=1,slab%nsld), (g(i,l),l=1,2*slab%nsld)
391 392 393 394 395 396 397 398 399 400
           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)

         ELSE
Gregor Michalicek's avatar
Gregor Michalicek committed
401
           write(*,'(4f15.8)') ((mcd%e_mcd(n,jspin,i),n=1,atoms%ntype),i=1,ncored)
402 403 404
           write(*,*)
           write(*,'(4f15.8)') (g(800,n),n=1,3*atoms%ntype*ncored)
           write(*,*)
Gregor Michalicek's avatar
Gregor Michalicek committed
405
           write(*,'(4f15.8)') (mcd_local(n,10,8),n=1,3*atoms%ntype*ncored)
406 407
           DO n = 1,atoms%ntype
             DO l = 1 , ned
Gregor Michalicek's avatar
Gregor Michalicek committed
408
               DO icore = 1 , mcd%ncore(n)
409 410
                 DO i = 1 , ned-1
                   IF (e(i).GT.0) THEN     ! take unoccupied part only
Gregor Michalicek's avatar
Gregor Michalicek committed
411 412
                   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
413 414 415
                   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
416 417
                       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)
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
                     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
440
                ,as,atr,2*kpts%nkpt,itria,kpts%nkpt,ev(1:ntb,1:kpts%nkpt), qval(:,1:ntb,1:kpts%nkpt),e,g)
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
            
!---- >     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
465
            eFermiCorrection = 0.0
466 467 468 469 470 471 472 473 474 475 476 477 478
            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

479
            OPEN (18,FILE='bands'//spin12(jspin))
480
            ntb = minval(results%neig(:,jspin))    
481
            kx(1) = 0.0
482
            vkr(:,1)=matmul(kpts%bk(:,1),cell%bmat)
483 484
            DO k = 2, kpts%nkpt
              
485
               vkr(:,k)=matmul(kpts%bk(:,k),cell%bmat)
486 487 488
               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)
489 490
            ENDDO
            DO i = 1, ntb
491
               DO k = 1, kpts%nkpt
492
                  write(18,'(2f15.9)') kx(k),ev(i,k)-eFermiCorrection
493
               ENDDO
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
            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
509
             DO ln = 1 , 3*atoms%ntype
510 511 512 513 514 515 516 517 518 519 520 521 522
               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

523
      DEALLOCATE(qal,qval,qlay)
Gregor Michalicek's avatar
Gregor Michalicek committed
524
      IF (l_mcd) DEALLOCATE( mcd_local )
525
99001 FORMAT (f10.5,110(1x,e10.3))
526 527 528

      END SUBROUTINE evaldos
      END MODULE m_evaldos