w_inpXML.f90 27.2 KB
Newer Older
1 2 3 4 5 6
!--------------------------------------------------------------------------------
! Copyright (c) 2016 Peter Grünberg Institut, Forschungszentrum Jülich, Germany
! This file is part of FLEUR and available as free software under the conditions
! of the MIT license as expressed in the LICENSE file in more detail.
!--------------------------------------------------------------------------------

7 8 9 10 11 12 13 14 15 16
MODULE m_winpXML

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!
!!!   XML input file generator
!!!
!!!   This subroutine is supposed to write out a file inp.xml
!!!   containing all required input data.
!!!                                         GM'16
!!!
17 18
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
CONTAINS
Matthias Redies's avatar
Matthias Redies committed
19 20
   SUBROUTINE w_inpXML( &
      atoms, vacuum, input, stars, sliceplot, forcetheo, banddos, &
21
      cell, sym, xcpot, noco, oneD, mpinp, hybinp, kpts, enpara, gfinp, &
Matthias Redies's avatar
Matthias Redies committed
22 23 24 25 26 27 28 29 30
      l_explicitIn, l_includeIn, filename)

      use m_types_input
      use m_types_sym
      use m_types_stars
      use m_types_atoms
      use m_types_vacuum
      use m_types_kpts
      use m_types_oneD
Matthias Redies's avatar
Matthias Redies committed
31
      use m_types_mpinp
Matthias Redies's avatar
Matthias Redies committed
32
      use m_types_hybinp
33
      use m_types_gfinp
Matthias Redies's avatar
Matthias Redies committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47
      use m_types_cell
      use m_types_banddos
      use m_types_sliceplot
      USE m_types_xcpot
      USE m_types_xcpot_inbuild_nofunction
      USE m_types_noco
      use m_types_enparaxml
      USE m_types_forcetheo

      USE m_juDFT
      USE m_constants
      USE m_xmlOutput

      IMPLICIT NONE
48 49 50

! arguments

Matthias Redies's avatar
Matthias Redies committed
51 52 53 54 55 56 57
      TYPE(t_input), INTENT(IN)   :: input
      TYPE(t_sym), INTENT(IN)     :: sym
      TYPE(t_stars), INTENT(IN)   :: stars
      TYPE(t_atoms), INTENT(IN)   :: atoms
      TYPE(t_vacuum), INTENT(IN)   :: vacuum
      TYPE(t_kpts), INTENT(IN)     :: kpts
      TYPE(t_oneD), INTENT(IN)     :: oneD
Matthias Redies's avatar
Matthias Redies committed
58 59

      TYPE(t_mpinp), INTENT(IN)    :: mpinp
Matthias Redies's avatar
Matthias Redies committed
60
      TYPE(t_hybinp), INTENT(IN)   :: hybinp
Matthias Redies's avatar
Matthias Redies committed
61 62 63 64 65
      TYPE(t_cell), INTENT(IN)     :: cell
      TYPE(t_banddos), INTENT(IN)  :: banddos
      TYPE(t_sliceplot), INTENT(IN):: sliceplot
      CLASS(t_xcpot), INTENT(IN)   :: xcpot
      TYPE(t_noco), INTENT(IN)     :: noco
66
      TYPE(t_gfinp), INTENT(IN)    :: gfinp
Matthias Redies's avatar
Matthias Redies committed
67 68 69 70 71 72 73 74 75 76 77
      CLASS(t_enparaxml), INTENT(IN)   :: enpara
      CLASS(t_forcetheo), INTENT(IN):: forcetheo !nothing is done here so far....
      LOGICAL, INTENT(IN)        :: l_explicitIn, l_includeIn(4)
      CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: filename

      INTEGER          :: iSpecies, fileNum
      CHARACTER(len=8) :: name(10)
      INTEGER          :: numSpecies
      INTEGER          :: speciesRepAtomType(atoms%ntype)
      CHARACTER(len=20):: speciesNames(atoms%ntype)
      LOGICAL          :: known_species
78

79
!+lda+u
Matthias Redies's avatar
Matthias Redies committed
80 81 82 83 84 85
      REAL u, j
      INTEGER l, i_u
      INTEGER uIndices(2, atoms%ntype)
      LOGICAL l_amf
      CHARACTER(len=3) ch_test
      NAMELIST /ldaU/ l, u, j, l_amf
86 87
!-lda+u
!+odim
Matthias Redies's avatar
Matthias Redies committed
88 89 90 91 92
      INTEGER MM, vM, m_cyl
      LOGICAL invs1, zrfs1
      INTEGER chi, rot
      LOGICAL d1, band
      NAMELIST /odim/ d1, MM, vM, m_cyl, chi, rot, invs1, zrfs1
93 94 95
!-odim
! ..
! ..  Local Variables
Matthias Redies's avatar
Matthias Redies committed
96 97
      REAL     :: zc, sumWeight, occ(2)
      INTEGER  ::nw, idsprs, n1, n2
98
      INTEGER ieq, i, k, na, n, ilo,iContour
Matthias Redies's avatar
Matthias Redies committed
99 100 101
      REAL s3, ah, a, hs2, rest
      LOGICAL l_hyb, ldum
      INTEGER :: ierr
102 103
! ..
!...  Local Arrays
Matthias Redies's avatar
Matthias Redies committed
104 105 106 107
      CHARACTER :: helpchar(atoms%ntype)
      CHARACTER(len=4) :: chntype
      CHARACTER(len=41) :: chform
      CHARACTER(len=100) :: line
108

Matthias Redies's avatar
Matthias Redies committed
109
!     added for HF and hybinp functionals
Matthias Redies's avatar
Matthias Redies committed
110 111 112 113 114 115 116 117 118
      REAL                  ::  aMix, omega
      INTEGER               :: idum
      CHARACTER(len=1)     ::  check

      CHARACTER(len=20) :: speciesName
      CHARACTER(len=150) :: format
      CHARACTER(len=20) :: mixingScheme
      CHARACTER(len=10) :: loType
      CHARACTER(len=10) :: bzIntMode
119
      LOGICAL ::   l_explicit, l_nocoOpt, l_gfOpt, l_include(4)
Matthias Redies's avatar
Matthias Redies committed
120 121 122 123 124 125 126 127 128
      INTEGER :: iAtomType, startCoreStates, endCoreStates
      CHARACTER(len=100) :: posString(3)
      CHARACTER(len=7) :: str
      REAL :: tempTaual(3, atoms%nat), scpos(3)
      REAL :: amatTemp(3, 3), bmatTemp(3, 3)

      l_include = l_includeIn .or. .not. present(filename)
      l_explicit = l_explicitIn .OR. .not. present(filename)
      l_nocoOpt = noco%l_noco .OR. juDFT_was_argument("-noco")
129
      l_gfOpt = gfinp%n>0 .OR. juDFT_was_argument("-greensf")
Matthias Redies's avatar
Matthias Redies committed
130 131 132 133 134 135 136 137

      band = .false.
      nw = 1

      IF (PRESENT(filename)) THEN
         filenum = 98
         OPEN (fileNum, file=TRIM(ADJUSTL(filename)), form='formatted', status='replace')
         WRITE (fileNum, '(a)') '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
138
         WRITE (fileNum, '(a)') '<fleurInput fleurInputVersion="0.32">'
Matthias Redies's avatar
Matthias Redies committed
139 140 141 142 143 144 145 146 147 148
      ELSE
         fileNum = getXMLOutputUnitNumber()
         CALL openXMLElementNoAttributes('inputData')
      END IF

      WRITE (fileNum, '(a)') '   <comment>'
      WRITE (fileNum, '(a6,10a8)') '      ', input%comment
      WRITE (fileNum, '(a)') '   </comment>'

      WRITE (fileNum, '(a)') '   <calculationSetup>'
149 150

!      <cutoffs Kmax="3.60000" Gmax="11.000000" GmaxXC="9.200000" numbands="0"/>
Matthias Redies's avatar
Matthias Redies committed
151 152
110   FORMAT('      <cutoffs Kmax="', f0.8, '" Gmax="', f0.8, '" GmaxXC="', f0.8, '" numbands="', i0, '"/>')
      WRITE (fileNum, 110) input%rkmax, input%gmax, xcpot%gmaxxc, input%gw_neigd
153

154
!      <scfLoop itmax="9" maxIterBroyd="99" imix="Anderson" alpha="0.05" precondParam="0.0" spinf="2.00"/>
Matthias Redies's avatar
Matthias Redies committed
155 156
120   FORMAT('      <scfLoop itmax="', i0, '" minDistance="', f0.8, '" maxIterBroyd="', i0, '" imix="', a, '" alpha="', f0.8, '" precondParam="', f3.1, '" spinf="', f0.8, '"/>')
      SELECT CASE (input%imix)
157
      CASE (1)
Matthias Redies's avatar
Matthias Redies committed
158
         mixingScheme = 'straight'
159
      CASE (3)
Matthias Redies's avatar
Matthias Redies committed
160
         mixingScheme = 'Broyden1'
161
      CASE (5)
Matthias Redies's avatar
Matthias Redies committed
162
         mixingScheme = 'Broyden2'
163
      CASE (7)
Matthias Redies's avatar
Matthias Redies committed
164
         mixingScheme = 'Anderson'
165
      CASE DEFAULT
Matthias Redies's avatar
Matthias Redies committed
166 167 168
         mixingScheme = 'errorUnknownMixing'
      END SELECT
      WRITE (fileNum, 120) input%itmax, input%minDistance, input%maxiter, TRIM(mixingScheme), input%alpha, input%preconditioning_param, input%spinf
169 170

!      <coreElectrons ctail="T" frcor="F" kcrel="0"/>
Matthias Redies's avatar
Matthias Redies committed
171 172
130   FORMAT('      <coreElectrons ctail="', l1, '" frcor="', l1, '" kcrel="', i0, '" coretail_lmax="', i0, '"/>')
      WRITE (fileNum, 130) input%ctail, input%frcor, input%kcrel, input%coretail_lmax
173

174 175 176
!      <magnetism jspins="1" l_noco="F" l_J="F" swsp="F" lflip="F", l_onlyMtStDen="F"/>
140   FORMAT('      <magnetism jspins="', i0, '" l_noco="', l1, '" swsp="', l1, '" lflip="', l1, '" l_onlyMtStDen="',l1, '"/>')
      WRITE (fileNum, 140) input%jspins, noco%l_noco, input%swsp, input%lflip, input%l_onlyMtStDen
Matthias Redies's avatar
Matthias Redies committed
177 178 179

      !      <soc theta="0.00000" phi="0.00000" l_soc="F" spav="F" off="F" soc66="F"/>
150   FORMAT('      <soc theta="', f0.8, '" phi="', f0.8, '" l_soc="', l1, '" spav="', l1, '"/>')
180
      WRITE (fileNum, 150) noco%theta_inp, noco%phi_inp, noco%l_soc, noco%l_spav
Matthias Redies's avatar
Matthias Redies committed
181

Matthias Redies's avatar
Matthias Redies committed
182
      IF (l_explicit .OR. hybinp%l_hybrid) THEN
Matthias Redies's avatar
Matthias Redies committed
183
155      FORMAT('      <prodBasis gcutm="', f0.8, '" tolerance="', f0.8, '" ewaldlambda="', i0, '" lexp="', i0, '" bands="', i0, '"/>')
Matthias Redies's avatar
Matthias Redies committed
184
         WRITE (fileNum, 155) mpinp%g_cutoff, mpinp%linear_dep_tol, hybinp%ewaldlambda, hybinp%lexp, hybinp%bands1
Matthias Redies's avatar
Matthias Redies committed
185 186 187
      END IF

      IF (l_nocoOpt .OR. l_explicit) THEN
Robin Hilgers's avatar
Robin Hilgers committed
188
160      FORMAT('      <nocoParams l_ss="', l1, '" l_mperp="', l1,'" l_mtNocoPot="', l1,'" l_RelaxMT="', l1, '" l_constr="', l1, '" l_sourceFree="', l1, &
Robin Hilgers's avatar
Robin Hilgers committed
189
                '" l_scaleMag="', l1, '" mag_scale="', f0.8, '" mix_b="', f0.8,'" l_RelaxAlpha="',l1, '" l_RelaxBeta="',l1,'" mix_RelaxWeightOffD="',f0.8,'">')
Robin Hilgers's avatar
Robin Hilgers committed
190
         WRITE (fileNum, 160) noco%l_ss, noco%l_mperp, noco%l_mtNocoPot, noco%l_alignMT,noco%l_constr, noco%l_sourceFree, noco%l_scaleMag, noco%mag_scale, noco%mix_b, noco%l_RelaxAlpha,noco%l_RelaxBeta,noco%mix_RelaxWeightOffD
Matthias Redies's avatar
Matthias Redies committed
191
162      FORMAT('         <qss>', f0.10, ' ', f0.10, ' ', f0.10, '</qss>')
192
         WRITE (fileNum, 162) noco%qss_inp
Matthias Redies's avatar
Matthias Redies committed
193 194 195 196 197 198 199
         WRITE (fileNum, '(a)') '      </nocoParams>'
      END IF

      IF (oneD%odd%d1) THEN
170      FORMAT('      <oneDParams d1="', l1, '" MM="', i0, '" vM="', i0, '" m_cyl="', i0, '" chi="', i0, '" rot="', i0, '" invs1="', l1, '" zrfs1="', l1, '"/>')
         WRITE (fileNum, 170) oneD%odd%d1, oneD%odd%M, oneD%odd%mb, oneD%odd%m_cyl, oneD%odd%chi, oneD%odd%rot, oneD%odd%invs, oneD%odd%zrfs
      END IF
200

Gregor Michalicek's avatar
Gregor Michalicek committed
201
!      <expertModes gw="0"  eig66="F" lpr="0" secvar="F" />
Matthias Redies's avatar
Matthias Redies committed
202 203
180   FORMAT('      <expertModes gw="', i0, '" secvar="', l1, '"/>')
      WRITE (fileNum, 180) input%gw, input%secvar
204 205

!      <geometryOptimization l_f="F" xa="2.00000" thetad="330.00000" epsdisp="0.00001" epsforce="0.00001"/>
Matthias Redies's avatar
Matthias Redies committed
206 207
190   FORMAT('      <geometryOptimization l_f="', l1, '" forcealpha="', f0.8, '" forcemix="', a, '" epsdisp="', f0.8, '" epsforce="', f0.8, '"/>')
      SELECT CASE (input%forcemix)
208
      CASE (0)
Matthias Redies's avatar
Matthias Redies committed
209
         mixingScheme = 'Straight'
210
      CASE (1)
Matthias Redies's avatar
Matthias Redies committed
211
         mixingScheme = 'CG'
212
      CASE (2)
Matthias Redies's avatar
Matthias Redies committed
213
         mixingScheme = 'BFGS'
214
      CASE DEFAULT
Matthias Redies's avatar
Matthias Redies committed
215 216 217
         mixingScheme = 'errorUnknownMixing'
      END SELECT
      WRITE (fileNum, 190) input%l_f, input%forcealpha, TRIM(mixingScheme), input%epsdisp, input%epsforce
218

219 220
      SELECT CASE (input%bz_integration)
      CASE (0)
221
         bzIntMode = 'hist'
222
      CASE (1)
Matthias Redies's avatar
Matthias Redies committed
223
         bzIntMode = 'gauss'
224
      CASE (2)
Matthias Redies's avatar
Matthias Redies committed
225
         bzIntMode = 'tria'
226
      CASE (3)
227
         bzIntMode = 'tetra'
228
      CASE DEFAULT
229
         CALL judft_error("Invalid brillouin zone integration mode",calledby="w_inpXML")
230
      END SELECT
231 232

!      <ldaU l_linMix="F" mixParam="0.05" spinf="1.0" />
Matthias Redies's avatar
Matthias Redies committed
233 234
195   FORMAT('      <ldaU l_linMix="', l1, '" mixParam="', f0.6, '" spinf="', f0.6, '"/>')
      WRITE (fileNum, 195) input%ldauLinMix, input%ldauMixParam, input%ldauSpinf
235

236
      IF(l_gfOpt) THEN
237 238
205      FORMAT('      <greensFunction l_mperp="', l1'">')
         WRITE(fileNum, 205) gfinp%l_mperp
Henning Janssen's avatar
Henning Janssen committed
239
206      FORMAT('         <realAxis ne="', i0, '" ellow="', f0.8, '" elup="', f0.8, '"/>')
240
         WRITE(fileNum, 206) gfinp%ne, gfinp%ellow, gfinp%elup
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
         IF(gfinp%numberContours>0) THEN
            DO iContour = 1, gfinp%numberContours
               SELECT CASE(gfinp%contour(iContour)%shape)
               CASE(CONTOUR_RECTANGLE_CONST)
207               FORMAT('         <contourRectangle n1="', i0, '" n2="', i0, '" n3="', i0, '" nmatsub="', i0,&
                         '" sigma="', f0.8, '" eb="', f0.8, '" label="', a,'"/>')
                  WRITE(fileNum, 207) gfinp%contour(iContour)%n1, gfinp%contour(iContour)%n2, gfinp%contour(iContour)%n3,&
                                      gfinp%contour(iContour)%nmatsub, gfinp%contour(iContour)%sigma, gfinp%contour(iContour)%eb,&
                                      gfinp%contour(iContour)%label
               CASE(CONTOUR_SEMICIRCLE_CONST)
208               FORMAT('         <contourSemicircle n="', i0, '" eb="', f0.8, '" et="', f0.8, '" alpha="', f0.8, '" label="', a,'"/>')
                  WRITE(fileNum, 208) gfinp%contour(iContour)%ncirc, gfinp%contour(iContour)%eb, gfinp%contour(iContour)%et,&
                                      gfinp%contour(iContour)%alpha,gfinp%contour(iContour)%label
               CASE(CONTOUR_DOS_CONST)
209               FORMAT('         <contourDOS n="', i0, '" sigma="', f0.8, '" eb="', f0.8, '" et="', f0.8, &
                         '" analytical_cont="', l1, '" l_fermi="', l1, '" label="', a,'"/>')
                  WRITE(fileNum, 209) gfinp%contour(iContour)%nDOS, gfinp%contour(iContour)%sigmaDOS, gfinp%contour(iContour)%eb,&
                                      gfinp%contour(iContour)%et, gfinp%contour(iContour)%l_anacont, gfinp%contour(iContour)%l_dosfermi,&
                                      gfinp%contour(iContour)%label
               CASE DEFAULT
                  CALL judft_error("Unknown green's function contour mode", calledby="w_inpXML")
               END SELECT
            ENDDO
         ELSE
Henning Janssen's avatar
Henning Janssen committed
265
            !Write out a default contour (Semicircle)
Henning Janssen's avatar
Henning Janssen committed
266
            WRITE(fileNum, 208) 128, -1.0, 0.0,1.0,"default"
267
         ENDIF
268 269 270 271
         WRITE(fileNum, '(a)') '      </greensFunction>'
      ENDIF


272
!      <bzIntegration valenceElectrons="8.00000" mode="hist" fermiSmearingEnergy="0.00100">
Matthias Redies's avatar
Matthias Redies committed
273 274 275 276 277 278 279 280 281 282
200   FORMAT('      <bzIntegration valenceElectrons="', f0.8, '" mode="', a, '" fermiSmearingEnergy="', f0.8, '">')
      WRITE (fileNum, 200) input%zelec, TRIM(ADJUSTL(bzIntMode)), input%tkb

      if (l_include(1)) THEN
         call kpts%print_xml(fileNum)
      else
         WRITE (fileNum, '(a)') '         <!-- k-points included here -->'
         WRITE (fileNum, '(a)') '         <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="kpts.xml"> </xi:include>'
      end if
      WRITE (fileNum, '(a)') '      </bzIntegration>'
283 284

!      <energyParameterLimits ellow="-2.00000" elup="2.00000"/>
Matthias Redies's avatar
Matthias Redies committed
285 286 287 288 289 290 291 292 293 294
220   FORMAT('      <energyParameterLimits ellow="', f0.8, '" elup="', f0.8, '"/>')
      WRITE (fileNum, 220) input%ellow, input%elup
      if (l_include(2)) THEN
         call sym%print_xml(fileNum)
      else
         WRITE (fileNum, '(a)') '      <!-- symmetry operations included here -->'
         WRITE (fileNum, '(a)') '      <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="sym.xml"> </xi:include>'
      end if
      WRITE (fileNum, '(a)') '   </calculationSetup>'
      WRITE (fileNum, '(a)') '   <cell>'
295 296 297
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! Note: Different options for the cell definition!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Matthias Redies's avatar
Matthias Redies committed
298
      IF (input%film) THEN
299 300 301
!      <xsd:attribute name="dVac" type="xsd:double" use="required"/>
!      <xsd:attribute name="dTilda" type="xsd:double" use="required"/>
!      <filmLattice ...>
Matthias Redies's avatar
Matthias Redies committed
302 303 304 305 306 307 308 309 310
241      FORMAT('      <filmLattice scale="', f0.8, '" dVac="', f0.8, '" dTilda="', f0.8, '">')
         WRITE (fileNum, 241) 1.0, vacuum%dvac, cell%amat(3, 3)
      ELSE
242      FORMAT('      <bulkLattice scale="', f0.10, '">')
         WRITE (fileNum, 242) 1.0
      ENDIF
      !         <bravaisMatrix>
      WRITE (fileNum, '(a)') '         <bravaisMatrix>'
      !            <row-1>0.00000 5.13000 5.13000</row-1>
Matthias Redies's avatar
Matthias Redies committed
311
250   FORMAT('            <row-1>', f16.10, ' ', f16.10, ' ', f16.10, '</row-1>')
Matthias Redies's avatar
Matthias Redies committed
312 313
      WRITE (fileNum, 250) cell%amat(:, 1)
      !            <row-2>5.13000 0.00000 5.13000</row-2>
Matthias Redies's avatar
Matthias Redies committed
314
260   FORMAT('            <row-2>', f16.10, ' ', f16.10, ' ', f16.10, '</row-2>')
Matthias Redies's avatar
Matthias Redies committed
315 316
      WRITE (fileNum, 260) cell%amat(:, 2)
      !            <row-3>5.13000 5.13000 0.00000</row-3>
Matthias Redies's avatar
Matthias Redies committed
317
270   FORMAT('            <row-3>', f16.10, ' ', f16.10, ' ', f16.10, '</row-3>')
Matthias Redies's avatar
Matthias Redies committed
318 319 320 321 322 323 324 325
      WRITE (fileNum, 270) cell%amat(:, 3)
      WRITE (fileNum, '(a)') '         </bravaisMatrix>'

      IF (input%film) THEN
268      FORMAT('         <vacuumEnergyParameters vacuum="', i0, '" spinUp="', f0.8, '" spinDown="', f0.8, '"/>')
         DO i = 1, vacuum%nvac
            WRITE (fileNum, 268) i, enpara%evac0(i, 1), enpara%evac0(i, input%jspins)
         END DO
326

Matthias Redies's avatar
Matthias Redies committed
327 328 329
         WRITE (fileNum, '(a)') '      </filmLattice>'
      ELSE
         WRITE (fileNum, '(a)') '      </bulkLattice>'
330
      END IF
Matthias Redies's avatar
Matthias Redies committed
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
      WRITE (fileNum, '(a)') '   </cell>'

      SELECT TYPE (xcpot)
      CLASS IS (t_xcpot_inbuild_nf)
         !   <xcFunctional name="pbe" relativisticCorrections="F">
280      FORMAT('   <xcFunctional name="', a, '" relativisticCorrections="', l1, '"/>')
         WRITE (fileNum, 280) trim(xcpot%get_name()), xcpot%relativistic_correction()
      END SELECT

      uIndices = -1
      DO i_u = 1, atoms%n_u
         IF (uIndices(1, atoms%lda_u(i_u)%atomType) .EQ. -1) uIndices(1, atoms%lda_u(i_u)%atomType) = i_u
         uIndices(2, atoms%lda_u(i_u)%atomType) = i_u
      END DO

      !Build list of species
      speciesNames = ''
      numSpecies = 0
      DO n = 1, atoms%ntype
350
         known_species = ANY(trim(atoms%speciesname(n)) == speciesNames(:numSpecies))
Matthias Redies's avatar
Matthias Redies committed
351 352
         if (.not. known_species) THEN
            numSpecies = numSpecies + 1
353
            speciesNames(numSpecies) = trim(atoms%speciesname(n))
Matthias Redies's avatar
Matthias Redies committed
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
            speciesRepAtomType(numSpecies) = n
         end if
      enddo

      if (.not. l_include(3)) then
         open (99, file='species.xml')
         WRITE (fileNum, '(a)') '      <!-- species included here -->'
         WRITE (fileNum, '(a)') '      <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="species.xml"> </xi:include>'
         fileNum = 99
      endif

      WRITE (fileNum, '(a)') '   <atomSpecies>'
      DO iSpecies = 1, numSpecies
         iAtomType = speciesRepAtomType(iSpecies)
         IF (iAtomType .EQ. -1) THEN
            EXIT
         END IF
371
!      <species name="Si-1" element="Si" atomicNumber="14" coreStates="4" magMom="0.0" flipSpin="F">
Matthias Redies's avatar
Matthias Redies committed
372
300      FORMAT('      <species name="', a, '" element="', a, '" atomicNumber="', i0, '" flipSpinPhi="', f0.8, '" flipSpinTheta="', f0.8, '" flipSpinScale="', l1, '">')
373
         speciesName = TRIM(ADJUSTL(speciesNames(iSpecies)))
Matthias Redies's avatar
Matthias Redies committed
374
         WRITE (fileNum, 300) TRIM(ADJUSTL(speciesName)), TRIM(ADJUSTL(namat_const(atoms%nz(iAtomType)))), atoms%nz(iAtomType), atoms%flipSpinPhi(iAtomType), atoms%flipSpinTheta(iAtomType), atoms%flipSpinScale(iAtomType)
375 376

!         <mtSphere radius="2.160000" gridPoints="521" logIncrement="0.022000"/>
Matthias Redies's avatar
Matthias Redies committed
377 378
310      FORMAT('         <mtSphere radius="', f0.8, '" gridPoints="', i0, '" logIncrement="', f0.8, '"/>')
         WRITE (fileNum, 310) atoms%rmt(iAtomType), atoms%jri(iAtomType), atoms%dx(iAtomType)
379 380

!         <atomicCutoffs lmax="8" lnonsphr="6"/>
Matthias Redies's avatar
Matthias Redies committed
381 382
320      FORMAT('         <atomicCutoffs lmax="', i0, '" lnonsphr="', i0, '"/>')
         WRITE (fileNum, 320) atoms%lmax(iAtomType), atoms%lnonsph(iAtomType)
383

Matthias Redies's avatar
Matthias Redies committed
384
         WRITE (fileNum, '(a)') '         <electronConfig>'
385
!         <coreConfig>[He] (2s1/2) (2p1/2) (2p3/2)</coreConfig>
Matthias Redies's avatar
Matthias Redies committed
386 387 388 389 390
322      FORMAT('            <coreConfig>', a, '</coreConfig>')
         WRITE (fileNum, 322) TRIM(ADJUSTL(atoms%econf(iAtomType)%coreconfig))
323      FORMAT('            <valenceConfig>', a, '</valenceConfig>')
         IF (len_TRIM(atoms%econf(iAtomType)%valenceconfig) > 1) THEN
            WRITE (fileNum, 323) TRIM(ADJUSTL(atoms%econf(iAtomType)%valenceconfig))
391
         END IF
Matthias Redies's avatar
Matthias Redies committed
392 393 394
         DO i = 1, MERGE(atoms%econf(iAtomType)%num_states, atoms%econf(iAtomType)%num_core_states, (len_TRIM(atoms%econf(iAtomType)%valenceconfig) > 1))
            occ = atoms%econf(iAtomType)%occupation(i, :)
            IF (ABS(occ(1) - occ(2)) > 1E-5 .OR. ABS(occ(1) - ABS(atoms%econf(iAtomType)%kappa(i))) > 1E-5) THEN
395
               !State not fully occupied
Matthias Redies's avatar
Matthias Redies committed
396 397 398
325            FORMAT('            <stateOccupation state="', a, '" spinUp="', f0.8, '" spinDown="', f0.8, '"/>')
               str = atoms%econf(iAtomType)%get_state_string(i)
               WRITE (fileNum, 325) str, occ(1), occ(2)
399 400
            END IF
         END DO
Matthias Redies's avatar
Matthias Redies committed
401
         WRITE (fileNum, '(a)') '         </electronConfig>'
402

Matthias Redies's avatar
Matthias Redies committed
403
         !IF (ALL(enpara%qn_el(0:3,iAtomType,1).ne.0)) THEN
404
!!         <energyParameters s="3" p="3" d="3" f="4"/>
Matthias Redies's avatar
Matthias Redies committed
405 406 407
321      FORMAT('         <energyParameters s="', i0, '" p="', i0, '" d="', i0, '" f="', i0, '"/>')
         WRITE (fileNum, 321) enpara%qn_el(0:3, iAtomType, 1)
         !END IF
Matthias Redies's avatar
Matthias Redies committed
408
         IF (l_explicit .OR. hybinp%l_hybrid) THEN
Matthias Redies's avatar
Matthias Redies committed
409 410
315         FORMAT('         <prodBasis lcutm="', i0, '" lcutwf="', i0, '" select="', a, '"/>')
            line = ''
Matthias Redies's avatar
Matthias Redies committed
411 412
            WRITE (line, '(i0,1x,i0,1x,i0,1x,i0)') hybinp%select1(1:4, iAtomType)
            WRITE (fileNum, 315) hybinp%lcutm1(iAtomType), hybinp%lcutwf(iAtomType), TRIM(ADJUSTL(line))
Matthias Redies's avatar
Matthias Redies committed
413
         END IF
414

Matthias Redies's avatar
Matthias Redies committed
415
         IF (uIndices(1, iAtomType) .NE. -1) THEN
Daniel Wortmann's avatar
Daniel Wortmann committed
416
!         <ldaU l="2" U="5.5" J="0.9" l_amf="F"/>
Matthias Redies's avatar
Matthias Redies committed
417 418 419 420 421
            DO i_u = uIndices(1, iAtomType), uIndices(2, iAtomType)
326            FORMAT('         <ldaU l="', i0, '" U="', f0.5, '" J="', f0.5, '" l_amf="', l1, '"/>')
               WRITE (fileNum, 326) atoms%lda_u(i_u)%l, atoms%lda_u(i_u)%u, atoms%lda_u(i_u)%j, atoms%lda_u(i_u)%l_amf
            END DO
         END IF
Daniel Wortmann's avatar
Daniel Wortmann committed
422

Matthias Redies's avatar
Matthias Redies committed
423
         DO ilo = 1, atoms%nlo(iAtomType)
424
!         <lo type="HELO" l="0" n="4"/>
Matthias Redies's avatar
Matthias Redies committed
425 426 427 428 429 430 431 432 433 434
            l = atoms%llo(ilo, iAtomType)
            n = enpara%qn_ello(ilo, iAtomType, 1)
            loType = 'SCLO'
            IF (n .LT. 0) THEN
               loType = 'HELO'
            END IF
            n = ABS(n)
324         FORMAT('         <lo type="', a, '" l="', i0, '" n="', i0, '" eDeriv="', i0, '"/>')
            WRITE (fileNum, 324) TRIM(ADJUSTL(loType)), l, n, atoms%ulo_der(ilo, iAtomType)
         END DO
435

Matthias Redies's avatar
Matthias Redies committed
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
         WRITE (fileNum, '(a)') '      </species>'
      END DO
      WRITE (fileNum, '(a)') '   </atomSpecies>'

      if (.not. l_include(3)) then
         close (99)
         fileNum = 98
      endif

      if (.not. l_include(4)) then
         open (99, file='atoms.xml')
         WRITE (fileNum, '(a)') '      <!-- atoms group included here -->'
         WRITE (fileNum, '(a)') '      <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="atoms.xml"> </xi:include>'
         fileNum = 98
      endif

      WRITE (fileNum, '(a)') '   <atomGroups>'
      na = 0
      DO iAtomType = 1, atoms%ntype
455
!      <atomGroup species="Si-1">
Matthias Redies's avatar
Matthias Redies committed
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
330      FORMAT('      <atomGroup species="', a, '">')
         speciesName = TRIM(ADJUSTL(atoms%speciesName(iAtomType)))
         WRITE (fileNum, 330) TRIM(ADJUSTL(speciesName))

         DO ieq = 1, atoms%neq(iAtomType)
            na = na + 1
            tempTaual(1, na) = atoms%taual(1, na)
            tempTaual(2, na) = atoms%taual(2, na)
            tempTaual(3, na) = atoms%taual(3, na)
            scpos = 1.0
            DO i = 2, 40
               rest = ABS(i*tempTaual(1, na) - NINT(i*tempTaual(1, na)))
               IF ((scpos(1) .EQ. 1.0) .AND. (rest .LT. (i*0.000001))) scpos(1) = real(i)
               rest = ABS(i*tempTaual(2, na) - NINT(i*tempTaual(2, na)))
               IF ((scpos(2) .EQ. 1.0) .AND. (rest .LT. (i*0.000001))) scpos(2) = real(i)
               IF (.not. input%film) THEN
                  rest = ABS(i*tempTaual(3, na) - NINT(i*tempTaual(3, na)))
                  IF ((scpos(3) .EQ. 1.0) .AND. (rest .LT. (i*0.000001))) scpos(3) = real(i)
               END IF
            END DO
            DO i = 1, 2
               tempTaual(i, na) = tempTaual(i, na)*scpos(i)
            END DO
            IF (.not. input%film) tempTaual(3, na) = tempTaual(3, na)*scpos(3)
            IF (input%film) THEN
               tempTaual(3, na) = cell%amat(3, 3)*tempTaual(3, na)
482 483
            END IF
!+odim in 1D case all the coordinates are given in cartesian YM
Matthias Redies's avatar
Matthias Redies committed
484 485 486 487
            IF (oneD%odd%d1) THEN
               !tempTaual(1,na) = tempTaual(1,na)*a1(1)
               !tempTaual(2,na) = tempTaual(2,na)*a2(2)
            END IF
488
!-odim
Matthias Redies's avatar
Matthias Redies committed
489 490 491
            IF (oneD%odd%d1) THEN
               call judft_error('1D position output not implemented!')
            ELSE IF (input%film) THEN
492
!         <filmPos> x/myConstant  y/myConstant  1/myConstant</filmPos>
Matthias Redies's avatar
Matthias Redies committed
493 494 495 496 497 498 499 500 501 502 503 504 505
340            FORMAT('         <filmPos label="', a20, '">', a, ' ', a, ' ', a, '</filmPos>')
               posString(:) = ''
               DO i = 1, 2
                  IF ((scpos(i) .NE. 1.0) .AND. (tempTaual(i, na) .NE. 0.0)) THEN
                     WRITE (posString(i), '(f0.3,a1,f0.3)') tempTaual(i, na), '/', scpos(i)
                  ELSE
                     WRITE (posString(i), '(f0.10)') tempTaual(i, na)
                  END IF
               END DO
               WRITE (posString(3), '(f0.10)') tempTaual(3, na)
               WRITE (fileNum, 340) TRIM(ADJUSTL(atoms%label(na))), &
                  TRIM(ADJUSTL(posString(1))), TRIM(ADJUSTL(posString(2))), TRIM(ADJUSTL(posString(3)))
            ELSE
506
!         <relPos> x/myConstant  y/myConstant  z/myConstant</relPos>
Matthias Redies's avatar
Matthias Redies committed
507 508 509 510 511 512 513 514 515 516 517 518 519
350            FORMAT('         <relPos label="', a20, '">', a, ' ', a, ' ', a, '</relPos>')
               posString(:) = ''
               DO i = 1, 3
                  IF ((scpos(i) .NE. 1.0) .AND. (tempTaual(i, na) .NE. 0.0)) THEN
                     WRITE (posString(i), '(f0.3,a1,f0.3)') tempTaual(i, na), '/', scpos(i)
                  ELSE
                     WRITE (posString(i), '(f0.10)') tempTaual(i, na)
                  END IF
               END DO
               WRITE (fileNum, 350) TRIM(ADJUSTL(atoms%label(na))), &
                  TRIM(ADJUSTL(posString(1))), TRIM(ADJUSTL(posString(2))), TRIM(ADJUSTL(posString(3)))
            END IF
         END DO
520
!         <force calculate="F" relaxX="T" relaxY="T" relaxZ="T"/>
Matthias Redies's avatar
Matthias Redies committed
521 522 523 524 525
360      FORMAT('         <force calculate="', l1, '" relaxXYZ="', 3l1, '"/>')
         WRITE (fileNum, 360) atoms%l_geo(iAtomType), atoms%relax(1, iAtomType), atoms%relax(2, iAtomType), atoms%relax(3, iAtomType)

         IF (l_nocoOpt .OR. l_explicit) THEN
362         FORMAT('         <nocoParams l_relax="', l1, '" alpha="', f0.8, '" beta="', &
526 527 528
                   f0.8,  '"/>')
            WRITE (fileNum, 362) noco%l_relax(iAtomType), noco%alph_inp(iAtomType), &
               noco%beta_inp(iAtomType)
Matthias Redies's avatar
Matthias Redies committed
529
         END IF
530

Matthias Redies's avatar
Matthias Redies committed
531 532 533 534 535 536 537
         WRITE (fileNum, '(a)') '      </atomGroup>'
      END DO
      WRITE (fileNum, '(a)') '   </atomGroups>'
      if (.not. l_include(4)) then
         close (99)
         fileNum = 98
      endif
538

539 540
368   FORMAT('   <output dos="', l1, '" band="', l1,  '" slice="', l1, '">')
      WRITE (fileNum, 368) banddos%dos, band, sliceplot%slice
541 542

!      <checks vchk="F" cdinf="F" disp="F"/>
Matthias Redies's avatar
Matthias Redies committed
543 544
370   FORMAT('      <checks vchk="', l1, '" cdinf="', l1, '"/>')
      WRITE (fileNum, 370) input%vchk, input%cdinf
545

546
!      <densityOfStates ndir="0" minEnergy="-0.50000" maxEnergy="0.50000" sigma="0.01500"/>
547
380   FORMAT('      <bandDOS minEnergy="', f0.8, '" maxEnergy="', f0.8, '" sigma="', f0.8, '"/>')
548
      WRITE (fileNum, 380)  banddos%e2_dos, banddos%e1_dos, banddos%sig_dos
549 550

!      <vacuumDOS layers="0" integ="F" star="F" nstars="0" locx1="0.00" locy1="0.00" locx2="0.00" locy2="0.00" nstm="0" tworkf="0.000000"/>
551 552
390   FORMAT('      <vacuumDOS vacdos="', l1, '" integ="', l1, '" star="', l1, '" nstars="', i0, '" locx1="', f0.5, '" locy1="', f0.5, '" locx2="', f0.5, '" locy2="', f0.5, '" nstm="', i0, '" tworkf="', f0.5, '"/>')
      WRITE (fileNum, 390) banddos%vacdos, input%integ, banddos%starcoeff, banddos%nstars, banddos%locx(1), banddos%locy(1), banddos%locx(2), banddos%locy(2), 0, 0.0
553

554
!      <unfoldingBand unfoldBand="F" supercellX="1" supercellY="1" supercellZ="1"/>
Matthias Redies's avatar
Matthias Redies committed
555 556
395   FORMAT('      <unfoldingBand unfoldBand="', l1, '" supercellX="', i0, '" supercellY="', i0, '" supercellZ="', i0, '"/>')
      WRITE (fileNum, 395) banddos%unfoldband, banddos%s_cell_x, banddos%s_cell_y, banddos%s_cell_z
557

558
!      <plotting iplot="0" />
Matthias Redies's avatar
Matthias Redies committed
559 560
400   FORMAT('      <plotting iplot="', i0, '"/>')
      WRITE (fileNum, 400) sliceplot%iplot
561 562

!      <chargeDensitySlicing numkpt="0" minEigenval="0.000000" maxEigenval="0.000000" nnne="0" pallst="F"/>
Matthias Redies's avatar
Matthias Redies committed
563 564
410   FORMAT('      <chargeDensitySlicing numkpt="', i0, '" minEigenval="', f0.8, '" maxEigenval="', f0.8, '" nnne="', i0, '" pallst="', l1, '"/>')
      WRITE (fileNum, 410) sliceplot%kk, sliceplot%e1s, sliceplot%e2s, sliceplot%nnne, input%pallst
565 566

!      <specialOutput form66="F" eonly="F" bmt="F"/>
Matthias Redies's avatar
Matthias Redies committed
567 568
420   FORMAT('      <specialOutput eonly="', l1, '" bmt="', l1, '"/>')
      WRITE (fileNum, 420) input%eonly, input%l_bmt
569

570
!      <magneticCircularDichroism energyLo="-10.0" energyUp="0.0"/>
571
430   FORMAT('      <magneticCircularDichroism mcd="',l1,'" energyLo="', f0.8, '" energyUp="', f0.8, '"/>')
572
      WRITE (fileNum, 430) banddos%l_mcd,banddos%e_mcd_lo, banddos%e_mcd_up
Matthias Redies's avatar
Matthias Redies committed
573 574 575 576 577 578 579 580 581 582 583 584

      WRITE (fileNum, '(a)') '   </output>'
      IF (present(filename)) THEN
         WRITE (fileNum, '(a)') '  <!-- We include the file relax.inp here to enable relaxations (see documentation) -->'
         WRITE (fileNum, '(a)') '  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="relax.xml"> <xi:fallback/> </xi:include>'
         WRITE (fileNum, '(a)') '</fleurInput>'
         CLOSE (fileNum)
      ELSE
         CALL closeXMLElement('inputData')
      END IF

   END SUBROUTINE w_inpXML
585
END MODULE m_winpXML