postprocessInput.F90 21.2 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
18

  USE m_juDFT
  USE m_types
  USE m_constants
  USE m_julia
19
  USE m_lapwdim
Daniel Wortmann's avatar
Daniel Wortmann committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  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_writegw
  USE m_prpxcfft
  USE m_stepf
  USE m_convn
  USE m_efield
  USE m_od_mapatom
  USE m_kptgen_hybrid
  USE m_od_kptsgen
  USE m_gen_bz
  USE m_nocoInputCheck
  USE m_kpoints
  IMPLICIT NONE

  TYPE(t_mpi)      ,INTENT   (IN) :: mpi
46
47
48
49
50
51
52
53
54
55
56
57
58
  CLASS(t_forcetheo),ALLOCATABLE,INTENT(IN)   :: forcetheo
  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
           END IF
           IF (input%isec1<input%itmax) THEN
103
              CALL juDFT_error("LO + Wu not implemented",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
104
105
106
           END IF
           IF (atoms%nlo(iType).GT.atoms%nlod) THEN
              WRITE (6,*) 'nlo(n) =',atoms%nlo(iType),' > nlod =',atoms%nlod
107
              CALL juDFT_error("nlo(n)>nlod",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
108
109
110
111
112
113
114
115
116
117
           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
118
                 CALL juDFT_error("llo(j,n)>llod",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
              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)
140
              IF (atoms%llo(ilo,iType)>atoms%llod) CALL juDFT_error(" l > llod!!!",calledby="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
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
166
167
168
              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
169
170
171
        IF (input%secvar) CALL juDFT_error("LDA+U and sevcar not implemented",calledby ="postprocessInput")
        IF (input%isec1<input%itmax) CALL juDFT_error("LDA+U and Wu 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
172
173
174
175
176
177
     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'//&
178
             ' can only be used if dos = true',calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
179
180
181
182
183
     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 "//&
184
                "internal dos-program",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
185
186
187
        END IF
        IF (banddos%sig_dos.LT.0) THEN
           CALL juDFT_error("STOP DOS: no valid broadening (sig_dos) for "//&
188
                "internal dos-PROGRAM",calledby ="postprocessInput")
Daniel Wortmann's avatar
Daniel Wortmann committed
189
190
191
192
193
        END IF
     END IF

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

     ! Check noco stuff and calculate missing noco parameters

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

214
        IF (noco%l_ss) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
215
216
217
218
219
220
221
222
223
224

           !--->    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))
225
              noco%alph(iType) = noco%alphInit(iType) + noco%phi
Daniel Wortmann's avatar
Daniel Wortmann committed
226
227
228
              na = na + atoms%neq(iType)
           END DO
        END IF
229
230
     ELSE
        IF (noco%l_ss) THEN
231
           CALL judft_warn("l_noco=F and l_ss=T is meaningless. Setting l_ss to F.")
232
233
           noco%l_ss = .FALSE.
        END IF
Daniel Wortmann's avatar
Daniel Wortmann committed
234
235
236
     END IF

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

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

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

     CALL lapw_fft_dim(cell,input,noco,stars)
     
260
        
Daniel Wortmann's avatar
Daniel Wortmann committed
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
     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
282
           WRITE(*,*) 'Note: Implementation for virtual crystal approximation should be changed in postprocessInput!'
Daniel Wortmann's avatar
Daniel Wortmann committed
283
284
285
286
287
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
           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
322
     l_gga=xcpot%is_gga()
Daniel Wortmann's avatar
Daniel Wortmann committed
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
     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

     dimension%nn2d = (2*stars%mx1+1)*(2*stars%mx2+1)
     dimension%nn3d = (2*stars%mx1+1)*(2*stars%mx2+1)*(2*stars%mx3+1)
     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))
     ALLOCATE (stars%igfft(0:dimension%nn3d-1,2),stars%igfft2(0:dimension%nn2d-1,2))
     ALLOCATE (stars%rgphs(-stars%mx1:stars%mx1,-stars%mx2:stars%mx2,-stars%mx3:stars%mx3))
     ALLOCATE (stars%pgfft(0:dimension%nn3d-1),stars%pgfft2(0:dimension%nn2d-1))
     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))
424
   
Daniel Wortmann's avatar
Daniel Wortmann committed
425
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
467
468
469
470
471
472
473
474
475
476
     ! 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
477
     IF (kpts%l_gamma.and. banddos%ndir .eq. 0.and.kpts%specificationType==2) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
478
479
480
481
482
483
        CALL gen_bz(kpts,sym)
     ELSE
        kpts%nkptf=0
     ENDIF

     ! Missing xc functionals initializations
484
     IF (xcpot%is_gga()) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
        ALLOCATE (stars%ft2_gfx(0:dimension%nn2d-1),stars%ft2_gfy(0:dimension%nn2d-1))
        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

     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

     ! 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.&
520
         (input%lflip).OR.(input%l_bmt)) l_opti = .TRUE.
Daniel Wortmann's avatar
Daniel Wortmann committed
521
522
523
524
525
526
527
528
529
530
531
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

     CALL prp_qfft(stars,cell,noco,input)

     IF (input%gw.GE.1) THEN
        CALL write_gw(atoms%ntype,sym%nop,1,input%jspins,atoms%nat,&
                      atoms%ncst,atoms%neq,atoms%lmax,sym%mrot,cell%amat,cell%bmat,input%rkmax,&
                      atoms%taual,atoms%zatom,cell%vol,1.0,DIMENSION%neigd,atoms%lmaxd,&
                      atoms%nlod,atoms%llod,atoms%nlo,atoms%llo,noco%l_soc)
     END IF

     CALL prp_xcfft(stars,input,cell,xcpot)
537
 
Daniel Wortmann's avatar
Daniel Wortmann committed
538
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

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

551
552
  ! 

Daniel Wortmann's avatar
Daniel Wortmann committed
553
554
555
556
557
558
559
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! End of input postprocessing (calculate missing parameters)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

END SUBROUTINE postprocessInput

END MODULE m_postprocessInput