-
Notifications
You must be signed in to change notification settings - Fork 30
/
vaspberry_0.93.f
2804 lines (2596 loc) · 110 KB
/
vaspberry_0.93.f
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
! PROGRAM VASPBERRY Version 1.0 (f77) for VASP
! Written by Hyun-Jung Kim ([email protected], [email protected])
! Korea Institute for Advanced Study (KIAS)
! Dep. of Phys., Hanyang Univ.
! Copyright 2015. Hyun-Jung Kim All rights reserved.
! Evaluate berry curvature omega(k) for a closed loop on a small patches in k-space
! version 0.1 rough version. not working at all : 2015. Mar. 17. H.-J. Kim
! version 0.2 error fix for k-loop finding : 2015. Mar. 18. H.-J. Kim
! version 0.3 ISPIN=1, ISPIN=2 available : 2015. Mar. 23. H.-J. Kim
! version 0.4 sign error fix for BZ boundary : 2015. Mar. 25. H.-J. Kim
! version 0.5 bug fix for defining overlap matrix S(k,k') : 2015. Mar. 31. H.-J. Kim
! version 0.6 including the option for circular dichroism : 2015. Apr. 10. H.-J. Kim
! version 0.7 set coefficients type to be complex*16 and : 2015. Apr. 12. H.-J. Kim
! implemented simple routine for grid extending
! version 0.8 routine for velocity expectation value : 2015. Apr. 30. H.-J. Kim
! version 0.9 Z2 invariant via Fukui's method:not finished: 2016. Feb. 18. H.-J. Kim
! version 0.91 routine for wavefunction plot: -wf n -k k : 2016. May. 10. H.-J. Kim
! version 0.92 MPI parallelization implemented (MPI_USE) : 2016. Jun. 27. H.-J. Kim & Y.-K. Kang &
! (during the CAC workshop & KIAS) S.-B. Cho & S.-W. Kim &
! -for Berrycurvature & Chern number evaluation Y.-J. Choi & S.-H. Lee
! version 0.93 MPI parallelization implemented (MPI_USE) : 2016. Jun. 29. H.-J. Kim
! -for Z2 invariant evaluation (routines are modified..)
! routine change: routine for getting a determiant -> get_det : 2018, Jun. 28. H.-J. Kim
! last update and bug fixes : 2020. Jun. 10. by H.-J. Kim
!#define MPI_USE
!#undef MPI_USE
PROGRAM VASPBERRY
implicit real*8 (a-h, o-z)
complex*8, allocatable :: coeff(:)
complex*16, allocatable :: Siju(:,:),Sijd(:,:),Sijt(:,:)
complex*16, allocatable :: coeff1u(:),coeff1d(:)
complex*16, allocatable :: coeff2u(:),coeff2d(:)
complex*16,allocatable :: cener(:)
real*8, allocatable :: berrycurv(:),recivec(:,:),wklp(:,:,:)
real*8, allocatable :: berrycurv_tot(:)
real*8, allocatable :: rnfield(:),rnfield_tot(:)
real*8, allocatable :: recivec_tot(:,:)
real*8, allocatable :: recilat_tot(:,:)
real*8, allocatable :: xrecivec(:,:),xberrycurv(:),wklist(:,:)
real*8, allocatable :: wnklist(:,:),xrnfield(:)
real*8, allocatable :: recilat(:,:),xrecilat(:,:),occ(:)
real*8, allocatable :: selectivity(:),xselectivity(:)
real*16, allocatable :: ener(:)
integer, allocatable :: ig(:,:),nplist(:)
dimension selectivitymax(4),selectivitymin(4)
dimension a1(3),a2(3),a3(3),b1(3),b2(3),b3(3),a2xa3(3),sumkg(3)
dimension wk(3),wkk(3,5),ikk(5),isgg(2,5),npl(5),itr(5),itrim(5)
dimension nbmax(3),xb(3),berrymax(4),berrymin(4),ng(3),rs(3)
complex*16 csum1,csum2
complex*16 detS(4),detA,detLOOP
integer k, n, nkx, nky,nini,nmax,ns,ne,icd,ivel
character*75 filename,foname,fonameo,fbz,ver_tag,vdirec
data c/0.262465831d0/ ! constant c = 2m/hbar**2 [1/eV Ang^2]
real*8 rfield,rnnfield,rnnfield_bottom
real*8 rnnfield_tot,rnnfield_bottom_tot
real*8, allocatable:: w_half_klist(:,:)
integer, allocatable:: i_half_klist(:),i_trim_klist(:)
integer :: myrank, nprocs, ierr
#ifdef MPI_USE
include 'mpif.h'
INTEGER status(MPI_STATUS_SIZE)
call MPI_INIT(ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD,nprocs,ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD,myrank,ierr)
if(myrank == 0)then
write(6,*)"THIS IS ROOT:",myrank
endif
if(myrank == 0)then
time_1=MPI_WTIME()
endif
#else
nprocs=1
myrank=0
#endif
ver_tag="# VASPBERRY (Ver 1.0), by Hyun-Jung Kim. 2018. Aug. 23."
pi=4.*atan(1.)
!default settings
kperiod=2
nkx=12 ;nky=12
ispinor=2 ! 2 for soc, 1 for non-soc
itr=0;itrim=0
!!$* reading general informations
call parse(filename,foname,nkx,nky,ispinor,icd,ixt,fbz,
& ivel,iz,ihf,nini,nmax,kperiod,it,iskp,ine,ver_tag,
& iwf,ikwf,ng,rs,imag)
if(myrank == 0)call creditinfo(ver_tag)
if (ixt .ne. 0) call extendingBZ(fbz,ixt)
if (it .eq. 1) call test
if(myrank == 0)write(6,'(A,A)')"# File reading... : ",filename
call inforead(irecl,ispin,nk,nband,ecut,a1,a2,a3,filename)
if (ispin .eq. 2) ispinor=1
allocate(cener(nband),ener(nband),occ(nband))
if(myrank == 0)write(6,'(A,I9)')"# TOTAL RECORD LENGTH = ",irecl
allocate(wklist(3,nk),nplist(nk))
if(iz == 0)then
iz2=1 ! enhancing factor for variable size define in subroutines
allocate(berrycurv(nk))
allocate(berrycurv_tot(nk))
allocate(xberrycurv(kperiod*2*kperiod*2*nk))
elseif(iz == 1)then
iz2=4 ! enhancing factor for variable size define in subroutines
allocate(rnfield(nk*iz2),rnfield_tot(nk*iz2))
allocate(xrnfield(kperiod*2*kperiod*2*nk*iz2))
allocate(wnklist(3,nk*iz2))
allocate(w_half_klist(3,nk),i_half_klist(nk),i_trim_klist(nk))
endif
do ik=1,nk
ne_temp0=ne
ne=0
irec=3+(ik-1)*(nband+1)
read(10,rec=irec) xnplane, (wk(i),i=1,3),
& (cener(nn),occ(nn),nn=1,nband)
wklist(:,ik)=wk(:)
nplist(ik)=nint(xnplane)
do n=1,nband; ne=ne+nint(occ(n)); enddo
if(ik .gt. 1 .and. ne_temp0 .ne. ne .and. ine .eq. 0) then
write(6,*)"error. !!! ne(K) /= ne(K') !!!",ne,ne_temp0,ik ;stop
endif
enddo
if(ine .ne. 0) ne=ine ! manually specified ne ; useful for the semimetal
! check whether multi or single band calculation is performed
if((nini.eq.nmax))then
nini=nmax
else if(nmax .eq. 999999)then
if(ispin .eq. 2 .and. icd .eq. 0) nmax=ne
if(ispin .eq. 1 .and. ispinor .eq. 2 .and. icd .eq. 0) nmax=ne
if(ispin .eq. 1 .and. ispinor .eq. 1 .and. icd .eq. 0) nmax=ne/2
if(ispin .eq. 2 .and. icd .eq. 1)then;nini=ne;nmax=nini+1;endif
if(ispin .eq. 1 .and. ispinor .eq. 1 .and. icd .eq. 1)then
nini=ne/2
nmax=nini+1
endif
if(ispinor .eq. 2 .and. icd .eq. 1)then
nini=ne
nmax=nini+1
endif
endif ! check multi or single ?
ns=nmax-nini+1
if(myrank == 0)then
write(6,'(A,I6)') "# NELECT : ",ne*ispin
if (ispinor .eq. 2)then
write(6,'(A,I6,A)')"# ISPIN : ",ispin," (LSORBIT =.TRUE.)"
else
write(6,'(A,I6,A)')"# ISPIN : ",ispin," (LSORBIT =.FALSE.)"
endif
write(6,'(A,F11.4)') "# ENCUT (eV) : ",ecut
write(6,'(A,I6)') "# NKPOINT : ",nk
write(6,'(A,I6,A,I4)')"# K-GRID : ",nkx," X",nky
write(6,'(A,I6)') "# NBANDS : ",nband
write(6,'(A,3F13.6)') "# LATTVEC A1 : ",(a1(i),i=1,3)
write(6,'(A,3F13.6)') "# LATTVEC A2 : ",(a2(i),i=1,3)
write(6,'(A,3F13.6)') "# LATTVEC A3 : ",(a3(i),i=1,3)
endif
call recilatt(b1,b2,b3,dSkxky, a1,a2,a3,nkx,nky)
if(myrank == 0)then
write(6,'(A,3F13.6)') "# RECIVEC B1 : ",(b1(i),i=1,3)
write(6,'(A,3F13.6)') "# RECIVEC B2 : ",(b2(i),i=1,3)
write(6,'(A,3F13.6)') "# RECIVEC B3 : ",(b3(i),i=1,3)
if(icd.eq.0)write(6,'(A,F13.6)') "# dk^2 = |dk1xk2| = ",dSkxky
endif
call reciproperty(nbmax,npmax, b1,b2,b3,ecut,ispinor)
if(myrank == 0)then
write(6,'(A,I6)') "# NPMAX : ",npmax
write(6,'(A,I6)') "# NB1MAX : ",nbmax(1)
write(6,'(A,I6)') "# NB2MAX : ",nbmax(2)
write(6,'(A,I6)') "# NB3MAX : ",nbmax(3)
endif
#ifdef MPI_USE
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
#endif
allocate(ig(3,npmax))
allocate(coeff(npmax))
if(iz == 1)then
allocate(wklp(3,5,nk*4))
allocate(recivec(3,4*nk),recilat(3,4*nk))
allocate(recivec_tot(3,4*nk),recilat_tot(3,4*nk))
allocate(xrecivec(3,kperiod*2*kperiod*2*nk*4))
allocate(xrecilat(3,kperiod*2*kperiod*2*nk*4))
elseif(iz ==0)then
allocate(wklp(3,5,nk))
allocate(recivec(3,nk),recilat(3,nk))
allocate(recivec_tot(3,nk),recilat_tot(3,nk))
allocate(xrecivec(3,kperiod*2*kperiod*2*nk))
allocate(xrecilat(3,kperiod*2*kperiod*2*nk))
endif
nbtot=(2*nbmax(1)+2)*(2*nbmax(2)+2)*(2*nbmax(3)+1)
allocate(coeff1u(nbtot),coeff1d(nbtot))
allocate(coeff2u(nbtot),coeff2d(nbtot))
if(icd.eq.1) allocate(selectivity(nk))
if(icd.eq.1) allocate(xselectivity(kperiod*2*kperiod*2*nk))
if(ivel .eq. 1 .and. myrank==0) then
ni=nini
nj=nini
call vel_expectation(a1,a2,a3,b1,b2,b3,
& kperiod,nbmax,npmax,ecut,ispinor,ispin,nband,ne,nk,wklist,
& nplist,ni,nj,irecl,filename,foname)
endif
if(iwf .ge. 1 .and. myrank==0)then ! plotting wavefunction
ilp=1
ikk(ilp)=ikwf
iband=iwf
npl(ilp)=nplist(ikk(ilp))
wk(:)=wklist(:,ikk(ilp))
nx=ng(1)
ny=ng(2)
nz=ng(3)
if(nx*ny*nz .eq. 0) then
nx=nbmax(1)
ny=nbmax(2)
nz=nbmax(3)
endif
write(6,'(A)')" "
write(6,'(A)')"# Evaluating wavefunction..."
call wf_plot(a1,a2,a3,b1,b2,b3,wk,
& nbmax,npmax,ecut,ispinor,ispin,nband,nk,
& npl,nmax,irecl,filename,foname,nx,ny,nz,iband,ikk,1,rs,imag)
endif !iwf end
if(iz .eq. 1) then !get Z2 invariant using Fukui's method
del=1E-6 ! criterion for k-point find
call set_BZ_fukui(nnk,wnklist,w_half_klist,i_half_klist,
& i_trim_klist,nhf, ispin,wklist,del,nk,iz2)
do isp=1,ispin !ispin start
if(myrank == 0)then
write(6,*)" "
if(isp.eq.1.and.ispin.eq.2) write(6,'(A,I2)')"# SPIN : UP"
if(isp.eq.2.and.ispin.eq.2) write(6,'(A,I2)')"# SPIN : DN"
write(6,*)" "
endif
#ifdef MPI_USE
nk_rank=nnk/nprocs
nk_rank_mod=mod(nnk,nprocs)
if(myrank<nk_rank_mod)then
ink=myrank*(nk_rank+1)+1
ifk=(myrank+1)*(nk_rank+1)
else
ink=myrank*nk_rank+nk_rank_mod+1
ifk=(myrank+1)*nk_rank+nk_rank_mod
endif
recivec=0.
recilat=0.
recivec_tot=0.
recilat_tot=0.
rnnfield=0.
rnnfield_bottom=0.
rnnfield_tot=0.
rnnfield_bottom_tot=0.
rnfield_tot=0.
rnfield=0.
#else
ink=1;ifk=nnk
#endif
do ik=ink, ifk !ik - loop
call get_nfield(rnfield(ik),wklp, isp,ik,nk,nband,nkx,nky,
& wnklist,ihf,nplist,nnk,iz,ns,kperiod,
& w_half_klist,i_half_klist,i_trim_klist,nhf,
& nbmax,npmax,ecut,ispinor,ispin,ne,irecl,
& nmax,nini,b1,b2,b3,iz2)
if((wklp(2,1,ik)+wklp(2,3,ik))/2. .gt. -del .and.
& (wklp(2,1,ik)+wklp(2,3,ik))/2. .lt. 0.5+del ) then
rnnfield=rnnfield+rnfield(ik)
else
rnnfield_bottom=rnnfield_bottom+rnfield(ik)
endif
! write(6,'(A)')"#__________________________
! &________________________________ "
! write(6,'(A)')"# Berry Curvature F (A^-2) :
! & -Im[logPI_S(det(S(K_s,K_s+1)))]/dk^2"
! write(6,'(A)')"# N-field strength :
! & Sum_s{Im[log(det(S(K_s,k_s+1)))]}/2pi - F/2pi "
do j=1,3
recivec(j,ik)=(wklp(1,1,ik)+wklp(1,3,ik))*b1(j)*0.5+
& (wklp(2,1,ik)+wklp(2,3,ik))*b2(j)*0.5+
& (wklp(3,1,ik)+wklp(3,3,ik))*b3(j)*0.5
recilat(j,ik)=(wklp(j,1,ik)+wklp(j,3,ik))*0.5
enddo
! write(6,'(A)')"# kx ky kz(A^-1)
! & n-field strength ,IK"
! write(6,'(A,3F11.6,A,F8.3,I4,A)')'#',(recivec(i,ik),i=1,3),
! & " ",rnfield(ik),ik,"th-K"
enddo ! ik end
#ifdef MPI_USE
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
call MPI_REDUCE(rnnfield,rnnfield_tot,1,MPI_REAL8,
& MPI_SUM,0,MPI_COMM_WORLD,ierr)
call MPI_REDUCE(rnnfield_bottom,rnnfield_bottom_tot,1,MPI_REAL8,
& MPI_SUM,0,MPI_COMM_WORLD,ierr)
call MPI_REDUCE(rnfield,rnfield_tot,iz2*nk,MPI_REAL8,
& MPI_SUM,0,MPI_COMM_WORLD,ierr)
call MPI_REDUCE(recivec,recivec_tot,3*iz2*nk,MPI_REAL8,
& MPI_SUM,0,MPI_COMM_WORLD,ierr)
call MPI_REDUCE(recilat,recilat_tot,3*iz2*nk,MPI_REAL8,
& MPI_SUM,0,MPI_COMM_WORLD,ierr)
rnnfield=rnnfield_tot
rnnfield_bottom=rnnfield_bottom_tot
rnfield=rnfield_tot
recivec=recivec_tot
recilat=recilat_tot
#endif
if(myrank == 0)then
write(6,*)" "
write(6,'(A)')"# DONE!"
if(nini .eq. nmax) then
write(6,'(A,I4)')"# Z2 invariant for the BAND : ",nini
else
write(6,'(A,I4,A,I4)')"# Z2 invariant for the BANDS : ",nini
& ," - ",nmax
endif
write(6,'(A,I2)')"# Z2 Invariant = ",
& mod((nint(rnnfield)),2)
write(6,'(A,I2)')"# Z2 Invariant(bottom) = ",
& mod((nint(rnnfield_bottom)),2)
call get_ext_variable(xrecivec,xrecilat,xrnfield,kext,
& recivec,recilat,rnfield,nnk,kperiod,nk,iz2,
& b1,b2,b3) ! extending over exteded-BZ
call get_sorted_xrvari(xrecivec,xrecilat,xrnfield,
& kext,kperiod,nk,iz2) ! sorting
call write_result(isp,ispin,ispinor,fonameo,foname,filename,
& irecl,ecut,nk,nkx,nky,nband,b1,b2,b3,kperiod,
& dSkxky,nini,nmax,xrecivec,xrecilat,kext,
& xrnfield,rnnfield,rnnfield_bottom,0,0,
& iz2,icd,iz,ivel,nprocs)
endif !myrank ==0
enddo !ispin end
goto 9999
endif !if Z2 end
do isp=1,ispin ! ispin start
if(icd+ivel+iz+iwf.eq.0)then
chernnumber=0.
if(myrank == 0)then
write(6,*)" "
if(isp.eq.1.and.ispin.eq.2) write(6,'(A,I2)')"# SPIN : UP"
if(isp.eq.2.and.ispin.eq.2) write(6,'(A,I2)')"# SPIN : DN"
write(6,*)" "
endif
#ifdef MPI_USE
nk_rank=nk/nprocs
nk_rank_mod=mod(nk,nprocs)
if(myrank<nk_rank_mod)then
ink=myrank*(nk_rank+1)+1
ifk=(myrank+1)*(nk_rank+1)
else
ink=myrank*nk_rank+nk_rank_mod+1
ifk=(myrank+1)*nk_rank+nk_rank_mod
endif
if(myrank == 0)then
time_2=MPI_Wtime()
endif
berrycurv=0.
berrycurv_tot=0.
recivec=0.
recilat=0.
recivec_tot=0.
recilat_tot=0.
#else
ink=1;ifk=nk
#endif
do ik=ink, ifk !ik loop.
call klpfind(wkk, isp,ik,nk,nband,nkx,nky,0,0,iz,iz2) !k-loop(4pts) of ik-kpoint (K)
write(6,*)" "
write(6,490) ik,(wkk(i,1),i=1,3)
490 format("#* Closed loop for KPOINT",I5," : (",3F9.5," )")
call kindxfind(ikk,isgg,npl,itr,itrim, wklist,nplist,wkk,nk,
& nband,
& iz,w_half_klist,i_half_klist,0,0,iz2) !find K-loop for ik
write(6,500)(ikk(i),i=1,5)
500 format('# K1>K2>K3>K4>K5=K1 (k-index):',
& I5,' >',I5,' >',I5,' >',I5,' >',I5)
do j=1,5
write(6,510)j,(wkk(i,j),i=1,3),j,(isgg(i,j),i=1,2)
510 format('# K',I1,' = (',3F9.5,' )',
& ', G',I1,' = (n1,n2) = (',I1,',',I1,')')
enddo
wklp(:,:,ik) = wkk(:,:) ! closed loop (C) for each K : RECIVEC
!!$* get overlap matrix S_ij(k,k+1) over the C and PI_s [det S(k_s,k_s+1)], s=1,4
allocate(Siju(ns,ns),Sijd(ns,ns),Sijt(ns,ns))
do ilp=1,4 ! berry curvature loop for ik
Siju=(0.,0.)
Sijd=(0.,0.)
Sijt=(0.,0.)
! construct overlap matrix S_ij(ikk1,ikk2)
! write(6,570)ilp,ilp+1,ilp,ilp+1
! 570 format('# Constructing overlap matrix, S_ij(K',I1,',K',I1,
! & ') = <u_i,K',I1,'(r)|u_j,K',I1,'(r)>')
do ni=nini, nmax ! calculate upto valence band maximum
ncnt=0;coeff1u=(0.,0.);coeff1d=(0.,0.);coeff=(0.,0.)
read(10,rec=(3+(ikk(ilp)-1)*(nband+1)+
& nk*(nband+1)*(isp-1)+ni))(coeff(i),i=1,npl(ilp))
do ig3=0,2*nbmax(3); ig3p=ig3
if (ig3.gt.nbmax(3)) ig3p=ig3-2*nbmax(3)-1
do ig2=0,2*nbmax(2); ig2p=ig2
if (ig2.gt.nbmax(2)) ig2p=ig2-2*nbmax(2)-1
do ig1=0,2*nbmax(1); ig1p=ig1
if (ig1.gt.nbmax(1)) ig1p=ig1-2*nbmax(1)-1
call get_etot(etot, ilp,ni,b1,b2,b3,isgg,ig1p,ig2p,ig3p,
& ig1,ig2,ig3,wkk,itrim,itr)
if (etot.lt.ecut) then; ncnt=ncnt+1
call get_incnt(incnt, ilp,ni,ig1p,ig2p,ig3p,nbmax,
& itr,itrim,isgg,wkk)
if(ispinor .eq. 2)then
coeff1d(incnt)=coeff(ncnt+npl(ilp)/2)
endif
coeff1u(incnt)=coeff(ncnt)
endif
enddo !loop for ig1
enddo !loop for ig2
enddo !loop for ig3
if (ispinor*ncnt.ne.npl(ilp)) then
write(0,*) '*ni error - computed NPL=',2*ncnt,
& ' != input nplane=',npl(ilp);stop
endif
do nj=nini, nmax
ncnt=0;coeff2u=(0.,0.);coeff2d=(0.,0.);coeff=(0.,0.)
read(10,rec=(3+(ikk(ilp+1)-1)*(nband+1)+nk*(nband+1)*(isp-1)
& +nj)) (coeff(i),i=1,npl(ilp+1))
do ig3=0,2*nbmax(3); ig3p=ig3
if (ig3.gt.nbmax(3)) ig3p=ig3-2*nbmax(3)-1
do ig2=0,2*nbmax(2); ig2p=ig2
if (ig2.gt.nbmax(2)) ig2p=ig2-2*nbmax(2)-1
do ig1=0,2*nbmax(1); ig1p=ig1
if (ig1.gt.nbmax(1)) ig1p=ig1-2*nbmax(1)-1
call get_etot(etot,ilp+1,nj,b1,b2,b3,isgg,ig1p,ig2p,ig3p,
& ig1,ig2,ig3,wkk,itrim,itr)
if (etot.lt.ecut) then; ncnt=ncnt+1
call get_incnt(incnt, ilp+1,nj,ig1p,ig2p,ig3p,nbmax,
& itr,itrim,isgg,wkk)
if(ispinor .eq. 2)then
coeff2d(incnt)=coeff(ncnt+npl(ilp+1)/2)
endif
coeff2u(incnt)=coeff(ncnt)
endif
enddo !loop for ig1
enddo !loop for ig2
enddo !loop for ig3
if (ispinor*ncnt.ne.npl(ilp+1)) then
write(0,*) '*nj error - computed NPL=',2*ncnt,
& ' != input nplane=',npl(ilp+1);stop
endif
if(ispinor .eq. 2)then
Siju(ni-nmax+ns,nj-nmax+ns)=dot_product(coeff1u,coeff2u)
Sijd(ni-nmax+ns,nj-nmax+ns)=dot_product(coeff1d,coeff2d)
Sijt(ni-nmax+ns,nj-nmax+ns)=Siju(ni-nmax+ns,nj-nmax+ns)+
& Sijd(ni-nmax+ns,nj-nmax+ns)
else if (ispinor .eq. 1)then
Sijt(ni-nmax+ns,nj-nmax+ns)=dot_product(coeff1u,coeff2u)
endif
enddo ! loop for nj
enddo ! loop for ni
if(nini .eq. nmax)then ! get determinant : det(S)
detS(ilp)=Sijt(1,1)
else
! call getdetA(detA, Sijt,ns)
call get_det(detA, Sijt,ns)
detS(ilp)=detA;detA=(0.,0.)
endif
enddo ! loop for ilp
detLOOP=detS(1)*detS(2)*detS(3)*detS(4)
write(6,'(A)')"# "
write(6,600)detLOOP
600 format('#===>PI_S[det(S(K_s,K_s+1))] =',F16.8,' +',F16.8,' i')
berrycurv(ik)=-1.*aimag(log(detLOOP))/dSkxky
write(6,'(A)')"#__________________________
&________________________________ "
write(6,'(A)')"# Berry Curvature (A^-2) :
& -Im[logPI_S(det(S(K_s,K_s+1)))]/dk^2"
do j=1,3
recivec(j,ik)=(wklp(1,1,ik)+wklp(1,3,ik))*b1(j)*0.5+
& (wklp(2,1,ik)+wklp(2,3,ik))*b2(j)*0.5+
& (wklp(3,1,ik)+wklp(3,3,ik))*b3(j)*0.5
recilat(j,ik)=(wklp(j,1,ik)+wklp(j,3,ik))*0.5
enddo
write(6,'(A)')"# kx ky kz(A^-1)
& Berry Curvature (A^-2)"
write(6,'(A,3F11.6,A,F16.6)')'#',(recivec(i,ik),i=1,3)," ",
& berrycurv(ik)
#ifdef MPI_USE
chernnumber=chernnumber+berrycurv(ik)*dSkxky/(2.*pi)
#else
chernnumber=chernnumber+berrycurv(ik)*dSkxky/(2.*pi)
if (ik .eq. 1)then
berrymax(4)=berrycurv(ik)
berrymax(1)=recilat(1,ik)
berrymax(2)=recilat(2,ik)
berrymax(3)=recilat(3,ik)
berrymin(4)=berrycurv(ik)
berrymin(1)=recilat(1,ik)
berrymin(2)=recilat(2,ik)
berrymin(3)=recilat(3,ik)
else if (ik .ge. 2 .and. berrycurv(ik) .ge. berrymax(4))then
berrymax(4)=berrycurv(ik)
berrymax(1)=recilat(1,ik)
berrymax(2)=recilat(2,ik)
berrymax(3)=recilat(3,ik)
else if (ik .ge.2 .and. berrycurv(ik) .le. berrymin(4)) then
berrymin(4)=berrycurv(ik)
berrymin(1)=recilat(1,ik)
berrymin(2)=recilat(2,ik)
berrymin(3)=recilat(3,ik)
endif
#endif
deallocate(Sijt)
deallocate(Siju)
deallocate(Sijd)
enddo ! ik loop over
#ifdef MPI_USE
if(myrank == 0)then
time_3=MPI_Wtime()
write(6,*)" "
write(6,'(A)')"# DONE!"
endif
#else
write(6,*)" "
write(6,'(A)')"# DONE!"
#endif
!!$* SUMMARIZTION and output the results..
if(myrank == 0)then
write(6,'(A)')"# Chern Number is sum of Berry Curvature on 1BZ"
if(nini .eq. nmax) then
write(6,'(A,I4)')"# Chern Number for the BAND : ",nini
else
write(6,'(A,I4,A,I4)')"# Chern Number for the BANDS : ",nini
& ," - ",nmax
endif
endif
#ifdef MPI_USE
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
call MPI_REDUCE(chernnumber,chernnumber_tot,1,MPI_REAL8,
& MPI_SUM,0,MPI_COMM_WORLD,ierr)
call MPI_REDUCE(berrycurv,berrycurv_tot,nk,MPI_REAL8,
& MPI_SUM,0,MPI_COMM_WORLD,ierr)
call MPI_REDUCE(recivec,recivec_tot,3*nk,MPI_REAL8,
& MPI_SUM,0,MPI_COMM_WORLD,ierr)
call MPI_REDUCE(recilat,recilat_tot,3*nk,MPI_REAL8,
& MPI_SUM,0,MPI_COMM_WORLD,ierr)
chernnumber=chernnumber_tot
berrycurv(:)=berrycurv_tot(:)
recivec(:,:)=recivec_tot(:,:)
recilat(:,:)=recilat_tot(:,:)
#endif
if(myrank==0)then
write(6,'(A,F16.6)')"# Chern Number = ",chernnumber
endif
!KKKKK NOTE : START-sorting
if(myrank==0)then
call get_ext_variable(xrecivec,xrecilat,xberrycurv,kext,
& recivec,recilat,berrycurv,nk,kperiod,nk,iz2,
& b1,b2,b3) ! extending over exteded-BZ
call get_sorted_xrvari(xrecivec,xrecilat,xberrycurv,
& kext,kperiod,nk,iz2) ! sorting
#ifdef MPI_USE
call write_result(isp,ispin,ispinor,fonameo,foname,filename,
& irecl,ecut,nk,nkx,nky,nband,b1,b2,b3,kperiod,
& dSkxky,nini,nmax,xrecivec,xrecilat,kext,
& xberrycurv,chernnumber,0.,0,0,
& iz2,icd,iz,ivel,nprocs)
#else
call write_result(isp,ispin,ispinor,fonameo,foname,filename,
& irecl,ecut,nk,nkx,nky,nband,b1,b2,b3,kperiod,
& dSkxky,nini,nmax,xrecivec,xrecilat,kext,
& xberrycurv,chernnumber,0.,berrymax,berrymin,
& iz2,icd,iz,ivel,nprocs)
#endif
endif
!!! ######### LOOP for OPTICAL SELECTIVITY ###########################################
elseif(icd.eq.1 .and. myrank==0)then ! calculate optical selectivity
call optical_selectivity(selectivity,
& selectivitymax,selectivitymin,
& b1,b2,b3,wklist,isp,
& nband,ecut,ispinor,nplist,nbmax,npmax,nk,nini,nmax)
do ik=1,nk
do j=1,3
recivec(j,ik)=wklist(1,ik)*b1(j)+
& wklist(2,ik)*b2(j)+
& wklist(3,ik)*b3(j)
recilat(j,ik)=wklist(j,ik)
enddo
enddo
call get_ext_variable(xrecivec,xrecilat,xselectivity,kext,
& recivec,recilat,selectivity,nk,kperiod,nk,iz2,
& b1,b2,b3) ! extending over exteded-BZ
call get_sorted_xrvari(xrecivec,xrecilat,xselectivity,
& kext,kperiod,nk,iz2) ! sorting
call write_result(isp,ispin,ispinor,fonameo,foname,filename,
& irecl,ecut,nk,nkx,nky,nband,b1,b2,b3,kperiod,
& dSkxky,nini,nmax,xrecivec,xrecilat,kext,
& xselectivity,0,0.,selectivitymax,selectivitymin,
& iz2,icd,iz,ivel,nprocs)
endif !icd over
!!! ######### LOOP END for OPTICAL SELECTIVITY ###########################################
enddo !ispin loop over
if(iskp .eq. 1 .and. myrank==0)call write_special_kpoint(b1,b2,b3)
#ifdef MPI_USE
if(myrank==0)then
#endif
write(6,'(A)')"# DONE! "
do isp=1, ispin
if(isp .eq. 1 .and. ispinor .eq. 1 .and. ispin .eq. 2) then
write(6,'(A,A,A)')"# Results are summarized in ",TRIM(foname),
& ".UP.dat for spin-1"
else if (isp.eq.2 .and. ispinor.eq.1 .and. ispin.eq.2)then
write(6,'(A,A,A)')"# Results are summarized in ",
& TRIM(foname),".DN.dat for spin-2"
else if (isp .eq. 1 .and. ispinor .eq. 2) then
write(6,'(A,A,A)')"# Results are summarized in ",
& TRIM(foname),".dat"
else if (isp.eq.1 .and. ispinor.eq.1 .and. ispin.eq.1) then
write(6,'(A,A,A)')"# Results are summarized in ",
& TRIM(foname),".dat"
endif
enddo
#ifdef MPI_USE
endif
#endif
9999 if(myrank==0) write(6,*)"end of program"
#ifdef MPI_USE
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
#endif
deallocate(ig)
deallocate(coeff)
deallocate(coeff1u)
deallocate(coeff1d)
deallocate(coeff2u)
deallocate(coeff2d)
deallocate(recilat)
deallocate(recivec)
deallocate(xrecilat)
deallocate(xrecivec)
deallocate(wklp)
deallocate(wklist)
deallocate(cener)
deallocate(ener)
if(iz == 0)then
deallocate(berrycurv)
deallocate(berrycurv_tot)
deallocate(xberrycurv)
elseif(iz == 1)then
deallocate(rnfield)
deallocate(rnfield_tot)
deallocate(wnklist)
deallocate(xrnfield)
deallocate(i_trim_klist)
deallocate(i_half_klist)
deallocate(w_half_klist)
endif
deallocate(occ)
deallocate(nplist)
if(icd.eq.1)deallocate(selectivity)
if(icd.eq.1)deallocate(xselectivity)
#ifdef MPI_USE
if(myrank == 0 .and. iz+ivel+icd+iwf .eq. 0)then
time_4=MPI_Wtime()
write(6,*) "Data reading : ",time_2-time_1
write(6,*) "Parallel sequence : ",time_3-time_1
write(6,*) "End sequence : ",time_4-time_3
endif
call MPI_BARRIER(MPI_COMM_WORLD,ierr)
CALL MPI_FINALIZE(ierr)
#endif
end program
!!$* subroutine for writing results
subroutine write_result(isp,ispin,ispinor,fonameo,foname,filename,
& irecl,ecut,nk,nkx,nky,nband,b1,b2,b3,kperiod,
& dSkxky,nini,nmax,xrecivec,xrecilat,kext,
& xrvari,rvari,rvari2,rvari3,rvari4,
& iz2,icd,iz,ivel,nprocs)
implicit real*8 (a-h,o-z)
dimension b1(3),b2(3),b3(3)
real*8 xrecivec(3,kperiod*2*kperiod*2*nk*iz2)
real*8 xrecilat(3,kperiod*2*kperiod*2*nk*iz2)
real*8 xrvari(kperiod*2*kperiod*2*nk*iz2)
real*8 rvari,rvari2
real*8 xb(3),xtemp,rvari3(4),rvari4(4)
character*75 filename,foname,fonameo
if(isp .eq. 1 .and. ispinor .eq. 1 .and. ispin.eq.2) then
write(fonameo,'(A,A)')TRIM(foname),'.UP.dat'
else if (isp .eq. 2 .and. ispinor .eq. 1 .and. ispin.eq.2)then
write(fonameo,'(A,A)')TRIM(foname),'.DN.dat'
else if (isp .eq. 1 .and. ispinor .eq. 2) then
write(fonameo,'(A,A)')TRIM(foname),'.dat'
else if (isp .eq. 1 .and. ispinor .eq. 1 .and. ispin.eq.1)then
write(fonameo,'(A,A)')TRIM(foname),'.dat'
endif
open(32,file=fonameo,status='unknown')
write(32,'(A,I4,A)')"# Job running on ",nprocs," total cores"
write(32,'(A,A)') "# File reading... : ",filename
write(32,'(A,I9)')"# TOTAL RECORD LENGTH = ",irecl
if (ispinor .eq. 2)then
write(32,'(A,I6,A)')"# ISPIN : ",ispin,
& " (LSORBIT = .TRUE.)"
else
write(32,'(A,I6,A)')"# ISPIN : ",ispin,
& " (LSORBIT = .FALSE.)"
endif
write(32,'(A,F11.4)') "# ENCUT (eV) : ",ecut
write(32,'(A,I6)') "# NKPOINT : ",nk
write(32,'(A,I6,A,I4)')"# K-GRID : ",nkx," X",nky
write(32,'(A,I6)') "# NBANDS : ",nband
write(32,'(A,3F13.6)') "# RECIVEC B1 (A^-1): ",(b1(i),i=1,3)
write(32,'(A,3F13.6)') "# RECIVEC B2 : ",(b2(i),i=1,3)
write(32,'(A,3F13.6)') "# RECIVEC B3 : ",(b3(i),i=1,3)
write(32,'(A,F13.6)') "# dk^2 = |dk1xk2| = ",dSkxky
write(32,*)" "
if(nini .eq. nmax) then
if(iz == 1)then
write(32,'(A,I4)')"# Z2 invariant for the BAND : ",nini
elseif(iz+ivel+icd .eq. 0)then
write(32,'(A,I4)')"# Chern Number for the BAND : ",nmax
endif
else
if(iz == 1)then
write(32,'(A,I4,A,I4)')"# Z2 invariant for the BANDS : ",nini,
& " - ",nmax
elseif(iz+ivel+icd .eq. 0)then
write(32,'(A,I4,A,I4)')"# Chern Number for the BANDS : ",nini,
& " - ",nmax
endif
endif
if(iz == 1)then !Z2 INVARIANT
write(32,'(A,I2)')"# Z2 Invariant (top) = ",
& mod((nint(rvari)),2)
write(32,'(A,I2)')"# Z2 Invariant (bottom) = ",
& mod((nint(rvari2)),2)
write(32,'(A)')"# Berry Curvature F (A^-2) :
& -Im[logPI_S(det(S(K_s,K_s+1)))]/dk^2"
write(32,'(A)')"# N-field strength :
& Sum_s{Im[log(det(S(K_s,k_s+1)))]}/2pi - F/2pi "
write(32,'(A)')"# (cart) kx ky kz(A^-1)
& n-field strength , (recip)kx ky kz"
elseif(icd == 1)then !OPTICAL SELECTIVITY
write(32,'(A,I4,A,I4)')"# OPTICAL SELECTIVITY BETWEEN BANDS: ",
& nini," - ",nmax
write(32,'(A)')"# n(k,w_cv)= |P(k,s,cv,+)|^2 - |P(k,s,cv,-)|^2"
write(32,'(A)')"# ---------------------------------"
write(32,'(A)')"# |P(k,s,cv,+)|^2 + |P(k,s,cv,-)|^2"
write(32,'(A)')"# The TRANSITION MATRIX ELEMENT P ="
write(32,'(A)')"# P(k,s,cv,+ or -) = 1/sqrt(2)[p_x(k,cv,s) +
&(or -) i*p_y(k,cv,s)]"
write(32,'(A)')"# THE INTERBAND TRANSITION MATRIX p_x,y ="
write(32,'(A)')"# p_x,y(k,cv,s)=<psi(k,c,s)|-i*hbar*1/dx(y)|
&psi(k,v,s>"
write(32,'(A,4F16.6)')"# MAXVAL of SELECTIVITY at kx,ky,kz
&(in reci)= ",(rvari3(i),i=1,4)
write(32,'(A,4F16.6)')"# MINVAL of SELECTIVITY at kx,ky,kz
&(in reci)= ",(rvari4(i),i=1,4)
write(32,'(A)')"# (cart) kx ky kz(A^-1)
& selectivity(n(k)), (recip)kx ky kz"
else !BERRYCURVATURE
write(32,'(A)')"# Chern Number is sum of
&Berry Curvature over 1BZ"
write(32,'(A,F16.6)')"# Chern Number = ",rvari
write(32,'(A,4F16.6)')"# MAXVAL of BERRYCURV at kx,ky,kz
&(in reci)= ",(rvari3(i),i=1,4)
write(32,'(A,4F16.6)')"# MINVAL of BERRYCURV at kx,ky,kz
&(in reci)= ",(rvari4(i),i=1,4)
write(32,'(A)')"# Berry Curvature (A^-2) :
&-Im[logPI_S(det(S(K_s,K_s+1)))]/dk^2"
write(32,'(A)')"# (cart) kx ky kz(A^-1)
& Berry Curvature (A^-2), (recip)kx ky kz"
endif
do ik=1,kext
write(32,'(3F11.6,A,F11.6,A,3F11.6)')(xrecivec(i,ik),i=1,3),
& " ",xrvari(ik)," ",
& (xrecilat(i,ik),i=1,3)
enddo
close(32)
return
end subroutine write_result
!!$* subroutine for sorting
subroutine get_sorted_xrvari(xrecivec,xrecilat,xrvari,
& kext,kperiod,nk,iz2)
implicit real*8 (a-h,o-z)
real*8 xrecivec(3,kperiod*2*kperiod*2*nk*iz2)
real*8 xrecilat(3,kperiod*2*kperiod*2*nk*iz2)
real*8 xrvari(kperiod*2*kperiod*2*nk*iz2)
real*8 xb(3),xtemp
do k=kext-1,1,-1 ! sorting kx
do j=1,k
if(xrecivec(1,j+1) .gt. xrecivec(1,j))then
xb(:)=xrecivec(:,j)
xrecivec(:,j)=xrecivec(:,j+1)
xrecivec(:,j+1)=xb(:)
xb(:)=xrecilat(:,j)
xrecilat(:,j)=xrecilat(:,j+1)
xrecilat(:,j+1)=xb(:)
xtemp=xrvari(j)
xrvari(j)=xrvari(j+1)
xrvari(j+1)=xtemp
endif
enddo
enddo
do k=kext-1,1,-1 ! sorting ky
do j=1,k
if(xrecivec(1,j+1) .eq. xrecivec(1,j))then
if(xrecivec(2,j+1) .gt. xrecivec(2,j))then
xb(:)=xrecivec(:,j)
xrecivec(:,j)=xrecivec(:,j+1)
xrecivec(:,j+1)=xb(:)
xb(:)=xrecilat(:,j)
xrecilat(:,j)=xrecilat(:,j+1)
xrecilat(:,j+1)=xb(:)
xtemp=xrvari(j)
xrvari(j)=xrvari(j+1)
xrvari(j+1)=xtemp
endif
endif
enddo
enddo
return
end subroutine get_sorted_xrvari
!!$* subroutine for extending data_set distribution over extended BZ: 2D array
subroutine get_ext_variable(xrecivec,xrecilat,xrvari,kext,
& recivec,recilat,rvari,nnk,kperiod,nk,iz2,
& b1,b2,b3) !iz2=4 for z2, other 1
implicit real*8 (a-h,o-z)
real*8 recivec(3,nk*iz2),recilat(3,nk*iz2)
real*8 xrecivec(3,kperiod*2*kperiod*2*nk*iz2)
real*8 xrecilat(3,kperiod*2*kperiod*2*nk*iz2)
real*8 rvari(nk*iz2),xrvari(kperiod*2*kperiod*2*nk*iz2)
dimension b1(3),b2(3),b3(3)
kk=0 ! extend variable distribution over extended BZ
do ib2=-1*(kperiod-1)+1,kperiod
do ib1=-1*(kperiod-1)+1,kperiod
do ik=1,nnk
kk=kk+1
xrecivec(1,kk)=recivec(1,ik) +(ib1-1)*b1(1)+(ib2-1)*b2(1)
xrecivec(2,kk)=recivec(2,ik) +(ib1-1)*b1(2)+(ib2-1)*b2(2)
xrecivec(3,kk)=recivec(3,ik) +(ib1-1)*b1(3)+(ib2-1)*b2(3)
xrecilat(1,kk)=recilat(1,ik) +(ib1-1)
xrecilat(2,kk)=recilat(2,ik) +(ib2-1)
xrecilat(3,kk)=recilat(3,ik)
xrvari(kk)=rvari(ik)
kext=kk
enddo
enddo
enddo
return
end subroutine
!!$* subroutine for getting planewave coefficient for given k & n
subroutine wf_plot(a1,a2,a3,b1,b2,b3,wk,
& nbmax,npmax,ecut,ispinor,ispin,nband,nk,
& npl,nmax,irecl,filename,foname,nx,ny,nz,iband,ikk,ilp,rs,imag)
implicit real*8 (a-h,o-z)
complex*8 coeff(npmax),coeffi(npmax)
complex*16 csum(ispinor,nx*ny*nz)
real*8 wklist(3,nk),w_half_klist(3,nk),pi,pi2
real*8 recivec(3),recilat(3,nk*4)
dimension a1(3),a2(3),a3(3),b1(3),b2(3),b3(3),a2xa3(3),sumkg(3)
dimension wk(3),wkg(3),rr(3),rs(3)
dimension wkgr(npmax)
integer nplist(nk)
integer ikk(5),isgg(2,5),npl(5),itrim(5),ig(3,npmax)
integer nbmax(3)
integer nk,nband,npmax,kperiod,ispin,irecl
character*75 filename,foname,fonameo,fonameoi
data c/0.262465831d0/ ! constant c = 2m/hbar**2 [1/eV Ang^2]
pi=4.*atan(1.)
pi2=pi*2.
itrim=0
call vcross(a2xa3,a2,a3)
vol=dot_product(a1,a2xa3)
ngrid=nx*ny*nz
nline=int(ngrid/5.)
nresi=mod(ngrid,5)
do isp=1,ispin
write(6,'(A,I1)')" ##Processing for spin-",isp
csum=(0.,0.);wkgr=0.
write(fonameo,'(A,A,I1)')TRIM(foname),"-SPIN",isp
call get_coeff(coeff,isgg, 1, iband,ikk,npl,nband,nk,isp,
& npmax,itrim)
call plindx(ig,ncnt,ispinor,wk,b1,b2,b3,nbmax,npl(1),ecut,npmax)
open(unit=18,file=fonameo,status='unknown')
call write_CHGCAR_head(18,fonameo,ikk,isp,iband,a1,a2,a3,
& nx,ny,nz,rs)
if(imag .eq. 1)then
write(fonameoi,'(A,A,I1)')TRIM(foname),"-IM-SPIN",isp
open(unit=19,file=fonameoi,status='unknown')
call write_CHGCAR_head(19,fonameoi,ikk,isp,iband,a1,a2,a3,
& nx,ny,nz,rs)
endif
ii=0
do i3=1,nz
do i2=1,ny
do i1=1,nx
ii=ii+1
do iispinor=1,ispinor
wkgr(:)=(wk(1)+ig(1,1:ncnt))*((i1-1)/dble(nx)+rs(1)) +
& (wk(2)+ig(2,1:ncnt))*((i2-1)/dble(ny)+rs(2)) +
& (wk(3)+ig(3,1:ncnt))*((i3-1)/dble(nz)+rs(3))
csum(iispinor,ii)= sum(
& coeff(1+npl(1)/2*(iispinor-1):ncnt+npl(1)/2*(iispinor-1))*
& cdexp(pi2*cmplx(0.,1.)*wkgr(1:ncnt))*dsqrt(vol) )
enddo !ispinor
enddo !i1
enddo !i2
if(mod(i3,nint(nz/10.)) == 0 )then
write(6,'(F5.1,A)',advance='yes')i3/dble(nz)*100,"%"
endif
enddo !i3
do iline=1,nline
write(18,'(5E15.7)')(real(csum(1,(iline-1)*5+i)),i=1,5)
enddo
if(nresi .ge. 1)then
write(18,'(5E15.7)')(real(csum(1,(nline)*5+i)),i=1,nresi)
endif
if(ispinor .ge. 2)then
write(18,*)nx,ny,nz
do iline=1,nline
write(18,'(5E15.7)')(real(csum(2,(iline-1)*5+i)),i=1,5)
enddo
if(nresi .ge. 1)then
write(18,'(5E15.7)')(real(csum(2,(nline)*5+i)),i=1,nresi)
endif
endif
if(imag .eq. 1)then
do iline=1,nline
write(19,'(5E15.7)')(dimag(csum(1,(iline-1)*5+i)),i=1,5)
enddo
if(nresi .ge. 1)then
write(19,'(5E15.7)')(dimag(csum(1,(nline)*5+i)),i=1,nresi)
endif
if(ispinor .ge. 2)then
write(19,*)nx,ny,nz
do iline=1,nline
write(19,'(5E15.7)')(dimag(csum(2,(iline-1)*5+i)),i=1,5)
enddo
if(nresi .ge. 1)then