postprocessInput.F90 20.9 KB
Newer Older
1 2 3 4 5 6
!--------------------------------------------------------------------------------
! Copyright (c) 2017 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.
!--------------------------------------------------------------------------------

Daniel Wortmann's avatar
Daniel Wortmann committed
7 8 9 10
MODULE m_postprocessInput

CONTAINS

11
SUBROUTINE postprocessInput(mpi,input,field,sym,stars,atoms,vacuum,obsolete,kpts,&
12 13
     oneD,hybrid,cell,banddos,sliceplot,xcpot,forcetheo,&
     noco,DIMENSION,enpara,sphhar,l_opti,noel,l_kpts)
Daniel Wortmann's avatar
Daniel Wortmann committed
14 15 16 17

  USE m_juDFT
  USE m_types
  USE m_constants
18
  USE m_lapwdim
Daniel Wortmann's avatar
Daniel Wortmann committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
  USE m_ylm
  USE m_convndim
  USE m_chkmt
  USE m_localsym
  USE m_strgndim
  USE m_od_chisym
  USE m_dwigner
  USE m_mapatom
  USE m_cdn_io
  USE m_strgn
  USE m_od_strgn1
  USE m_prpqfft
  USE m_prpxcfft
  USE m_stepf
  USE m_convn
  USE m_efield
  USE m_od_mapatom
  USE m_od_kptsgen
  USE m_gen_bz
  USE m_nocoInputCheck
39 40 41
  USE m_kpoints   
  USE m_types_forcetheo_extended

Daniel Wortmann's avatar
Daniel Wortmann committed
42 43 44
  IMPLICIT NONE

  TYPE(t_mpi)      ,INTENT   (IN) :: mpi
45
  CLASS(t_forcetheo),INTENT(IN)   :: forcetheo
46 47 48 49 50 51 52 53 54 55 56 57
  TYPE(t_input),    INTENT(INOUT) :: input
  TYPE(t_sym),      INTENT(INOUT) :: sym
  TYPE(t_stars),    INTENT(INOUT) :: stars 
  TYPE(t_atoms),    INTENT(INOUT) :: atoms
  TYPE(t_vacuum),   INTENT(INOUT) :: vacuum
  TYPE(t_obsolete), INTENT(INOUT) :: obsolete
  TYPE(t_kpts),     INTENT(INOUT) :: kpts
  TYPE(t_oneD),     INTENT(INOUT) :: oneD
  TYPE(t_hybrid),   INTENT(INOUT) :: hybrid
  TYPE(t_cell),     INTENT(INOUT) :: cell
  TYPE(t_banddos),  INTENT(INOUT) :: banddos
  TYPE(t_sliceplot),INTENT(INOUT) :: sliceplot
58
  CLASS(t_xcpot),   INTENT(INOUT) :: xcpot
Daniel Wortmann's avatar
Daniel Wortmann committed
59 60 61 62
  TYPE(t_noco),     INTENT(INOUT) :: noco
  TYPE(t_dimension),INTENT(INOUT) :: dimension
  TYPE(t_enpara)   ,INTENT(INOUT) :: enpara
  TYPE(t_sphhar)   ,INTENT  (OUT) :: sphhar
63
  TYPE(t_field),    INTENT(INOUT) :: field
Daniel Wortmann's avatar
Daniel Wortmann committed
64 65 66 67
  LOGICAL,          INTENT  (OUT) :: l_opti
  LOGICAL,          INTENT   (IN) :: l_kpts
  CHARACTER(len=3), ALLOCATABLE, INTENT(IN) :: noel(:)

68
  INTEGER              :: i, j, n, na, n1, n2, iType, l, ilo, ikpt
Daniel Wortmann's avatar
Daniel Wortmann committed
69 70 71 72 73
  INTEGER              :: minNeigd, nv, nv2, kq1, kq2, kq3, jrc, jsp, ii
  INTEGER              :: ios, ntst, ierr
  REAL                 :: sumWeight, rmtmax, zp, radius, dr
  REAL                 :: kmax1, dtild1, dvac1
  REAL                 :: bk(3)
74 75
  LOGICAL              :: l_vca, l_test,l_gga
 
Daniel Wortmann's avatar
Daniel Wortmann committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
  INTEGER, ALLOCATABLE :: lmx1(:), nq1(:), nlhtp1(:)
  INTEGER, ALLOCATABLE :: jri1(:), lmax1(:)
  REAL,    ALLOCATABLE :: rmt1(:), dx1(:)

#ifdef CPP_MPI
  INCLUDE 'mpif.h'
#endif

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! Start of input postprocessing (calculate missing parameters)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  IF (mpi%irank.EQ.0) THEN

  ! Check the LO stuff and call setlomap (from inped):

     ALLOCATE(atoms%lo1l(0:atoms%llod,atoms%ntype))
     ALLOCATE(atoms%nlol(0:atoms%llod,atoms%ntype))

     IF (ANY(atoms%lapw_l(:).NE.-1)) input%l_useapw = .TRUE.
     DO iType = 1, atoms%ntype
        IF (atoms%nlo(iType).GE.1) THEN
           IF (input%secvar) THEN
99
              CALL juDFT_error("LO + sevcar not implemented",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
100 101 102
           END IF
           IF (atoms%nlo(iType).GT.atoms%nlod) THEN
              WRITE (6,*) 'nlo(n) =',atoms%nlo(iType),' > nlod =',atoms%nlod
103
              CALL juDFT_error("nlo(n)>nlod",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
104 105 106 107 108 109 110 111 112 113
           END IF
           DO j=1,atoms%nlo(iType)
              IF (.NOT.input%l_useapw) THEN
                 IF (atoms%llo(j,iType).LT.0) THEN ! CALL juDFT_error("llo<0 ; compile with DCPP_APW!",calledby="inped")
                    WRITE(6,'(A)') 'Info: l_useapw not set.'
                    WRITE(6,'(A,I2,A,I2,A)') '      LO #', j, ' at atom type', iType, ' is an e-derivative.'
                 END IF
              ENDIF
              IF ( (atoms%llo(j,iType).GT.atoms%llod).OR.(mod(-atoms%llod,10)-1).GT.atoms%llod ) THEN
                 WRITE (6,*) 'llo(j,n) =',atoms%llo(j,iType),' > llod =',atoms%llod
114
                 CALL juDFT_error("llo(j,n)>llod",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
              END IF
           END DO

           ! Replace call to setlomap with the following 3 loops (preliminary).
           ! atoms%nlol and atoms%lo1l arrays are strange. This should be solved differently.
           DO l = 0,atoms%llod
              atoms%nlol(l,iType) = 0
              atoms%lo1l(l,iType) = 0
           END DO

           DO ilo = 1,atoms%nlod
              atoms%l_dulo(ilo,iType) = .FALSE.
           END DO

           DO ilo = 1,atoms%nlo(iType)
              if (input%l_useapW) THEN
                 IF (atoms%ulo_der(ilo,iType).EQ.1) THEN
                    atoms%l_dulo(ilo,iType) = .TRUE.
                 END IF
              endif
              WRITE(6,'(A,I2,A,I2)') 'I use',atoms%ulo_der(ilo,iType),'. derivative of l =',atoms%llo(ilo,iType)
136
              IF (atoms%llo(ilo,iType)>atoms%llod) CALL juDFT_error(" l > llod!!!",calledby="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
              l = atoms%llo(ilo,iType)
              IF (ilo.EQ.1) THEN
                 atoms%lo1l(l,iType) = ilo
              ELSE
                 IF (l.NE.atoms%llo(ilo-1,iType)) THEN
                    atoms%lo1l(l,iType) = ilo
                 END IF
              END IF
              atoms%nlol(l,iType) = atoms%nlol(l,iType) + 1
           END DO
           WRITE (6,*) 'atoms%lapw_l(n) = ',atoms%lapw_l(iType)
        END IF

     END DO

     ! Check lda+u stuff (from inped)

     DO i = 1, atoms%n_u
        n = atoms%lda_u(i)%atomType
        IF (atoms%nlo(n).GE.1) THEN
           DO j = 1, atoms%nlo(n)
              IF ((ABS(atoms%llo(j,n)).EQ.atoms%lda_u(i)%l) .AND. (.NOT.atoms%l_dulo(j,n)) ) &
                 WRITE (*,*) 'LO and LDA+U for same l not implemented'
           END DO
        END IF
     END DO

     IF (atoms%n_u.GT.0) THEN
165 166
        IF (input%secvar) CALL juDFT_error("LDA+U and sevcar not implemented",calledby ="postprocessInput")
        IF (noco%l_mperp) CALL juDFT_error("LDA+U and l_mperp not implemented",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
167 168 169 170 171 172
     END IF

     ! Check DOS related stuff (from inped)

     IF ((banddos%ndir.LT.0).AND..NOT.banddos%dos) THEN
        CALL juDFT_error('STOP banddos: the inbuild dos-program  <0'//&
173
             ' can only be used if dos = true',calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
174 175 176 177 178
     END IF

     IF ((banddos%ndir.LT.0).AND.banddos%dos) THEN
        IF (banddos%e1_dos-banddos%e2_dos.LT.1e-3) THEN
           CALL juDFT_error("STOP banddos: no valid energy window for "//&
179
                "internal dos-program",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
180 181 182
        END IF
        IF (banddos%sig_dos.LT.0) THEN
           CALL juDFT_error("STOP DOS: no valid broadening (sig_dos) for "//&
183
                "internal dos-PROGRAM",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
184 185 186 187 188
        END IF
     END IF

     IF (banddos%vacdos) THEN
        IF (.NOT.banddos%dos) THEN
189
           CALL juDFT_error("STOP DOS: only set vacdos = .true. if dos = .true.",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
190 191
        END IF
        IF (.NOT.vacuum%starcoeff.AND.(vacuum%nstars.NE.1))THEN
192
           CALL juDFT_error("STOP banddos: if stars = f set vacuum=1",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
193 194
        END IF
        IF (vacuum%layers.LT.1) THEN
195
           CALL juDFT_error("STOP DOS: specify layers if vacdos = true",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
196 197 198
        END IF
        DO i=1,vacuum%layers
           IF (vacuum%izlay(i,1).LT.1) THEN
199
              CALL juDFT_error("STOP DOS: all layers must be at z>0",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
200 201 202 203 204 205 206
           END IF
        END DO
     END IF

     ! Check noco stuff and calculate missing noco parameters

     IF (noco%l_noco) THEN
207
        CALL nocoInputCheck(atoms,input,vacuum,noco)
Daniel Wortmann's avatar
Daniel Wortmann committed
208

209
        IF (noco%l_ss) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
210 211 212 213 214 215 216 217 218 219

           !--->    the angle beta is relative to the spiral in a spin-spiral
           !--->    calculation, i.e. if beta = 0 for all atoms in the unit cell
           !--->    that means that the moments are "in line" with the spin-spiral
           !--->    (beta = qss * taual). note: this means that only atoms within
           !--->    a plane perpendicular to qss can be equivalent!

           na = 1
           DO iType = 1,atoms%ntype
              noco%phi = tpi_const*dot_product(noco%qss,atoms%taual(:,na))
220
              noco%alph(iType) = noco%alphInit(iType) + noco%phi
Daniel Wortmann's avatar
Daniel Wortmann committed
221 222 223
              na = na + atoms%neq(iType)
           END DO
        END IF
224 225
     ELSE
        IF (noco%l_ss) THEN
226
           CALL judft_warn("l_noco=F and l_ss=T is meaningless. Setting l_ss to F.")
227 228
           noco%l_ss = .FALSE.
        END IF
Daniel Wortmann's avatar
Daniel Wortmann committed
229 230 231
     END IF

     ! Calculate missing kpts parameters
232
     CALL kpoints(oneD,sym,cell,input,noco,banddos,kpts,l_kpts)
Daniel Wortmann's avatar
Daniel Wortmann committed
233 234
    
     ! Generate missing general parameters
235
     
236
     minNeigd = MAX(5,NINT(0.75*input%zelec) + 1)
Daniel Wortmann's avatar
Daniel Wortmann committed
237 238
     IF (noco%l_soc.and.(.not.noco%l_noco)) minNeigd = 2 * minNeigd
     IF (noco%l_soc.and.noco%l_ss) minNeigd=(3*minNeigd)/2
239
     IF ((dimension%neigd.NE.-1).AND.(dimension%neigd.LT.minNeigd)) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
240 241 242 243 244 245 246
        IF (dimension%neigd>0) THEN
           WRITE(*,*) 'numbands is too small. Setting parameter to default value.'
           WRITE(*,*) 'changed numbands (dimension%neigd) to ',minNeigd
        ENDIF
        dimension%neigd = minNeigd
     END IF

247
   
Daniel Wortmann's avatar
Daniel Wortmann committed
248 249
     !cell%aamat=matmul(transpose(cell%amat),cell%amat)
     cell%bbmat=matmul(cell%bmat,transpose(cell%bmat))
250 251 252 253

     CALL lapw_dim(kpts,cell,input,noco,oneD,forcetheo,DIMENSION)

     CALL lapw_fft_dim(cell,input,noco,stars)
254 255 256 257 258 259 260 261 262 263 264 265

     atoms%nlotot = 0
     DO n = 1, atoms%ntype
        DO l = 1,atoms%nlo(n)
           atoms%nlotot = atoms%nlotot + atoms%neq(n) * ( 2*atoms%llo(l,n) + 1 )
        END DO
     END DO

     IF(dimension%neigd.EQ.-1) THEN
        dimension%neigd = dimension%nvd + atoms%nlotot
     END IF

Daniel Wortmann's avatar
Daniel Wortmann committed
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
     obsolete%lepr = 0

     IF (noco%l_noco) dimension%neigd = 2*dimension%neigd

     ! Generate missing parameters for atoms and calculate volume of the different regions

     cell%volint = cell%vol
     atoms%jmtd = maxval(atoms%jri(:))
     CALL ylmnorm_init(atoms%lmaxd)
     dimension%nspd=(atoms%lmaxd+1+mod(atoms%lmaxd+1,2))*(2*atoms%lmaxd+1)
     rmtmax = maxval(atoms%rmt(:))
     rmtmax = rmtmax*stars%gmax
     CALL convn_dim(rmtmax,dimension%ncvd)
     dimension%msh = 0
     ALLOCATE(atoms%rmsh(atoms%jmtd,atoms%ntype))
     ALLOCATE(atoms%volmts(atoms%ntype))
     na = 0
     DO iType = 1, atoms%ntype
        l_vca = .FALSE.
        INQUIRE (file="vca.in", exist=l_vca)
        IF (l_vca) THEN
287
           WRITE(*,*) 'Note: Implementation for virtual crystal approximation should be changed in postprocessInput!'
Daniel Wortmann's avatar
Daniel Wortmann committed
288 289 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 317 318 319 320 321 322 323 324 325 326
           WRITE(*,*) 'I am not sure whether the implementation actually makes any sense. It is from inped.'
           WRITE(*,*) 'We have to get rid of the file vca.in!'
           OPEN (17,file='vca.in',form='formatted')
           DO i= 1, iType
              READ (17,*,IOSTAT=ios) ntst,zp
              IF (ios /= 0) EXIT
              IF (ntst == iType) THEN
                 atoms%zatom(iType) = atoms%zatom(iType) + zp
              END IF
           END DO
           CLOSE (17)
        END IF

        ! Calculate mesh for valence states
        radius = atoms%rmt(iType)*exp(atoms%dx(iType)*(1-atoms%jri(iType)))
        dr = exp(atoms%dx(iType))
        DO i = 1, atoms%jri(iType)
           atoms%rmsh(i,iType) = radius
           radius = radius*dr
        END DO
        ! Calculate mesh dimension for core states
        radius = atoms%rmt(iType)
        jrc = atoms%jri(iType)
        DO WHILE (radius < atoms%rmt(iType) + 20.0)
           jrc = jrc + 1
           radius = radius*dr
        END DO
        dimension%msh = max(dimension%msh,jrc)

        atoms%volmts(iType) = (fpi_const/3.0)*atoms%rmt(iType)**3
        cell%volint = cell%volint - atoms%volmts(iType)*atoms%neq(iType)
     END DO


     ! Check muffin tin radii

     ALLOCATE (jri1(atoms%ntype), lmax1(atoms%ntype))
     ALLOCATE (rmt1(atoms%ntype), dx1(atoms%ntype))
     l_test = .TRUE. ! only checking, dont use new parameters
327
     l_gga=xcpot%is_gga()
Daniel Wortmann's avatar
Daniel Wortmann committed
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 377 378 379 380 381 382 383 384 385 386 387 388 389
     CALL chkmt(atoms,input,vacuum,cell,oneD,l_gga,noel,l_test,&
                kmax1,dtild1,dvac1,lmax1,jri1,rmt1,dx1)
     DEALLOCATE (jri1,lmax1,rmt1,dx1)

     ! Dimensioning of lattice harmonics

     ALLOCATE(atoms%nlhtyp(atoms%ntype),atoms%ntypsy(atoms%nat))
     ALLOCATE(sphhar%clnu(1,1,1),sphhar%nlh(1),sphhar%llh(1,1),sphhar%nmem(1,1),sphhar%mlh(1,1,1))
     sphhar%ntypsd = 0
     IF (.NOT.oneD%odd%d1) THEN
        CALL local_sym(atoms%lmaxd,atoms%lmax,sym%nop,sym%mrot,sym%tau,&
             atoms%nat,atoms%ntype,atoms%neq,cell%amat,cell%bmat,&
             atoms%taual,sphhar%nlhd,sphhar%memd,sphhar%ntypsd,.true.,&
             atoms%nlhtyp,atoms%ntypsy,sphhar%nlh,sphhar%llh,&
             sphhar%nmem,sphhar%mlh,sphhar%clnu)
     ELSE IF (oneD%odd%d1) THEN
        WRITE(*,*) 'Note: I would be surprised if lattice harmonics generation works'
        WRITE(*,*) 'Dimensioning of local arrays seems to be inconsistent with routine local_sym'
        ALLOCATE (nq1(atoms%nat),lmx1(atoms%nat),nlhtp1(atoms%nat))
        ii = 1
        nq1=1
        DO i = 1,atoms%ntype
           DO j = 1,atoms%neq(i)
              lmx1(ii) = atoms%lmax(i)
              ii = ii + 1
           END DO
        END DO
        CALL local_sym(atoms%lmaxd,lmx1,sym%nop,sym%mrot,sym%tau,&
                       atoms%nat,atoms%nat,nq1,cell%amat,cell%bmat,atoms%taual,&
                       sphhar%nlhd,sphhar%memd,sphhar%ntypsd,.true.,nlhtp1,&
                       atoms%ntypsy,sphhar%nlh,sphhar%llh,sphhar%nmem,&
                       sphhar%mlh,sphhar%clnu)        
        ii = 1
        DO i = 1,atoms%ntype
           atoms%nlhtyp(i) = nlhtp1(ii)
           ii = ii + atoms%neq(i)
        END DO
        DEALLOCATE (nq1,lmx1,nlhtp1)
     END IF
     DEALLOCATE(sphhar%clnu,sphhar%nlh,sphhar%llh,sphhar%nmem,sphhar%mlh)

     ALLOCATE(sphhar%clnu(sphhar%memd,0:sphhar%nlhd,sphhar%ntypsd))
     ALLOCATE(sphhar%llh(0:sphhar%nlhd,sphhar%ntypsd))
     ALLOCATE(sphhar%mlh(sphhar%memd,0:sphhar%nlhd,sphhar%ntypsd))
     ALLOCATE(sphhar%nlh(sphhar%ntypsd),sphhar%nmem(0:sphhar%nlhd,sphhar%ntypsd))

     ! Dimensioning of stars

     IF (input%film.OR.(sym%namgrp.ne.'any ')) THEN
        CALL strgn1_dim(stars%gmax,cell%bmat,sym%invs,sym%zrfs,sym%mrot,&
                        sym%tau,sym%nop,sym%nop2,stars%mx1,stars%mx2,stars%mx3,&
                        stars%ng3,stars%ng2,oneD%odd)

     ELSE
        CALL strgn2_dim(stars%gmax,cell%bmat,sym%invs,sym%zrfs,sym%mrot,&
                        sym%tau,sym%nop,stars%mx1,stars%mx2,stars%mx3,&
                        stars%ng3,stars%ng2)
        oneD%odd%n2d = stars%ng2
        oneD%odd%nq2 = stars%ng2
        oneD%odd%nop = sym%nop
     END IF

390 391
     stars%kimax2= (2*stars%mx1+1)* (2*stars%mx2+1)-1
     stars%kimax = (2*stars%mx1+1)* (2*stars%mx2+1)* (2*stars%mx3+1)-1
Daniel Wortmann's avatar
Daniel Wortmann committed
392 393 394 395 396 397 398 399 400 401 402 403 404 405
     IF (oneD%odd%d1) THEN
        oneD%odd%k3 = stars%mx3
        oneD%odd%nn2d = (2*(oneD%odd%k3)+1)*(2*(oneD%odd%M)+1)
     ELSE
        oneD%odd%k3 = 0
        oneD%odd%M = 0
        oneD%odd%nn2d = 1
        oneD%odd%mb = 0
     END IF
     ALLOCATE (stars%ig(-stars%mx1:stars%mx1,-stars%mx2:stars%mx2,-stars%mx3:stars%mx3))
     ALLOCATE (stars%ig2(stars%ng3))
     ALLOCATE (stars%kv2(2,stars%ng2),stars%kv3(3,stars%ng3))
     ALLOCATE (stars%nstr2(stars%ng2),stars%nstr(stars%ng3))
     ALLOCATE (stars%sk2(stars%ng2),stars%sk3(stars%ng3),stars%phi2(stars%ng2))
406
     ALLOCATE (stars%igfft(0:stars%kimax,2),stars%igfft2(0:stars%kimax2,2))
Daniel Wortmann's avatar
Daniel Wortmann committed
407
     ALLOCATE (stars%rgphs(-stars%mx1:stars%mx1,-stars%mx2:stars%mx2,-stars%mx3:stars%mx3))
408
     ALLOCATE (stars%pgfft(0:stars%kimax),stars%pgfft2(0:stars%kimax2))
Daniel Wortmann's avatar
Daniel Wortmann committed
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
     ALLOCATE (stars%ufft(0:27*stars%mx1*stars%mx2*stars%mx3-1),stars%ustep(stars%ng3))

     stars%sk2(:) = 0.0
     stars%phi2(:) = 0.0

     ! Initialize xc fft box

     CALL prp_xcfft_box(xcpot%gmaxxc,cell%bmat,stars%kxc1_fft,stars%kxc2_fft,stars%kxc3_fft)

     ! Initialize missing 1D code arrays

     ALLOCATE (oneD%ig1(-oneD%odd%k3:oneD%odd%k3,-oneD%odd%M:oneD%odd%M))
     ALLOCATE (oneD%kv1(2,oneD%odd%n2d),oneD%nstr1(oneD%odd%n2d))
     ALLOCATE (oneD%ngopr1(atoms%nat),oneD%mrot1(3,3,oneD%odd%nop),oneD%tau1(3,oneD%odd%nop))
     ALLOCATE (oneD%invtab1(oneD%odd%nop),oneD%multab1(oneD%odd%nop,oneD%odd%nop))
     ALLOCATE (oneD%igfft1(0:oneD%odd%nn2d-1,2),oneD%pgfft1(0:oneD%odd%nn2d-1))

     ! Initialize missing hybrid functionals arrays

     ALLOCATE (hybrid%nindx(0:atoms%lmaxd,atoms%ntype))
429
   
Daniel Wortmann's avatar
Daniel Wortmann committed
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
     ! Generate lattice harmonics

     IF (.NOT.oneD%odd%d1) THEN
        CALL local_sym(atoms%lmaxd,atoms%lmax,sym%nop,sym%mrot,sym%tau,&
                       atoms%nat,atoms%ntype,atoms%neq,cell%amat,cell%bmat,atoms%taual,&
                       sphhar%nlhd,sphhar%memd,sphhar%ntypsd,.FALSE.,&
                       atoms%nlhtyp,atoms%ntypsy,sphhar%nlh,sphhar%llh,sphhar%nmem,sphhar%mlh,sphhar%clnu)
        sym%nsymt = sphhar%ntypsd
        oneD%mrot1(:,:,:) = sym%mrot(:,:,:)
        oneD%tau1(:,:) = sym%tau(:,:)
     ELSE IF (oneD%odd%d1) THEN
        WRITE(*,*) 'Note: I would be surprised if lattice harmonics generation works'
        WRITE(*,*) 'Dimensioning of local arrays seems to be inconsistent with routine local_sym'
        CALL od_chisym(oneD%odd,oneD%mrot1,oneD%tau1,sym%zrfs,sym%invs,sym%invs2,cell%amat)
        ALLOCATE (nq1(atoms%nat),lmx1(atoms%nat),nlhtp1(atoms%nat))
        ii = 1
        DO i = 1,atoms%ntype
           DO j = 1,atoms%neq(i)
              nq1(ii) = 1
              lmx1(ii) = atoms%lmax(i)
              ii = ii + 1
           END DO
        END DO
        CALL local_sym(atoms%lmaxd,lmx1,sym%nop,sym%mrot,sym%tau,&
                       atoms%nat,atoms%nat,nq1,cell%amat,cell%bmat,atoms%taual,&
                       sphhar%nlhd,sphhar%memd,sphhar%ntypsd,.FALSE.,&
                       nlhtp1,atoms%ntypsy,sphhar%nlh,sphhar%llh,sphhar%nmem,sphhar%mlh,sphhar%clnu)
        sym%nsymt = sphhar%ntypsd
        ii = 1
        DO i = 1,atoms%ntype
           atoms%nlhtyp(i) = nlhtp1(ii)
           ii = ii + atoms%neq(i)
        END DO
        DEALLOCATE (lmx1,nlhtp1)
     END IF

     ! Calculate additional symmetry information

     IF (atoms%n_u.GT.0) THEN
        CALL d_wigner(sym%nop,sym%mrot,cell%bmat,3,sym%d_wgn)
     END IF
     IF (.NOT.oneD%odd%d1) THEN
        CALL mapatom(sym,atoms,cell,input,noco)
        oneD%ngopr1(1:atoms%nat) = atoms%ngopr(1:atoms%nat)
        !     DEALLOCATE ( nq1 )
     ELSE
        CALL juDFT_error("The oneD version is broken here. Compare call to mapatom with old version")
        CALL mapatom(sym,atoms,cell,input,noco)
        CALL od_mapatom(oneD,atoms,sym,cell)
     END IF

     !Calculate kpoint in the full BZ
482
     IF (kpts%l_gamma.and. banddos%ndir .eq. 0.and.kpts%specificationType==2) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
483 484 485 486 487 488
        CALL gen_bz(kpts,sym)
     ELSE
        kpts%nkptf=0
     ENDIF

     ! Missing xc functionals initializations
489
     IF (xcpot%is_gga()) THEN
490
        ALLOCATE (stars%ft2_gfx(0:stars%kimax2),stars%ft2_gfy(0:stars%kimax2))
Daniel Wortmann's avatar
Daniel Wortmann committed
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
        ALLOCATE (oneD%pgft1x(0:oneD%odd%nn2d-1),oneD%pgft1xx(0:oneD%odd%nn2d-1),&
                  oneD%pgft1xy(0:oneD%odd%nn2d-1),&
                  oneD%pgft1y(0:oneD%odd%nn2d-1),oneD%pgft1yy(0:oneD%odd%nn2d-1))
     ELSE
        ALLOCATE (stars%ft2_gfx(0:1),stars%ft2_gfy(0:1))
        ALLOCATE (oneD%pgft1x(0:1),oneD%pgft1xx(0:1),oneD%pgft1xy(0:1),&
                  oneD%pgft1y(0:1),oneD%pgft1yy(0:1))
     END IF
     oneD%odd%nq2 = oneD%odd%n2d
     oneD%odi%nq2 = oneD%odd%nq2

     ! Store structure data

     CALL storeStructureIfNew(input, atoms, cell, vacuum, oneD, sym)

     ! Generate stars

Uliana Alekseeva's avatar
Uliana Alekseeva committed
508
     CALL timestart("strgn") 
Daniel Wortmann's avatar
Daniel Wortmann committed
509 510 511 512 513 514 515 516
     IF (input%film.OR.(sym%namgrp.NE.'any ')) THEN
        CALL strgn1(stars,sym,atoms,vacuum,sphhar,input,cell,xcpot)
        IF (oneD%odd%d1) THEN
           CALL od_strgn1(xcpot,cell,sym,oneD)
        END IF
     ELSE
        CALL strgn2(stars,sym,atoms,vacuum,sphhar,input,cell,xcpot)
     END IF
Uliana Alekseeva's avatar
Uliana Alekseeva committed
517
     CALL timestop("strgn") 
Daniel Wortmann's avatar
Daniel Wortmann committed
518 519 520 521 522 523 524 525 526

     ! Other small stuff

     input%strho = .FALSE.

     INQUIRE(file="cdn1",exist=l_opti)
     if (noco%l_noco) INQUIRE(file="rhomat_inp",exist=l_opti)
     l_opti=.not.l_opti
     IF ((sliceplot%iplot).OR.(input%strho).OR.(input%swsp).OR.&
527
         (input%lflip).OR.(input%l_bmt)) l_opti = .TRUE.
Daniel Wortmann's avatar
Daniel Wortmann committed
528 529 530 531 532 533 534 535 536 537

     IF (.NOT.l_opti) THEN
        !      The following call to inpeig should not be required.
        !      CALL inpeig(atoms,cell,input,oneD%odd%d1,kpts,enpara)
     END IF

     CALL prp_qfft(stars,cell,noco,input)


     CALL prp_xcfft(stars,input,cell,xcpot)
538
 
Daniel Wortmann's avatar
Daniel Wortmann committed
539 540 541 542 543
  END IF !(mpi%irank.EQ.0)
#ifdef CPP_MPI
  CALL MPI_BCAST(sliceplot%iplot,1,MPI_LOGICAL,0,mpi%mpi_comm,ierr)
#endif

Uliana Alekseeva's avatar
Uliana Alekseeva committed
544
  CALL timestart("stepf") 
545
  CALL stepf(sym,stars,atoms,oneD,input,cell,vacuum,mpi)
Uliana Alekseeva's avatar
Uliana Alekseeva committed
546
  CALL timestop("stepf") 
547
  IF (.NOT.sliceplot%iplot) THEN   
Daniel Wortmann's avatar
Daniel Wortmann committed
548 549
     IF (mpi%irank.EQ.0) THEN
        CALL convn(DIMENSION,atoms,stars)
550
        CALL e_field(atoms,DIMENSION,stars,sym,vacuum,cell,input,field%efield)
Daniel Wortmann's avatar
Daniel Wortmann committed
551 552 553
     END IF !(mpi%irank.EQ.0)
  END IF

554 555
  ! 

Daniel Wortmann's avatar
Daniel Wortmann committed
556 557 558 559 560 561 562
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! End of input postprocessing (calculate missing parameters)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

END SUBROUTINE postprocessInput

END MODULE m_postprocessInput