wann_plot.F 16.9 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
      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
40 41 42
      SUBROUTINE wann_plot(
     >     DIMENSION,oneD,vacuum,stars,cell,atoms,
     >     nv2d,jspin,odi,ods,n3d,nmzxyd,n2d,ntypsd,
43 44 45 46 47
     >     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,
48 49 50
     >     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)
51
!    *****************************************************
52 53
      USE m_constants
      USE m_types
54 55 56 57
      USE m_wann_real
      USE m_xsf_io
      USE m_wann_plot_vac
      USE m_wann_2dvacabcof
58 59
      USE m_wann_plot_od_vac
      USE m_wann_1dvacabcof
60 61

      IMPLICIT NONE
62 63 64 65 66 67 68 69

      TYPE(t_dimension),INTENT(IN)   :: DIMENSION
      TYPE(t_oneD),INTENT(IN)        :: oneD
      TYPE(t_vacuum),INTENT(IN)      :: vacuum
      TYPE(t_stars),INTENT(IN)       :: stars
      TYPE(t_cell),INTENT(IN)        :: cell
      TYPE(t_atoms),INTENT(IN)       :: atoms

70 71 72 73 74 75
!     .. 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
76
      INTEGER, INTENT (IN) :: nnne,kk,addnoco,index_kq
77
      LOGICAL, INTENT (IN) :: symor,invs,slice,invs2,film
78
      LOGICAL, INTENT (IN) :: l_noco,l_ss,l_sgwf
79
      REAL,    INTENT (IN) :: z1,delz,volint,omtil
80
      REAL,    INTENT (IN) :: qss(3)
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
      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)
96 97 98
      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)
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 126 127 128
      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(:,:,:)
129
      complex, allocatable :: ac_1(:,:,:),bc_1(:,:,:)
130
      real,    allocatable :: u(:,:,:),ue(:,:,:)
131 132
      real,    allocatable :: u_1(:,:,:),ue_1(:,:,:)

133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
      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

151 152 153 154 155 156
      !write(*,*)'in wann_plot'
      !write(*,*)'jspin:',jspin
      !write(*,*)'addnoco:',addnoco
      !write(*,*)'l_noco,l_ss: ',l_noco,l_ss
      !write(*,*)'qss:',qss

157 158 159 160 161 162 163 164 165 166 167 168 169
      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  "
170
         WRITE(20,*) "  zero(1)=0.0 zero(2)=0.0 zero(3)=0.0 "
171 172 173 174 175 176 177 178 179
         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

180
      if(film.and..not.odi%d1)then
181 182 183 184 185
         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,
186
     <         ac,bc,u,ue,addnoco,l_ss,qss,jspin)
187
      endif
188 189 190 191 192 193 194

      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(
195
     >         DIMENSION,oneD,vacuum,stars,cell,
196 197 198 199 200 201 202 203 204
     >         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   


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

      !<-- 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)
248
            CALL xsf_WRITE_atoms(55,atoms,film,odi%d1,amat)
249
            OPEN(56,file=name2)
250
            CALL xsf_WRITE_atoms(56,atoms,film,odi%d1,amat)
251
            OPEN(57,file=name3)
252
            CALL xsf_WRITE_atoms(57,atoms,film,odi%d1,amat)
253 254 255 256 257 258 259 260 261 262 263 264
            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
265 266 267 268
               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)
269
               OPEN(55,file=vandername)
270 271 272 273 274
               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
275 276 277
    7          FORMAT (5i4)
            ENDIF
         ENDIF
278 279 280 281 282 283 284 285

         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   

286 287 288 289 290 291 292
         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
293

294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
             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),
320
     >                   nv,k1,k2,k3,lmd,nbasfcn,l_ss,qss,jspin,addnoco,
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 374 375 376
     <                   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
377 378 379 380
               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)
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
                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),
401
     >             nv,k1,k2,k3,lmd,nbasfcn,l_ss,qss,jspin,addnoco,
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
     <             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)
427
      if (film.and..not.odi%d1) then
428 429 430 431 432 433 434 435
      deallocate ( ac,bc,u,ue)
      endif

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