fleur.F90 18.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
MODULE m_fleur
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
  IMPLICIT NONE
CONTAINS
  SUBROUTINE fleur_execute(mpi_comm)

    !     ***************************************************************
    !
    !     based on flapw7 (c.l.fu, m.weinert, e.wimmer):
    !     full potential linearized augmented plane wave method for thin
    !     films and superlattices (version 7 ---- general symmetry)
    !     symmetry part       ---  e.wimmer
    !     potential generator ---  c.l.fu,r.podloucky
    !     matrix elements     ---  m.weinert
    !     charge density      ---  c.l.fu
    !                                c.l.fu        1987
    !     2nd variation diagon.  --- r.-q. wu      1992
    !     forces a la Yu et al   --- r.podloucky   1995
    !     full relativistic core --- a.shick       1996
    !     broyden mixing         --- r.pentcheva   1996
    !     gga (pw91, pbe)        --- t.asada       1997
    !     local orbitals         --- p.kurz        1997
    !     automatic symmetry     --- w.hofer       1997
    !     core tails & start     --- r.abt         1998
    !     spin orbit coupling    --- a.shick,x.nie 1998
    !     non-colinear magnet.   --- p.kurz        1999
    !     one-dimensional        --- y.mokrousov   2002
    !     exchange parameters    --- m.lezaic      2004
    !
    !                       g.bihlmayer, s.bluegel 1999
    !     ***************************************************************
    !----------------------------------------
    ! this routine is the main PROGRAM

    USE m_types
    USE m_constants
    USE m_fleur_init
    USE m_optional
44
    USE m_cdn_io
45
    USE m_broyd_io
46
    USE m_qfix
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
    USE m_vgen
    USE m_rhodirgen
    USE m_writexcstuff
    USE m_vmatgen
    USE m_eigen
    USE m_eigenso
    USE m_fermie
    USE m_force0
    USE m_cdngen
    USE m_totale
    USE m_potdis
    USE m_mix
    USE m_xmlOutput
    USE m_juDFT_time
    USE m_calc_hybrid
    USE m_wann_optional
    USE m_wannier
    USE m_bs_comfort
    USE m_gen_map
    USE m_dwigner
    USE m_ylm
68
#ifdef CPP_MPI
69
    USE m_mpi_bc_all,  ONLY : mpi_bc_all
70
    USE m_mpi_bc_potden
71
#endif
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    USE m_eig66_io,   ONLY : open_eig, close_eig
    IMPLICIT NONE

    INTEGER,INTENT(IN) :: mpi_comm

    !     Types, these variables contain a lot of data!
    TYPE(t_input)    :: input
    TYPE(t_dimension):: DIMENSION
    TYPE(t_atoms)    :: atoms
    TYPE(t_sphhar)   :: sphhar
    TYPE(t_cell)     :: cell
    TYPE(t_stars)    :: stars
    TYPE(t_sym)      :: sym
    TYPE(t_noco)     :: noco
    TYPE(t_vacuum)   :: vacuum
    TYPE(t_sliceplot):: sliceplot
    TYPE(t_banddos)  :: banddos
    TYPE(t_obsolete) :: obsolete
90
    TYPE(t_enpara)   :: enpara
91 92 93 94 95 96
    TYPE(t_xcpot)    :: xcpot
    TYPE(t_results)  :: results
    TYPE(t_kpts)     :: kpts
    TYPE(t_hybrid)   :: hybrid
    TYPE(t_oneD)     :: oneD
    TYPE(t_mpi)      :: mpi
97
    TYPE(t_coreSpecInput) :: coreSpecInput
98
    TYPE(t_wann)     :: wann
99
    TYPE(t_potden)   :: vTot,vx,vCoul,vTemp
100
    TYPE(t_potden)   :: inDen, outDen, inDenRot
101
    CLASS(t_forcetheo),ALLOCATABLE:: forcetheo
102 103

    !     .. Local Scalars ..
104
    INTEGER:: eig_id, archiveType
105 106
    INTEGER:: n,it,ithf
    LOGICAL:: reap,l_opti,l_cont,l_qfix, l_wann_inp
107
    REAL   :: fermiEnergyTemp, fix
108
#ifdef CPP_MPI
109 110
    INCLUDE 'mpif.h'
    INTEGER:: ierr(2)
111
#endif
112

113
    mpi%mpi_comm = mpi_comm
114
 
115
    CALL timestart("Initialization")
116
    CALL fleur_init(mpi,input,DIMENSION,atoms,sphhar,cell,stars,sym,noco,vacuum,forcetheo,&
117
         sliceplot,banddos,obsolete,enpara,xcpot,results,kpts,hybrid,&
118
         oneD,coreSpecInput,wann,l_opti)
119
    CALL timestop("Initialization")
Daniel Wortmann's avatar
Daniel Wortmann committed
120 121


122

123 124 125 126
    IF (l_opti) &
         CALL OPTIONAL(mpi,atoms,sphhar,vacuum,DIMENSION,&
         stars,input,sym,cell,sliceplot,obsolete,xcpot,noco,oneD)
 
127 128

    !+Wannier
129 130
    INQUIRE (file='wann_inp',exist=l_wann_inp)
    input%l_wann = input%l_wann.OR.l_wann_inp
131 132
    IF (input%l_wann.AND.(mpi%irank==0).AND.(.NOT.wann%l_bs_comf)) THEN
       IF(mpi%isize.NE.1) CALL juDFT_error('No Wannier+MPI at the moment',calledby = 'fleur')
133
       CALL wann_optional(input,kpts,atoms,sym,cell,oneD,noco,wann)
134 135 136
    END IF
    IF (wann%l_gwf) input%itmax = 1

137
    !-Wannier
138 139 140 141 142


    it     = 0
    ithf   = 0
    l_cont = ( it < input%itmax )
143
    
144 145 146
    results%last_distance = -1.0
    IF (mpi%irank.EQ.0) CALL openXMLElementNoAttributes('scfLoop')

147
    ! Initialize and load inDen density (start)
Gregor Michalicek's avatar
Gregor Michalicek committed
148 149
    CALL inDen%init(stars,atoms,sphhar,vacuum,noco,oneD,input%jspins,noco%l_noco,POTDEN_TYPE_DEN)
    CALL inDenRot%init(stars,atoms,sphhar,vacuum,noco,oneD,input%jspins,noco%l_noco,POTDEN_TYPE_DEN)
150 151 152 153

    archiveType = CDN_ARCHIVE_TYPE_CDN1_const
    IF (noco%l_noco) archiveType = CDN_ARCHIVE_TYPE_NOCO_const

154 155
    IF(mpi%irank.EQ.0) THEN
       CALL readDensity(stars,vacuum,atoms,cell,sphhar,input,sym,oneD,archiveType,CDN_INPUT_DEN_const,&
156
            0,fermiEnergyTemp,l_qfix,inDen)
157
       CALL timestart("Qfix")
158
       CALL qfix(stars,atoms,sym,vacuum, sphhar,input,cell,oneD,inDen,noco%l_noco,.FALSE.,.false.,fix)
159 160
       CALL timestop("Qfix")
       CALL writeDensity(stars,vacuum,atoms,cell,sphhar,input,sym,oneD,archiveType,CDN_INPUT_DEN_const,&
161
            0,-1.0,0.0,.FALSE.,inDen)
162
    END IF
163
    ! Initialize and load inDen density (end)
164

165
    ! Initialize potentials (start)
166 167
    CALL vTot%init(stars,atoms,sphhar,vacuum,noco,oneD,DIMENSION%jspd,noco%l_noco,POTDEN_TYPE_POTTOT)
    CALL vCoul%init(stars,atoms,sphhar,vacuum,noco,oneD,DIMENSION%jspd,noco%l_noco,POTDEN_TYPE_POTCOUL)
168
    CALL vx%init(stars,atoms,sphhar,vacuum,noco,oneD,DIMENSION%jspd,.FALSE.,POTDEN_TYPE_POTCOUL)
169
    CALL vTemp%init(stars,atoms,sphhar,vacuum,noco,oneD,DIMENSION%jspd,noco%l_noco,POTDEN_TYPE_POTTOT)
170
    ! Initialize potentials (end)
171

172
    scfloop:DO WHILE (l_cont)
173 174

       it = it + 1
175 176
       IF (mpi%irank.EQ.0) CALL openXMLElementFormPoly('iteration',(/'numberForCurrentRun','overallNumber      '/)&
            ,(/it,inden%iter/), RESHAPE((/19,13,5,5/),(/2,2/)))
177 178
       inDenRot = inDen

179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
!!$       !+t3e
!!$       IF (input%alpha.LT.10.0) THEN
!!$
!!$          IF (it.GT.1) THEN
!!$             input%alpha = input%alpha - NINT(input%alpha)
!!$          END IF

       CALL resetIterationDependentTimers()
       CALL timestart("Iteration")
       IF (mpi%irank.EQ.0) THEN
          !-t3e
          WRITE (6,FMT=8100) it
          WRITE (16,FMT=8100) it
8100      FORMAT (/,10x,'   it=    ',i5)


          !      ----> potential generator
          !
          !---> pk non-collinear
          !--->        reload the density matrix from file rhomat_in
          !--->        calculate spin-up and -down density for USE in the
          !--->        potential generator and store the direction of
          !--->        magnetization on file dirofmag
          IF (noco%l_noco) THEN
             CALL timestart("gen. spin-up and -down density")
             CALL rhodirgen(DIMENSION,sym,stars,atoms,sphhar,&
                  vacuum,cell,input,noco,oneD,inDenRot)
             CALL timestop("gen. spin-up and -down density")
          ENDIF
          !---> pk non-collinear
209

210 211 212
          reap=.NOT.obsolete%disp
          input%total = .TRUE.
       ENDIF !mpi%irank.eq.0
213
#ifdef CPP_MPI
214
       CALL MPI_BCAST(input%total,1,MPI_LOGICAL,0,mpi%mpi_comm,ierr)
215
#endif
216

217
#ifdef CPP_MPI
218 219
       CALL mpi_bc_potden(mpi,stars,sphhar,atoms,input,vacuum,oneD,noco,inDen)
       CALL mpi_bc_potden(mpi,stars,sphhar,atoms,input,vacuum,oneD,noco,inDenRot)
220 221
#endif

Daniel Wortmann's avatar
Daniel Wortmann committed
222

223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
       IF ( noco%l_soc ) THEN
          dimension%neigd2 = dimension%neigd*2
       ELSE
          dimension%neigd2 = dimension%neigd
       END IF


       !HF
       IF (hybrid%l_hybrid) CALL  calc_hybrid(hybrid,kpts,atoms,input,DIMENSION,mpi,noco,&
            cell,vacuum,oneD,banddos,results,sym,xcpot,vTot,it)
       !#endif

!!$             DO pc = 1, wann%nparampts
!!$                !---> gwf
!!$                IF (wann%l_sgwf.OR.wann%l_ms) THEN
!!$                   noco%qss(:) = wann%param_vec(:,pc)
!!$                   noco%alph(:) = wann%param_alpha(:,pc)
!!$                ELSE IF (wann%l_socgwf) THEN
!!$                   IF(wann%l_dim(2)) noco%phi   = tpi_const * wann%param_vec(2,pc)
!!$                   IF(wann%l_dim(3)) noco%theta = tpi_const * wann%param_vec(3,pc)
!!$                END IF
       !---< gwf

       CALL timestart("generation of potential")
       CALL vgen(hybrid,reap,input,xcpot,DIMENSION, atoms,sphhar,stars,vacuum,&
            sym,obsolete,cell, oneD,sliceplot,mpi ,results,noco,inDen,inDenRot,vTot,vx,vCoul)
       CALL timestop("generation of potential")

       IF (mpi%irank.EQ.0) THEN
          !---> pk non-collinear
          !--->          generate the four component matrix potential from spin up
          !--->          and down potentials and direction of the magnetic field
          IF (noco%l_noco) THEN
             CALL timestart("generation of potential-matrix")
             CALL vmatgen(stars, atoms,sphhar,vacuum,sym,input,oneD,inDenRot,vTot)
             CALL timestop("generation of potential-matrix")
          ENDIF
          !
       ENDIF ! mpi%irank.eq.0
262

Daniel Wortmann's avatar
Daniel Wortmann committed
263 264


265
#ifdef CPP_MPI
266
       CALL MPI_BARRIER(mpi%mpi_comm,ierr)
267 268
#endif

269 270
       CALL forcetheo%start()

271
       forcetheoloop:DO WHILE(forcetheo%next_job(it==input%itmax,noco))
272

273

274 275 276
          CALL timestart("generation of hamiltonian and diagonalization (total)")
          CALL timestart("eigen")
          vTemp = vTot
277
          CALL enpara%update(mpi,atoms,vacuum,input,vToT)
278
          CALL eigen(mpi,stars,sphhar,atoms,obsolete,xcpot,&
279
               sym,kpts,DIMENSION,vacuum,input,cell,enpara,banddos,noco,oneD,hybrid,&
280 281 282 283 284 285 286
               it,eig_id,results,inDenRot,vTemp,vx)
          vTot%mmpMat = vTemp%mmpMat
!!$          eig_idList(pc) = eig_id
          CALL timestop("eigen")
          !
          !                   add all contributions to total energy
          !
287
#ifdef CPP_MPI
288 289 290 291 292 293 294 295 296 297 298 299 300
          ! send all result of local total energies to the r
          IF (mpi%irank==0) THEN
             CALL MPI_Reduce(MPI_IN_PLACE,results%te_hfex%valence,&
                  1,MPI_REAL8,MPI_SUM,0,mpi%mpi_comm,ierr(1))
             CALL MPI_Reduce(MPI_IN_PLACE,results%te_hfex%core,&
                  1,MPI_REAL8,MPI_SUM,0,mpi%mpi_comm,ierr(1))
          ELSE
             CALL MPI_Reduce(results%te_hfex%valence,MPI_IN_PLACE,&
                  1,MPI_REAL8,MPI_SUM,0, mpi%mpi_comm,ierr(1))
             CALL MPI_Reduce(results%te_hfex%core,MPI_IN_PLACE,&
                  1,MPI_REAL8,MPI_SUM,0, mpi%mpi_comm,ierr(1))
          ENDIF
          !                                  END IF
301 302
#endif

Daniel Wortmann's avatar
Daniel Wortmann committed
303

304

305 306 307
          ! WRITE(6,fmt='(A)') 'Starting 2nd variation ...'
          IF (noco%l_soc.AND..NOT.noco%l_noco) &
               CALL eigenso(eig_id,mpi,DIMENSION,stars,vacuum,atoms,sphhar,&
308
               obsolete,sym,cell,noco,input,kpts, oneD,vTot,enpara)
309
          CALL timestop("generation of hamiltonian and diagonalization (total)")
310 311

#ifdef CPP_MPI
312
          CALL MPI_BARRIER(mpi%mpi_comm,ierr)
313 314
#endif

315 316 317 318 319 320 321 322 323 324 325 326
          !
          !              ----> fermi level and occupancies

          IF ( noco%l_soc .AND. (.NOT. noco%l_noco) ) DIMENSION%neigd = 2*DIMENSION%neigd
          IF( .NOT. ALLOCATED(results%w_iks) )&
               ALLOCATE ( results%w_iks(DIMENSION%neigd,kpts%nkpt,DIMENSION%jspd) )
          IF ( (mpi%irank.EQ.0)) THEN
             CALL timestart("determination of fermi energy")

             IF ( noco%l_soc .AND. (.NOT. noco%l_noco) ) THEN
                input%zelec = input%zelec*2
                CALL fermie(eig_id,mpi,kpts,obsolete,&
327
                     input,noco,enpara%epara_min,cell,results)
328 329 330 331 332
                results%seigscv = results%seigscv/2
                results%ts = results%ts/2
                input%zelec = input%zelec/2
             ELSE
                CALL fermie(eig_id,mpi,kpts,obsolete,&
333
                     input,noco,enpara%epara_min,cell,results)
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
             ENDIF
             CALL timestop("determination of fermi energy")
!!$             
!!$          !+Wannier
!!$          IF(wann%l_bs_comf)THEN
!!$             IF(pc.EQ.1) THEN
!!$                OPEN(777,file='out_eig.1')
!!$                OPEN(778,file='out_eig.2')
!!$                OPEN(779,file='out_eig.1_diag')
!!$                OPEN(780,file='out_eig.2_diag')
!!$             END IF
!!$
!!$             CALL bs_comfort(eig_id,DIMENSION,input,noco,kpts%nkpt,pc)
!!$
!!$             IF(pc.EQ.wann%nparampts)THEN
!!$                CLOSE(777)
!!$                CLOSE(778)
!!$                CLOSE(779)
!!$                CLOSE(780)
!!$             END IF
!!$          END IF
!!$          !-Wannier
          ENDIF
357
#ifdef CPP_MPI
358 359
          CALL MPI_BCAST(results%ef,1,MPI_DOUBLE_PRECISION,0,mpi%mpi_comm,ierr)
          CALL MPI_BCAST(results%w_iks,SIZE(results%w_iks),MPI_DOUBLE_PRECISION,0,mpi%mpi_comm,ierr)
360 361 362
#endif


363
          IF (forcetheo%eval(eig_id,DIMENSION,atoms,kpts,sym,&
364 365 366 367
               cell,noco, input,mpi, oneD,enpara,vToT,results)) THEN
             IF ( noco%l_soc .AND. (.NOT. noco%l_noco) ) DIMENSION%neigd=DIMENSION%neigd/2
             CYCLE forcetheoloop
          ENDIF
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386


          CALL force_0(results)!        ----> initialise force_old
          !        ----> charge density
          
!!$          !+Wannier functions
!!$          IF ((input%l_wann).AND.(.NOT.wann%l_bs_comf)) THEN
!!$             CALL wannier(DIMENSION,mpi,input,kpts,sym,atoms,stars,vacuum,sphhar,oneD,&
!!$                  wann,noco,cell,enpara,banddos,sliceplot,vTot,results,&
!!$                  eig_idList,(sym%invs).AND.(.NOT.noco%l_soc).AND.(.NOT.noco%l_noco),kpts%nkpt)
!!$          END IF
!!$          IF (wann%l_gwf) CALL juDFT_error("provide wann_inp if l_gwf=T", calledby = "fleur")
!!$          !-Wannier

          CALL timestart("generation of new charge density (total)")
          CALL outDen%init(stars,atoms,sphhar,vacuum,noco,oneD,input%jspins,noco%l_noco,POTDEN_TYPE_DEN)
          outDen%iter = inDen%iter
          CALL cdngen(eig_id,mpi,input,banddos,sliceplot,vacuum,&
               DIMENSION,kpts,atoms,sphhar,stars,sym,obsolete,&
387
               enpara,cell,noco,vTot,results,oneD,coreSpecInput,&
388 389 390 391
               archiveType,outDen)

          IF ( noco%l_soc .AND. (.NOT. noco%l_noco) ) DIMENSION%neigd=DIMENSION%neigd/2
          !+t3e
392
#ifdef CPP_MPI
393 394 395 396 397 398 399 400 401
          CALL MPI_BCAST(enpara%evac0,SIZE(enpara%evac0),MPI_DOUBLE_PRECISION,0,mpi%mpi_comm,ierr)
          CALL MPI_BCAST(enpara%el0,SIZE(enpara%el0),MPI_DOUBLE_PRECISION,0,mpi%mpi_comm,ierr)
          CALL MPI_BCAST(enpara%ello0,SIZE(enpara%ello0),MPI_DOUBLE_PRECISION,0,mpi%mpi_comm,ierr)
          
          IF (noco%l_noco) THEN
             DO n= 1,atoms%ntype
                IF (noco%l_relax(n)) THEN
                   CALL MPI_BCAST(noco%alph(n),1,MPI_DOUBLE_PRECISION,0,mpi%mpi_comm,ierr)
                   CALL MPI_BCAST(noco%beta(n),1,MPI_DOUBLE_PRECISION,0,mpi%mpi_comm,ierr)
402
                ENDIF
403 404 405
             ENDDO
             IF (noco%l_constr) THEN
                CALL MPI_BCAST(noco%b_con,SIZE(noco%b_con),MPI_DOUBLE_PRECISION,0,mpi%mpi_comm,ierr)
406
             ENDIF
407
          ENDIF
408
#endif
409
          CALL timestop("generation of new charge density (total)")
410 411
          IF (mpi%irank.EQ.0) THEN
             !-t3e
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
             
!!$             !----> output potential and potential difference
!!$             IF (obsolete%disp) THEN
!!$                reap = .FALSE.
!!$                input%total = .FALSE.
!!$                CALL timestart("generation of potential (total)")
!!$                CALL vgen(hybrid,reap,input,xcpot,DIMENSION, atoms,sphhar,stars,vacuum,sym,&
!!$                     obsolete,cell,oneD,sliceplot,mpi, results,noco,outDen,inDenRot,vTot,vx,vCoul)
!!$                CALL timestop("generation of potential (total)")
!!$
!!$                CALL potdis(stars,vacuum,atoms,sphhar, input,cell,sym)
!!$             END IF
             
             !----> total energy
             CALL timestart('determination of total energy')
             CALL totale(atoms,sphhar,stars,vacuum,DIMENSION,&
                  sym,input,noco,cell,oneD,xcpot,hybrid,vTot,vCoul,it,inDen,results)
429

430 431 432 433 434 435 436 437
             CALL timestop('determination of total energy')
          ENDIF ! mpi%irank.EQ.0
          IF ( hybrid%l_hybrid ) CALL close_eig(eig_id)

       END DO forcetheoloop

       CALL forcetheo%postprocess()
       
438
       CALL enpara%mix(mpi,atoms,vacuum,input,vTot%mt(:,0,:,:),vtot%vacz)
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
       IF (mpi%irank.EQ.0) THEN
          !          ----> mix input and output densities
          CALL timestart("mixing")
          CALL mix(stars,atoms,sphhar,vacuum,input,sym,cell,noco,oneD,hybrid,archiveType,inDen,outDen,results)
          CALL timestop("mixing")
          
          WRITE (6,FMT=8130) it
          WRITE (16,FMT=8130) it
8130      FORMAT (/,5x,'******* it=',i3,'  is completed********',/,/)
          WRITE(*,*) "Iteration:",it," Distance:",results%last_distance
          CALL timestop("Iteration")
          !+t3e
       ENDIF ! mpi%irank.EQ.0
       
          
454
#ifdef CPP_MPI
455 456
       CALL MPI_BCAST(results%last_distance,1,MPI_DOUBLE_PRECISION,0,mpi%mpi_comm,ierr)
       CALL MPI_BARRIER(mpi%mpi_comm,ierr)
457
#endif
458 459
       CALL priv_geo_end(mpi)

460 461 462 463 464 465 466 467
!!$       IF ( hybrid%l_calhf ) ithf = ithf + 1
!!$    IF ( hybrid%l_subvxc ) THEN
!!$       l_cont = ( ithf < input%itmax )
!!$       results%te_hfex%core    = 0
!!$       results%te_hfex%valence = 0
!!$    ELSE
       l_cont = ( it < input%itmax )
!!$    END IF
468 469 470 471 472 473 474 475 476
       CALL writeTimesXML()
       CALL check_time_for_next_iteration(it,l_cont)

       l_cont = l_cont.AND.((input%mindistance<=results%last_distance).OR.input%l_f)

       IF ((mpi%irank.EQ.0).AND.(isCurrentXMLElement("iteration"))) THEN
          CALL closeXMLElement('iteration')
       END IF

477
    END DO scfloop ! DO WHILE (l_cont)
478 479 480

    IF (mpi%irank.EQ.0) CALL closeXMLElement('scfLoop')
    CALL juDFT_end("all done",mpi%irank)
481
    
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
  CONTAINS
    SUBROUTINE priv_geo_end(mpi)
      TYPE(t_mpi),INTENT(IN)::mpi
      LOGICAL :: l_exist
      !Check if a new input was generated
      INQUIRE (file='inp_new',exist=l_exist)
      IF (l_exist) THEN
         CALL juDFT_end(" GEO new inp created ! ",mpi%irank)
      END IF
      !check for inp.xml
      INQUIRE (file='inp_new.xml',exist=l_exist)
      IF (.NOT.l_exist) RETURN
      IF (mpi%irank==0) THEN
         CALL system('mv inp.xml inp_old.xml')
         CALL system('mv inp_new.xml inp.xml')
         INQUIRE (file='qfix',exist=l_exist)
         IF (l_exist) THEN
            OPEN(2,file='qfix')
            WRITE(2,*)"F"
            CLOSE(2)
            PRINT *,"qfix set to F"
         ENDIF
504
         CALL resetBroydenHistory()
505 506 507
      ENDIF
      CALL juDFT_end(" GEO new inp.xml created ! ",mpi%irank)
    END SUBROUTINE priv_geo_end
508
    
509 510
  END SUBROUTINE fleur_execute
END MODULE m_fleur