set_inp.f90 19.7 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
      MODULE m_setinp
      use m_juDFT
!---------------------------------------------------------------------
!  Check muffin tin radii and determine a reasonable choice for MTRs.
!  Derive also other parameters for the input file, to provide some
!  help in the out-file.                                        gb`02
!---------------------------------------------------------------------
      CONTAINS
      SUBROUTINE set_inp(&
16
     &                   infh,nline,xl_buffer,bfh,buffer,l_hyb,&
17 18
     &                   atoms,sym,cell,title,idlist,&
     &                   input,vacuum,noco,&
19
     &                   atomTypeSpecies,speciesRepAtomType,numSpecies,&
20 21
     &                   a1,a2,a3)

22
      USE m_types
23
      USE iso_c_binding
24
      USE m_chkmt
25
      USE m_constants
26 27 28
      USE m_atominput
      USE m_lapwinput
      USE m_rwinp
29 30
      USE m_winpXML
      USE m_juDFT_init
31
      USE m_kpoints
32
      USE m_inv3
33
      USE m_types_xcpot_inbuild
34

35 36 37 38 39 40 41 42
      IMPLICIT NONE
      TYPE(t_input),INTENT(INOUT)    :: input
      TYPE(t_vacuum),INTENT(INOUT)   :: vacuum
      TYPE(t_noco),INTENT(INOUT)     :: noco
      TYPE(t_sym),INTENT(INOUT)      :: sym
      TYPE(t_cell),INTENT(INOUT)     :: cell
      TYPE(t_atoms),INTENT(INOUT)    :: atoms

43
      INTEGER, INTENT (IN) :: infh,xl_buffer,bfh,numSpecies
44
      INTEGER, INTENT (INOUT) :: nline
45 46
      INTEGER, INTENT (IN) :: atomTypeSpecies(atoms%ntype)
      INTEGER, INTENT (IN) :: speciesRepAtomType(atoms%nat)
47 48 49
      CHARACTER(len=xl_buffer) :: buffer
      LOGICAL, INTENT (IN) :: l_hyb  
      REAL,    INTENT (IN) :: idlist(:)
50
      REAL,    INTENT (INOUT) :: a1(3),a2(3),a3(3)
51 52
      CHARACTER(len=80), INTENT (IN) :: title
 
53 54
      INTEGER nel,i,j, nkptOld
      REAL    kmax,dtild,dvac1,n1,n2,gam,kmax0,dtild0,dvac0,sumWeight
55
      REAL    recVecLength, kPointDen(3)
56
      LOGICAL l_test,l_gga,l_exists, l_explicit, l_kpts
57
      REAL     dx0(atoms%ntype), rmtTemp(atoms%ntype)
58
      REAL     a1Temp(3),a2Temp(3),a3Temp(3) 
59 60
      INTEGER  div(3)
      INTEGER jri0(atoms%ntype),lmax0(atoms%ntype),nlo0(atoms%ntype),llo0(atoms%nlod,atoms%ntype)
61 62 63
      CHARACTER(len=1)  :: ch_rw
      CHARACTER(len=4)  :: namex
      CHARACTER(len=3)  :: noel(atoms%ntype)
64
      CHARACTER(len=12) :: relcor
65 66 67
      CHARACTER(len=3)  :: latnamTemp
      CHARACTER(LEN=20) :: filename
      INTEGER  nu,iofile
68
      INTEGER  iggachk
69
      INTEGER  n ,iostat, errorStatus
70
      REAL     scpos ,zc
71 72 73 74 75 76 77

      TYPE(t_banddos)::banddos
      TYPE(t_obsolete)::obsolete
      TYPE(t_sliceplot)::sliceplot
      TYPE(t_oneD)::oneD
      TYPE(t_stars)::stars
      TYPE(t_hybrid)::hybrid
78
      TYPE(t_xcpot_inbuild)::xcpot
79
      TYPE(t_kpts)::kpts
80
      TYPE(t_enpara)::enpara
Daniel Wortmann's avatar
Daniel Wortmann committed
81
      TYPE(t_forcetheo)::forcetheo
82 83 84 85 86 87 88

    !-odim
!+odim
!      REAL, PARAMETER :: eps=0.00000001
!     ..
!HF   added for HF and hybrid functionals
      REAL     ::  taual_hyb(3,atoms%nat)
89
      INTEGER  ::  bands
90 91 92 93
      LOGICAL  ::  l_gamma
      INTEGER  :: nkpt3(3)
!HF

94
      INTEGER :: xmlElectronStates(29,atoms%ntype)
95 96 97
      LOGICAL :: xmlPrintCoreStates(29,atoms%ntype)
      REAL    :: xmlCoreOccs(2,29,atoms%ntype)
      REAL    :: xmlCoreRefOccs(29)
98 99 100 101 102 103 104 105

      interface
         function dropInputSchema() bind(C, name="dropInputSchema")
            use iso_c_binding
            INTEGER(c_int) dropInputSchema
         end function dropInputSchema
      end interface

106 107
      DATA xmlCoreRefOccs /2,2,2,4,2,2,4,2,4,6,2,4,2,4,6,2,4,2,6,8,4,&
     &                     6,2,4,2,6,8,4,6/
108
      xmlElectronStates = noState_const
109 110 111
      xmlPrintCoreStates = .FALSE.
      xmlCoreOccs = 0.0

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
      l_test = .false.
      l_gga  = .true.
      atoms%nlod=9
      ALLOCATE(atoms%nz(atoms%ntype))
      ALLOCATE(atoms%jri(atoms%ntype))
      ALLOCATE(atoms%dx(atoms%ntype))
      ALLOCATE(atoms%lmax(atoms%ntype))
      ALLOCATE(atoms%nlo(atoms%ntype))
      ALLOCATE(atoms%llo(atoms%nlod,atoms%ntype))
      ALLOCATE(atoms%ncst(atoms%ntype))
      ALLOCATE(atoms%lnonsph(atoms%ntype))
      ALLOCATE(atoms%nflip(atoms%ntype))
      ALLOCATE(atoms%l_geo(atoms%ntype))
      ALLOCATE(atoms%lda_u(atoms%ntype))
      ALLOCATE(atoms%bmu(atoms%ntype))
      ALLOCATE(atoms%relax(3,atoms%ntype))
128
      ALLOCATE(atoms%ulo_der(atoms%nlod,atoms%ntype))
129
      
130 131 132 133 134 135
      atoms%nz(:) = NINT(atoms%zatom(:))
      DO i = 1, atoms%ntype
       noel(i) = namat_const(atoms%nz(i))
      ENDDO
      atoms%rmt(:) = 999.9
      atoms%pos(:,:) = matmul( cell%amat , atoms%taual(:,:) )
136
      atoms%ulo_der = 0
137 138
      ch_rw = 'w'
      sym%namgrp= 'any ' 
139
      banddos%dos   = .false. ; banddos%l_mcd = .false. ; banddos%unfoldband = .FALSE. ; input%secvar = .false.
140 141 142
      input%vchk = .false. ; input%cdinf = .false. 
      input%l_bmt= .false. ; input%eonly  = .false.
      input%gauss= .false. ; input%tria  = .false. 
143
      sliceplot%slice= .false. ;  input%swsp  = .false.
144 145 146 147
      input%lflip= .false. ; banddos%vacdos= .false. ; input%integ = .false.
      sliceplot%iplot= .false. ; input%score = .false. ; sliceplot%plpot = .false.
      input%pallst = .false. ; obsolete%lwb = .false. ; vacuum%starcoeff = .false.
      input%strho  = .false.  ; input%l_f = .false. ; atoms%l_geo(:) = .true.
148
      noco%l_noco = noco%l_ss ;   input%jspins = 1
149 150
      input%itmax = 9 ; input%maxiter = 99 ; input%imix = 7 ; input%alpha = 0.05
      input%preconditioning_param = 0.0 ; input%minDistance = 0.0
151
      input%spinf = 2.0 ; obsolete%lepr = 0 ; input%coretail_lmax = 0
152
      sliceplot%kk = 0 ; sliceplot%nnne = 0  ; vacuum%nstars = 0 ; vacuum%nstm = 0 
153 154
      input%isec1 = 99 ; nu = 5 ; vacuum%layerd = 1 ; iofile = 6
      ALLOCATE(vacuum%izlay(vacuum%layerd,2))
155 156
      banddos%ndir = 0 ; vacuum%layers = 0 ; atoms%nflip(:) = 1 ; vacuum%izlay(:,:) = 0
      banddos%e_mcd_lo = -10.0 ; banddos%e_mcd_up = 0.0
157 158 159
      atoms%lda_u%l = -1 ; atoms%relax(1:2,:) = 1 ; atoms%relax(:,:) = 1
      input%epsdisp = 0.00001 ; input%epsforce = 0.00001 ; input%xa = 2.0 ; input%thetad = 330.0
      sliceplot%e1s = 0.0 ; sliceplot%e2s = 0.0 ; banddos%e1_dos = 0.5 ; banddos%e2_dos = -0.5 ; input%tkb = 0.001
160 161
      banddos%sig_dos = 0.015 ; vacuum%tworkf = 0.0 ; input%scaleCell = 1.0 ; scpos = 1.0
      input%scaleA1 = 1.0 ; input%scaleA2 = 1.0 ; input%scaleC = 1.0
162
      zc = 0.0 ; vacuum%locx(:) = 0.0 ;  vacuum%locy(:) = 0.0
163
      kpts%numSpecialPoints = 0
164
      input%ldauLinMix = .FALSE. ; input%ldauMixParam = 0.05 ; input%ldauSpinf = 1.0
165
      input%l_wann = .FALSE.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193

!+odim
      oneD%odd%mb = 0 ; oneD%odd%M = 0 ; oneD%odd%m_cyl = 0 ; oneD%odd%chi = 0 ; oneD%odd%rot = 0
      oneD%odd%k3 = 0 ; oneD%odd%n2d= 0 ; oneD%odd%nq2 = 0 ; oneD%odd%nn2d = 0 
      oneD%odd%nop = 0 ; oneD%odd%kimax2 = 0 ; oneD%odd%nat = 0
      oneD%odd%invs = .false. ; oneD%odd%zrfs = .false. ; oneD%odd%d1 = .false.
!-odim
! check for magnetism
      atoms%bmu(:) = 0.0
      DO n = 1, atoms%ntype
        IF (atoms%nz(n).EQ.24) atoms%bmu(n) = 1.0  ! Cr - Ni
        IF (atoms%nz(n).EQ.25) atoms%bmu(n) = 3.5
        IF (atoms%nz(n).EQ.26) atoms%bmu(n) = 2.2
        IF (atoms%nz(n).EQ.27) atoms%bmu(n) = 1.6
        IF (atoms%nz(n).EQ.28) atoms%bmu(n) = 1.1
        IF (atoms%nz(n).EQ.59) atoms%bmu(n) = 2.1  ! Pr - Tm
        IF (atoms%nz(n).EQ.60) atoms%bmu(n) = 3.1
        IF (atoms%nz(n).EQ.61) atoms%bmu(n) = 4.1
        IF (atoms%nz(n).EQ.62) atoms%bmu(n) = 5.1
        IF (atoms%nz(n).EQ.63) atoms%bmu(n) = 7.1
        IF (atoms%nz(n).EQ.64) atoms%bmu(n) = 7.1 
        IF (atoms%nz(n).EQ.65) atoms%bmu(n) = 6.1
        IF (atoms%nz(n).EQ.66) atoms%bmu(n) = 5.1
        IF (atoms%nz(n).EQ.67) atoms%bmu(n) = 4.1
        IF (atoms%nz(n).EQ.68) atoms%bmu(n) = 3.1
        IF (atoms%nz(n).EQ.69) atoms%bmu(n) = 2.1
      ENDDO

Daniel Wortmann's avatar
Daniel Wortmann committed
194
      input%delgau = input%tkb ; atoms%ntype = atoms%ntype ; atoms%nat = atoms%nat
195 196
      DO i = 1, 10
        j = (i-1) * 8 + 1
197
        input%comment(i) = title(j:j+7)
198 199 200 201 202 203 204 205 206 207 208 209
      ENDDO 
      IF (noco%l_noco) input%jspins = 2
       
      a1(:) = cell%amat(:,1) ; a2(:) = cell%amat(:,2) ; a3(:) = cell%amat(:,3) 

      CALL chkmt(&
     &           atoms,input,vacuum,cell,oneD,&
     &           l_gga,noel,l_test,&
     &           kmax,dtild,vacuum%dvac,atoms%lmax,atoms%jri,atoms%rmt,atoms%dx)

! --> read in (possibly) atomic info

210 211 212
      stars%gmax = 3.0 * kmax ; xcpot%gmaxxc = 2.5 * kmax ; input%rkmax = kmax
      atoms%lnonsph(:) = min( max( (atoms%lmax(:)-2),3 ), 8 )

213
      CALL atom_input(&
214
     &                infh,xl_buffer,bfh,buffer,&
215
     &                input,idlist,xmlCoreRefOccs,&
216
     &                nline,&
217
     &                xmlElectronStates,xmlPrintCoreStates,xmlCoreOccs,&
218
     &                atomTypeSpecies,numSpecies,&
219
     &                nel,atoms,enpara)
220

221 222 223 224 225 226 227 228 229 230 231 232
      DO n = 1, atoms%ntype
         IF (atoms%lnonsph(n).GT.atoms%lmax(n)) THEN
            WRITE(*,'(a20,i5,a25,i3,a4,i3,a1)')& 
               'NOTE: For atom type ', n,' lnonsph is reduced from ',& 
               atoms%lnonsph(n),' to ', atoms%lmax(n), '.'
            WRITE(6,'(a20,i5,a25,i3,a4,i3,a1)')&
               'NOTE: For atom type ', n, ' lnonsph is reduced from ',& 
               atoms%lnonsph(n),' to ', atoms%lmax(n), '.'
            atoms%lnonsph(n) = atoms%lmax(n)
         END IF
      END DO

233
      input%zelec = nel
234

235 236
! --> check once more
      rmtTemp = 999.0
237 238 239 240
      l_test = .true.
      CALL chkmt(&
     &           atoms,input,vacuum,cell,oneD,&
     &           l_gga,noel,l_test,&
241
     &           kmax0,dtild0,dvac0,lmax0,jri0,rmtTemp,dx0)
242 243 244 245 246 247 248 249 250 251

      IF ( ANY(atoms%nlo(:).NE.0) ) THEN
        input%ellow = -1.8
      ELSE
        input%ellow = -0.8  
      ENDIF
      IF (input%film) THEN
         input%elup = 0.5
      ELSE
         input%elup = 1.0
252
      ENDIF 
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294

      IF (.not.input%film) THEN
         vacuum%dvac = a3(3) ; dtild = vacuum%dvac
      ENDIF
      IF ( (abs(a1(3)).GT.eps).OR.(abs(a2(3)).GT.eps).OR.&
     &     (abs(a3(1)).GT.eps).OR.(abs(a3(2)).GT.eps) ) THEN          
        cell%latnam = 'any'
      ELSE
        IF ( (abs(a1(2)).LT.eps).AND.(abs(a2(1)).LT.eps) ) THEN
          IF (abs(a1(1)-a2(2)).LT.eps) THEN
            cell%latnam = 'squ'
          ELSE
            cell%latnam = 'p-r'
          ENDIF
        ELSE
          n1 = sqrt(a1(1)**2 + a1(2)**2); n2 = sqrt(a2(1)**2 + a2(2)**2)
          IF (abs(n1-n2).LT.eps) THEN
            gam = ( a1(1)*a2(1) + a1(2)*a2(2) ) / (n1 * n2)
            gam = 57.295779512*acos(gam)
            IF (abs(gam-60.).LT.eps) THEN
               cell%latnam = 'hex'
               a1(2) = n1 * 0.5
               a1(1) = a1(2) * sqrt(3.0)
            ELSEIF (abs(gam-120.).LT.eps) THEN
               cell%latnam = 'hx3'
               a1(1) = n1 * 0.5
               a1(2) = a1(1) * sqrt(3.0)
            ELSE
               cell%latnam = 'c-r'
               gam = 0.5 * gam / 57.295779512
               a1(1) =  n1 * cos(gam)
               a1(2) = -n1 * sin(gam)
            ENDIF
            a2(1) =   a1(1)
            a2(2) = - a1(2)
          ELSE
            cell%latnam = 'obl'
          ENDIF
        ENDIF
      ENDIF

!HF   added for HF and hybrid functionals
295
      hybrid%gcutm1       = input%rkmax - 0.5
296
      hybrid%tolerance1   = 1e-4
297
      taual_hyb   = atoms%taual
Daniel Wortmann's avatar
Daniel Wortmann committed
298
      ALLOCATE(hybrid%lcutwf(atoms%ntype))
299 300
      ALLOCATE(hybrid%lcutm1(atoms%ntype))
      ALLOCATE(hybrid%select1(4,atoms%ntype))
301 302 303
      hybrid%lcutwf      = atoms%lmax - atoms%lmax / 10
      hybrid%ewaldlambda = 3
      hybrid%lexp        = 16
304 305 306 307 308
      hybrid%lcutm1 = 4
      hybrid%select1(1,:) = 4
      hybrid%select1(2,:) = 0
      hybrid%select1(3,:) = 4
      hybrid%select1(4,:) = 2
309
      bands       = max( nint(input%zelec)*10, 60 )
310
      l_gamma     = .false.
311
      hybrid%l_hybrid = l_hyb
312 313 314 315 316 317 318 319
      IF (l_hyb) THEN
         input%ellow = input%ellow -  2.0
         input%elup  = input%elup  + 10.0
         input%gw_neigd = bands
         l_gamma = .true.
         IF(juDFT_was_argument("-old")) THEN
            CALL juDFT_error('No hybrid functionals input for old input file implemented', calledby='set_inp')
         END IF
320
         input%minDistance = 1.0e-5
321 322 323 324 325 326
      ELSE
        input%gw_neigd = 0
      END IF
!HF

! rounding
327 328 329 330 331 332
      atoms%rmt(:)  = real(NINT(atoms%rmt(:)  * 100 ) / 100.)
      atoms%dx(:)   = real(NINT(atoms%dx(:)   * 1000) / 1000.)
      stars%gmax    = real(NINT(stars%gmax    * 10  ) / 10.)
      input%rkmax   = real(NINT(input%rkmax   * 10  ) / 10.)
      xcpot%gmaxxc  = real(NINT(xcpot%gmaxxc  * 10  ) / 10.)
      hybrid%gcutm1 = real(NINT(hybrid%gcutm1 * 10  ) / 10.)
333
      IF (input%film) THEN
334 335
       vacuum%dvac = real(NINT(vacuum%dvac*100)/100.)
       dtild = real(NINT(dtild*100)/100.)
336 337 338 339 340
      ENDIF
!
! read some lapw input
!
      CALL lapw_input(&
341
     &                infh,nline,xl_buffer,bfh,buffer,&
342
     &                input%jspins,input%kcrel,obsolete%ndvgrd,kpts%nkpt,div,kpts%kPointDensity,&
343
     &                input%frcor,input%ctail,obsolete%chng,input%tria,input%rkmax,stars%gmax,xcpot%gmaxxc,&
344
     &                vacuum%dvac,dtild,input%tkb,namex,relcor)
345 346

      stars%gmaxInit = stars%gmax
347 348 349
!
      IF (input%film) atoms%taual(3,:) = atoms%taual(3,:) * a3(3) / dtild

350
      INQUIRE(file="inp",exist=l_exists)
351
      IF (l_exists) THEN
352
         CALL juDFT_error("inp-file exists. Cannot write another input file in this directory.",calledby="set_inp")
353
      ENDIF
354 355 356 357 358
      INQUIRE(file="inp.xml",exist=l_exists)
      IF (l_exists) THEN
         CALL juDFT_error("inp.xml-file exists. Cannot write another input file in this directory.",calledby="set_inp")
      ENDIF

359 360
      nu = 8 
      input%gw = 0
361

362 363 364
      IF (kpts%nkpt == 0) THEN     ! set some defaults for the k-points
        IF (input%film) THEN
          cell%area = cell%omtil / vacuum%dvac
365
          kpts%nkpt = MAX(nint((3600/cell%area)/sym%nop2),1)
366
        ELSE
367
          kpts%nkpt = MAX(nint((216000/cell%omtil)/sym%nop),1)
368 369
        ENDIF
      ENDIF
370

371
      kpts%specificationType = 0
372 373 374 375
      IF((ANY(div(:).NE.0)).AND.(ANY(kpts%kPointDensity(:).NE.0.0))) THEN
         CALL juDFT_error('Double specification of k point set', calledby = 'set_inp')
      END IF
      IF (ANY(div(:).NE.0)) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
376
         kpts%specificationType = 2
377 378 379 380 381
      ELSE IF (ANY(kpts%kPointDensity(:).NE.0.0)) THEN
         kpts%specificationType = 4
      ELSE
         kpts%specificationType = 1
      END IF
382
      l_kpts = .FALSE.
Daniel Wortmann's avatar
Daniel Wortmann committed
383 384 385 386 387 388

      IF(TRIM(ADJUSTL(sym%namgrp)).EQ.'any') THEN
         sym%symSpecType = 1
      ELSE
         sym%symSpecType = 2
      END IF
389

390
      ! set vacuum%nvac
391 392 393 394
      vacuum%nvac = 2
      IF (sym%zrfs.OR.sym%invs) vacuum%nvac = 1
      IF (oneD%odd%d1) vacuum%nvac = 1
      
395
      ! Set defaults for noco  types
396 397
      ALLOCATE(noco%l_relax(atoms%ntype),noco%b_con(2,atoms%ntype))
      ALLOCATE(noco%alphInit(atoms%ntype),noco%alph(atoms%ntype),noco%beta(atoms%ntype))
398
   
399
      IF (noco%l_ss) input%ctail = .FALSE.
400 401 402 403 404 405 406 407 408 409 410
      noco%l_mperp = .FALSE.
      noco%l_constr = .FALSE.
      noco%mix_b = 0.0
      noco%qss = 0.0

      noco%l_relax(:) = .FALSE.
      noco%alphInit(:) = 0.0
      noco%alph(:) = 0.0
      noco%beta(:) = 0.0
      noco%b_con(:,:) = 0.0

411
     
412 413 414 415 416 417 418
      CALL inv3(cell%amat,cell%bmat,cell%omtil)
      cell%bmat=tpi_const*cell%bmat
      kpts%nkpt3(:) = div(:)

      IF (kpts%specificationType.EQ.4) THEN
         DO i = 1, 3
            IF (kpts%kPointDensity(i).LE.0.0) THEN
419
               CALL juDFT_error('Error: Nonpositive kpointDensity provided', calledby = 'set_inp')
420 421 422 423 424 425
            END IF
            recVecLength = SQRT(cell%bmat(i,1)**2 + cell%bmat(i,2)**2 + cell%bmat(i,3)**2)
            kpts%nkpt3(i) = CEILING(kpts%kPointDensity(i) * recVecLength)
         END DO
         kpts%nkpt = kpts%nkpt3(1) * kpts%nkpt3(2) * kpts%nkpt3(3)
      END IF
426

427 428 429
      IF (l_hyb) THEN
         ! Changes for hybrid functionals
         input%isec1 = 999
430 431
         namex = 'pbe0'
         input%ctail = .false. ; atoms%l_geo = .false.! ; input%frcor = .true.
432
         input%itmax = 15 ; input%maxiter = 25!; input%imix  = 17
Gregor Michalicek's avatar
Gregor Michalicek committed
433 434 435
         IF (ANY(kpts%nkpt3(:).EQ.0)) kpts%nkpt3(:) = 4
         div(:) = kpts%nkpt3(:)
         kpts%specificationType = 2
436 437
      END IF

438
      IF(.NOT.juDFT_was_argument("-old")) THEN
439 440 441
         nkptOld = kpts%nkpt
         latnamTemp = cell%latnam

442 443
         l_explicit = juDFT_was_argument("-explicit")

444 445 446
         a1Temp(:) = a1(:)
         a2Temp(:) = a2(:)
         a3Temp(:) = a3(:)
447

448
         IF(l_explicit) THEN
449 450
            ! kpts generation
            kpts%l_gamma = l_gamma
451

452
            CALL kpoints(oneD,sym,cell,input,noco,banddos,kpts,l_kpts)
453

454
            kpts%specificationType = 3
455 456
            IF (l_hyb) kpts%specificationType = 2
         END IF
457

458 459
         IF(l_explicit) THEN
            sym%symSpecType = 3
460 461
            !set latnam to any
            cell%latnam = 'any'
462 463 464 465

            a1Temp(:) = cell%amat(:,1)
            a2Temp(:) = cell%amat(:,2)
            a3Temp(:) = cell%amat(:,3)
466 467
         END IF

468 469 470 471 472
         errorStatus = 0
         errorStatus = dropInputSchema()
         IF(errorStatus.NE.0) THEN
            STOP 'Error: Cannot print out FleurInputSchema.xsd'
         END IF
473
         filename = 'inp.xml'
474

475
         CALL w_inpXML(&
476
     &                 atoms,obsolete,vacuum,input,stars,sliceplot,forcetheo,banddos,&
477
     &                 cell,sym,xcpot,noco,oneD,hybrid,kpts,div,l_gamma,&
478
     &                 noel,namex,relcor,a1Temp,a2Temp,a3Temp,dtild,input%comment,&
479
     &                 xmlElectronStates,xmlPrintCoreStates,xmlCoreOccs,&
480
     &                 atomTypeSpecies,speciesRepAtomType,.FALSE.,filename,&
481
     &                 l_explicit,numSpecies,enpara)
482

483 484
         IF(juDFT_was_argument("-explicit")) THEN
            sumWeight = 0.0
485 486
            WRITE(6,*) ''
            WRITE(6,'(a,(a3,i10))') 'k-point count:','', kpts%nkpt
487
            DO i = 1, kpts%nkpt
Daniel Wortmann's avatar
Daniel Wortmann committed
488
               sumWeight = sumWeight + kpts%wtkpt(i)
489 490
            END DO
            DO i = 1, kpts%nkpt
Daniel Wortmann's avatar
Daniel Wortmann committed
491 492
               kpts%wtkpt(i) = kpts%wtkpt(i) / sumWeight
               kpts%wtkpt(i) = kpts%wtkpt(i)
493 494 495
            END DO
         END IF

496 497 498 499
         kpts%nkpt = nkptOld
         cell%latnam = latnamTemp
      END IF !xml output

500
      DEALLOCATE (noco%l_relax,noco%b_con,noco%alphInit,noco%alph,noco%beta)
501
      DEALLOCATE (atoms%ulo_der)
502

503 504 505 506 507 508 509 510 511 512 513 514 515
      IF (ANY(kpts%nkpt3(:).NE.0)) THEN
         DO i = 1, 3
            recVecLength = SQRT(cell%bmat(i,1)**2 + cell%bmat(i,2)**2 + cell%bmat(i,3)**2)
            kPointDen(i) = kpts%nkpt3(i) / recVecLength
         END DO
         WRITE(6,*) ''
         WRITE(6,'(a,3(a4,i10))')   'k-point mesh:'   , '', kpts%nkpt3(1),'', kpts%nkpt3(2),'', kpts%nkpt3(3)
         WRITE(6,'(a,3(a4,f10.6))') 'k-point density:', '', kPointDen(1),'', kPointDen(2),'', kPointDen(3)
         WRITE(6,*) ''
      END IF

      CLOSE (6)

516 517 518 519
      IF (juDFT_was_argument("-old")) THEN
         IF (atoms%ntype.GT.999) THEN
            CALL juDFT_error('More than 999 atom types only work with the inp.xml input file',calledby='set_inp')
         END IF
520 521 522 523
         IF (kpts%specificationType.EQ.4) THEN
            CALL juDFT_error('No k point set specification by density supported for old inp file',&
                             calledby = 'set_inp')
         END IF
524

525 526 527
         CALL rw_inp(ch_rw,atoms,obsolete,vacuum,input,stars,sliceplot,banddos,&
                     cell,sym,xcpot,noco,oneD,hybrid,kpts,&
                     noel,namex,relcor,a1,a2,a3,dtild,input%comment)
528 529 530

         iofile = 6
         OPEN (iofile,file='inp',form='formatted',status='old',position='append')
531
      
532
         IF((div(1) == 0).OR.(div(2) == 0)) THEN 
533 534 535 536 537 538
            WRITE (iofile,'(a5,i5)') 'nkpt=',kpts%nkpt
         ELSE
            WRITE (iofile,'(a5,i5,3(a4,i2))') 'nkpt=',kpts%nkpt,',nx=',div(1),',ny=',div(2),',nz=',div(3)
         ENDIF

         CLOSE (iofile)
539

540
      END IF
541 542 543

      END SUBROUTINE set_inp
      END MODULE m_setinp