evaldos.f90 20.3 KB
Newer Older
1 2
      MODULE m_evaldos
      CONTAINS
3 4
      SUBROUTINE evaldos(eig_id,input,banddos,vacuum,kpts,atoms,sym,noco,oneD,cell,results,dos,&
                         dimension,efermiarg,bandgap,l_mcd,ncore,e_mcd,nsld)
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)
!
!----------------------------------------------------------------------
22
      USE m_eig66_io,ONLY:read_dos,read_eig
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
44 45 46 47
      TYPE(t_kpts),INTENT(IN)        :: kpts
      TYPE(t_atoms),INTENT(IN)       :: atoms

      INTEGER, INTENT(IN) :: nsld
48
      REAL,    INTENT(IN) :: efermiarg, bandgap
49 50
      LOGICAL, INTENT(IN) :: l_mcd 

51 52
      INTEGER, INTENT(IN) :: ncore(atoms%ntype)!(ntype)
      REAL,    INTENT(IN) :: e_mcd(atoms%ntype,input%jspins,dimension%nstd) 
53 54 55 56 57
!-odim
!+odim 
!    locals
      INTEGER, PARAMETER ::  lmax= 4, ned = 1301
      INTEGER  i,s,v,index,jspin,k,l,l1,l2,ln,n,nl,ntb,ntria,ntetra
58
      INTEGER  icore,qdim,n_orb,ncored
59 60 61
      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
62 63 64

      INTEGER  itria(3,2*kpts%nkpt),nevk(kpts%nkpt),itetra(4,6*kpts%nkpt)
      INTEGER, ALLOCATABLE :: ksym(:),jsym(:)
65
      REAL     voltet(6*kpts%nkpt),kx(kpts%nkpt),vkr(3,kpts%nkpt)
Daniel Wortmann's avatar
Daniel Wortmann committed
66 67
      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)
68
      REAL,    ALLOCATABLE :: qal(:,:,:),qval(:,:,:),qlay(:,:,:),g(:,:),qal_tmp(:,:,:),qis(:),qvlay(:,:,:)
69 70 71 72 73 74 75
      REAL,    ALLOCATABLE :: mcd(:,:,:),orbcomp(:,:,:),qmtp(:,:)
      REAL,    ALLOCATABLE :: qintsl(:,:),qmtsl(:,:),qvac(:,:)
      COMPLEX, ALLOCATABLE :: qstars(:,:,:,:)
      CHARACTER(len=2) :: spin12(2),ch_mcd(3)
      CHARACTER(len=8) :: chntype*2,chform*19
      DATA spin12/'.1' , '.2'/
      DATA ch_mcd/'.+' , '.-' , '.0'/
76 77

      ncored =  MAX(0,MAXVAL(ncore))
Daniel Wortmann's avatar
Daniel Wortmann committed
78 79 80
      qdim = lmax*atoms%ntype+3
      l_orbcomp = banddos%l_orb
      IF (banddos%ndir.EQ.-3) THEN
81 82
        qdim = 2*nsld 
        n_orb = 0
Daniel Wortmann's avatar
Daniel Wortmann committed
83 84 85 86 87
        IF (banddos%l_orb) THEN
           n_orb = banddos%orbCompAtom
           WRITE (*,*) 'DOS: orbcomp',n_orb
           qdim = 23
        END IF
88
      ENDIF
Daniel Wortmann's avatar
Daniel Wortmann committed
89 90
      ALLOCATE( qal(qdim,dimension%neigd,kpts%nkpt),&
     &          qval(vacuum%nstars*vacuum%layers*vacuum%nvac,dimension%neigd,kpts%nkpt),&
91
     &          qlay(dimension%neigd,vacuum%layerd,2),qstars(vacuum%nstars,dimension%neigd,vacuum%layerd,2))
92 93 94 95 96
      IF (l_mcd) THEN 
         ALLOCATE( mcd(3*atoms%ntype*ncored,dimension%neigd,kpts%nkpt) )
      ELSE
         ALLOCATE(mcd(0,0,0))
      ENDIF
97 98
!
! scale energies
99 100 101 102
      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
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
 
      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
            DO icore = 1 , ncore(n)
              e_lo = min(e_mcd(n,jspin,icore),e_lo)
              e_up = max(e_mcd(n,jspin,icore),e_up)
            ENDDO
          ENDDO
        ENDDO
137 138
        e_lo = e_lo*hartree_to_ev_const - efermi - emax 
        e_up = e_up*hartree_to_ev_const - efermi
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
        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
!
162
!     read data from file!
163 164
!
            ALLOCATE( ksym(dimension%neigd),jsym(dimension%neigd) )
165
            ALLOCATE( qal_tmp(1:lmax,atoms%ntype,dimension%neigd))
Daniel Wortmann's avatar
Daniel Wortmann committed
166 167
            ALLOCATE( orbcomp(dimension%neigd,23,atoms%nat),qintsl(nsld,dimension%neigd))
            ALLOCATE( qmtsl(nsld,dimension%neigd),qmtp(dimension%neigd,atoms%nat),qvac(dimension%neigd,2))
168
            ALLOCATE( qis(dimension%neigd),qvlay(dimension%neigd,vacuum%layerd,2))
169
            CALL read_eig(eig_id,k,jspin,neig=nevk(k),eig=ev(:,k))
170
            CALL read_dos(eig_id,k,jspin,qal_tmp,qvac,qis,qvlay,qstars,ksym,jsym,mcd,qintsl,qmtsl,qmtp,orbcomp)
Daniel Wortmann's avatar
Daniel Wortmann committed
171 172 173 174 175 176
            IF (.NOT.l_orbcomp) THEN
               qal(1:lmax*atoms%ntype,:,k)=reshape(qal_tmp,(/lmax*atoms%ntype,size(qal_tmp,3)/))
               qal(lmax*atoms%ntype+2,:,k)=qvac(:,1)         ! vacuum 1
               qal(lmax*atoms%ntype+3,:,k)=qvac(:,2)         ! vacuum 2
               qal(lmax*atoms%ntype+1,:,k)=qis              ! interstitial
            ELSE
177 178 179 180 181 182 183
               IF (n_orb == 0) THEN
                  qal(1:nsld,:,k)        = qintsl(:,:)
                  qal(nsld+1:2*nsld,:,k) = qmtsl(:,:)
               ELSE 
                  DO i = 1, 23
                     DO l = 1, nevk(k)
                        qal(i,l,k) = orbcomp(l,i,n_orb)*qmtp(l,n_orb)/10000.
Daniel Wortmann's avatar
Daniel Wortmann committed
184
                     END DO
185 186
                     DO l = nevk(k)+1, dimension%neigd
                        qal(i,l,k) = 0.0
Daniel Wortmann's avatar
Daniel Wortmann committed
187 188 189 190 191
                     END DO
                  END DO
               END IF
            END IF
            DEALLOCATE( ksym,jsym )
192
            DEALLOCATE( orbcomp,qintsl,qmtsl,qmtp,qvac,qis,qal_tmp,qvlay)
193 194 195 196 197 198 199 200 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 229 230 231 232 233 234 235 236 237 238 239
            ntb = max(ntb,nevk(k))
!
!     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
               DO i = 1,nevk(k)
                  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
                           qval(index+s,i,k) = real(qstars(s,i,l,v))
                        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
!
            DO i = 1 , nevk(k)
240
               ev(i,k) = ev(i,k)*hartree_to_ev_const - efermi
241 242 243 244 245 246 247 248 249 250 251 252 253
            ENDDO
            DO i = nevk(k) + 1, dimension%neigd
               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
254
             CALL triang(kpts%bk,kpts%nkpt,itria,ntria,atr,as,l_tria)
255 256 257 258 259 260 261 262
             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
263 264 265 266 267 268 269 270 271 272 273 274 275
             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
276 277 278 279 280 281 282 283 284 285 286 287
             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
288
             CALL triang(kpts%bk,kpts%nkpt,itria,ntria,atr,as,l_tria)
289 290 291 292 293 294 295 296 297 298
             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
299
               CALL make_tetra(kpts%nkpt,kpts%bk,ntria,itria,atr,&
300 301 302 303 304 305 306 307 308 309 310 311
                    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
312
         ALLOCATE (g(ned,3*atoms%ntype*ncored))
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
        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,&
                            itetra,efermi,voltet,e,nevk, ev,qal, g)
              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,&
339
                 nevk,kpts%wtkpt(1:kpts%nkpt),ev,qal, g)
340
            ELSE
Daniel Wortmann's avatar
Daniel Wortmann committed
341
            CALL dos_bin(input%jspins,3*atoms%ntype*ncored,ned,emin,emax,ntb,kpts%nkpt,&
342
                 nevk(1:kpts%nkpt),kpts%wtkpt(1:kpts%nkpt),ev(1:ntb,1:kpts%nkpt), mcd(1:3*atoms%ntype*ncored,1:ntb,1:kpts%nkpt), g)
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 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 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
            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
            DO l = 1 , nsld
               nl = nsld+l
               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
          DO nl = 1 , nsld
             totdos = totdos + gpart(i,nl)
          ENDDO
          WRITE (18,99001)  e(i),totdos,(gpart(i,nl),nl=1,nsld), (g(i,l),l=1,2*nsld)
           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
           write(*,'(4f15.8)') ((e_mcd(n,jspin,i),n=1,atoms%ntype),i=1,ncored)
           write(*,*)
           write(*,'(4f15.8)') (g(800,n),n=1,3*atoms%ntype*ncored)
           write(*,*)
           write(*,'(4f15.8)') (mcd(n,10,8),n=1,3*atoms%ntype*ncored)
           DO n = 1,atoms%ntype
             DO l = 1 , ned
               DO icore = 1 , ncore(n)
                 DO i = 1 , ned-1
                   IF (e(i).GT.0) THEN     ! take unoccupied part only
421 422
                   e_test1 = -e(i) - efermi +e_mcd(n,jspin,icore)*hartree_to_ev_const
                   e_test2 = -e(i+1)-efermi +e_mcd(n,jspin,icore)*hartree_to_ev_const
423 424 425
                   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
426 427
                       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)
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
                     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
450
                ,as,atr,2*kpts%nkpt,itria,kpts%nkpt,ev(1:ntb,1:kpts%nkpt), qval(:,1:ntb,1:kpts%nkpt),e,g)
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
            
!---- >     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
475
            eFermiCorrection = 0.0
476 477 478 479 480 481 482 483 484 485 486 487 488
            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

489 490 491
            OPEN (18,FILE='bands'//spin12(jspin))
            ntb = minval(nevk(:))    
            kx(1) = 0.0
492
            vkr(:,1)=matmul(kpts%bk(:,1),cell%bmat)
493 494
            DO k = 2, kpts%nkpt
              
495
               vkr(:,k)=matmul(kpts%bk(:,k),cell%bmat)
496 497 498
               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)
499 500
            ENDDO
            DO i = 1, ntb
501
               DO k = 1, kpts%nkpt
502
                  write(18,'(2f15.9)') kx(k),ev(i,k)-eFermiCorrection
503
               ENDDO
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
            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
519
             DO ln = 1 , 3*atoms%ntype
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
               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

      DEALLOCATE(qal,qval,qlay,qstars)
      IF (l_mcd) DEALLOCATE( mcd )
535
99001 FORMAT (f10.5,110(1x,e10.3))
536 537 538

      END SUBROUTINE evaldos
      END MODULE m_evaldos