-
Notifications
You must be signed in to change notification settings - Fork 15
/
print_energy.f90
1732 lines (1608 loc) · 84.3 KB
/
print_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 print_band_structure(PKPTS, ETBA, EDFT, PGEOM, PINPT, PPRAM, PWGHT)
use parameters, only : kpoints, energy, poscar, incar, params, weight
use mpi_setup
use print_io
implicit none
type(incar) :: PINPT
type(params) :: PPRAM
type(energy) :: ETBA, EDFT
type(poscar) :: PGEOM
type(weight) :: PWGHT
type(kpoints) :: PKPTS
integer*4 mpierr
! if(.not. PINPT%flag_distribute_nkp) then
if( myid .ne. 0) return
! endif
if(PINPT%flag_print_energy_diff ) then
if(PINPT%flag_get_band) call print_energy(PKPTS, ETBA%E, EDFT%E, ETBA%V, ETBA%SV, PGEOM%neig, PGEOM%init_erange, PGEOM%nband, &
PINPT, PWGHT, PPRAM%flag_use_overlap, .TRUE.,'')
elseif(.not. PINPT%flag_print_energy_diff ) then
if(PINPT%flag_get_band) then
! if(.not. PINPT%flag_distribute_nkp) then
call print_energy(PKPTS, ETBA%E, ETBA%E, ETBA%V, ETBA%SV, PGEOM%neig, PGEOM%init_erange, PGEOM%nband, &
PINPT, PWGHT, PPRAM%flag_use_overlap, .TRUE., '')
if(PINPT%flag_get_band_order) then
call print_energy(PKPTS, ETBA%E_ORD, ETBA%E_ORD, ETBA%V_ORD, ETBA%SV_ORD, PGEOM%neig, PGEOM%init_erange, PGEOM%nband, &
PINPT, PWGHT, PPRAM%flag_use_overlap, .TRUE., '_ordered')
endif
! elseif(PINPT%flag_distribute_nkp) then
! !call print_energy_distributed(ETBA%E, ETBA%E, ETBA%V, ETBA%SV, PGEOM%neig, PGEOM%init_erange, PGEOM%nband, &
! ! PINPT, PWGHT, PPRAM%flag_use_overlap, .TRUE., '')
! write(message,'(A)')' !WARN! The current version does not support PINPT%flag_distribute_nkp (LDISTRK) = .TRUE. ' ; write_msg
! write(message,'(A)')' for band structure storing. The subroutine for this "print_energy_distributed" ' ; write_msg
! write(message,'(A)')' will be implemented in the near future.' ; write_msg
! write(message,'(A)')' Exit program... 19. Mar. 2021. HJ Kim' ; write_msg
! kill_job
! endif
endif
endif
if(PINPT%flag_print_proj ) then
call print_energy_proj(PKPTS, ETBA%E, ETBA%V, ETBA%SV, PGEOM, PINPT, PPRAM)
endif
return
endsubroutine
subroutine print_energy_ensurf (kpoint, nkpoint,ie, nspin, E, V, SV, PGEOM, PINPT, fname_header, kunit, flag_use_overlap)
use parameters, only : pid_energy, incar, poscar, zi
implicit none
type(incar) :: PINPT
type(poscar) :: PGEOM
integer*4 is, ie, ik, im
integer*4 nkpoint
integer*4 nspin, nbasis
real*8 kpoint(3,nkpoint)
logical flag_print_orbital
real*8 E(nspin,nkpoint)
complex*16 V(PGEOM%neig*PINPT%ispin,nspin,nkpoint)
complex*16 SV(PGEOM%neig*PINPT%ispin,nspin,nkpoint)
complex*16 c_up, c_dn
complex*16 sc_up, sc_dn
character(*) fname_header
character*80 fname
character*1 kunit
character*6 kunit_
character*8 sigma
character*28 kmode
logical flag_use_overlap
! NOTE: this routine write eigenvalues for certain energy level "ie" (and their opposite spin state if collinear case)
! hence, variable size of E is (nspin,nkpoint)
sigma='sigma_0 '
nbasis = PGEOM%neig
call get_kunit(kunit, kunit_)
call get_plotmode(.false., .true., kunit_, kmode)
spin:do is = 1, nspin
call get_fname(fname_header, fname, is, PINPT%flag_collinear, PINPT%flag_noncollinear)
open(pid_energy, file=trim(fname), status = 'unknown')
write(pid_energy, '(2A,I8,A)', ADVANCE = 'yes') kmode,' energy(eV) :', ie,' -th eigen'
if(.not. PINPT%flag_print_orbital) then
write(pid_energy,'(A)',ADVANCE='yes')''
elseif( PINPT%flag_print_orbital) then
if(PINPT%axis_print_mag .eq. 'mz') sigma='sigma_z '
if(PINPT%axis_print_mag .eq. 'mx') sigma='sigma_x '
if(PINPT%axis_print_mag .eq. 'my') sigma='sigma_y '
write(pid_energy, '(2A)',ADVANCE='YES') '# wavefunction coeff.: <ci|sigma|ci>,sigma= ',sigma
write(pid_energy, '( A)',ADVANCE='NO') '# k-dist (ci: wfn coeff for i-th orb) E(eV), i='
mm: do im=1,nbasis
write(pid_energy, '(I9)',ADVANCE='NO')im
if(im .ge. 30 .and. im .lt. nbasis) then
write(pid_energy, '(A)',ADVANCE='NO')' ... '
exit mm
endif
enddo mm
write(pid_energy,'(A)',ADVANCE='yes')''
endif
kp:do ik = 1, nkpoint
write(pid_energy,'(1x,3F12.6,F14.6,1x)',ADVANCE='NO')kpoint(:,ik), E(1+(is-1),ik)
if(PINPT%flag_print_orbital) then
basis:do im=1,nbasis-1
if(PINPT%ispinor .eq. 2) then
c_up = V(im,is,ik); c_dn = V(im + nbasis,is,ik)
if(flag_use_overlap) then
sc_up = SV(im,is,ik); sc_dn = SV(im + nbasis,is,ik)
else
sc_up = V(im,is,ik); sc_dn = V(im + nbasis,is,ik)
endif
if (PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'mz') then
write(pid_energy,'(*(F9.4))',ADVANCE='NO') real( conjg(c_up)*sc_up - conjg(c_dn)*sc_dn) ! up - dn : mz
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'mx') then
write(pid_energy,'(*(F9.4))',ADVANCE='NO') real( conjg(c_dn)*sc_up + conjg(c_up)*sc_dn) ! up*dn + dn*up : mx
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'my') then
write(pid_energy,'(*(F9.4))',ADVANCE='NO') real((conjg(c_dn)*sc_up - conjg(c_up)*sc_dn)*zi) ! (up*dn - dn*up)*i : my
else
write(pid_energy,'(*(F9.4))',ADVANCE='NO') real( conjg(c_up)*sc_up + conjg(c_dn)*sc_dn) ! up + dn : total
endif
elseif(PINPT%ispinor .eq. 1) then
c_up = V(im+PGEOM%neig*(is-1),is,ik)
if(flag_use_overlap) then
sc_up = SV(im+PGEOM%neig*(is-1),is,ik)
else
sc_up = V(im+PGEOM%neig*(is-1),is,ik)
endif
write(pid_energy,'(*(F9.4))',ADVANCE='NO') real(conjg(c_up)*sc_up)
endif
enddo basis
if(PINPT%ispinor .eq. 2) then
c_up = V(im,is,ik); c_dn = V(im + nbasis,is,ik)
if(flag_use_overlap) then
sc_up = SV(im,is,ik); sc_dn = SV(im + nbasis,is,ik)
else
sc_up = V(im,is,ik); sc_dn = V(im + nbasis,is,ik)
endif
if(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'mz') then
write(pid_energy,'(*(F9.4))',ADVANCE='YES') real( conjg(c_up)*sc_up - conjg(c_dn)*sc_dn) ! up - dn : mz
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'mx') then
write(pid_energy,'(*(F9.4))',ADVANCE='YES') real( conjg(c_dn)*sc_up + conjg(c_up)*sc_dn) ! up*dn + dn*up : mx
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'my') then
write(pid_energy,'(*(F9.4))',ADVANCE='YES') real((conjg(c_dn)*sc_up - conjg(c_up)*sc_dn)*zi) ! (up*dn - dn*up)*i : my
else
write(pid_energy,'(*(F9.4))',ADVANCE='YES') real( conjg(c_up)*sc_up + conjg(c_dn)*sc_dn) ! up + dn : total
endif
elseif(PINPT%ispinor .eq. 1) then
c_up = V(nbasis+PGEOM%neig*(is-1),is,ik)
if(flag_use_overlap) then
sc_up = SV(nbasis+PGEOM%neig*(is-1),is,ik)
else
sc_up = V(nbasis+PGEOM%neig*(is-1),is,ik)
endif
write(pid_energy,'(*(F9.4))',ADVANCE='YES') real(conjg(c_up)*sc_up)
endif
endif
if(.not.PINPT%flag_print_orbital) write(pid_energy,*)''
enddo kp
write(pid_energy,*)''
write(pid_energy,*)''
close(pid_energy)
enddo spin
return
endsubroutine
subroutine print_energy_eff( PKPTS, E, V, PGEOM, PINPT, neig, fname_header )
use parameters, only : pid_energy, incar, poscar, kpoints, zi
implicit none
type(incar) :: PINPT
type(poscar) :: PGEOM
type(kpoints):: PKPTS
integer*4 neig
integer*4 ie,is,ik,im
integer*4 nspin, nbasis, nkpoint
real*8 kline(PKPTS%nkpoint),kpoint(3,PKPTS%nkpoint)
logical flag_klinemode, flag_kgridmode, flag_print_orbital
real*8 E(neig*PINPT%ispin,PKPTS%nkpoint)
complex*16 V(neig*PINPT%ispin,neig*PINPT%ispin,PKPTS%nkpoint)
complex*16 c_up, c_dn
character*80 fname_header
character*80 fname
character*6 kunit_
character*28 kmode
character*8 sigma
! NOTE: this subroutine is not for SPARSE matrix
! and probably need to be updated to accept ERANGE tag where init_erange is not 1
flag_klinemode = PKPTS%flag_klinemode
flag_kgridmode = PKPTS%flag_kgridmode
flag_print_orbital = PINPT%flag_print_orbital
kpoint = PKPTS%kpoint
nkpoint= PKPTS%nkpoint
nbasis = neig
nspin = PINPT%nspin
sigma='sigma_0 '
call get_kunit(PKPTS%kunit, kunit_)
call get_plotmode(flag_klinemode, flag_kgridmode, kunit_, kmode)
if(flag_klinemode) call get_kline_dist(kpoint, nkpoint, kline)
spin:do is = 1, nspin
call get_fname(fname_header, fname, is, PINPT%flag_collinear, PINPT%flag_noncollinear)
open(pid_energy, file=trim(fname), status = 'unknown')
eig:do ie =1, neig*PINPT%ispinor
write(pid_energy, '(2A,I8,A)', ADVANCE = 'yes') kmode,' energy(eV) :', ie,' -th eigen'
if(.not. flag_print_orbital) then
write(pid_energy,'(A)',ADVANCE='NO')''
elseif( flag_print_orbital) then
if(PINPT%axis_print_mag .eq. 'mz') sigma='sigma_z '
if(PINPT%axis_print_mag .eq. 'mx') sigma='sigma_x '
if(PINPT%axis_print_mag .eq. 'my') sigma='sigma_y '
write(pid_energy, '(2A)',ADVANCE='YES') '# wavefunction coeff.: <ci|sigma|ci>,sigma=',sigma
write(pid_energy, '( A)',ADVANCE='NO') '# k-dist (ci: wfn coeff for i-th orb) E(eV), i='
mm: do im=1,nbasis
write(pid_energy, '(I9)',ADVANCE='NO')im
if(im .ge. 30 .and. im .lt. nbasis) then
write(pid_energy, '(A)',ADVANCE='NO')' ... '
exit mm
endif
enddo mm
write(pid_energy,'(A)')''
endif
kp:do ik = 1, nkpoint
if(flag_klinemode) then
write(pid_energy,'(1x,F12.6,24x,F14.6,1x)',ADVANCE='NO')kline(ik), E(ie+neig*(is-1),ik)
elseif(flag_kgridmode) then
write(pid_energy,'(1x,3F12.6,F14.6,1x)',ADVANCE='NO')kpoint(:,ik), E(ie+neig*(is-1),ik)
endif
if(flag_print_orbital) then
basis:do im = 1, nbasis-1
if(PINPT%ispinor .eq. 2) then
c_up = V(im,ie,ik); c_dn = V(im+nbasis,ie,ik)
if(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'mz') then
write(pid_energy,'(*(F9.4))',ADVANCE='NO') real( conjg(c_up)*c_up - conjg(c_dn)*c_dn) ! up - dn : mz
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'mx') then
write(pid_energy,'(*(F9.4))',ADVANCE='NO') real( conjg(c_dn)*c_up + conjg(c_up)*c_dn) ! up*dn + dn*up : mx
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'my') then
write(pid_energy,'(*(F9.4))',ADVANCE='NO') real((conjg(c_dn)*c_up - conjg(c_up)*c_dn)*zi) ! (up*dn - dn*up)*i : my
else
write(pid_energy,'(*(F9.4))',ADVANCE='NO') real( conjg(c_up)*c_up + conjg(c_dn)*c_dn) ! up + dn : total
endif
elseif(PINPT%ispinor .eq. 1) then
c_up = V(im+neig*(is-1), ie+neig*(is-1),ik)
write(pid_energy,'(*(F9.4))',ADVANCE='NO') real(conjg(c_up)*c_up)
endif
enddo basis
if(PINPT%ispinor .eq. 2) then
c_up = V(im,ie,ik); c_dn = V(im+nbasis,ie,ik)
if(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'mz') then
write(pid_energy,'(*(F9.4))',ADVANCE='YES') real( conjg(c_up)*c_up - conjg(c_dn)*c_dn) ! up - dn : mz
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'mx') then
write(pid_energy,'(*(F9.4))',ADVANCE='YES') real( conjg(c_dn)*c_up + conjg(c_up)*c_dn) ! up*dn + dn*up : mx
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'my') then
write(pid_energy,'(*(F9.4))',ADVANCE='YES') real((conjg(c_dn)*c_up - conjg(c_up)*c_dn)*zi) ! (up*dn - dn*up)*i : my
else
write(pid_energy,'(*(F9.4))',ADVANCE='YES') real( conjg(c_up)*c_up + conjg(c_dn)*c_dn) ! up + dn : total
endif
elseif(PINPT%ispinor .eq. 1) then
c_up = V(im+neig*(is-1), ie+neig*(is-1),ik)
write(pid_energy,'(*(F9.4))',ADVANCE='YES') real(conjg(c_up)*c_up)
endif
endif
if(.not. flag_print_orbital) write(pid_energy,*)''
enddo kp
write(pid_energy,*)''
write(pid_energy,*)''
enddo eig
close(pid_energy)
enddo spin
return
endsubroutine
subroutine print_energy_proj(PKPTS,E,V,SV,PGEOM,PINPT,PPRAM)
use parameters, only: pid_energy, incar, poscar, kpoints, params, zi
implicit none
type(incar) :: PINPT
type(poscar) :: PGEOM
type(kpoints):: PKPTS
type(params ):: PPRAM
integer*4 mysystem
integer*4 ie,is,ik,im,ia
integer*4 isum, iatom, iorb
integer*4 nspin, nbasis
integer*4 nkpoint
integer*4 proj_natom, proj_atom(maxval(PINPT%proj_natom(1:PINPT%nproj_sum)))
integer*4 init_e, fina_e
integer*4 ne_found(PINPT%nspin, PKPTS%nkpoint)
integer*4 imatrix
real*8 kline(PKPTS%nkpoint),kpoint(3,PKPTS%nkpoint)
logical flag_klinemode, flag_kgridmode, flag_print_orbital, flag_use_overlap
logical flag_proj_sum, flag_proj_atom
real*8 E(PGEOM%nband*PINPT%nspin,PKPTS%nkpoint)
complex*16 V(PGEOM%neig*PINPT%ispin,PGEOM%nband*PINPT%nspin,PKPTS%nkpoint)
complex*16 SV(PGEOM%neig*PINPT%ispin,PGEOM%nband*PINPT%nspin,PKPTS%nkpoint)
complex*16 c_up, c_dn, c_tot
complex*16 sc_up, sc_dn
complex*16 c_sum(PGEOM%nband,PKPTS%nkpoint)
complex*16 c_sum_orb(PGEOM%max_orb,PGEOM%nband,PKPTS%nkpoint)
complex*16 c_tot_orb(PGEOM%max_orb)
character*80 fname_header, fname_header_sum
character*80 fname, fname_sum
character*6 kunit_
character*28 kmode
character*8 sigma
mysystem = PGEOM%mysystem
flag_klinemode = PKPTS%flag_klinemode
flag_kgridmode = PKPTS%flag_kgridmode
flag_print_orbital = PINPT%flag_get_orbital
flag_proj_sum = PINPT%flag_print_proj_sum
flag_proj_atom= PINPT%flag_print_proj_atom
kpoint = PKPTS%kpoint
nkpoint= PKPTS%nkpoint
nbasis = PGEOM%neig
nspin = PINPT%nspin
sigma='sigma_0 '
flag_use_overlap = PPRAM%flag_use_overlap
do isum = 1, PINPT%nproj_sum
proj_natom = PINPT%proj_natom(isum)
proj_atom = PINPT%proj_atom(1:proj_natom,isum)
if(PINPT%flag_sparse) then
ne_found = PINPT%feast_ne
else
ne_found = PGEOM%nband
endif
call get_kunit(PKPTS%kunit, kunit_)
call get_plotmode(flag_klinemode, flag_kgridmode, kunit_, kmode)
init_e = PGEOM%init_erange ; fina_e = init_e + PGEOM%nband - 1
if(flag_klinemode) call get_kline_dist(kpoint, nkpoint, kline)
spin:do is = 1, nspin
if(flag_proj_sum) then
c_sum = 0d0
c_sum_orb = 0d0
write(fname_header_sum,'(3A,I0)')'band_structure_TBA_atom',trim(PINPT%title(mysystem)),'.sum',isum
call get_fname(fname_header_sum, fname_sum, is, PINPT%flag_collinear, PINPT%flag_noncollinear)
open(pid_energy+100, file = trim(fname_sum), status = 'unknown')
if(PINPT%flag_sparse) then
write(pid_energy+100, '(A,2(F10.4,A),I0)')'# The EWINDOW mode: energy window [EMIN:EMAX]=[ ', &
PINPT%feast_emin,' : ', PINPT%feast_emax,' ], NE_MAX= ',PINPT%feast_nemax
do ik = 1, nkpoint
write(pid_energy+100, '(A,I0,A,I0)')'# NE_FOUND(ik=',ik,')= ',ne_found(is,ik)
enddo
elseif(PINPT%flag_erange) then
write(pid_energy+100, '(A,I0,A,I0,A)')'# ERANGE=[ ',init_e,' : ',fina_e,' ]'
endif
write(pid_energy+100, '(A, *(I0,1x))') '# ATOM_INDEX to be sum up: ', proj_atom(1:proj_natom)
endif
atom:do iatom = 1, proj_natom
ia = proj_atom(iatom)
imatrix = sum( PGEOM%n_orbital(1:ia) ) - PGEOM%n_orbital(ia) + 1
if(flag_proj_atom) then
write(fname_header,'(3A,I0)')'band_structure_TBA_atom',trim(PINPT%title(mysystem)),'.',ia
call get_fname(fname_header, fname, is, PINPT%flag_collinear, PINPT%flag_noncollinear)
open(pid_energy, file = trim(fname), status = 'unknown')
if(PINPT%flag_sparse) then
write(pid_energy, '(A,2(F10.4,A),I0)')'# The EWINDOW mode: energy window [EMIN:EMAX]=[ ', &
PINPT%feast_emin,' : ', PINPT%feast_emax,'], NE_MAX= ',PINPT%feast_nemax
do ik = 1, nkpoint
write(pid_energy, '(A,I0,A,I0)')'# NE_FOUND(ik=',ik,')= ',ne_found(is,ik)
enddo
elseif(PINPT%flag_erange) then
write(pid_energy, '(A,I0,A,I0,A)')'# ERANGE=[ ',init_e,' : ',fina_e,' ]'
endif
endif
eig:do ie = 1, PGEOM%nband ! init_e, fina_e
if(flag_proj_atom) then
write(pid_energy,'(2A,I8,A,I8,3A)',ADVANCE='yes')kmode,' energy(eV) :',init_e+ie-1,' -th eigen | ',ia, &
' -th atom (spec= ',trim(PGEOM%c_spec(PGEOM%spec(ia))),' )'
endif
if(PINPT%axis_print_mag .eq. 'mz') sigma='sigma_z '
if(PINPT%axis_print_mag .eq. 'mx') sigma='sigma_x '
if(PINPT%axis_print_mag .eq. 'my') sigma='sigma_y '
if(flag_proj_atom) then
write(pid_energy, '(2A)',ADVANCE='YES') '# wavefunction coeff.: <ci|sigma|ci>,sigma=',sigma
write(pid_energy, '( A)',ADVANCE='NO') '# k-dist (ci: wfn coeff for i-th orb) E(eV), i='
do im=imatrix, imatrix + PGEOM%n_orbital(ia) - 1
write(pid_energy, '(I9)',ADVANCE='NO')im
enddo
write(pid_energy,'(A9)',ADVANCE='YES') ' tot'
endif
if(iatom .eq. proj_natom .and. flag_proj_sum) then
write(pid_energy+100,'(2A,I8,A )',ADVANCE='yes')kmode,' energy(eV) :',init_e+ie-1,' -th eigen '
if(PINPT%axis_print_mag .eq. 'mz') sigma='sigma_z '
if(PINPT%axis_print_mag .eq. 'mx') sigma='sigma_x '
if(PINPT%axis_print_mag .eq. 'my') sigma='sigma_y '
write(pid_energy+100, '(2A)',ADVANCE='YES') '# wavefunction coeff.: <ci|sigma|ci>,sigma=',sigma
write(pid_energy+100, '( A)',ADVANCE='NO') '# k-dist (ci: wfn coeff for i-th orb) E(eV), '
do im=1 , PGEOM%n_orbital(ia) ! note: PROJ_BAND should be summed up with those atoms having same number of basis and same orbitals
!write(pid_energy+100, '(I9)',ADVANCE='NO')im
write(pid_energy+100, '(1X,A8)',ADVANCE='NO')trim(PGEOM%c_orbital(im,ia))
enddo
write(pid_energy+100,'(A)',ADVANCE='YES') ' tot(atom_sum)'
endif
kp:do ik = 1, nkpoint
if(flag_klinemode .and. flag_proj_atom) then
if( ie .le. ne_found(is, ik) ) then
write(pid_energy,'(1x,F12.6,24x,F14.6,1x)',ADVANCE='NO')kline(ik), E(ie+PGEOM%nband*(is-1),ik)
elseif( ie .gt. ne_found(is, ik)) then
write(pid_energy,'(1x,F12.6,24x,F14.6,1x)',ADVANCE='NO')kline(ik)
endif
elseif(flag_kgridmode .and. flag_proj_atom) then
if( ie .le. ne_found(is, ik) ) then
write(pid_energy,'(1x,3F12.6,F14.6,1x)',ADVANCE='NO')kpoint(:,ik), E(ie+PGEOM%nband*(is-1),ik)
elseif(ie .gt. ne_found(is, ik)) then
write(pid_energy,'(1x,3F12.6,F14.6,1x)',ADVANCE='NO')kpoint(:,ik)
endif
endif
if(flag_proj_sum .and. iatom .eq. proj_natom) then
if(flag_klinemode) then
if( ie .le. ne_found(is, ik) ) then
write(pid_energy+100,'(1x,F12.6,24x,F14.6,1x)',ADVANCE='NO')kline(ik), E(ie+PGEOM%nband*(is-1),ik)
elseif( ie .gt. ne_found(is, ik)) then
write(pid_energy+100,'(1x,F12.6,24x,F14.6,1x)',ADVANCE='NO')kline(ik)
endif
elseif(flag_kgridmode) then
if( ie .le. ne_found(is, ik) ) then
write(pid_energy+100,'(1x,3F12.6,F14.6,1x)',ADVANCE='NO')kpoint(:,ik), E(ie+PGEOM%nband*(is-1),ik)
elseif(ie .gt. ne_found(is, ik)) then
write(pid_energy+100,'(1x,3F12.6,F14.6,1x)',ADVANCE='NO')kpoint(:,ik)
endif
endif
endif
if( ie .le. ne_found(is, ik) ) then
if(flag_print_orbital) then
c_tot = 0d0 !initialize
c_tot_orb = 0d0 ! initialize
iorb=0
basis:do im=imatrix, imatrix+PGEOM%n_orbital(ia) - 1
iorb=iorb + 1
if(PINPT%ispinor .eq. 2) then
c_up = V(im,ie,ik); c_dn = V(im + nbasis,ie,ik)
if(flag_use_overlap) then
sc_up = SV(im,ie,ik); sc_dn = SV(im + nbasis,ie,ik)
else
sc_up = V(im,ie,ik); sc_dn = V(im + nbasis,ie,ik)
endif
if (PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'mz') then
c_tot_orb(iorb) = real( conjg(c_up)*sc_up - conjg(c_dn)*sc_dn) ! ! up - dn : mz
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'mx') then
c_tot_orb(iorb) = real( conjg(c_dn)*sc_up + conjg(c_up)*sc_dn) ! ! up*dn + dn*up : mx
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'my') then
c_tot_orb(iorb) = real((conjg(c_dn)*sc_up - conjg(c_up)*sc_dn)*zi) ! (up*dn - dn*up)*i : my
else
c_tot_orb(iorb) = real( conjg(c_up)*sc_up + conjg(c_dn)*sc_dn) ! up + dn : total
endif
elseif(PINPT%ispinor .eq. 1) then
c_up = V(im+PGEOM%neig*(is-1),ie+PGEOM%nband*(is-1),ik)
if(flag_use_overlap) then
sc_up = SV(im+PGEOM%neig*(is-1),ie+PGEOM%nband*(is-1),ik)
else
sc_up = V(im+PGEOM%neig*(is-1),ie+PGEOM%nband*(is-1),ik)
endif
c_tot_orb(iorb) = real(conjg(c_up)*sc_up)
endif
if(flag_proj_atom) then
write(pid_energy,'(*(F9.4))',ADVANCE='NO') real(c_tot_orb(iorb))
endif
c_tot = c_tot + real(c_tot_orb(iorb))
enddo basis
if(flag_proj_atom) then
write(pid_energy,'(*(F9.4))',ADVANCE='YES') real(c_tot)
endif
if(flag_proj_sum) then
c_sum(ie,ik) = c_sum(ie,ik) + c_tot
c_sum_orb(1:PGEOM%n_orbital(ia),ie,ik) = c_sum_orb(1:PGEOM%n_orbital(ia),ie,ik) + c_tot_orb(1:PGEOM%n_orbital(ia))
endif
if(flag_proj_sum .and. iatom .eq. proj_natom) then
write(pid_energy+100,'(*(F9.4))',ADVANCE='YES') real(c_sum_orb(1:PGEOM%n_orbital(ia),ie,ik)), real(c_sum(ie, ik))
endif
endif
if(.not.flag_print_orbital .and. flag_proj_atom) write(pid_energy,*)''
if(.not.flag_print_orbital .and. flag_proj_sum) write(pid_energy+100,*)'' ! maybe do not need.. but who knows?
elseif(ie .gt. ne_found(is, ik)) then
if(flag_proj_atom) write(pid_energy,*)''
if(iatom .eq. proj_natom .and. flag_proj_sum) write(pid_energy+100,*)''
endif
enddo kp
if(flag_proj_atom) write(pid_energy,*)''
if(flag_proj_atom) write(pid_energy,*)''
if(iatom .eq. proj_natom .and. flag_proj_sum) write(pid_energy+100,*)''
if(iatom .eq. proj_natom .and. flag_proj_sum) write(pid_energy+100,*)''
enddo eig
if(flag_proj_atom) close(pid_energy)
enddo atom
if(iatom-1 .eq. proj_natom .and. flag_proj_sum) close(pid_energy+100)
enddo spin
enddo
return
endsubroutine
subroutine print_energy_singlek( E, V, SV, neig, iband, nband, iik , kp, PINPT, flag_use_overlap, mysystem)
use parameters, only : pid_energy, incar, poscar, zi
use mpi_setup
type(incar) :: PINPT
integer*4 mysystem
integer*4 neig, iband, nband
integer*4 iik, nkp
integer*4 ie, is ,ik, im
integer*4 nspin, nbasis
integer*4 ikmode
integer*4 init_e, fina_e
integer*4 ne_found(PINPT%nspin)
integer*4 my_pid_energy, mpierr
integer*4 my_pid_energyS
real*8 E(nband*PINPT%nspin)
real*8 kp(3)
complex*16 V(neig*PINPT%ispin,nband*PINPT%nspin)
complex*16 SV(neig*PINPT%ispin,nband*PINPT%nspin) ! overlap matrix multiplied wavefunction
complex*16 c_up, c_dn
complex*16 sc_up, sc_dn ! for overlap matrix multiplied wavefunction
character*80 fname_header
character*80 fname
character*80 fname_headerS, fnameS ! for overlap matrix multiplied wavefunction
character*28 kmode
character*6 kunit_
character*20,external :: int2str
logical flag_print_orbital, flag_use_overlap, flag_file_exist
character*8 sigma
my_pid_energy = pid_energy + myid
my_pid_energyS= pid_energy + myid + nprocs
fname_header = 'band_structure_TBA'//trim(PINPT%title(mysystem))//'.kp_'//trim(ADJUSTL(int2str(iik)))
fname_headerS = 'band_structure_TBA_S'//trim(PINPT%title(mysystem))//'.kp_'//trim(ADJUSTL(int2str(iik)))
flag_print_orbital = PINPT%flag_print_orbital
nbasis = neig
nspin = PINPT%nspin
sigma='sigma_0 '
ikmode = 3
flag_file_exist = .FALSE.
if(PINPT%flag_sparse) then
ne_found = PINPT%feast_ne(1:PINPT%nspin,iik)
else
ne_found = nband
endif
call get_kunit('A', kunit_) ! enforce as default
call get_plotmode(.false., .true., kunit_, kmode)
init_e = iband ; fina_e = init_e + nband - 1
if(.not. PINPT%flag_write_unformatted) then
spin:do is = 1, nspin
call get_fname(fname_header, fname, is, PINPT%flag_collinear, PINPT%flag_noncollinear)
inquire(file=trim(fname),exist=flag_file_exist)
if(flag_file_exist) return
open(my_pid_energy, file=trim(fname), status = 'unknown')
if(flag_use_overlap .and. trim(PINPT%axis_print_mag) .eq. 'wf') then
call get_fname(fname_headerS, fnameS, is, PINPT%flag_collinear, PINPT%flag_noncollinear)
open(my_pid_energyS, file=trim(fnameS), status = 'unknown')
endif
if(trim(PINPT%axis_print_mag) .eq. 'rh') then
write(my_pid_energy,'(3A)')'# MODE LORBIT=[ ',trim(PINPT%axis_print_mag), &
' ] -> <phi_ij|psi_nk> ; i,j => orbital j in atom i; n,k => band index (n) and kpoint index (k)'
elseif(trim(PINPT%axis_print_mag) .eq. 'wf') then
write(my_pid_energy,'(3A)')'# MODE LORBIT=[ ',trim(PINPT%axis_print_mag), ' ] -> wavefunction coefficients '
if(flag_use_overlap) then
write(my_pid_energyS,'(3A)')'# MODE LORBIT=[ ',trim(PINPT%axis_print_mag), ' ] -> wavefunction coefficients multiplied with overlap matrix S(k)'
endif
elseif(trim(PINPT%axis_print_mag) .eq. 'no') then
write(my_pid_energy,'(3A)')'# MODE LORBIT=[ ',trim(PINPT%axis_print_mag), ' ]'
elseif(trim(PINPT%axis_print_mag) .eq. 'mx' .or. &
trim(PINPT%axis_print_mag) .eq. 'my' .or. &
trim(PINPT%axis_print_mag) .eq. 'mz') then
write(my_pid_energy,'(3A)')'# MODE LORBIT=[ ',trim(PINPT%axis_print_mag), ' ] -> magnetization <sigma_i>'
endif
if(PINPT%flag_sparse) then
write(my_pid_energy, '(A,2(F10.4,A),I0)')'# The EWINDOW mode: energy window [EMIN:EMAX]=[ ',PINPT%feast_emin, &
' : ',PINPT%feast_emax,' ], NE_MAX= ',PINPT%feast_nemax
write(my_pid_energy, '(A,I0,A,I0)')'# NE_FOUND(ik=',iik,')= ',ne_found(is)
if(flag_use_overlap .and. trim(PINPT%axis_print_mag) .eq. 'wf') then
write(my_pid_energyS, '(A,2(F10.4,A),I0)')'# The EWINDOW mode: energy window [EMIN:EMAX]=[ ',PINPT%feast_emin, &
' : ',PINPT%feast_emax,' ], NE_MAX= ',PINPT%feast_nemax
write(my_pid_energyS, '(A,I0,A,I0)')'# NE_FOUND(ik=',iik,')= ',ne_found(is)
endif
elseif(PINPT%flag_erange) then
write(my_pid_energy, '(A,I0,A,I0,A)')'# ERANGE=[ ',init_e,' : ',fina_e,' ]'
if(flag_use_overlap .and. trim(PINPT%axis_print_mag) .eq. 'wf') then
write(my_pid_energy, '(A,I0,A,I0,A)')'# ERANGE=[ ',init_e,' : ',fina_e,' ]'
endif
endif
eig:do ie =1, nband !init_e, fina_e
write(my_pid_energy, '(2A,I8,A)', ADVANCE = 'yes') kmode,' energy(eV) :', init_e + ie - 1,' -th eigen'
if(flag_use_overlap .and. trim(PINPT%axis_print_mag) .eq. 'wf') then
write(my_pid_energyS, '(2A,I8,A)', ADVANCE = 'yes') kmode,' energy(eV) :', init_e + ie - 1,' -th eigen'
endif
if(.not. flag_print_orbital) then
write(my_pid_energy,'(A)',ADVANCE='NO')''
elseif( flag_print_orbital) then
if(PINPT%axis_print_mag .eq. 'mz') sigma='sigma_z '
if(PINPT%axis_print_mag .eq. 'mx') sigma='sigma_x '
if(PINPT%axis_print_mag .eq. 'my') sigma='sigma_y '
if(PINPT%axis_print_mag .ne. 'wf') then
if(PINPT%axis_print_mag .ne. 'wf') then
write(my_pid_energy, '(2A)',ADVANCE='YES') '# overlap S multiplied wavefunction coeff.: <ci|sigma*S|ci>,sigma=',sigma
else
write(my_pid_energy, '(2A)',ADVANCE='YES') '# wavefunction coeff.: <ci|sigma|ci>,sigma=',sigma
endif
write(my_pid_energy, '( A)',ADVANCE='NO') '# k-dist (ci: wfn coeff for i-th orb) E(eV), i='
elseif(PINPT%axis_print_mag .eq. 'wf') then
write(my_pid_energy, '(1A)',ADVANCE='YES') '# wavefunction coeff.: |ci> '
write(my_pid_energy, '( A)',ADVANCE='NO') '# k-dist (ci: wfn coeff for i-th orb) E(eV), i='
if(flag_use_overlap) then
write(my_pid_energyS, '(1A)',ADVANCE='YES') '# wavefunction coeff.: |ci> '
write(my_pid_energyS, '( A)',ADVANCE='NO') '# k-dist (ci: wfn coeff for i-th orb) E(eV), i='
endif
endif
mm:do im=1,nbasis
if(PINPT%axis_print_mag .ne. 'wf') then
write(my_pid_energy, '(I9)',ADVANCE='NO')im
elseif(PINPT%axis_print_mag .eq. 'wf') then
if(PINPT%ispinor .eq. 2) then
write(my_pid_energy, '(I38)',ADVANCE='NO')im
if(flag_use_overlap) then
write(my_pid_energyS, '(I38)',ADVANCE='NO')im
endif
elseif(PINPT%ispinor .eq. 1) then
write(my_pid_energy, '(I19)',ADVANCE='NO')im
if(flag_use_overlap) then
write(my_pid_energyS, '(I19)',ADVANCE='NO')im
endif
endif
endif
if(im .ge. 30 .and. im .lt. nbasis) then
write(my_pid_energy, '(A)',ADVANCE='NO')' ... '
if(flag_use_overlap .and. trim(PINPT%axis_print_mag) .eq. 'wf') then
write(my_pid_energyS, '(A)',ADVANCE='NO')' ... '
endif
exit mm
endif
enddo mm
write(my_pid_energy,'(A)')''
if(flag_use_overlap .and. trim(PINPT%axis_print_mag) .eq. 'wf') then
write(my_pid_energyS,'(A)')''
endif
endif
if( ie .le. ne_found(is ) ) then
write(my_pid_energy,'(1x,3F12.6,F14.6,1x)',ADVANCE='NO')kp(:), E(ie+nband*(is-1))
if(flag_use_overlap .and. trim(PINPT%axis_print_mag) .eq. 'wf') then
write(my_pid_energyS,'(1x,3F12.6,F14.6,1x)',ADVANCE='NO')kp(:), E(ie+nband*(is-1))
endif
elseif(ie .gt. ne_found(is )) then
write(my_pid_energy,'(1x,3F12.6,F14.6,1x)',ADVANCE='NO')kp(:)
if(flag_use_overlap .and. trim(PINPT%axis_print_mag) .eq. 'wf') then
write(my_pid_energyS,'(1x,3F12.6,F14.6,1x)',ADVANCE='NO')kp(:)
endif
endif
if( ie .le. ne_found(is ) ) then
if(flag_print_orbital) then
basis:do im=1,nbasis-1
if(PINPT%ispinor .eq. 2) then
c_up = V(im,ie); c_dn = V(im + nbasis,ie)
if(flag_use_overlap) then
sc_up = SV(im,ie); sc_dn = SV(im + nbasis,ie)
else
sc_up = V(im,ie); sc_dn = V(im + nbasis,ie)
endif
if (PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'mz') then
write(my_pid_energy,'(*(F9.4))',ADVANCE='NO') real( conjg(c_up)*sc_up - conjg(c_dn)*sc_dn) ! up - dn : mz
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'mx') then
write(my_pid_energy,'(*(F9.4))',ADVANCE='NO') real( conjg(c_dn)*sc_up + conjg(c_up)*sc_dn) ! up*dn + dn*up : mx
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'my') then
write(my_pid_energy,'(*(F9.4))',ADVANCE='NO') real((conjg(c_dn)*sc_up - conjg(c_up)*sc_dn)*zi) ! (up*dn - dn*up)*i : my
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'wf') then
write(my_pid_energy,'(2(F9.4,F9.4," "))',ADVANCE='NO') c_up, c_dn ! c_up and c_dn (real,imag) wavefunction coefficient
if(flag_use_overlap) then
write(my_pid_energyS,'(2(F9.4,F9.4," "))',ADVANCE='NO') sc_up, sc_dn ! sc_up and sc_dn (real,imag) S multiplied wavefunction coefficient
endif
else
write(my_pid_energy,'(*(F9.4))',ADVANCE='NO') real( conjg(c_up)*sc_up + conjg(c_dn)*sc_dn) ! up + dn : total
endif
elseif(PINPT%ispinor .eq. 1) then
c_up = V(im+nbasis*(is-1),ie+nband*(is-1))
if(flag_use_overlap) then
sc_up = SV(im+nbasis*(is-1),ie+nband*(is-1))
else
sc_up = V(im+nbasis*(is-1),ie+nband*(is-1))
endif
if(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'wf') then
write(my_pid_energy,'(1(F9.4,F9.4," "))',ADVANCE='NO') c_up
else
write(my_pid_energy,'(*(F9.4))',ADVANCE='NO') real(conjg(c_up)*sc_up)
endif
endif
enddo basis
if(PINPT%ispinor .eq. 2) then
c_up = V(im,ie); c_dn = V(im + nbasis,ie)
if(flag_use_overlap) then
sc_up = SV(im,ie); sc_dn = SV(im + nbasis,ie)
else
sc_up = V(im,ie); sc_dn = V(im + nbasis,ie)
endif
if (PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'mz') then
write(my_pid_energy,'(*(F9.4))',ADVANCE='YES') real( conjg(c_up)*sc_up - conjg(c_dn)*sc_dn) ! up - dn : mz
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'mx') then
write(my_pid_energy,'(*(F9.4))',ADVANCE='YES') real( conjg(c_dn)*sc_up + conjg(c_up)*sc_dn) ! up*dn + dn*up : mx
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'my') then
write(my_pid_energy,'(*(F9.4))',ADVANCE='YES') real((conjg(c_dn)*sc_up - conjg(c_up)*sc_dn)*zi) ! (up*dn - dn*up)*i : my
elseif(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'wf') then
write(my_pid_energy,'(2(F9.4,F9.4," "))',ADVANCE='YES') c_up, c_dn ! c_up and c_dn (real,imag) wavefunction coefficient
if(flag_use_overlap) then
write(my_pid_energyS,'(2(F9.4,F9.4," "))',ADVANCE='YES') sc_up, sc_dn ! c_up and c_dn (real,imag) S multiploed wavefunction coefficient
endif
else
write(my_pid_energy,'(*(F9.4))',ADVANCE='YES') real( conjg(c_up)*sc_up + conjg(c_dn)*sc_dn) ! up + dn : total
endif
elseif(PINPT%ispinor .eq. 1) then
c_up = V(nbasis+nbasis*(is-1),ie+nband*(is-1))
if(flag_use_overlap) then
sc_up = SV(nbasis+nbasis*(is-1),ie+nband*(is-1))
else
sc_up = V(nbasis+nbasis*(is-1),ie+nband*(is-1))
endif
if(PINPT%flag_print_mag .and. PINPT%axis_print_mag .eq. 'wf') then
write(my_pid_energy,'(1(F9.4,F9.4," "))',ADVANCE='YES') c_up
if(flag_use_overlap) then
write(my_pid_energyS,'(1(F9.4,F9.4," "))',ADVANCE='YES') sc_up
endif
else
write(my_pid_energy,'(*(F9.4))',ADVANCE='YES') real(conjg(c_up)*sc_up)
endif
endif
endif
if(.not.flag_print_orbital) then
write(my_pid_energy,*)''
endif
elseif(ie .gt. ne_found(is)) then
write(my_pid_energy,*)''
if(flag_use_overlap .and. trim(PINPT%axis_print_mag) .eq. 'wf') then
write(my_pid_energyS,*)''
endif
endif
write(my_pid_energy,*)''
write(my_pid_energy,*)''
if(flag_use_overlap .and. trim(PINPT%axis_print_mag) .eq. 'wf') then
write(my_pid_energyS,*)''
write(my_pid_energyS,*)''
endif
enddo eig
close(my_pid_energy)
if(flag_use_overlap .and. trim(PINPT%axis_print_mag) .eq. 'wf') then
close(my_pid_energyS)
endif
enddo spin
elseif(PINPT%flag_write_unformatted) then
spinb:do is = 1, nspin
call get_fname_bin(fname_header, fname, is, PINPT%flag_collinear, PINPT%flag_noncollinear)
inquire(file=trim(fname),exist=flag_file_exist)
if(flag_file_exist) return
if(flag_use_overlap .and. PINPT%axis_print_mag .eq. 'wf') then
call get_fname_bin(fname_headerS, fnameS, is, PINPT%flag_collinear, PINPT%flag_noncollinear)
endif
open(my_pid_energy, file=trim(fname), form='unformatted', status='unknown')
write(my_pid_energy) ikmode, flag_print_orbital, PINPT%flag_print_single, PINPT%flag_erange, &
PINPT%flag_sparse, neig, 1, nband, &
PINPT%ispin, PINPT%nspin, PINPT%ispinor, PINPT%axis_print_mag
if(PINPT%flag_erange) then
write(my_pid_energy) PINPT%flag_erange, init_e , fina_e
else
write(my_pid_energy) PINPT%flag_erange ! .FALSE.
endif
if(PINPT%flag_sparse) then
write(my_pid_energy) PINPT%flag_sparse, PINPT%feast_emin, PINPT%feast_emax, PINPT%feast_nemax
else
write(my_pid_energy) PINPT%flag_sparse ! .FALSE.
endif
if(flag_use_overlap .and. PINPT%axis_print_mag .eq. 'wf') then
open(my_pid_energyS, file=trim(fnameS), form='unformatted', status='unknown')
write(my_pid_energyS) ikmode, flag_print_orbital, PINPT%flag_print_single, PINPT%flag_erange, &
PINPT%flag_sparse, neig, 1, nband, &
PINPT%ispin, PINPT%nspin, PINPT%ispinor, PINPT%axis_print_mag
if(PINPT%flag_erange) then
write(my_pid_energyS) PINPT%flag_erange, init_e , fina_e
else
write(my_pid_energyS) PINPT%flag_erange ! .FALSE.
endif
if(PINPT%flag_sparse) then
write(my_pid_energyS) PINPT%flag_sparse, PINPT%feast_emin, PINPT%feast_emax, PINPT%feast_nemax
else
write(my_pid_energyS) PINPT%flag_sparse ! .FALSE.
endif
endif
! write main wavefunction information
if(flag_print_orbital) then
if(PINPT%ispinor .eq. 2) then
if(PINPT%axis_print_mag .eq. 'wf') then
if(.not.PINPT%flag_print_single) then
write(my_pid_energy) ne_found(is), kp(:), (E(ie+nband*(is-1)),ie=1,ne_found(is))
if(flag_use_overlap) then
write(my_pid_energyS) ne_found(is), kp(:), (E(ie+nband*(is-1)),ie=1,ne_found(is))
endif
do ie = 1, ne_found(is)
do im = 1, nbasis
write(my_pid_energy) V(im,ie), V(im+nbasis,ie)
if(flag_use_overlap) write(my_pid_energyS) SV(im,ie), SV(im+nbasis,ie)
enddo
enddo
elseif(PINPT%flag_print_single) then
write(my_pid_energy) ne_found(is), real(kp(:),kind=4), (real(E(ie+nband*(is-1)),kind=4),ie=1,ne_found(is))
do ie = 1, ne_found(is)
do im = 1, nbasis
if(.not.flag_use_overlap) then
write(my_pid_energy) cmplx((/V(im,ie), V(im+nbasis,ie)/),kind=4)
else
write(my_pid_energy) cmplx((/V(im,ie), SV(im+nbasis,ie)/),kind=4)
endif
enddo
enddo
endif
elseif(PINPT%axis_print_mag .eq. 'rh') then
if(.not.PINPT%flag_print_single) then
write(my_pid_energy) ne_found(is), kp(:), (E(ie+nband*(is-1)),ie=1,ne_found(is))
do ie = 1, ne_found(is)
do im = 1, nbasis
if(.not.flag_use_overlap) then
write(my_pid_energy) real( conjg(V(im,ie))*V(im,ie) + conjg(V(im+nbasis,ie))*V(im+nbasis,ie) )
else
write(my_pid_energy) real( conjg(V(im,ie))*SV(im,ie) + conjg(V(im+nbasis,ie))*SV(im+nbasis,ie) )
endif
enddo
enddo
elseif(PINPT%flag_print_single) then
write(my_pid_energy) ne_found(is), real(kp(:),kind=4), (real(E(ie+nband*(is-1)),kind=4),ie=1,ne_found(is))
do ie = 1, ne_found(is)
do im = 1, nbasis
if(.not. flag_use_overlap) then
write(my_pid_energy) real( conjg(V(im,ie))*V(im,ie)+conjg(V(im+nbasis,ie))*V(im+nbasis,ie), kind=4 )
else
write(my_pid_energy) real( conjg(V(im,ie))*SV(im,ie)+conjg(V(im+nbasis,ie))*SV(im+nbasis,ie), kind=4 )
endif
enddo
enddo
endif
endif
elseif(PINPT%ispinor .eq. 1) then
if(PINPT%axis_print_mag .eq. 'wf') then
if(.not.PINPT%flag_print_single) then
write(my_pid_energy) ne_found(is), kp(:), (E(ie+nband*(is-1)),ie=1,ne_found(is))
if(flag_use_overlap) then
write(my_pid_energyS) ne_found(is), kp(:), (E(ie+nband*(is-1)),ie=1,ne_found(is))
endif
do ie = 1+nband*(is-1), nband*(is-1)+ne_found(is)
do im = 1+nbasis*(is-1),nbasis*is
write(my_pid_energy) V(im,ie)
if(flag_use_overlap) then
write(my_pid_energyS) SV(im,ie)
endif
enddo
enddo
elseif(PINPT%flag_print_single) then
write(my_pid_energy) ne_found(is), real(kp(:),kind=4), (real(E(ie+nband*(is-1)),kind=4),ie=1,ne_found(is))
if(flag_use_overlap) then
write(my_pid_energyS) ne_found(is), real(kp(:),kind=4), (real(E(ie+nband*(is-1)),kind=4),ie=1,ne_found(is))
endif
do ie = 1+nband*(is-1), nband*(is-1)+ne_found(is)
do im = 1+nbasis*(is-1),nbasis*is
write(my_pid_energy) cmplx(V(im,ie), kind=4)
if(flag_use_overlap) then
write(my_pid_energyS) cmplx(SV(im,ie), kind=4)
endif
enddo
enddo
endif
elseif(PINPT%axis_print_mag .eq. 'rh') then
if(.not.PINPT%flag_print_single) then
write(my_pid_energy) ne_found(is), kp(:), (E(ie+nband*(is-1)),ie=1,ne_found(is))
do ie = 1+nband*(is-1),nband*(is-1)+ne_found(is)
do im = 1+nbasis*(is-1),nbasis*is
if(.not. flag_use_overlap) then
write(my_pid_energy) real(conjg(V(im,ie))*V(im,ie))
else
write(my_pid_energy) real(conjg(V(im,ie))*SV(im,ie))
endif
enddo
enddo
elseif(PINPT%flag_print_single) then
write(my_pid_energy) ne_found(is), real(kp(:),kind=4), (real(E(ie+nband*(is-1)),kind=4),ie=1,ne_found(is))
do ie = 1+nband*(is-1),nband*(is-1)+ne_found(is)
do im = 1+nbasis*(is-1),nbasis*is
if(.not. flag_use_overlap) then
write(my_pid_energy) real(conjg(V(im,ie))*V(im,ie),kind=4)
else
write(my_pid_energy) real(conjg(V(im,ie))*SV(im,ie),kind=4)
endif
enddo
enddo
endif
endif
endif
elseif(.not. flag_print_orbital) then
if(.not. PINPT%flag_print_single) then
write(my_pid_energy) ne_found(is), kp(:), (E(ie+nband*(is-1)),ie=1,ne_found(is))
elseif(PINPT%flag_print_single) then
write(my_pid_energy) ne_found(is), real(kp(:),kind=4), (real(E(ie+nband*(is-1)),kind=4),ie=1,ne_found(is))
endif
endif
close(my_pid_energy)
if(flag_use_overlap .and. PINPT%axis_print_mag .eq. 'wf') then
close(my_pid_energyS)
endif
enddo spinb
endif
return
endsubroutine
subroutine print_energy( PKPTS, E, E2, V, SV, neig, iband, nband, PINPT, PWGHT, flag_use_overlap, flag_final_step, suffix)
use parameters, only : pid_energy, incar, poscar, weight, kpoints, zi
use print_io
use mpi_setup
type(incar) :: PINPT
type(kpoints):: PKPTS
type(weight ):: PWGHT
integer*4 mysystem
integer*4 neig, iband, nband
integer*4 ie,is,ik,im
integer*4 nspin, nbasis
integer*4 ikmode
integer*4 init_e, fina_e
integer*4 ne_found(PINPT%nspin, PKPTS%nkpoint)
integer*4 irecl, i_continue, irec
real*8 kline(PKPTS%nkpoint),kpoint(3,PKPTS%nkpoint)
real*8, allocatable :: kpoint_(:,:)
logical flag_klinemode, flag_kgridmode, flag_print_orbital
real*8 E(nband*PINPT%nspin,PKPTS%nkpoint) ! TB energy
real*8 D(3,nband*PINPT%nspin,PKPTS%nkpoint) ! TB degeneracy info
real*8 E2(nband*PINPT%nspin,PKPTS%nkpoint) ! Target DFT energy
real*8 D2(3,nband*PINPT%nspin,PKPTS%nkpoint) ! Target DFT degeneracy info
complex*16 V(neig*PINPT%ispin,nband*PINPT%nspin,PKPTS%nkpoint)
complex*16 SV(neig*PINPT%ispin,nband*PINPT%nspin,PKPTS%nkpoint)
complex*16 c_up, c_dn
complex*16 sc_up, sc_dn
character*80 fname_header, fname_headerS !, suffix
character(*) suffix
character*80 fname, fnameS
integer*4 pid_energyS
character*6 kunit_
character*28 kmode
character*8 sigma
logical flag_print_energy_diff, flag_fit_degeneracy
logical flag_final_step ! if true, print D2 - D as well with D (only if flag_print_energy_diff and flag_fit_degeneracy)
! if false, print D only (only if flag_print_energy_diff and flag_fit_degeneracy)
! The purpose of this tag is to enable one can track the changes of D and its deviation from D2 (of DFT)
! during fitting, it does not save D2 - D during iteration step but after finishing iterations, it can save
! D2 - D. Which is only relevant to plot it, in my opinion.
logical flag_use_overlap
real*8 max_wt