wann_plot.F 16.8 KB
Newer Older
1 2 3 4 5 6
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
      MODULE m_wann_plot
      use m_juDFT
!     +++++++++++++++++++++++++++++++++++++++++++++++++
!     plots the periodic part of the wavefunction at the given k-point
!       and specified bands. Needed for real-space
!       visualization of the Wannier Functions
!     
!     if twodim = .false. a 3-D plot with nplot layers in z-direction
!     is constructed; the 3x3 matrix gives the 3 vectors of the cell ..
!     .gustav
!
!    Changed the input/output for easier use. 
!    This subroutine uses the file plot_inp for input. 
!       based on the routine by:  Juelich, 21.1.06 D.Wortmann
!            Y.Mokrousov 16.8.6 Hamburg
!
!    First of all, if xsf then the files are written in the following
!       format: k.bnd.real.jsp.xsf and k.bnd.imag.jsp.xsf
!               for reading with XCrysDen,where 
!               k is the kpoint, bnd is the band index
!               imag/real stand for the real and imaginary parts of wavefn
!               jsp stands for spin, for all the k-points and bands
!    If the xsf is false, than the files are written in the
!       format suitable for the Vanderbilt's code:
!       UNK0000k.jsp, having all the bands in this file, real and imag
!
!    Then, if xsf=true, then:
! 
!    If slice=T, the kk specifies the k-point and the nnne
!       specifies the number of the band, the wavefunction is
!       written to the file kk.nnne.real.jsp.xsf and kk.nnne.imag.jsp.xsf
!     +++++++++++++++++++++++++++++++++++++++++++++++++
      CONTAINS
      SUBROUTINE wann_plot(nv2d,jspin,odi,ods,n3d,nmzxyd,n2d,ntypsd,
     >     ntype,lmaxd,jmtd,ntypd,natd,nmzd,neq,nq3,nvac,
     >     nmz,nmzxy,nq2,nop,nop2,volint,film,slice,symor,
     >     invs,invs2,z1,delz,ngopr,ntypsy,jri,pos,zatom,
     >     lmax,mrot,tau,rmsh,invtab,amat,bmat,bbmat,ikpt,nnne,kk,
     >     nvd,nlod,llod,nv,lmd,bkpt,omtil,nlo,llo,k1,k2,k3,evac,vz,
46 47 48
     >     nslibd,nbasfcn,neigd,ff,gg,flo,acof,bcof,ccof,z,
     >     k1d,k2d,k3d,ig,ig2,sk2,phi2,l_noco,l_ss,qss,addnoco,
     >     index_kq,l_sgwf)
49 50 51 52 53 54 55 56
!    *****************************************************
      USE m_constants, ONLY : pimach
      USE m_od_types, ONLY : od_inp, od_sym
      USE m_wann_real
      USE m_xsf_io
      USE m_dotir
      USE m_wann_plot_vac
      USE m_wann_2dvacabcof
57 58
      USE m_wann_plot_od_vac
      USE m_wann_1dvacabcof
59 60 61 62 63 64 65 66 67

      IMPLICIT NONE
!     ..
!     .. Scalar Arguments ..
      INTEGER, INTENT (IN) :: n3d,nmzxyd,n2d,ntypsd,ikpt,jspin,nv2d
      INTEGER, INTENT (IN) :: lmaxd,jmtd,ntypd,natd,nmzd
      INTEGER, INTENT (IN) :: nq3,nvac,nmz,nmzxy,nq2,nop,nop2,ntype
      INTEGER, INTENT (IN) :: nvd,nv,lmd,llod,nlod
      INTEGER, INTENT (IN) :: nslibd,nbasfcn,neigd
68
      INTEGER, INTENT (IN) :: nnne,kk,addnoco,index_kq
69
      LOGICAL, INTENT (IN) :: symor,invs,slice,invs2,film
70
      LOGICAL, INTENT (IN) :: l_noco,l_ss,l_sgwf
71
      REAL,    INTENT (IN) :: z1,delz,volint,omtil
72
      REAL,    INTENT (IN) :: qss(3)
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
      real,    intent (in) :: vz(nmzd,2)
!     ..
!     .. Array Arguments ..
      INTEGER, INTENT (IN) :: ngopr(natd),ntypsy(natd),lmax(ntypd)
      INTEGER, INTENT (IN) :: jri(ntypd),neq(ntypd),mrot(3,3,nop)
      INTEGER, INTENT (IN) :: invtab(nop),nlo(ntypd),llo(nlod,ntypd)
      INTEGER, INTENT (IN) :: k1(nvd),k2(nvd),k3(nvd)
      REAL,    INTENT (IN) :: zatom(:),amat(3,3),bmat(3,3),pos(3,natd)
      REAL,    INTENT (IN) :: rmsh(jmtd,ntypd),tau(3,nop),bkpt(3)
      REAL,    INTENT (IN) :: ff(ntypd,jmtd,2,0:lmaxd),bbmat(3,3)
      REAL,    INTENT (IN) :: gg(ntypd,jmtd,2,0:lmaxd),evac(2)
      REAL,    INTENT (IN) :: flo(ntypd,jmtd,2,nlod)
      COMPLEX, INTENT (IN) :: ccof(-llod:llod,nslibd,nlod,natd)
      COMPLEX, INTENT (IN) :: acof(nslibd,0:lmd,natd)
      COMPLEX, INTENT (IN) :: bcof(nslibd,0:lmd,natd)
88 89 90
      integer, intent (in) :: k1d,k2d,k3d,ig2(n3d)
      integer, intent (in) :: ig(-k1d:k1d,-k2d:k2d,-k3d:k3d)
      real,    intent (in) :: sk2(n2d),phi2(n2d)
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
      TYPE (od_inp), INTENT (IN) :: odi
      TYPE (od_sym), INTENT (IN) :: ods
#if ( !defined(CPP_INVERSION) || defined(CPP_SOC) )
      COMPLEX, INTENT (IN) :: z(nbasfcn,neigd)
#else
      REAL, INTENT (IN) :: z(nbasfcn,neigd)
#endif
!     ..
!     .. Local Scalars ..
      integer n2,k,j,l
      REAL          :: s
      COMPLEX       :: xdnout
      INTEGER       :: i,i1,i2,i3,ii3,ix,iy,iz,na,nplo,nbn
      INTEGER       :: nbmin,nbmax,n
      INTEGER       :: nplot,nq,nt,jm,iter,ii1,ii2
      CHARACTER*8   :: dop,iop
      LOGICAL       :: twodim
!     ..
!     .. Local Arrays ..
      REAL    :: pt(3),vec1(3),vec2(3),vec3(3),zero(3)
      INTEGER :: grid(3)
      LOGICAL :: cartesian,xsf
      REAL    :: rhocc(jmtd)
      REAL    :: point(3),post(3,natd)
      CHARACTER(len=30):: filename
      CHARACTER(len=20):: name1,name2,name3
      CHARACTER(len=10):: vandername
      CHARACTER*8      :: name(10)
c     ..basis wavefunctions in the vacuum
      complex, allocatable :: ac(:,:,:),bc(:,:,:)
121
      complex, allocatable :: ac_1(:,:,:),bc_1(:,:,:)
122
      real,    allocatable :: u(:,:,:),ue(:,:,:)
123 124
      real,    allocatable :: u_1(:,:,:),ue_1(:,:,:)

125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
      integer ik,nv2,ivac,jvac
      complex factor
      real fas


      NAMELIST /plot/twodim,cartesian,vec1,vec2,vec3,grid,zero,filename
      
      intrinsic real,aimag,conjg
c      external dotirp
c      real dotirp  !module now
      IF (slice) THEN
        nbmin = nnne
        nbmax = nnne
      ELSE
        nbmin = 1
        nbmax = nslibd
      ENDIF

143 144 145 146 147 148
      !write(*,*)'in wann_plot'
      !write(*,*)'jspin:',jspin
      !write(*,*)'addnoco:',addnoco
      !write(*,*)'l_noco,l_ss: ',l_noco,l_ss
      !write(*,*)'qss:',qss

149 150 151 152 153 154 155 156 157 158 159 160 161
      INQUIRE(file ="plot_inp",exist= twodim)
      IF (.NOT.twodim) THEN !no input file exists, create a template and
                            !exit
         OPEN(20,file ="plot_inp")
         WRITE(20,'(i2,a5,l1)') 1,",xsf=",.false.
c         WRITE(20,*) "&PLOT twodim=t,cartesian=t"
c         WRITE(20,*) "  vec1(1)=10.0 vec2(2)=10.0"
c         WRITE(20,*) "  filename='plot1' /"
         WRITE(20,*) "&PLOT twodim=f,cartesian=f"
         WRITE(20,*) "  vec1(1)=1.0 vec1(2)=0.0 vec1(3)=0.0 "
         WRITE(20,*) "  vec2(1)=0.0 vec2(2)=1.0 vec2(3)=0.0 "
         WRITE(20,*) "  vec3(1)=0.0 vec3(2)=0.0 vec3(3)=1.0 "
         WRITE(20,*) "  grid(1)=30  grid(2)=30  grid(3)=30  "
162
         WRITE(20,*) "  zero(1)=0.0 zero(2)=0.0 zero(3)=0.0 "
163 164 165 166 167 168 169 170 171
         WRITE(20,*) "  filename ='plot2' /"
         CLOSE(20)
         WRITE(*,*) "No plot_inp file found. Created a template"
         CALL juDFT_error("Missing input for plot; modify plot_inp"
     +        ,calledby ="wann_plot")
      ENDIF

c make preparations for plotting in vacuum

172
      if(film.and..not.odi%d1)then
173 174 175 176 177
         allocate ( ac(nv2d,nslibd,2),bc(nv2d,nslibd,2),
     +         u(nmzd,nv2d,nvac),ue(nmzd,nv2d,nvac))
         call wann_2dvacabcof(
     >         nv2d,nslibd,nvac,nmzd,nmz,omtil,vz,nv,bkpt,z1,
     >         nvd,k1,k2,k3,evac,bbmat,delz,bmat,nbasfcn,neigd,z,
178
     <         ac,bc,u,ue,addnoco,l_ss,qss,jspin)
179
      endif
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195

      if (odi%d1)then
         allocate ( ac_1(nv2d,-odi%mb:odi%mb,nslibd),
     &              bc_1(nv2d,-odi%mb:odi%mb,nslibd),
     &              u_1(nmzd,nv2d,-odi%mb:odi%mb),
     &              ue_1(nmzd,nv2d,-odi%mb:odi%mb) )
         call wann_1dvacabcof(
     >         nv2d,nslibd,nmzd,nmz,omtil,vz(:,:),
     >         nv,bkpt,z1,odi,ods,
     >         nvd,k1,k2,k3,evac,
     >         bbmat,delz,bmat,nbasfcn,neigd,z,
     >         n2d,n3d,ig,nmzxy,nmzxyd,ig2,sk2,phi2,k1d,k2d,k3d,
     <         ac_1,bc_1,u_1,ue_1,addnoco,l_ss,qss,jspin)
      endif !preparations for vacuum   


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 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261

      !<-- Open the plot_inp file for input
      OPEN (18,file='plot_inp')
      READ(18,'(i2,5x,l1)') nplot,xsf
      ! If xsf is specified we create an input file for xcrysden
      IF (nplot.ge.2) 
     &     CALL juDFT_error
     +     ("plots one by one, please, this is not charge density"
     +     ,calledby="wann_plot")
      !<-- Loop over all plots
      DO nplo=1,nplot
         ! the defaults
         twodim = .TRUE.;cartesian=.TRUE.;grid=(/100,100,100/)
         vec1 = (/0.,0.,0./);vec2=(/0.,0.,0./);vec3=(/0.,0.,0./)
         zero = (/0.,0.,0./);filename="default"
         READ(18,plot)
         IF (twodim.AND.ANY(grid(1:2)<1)) 
     +        CALL juDFT_error("Illegal grid size in plot",calledby
     +        ="wann_plot")
         IF (.NOT.twodim.AND.ANY(grid<1)) 
     +        CALL juDFT_error("Illegal grid size in plot",calledby
     +        ="wann_plot")
         IF (twodim) grid(3) = 1
         !calculate cartesian coordinates if needed
         IF (.NOT.cartesian) THEN
            vec1=matmul(amat,vec1)
            vec2=matmul(amat,vec2)
            vec3=matmul(amat,vec3)
            zero=matmul(amat,zero)
         ENDIF
         !Open the file
         IF (filename =="default") WRITE(filename,'(a,i2)') "plot",nplo
c..loop by the bands
         bands:DO nbn = nbmin,nbmax

         IF (xsf) THEN
            write (name1,22) ikpt,nbn,jspin
   22       format (i5.5,'.',i3.3,'.real.',i1,'.xsf')
            write (name2,23) ikpt,nbn,jspin
   23       format (i5.5,'.',i3.3,'.imag.',i1,'.xsf')
            write (name3,24) ikpt,nbn,jspin
   24       format (i5.5,'.',i3.3,'.absv.',i1,'.xsf')
            OPEN(55,file=name1)
            CALL xsf_WRITE_atoms(
     >                        55,film,odi%d1,amat,neq(:ntype),
     >                        zatom(:ntype),pos)
            OPEN(56,file=name2)
            CALL xsf_WRITE_atoms(
     >                        56,film,odi%d1,amat,neq(:ntype),
     >                        zatom(:ntype),pos)
            OPEN(57,file=name3)
            CALL xsf_WRITE_atoms(
     >                        57,film,odi%d1,amat,neq(:ntype),
     >                        zatom(:ntype),pos)
            CALL xsf_WRITE_header(55,twodim,filename,(vec1),
     &       (vec2),(vec3),zero
     $           ,grid)
            CALL xsf_WRITE_header(56,twodim,filename,(vec1),
     &       (vec2),(vec3),zero
     $           ,grid)
            CALL xsf_WRITE_header(57,twodim,filename,(vec1),
     &       (vec2),(vec3),zero
     $           ,grid)
         ELSE
            IF (nbn.EQ.nbmin) THEN
               WRITE (vandername,201) ikpt,jspin
262 263 264 265
               IF(l_noco) WRITE(vandername,202)ikpt,jspin
               IF(l_sgwf) WRITE(vandername,202)index_kq,jspin
  201          FORMAT ('UNK',i5.5,'.',i1)
  202          FORMAT ('RNK',i5.5,'.',i1)
266
               OPEN(55,file=vandername)
267 268 269 270 271
               IF(.NOT.l_sgwf) THEN
                  WRITE(55,7) grid(1),grid(2),grid(3),ikpt,nslibd
               ELSE
                  WRITE(55,7) grid(1),grid(2),grid(3),index_kq,nslibd
               ENDIF
272 273 274
    7          FORMAT (5i4)
            ENDIF
         ENDIF
275 276 277 278 279 280 281 282

         if(film.and..not.odi%d1)then
           fas=-bkpt(3)*bmat(3,3)*z1
           factor=cmplx(cos(fas),sin(fas))
         else
           factor=cmplx(1.0,0.0)
         endif   

283 284 285 286 287 288 289
         DO iz = 0,grid(3)-1
          DO iy = 0,grid(2)-1
           xloop:DO ix = 0,grid(1)-1
            point = zero+vec1*REAL(ix)/grid(1)+vec2*REAL(iy)
     $                 /grid(2)
            IF (.NOT.twodim) point = point+vec3*REAL(iz)/grid(3)
!Check if the point is in MT-sphere
290

291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
             ii1 = 3
             ii2 = 3
             ii3 = 3
             IF (film .AND. .NOT.odi%d1) ii3 = 0
             IF (odi%d1) THEN
                ii1 = 0 ; ii2 = 0
             END IF
             DO  i1 = -ii1,ii1
              DO  i2 = -ii2,ii2
               DO  i3 = -ii3,ii3
                pt = point+MATMUL(amat,(/i1,i2,i3/))
                na = 0
                DO nt = 1,ntype
                 DO nq = 1,neq(nt)
                  na   = na + 1
                  s  = SQRT(dot_PRODUCT(pos(:,na)-pt,pos(:,na)-pt))
                  IF (s<rmsh(jri(nt),nt)) THEN
                    CALL wann_real(
     >                   pt,nt,na,0,1,bkpt,
     >                   n3d,nmzxyd,n2d,ntypsd,lmaxd,jmtd,
     >                   natd,ntypd,nmzd,nop,nop2,mrot,tau,invtab,
     >                   nq3,nvac,invs,z1,delz,nmz,nmzxy,nq2,
     >                   lmax,rmsh,jri,pos,ngopr,ntypsy,nvd,
     >                   omtil,amat,bmat,odi,ods,nlod,llod,nlo,llo,
     >                   ff,gg,flo,acof(nbn,:,:),bcof(nbn,:,:),
     >                   ccof(:,nbn,:,:),z(:,nbn),
317
     >                   nv,k1,k2,k3,lmd,nbasfcn,l_ss,qss,jspin,addnoco,
318 319 320 321 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 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
     <                   xdnout)
                    xdnout=xdnout*factor
                   IF (xsf) THEN
                      WRITE(55,*) real(xdnout)
                      WRITE(56,*) aimag(xdnout)
                      WRITE(57,*) real(xdnout*conjg(xdnout))
                   ELSE
                      WRITE(55,8) real(xdnout),aimag(xdnout)
                   ENDIF
                   CYCLE xloop
                  ENDIF
                 ENDDO
                ENDDO !nt
               ENDDO
              ENDDO
             ENDDO !i1
!Check for point in vacuum
             IF (film.AND..NOT.odi%d1.AND.ABS(point(3))>=z1) THEN
                ivac=1
                if (point(3).lt. 0.0)ivac=2
                jvac=ivac
                if(nvac==1)jvac=1
                call wann_plot_vac(point,z1,nmzd,nv2d,n3d,nvac,
     >            nmz,delz,bmat,bbmat,evac,bkpt,vz,jspin,k1,k2,k3,nvd, 
     >            nbasfcn,neigd,z(:,nbn),nv,omtil,nslibd,ac(:,nbn,ivac),
     &             bc(:,nbn,ivac),
     &            u(:,:,jvac),ue(:,:,jvac),xdnout)
                xdnout=xdnout*factor
                if(real(xdnout).gt.9.0 .or.real(xdnout).lt.-9.0
     &        .or.aimag(xdnout).gt.9.0 .or. aimag(xdnout).lt.-9.0)then
                xdnout=cmplx(0.0,0.0)
                print*,"vac-problem at z=",point(3)
                endif
c               CALL wann_real(
c     >              point,0,0,1,0,bkpt,
c     >              n3d,nmzxyd,n2d,ntypsd,lmaxd,jmtd,
c     >              natd,ntypd,nmzd,nop,nop2,mrot,tau,invtab,
c     >              nq3,nvac,invs,z1,delz,nmz,nmzxy,nq2,
c     >              lmax,rmsh,jri,pos,ngopr,ntypsy,nvd,
c     >              omtil,amat,bmat,odi,ods,nlod,llod,nlo,llo,
c     >              ff,gg,flo,acof(nbn,:,:),bcof(nbn,:,:),
c     >              ccof(:,nbn,:,:),z(:,nbn),
c     >              nv,k1,k2,k3,lmd,nbasfcn,
c     <              xdnout)
              IF (xsf) THEN
                 WRITE(55,*) real(xdnout)
                 WRITE(56,*) aimag(xdnout)
                 WRITE(57,*) real(xdnout*conjg(xdnout))
              ELSE
                 WRITE(55,8) real(xdnout),aimag(xdnout)
              ENDIF
              CYCLE xloop
             END IF
            
             IF (odi%d1) THEN
              IF (SQRT((pt(1))**2 + (pt(2))**2)>=z1) THEN
374 375 376 377
               call wann_plot_od_vac(point,z1,nmzd,nv2d,odi,
     >            nmz,delz,bmat,bkpt,nvd,nv,omtil,k3,
     >            ac_1(:,:,nbn),bc_1(:,:,nbn),u_1,ue_1,
     <            xdnout)
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
                xdnout=xdnout*factor
               IF (xsf) THEN
                  WRITE(55,*) real(xdnout)
                  WRITE(56,*) aimag(xdnout)
                  WRITE(57,*) real(xdnout*conjg(xdnout))
               ELSE
                  WRITE (55,8) real(xdnout),aimag(xdnout)
               ENDIF
               CYCLE xloop
              END IF
             END IF
             CALL wann_real(
     >             point,0,0,0,2,bkpt,
     >             n3d,nmzxyd,n2d,ntypsd,lmaxd,jmtd,
     >             natd,ntypd,nmzd,nop,nop2,mrot,tau,invtab,
     >             nq3,nvac,invs,z1,delz,nmz,nmzxy,nq2,
     >             lmax,rmsh,jri,pos,ngopr,ntypsy,nvd,
     >             omtil,amat,bmat,odi,ods,nlod,llod,nlo,llo,
     >             ff,gg,flo,acof(nbn,:,:),bcof(nbn,:,:),
     >             ccof(:,nbn,:,:),z(:,nbn),
398
     >             nv,k1,k2,k3,lmd,nbasfcn,l_ss,qss,jspin,addnoco,
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
     <             xdnout)
             xdnout=xdnout*factor
             IF (xsf) THEN
                WRITE(55,*) real(xdnout)
                WRITE(56,*) aimag(xdnout)
                WRITE(57,*) real(xdnout*conjg(xdnout))
             ELSE
                WRITE(55,8) real(xdnout),aimag(xdnout)
             ENDIF
            ENDDO xloop
           ENDDO
          ENDDO !z-loop

          IF (xsf) THEN
              CALL xsf_WRITE_endblock(55,twodim)
              CALL xsf_WRITE_endblock(56,twodim)
              CALL xsf_WRITE_endblock(57,twodim)
              CLOSE (55) ; CLOSE (56) ; CLOSE (57)
          ENDIF
c..end of the loop by the bands
          ENDDO bands   
      ENDDO   !nplot      
      CLOSE(18)
      IF (.not.xsf) CLOSE(55)
    8 FORMAT (f20.12,1x,f20.12)
424
      if (film.and..not.odi%d1) then
425 426 427 428 429 430 431 432
      deallocate ( ac,bc,u,ue)
      endif

      RETURN
      END SUBROUTINE wann_plot
!------------------------------------------
      
      END MODULE m_wann_plot