postprocessInput.F90 21.4 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
  USE m_kpoints   
  USE m_types_forcetheo_extended
41
  USE m_relaxio
42

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

  TYPE(t_mpi)      ,INTENT   (IN) :: mpi
46
  CLASS(t_forcetheo),INTENT(IN)   :: forcetheo
47 48 49 50 51 52 53 54 55 56 57 58
  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
59
  CLASS(t_xcpot),   INTENT(INOUT) :: xcpot
Daniel Wortmann's avatar
Daniel Wortmann committed
60 61 62 63
  TYPE(t_noco),     INTENT(INOUT) :: noco
  TYPE(t_dimension),INTENT(INOUT) :: dimension
  TYPE(t_enpara)   ,INTENT(INOUT) :: enpara
  TYPE(t_sphhar)   ,INTENT  (OUT) :: sphhar
64
  TYPE(t_field),    INTENT(INOUT) :: field
Daniel Wortmann's avatar
Daniel Wortmann committed
65 66 67 68
  LOGICAL,          INTENT  (OUT) :: l_opti
  LOGICAL,          INTENT   (IN) :: l_kpts
  CHARACTER(len=3), ALLOCATABLE, INTENT(IN) :: noel(:)

69
  INTEGER              :: i, j, n, na, n1, n2, iType, l, ilo, ikpt
Daniel Wortmann's avatar
Daniel Wortmann committed
70 71 72 73 74
  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)
75 76
  LOGICAL              :: l_vca, l_test,l_gga
 
Daniel Wortmann's avatar
Daniel Wortmann committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
  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
100
              CALL juDFT_error("LO + sevcar not implemented",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
101 102 103
           END IF
           IF (atoms%nlo(iType).GT.atoms%nlod) THEN
              WRITE (6,*) 'nlo(n) =',atoms%nlo(iType),' > nlod =',atoms%nlod
104
              CALL juDFT_error("nlo(n)>nlod",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
105 106 107 108 109 110 111 112 113 114
           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
115
                 CALL juDFT_error("llo(j,n)>llod",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
              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)
137
              IF (atoms%llo(ilo,iType)>atoms%llod) CALL juDFT_error(" l > llod!!!",calledby="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
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 165
              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
166 167
        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
168 169 170 171 172 173
     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'//&
174
             ' can only be used if dos = true',calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
175 176 177 178 179
     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 "//&
180
                "internal dos-program",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
181 182 183
        END IF
        IF (banddos%sig_dos.LT.0) THEN
           CALL juDFT_error("STOP DOS: no valid broadening (sig_dos) for "//&
184
                "internal dos-PROGRAM",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
185 186 187 188 189
        END IF
     END IF

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

     ! Check noco stuff and calculate missing noco parameters

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

210
        IF (noco%l_ss) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
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
220
              noco%alph(iType) = noco%alphInit(iType) + tpi_const*dot_product(noco%qss,atoms%taual(:,na))
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
229 230 231 232
        IF (noco%l_mperp) THEN
           CALL judft_warn("l_noco=F and l_mperp=T is meaningless. Setting l_mperp to F.")
           noco%l_mperp = .FALSE.
        END IF
Daniel Wortmann's avatar
Daniel Wortmann committed
233 234 235
     END IF

     ! Calculate missing kpts parameters
236
     CALL kpoints(oneD,sym,cell,input,noco,banddos,kpts,l_kpts)
Daniel Wortmann's avatar
Daniel Wortmann committed
237 238
    
     ! Generate missing general parameters
239
     
240
     minNeigd = MAX(5,NINT(0.75*input%zelec) + 1)
Daniel Wortmann's avatar
Daniel Wortmann committed
241 242
     IF (noco%l_soc.and.(.not.noco%l_noco)) minNeigd = 2 * minNeigd
     IF (noco%l_soc.and.noco%l_ss) minNeigd=(3*minNeigd)/2
243
     IF ((dimension%neigd.NE.-1).AND.(dimension%neigd.LT.minNeigd)) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
244 245 246 247 248 249 250
        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

251
   
Daniel Wortmann's avatar
Daniel Wortmann committed
252 253
     !cell%aamat=matmul(transpose(cell%amat),cell%amat)
     cell%bbmat=matmul(cell%bmat,transpose(cell%bmat))
254 255 256 257

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

     CALL lapw_fft_dim(cell,input,noco,stars)
258 259 260 261 262 263 264 265 266 267 268 269

     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
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
     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
291
           WRITE(*,*) 'Note: Implementation for virtual crystal approximation should be changed in postprocessInput!'
Daniel Wortmann's avatar
Daniel Wortmann committed
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 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 377 378 379 380 381 382 383 384 385
           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




     ! 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

386 387
     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
388 389 390 391 392 393 394 395 396 397 398 399 400 401
     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))
402
     ALLOCATE (stars%igfft(0:stars%kimax,2),stars%igfft2(0:stars%kimax2,2))
Daniel Wortmann's avatar
Daniel Wortmann committed
403
     ALLOCATE (stars%rgphs(-stars%mx1:stars%mx1,-stars%mx2:stars%mx2,-stars%mx3:stars%mx3))
404
     ALLOCATE (stars%pgfft(0:stars%kimax),stars%pgfft2(0:stars%kimax2))
Daniel Wortmann's avatar
Daniel Wortmann committed
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
     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))
425
   
Daniel Wortmann's avatar
Daniel Wortmann committed
426 427 428 429 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
     ! 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
467

Daniel Wortmann's avatar
Daniel Wortmann committed
468 469 470 471 472 473 474 475 476
     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
477 478 479 480 481 482 483
    ! Check muffin tin radii

     l_test = .TRUE. ! only checking, dont use new parameters
     CALL chkmt(atoms,input,vacuum,cell,oneD,l_test)

     !adjust positions by displacements
     CALL apply_displacements(cell,input,vacuum,oneD,sym,noco,atoms)
Daniel Wortmann's avatar
Daniel Wortmann committed
484 485

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

     ! Missing xc functionals initializations
493
     IF (xcpot%needs_grad()) THEN
494
        ALLOCATE (stars%ft2_gfx(0:stars%kimax2),stars%ft2_gfy(0:stars%kimax2))
Daniel Wortmann's avatar
Daniel Wortmann committed
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

508
     CALL storeStructureIfNew(input,stars, atoms, cell, vacuum, oneD, sym, mpi,sphhar,noco)
Daniel Wortmann's avatar
Daniel Wortmann committed
509 510 511

     ! Generate stars

Uliana Alekseeva's avatar
Uliana Alekseeva committed
512
     CALL timestart("strgn") 
Daniel Wortmann's avatar
Daniel Wortmann committed
513 514 515 516 517 518 519 520
     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
521
     CALL timestop("strgn") 
Daniel Wortmann's avatar
Daniel Wortmann committed
522 523 524 525 526 527 528 529 530

     ! 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.&
531
         (input%lflip).OR.(input%l_bmt)) l_opti = .TRUE.
Daniel Wortmann's avatar
Daniel Wortmann committed
532 533 534 535 536

     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
537
     kpts%wtkpt=kpts%wtkpt/sum(kpts%wtkpt) !Normalize k-point weight
Daniel Wortmann's avatar
Daniel Wortmann committed
538 539 540 541
     CALL prp_qfft(stars,cell,noco,input)


     CALL prp_xcfft(stars,input,cell,xcpot)
542
 
Daniel Wortmann's avatar
Daniel Wortmann committed
543 544 545
  END IF !(mpi%irank.EQ.0)
#ifdef CPP_MPI
  CALL MPI_BCAST(sliceplot%iplot,1,MPI_LOGICAL,0,mpi%mpi_comm,ierr)
546
  CALL MPI_BCAST(input%qfix,1,MPI_INTEGER,0,mpi%mpi_comm,ierr)
547
  CALL MPI_BCAST(noco%l_noco,1,MPI_LOGICAL,0,mpi%mpi_comm,ierr)
Daniel Wortmann's avatar
Daniel Wortmann committed
548 549
#endif

Uliana Alekseeva's avatar
Uliana Alekseeva committed
550
  CALL timestart("stepf") 
551
  CALL stepf(sym,stars,atoms,oneD,input,cell,vacuum,mpi)
Uliana Alekseeva's avatar
Uliana Alekseeva committed
552
  CALL timestop("stepf") 
553
  IF (.NOT.sliceplot%iplot) THEN   
Daniel Wortmann's avatar
Daniel Wortmann committed
554 555
     IF (mpi%irank.EQ.0) THEN
        CALL convn(DIMENSION,atoms,stars)
556
        CALL e_field(atoms,DIMENSION,stars,sym,vacuum,cell,input,field%efield)
Daniel Wortmann's avatar
Daniel Wortmann committed
557 558 559
     END IF !(mpi%irank.EQ.0)
  END IF

560
  !At some point this should be enabled for noco as well
561
#ifdef CPP_MPI
562
  CALL MPI_BCAST(atoms%nat,1,MPI_INTEGER,0,mpi%mpi_comm,ierr)
563
#endif
564
  IF (.not.noco%l_noco) & 
565
  CALL transform_by_moving_atoms(mpi,stars,atoms,vacuum, cell, sym, sphhar,input,oned,noco)
566

Daniel Wortmann's avatar
Daniel Wortmann committed
567 568 569 570 571 572 573
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! End of input postprocessing (calculate missing parameters)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

END SUBROUTINE postprocessInput

END MODULE m_postprocessInput