-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathread_energy.f90
1962 lines (1766 loc) · 77.9 KB
/
read_energy.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "alias.inc"
subroutine set_target_and_weight(EDFT, PWGHT, PINPT, PGEOM, PKPTS)
use parameters, only : energy, incar, weight, poscar, kpoints
use mpi_setup
use print_io
implicit none
type(incar) :: PINPT
type(energy) :: EDFT, EDFT_ALL
type(weight) :: PWGHT
type(poscar) :: PGEOM
type(kpoints) :: PKPTS
integer*4 mpierr
integer*4 i
logical flag_efile_exist, flag_efileu_exist, flag_efiled_exist
character*80 fname
if(PINPT%flag_tbfit_finish) return
if(.not. PINPT%flag_tbfit) return
! read info: target energy to be fitted with
if(PINPT%flag_tbfit) then
if(PINPT%flag_collinear .and. PWGHT%efile_type .eq. 'user') then
if(len_trim(PWGHT%efilenmu) .eq. 0 .or. len_trim(PWGHT%efilenmd) .eq. 0) then
write(message,'(A)')' !WARN! EFILE has not been set properly. Check EFILE or EFILEU, EFILED. Exit program.' ; write_msg
kill_job
endif
inquire(file=PWGHT%efilenmu,exist=flag_efileu_exist)
inquire(file=PWGHT%efilenmd,exist=flag_efiled_exist)
else
inquire(file=PWGHT%efilenmu,exist=flag_efileu_exist)
endif
endif
if(PINPT%flag_collinear .and. PINPT%flag_tbfit) then
if(flag_efileu_exist .and. flag_efiled_exist .and. PWGHT%efile_type .eq. 'user') then
flag_efile_exist = .true.
elseif(flag_efileu_exist .and. PWGHT%efile_type .eq. 'vasp' ) then
flag_efile_exist = .true.
else
flag_efile_exist = .false.
endif
elseif(.not. PINPT%flag_collinear .and. PINPT%flag_tbfit) then
if(flag_efileu_exist) then
flag_efile_exist = .true.
else
flag_efile_exist = .false.
endif
endif
if(PINPT%flag_tbfit .and. flag_efile_exist) then
if(PWGHT%flag_weight_default) then
allocate(PWGHT%WT(PGEOM%neig*PINPT%ispin, PKPTS%nkpoint))
PWGHT%WT(:,:)=0.00001d0 !initialize
if(PINPT%flag_fit_degeneracy) allocate(PWGHT%DEGENERACY_WT(PGEOM%neig*PINPT%ispin, PKPTS%nkpoint))
if(PINPT%flag_fit_degeneracy) PWGHT%DEGENERACY_WT(:,:)=0d0 !initialize
if(PINPT%flag_set_weight_from_file) then
if(PINPT%flag_wfile_parse) then
PWGHT%wfilenm = PINPT%wfilenm_parse
endif
call set_weight_from_file(PWGHT%WT, PGEOM%neig, PINPT%ispin, PKPTS%nkpoint, PWGHT%wfilenm)
endif
if(PWGHT%efile_type .eq. 'vasp') then
call read_energy_vasp(PINPT,PGEOM,PKPTS,EDFT,EDFT_all,PWGHT)
else
call read_energy(PINPT,PGEOM,PKPTS,EDFT,EDFT_all,PWGHT)
endif
write(message,*)' ' ; write_msg
write(message,*)'#-START SET WEIGHT FOR FITTING --------------------'; write_msg
if(PINPT%flag_fit_degeneracy) then
call get_degeneracy(EDFT, PGEOM%neig*PINPT%ispin, PKPTS%nkpoint, PINPT)
do i=1, PWGHT%ndegenw
PWGHT%max_len_strip_kp =max(len_trim(PWGHT%strip_kp_deg(i)), PWGHT%max_len_strip_kp)
PWGHT%max_len_strip_tb =max(len_trim(PWGHT%strip_tb_deg(i)), PWGHT%max_len_strip_tb)
PWGHT%max_len_strip_df =max(len_trim(PWGHT%strip_df_deg(i)), PWGHT%max_len_strip_df)
call set_weight(PINPT, PGEOM, PKPTS, PWGHT, EDFT, EDFT_all, PWGHT%strip_kp_deg(i), PWGHT%strip_tb_deg(i), &
PWGHT%strip_df_deg(i), PWGHT%strip_wt_deg(i), PWGHT%DEGENERACY_WT, 2)
enddo
endif
if(PINPT%flag_print_only_target ) then
fname = 'band_structure_DFT'//trim(PINPT%title(EDFT%mysystem))//'.dat'
if_main call print_energy_weight( PKPTS%kpoint, PKPTS%nkpoint, EDFT, PWGHT, PGEOM%neig, PINPT, &
fname,PINPT%flag_get_band_order)
write(message,'(A )')' !WARN! PRINT_ONLY_TARGET requested..' ; write_msg
write(message,'(A,A,A)')' !WARN! check ', trim(fname), ' Exit..' ; write_msg
kill_job
endif
elseif(.not. PWGHT%flag_weight_default) then
allocate(PWGHT%WT(PGEOM%neig*PINPT%ispin, PKPTS%nkpoint))
if(PINPT%flag_fit_degeneracy) allocate( PWGHT%DEGENERACY_WT(PGEOM%neig*PINPT%ispin, PKPTS%nkpoint) )
if(PWGHT%efile_type .eq. 'vasp') then
call read_energy_vasp(PINPT,PGEOM,PKPTS,EDFT,EDFT_all,PWGHT)
else
call read_energy(PINPT,PGEOM,PKPTS,EDFT,EDFT_all,PWGHT)
endif
write(message,*)' ' ; write_msg
write(message,*)'#-START SET WEIGHT FOR FITTING --------------------'; write_msg
PWGHT%WT(:,:)=0.00001d0 !initialize
if(PINPT%flag_fit_degeneracy) PWGHT%DEGENERACY_WT(:,:)=0d0 !initialize
if(.not. PINPT%flag_set_weight_from_file) then
do i=1, PWGHT%nweight
PWGHT%max_len_strip_kp =max(len_trim(PWGHT%strip_kp(i)), PWGHT%max_len_strip_kp)
PWGHT%max_len_strip_tb =max(len_trim(PWGHT%strip_tb(i)), PWGHT%max_len_strip_tb)
PWGHT%max_len_strip_df =max(len_trim(PWGHT%strip_df(i)), PWGHT%max_len_strip_df)
enddo
do i=1, PWGHT%nweight
call set_weight(PINPT, PGEOM, PKPTS, PWGHT, EDFT, EDFT_all, PWGHT%strip_kp(i), PWGHT%strip_tb(i), &
PWGHT%strip_df(i), PWGHT%strip_wt(i), PWGHT%WT, 1)
enddo
elseif(PINPT%flag_set_weight_from_file) then
if(PINPT%flag_wfile_parse) then
PWGHT%wfilenm = PINPT%wfilenm_parse
endif
call set_weight_from_file(PWGHT%WT, PGEOM%neig, PINPT%ispin, PKPTS%nkpoint, PWGHT%wfilenm)
endif
if(PINPT%flag_fit_degeneracy) then
! get degeneracy information for DFT target
call get_degeneracy(EDFT, PGEOM%neig*PINPT%ispin, PKPTS%nkpoint, PINPT)
do i=1, PWGHT%ndegenw
PWGHT%max_len_strip_kp =max(len_trim(PWGHT%strip_kp_deg(i)), PWGHT%max_len_strip_kp)
PWGHT%max_len_strip_tb =max(len_trim(PWGHT%strip_tb_deg(i)), PWGHT%max_len_strip_tb)
PWGHT%max_len_strip_df =max(len_trim(PWGHT%strip_df_deg(i)), PWGHT%max_len_strip_df)
enddo
do i=1, PWGHT%ndegenw
call set_weight(PINPT, PGEOM, PKPTS, PWGHT, EDFT, EDFT_all, PWGHT%strip_kp_deg(i), PWGHT%strip_tb_deg(i), &
PWGHT%strip_df_deg(i), PWGHT%strip_wt_deg(i), PWGHT%DEGENERACY_WT, 2)
enddo
endif
! normalize weight so that their sum to be 1
!PWGHT%WT = PWGHT%WT / sum(PWGHT%WT)
if(PINPT%flag_print_only_target ) then
fname = 'band_structure_DFT'//trim(PINPT%title(EDFT%mysystem))//'.dat'
if_main call print_energy_weight( PKPTS%kpoint, PKPTS%nkpoint, EDFT, PWGHT, PGEOM%neig, PINPT, &
fname,PINPT%flag_get_band_order)
write(message,'(A )')' !WARN! PRINT_ONLY_TARGET requested..' ; write_msg
write(message,'(A,A,A)')' !WARN! check ', trim(fname), ' Exit..' ; write_msg
kill_job
endif
endif
if(.not. PWGHT%flag_weight_orb) then
allocate(PWGHT%PENALTY_ORB(PGEOM%neig*PINPT%ispin,PGEOM%neig*PINPT%ispin, PKPTS%nkpoint))
PWGHT%PENALTY_ORB(:,:,:) = 0.d0 ! initialize & set default value (zeros for all)
elseif(PWGHT%flag_weight_orb) then
allocate(PWGHT%PENALTY_ORB(PGEOM%neig*PINPT%ispin,PGEOM%neig*PINPT%ispin, PKPTS%nkpoint))
PWGHT%PENALTY_ORB(:,:,:) = 0.d0 ! initialize
do i = 1, PWGHT%npenalty_orb
PWGHT%max_len_strip_kp =max(len_trim(PWGHT%strip_kp_orb(i)), PWGHT%max_len_strip_kp)
PWGHT%max_len_strip_tb =max(len_trim(PWGHT%strip_tb_orb(i)), PWGHT%max_len_strip_tb)
PWGHT%max_len_strip_ob =max(len_trim(PWGHT%strip_pen_orb(i)),PWGHT%max_len_strip_ob)
PWGHT%max_len_strip_st =max(len_trim(PWGHT%strip_site(i)), PWGHT%max_len_strip_st)
enddo
do i = 1, PWGHT%npenalty_orb
call set_penalty_orb(PINPT, PGEOM, PKPTS, PWGHT, PWGHT%strip_kp_orb(i), PWGHT%strip_tb_orb(i), &
PWGHT%strip_orb(i), PWGHT%strip_site(i), PWGHT%strip_pen_orb(i) )
enddo
endif
write(message,*)'#- END SET WEIGHT FOR FITTING --------------------' ; write_msg
write(message,*)' ' ; write_msg
elseif(PINPT%flag_tbfit .and. .not. flag_efile_exist ) then
write(message,'(A,A,A)')' !WARN! The target file ',trim(PWGHT%efilenmu),' does not exist or not specified!! '; write_msg
write(message,'(A )')' Please check EFILE tag again. Exit...' ; write_msg
kill_job
endif
return
endsubroutine
subroutine read_energy_vasp(PINPT, PGEOM,PKPTS,EDFT, EDFT_all, PWGHT) ! read EIGENVAL file
use parameters
use mpi_setup
use print_io
implicit none
character*132 fname, fnameu,fnamed
character*256 inputline
character*40 desc_str,dummy, dummy_(1000)
character(*), parameter :: func = 'read_energy'
integer*4, parameter :: max_eig = 1000000
integer*4 ie, ik, k, i_continue, line_tot
integer*4 size_range
integer*4 idummy, ispin, nkp_target, neig_target, nelect_vasp, ie_start
integer*4 iread_occ
integer*4, allocatable :: irange(:),irange_up(:), irange_dn(:), occ(:,:), occ_(:,:)
type(incar) :: PINPT
type(poscar) :: PGEOM
type(kpoints) :: PKPTS
type(energy) :: EDFT_, EDFT__
type(energy) :: EDFT_all
type(energy) :: EDFT
type(weight) :: PWGHT
iread_occ=1 ! default ; if LORBIT = 0 and the EIGENVAL does not contain occupation info,
! set iread_occ = 0 when energy surface extraction (-scf)
if(PINPT%flag_collinear) then
allocate( EDFT%E(PGEOM%neig*PINPT%ispin, PKPTS%nkpoint) )
if(PINPT%flag_fit_degeneracy) then
allocate( EDFT%D(3,PGEOM%neig*PINPT%ispin, PKPTS%nkpoint) )
endif
if(PGEOM%neig*2 .gt. max_eig) then
write(message,'(A)')' !WARNING! NEIG is exceeding predefined max_eig=1000000. Please increase "max_eig"' ; write_msg
write(message,'(A,A)')' !WARNING! Exit program... ',func ; write_msg
stop
endif
elseif(PINPT%flag_noncollinear) then
allocate( EDFT%E(PGEOM%neig*PINPT%ispin, PKPTS%nkpoint) )
if(PINPT%flag_fit_degeneracy) then
allocate( EDFT%D(3,PGEOM%neig*PINPT%ispin, PKPTS%nkpoint) )
endif
if(PGEOM%neig .gt. max_eig) then
write(message,'(A)')' !WARNING! NEIG is exceeding predefined max_eig=1000000. Please increase "max_eig"' ; write_msg
write(message,'(A,A)')' !WARNING! Exit program... ',func ; write_msg
stop
endif
else
allocate( EDFT%E(PGEOM%neig, PKPTS%nkpoint) )
if(PINPT%flag_fit_degeneracy) then
allocate( EDFT%D(3,PGEOM%neig, PKPTS%nkpoint) )
endif
if(PGEOM%neig .gt. max_eig) then
write(message,'(A)')' !WARNING! NEIG is exceeding predefined max_eig=1000000. Please increase "max_eig"' ; write_msg
write(message,'(A,A)')' !WARNING! Exit program... ',func ; write_msg
stop
endif
endif
fname = trim(PWGHT%efilenmu)
allocate( EDFT_%E(max_eig, PKPTS%nkpoint) )
allocate( EDFT__%E(max_eig, PKPTS%nkpoint) )
allocate( occ(max_eig, PKPTS%nkpoint) )
allocate( occ_(max_eig, PKPTS%nkpoint) )
open(pid_energy,file=trim(fname), status='old', iostat=i_continue)
write(message,*)' ' ; write_msg
write(message,*)'#- READING TARGET ENERGY FILE: ',trim(fname) ; write_msg
ie_start=PWGHT%itarget_e_start
line_tot = 0
! reading header for EIGENVAL
read(pid_energy,*) idummy, idummy, idummy, ispin
do k=1, 4
read(pid_energy, *) dummy
enddo
read(pid_energy,*) nelect_vasp, nkp_target, neig_target
! read energy for each k-point
do ik=1,nkp_target
read(pid_energy,*) dummy
do ie = 1, neig_target
if( iread_occ .eq. 1) then
if(ispin .eq. 2) then
read(pid_energy,*) dummy, EDFT__%E(ie, ik), EDFT__%E(ie+neig_target, ik), occ_(ie,ik), occ_(ie+neig_target,ik)
else
read(pid_energy,*) dummy, EDFT__%E(ie, ik), occ_(ie,ik)
endif
else
if(ispin .eq. 2) then
read(pid_energy,*) dummy, EDFT__%E(ie, ik), EDFT__%E(ie+neig_target, ik)
else
read(pid_energy,*) dummy, EDFT__%E(ie, ik)
endif
endif
enddo
enddo
EDFT__%E = EDFT__%E - PWGHT%efile_ef
if(PINPT%flag_collinear) then
if(PWGHT%fband .eq. -9999) PWGHT%fband = PGEOM%neig
elseif(PINPT%flag_noncollinear) then
if(PWGHT%fband .eq. -9999) PWGHT%fband = PGEOM%neig*2
else
if(PWGHT%fband .eq. -9999) PWGHT%fband = PGEOM%neig
endif
size_range = size( (/(k, k=PWGHT%iband,PWGHT%fband)/) )
! reset according to the initial target
if(ispin .eq. 2) then
if( (neig_target - PWGHT%itarget_e_start + 1) .ge. size_range ) then
EDFT_%E(1:neig_target-PWGHT%itarget_e_start+1,1:nkp_target) = EDFT__%E(PWGHT%itarget_e_start:neig_target,1:nkp_target)
EDFT_%E(1+neig_target-PWGHT%itarget_e_start+1: (neig_target-PWGHT%itarget_e_start+1)*2,1:nkp_target) = EDFT__%E(1+neig_target:neig_target*2,1:nkp_target)
occ(1:neig_target-PWGHT%itarget_e_start+1,1:nkp_target) = occ_(PWGHT%itarget_e_start:neig_target,1:nkp_target)
occ(1+neig_target-PWGHT%itarget_e_start+1: (neig_target-PWGHT%itarget_e_start+1)*2,1:nkp_target) = occ_(1+neig_target:neig_target*2,1:nkp_target)
else ! if neig_target - PWGHT%itarget_e_start + 1 is less than fband - iband + 1
idummy = size_range - (neig_target - PWGHT%itarget_e_start + 1)
EDFT_%E(1:neig_target-PWGHT%itarget_e_start+1,1:nkp_target) = EDFT__%E(PWGHT%itarget_e_start:neig_target,1:nkp_target)
EDFT_%E(neig_target-PWGHT%itarget_e_start+1+1:size_range,1:nkp_target) = 100d0 ! dummy value is added
EDFT_%E(size_range + 1: size_range + neig_target-PWGHT%itarget_e_start+1,1:nkp_target) = EDFT__%E(1+neig_target:neig_target*2,1:nkp_target)
EDFT_%E(size_range + neig_target-PWGHT%itarget_e_start+1+1:size_range*2,1:nkp_target) = 100d0
occ(1:neig_target-PWGHT%itarget_e_start+1,1:nkp_target) = occ_(PWGHT%itarget_e_start:neig_target,1:nkp_target)
occ(neig_target-PWGHT%itarget_e_start+1+1:size_range,1:nkp_target) = 100d0 ! dummy value is added
occ(size_range + 1: size_range + neig_target-PWGHT%itarget_e_start+1,1:nkp_target) = occ_(1+neig_target:neig_target*2,1:nkp_target)
occ(size_range + neig_target-PWGHT%itarget_e_start+1+1:size_range*2,1:nkp_target) = 100d0
endif
else
if( (neig_target - PWGHT%itarget_e_start + 1) .ge. size_range ) then
EDFT_%E(1:neig_target-PWGHT%itarget_e_start+1,1:nkp_target) = EDFT__%E(PWGHT%itarget_e_start:neig_target,1:nkp_target)
occ(1:neig_target-PWGHT%itarget_e_start+1,1:nkp_target) = occ_(PWGHT%itarget_e_start:neig_target,1:nkp_target)
else
EDFT_%E(1:neig_target-PWGHT%itarget_e_start+1,1:nkp_target) = EDFT__%E(PWGHT%itarget_e_start:neig_target,1:nkp_target)
EDFT_%E(neig_target-PWGHT%itarget_e_start+1+1:size_range,1:nkp_target) = 100d0
occ(1:neig_target-PWGHT%itarget_e_start+1,1:nkp_target) = occ_(PWGHT%itarget_e_start:neig_target,1:nkp_target)
occ(neig_target-PWGHT%itarget_e_start+1+1:size_range,1:nkp_target) = 100d0
endif
endif
if(neig_target - PWGHT%itarget_e_start + 1 .ge. size_range) then
PGEOM%neig_target=neig_target * ispin
write(message,'(A,I8)')' N_TARGET:',PGEOM%neig_target ; write_msg
else
PGEOM%neig_target=size_range * ispin
write(message,'(A,I8)')' N_TARGET: (adjusted)',PGEOM%neig_target ; write_msg
endif
allocate( EDFT_all%E(PGEOM%neig_target, nkp_target) )
if(PINPT%flag_collinear) then
allocate( irange_up(size_range) )
allocate( irange_dn(size_range) )
allocate( irange(size_range*PINPT%ispin) )
elseif(PINPT%flag_noncollinear) then
allocate( irange(size_range*PINPT%ispin) )
else
allocate( irange(size_range) )
endif
if(PINPT%flag_collinear) then
irange_up = (/(k, k=PWGHT%iband,PWGHT%fband)/)
irange_dn = irange_up + PGEOM%neig_target / 2
irange = (/irange_up, irange_dn/)
elseif(PINPT%flag_noncollinear) then
irange = (/(k, k=PWGHT%iband,PWGHT%fband)/)
else
irange = (/(k, k=PWGHT%iband,PWGHT%fband)/)
endif
if(PINPT%flag_collinear) then
if(PINPT%flag_scissor) then
EDFT_%E(PINPT%i_scissor:PGEOM%neig,1:PKPTS%nkpoint) = &
EDFT_%E(PINPT%i_scissor:PGEOM%neig,1:PKPTS%nkpoint) + PINPT%r_scissor
EDFT_%E(PGEOM%neig+PINPT%i_scissor:PGEOM%neig*2,1:PKPTS%nkpoint) = &
EDFT_%E(PGEOM%neig+PINPT%i_scissor:PGEOM%neig*2,1:PKPTS%nkpoint) + PINPT%r_scissor
endif
EDFT%E(1:PGEOM%neig*PINPT%ispin,1:PKPTS%nkpoint) = EDFT_%E(irange,1:PKPTS%nkpoint)
elseif(PINPT%flag_noncollinear) then
if(PINPT%flag_scissor) then
EDFT_%E(PINPT%i_scissor:PGEOM%neig*2,1:PKPTS%nkpoint) = &
EDFT_%E(PINPT%i_scissor:PGEOM%neig*2,1:PKPTS%nkpoint) + PINPT%r_scissor
endif
EDFT%E(1:PGEOM%neig*PINPT%ispin,1:PKPTS%nkpoint) = EDFT_%E(irange,1:PKPTS%nkpoint)
else
if(PINPT%flag_scissor) then
EDFT_%E(PINPT%i_scissor:PGEOM%neig,1:PKPTS%nkpoint) = &
EDFT_%E(PINPT%i_scissor:PGEOM%neig,1:PKPTS%nkpoint) + PINPT%r_scissor
endif
EDFT%E(1:PGEOM%neig,1:PKPTS%nkpoint) = EDFT_%E(irange,1:PKPTS%nkpoint)
endif
EDFT_all%E(1:PGEOM%neig_target,1:PKPTS%nkpoint) = EDFT_%E(1:PGEOM%neig_target,1:PKPTS%nkpoint)
write(message,*)'#- END READING TARGET ENERGY FILE --------------' ; write_msg
write(message,*)' ' ; write_msg
close(pid_energy)
deallocate(EDFT_%E)
if(allocated(EDFT__%E)) deallocate(EDFT__%E)
if(allocated(occ)) deallocate(occ)
if(allocated(occ_)) deallocate(occ_)
return
endsubroutine
subroutine read_energy(PINPT, PGEOM,PKPTS,EDFT, EDFT_all, PWGHT)
use parameters
use mpi_setup
use print_io
implicit none
type(incar) :: PINPT
type(poscar) :: PGEOM
type(kpoints) :: PKPTS
type(energy) :: EDFT_
type(energy) :: EDFT_all
type(energy) :: EDFT
type(weight) :: PWGHT
character*132 fnameu,fnamed
character*256 inputline
character*40 desc_str,dummy, dummy_(1000)
character(*), parameter:: func = 'read_energy'
integer*4, parameter :: max_eig = 100000
integer*4 ie, ik, k, i_continue
integer*4 size_range
integer*4 mpierr
integer*4 ik_, kreduce
integer*4, allocatable :: irange(:),irange_up(:), irange_dn(:)
logical flag_order, flag_fit_orbital
integer*4 vasp_orb_order(PINPT%lmmax)
real*8, allocatable :: TOT(:,:)
flag_order = PINPT%flag_get_band_order
flag_fit_orbital = PINPT%flag_fit_orbital ! This is only and should available with spd orbital resolved data file.
! One can obtain such data, for example via VASP PROCAR file.
! The target DFT file format should be as follows:
! 1st-column 2nd-column 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th
! k-path(k1) energy(e1) s p d s py pz px dxy dyz dz2 dxz dx2 tot
! k2 e1 s p d s py pz px dxy dyz dz2 dxz dx2 tot
! k3 e1 s p d s py pz px dxy dyz dz2 dxz dx2 tot
! k4 e1 s p d s py pz px dxy dyz dz2 dxz dx2 tot
! k5 e1 s p d s py pz px dxy dyz dz2 dxz dx2 tot
! k6 .....
! k7 .....
! k8 .....
! k1 e2 s p d s py pz px dxy dyz dz2 dxz dx2 tot
! k2 e2 s p d s py pz px dxy dyz dz2 dxz dx2 tot
! k3 e2 s p d s py pz px dxy dyz dz2 dxz dx2 tot
! k4 .....
! k5 .....
! k6 .....
! k1 e3 s p d s py pz px dxy dyz dz2 dxz dx2 tot
! k2 e3 s p d s py pz px dxy dyz dz2 dxz dx2 tot
! k3 e3 s p d s py pz px dxy dyz dz2 dxz dx2 tot
! k4 .....
! k5 .....
! k6 .....
! NOTE: Here, the data should/would be normalized so that the "tot" to be unity after reading the data.
! NOTE: kreduce with greater than 1 is only applicaple with PINPT%
if(PKPTS%kreduce .gt. 1) then
kreduce = PKPTS%kreduce
if( trim(PKPTS%kline_type) .eq. 'vasp' .or. trim(PKPTS%kline_type) .eq. 'VASP') then
write(message,'(A)')' !WARNING! KREDUCE should be 1 if you read VASP type of target energy file.' ; write_msg
write(message,'(A)')' Please read user manual with KREDUCE tag and KFILE tag.' ; write_msg
write(message,'(A)')' Exit program...' ; write_msg
kill_job
endif
else
kreduce = 1
endif
if(PINPT%flag_collinear) then
fnameu = trim(PWGHT%efilenmu)
fnamed = trim(PWGHT%efilenmd)
allocate( EDFT%E(PGEOM%neig*PINPT%ispin, PKPTS%nkpoint) )
if(flag_order) allocate( EDFT%E_ORD(PGEOM%neig*PINPT%ispin, PKPTS%nkpoint) )
if(PINPT%flag_fit_degeneracy) then
allocate( EDFT%D(3,PGEOM%neig*PINPT%ispin, PKPTS%nkpoint) )
endif
if(flag_fit_orbital) allocate( EDFT%ORB(PINPT%lmmax,PGEOM%neig*PINPT%ispin, PKPTS%nkpoint) )
if(PGEOM%neig*2 .gt. max_eig) then
write(message,'(A)')' !WARNING! NEIG is exceeding predefined max_eig=1000000. Please increase "max_eig"' ; write_msg
write(message,'(A,A)')' !WARNING! Exit program... ',func ; write_msg
stop
endif
elseif(PINPT%flag_noncollinear) then
fnameu = trim(PWGHT%efilenmu)
allocate( EDFT%E(PGEOM%neig*PINPT%ispin, PKPTS%nkpoint) )
if(flag_fit_orbital) allocate( EDFT%ORB(PINPT%lmmax,PGEOM%neig*PINPT%ispin, PKPTS%nkpoint) )
if(flag_order) allocate( EDFT%E_ORD(PGEOM%neig*PINPT%ispin, PKPTS%nkpoint) )
if(PINPT%flag_fit_degeneracy) then
allocate( EDFT%D(3,PGEOM%neig*PINPT%ispin, PKPTS%nkpoint) )
endif
if(PGEOM%neig .gt. max_eig) then
write(message,'(A)')' !WARNING! NEIG is exceeding predefined max_eig=1000000. Please increase "max_eig"' ; write_msg
write(message,'(A,A)')' !WARNING! Exit program... ',func ; write_msg
stop
endif
else
fnameu = trim(PWGHT%efilenmu)
allocate( EDFT%E(PGEOM%neig, PKPTS%nkpoint) )
if(flag_fit_orbital) allocate( EDFT%ORB(PINPT%lmmax,PGEOM%neig, PKPTS%nkpoint) )
if(flag_order) allocate( EDFT%E_ORD(PGEOM%neig, PKPTS%nkpoint) )
if(PINPT%flag_fit_degeneracy) then
allocate( EDFT%D(3,PGEOM%neig, PKPTS%nkpoint) )
endif
if(PGEOM%neig .gt. max_eig) then
write(message,'(A)')' !WARNING! NEIG is exceeding predefined max_eig=1000000. Please increase "max_eig"' ; write_msg
write(message,'(A,A)')' !WARNING! Exit program... ',func ; write_msg
stop
endif
endif
allocate( EDFT_%E(max_eig, PKPTS%nkpoint) )
if(flag_order) allocate( EDFT_%E_ORD(max_eig, PKPTS%nkpoint) )
if(flag_fit_orbital) then
allocate( EDFT_%ORB(PINPT%lmmax,max_eig,PKPTS%nkpoint))
allocate( TOT( max_eig,PKPTS%nkpoint)) ! temporal, for the normalization purpose
TOT = 0d0
if(PINPT%lmmax .eq. 9) then
vasp_orb_order=(/1,3,4,2,7,9,5,8,6/)
elseif(PINPT%lmmax .eq. 3) then
vasp_orb_order=(/1,2,3/)
endif
endif
if(PINPT%ispin .eq. 2)then
open(pid_energy, file=trim(fnameu), status='old', iostat=i_continue)
open(pid_energy+1,file=trim(fnamed), status='old', iostat=i_continue)
else
open(pid_energy,file=trim(fnameu), status='old', iostat=i_continue)
endif
!# ORDERED ENERGY => E_ORD
!# PRISITINE ENERGY => E
write(message,*)' ' ; write_msg
if(PINPT%flag_collinear) then
write(message,*)'#- READING TARGET ENERGY FILE: ',trim(fnameu), ' and ', trim(fnamed) ; write_msg
else
write(message,*)'#- READING TARGET ENERGY FILE: ',trim(fnameu) ; write_msg
endif
ie=0
!loop1 for spin up
loop1:do
ik=0; ik_ = 0
ie=ie + 1
do while (ik .lt. PKPTS%nkpoint)
read(pid_energy,'(A)',iostat=i_continue) inputline
if(i_continue<0) exit loop1 ! end of file reached
if(i_continue>0) then
write(message,*)'Unknown error reading file:',trim(fnameu),func ; write_msg
stop
endif
! check comment and emtpy line
read(inputline,*,iostat=i_continue) desc_str
if (desc_str(1:1).eq.'#') cycle ! skip comment
if (i_continue .ne. 0) cycle ! skip empty
ik_ = ik_ + 1
if( mod(ik_ - 1, kreduce) .eq. 0) then
ik = ik + 1
if(PWGHT%read_energy_column_index .eq. 2) then
if(.not. flag_order) then
if(flag_fit_orbital) then
if(PINPT%lmmax .eq.9) then
read(inputline,*,iostat=i_continue) dummy, EDFT_%E(ie, ik), dummy,dummy,dummy,EDFT_%ORB(vasp_orb_order,ie,ik)
elseif(PINPT%lmmax .eq. 3) then
read(inputline,*,iostat=i_continue) dummy, EDFT_%E(ie, ik), EDFT_%ORB(vasp_orb_order,ie,ik)
endif
TOT(ie,ik) = sum(EDFT_%ORB(vasp_orb_order,ie,ik))! NOTE: not work for f-electron case
else
read(inputline,*,iostat=i_continue) dummy, EDFT_%E(ie, ik)
endif
elseif(flag_order) then
! this is for read re-ordered target band and save it to E_ORD,
! hence, be sure that file should contain this information too!
read(inputline,*,iostat=i_continue) dummy, EDFT_%E(ie, ik), EDFT_%E_ORD(ie, ik)
endif
elseif(PWGHT%read_energy_column_index .eq. 3) then
if(.not. flag_order) then
read(inputline,*,iostat=i_continue) dummy, dummy, EDFT_%E(ie, ik)
elseif(flag_order) then
read(inputline,*,iostat=i_continue) dummy, dummy, EDFT_%E(ie, ik), EDFT_%E_ORD(ie, ik)
endif
elseif(PWGHT%read_energy_column_index .eq. 4) then
read(inputline,*,iostat=i_continue) dummy, dummy, dummy, EDFT_%E(ie, ik)
elseif(PWGHT%read_energy_column_index .eq. 5) then
read(inputline,*,iostat=i_continue) dummy, dummy, dummy, dummy, EDFT_%E(ie, ik)
elseif(PWGHT%read_energy_column_index .eq. 6) then
read(inputline,*,iostat=i_continue) dummy, dummy, dummy, dummy, dummy, EDFT_%E(ie, ik)
elseif(PWGHT%read_energy_column_index .eq. 7) then
read(inputline,*,iostat=i_continue) dummy, dummy, dummy, dummy, dummy, dummy, EDFT_%E(ie, ik)
elseif(PWGHT%read_energy_column_index .eq. 8) then
read(inputline,*,iostat=i_continue) dummy, dummy, dummy, dummy, dummy, dummy, dummy, EDFT_%E(ie, ik)
elseif(PWGHT%read_energy_column_index .ge. 9) then
read(inputline,*,iostat=i_continue) dummy_(1:PWGHT%read_energy_column_index-1), EDFT_%E(ie, ik)
endif
else
read(inputline,*,iostat=i_continue) dummy
endif
enddo
if(ik .ne. PKPTS%nkpoint) then
write(message,'(A,A )')' !WARN! error in reading ',trim(fnameu) ; write_msg
write(message,'(A,I8)')' Exit.. NKPTS !=',ik ; write_msg
stop
endif
enddo loop1
if(PINPT%flag_collinear) then
ie = ie - 1
!loop2 for spin dn
loop2: do
ik=0
ie=ie + 1
do while (ik .lt. PKPTS%nkpoint)
read(pid_energy+1,'(A)',iostat=i_continue) inputline
if(i_continue<0) exit loop2 ! end of file reached
if(i_continue>0) then
write(message,*)'Unknown error reading file:',trim(fnamed),func ; write_msg
stop
endif
! check comment and emtpy line
read(inputline,*,iostat=i_continue) desc_str
if (desc_str(1:1).eq.'#') cycle ! skip comment
if (i_continue .ne. 0) cycle ! skip empty
ik = ik + 1
if(PWGHT%read_energy_column_index_dn .eq. 2) then
if(.not.flag_order) then
if(flag_fit_orbital) then
if(PINPT%lmmax .eq. 9) then
read(inputline,*,iostat=i_continue) dummy, EDFT_%E(ie, ik), dummy,dummy,dummy,EDFT_%ORB(vasp_orb_order,ie,ik)
elseif(PINPT%lmmax .eq. 3) then
read(inputline,*,iostat=i_continue) dummy, EDFT_%E(ie, ik), EDFT_%ORB(vasp_orb_order,ie,ik) ! NOTE: not work for f-electron case
endif
TOT(ie,ik) = sum(EDFT_%ORB(vasp_orb_order,ie,ik))
else
read(inputline,*,iostat=i_continue) dummy, EDFT_%E(ie, ik)
endif
elseif(flag_order) then
read(inputline,*,iostat=i_continue) dummy, EDFT_%E(ie, ik), EDFT_%E_ORD(ie, ik)
endif
elseif(PWGHT%read_energy_column_index_dn .eq. 3) then
if(.not. flag_order)then
read(inputline,*,iostat=i_continue) dummy, dummy, EDFT_%E(ie, ik)
elseif(flag_order) then
read(inputline,*,iostat=i_continue) dummy, dummy, EDFT_%E(ie, ik), EDFT_%E_ORD(ie, ik)
endif
endif
enddo
if(ik .ne. PKPTS%nkpoint) then
write(message,'(A,A )')' !WARN! error in reading ',trim(fnamed) ; write_msg
write(message,'(A,I8)')' Exit.. NKPTS !=',ik ; write_msg
stop
endif
enddo loop2
endif ! flag_collinear
PGEOM%neig_target=ie - 1
write(message,'(A,I8)')' N_TARGET:',PGEOM%neig_target ; write_msg
allocate( EDFT_all%E(PGEOM%neig_target, PKPTS%nkpoint) )
if(flag_fit_orbital) allocate( EDFT_all%ORB(PINPT%lmmax, PGEOM%neig_target, PKPTS%nkpoint))
if(flag_order) allocate( EDFT_all%E_ORD(PGEOM%neig_target, PKPTS%nkpoint) )
if(PINPT%flag_collinear) then
if(PWGHT%fband .eq. -9999) PWGHT%fband = PGEOM%neig
elseif(PINPT%flag_noncollinear) then
if(PWGHT%fband .eq. -9999) PWGHT%fband = PGEOM%neig*2 !(multiplying ispinor)
else
if(PWGHT%fband .eq. -9999) PWGHT%fband = PGEOM%neig
endif
size_range = size( (/(k, k=PWGHT%iband,PWGHT%fband)/) )
if(PINPT%flag_collinear) then
allocate( irange_up(size_range) )
allocate( irange_dn(size_range) )
allocate( irange(size_range*PINPT%ispin) )
elseif(PINPT%flag_noncollinear) then
allocate( irange(size_range*PINPT%ispin) )
else
allocate( irange(size_range) )
endif
if(PINPT%flag_collinear) then
irange_up = (/(k, k=PWGHT%iband,PWGHT%fband)/)
irange_dn = irange_up + PGEOM%neig_target / 2
irange = (/irange_up, irange_dn/)
elseif(PINPT%flag_noncollinear) then
irange = (/(k, k=PWGHT%iband,PWGHT%fband)/)
else
irange = (/(k, k=PWGHT%iband,PWGHT%fband)/)
endif
EDFT_%E = EDFT_%E - PWGHT%efile_ef
if(flag_order) EDFT_%E_ORD = EDFT_%E_ORD - PWGHT%efile_ef
if(PINPT%flag_collinear) then
if(PINPT%flag_scissor) then ! setup scissor
EDFT_%E(PINPT%i_scissor:PGEOM%neig,1:PKPTS%nkpoint) = &
EDFT_%E(PINPT%i_scissor:PGEOM%neig,1:PKPTS%nkpoint) + PINPT%r_scissor
EDFT_%E(PGEOM%neig+PINPT%i_scissor:PGEOM%neig*2,1:PKPTS%nkpoint) = &
EDFT_%E(PGEOM%neig+PINPT%i_scissor:PGEOM%neig*2,1:PKPTS%nkpoint) + PINPT%r_scissor
if(flag_order) then
EDFT_%E_ORD(PINPT%i_scissor:PGEOM%neig,1:PKPTS%nkpoint) = &
EDFT_%E_ORD(PINPT%i_scissor:PGEOM%neig,1:PKPTS%nkpoint) + PINPT%r_scissor
EDFT_%E_ORD(PGEOM%neig+PINPT%i_scissor:PGEOM%neig*2,1:PKPTS%nkpoint) = &
EDFT_%E_ORD(PGEOM%neig+PINPT%i_scissor:PGEOM%neig*2,1:PKPTS%nkpoint) + PINPT%r_scissor
endif
endif
! store target data to EDFT%E
EDFT%E(1:PGEOM%neig*PINPT%ispin,1:PKPTS%nkpoint) = EDFT_%E(irange,1:PKPTS%nkpoint)
if(flag_fit_orbital) EDFT%ORB(:,1:PGEOM%neig*PINPT%ispin,1:PKPTS%nkpoint) = EDFT_%ORB(:,irange,1:PKPTS%nkpoint)
if(flag_order) EDFT%E_ORD(1:PGEOM%neig*PINPT%ispin,1:PKPTS%nkpoint) = EDFT_%E_ORD(irange,1:PKPTS%nkpoint)
elseif(PINPT%flag_noncollinear) then
if(PINPT%flag_scissor) then ! setup scissor
EDFT_%E(PINPT%i_scissor:PGEOM%neig*2,1:PKPTS%nkpoint) = &
EDFT_%E(PINPT%i_scissor:PGEOM%neig*2,1:PKPTS%nkpoint) + PINPT%r_scissor
if(flag_order) then
EDFT_%E_ORD(PINPT%i_scissor:PGEOM%neig*2,1:PKPTS%nkpoint) = &
EDFT_%E_ORD(PINPT%i_scissor:PGEOM%neig*2,1:PKPTS%nkpoint) + PINPT%r_scissor
endif
endif
! store target data to EDFT%E
EDFT%E(1:PGEOM%neig*PINPT%ispin,1:PKPTS%nkpoint) = EDFT_%E(irange,1:PKPTS%nkpoint)
if(flag_order) EDFT%E_ORD(1:PGEOM%neig*PINPT%ispin,1:PKPTS%nkpoint) = EDFT_%E_ORD(irange,1:PKPTS%nkpoint)
if(flag_fit_orbital) EDFT%ORB(:,1:PGEOM%neig*PINPT%ispin,1:PKPTS%nkpoint) = EDFT_%ORB(:,irange,1:PKPTS%nkpoint)
else ! if nonmagnetic
if(PINPT%flag_scissor) then ! setup scissor
EDFT_%E(PINPT%i_scissor:PGEOM%neig,1:PKPTS%nkpoint) = &
EDFT_%E(PINPT%i_scissor:PGEOM%neig,1:PKPTS%nkpoint) + PINPT%r_scissor
if(flag_order) then
EDFT_%E_ORD(PINPT%i_scissor:PGEOM%neig,1:PKPTS%nkpoint) = &
EDFT_%E_ORD(PINPT%i_scissor:PGEOM%neig,1:PKPTS%nkpoint) + PINPT%r_scissor
endif
endif
! store target data to EDFT%E
EDFT%E(1:PGEOM%neig,1:PKPTS%nkpoint) = EDFT_%E(irange,1:PKPTS%nkpoint)
if(flag_order) EDFT%E_ORD(1:PGEOM%neig,1:PKPTS%nkpoint) = EDFT_%E_ORD(irange,1:PKPTS%nkpoint)
if(flag_fit_orbital) then
do ik = 1, PKPTS%nkpoint
do ie = 1, PGEOM%neig
EDFT%ORB(:,ie,ik) = EDFT_%ORB(:,irange(ie),ik)/TOT(irange(ie),ik)
enddo
enddo
endif
endif
EDFT_all%E(1:PGEOM%neig_target,1:PKPTS%nkpoint) = EDFT_%E(1:PGEOM%neig_target,1:PKPTS%nkpoint)
if(flag_fit_orbital) EDFT_all%ORB(:,1:PGEOM%neig_target,1:PKPTS%nkpoint) = EDFT_%ORB(:,1:PGEOM%neig_target,1:PKPTS%nkpoint)
if(flag_order) EDFT_all%E_ORD(1:PGEOM%neig_target,1:PKPTS%nkpoint) = EDFT_%E_ORD(1:PGEOM%neig_target,1:PKPTS%nkpoint)
write(message,*)'#- END READING TARGET ENERGY FILE --------------' ; write_msg
write(message,*)' ' ; write_msg
close(pid_energy)
if(PINPT%flag_collinear) close(pid_energy+1)
deallocate(EDFT_%E)
if(flag_order) deallocate(EDFT_%E_ORD)
return
endsubroutine
subroutine read_energy_tbfit_V(PRPLT, PINPT, E, V, ne_found, ispin, nspin, nbasis, nband, nk, kmode, flag_vector, flag_wf, flag_formatted, flag_exit)
! read band_structure_TBA.xxx generated by TBFIT.
use parameters, only : pid_energy, t1, t0, replot, incar
use time
use print_io
use mpi_setup
implicit none
type(incar) :: PINPT
type(replot) :: PRPLT
integer*4 ispin, nspin, nbasis, nband, nk
integer*4 ispinor
integer*4 pid, i_continue
integer*4 ie,ik,is
integer*4 ii, fi, im, fm
integer*4 linecount
integer*4 ne_found(nspin, nk)
real*8 E(nband*nspin,nk)
complex*16 V(nbasis*ispin,nband*nspin,nk)
real*8 kpoint
character*256 inputline
character*40 desc_str
character*4 kmode
external nitems
integer*4 nitems, idummy
logical flag_go, flag_vector
logical flag_wf, flag_formatted
character*80 fnameu, fnamed
character*11 form_
logical flag_exit
call time_check(t1,t0,'init')
flag_exit = .false.
if(flag_formatted) form_ = 'formatted'
if(.not.flag_formatted) form_ = 'unformatted'
pid = pid_energy
linecount = 0
ie= 0
flag_go = .false.
if(ispin .eq. 2 .and. nspin .eq. 1) then
ispinor = 2
else
ispinor = 1
endif
if(nspin .eq. 2) then ! collinear
if(flag_formatted) then
fnameu = 'band_structure_TBA'//trim(PINPT%title(PRPLT%mysystem))//'.up.dat'
fnamed = 'band_structure_TBA'//trim(PINPT%title(PRPLT%mysystem))//'.dn.dat'
elseif(.not. flag_formatted) then
fnameu = 'band_structure_TBA'//trim(PINPT%title(PRPLT%mysystem))//'.up.bin'
fnamed = 'band_structure_TBA'//trim(PINPT%title(PRPLT%mysystem))//'.dn.bin'
endif
elseif(nspin .eq. 1) then ! nm or non-collinear
if(flag_formatted) then
fnameu = 'band_structure_TBA'//trim(PINPT%title(PRPLT%mysystem))//'.dat'
elseif(.not. flag_formatted) then
fnameu = 'band_structure_TBA'//trim(PINPT%title(PRPLT%mysystem))//'.bin'
endif
endif
do is = 1, nspin
if(is .eq. 1) then
if(flag_formatted) open(pid,file = trim(fnameu), status='old', iostat=i_continue)
if(.not. flag_formatted) open(pid,file = trim(fnameu), form='unformatted',status='old', iostat=i_continue)
if(i_continue .ne. 0) then
write(message,'(A)')' !!! ERROR IN READING (up) ', trim(fnameu) ; write_msg
write(message,'(A)')' EXIT PROGRAM : read_energy_tbfit_V ' ; write_msg
flag_exit = .true.
endif
elseif(is .eq. 2) then
if(flag_formatted) open(pid,file = trim(fnamed), status='old', iostat=i_continue)
if(.not. flag_formatted) open(pid,file = trim(fnamed), form='unformatted',status='old', iostat=i_continue)
if(i_continue .ne. 0) then
write(message,'(A)')' !!! ERROR IN READING (dn) ', trim(fnamed) ; write_msg
write(message,'(A)')' EXIT PROGRAM : read_energy_tbfit_V ' ; write_msg
flag_exit = .true.
endif
endif
if(.not. flag_exit) then
ii = 1+nband*(is-1) ; fi = nband+nband*(is-1)
im = 1+nbasis*(is-1) ; fm = nbasis*ispinor +nbasis*(is-1)
if(flag_formatted) then
call load_band_structure_V(E(ii:fi,:), V(im:fm,ii:fi,:), ne_found(is,:), &
ispinor, ispin, nspin, nband, nbasis, nk, kmode, pid, flag_vector)
! ispinor, ispin, nspin, nband, nbasis, nk, kmode, pid, flag_vector, flag_exit)
elseif(.not. flag_formatted) then
call load_band_structure_V_bin(E(ii:fi,:), V(im:fm,ii:fi,:), ne_found(is,:), &
ispinor, ispin, nspin, nband, nbasis, nk, kmode, pid, flag_vector, flag_exit)
endif
close(pid)
endif
enddo
call time_check(t1,t0,'end')
if(nspin .eq. 1) then
write(message,'(3A,F12.6)')" TIME for LOADING (s) ",trim(fnameu)," : ", t1 ; write_msg
write(message,'(A)')'' ; write_msg
elseif(nspin .eq. 2) then
write(message,'(5A,F12.6)')" TIME for LOADING (s) ",trim(fnameu)," and ", trim(fnamed), " : " , t1 ; write_msg
write(message,'(A)')'' ; write_msg
endif
return
endsubroutine
subroutine read_energy_tbfit_V2(PRPLT, PINPT, E, V2, ne_found, ispin, nspin, nbasis, nband, nk, kmode, flag_vector, flag_wf, flag_formatted, flag_exit)
!read band_structure_TBA.xxx with c_mode = 'rh'
use parameters, only : pid_energy, t1, t0, replot, incar
use time
use mpi_setup
use print_io
implicit none
type(incar) :: PINPT
type(replot) :: PRPLT
integer*4 ispin, nspin, nbasis, nband, nk
integer*4 ispinor
integer*4 pid, i_continue
integer*4 ie,ik,is
integer*4 ii, fi, im, fm
integer*4 linecount
integer*4 ne_found(nspin, nk)
real*8 E(nband*nspin,nk)
real*8 V2(nbasis,nband*nspin,nk)
real*8 kpoint
character*256 inputline
character*40 desc_str
character*4 kmode
external nitems
integer*4 nitems, idummy
logical flag_go, flag_vector
logical flag_wf
logical flag_formatted
logical flag_exit
character*80 fnameu, fnamed
character*11 form_
call time_check(t1,t0,'init')
flag_exit = .false.
pid = pid_energy
linecount = 0
ie= 0
flag_go = .false.
if(ispin .eq. 2 .and. nspin .eq. 1) then
ispinor = 2
else
ispinor = 1
endif
if(nspin .eq. 2) then ! collinear
if(flag_formatted) then
fnameu = 'band_structure_TBA'//trim(PINPT%title(PRPLT%mysystem))//'.up.dat'
fnamed = 'band_structure_TBA'//trim(PINPT%title(PRPLT%mysystem))//'.dn.dat'
elseif(.not. flag_formatted) then
fnameu = 'band_structure_TBA'//trim(PINPT%title(PRPLT%mysystem))//'.up.bin'
fnamed = 'band_structure_TBA'//trim(PINPT%title(PRPLT%mysystem))//'.dn.bin'
endif
elseif(nspin .eq. 1) then ! nm or non-collinear
if(flag_formatted) then
fnameu = 'band_structure_TBA'//trim(PINPT%title(PRPLT%mysystem))//'.dat'
elseif(.not. flag_formatted) then
fnameu = 'band_structure_TBA'//trim(PINPT%title(PRPLT%mysystem))//'.bin'
endif
endif
do is = 1, nspin
if(is .eq. 1) then
if(flag_formatted) open(pid,file = trim(fnameu), status='old', iostat=i_continue)
if(.not. flag_formatted) open(pid,file = trim(fnameu), form='unformatted',status='old', iostat=i_continue)
if(i_continue .ne. 0) then
write(message,'(A)')' !!! ERROR IN READING (up) ', trim(fnameu) ; write_msg
write(message,'(A)')' EXIT PROGRAM : read_energy_tbfit_V2 ' ; write_msg
flag_exit = .true.
endif
elseif(is .eq. 2) then
if(flag_formatted) open(pid,file = trim(fnamed), status='old', iostat=i_continue)
if(.not. flag_formatted) open(pid,file = trim(fnamed), form='unformatted',status='old', iostat=i_continue)
if(i_continue .ne. 0) then
write(message,'(A)')' !!! ERROR IN READING (dn) ', trim(fnamed) ; write_msg
write(message,'(A)')' EXIT PROGRAM : read_energy_tbfit_V2 ' ; write_msg
flag_exit = .true.
endif
endif
if(.not. flag_exit) then
ii = 1+nband*(is-1) ; fi = nband+nband*(is-1)
im = 1 ; fm = nbasis
if(flag_formatted) then
call load_band_structure_V2(E(ii:fi,:), V2(im:fm,ii:fi,:), ne_found(is,:), ispin, nspin, nband, nbasis, nk, kmode, pid, &
flag_vector)
elseif(.not. flag_formatted) then
call load_band_structure_V2_bin(E(ii:fi,:), V2(im:fm,ii:fi,:), ne_found(is,:), &
ispin, nspin, nband, nbasis, nk, kmode, pid, flag_vector, flag_exit)
endif
close(pid)
endif
enddo
call time_check(t1,t0,'end')
if(nspin .eq. 1) then
write(message,'(3A,F12.6)')" TIME for LOADING (s) ",trim(fnameu)," : ", t1 ; write_msg
write(message,'(A)')'' ; write_msg
elseif(nspin .eq. 2) then
write(message,'(5A,F12.6)')" TIME for LOADING (s) ",trim(fnameu)," and ", trim(fnamed), " : " , t1 ; write_msg
write(message,'(A)')'' ; write_msg
endif
return
endsubroutine
subroutine read_energy_tbfit(PRPLT, PINPT, E, ne_found, ispin, nspin, nbasis, nband, nk, kmode, flag_formatted, flag_exit)
!read band_structure_TBA.xxx with c_mode = 'no'
use parameters, only : pid_energy, t1, t0, replot, incar
use time
use mpi_setup
use print_io
implicit none
type(incar) :: PINPT
type(replot) :: PRPLT
integer*4 ispin, nspin, nbasis, nband, nk
integer*4 ispinor
integer*4 pid, i_continue
integer*4 ie,ik,is
integer*4 ii, fi, im, fm
integer*4 linecount
integer*4 ne_found(nspin, nk)
real*8 E(nband*nspin,nk)
real*8 kpoint
character*256 inputline
character*40 desc_str
character*4 kmode