writeBasis.F90 26.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
!--------------------------------------------------------------------------------
! Copyright (c) 2018 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.
!--------------------------------------------------------------------------------

MODULE m_writeBasis

CONTAINS

11
SUBROUTINE writeBasis(input,noco,kpts,atoms,sym,cell,enpara,vTot,mpi,DIMENSION,results,eig_id,oneD,sphhar,stars,vacuum)
12 13 14

   USE m_types
   USE m_juDFT
Daniel Wortmann's avatar
Daniel Wortmann committed
15
#ifdef CPP_HDF   
16 17
   USE hdf5
   USE m_hdf_tools
Daniel Wortmann's avatar
Daniel Wortmann committed
18
#endif   
19
    USE m_genmtbasis
20
   USE m_pot_io
21 22
   USE m_abcof
   USE m_eig66_io, ONLY : read_eig
23 24

   IMPLICIT NONE
25 26 27 28
!   TYPE(t_results),INTENT(IN):: results
      TYPE(t_dimension),INTENT(IN) :: DIMENSION
      TYPE(t_enpara),INTENT(IN)    :: enpara
!      TYPE(t_banddos),INTENT(IN)   :: banddos
29 30 31 32

      TYPE(t_sphhar),INTENT(IN)    :: sphhar
      TYPE(t_stars),INTENT(IN)     :: stars
      TYPE(t_vacuum),INTENT(IN)    :: vacuum
33 34 35 36

      TYPE(t_input),INTENT(IN)     :: input
      TYPE(t_noco),INTENT(IN)      :: noco
      TYPE(t_kpts),INTENT(IN)      :: kpts
37
      TYPE(t_atoms),INTENT(INOUT)     :: atoms
38 39 40 41
      TYPE(t_sym),INTENT(IN)       :: sym
      TYPE(t_cell),INTENT(IN)      :: cell
      TYPE(t_potden), INTENT(IN)   :: vTot
      TYPE(t_mpi), INTENT(IN)      :: mpi
42 43 44
      TYPE(t_results), INTENT(INOUT)  :: results
      INTEGER, INTENT(IN)          :: eig_id
      TYPE(t_oneD), INTENT(IN)     :: oneD
45 46 47

      TYPE (t_usdus)               :: usdus
      TYPE(t_lapw)                 :: lapw
48 49 50
      TYPE (t_eigVecCoeffs)        :: eigVecCoeffs
      TYPE (t_force)               :: force
      TYPE(t_mat)                  :: zMat
51

52 53
#ifdef CPP_HDF   
      
54 55
      LOGICAL           :: l_exist
      CHARACTER(LEN=30) :: filename
S.Rost's avatar
S.Rost committed
56
      CHARACTER(LEN=50) :: kpt_name
57 58 59
      CHARACTER(LEN=30) :: jsp_name
      CHARACTER(LEN=30) :: itype_name
!      CHARACTER(LEN=30) :: l_name
60 61 62

   
      INTEGER(HID_T)    :: fileID
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
      INTEGER(HID_T)    :: metaGroupID
      INTEGER(HID_T)    :: generalGroupID
      INTEGER(HID_T)    :: cellGroupID
      INTEGER(HID_T)    :: atomsGroupID
      INTEGER(HID_T)    :: kptsGroupID
      INTEGER(HID_T)    :: kptGroupID
      INTEGER(HID_T)    :: jspGroupID
      INTEGER(HID_T)    :: itypeGroupID,  itypeSpaceID, itypeSetID
!      INTEGER(HID_T)    :: lGroupID

!      INTEGER(HID_T)    :: stringTypeID
!      INTEGER(SIZE_T)   :: stringLength

      INTEGER(HID_T)    :: bravaisMatrixSpaceID, bravaisMatrixSetID
      INTEGER(HID_T)    :: reciprocalCellSpaceID, reciprocalCellSetID

      INTEGER(HID_T)    :: atomPosSpaceID, atomPosSetID
      INTEGER(HID_T)    :: gvecSpaceID, gvecSetID
81 82
      INTEGER(HID_T)    :: eigSpaceID, eigSetID
      INTEGER(HID_T)    :: zmatSpaceID, zmatSetID
83 84 85 86 87 88 89
      INTEGER(HID_T)    :: atomicNumbersSpaceID, atomicNumbersSetID
      INTEGER(HID_T)    :: equivAtomsClassSpaceID, equivAtomsClassSetID

      INTEGER(HID_T)    :: kptCoordSpaceID, kptCoordSetID
      INTEGER(HID_T)    :: kptWeightSpaceID, kptWeightSetID
 !     INTEGER(HID_T)    :: kptSPLabelsSpaceID, kptSPLabelsSetID
 !     INTEGER(HID_T)    :: kptsSPIndicesSpaceID, kptsSPIndicesSetID
90
      INTEGER(HSIZE_T)  :: dims(7)
91

92
      INTEGER           :: j, iAtom, i
93 94 95 96
!      INTEGER           :: noded, nodeu

      INTEGER           :: hdfError, dimsInt(7)
      INTEGER           :: version
97
      REAL, ALLOCATABLE  :: output(:,:,:,:),output5(:,:,:,:,:),output3(:,:,:)
98 99 100 101
!      INTEGER           :: fakeLogical
!      REAL              :: eFermiPrev
 !     LOGICAL           :: l_error

102
      INTEGER           :: atomicNumbers(atoms%nat),ngopr_temp(atoms%nat)
103 104 105 106 107 108 109 110 111
      INTEGER           :: equivAtomsGroup(atoms%nat)


!      REAL              :: wronk


      REAL,    ALLOCATABLE :: f(:,:,:,:),g(:,:,:,:)
      REAL,    ALLOCATABLE :: flo(:,:,:)

112 113 114 115 116
      real,    allocatable :: cof(:,:,:,:)
      integer(HSIZE_T)              :: Hdim1(4)
      INTEGER		  :: lmn, na,lm,n,nn, m
      complex, parameter   :: img=(0.,1.)

117 118
      LOGICAL l_zref,l_real
      INTEGER jsp,nk,l,itype
119
      INTEGER numbands, nbasfcn, ndbands !ndbands number of bands without highest (degenerate)
120 121 122

    CALL force%init1(input,atoms)

123 124 125 126 127 128 129 130 131

    IF (noco%l_mperp) THEN
       ALLOCATE ( f(atoms%jmtd,2,0:atoms%lmaxd,input%jspins),g(atoms%jmtd,2,0:atoms%lmaxd,input%jspins) )
    ELSE
       ALLOCATE ( f(atoms%jmtd,2,0:atoms%lmaxd,1:input%jspins) )
       ALLOCATE ( g(atoms%jmtd,2,0:atoms%lmaxd,1:input%jspins) )
    ENDIF
    ALLOCATE (flo(atoms%jmtd,2,atoms%nlod))

132 133


134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
	l_real=sym%invs.AND..NOT.noco%l_noco
	! check if z-reflection trick can be used
	l_zref=(sym%zrfs.AND.(SUM(ABS(kpts%bk(3,:kpts%nkpt))).LT.1e-9).AND..NOT.noco%l_noco)
!	IF (mpi%n_size > 1) l_zref = .FALSE.
      version = 1
      filename = 'basis.hdf'

      INQUIRE(FILE=TRIM(ADJUSTL(filename)),EXIST=l_exist)
      IF(l_exist) THEN
         CALL system('rm '//TRIM(ADJUSTL(filename)))       
      END IF

      CALL h5fcreate_f(TRIM(ADJUSTL(filename)), H5F_ACC_TRUNC_F, fileID, hdfError, H5P_DEFAULT_F, H5P_DEFAULT_F)

      CALL h5gcreate_f(fileID, '/meta', metaGroupID, hdfError)
      CALL io_write_attint0(metaGroupID,'version',version)
      CALL h5gclose_f(metaGroupID, hdfError)

      CALL h5gcreate_f(fileID, '/general', generalGroupID, hdfError)
S.Rost's avatar
S.Rost committed
153 154 155 156 157 158
      CALL io_write_attint0(generalGroupID,'jspins',input%jspins)
      CALL io_write_attlog0(generalGroupID,'invs',sym%invs)
      CALL io_write_attlog0(generalGroupID,'l_soc',noco%l_soc)
      CALL io_write_attlog0(generalGroupID,'l_real',l_real)
      CALL io_write_attreal0(generalGroupID,'rkmax',input%rkmax)
      CALL h5gclose_f(generalGroupID, hdfError)      
159 160 161 162 163 164

      CALL h5gcreate_f(fileID, '/cell', cellGroupID, hdfError)

      dims(:2)=(/3,3/)
      dimsInt=dims
      CALL h5screate_simple_f(2,dims(:2),bravaisMatrixSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
165
      CALL h5dcreate_f(cellGroupID, "amat", H5T_NATIVE_DOUBLE, bravaisMatrixSpaceID, bravaisMatrixSetID, hdfError)
166 167 168 169 170 171 172
      CALL h5sclose_f(bravaisMatrixSpaceID,hdfError)
      CALL io_write_real2(bravaisMatrixSetID,(/1,1/),dimsInt(:2),cell%amat)
      CALL h5dclose_f(bravaisMatrixSetID, hdfError)

      dims(:2)=(/3,3/)
      dimsInt=dims
      CALL h5screate_simple_f(2,dims(:2),reciprocalCellSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
173
      CALL h5dcreate_f(cellGroupID, "bmat", H5T_NATIVE_DOUBLE, reciprocalCellSpaceID, reciprocalCellSetID, hdfError)
174 175 176
      CALL h5sclose_f(reciprocalCellSpaceID,hdfError)
      CALL io_write_real2(reciprocalCellSetID,(/1,1/),dimsInt(:2),cell%bmat)
      CALL h5dclose_f(reciprocalCellSetID, hdfError)
S.Rost's avatar
S.Rost committed
177 178 179 180 181 182
      
      CALL io_write_attreal0(cellGroupID,'scaleCell',input%scaleCell)
      CALL io_write_attreal0(cellGroupID,'scaleA1',input%scaleA1)
      CALL io_write_attreal0(cellGroupID,'scaleA2',input%scaleA2)
      CALL io_write_attreal0(cellGroupID,'scaleC',input%scaleC)

183 184

      CALL h5gclose_f(cellGroupID, hdfError)
185
      iAtom = 0
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
      DO iType = 1, atoms%ntype
         DO j = 1, atoms%neq(iType)
            iAtom = iAtom + 1
            atomicNumbers(iAtom) = atoms%nz(iType)
            equivAtomsGroup(iAtom) = iType
         END DO
      END DO

      CALL h5gcreate_f(fileID, '/atoms', atomsGroupID, hdfError)
      CALL io_write_attint0(atomsGroupID,'nAtoms',atoms%nat)
      CALL io_write_attint0(atomsGroupID,'nTypes',atoms%ntype)
      CALL io_write_attint0(atomsGroupID,'nlod',atoms%nlod)
      CALL io_write_attint0(atomsGroupID,'llod',atoms%llod)
      CALL io_write_attint0(atomsGroupID,'nlotot',atoms%nlotot)
      CALL io_write_attint0(atomsGroupID,'lmaxd',atoms%lmaxd)
      CALL io_write_attint0(atomsGroupID,'jmtd',atoms%jmtd)

      dims(:1)=(/atoms%ntype/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),atomicNumbersSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
206
      CALL h5dcreate_f(atomsGroupID, "jri", H5T_NATIVE_INTEGER, atomicNumbersSpaceID, atomicNumbersSetID, hdfError)
207 208 209 210 211 212 213
      CALL h5sclose_f(atomicNumbersSpaceID,hdfError)
      CALL io_write_integer1(atomicNumbersSetID,(/1/),dimsInt(:1),atoms%jri)
      CALL h5dclose_f(atomicNumbersSetID, hdfError)

      dims(:1)=(/atoms%ntype/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),atomicNumbersSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
214
      CALL h5dcreate_f(atomsGroupID, "lmax", H5T_NATIVE_INTEGER, atomicNumbersSpaceID, atomicNumbersSetID, hdfError)
215 216 217
      CALL h5sclose_f(atomicNumbersSpaceID,hdfError)
      CALL io_write_integer1(atomicNumbersSetID,(/1/),dimsInt(:1),atoms%lmax)
      CALL h5dclose_f(atomicNumbersSetID, hdfError)
S.Rost's avatar
S.Rost committed
218 219 220 221 222 223 224 225
      
      dims(:1)=(/atoms%ntype/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),atomicNumbersSpaceID,hdfError)
      CALL h5dcreate_f(atomsGroupID, "neq", H5T_NATIVE_INTEGER, atomicNumbersSpaceID, atomicNumbersSetID, hdfError)
      CALL h5sclose_f(atomicNumbersSpaceID,hdfError)
      CALL io_write_integer1(atomicNumbersSetID,(/1/),dimsInt(:1),atoms%neq)
      CALL h5dclose_f(atomicNumbersSetID, hdfError)
226 227 228 229

      dims(:1)=(/atoms%ntype/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),atomicNumbersSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
230
      CALL h5dcreate_f(atomsGroupID, "nlo", H5T_NATIVE_INTEGER, atomicNumbersSpaceID, atomicNumbersSetID, hdfError)
231 232 233 234 235 236 237
      CALL h5sclose_f(atomicNumbersSpaceID,hdfError)
      CALL io_write_integer1(atomicNumbersSetID,(/1/),dimsInt(:1),atoms%nlo)
      CALL h5dclose_f(atomicNumbersSetID, hdfError)

      dims(:2)=(/atoms%nlod,atoms%ntype/)
      dimsInt=dims
      CALL h5screate_simple_f(2,dims(:2),atomPosSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
238
      CALL h5dcreate_f(atomsGroupID, "llo", H5T_NATIVE_INTEGER, atomPosSpaceID, atomPosSetID, hdfError)
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
      CALL h5sclose_f(atomPosSpaceID,hdfError)
      CALL io_write_integer2(atomPosSetID,(/1,1/),dimsInt(:2),atoms%llo)
      CALL h5dclose_f(atomPosSetID, hdfError)

      dims(:2)=(/atoms%jmtd,atoms%ntype/)
      dimsInt=dims
      CALL h5screate_simple_f(2,dims(:2),atomPosSpaceID,hdfError)
      CALL h5dcreate_f(atomsGroupID, "rmsh", H5T_NATIVE_DOUBLE, atomPosSpaceID, atomPosSetID, hdfError)
      CALL h5sclose_f(atomPosSpaceID,hdfError)
      CALL io_write_real2(atomPosSetID,(/1,1/),dimsInt(:2),atoms%rmsh)
      CALL h5dclose_f(atomPosSetID, hdfError)



      dims(:2)=(/3,atoms%nat/)
      dimsInt=dims
      CALL h5screate_simple_f(2,dims(:2),atomPosSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
256
      CALL h5dcreate_f(atomsGroupID, "ratoms", H5T_NATIVE_DOUBLE, atomPosSpaceID, atomPosSetID, hdfError)
257 258 259 260 261 262 263
      CALL h5sclose_f(atomPosSpaceID,hdfError)
      CALL io_write_real2(atomPosSetID,(/1,1/),dimsInt(:2),atoms%taual)
      CALL h5dclose_f(atomPosSetID, hdfError)

      dims(:1)=(/atoms%nat/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),atomicNumbersSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
264
      CALL h5dcreate_f(atomsGroupID, "zatoms", H5T_NATIVE_INTEGER, atomicNumbersSpaceID, atomicNumbersSetID, hdfError)
265 266 267 268
      CALL h5sclose_f(atomicNumbersSpaceID,hdfError)
      CALL io_write_integer1(atomicNumbersSetID,(/1/),dimsInt(:1),atomicNumbers)
      CALL h5dclose_f(atomicNumbersSetID, hdfError)

S.Rost's avatar
S.Rost committed
269 270 271 272 273
      dims(:1)=(/atoms%ntype/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),atomicNumbersSpaceID,hdfError)
      CALL h5dcreate_f(atomsGroupID, "ztype", H5T_NATIVE_INTEGER, atomicNumbersSpaceID, atomicNumbersSetID, hdfError)
      CALL h5sclose_f(atomicNumbersSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
274
      CALL io_write_integer1(atomicNumbersSetID,(/1/),dimsInt(:1),atoms%nz)
S.Rost's avatar
S.Rost committed
275 276
      CALL h5dclose_f(atomicNumbersSetID, hdfError)

277 278 279 280 281 282 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
      dims(:1)=(/atoms%nat/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),equivAtomsClassSpaceID,hdfError)
      CALL h5dcreate_f(atomsGroupID, "equivAtomsGroup", H5T_NATIVE_INTEGER, equivAtomsClassSpaceID, equivAtomsClassSetID, hdfError)
      CALL h5sclose_f(equivAtomsClassSpaceID,hdfError)
      CALL io_write_integer1(equivAtomsClassSetID,(/1/),dimsInt(:1),equivAtomsGroup)
      CALL h5dclose_f(equivAtomsClassSetID, hdfError)

      CALL h5gclose_f(atomsGroupID, hdfError)

      CALL h5gcreate_f(fileID, '/kpts', kptsGroupID, hdfError)

      CALL io_write_attint0(kptsGroupID,'nkpt',kpts%nkpt)

      dims(:2)=(/3,kpts%nkpt/)
      dimsInt=dims
      CALL h5screate_simple_f(2,dims(:2),kptCoordSpaceID,hdfError)
      CALL h5dcreate_f(kptsGroupID, "coordinates", H5T_NATIVE_DOUBLE, kptCoordSpaceID, kptCoordSetID, hdfError)
      CALL h5sclose_f(kptCoordSpaceID,hdfError)
      CALL io_write_real2(kptCoordSetID,(/1,1/),dimsInt(:2),kpts%bk)
      CALL h5dclose_f(kptCoordSetID, hdfError)

      dims(:1)=(/kpts%nkpt/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),kptWeightSpaceID,hdfError)
      CALL h5dcreate_f(kptsGroupID, "weights", H5T_NATIVE_DOUBLE, kptWeightSpaceID, kptWeightSetID, hdfError)
      CALL h5sclose_f(kptWeightSpaceID,hdfError)
      CALL io_write_real1(kptWeightSetID,(/1/),dimsInt(:1),kpts%wtkpt)
      CALL h5dclose_f(kptWeightSetID, hdfError)

      CALL h5gclose_f(kptsGroupID, hdfError)

   CALL usdus%init(atoms,input%jspins)

   DO jsp = 1,MERGE(1,input%jspins,noco%l_noco)
       write(jsp_name , '(a,i0)') '/jsp_',jsp
       CALL h5gcreate_f(fileID, TRIM(ADJUSTL(jsp_name)), jspGroupID, hdfError)
!      DO nk = mpi%n_start,kpts%nkpt,mpi%n_stride
       DO nk = 1,kpts%nkpt
            CALL lapw%init(input,noco,kpts,atoms,sym,nk,cell,l_zref)
S.Rost's avatar
S.Rost committed
317
            !write(kpt_name , '(2a,i0)') TRIM(ADJUSTL(jsp_name)),'/kpt_',nk
318
            write(kpt_name , '(2a,f12.10,a,f12.10,a,f12.10)') TRIM(ADJUSTL(jsp_name)),'/kpt_',kpts%bk(1,nk),',',kpts%bk(2,nk),',',kpts%bk(3,nk)
319 320 321 322 323 324 325 326 327 328 329 330
	    CALL h5gcreate_f(fileID, TRIM(ADJUSTL(kpt_name)), kptGroupID, hdfError)
!--------------------enter output gvec etc here--------------------
!lapw%gvec(3,nv,input%jspins)
            CALL io_write_attint0(kptGroupID,'nv',lapw%nv(jsp))

	      dims(:2)=(/3,lapw%nv(jsp)/)
	      dimsInt=dims
	      CALL h5screate_simple_f(2,dims(:2),gvecSpaceID,hdfError)
	      CALL h5dcreate_f(kptGroupID, "gvec", H5T_NATIVE_INTEGER, gvecSpaceID, gvecSetID, hdfError)
	      CALL h5sclose_f(gvecSpaceID,hdfError)
	      CALL io_write_integer2(gvecSetID,(/1,1/),dimsInt(:2),lapw%gvec(:,:lapw%nv(jsp),jsp))
	      CALL h5dclose_f(gvecSetID, hdfError)
331 332
!index_lo(:,:)	
	      CALL h5gclose_f(kptGroupID, hdfError)
333 334 335 336 337 338 339 340
            
       END DO


       DO itype = 1,atoms%ntype
		write(itype_name , '(2a,i0)') TRIM(ADJUSTL(jsp_name)),'/itype_',itype
		CALL h5gcreate_f(fileID, TRIM(ADJUSTL(itype_name)), itypeGroupID, hdfError)

Daniel Wortmann's avatar
Daniel Wortmann committed
341
                CALL genMTBasis(atoms,enpara,vTot,mpi,itype,jsp,usdus,f(:,:,0:,jsp),g(:,:,0:,jsp),flo)
342 343 344
		dims(:3)=(/atoms%jmtd,2,atoms%lmaxd+1/)
		dimsInt = dims
		CALL h5screate_simple_f(3,dims(:3),itypeSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
345
		CALL h5dcreate_f(itypeGroupID, "f", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
346 347 348 349 350
		CALL h5sclose_f(itypeSpaceID,hdfError)
		CALL io_write_real3(itypeSetID,(/1,1,1/),dimsInt(:3),f(:,:,0:,jsp))
		CALL h5dclose_f(itypeSetID, hdfError)

		CALL h5screate_simple_f(3,dims(:3),itypeSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
351
		CALL h5dcreate_f(itypeGroupID, "g", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
352 353 354 355 356 357 358
		CALL h5sclose_f(itypeSpaceID,hdfError)
		CALL io_write_real3(itypeSetID,(/1,1,1/),dimsInt(:3),g(:,:,0:,jsp))
		CALL h5dclose_f(itypeSetID, hdfError)

		dims(:3)=(/atoms%jmtd,2,atoms%nlod/)
		dimsInt = dims
		CALL h5screate_simple_f(3,dims(:3),itypeSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
359
		CALL h5dcreate_f(itypeGroupID, "flo", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
360 361 362 363
		CALL h5sclose_f(itypeSpaceID,hdfError)
		CALL io_write_real3(itypeSetID,(/1,1,1/),dimsInt(:3),flo(:,:,:))
		CALL h5dclose_f(itypeSetID, hdfError)

S.Rost's avatar
S.Rost committed
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
		dims(:1)=(/atoms%lmaxd+1/)
		dimsInt = dims
		CALL h5screate_simple_f(1,dims(:1),itypeSpaceID,hdfError)
		CALL h5dcreate_f(itypeGroupID, "us", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
		CALL h5sclose_f(itypeSpaceID,hdfError)
		CALL io_write_real1(itypeSetID,(/1/),dimsInt(:1),usdus%us(:,itype,jsp))
		CALL h5dclose_f(itypeSetID, hdfError)

		CALL h5screate_simple_f(1,dims(:1),itypeSpaceID,hdfError)
		CALL h5dcreate_f(itypeGroupID, "dus", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
		CALL h5sclose_f(itypeSpaceID,hdfError)
		CALL io_write_real1(itypeSetID,(/1/),dimsInt(:1),usdus%dus(:,itype,jsp))
		CALL h5dclose_f(itypeSetID, hdfError)

		CALL h5screate_simple_f(1,dims(:1),itypeSpaceID,hdfError)
		CALL h5dcreate_f(itypeGroupID, "uds", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
		CALL h5sclose_f(itypeSpaceID,hdfError)
		CALL io_write_real1(itypeSetID,(/1/),dimsInt(:1),usdus%uds(:,itype,jsp))
		CALL h5dclose_f(itypeSetID, hdfError)

		CALL h5screate_simple_f(1,dims(:1),itypeSpaceID,hdfError)
		CALL h5dcreate_f(itypeGroupID, "duds", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
		CALL h5sclose_f(itypeSpaceID,hdfError)
		CALL io_write_real1(itypeSetID,(/1/),dimsInt(:1),usdus%duds(:,itype,jsp))
		CALL h5dclose_f(itypeSetID, hdfError)

		dims(:1)=(/atoms%nlod/)
		dimsInt = dims
		CALL h5screate_simple_f(1,dims(:1),itypeSpaceID,hdfError)
		CALL h5dcreate_f(itypeGroupID, "dulos", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
		CALL h5sclose_f(itypeSpaceID,hdfError)
		CALL io_write_real1(itypeSetID,(/1/),dimsInt(:1),usdus%dulos(:,itype,jsp))
		CALL h5dclose_f(itypeSetID, hdfError)

		CALL h5screate_simple_f(1,dims(:1),itypeSpaceID,hdfError)
		CALL h5dcreate_f(itypeGroupID, "ulos", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
		CALL h5sclose_f(itypeSpaceID,hdfError)
		CALL io_write_real1(itypeSetID,(/1/),dimsInt(:1),usdus%ulos(:,itype,jsp))
		CALL h5dclose_f(itypeSetID, hdfError)

		dims(:1)=(/atoms%lmaxd+1/)
		dimsInt = dims
		CALL h5screate_simple_f(1,dims(:1),itypeSpaceID,hdfError)
		CALL h5dcreate_f(itypeGroupID, "el0", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
		CALL h5sclose_f(itypeSpaceID,hdfError)
		CALL io_write_real1(itypeSetID,(/1/),dimsInt(:1),enpara%el0(:,itype,jsp))
		CALL h5dclose_f(itypeSetID, hdfError)

		dims(:1)=(/atoms%nlod/)
		dimsInt = dims
		CALL h5screate_simple_f(1,dims(:1),itypeSpaceID,hdfError)
		CALL h5dcreate_f(itypeGroupID, "ello0", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
		CALL h5sclose_f(itypeSpaceID,hdfError)
		CALL io_write_real1(itypeSetID,(/1/),dimsInt(:1),enpara%ello0(:,itype,jsp))
		CALL h5dclose_f(itypeSetID, hdfError)


421 422 423 424 425 426 427 428
!			write(kpt_name , '(3a,i0)') TRIM(ADJUSTL(jsp_name)),TRIM(ADJUSTL(itype_name)),'/l_',l
!			CALL h5gcreate_f(fileID, TRIM(ADJUSTL(l_name)), lGroupID, hdfError)
!			CALL h5gclose_f(lGroupID, hdfError)
		CALL h5gclose_f(itypeGroupID, hdfError)
	END DO

       CALL h5gclose_f(jspGroupID, hdfError)
   END DO
429 430
   CALL h5fclose_f(fileID, hdfError)
      version = 1
431
      filename = 'eig_gw.hdf'
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449

      INQUIRE(FILE=TRIM(ADJUSTL(filename)),EXIST=l_exist)
      IF(l_exist) THEN
         CALL system('rm '//TRIM(ADJUSTL(filename)))       
      END IF

      CALL h5fcreate_f(TRIM(ADJUSTL(filename)), H5F_ACC_TRUNC_F, fileID, hdfError, H5P_DEFAULT_F, H5P_DEFAULT_F)

      CALL h5gcreate_f(fileID, '/meta', metaGroupID, hdfError)
      CALL io_write_attint0(metaGroupID,'version',version)
      CALL h5gclose_f(metaGroupID, hdfError)

   DO jsp = 1,MERGE(1,input%jspins,noco%l_noco)
       write(jsp_name , '(a,i0)') '/jsp_',jsp
       CALL h5gcreate_f(fileID, TRIM(ADJUSTL(jsp_name)), jspGroupID, hdfError)
!      DO nk = mpi%n_start,kpts%nkpt,mpi%n_stride
       DO nk = 1,kpts%nkpt
            CALL lapw%init(input,noco,kpts,atoms,sym,nk,cell,l_zref)
450 451
            !write(kpt_name , '(2a,i0)') TRIM(ADJUSTL(jsp_name)),'/kpt_',nk
            write(kpt_name , '(2a,f12.10,a,f12.10,a,f12.10)') TRIM(ADJUSTL(jsp_name)),'/kpt_',kpts%bk(1,nk),',',kpts%bk(2,nk),',',kpts%bk(3,nk)
452
            CALL h5gcreate_f(fileID, TRIM(ADJUSTL(kpt_name)), kptGroupID, hdfError)
453
!--------------------abcoff, zmat, eig output here-------------------
454 455 456 457
!,results%neig(nk,jsp),results%eig(:,nk,jsp)
            numbands=results%neig(nk,jsp)
            nbasfcn = MERGE(lapw%nv(1)+lapw%nv(2)+2*atoms%nlotot,lapw%nv(1)+atoms%nlotot,noco%l_noco)
            CALL zMat%init(l_real,nbasfcn,numbands)
458
            CALL read_eig(eig_id,nk,jsp,zmat=zMat)
459 460
	    CALL eigVecCoeffs%init(input,DIMENSION,atoms,noco,jsp,numbands)
            IF (input%l_f) CALL force%init2(numbands,input,atoms)
461 462 463 464
            DO i=1,atoms%nat
	    	ngopr_temp(i)=atoms%ngopr(i)
                atoms%ngopr(i)=1
            END DO
465 466
		CALL abcof(input,atoms,sym,cell,lapw,numbands,usdus,noco,jsp,oneD,&
		    eigVecCoeffs%acof(:,0:,:,jsp),eigVecCoeffs%bcof(:,0:,:,jsp),&
467 468 469 470
		    eigVecCoeffs%ccof(-atoms%llod:,:,:,:,jsp),zMat,results%eig(:,nk,jsp),force) 
            DO i=1,atoms%nat
	     	atoms%ngopr(i)=ngopr_temp(i)
            END DO
S.Rost's avatar
S.Rost committed
471
!-------------------------for spex output: nbasfcn=nv(because lo info not needed) and numbands setting to numbands without highest (degenerat) state-------- 
472 473 474 475 476 477 478 479 480 481 482 483 484 485
                nbasfcn=lapw%nv(jsp)
		ndbands=numbands-1
		DO i=(numbands-1),1,-1
		    IF (abs(results%eig(i+1,nk,jsp)-results%eig(i,nk,jsp)).LT.0.000001) THEN
		        ndbands=ndbands-1
		    ELSE
			EXIT
		    END IF
		END DO
write(*,*)numbands,ndbands
		numbands=ndbands
!------------------------setting variables numbands and nbasfcn end -------------------
		!CALL read_eig(eig_id,nk,jsp,eig=results%eig(:,nk,jsp),zmat=zMat)
		dims(:1)=(/numbands/)
486 487 488 489
		dimsInt=dims
		CALL h5screate_simple_f(1,dims(:1),eigSpaceID,hdfError)
		CALL h5dcreate_f(kptGroupID, "eig", H5T_NATIVE_DOUBLE, eigSpaceID, eigSetID, hdfError)
		CALL h5sclose_f(eigSpaceID,hdfError)
490
		CALL io_write_real1(eigSetID,(/1/),dimsInt(:1),results%eig(:numbands,nk,jsp))
491
		CALL h5dclose_f(eigSetID, hdfError)
492 493
   
    CALL io_write_attint0(kptGroupID,'numbands',numbands)            
494
		IF (zMat%l_real) THEN
495
		      dims(:2)=(/nbasfcn,numbands/)
496 497
		      dimsInt=dims
		      CALL h5screate_simple_f(2,dims(:2),kptCoordSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
498
		      CALL h5dcreate_f(kptGroupID, "pw", H5T_NATIVE_DOUBLE, kptCoordSpaceID, kptCoordSetID, hdfError)
499
		      CALL h5sclose_f(kptCoordSpaceID,hdfError)
500
		      CALL io_write_real2(kptCoordSetID,(/1,1/),dimsInt(:2),zMat%data_r(:nbasfcn,:numbands))
501 502
		      CALL h5dclose_f(kptCoordSetID, hdfError)
		ELSE
503 504
                      AllOCATE(output3(2,nbasfcn,numbands))
!			SIZE(zMat%data_c,1),SIZE(zMat%data_c,2)
505 506
		      output3(1,:,:)=REAL(zMat%data_c(:,:))
		      output3(2,:,:)=AIMAG(zMat%data_c(:,:))
507
		      dims(:3)=(/2,nbasfcn,numbands/)
508 509
		      dimsInt=dims
		      CALL h5screate_simple_f(3,dims(:3),zmatSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
510
		      CALL h5dcreate_f(kptGroupID, "pw", H5T_NATIVE_DOUBLE, zmatSpaceID, zmatSetID, hdfError)
511
		      CALL h5sclose_f(zmatSpaceID,hdfError)
512
		      CALL io_write_real3(zmatSetID,(/1,1,1/),dimsInt(:3),output3(:2,:nbasfcn,:numbands))
513 514 515
		      CALL h5dclose_f(zmatSetID, hdfError)
		      DEAllOCATE(output3)
		END IF
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
		!AllOCATE(output(2,numbands,dimension%lmd+1,atoms%nat))
		!output(1,:,:,:)=REAL(eigVecCoeffs%acof(:,0:,:,jsp))
		!output(2,:,:,:)=AIMAG(eigVecCoeffs%acof(:,0:,:,jsp))
		!dims(:4)=(/2,numbands,dimension%lmd+1,atoms%nat/)
		!dimsInt = dims
                !CALL h5screate_simple_f(4,dims(:4),itypeSpaceID,hdfError)
		!CALL h5dcreate_f(kptGroupID, "acof", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
		!CALL h5sclose_f(itypeSpaceID,hdfError)
		!CALL io_write_real4(itypeSetID,(/1,1,1,1/),dimsInt(:4), output)
		!CALL h5dclose_f(itypeSetID, hdfError)
		!DEAllOCATE(output)

		!AllOCATE(output(2,numbands,dimension%lmd+1,atoms%nat))
		!output(1,:,:,:)=REAL(eigVecCoeffs%bcof(:,0:,:,jsp))
		!output(2,:,:,:)=AIMAG(eigVecCoeffs%bcof(:,0:,:,jsp))
		!dims(:4)=(/2,numbands,dimension%lmd+1,atoms%nat/)
		!dimsInt = dims
                !CALL h5screate_simple_f(4,dims(:4),itypeSpaceID,hdfError)
		!CALL h5dcreate_f(kptGroupID, "bcof", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
		!CALL h5sclose_f(itypeSpaceID,hdfError)
		!CALL io_write_real4(itypeSetID,(/1,1,1,1/),dimsInt(:4), output)
		!CALL h5dclose_f(itypeSetID, hdfError)
		!DEAllOCATE(output)

		!AllOCATE(output5(2,atoms%llod*2+1,numbands,atoms%nlod,atoms%nat))
		!output5(1,:,:,:,:)=REAL(eigVecCoeffs%ccof(-atoms%llod:,:,:,:,jsp))
		!output5(2,:,:,:,:)=AIMAG(eigVecCoeffs%ccof(-atoms%llod:,:,:,:,jsp))
		!dims(:5)=(/2,atoms%llod*2+1,numbands,atoms%nlod,atoms%nat/)
		!dimsInt = dims
                !CALL h5screate_simple_f(5,dims(:5),itypeSpaceID,hdfError)
		!CALL h5dcreate_f(kptGroupID, "ccof", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
		!CALL h5sclose_f(itypeSpaceID,hdfError)
		!CALL io_write_real5(itypeSetID,(/1,1,1,1,1/),dimsInt(:5), output5)
		!CALL h5dclose_f(itypeSetID, hdfError)
		!DEAllOCATE(output5)

!-------------------------output spex format-------------------
	      ! get dimensions for MT cof
	      lmn = 0
	      na  = 0
	      do n = 1,atoms%ntype
		do nn = 1,atoms%neq(n)
		  na = na + 1
		  lm = 0
		  do l = 0,atoms%lmax(n)
		    lm = lm + 2*(2*l+1)
		  enddo
		  do i = 1,atoms%nlo(n)
		    lm = lm + 2*atoms%llo(i,n)+1
		  enddo
		  lmn = max(lmn,lm)
		enddo
	      enddo
	      Hdim1 = (/ 2,lmn,na,numbands /)

		allocate ( cof(Hdim1(1),Hdim1(2),Hdim1(3),Hdim1(4)) )
		      cof = 0
		      na  = 0
		      do n = 1,atoms%ntype
			do nn = 1,atoms%neq(n)
			  na = na + 1
			  lm  = 0
			  lmn = 0
			  do l = 0,atoms%lmax(n)
			    do m = -l,l              
			      cof(1,lmn+1,na,:) = real ( eigVecCoeffs%acof(:numbands,lm,na,jsp) * img**l )
			      cof(1,lmn+2,na,:) = real ( eigVecCoeffs%bcof(:numbands,lm,na,jsp) * img**l )
			      cof(2,lmn+1,na,:) = aimag ( eigVecCoeffs%acof(:numbands,lm,na,jsp) * img**l )
			      cof(2,lmn+2,na,:) = aimag ( eigVecCoeffs%bcof(:numbands,lm,na,jsp) * img**l )
			      lm  = lm  + 1
			      lmn = lmn + 2
			      do i = 1,atoms%nlo(n)
				if(atoms%llo(i,n).eq.l) then
				  lmn = lmn + 1
				  cof(1,lmn,na,:) = real( eigVecCoeffs%ccof(m,:numbands,i,na,jsp) * img**l )
				  cof(2,lmn,na,:) = aimag( eigVecCoeffs%ccof(m,:numbands,i,na,jsp) * img**l )
				endif
			      enddo
			    enddo
			  enddo
			enddo
			if(lmn.gt.size(cof,2)) then
			  write(*,*) lmn,size(cof,2)
			endif
		      enddo

		dims(:4)=Hdim1
603 604
		dimsInt = dims
                CALL h5screate_simple_f(4,dims(:4),itypeSpaceID,hdfError)
605
		CALL h5dcreate_f(kptGroupID, "mt", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
606
		CALL h5sclose_f(itypeSpaceID,hdfError)
607
		CALL io_write_real4(itypeSetID,(/1,1,1,1/),dimsInt(:4), cof)
608
		CALL h5dclose_f(itypeSetID, hdfError)
609 610
		      deallocate ( cof )
!-------------------------end output spex format-----------------
611 612 613 614 615 616 617

		CALL h5gclose_f(kptGroupID, hdfError)
            
        END DO
       CALL h5gclose_f(jspGroupID, hdfError)
   END DO
   CALL h5fclose_f(fileID, hdfError)  
618 619 620 621 622
!-------------------------write potential--------------------

   CALL writePotential(stars,vacuum,atoms,cell,sphhar,input,sym,oneD,1,vTot%iter,vTot%mt,vTot%pw,vTot%vacz,vTot%vacxy)
   CALL writePotential(stars,vacuum,atoms,cell,sphhar,input,sym,oneD,2,vTot%iter,vTot%mt,vTot%pw,vTot%vacz,vTot%vacxy)
   CALL writePotential(stars,vacuum,atoms,cell,sphhar,input,sym,oneD,3,vTot%iter,vTot%mt,vTot%pw,vTot%vacz,vTot%vacxy)
623 624 625



626 627 628 629 630 631 632
#else
   CALL juDFT_error("writeBasis called without HDF5! ",calledby="writeBasis")
#endif

END SUBROUTINE writeBasis

END MODULE m_writeBasis