writeBasis.F90 25.9 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)
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
20
    USE m_genmtbasis
!   USE m_cdn_io
21
22
   USE m_abcof
   USE m_eig66_io, ONLY : read_eig
23
24

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

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

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

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

   
      INTEGER(HID_T)    :: fileID
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
      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
79
80
      INTEGER(HID_T)    :: eigSpaceID, eigSetID
      INTEGER(HID_T)    :: zmatSpaceID, zmatSetID
81
82
83
84
85
86
87
      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
88
      INTEGER(HSIZE_T)  :: dims(7)
89

90
      INTEGER           :: j, iAtom, i
91
92
93
94
!      INTEGER           :: noded, nodeu

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

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


!      REAL              :: wronk


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

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

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

    CALL force%init1(input,atoms)

121
122
123
124
125
126
127
128
129

    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))

130
131


132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
	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
151
152
153
154
155
156
      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)      
157
158
159
160
161
162

      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
163
      CALL h5dcreate_f(cellGroupID, "amat", H5T_NATIVE_DOUBLE, bravaisMatrixSpaceID, bravaisMatrixSetID, hdfError)
164
165
166
167
168
169
170
      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
171
      CALL h5dcreate_f(cellGroupID, "bmat", H5T_NATIVE_DOUBLE, reciprocalCellSpaceID, reciprocalCellSetID, hdfError)
172
173
174
      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
175
176
177
178
179
180
      
      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)

181
182

      CALL h5gclose_f(cellGroupID, hdfError)
183
      iAtom = 0
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
      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
204
      CALL h5dcreate_f(atomsGroupID, "jri", H5T_NATIVE_INTEGER, atomicNumbersSpaceID, atomicNumbersSetID, hdfError)
205
206
207
208
209
210
211
      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
212
      CALL h5dcreate_f(atomsGroupID, "lmax", H5T_NATIVE_INTEGER, atomicNumbersSpaceID, atomicNumbersSetID, hdfError)
213
214
215
      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
216
217
218
219
220
221
222
223
      
      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)
224
225
226
227

      dims(:1)=(/atoms%ntype/)
      dimsInt=dims
      CALL h5screate_simple_f(1,dims(:1),atomicNumbersSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
228
      CALL h5dcreate_f(atomsGroupID, "nlo", H5T_NATIVE_INTEGER, atomicNumbersSpaceID, atomicNumbersSetID, hdfError)
229
230
231
232
233
234
235
      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
236
      CALL h5dcreate_f(atomsGroupID, "llo", H5T_NATIVE_INTEGER, atomPosSpaceID, atomPosSetID, hdfError)
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
      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
254
      CALL h5dcreate_f(atomsGroupID, "ratoms", H5T_NATIVE_DOUBLE, atomPosSpaceID, atomPosSetID, hdfError)
255
256
257
258
259
260
261
      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
262
      CALL h5dcreate_f(atomsGroupID, "zatoms", H5T_NATIVE_INTEGER, atomicNumbersSpaceID, atomicNumbersSetID, hdfError)
263
264
265
266
      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
267
268
269
270
271
      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
272
      CALL io_write_integer1(atomicNumbersSetID,(/1/),dimsInt(:1),atoms%nz)
S.Rost's avatar
S.Rost committed
273
274
      CALL h5dclose_f(atomicNumbersSetID, hdfError)

275
276
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
      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
315
316
            !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)),'/',kpts%bk(1,nk),',',kpts%bk(2,nk),',',kpts%bk(3,nk)
317
318
319
320
321
322
323
324
325
326
327
328
	    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)
329
330
!index_lo(:,:)	
	      CALL h5gclose_f(kptGroupID, hdfError)
331
332
333
334
335
336
337
338
            
       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
339
                CALL genMTBasis(atoms,enpara,vTot,mpi,itype,jsp,usdus,f(:,:,0:,jsp),g(:,:,0:,jsp),flo)
340
341
342
		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
343
		CALL h5dcreate_f(itypeGroupID, "f", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
344
345
346
347
348
		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
349
		CALL h5dcreate_f(itypeGroupID, "g", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
350
351
352
353
354
355
356
		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
357
		CALL h5dcreate_f(itypeGroupID, "flo", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
358
359
360
361
		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
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
		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)


419
420
421
422
423
424
425
426
!			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
427
428
   CALL h5fclose_f(fileID, hdfError)
      version = 1
429
      filename = 'eig_gw.hdf'
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450

      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)
            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)),'_',kpts%bk(1,nk),',',kpts%bk(2,nk),',',kpts%bk(3,nk)
            CALL h5gcreate_f(fileID, TRIM(ADJUSTL(kpt_name)), kptGroupID, hdfError)
451
!--------------------abcoff, zmat, eig output here-------------------
452
453
454
455
!,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)
456
            CALL read_eig(eig_id,nk,jsp,zmat=zMat)
457
458
	    CALL eigVecCoeffs%init(input,DIMENSION,atoms,noco,jsp,numbands)
            IF (input%l_f) CALL force%init2(numbands,input,atoms)
459
460
461
462
            DO i=1,atoms%nat
	    	ngopr_temp(i)=atoms%ngopr(i)
                atoms%ngopr(i)=1
            END DO
463
464
		CALL abcof(input,atoms,sym,cell,lapw,numbands,usdus,noco,jsp,oneD,&
		    eigVecCoeffs%acof(:,0:,:,jsp),eigVecCoeffs%bcof(:,0:,:,jsp),&
465
466
467
468
		    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
469
!-------------------------for spex output: nbasfcn=nv(because lo info not needed) and numbands setting to numbands without highest (degenerat) state-------- 
470
471
472
473
474
475
476
477
478
479
480
481
482
483
                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/)
484
485
486
487
		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)
488
		CALL io_write_real1(eigSetID,(/1/),dimsInt(:1),results%eig(:numbands,nk,jsp))
489
490
491
		CALL h5dclose_f(eigSetID, hdfError)
                
		IF (zMat%l_real) THEN
492
		      dims(:2)=(/nbasfcn,numbands/)
493
494
		      dimsInt=dims
		      CALL h5screate_simple_f(2,dims(:2),kptCoordSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
495
		      CALL h5dcreate_f(kptGroupID, "pw", H5T_NATIVE_DOUBLE, kptCoordSpaceID, kptCoordSetID, hdfError)
496
		      CALL h5sclose_f(kptCoordSpaceID,hdfError)
497
		      CALL io_write_real2(kptCoordSetID,(/1,1/),dimsInt(:2),zMat%data_r(:nbasfcn,:numbands))
498
499
		      CALL h5dclose_f(kptCoordSetID, hdfError)
		ELSE
500
501
                      AllOCATE(output3(2,nbasfcn,numbands))
!			SIZE(zMat%data_c,1),SIZE(zMat%data_c,2)
502
503
		      output3(1,:,:)=REAL(zMat%data_c(:,:))
		      output3(2,:,:)=AIMAG(zMat%data_c(:,:))
504
		      dims(:3)=(/2,nbasfcn,numbands/)
505
506
		      dimsInt=dims
		      CALL h5screate_simple_f(3,dims(:3),zmatSpaceID,hdfError)
S.Rost's avatar
S.Rost committed
507
		      CALL h5dcreate_f(kptGroupID, "pw", H5T_NATIVE_DOUBLE, zmatSpaceID, zmatSetID, hdfError)
508
		      CALL h5sclose_f(zmatSpaceID,hdfError)
509
		      CALL io_write_real3(zmatSetID,(/1,1,1/),dimsInt(:3),output3(:2,:nbasfcn,:numbands))
510
511
512
		      CALL h5dclose_f(zmatSetID, hdfError)
		      DEAllOCATE(output3)
		END IF
513
514
515
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
		!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
600
601
		dimsInt = dims
                CALL h5screate_simple_f(4,dims(:4),itypeSpaceID,hdfError)
602
		CALL h5dcreate_f(kptGroupID, "mt", H5T_NATIVE_DOUBLE, itypeSpaceID, itypeSetID, hdfError)
603
		CALL h5sclose_f(itypeSpaceID,hdfError)
604
		CALL io_write_real4(itypeSetID,(/1,1,1,1/),dimsInt(:4), cof)
605
		CALL h5dclose_f(itypeSetID, hdfError)
606
607
		      deallocate ( cof )
!-------------------------end output spex format-----------------
608
609
610
611
612
613
614

		CALL h5gclose_f(kptGroupID, hdfError)
            
        END DO
       CALL h5gclose_f(jspGroupID, hdfError)
   END DO
   CALL h5fclose_f(fileID, hdfError)  
615
616
617



618
619
620
621
622
623
624
#else
   CALL juDFT_error("writeBasis called without HDF5! ",calledby="writeBasis")
#endif

END SUBROUTINE writeBasis

END MODULE m_writeBasis