-
Notifications
You must be signed in to change notification settings - Fork 0
/
ek_bulk.f90
executable file
·3419 lines (2799 loc) · 101 KB
/
ek_bulk.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
!> There are three modes to calculate the energy bands in the BZ
!> 1. Line mode : k points are defined in the KPATH_BULK, subroutine ek_bulk_line
!> 2. Plane mode: k points are defined in the KPLANE_BULK, subroutine ek_bulk_plane
!> 3. Cube mode : k points are defined in the KCUBE_BULK, subroutine ek_bulk_cube
subroutine ek_bulk_line
! Calculate bulk's energy bands using wannier TB method
! Line mode
! Copyright (c) 2010 QuanSheng Wu. All rights reserved.
use wmpi
use para
implicit none
integer :: ik, il, ig, io, i, j, knv3, ierr
real(dp) :: emin, emax, k(3)
character*40 :: filename
!> eigenvalues of H
real(Dp), allocatable :: W(:)
! Hamiltonian of bulk system
complex(Dp), allocatable :: Hamk_bulk(:, :)
! eigenectors of H
real(dp), allocatable :: eigv(:,:), eigv_mpi(:,:)
real(dp), allocatable :: weight(:,:,:), weight_mpi(:,:,:), weight_sum(:,:)
knv3= nk3_band
allocate(W(Num_wann))
allocate(Hamk_bulk(Num_wann, Num_wann))
allocate( eigv (Num_wann, knv3))
allocate( eigv_mpi(Num_wann, knv3))
allocate( weight (NumberofSelectedOrbitals_groups,Num_wann, knv3))
allocate( weight_mpi(NumberofSelectedOrbitals_groups,Num_wann, knv3))
allocate( weight_sum(Num_wann, knv3))
W = 0d0; Hamk_bulk = 0d0
eigv = 0d0; eigv_mpi= 0d0
weight = 0d0; weight_sum = 0d0; weight_mpi = 0d0
do ik= 1+cpuid, knv3, num_cpu
k = k3points(:, ik)
! calculation bulk hamiltonian
Hamk_bulk= 0d0
! generate bulk Hamiltonian
if (index(KPorTB, 'KP')/=0)then
call ham_bulk_kp(k, Hamk_bulk)
else
!> deal with phonon system
if (index(Particle,'phonon')/=0.and.LOTO_correction) then
call ham_bulk_LOTO(k, Hamk_bulk)
else
call ham_bulk_latticegauge(k, Hamk_bulk)
!call ham_bulk_atomicgauge(k, Hamk_bulk)
endif
endif
!> diagonalization by call zheev in lapack
W= 0d0
call eigensystem_c('V', 'U', Num_wann ,Hamk_bulk, W)
eigv(:, ik)= W
do j= 1, Num_wann !> band
do ig= 1, NumberofSelectedOrbitals_groups
do i= 1, NumberofSelectedOrbitals(ig)
io= Selected_WannierOrbitals(ig)%iarray(i)
weight(ig, j, ik)= weight(ig, j, ik)+ abs(Hamk_bulk(io, j))**2
enddo !i
enddo !ig
enddo !j
enddo !ik
#if defined (MPI)
call mpi_allreduce(eigv,eigv_mpi,size(eigv),&
mpi_dp,mpi_sum,mpi_cmw,ierr)
call mpi_allreduce(weight, weight_mpi,size(weight),&
mpi_dp,mpi_sum,mpi_cmw,ierr)
#else
eigv_mpi= eigv
weight_mpi= weight
#endif
if (index(Particle,'phonon')/=0) then
eigv_mpi = eigv_mpi - MINVAL(eigv_mpi)
endif
!> deal with phonon system
if (index(Particle,'phonon')/=0) then
do ik=1, knv3
do j=1, Num_wann
eigv_mpi(j, ik)= sqrt(abs(eigv_mpi(j, ik)))*sign(1d0, eigv_mpi(j, ik))
!eigv_mpi(j, ik)= (abs(eigv_mpi(j, ik)))*sign(1d0, eigv_mpi(j, ik))
enddo
enddo
endif
eigv_mpi= eigv_mpi/eV2Hartree
outfileindex= outfileindex+ 1
if (cpuid==0)then
do il= 1, nk3lines
if (il<10) then
write(filename, '(a,i1)')'bulkek.dat-segment', il
elseif (il>=10.and.il<100) then
write(filename, '(a,i2)')'bulkek.dat-segment', il
elseif (il>=100.and.il<1000) then
write(filename, '(a,i3)')'bulkek.dat-segment', il
endif
write(filename, '(5a)')'bulkek.dat-', trim(adjustl(k3line_name(il))), '-', trim(adjustl(k3line_name(il+1)))
outfileindex= outfileindex+ 1
open(unit=outfileindex, file=filename)
write(outfileindex, '(a, a6, a, a6)')'# segment between', k3line_name(il), ' and ', k3line_name(il+1)
write(outfileindex, '(a, 3f10.6)')'# kstart (fractional units)', k3line_start(:, il)*Angstrom2atomic
write(outfileindex, '(a, 3f10.6)')'# kend (fractional units)', k3line_end(:, il)*Angstrom2atomic
do i=1, Num_wann
do ik=1+(il-1)*Nk1, il*Nk1
write(outfileindex, '(2f19.9, 10000i5)')(k3len(ik)*Angstrom2atomic-k3len((il-1)*Nk1+1)*Angstrom2atomic),eigv_mpi(i, ik)
enddo
write(outfileindex, *)' '
enddo ! i
close(outfileindex)
enddo ! il
endif
outfileindex= outfileindex+ nk3lines+1
if (cpuid==0)then
open(unit=outfileindex, file='bulkek.dat')
write(outfileindex, &
"('#', a12, a14, 1X, '| projection', 100(3X,'|group', i2, ': A '))")&
'klen', 'E', (i, i=1, NumberofSelectedOrbitals_groups)
write(outfileindex, "('#column', i5, 200i16)")(i, i=1, 2+NumberofSelectedOrbitals_groups)
do i=1, Num_wann
do ik=1, knv3
write(outfileindex, '(200f16.9)')k3len(ik)*Angstrom2atomic,eigv_mpi(i, ik), &
weight_mpi(:, i, ik)
enddo
write(outfileindex, *)' '
enddo
close(outfileindex)
endif
outfileindex= outfileindex+ nk3lines+1
if (cpuid==0)then
open(unit=outfileindex, file='bulkek.dat-matlab')
write(outfileindex, '(2a19)')'% klen', 'E(n)'
do ik=1, knv3
write(outfileindex, '(2000f19.9)')k3len(ik)*Angstrom2atomic,eigv_mpi(:, ik)
enddo
close(outfileindex)
endif
!> minimum and maximum value of energy bands
emin= minval(eigv_mpi)-0.5d0
emax= maxval(eigv_mpi)+0.5d0
call generate_ek_kpath_gnu('bulkek.dat', 'bulkek.gnu', 'bulkek.pdf', &
emin, emax, knv3, Nk3lines, &
k3line_name, k3line_stop, k3len)
deallocate(W)
deallocate(Hamk_bulk)
deallocate( eigv )
deallocate( eigv_mpi)
deallocate( weight )
deallocate( weight_mpi)
deallocate( weight_sum)
return
end subroutine ek_bulk_line
subroutine ek_bulk_line_valley
! Calculate bulk's energy bands using wannier TB method
! Line mode
! Copyright (c) 2010 QuanSheng Wu. All rights reserved.
use wmpi
use para
implicit none
integer :: ik, il, ig, io, i, j, knv3, ierr
integer :: ie, ND, NDMAX, ie1, ie2
real(dp) :: emin, emax, k(3)
character*40 :: filename
complex(dp), external :: zdotc
!> eigenvalues of H
real(Dp), allocatable :: W(:)
! Hamiltonian of bulk system
complex(Dp), allocatable :: psi(:), vpsi(:), valley_k_nd(:, :), psi1(:), psi2(:)
complex(Dp), allocatable :: Hamk_bulk(:, :), valley_k(:, :)
complex(Dp), allocatable :: VL(:, :), VR(:, :), valley_eig(:)
logical, allocatable :: valley_plus(:, :), valley_plus_mpi(:, :)
! eigenectors of H
real(dp), allocatable :: eigv(:,:), eigv_mpi(:,:)
real(dp), allocatable :: weight(:,:), weight_mpi(:,:)
real(dp) :: tolde= 1E-4
NDMAX= 12
knv3= nk3_band
allocate(W(Num_wann))
allocate(Hamk_bulk(Num_wann, Num_wann))
allocate( eigv (Num_wann, knv3))
allocate( eigv_mpi(Num_wann, knv3))
allocate( weight (Num_wann, knv3))
allocate( weight_mpi(Num_wann, knv3))
allocate( psi(Num_wann), vpsi(Num_wann))
allocate( psi1(Num_wann), psi2(Num_wann))
allocate(valley_k(Num_wann, Num_wann))
allocate(valley_plus(Num_wann, knv3))
allocate(valley_plus_mpi(Num_wann, knv3))
allocate( valley_k_nd(NDMAX, NDMAX), valley_eig(NDMAX))
allocate( VL(NDMAX, NDMAX), VR(NDMAX, NDMAX))
W = 0d0; Hamk_bulk = 0d0
eigv = 0d0; eigv_mpi= 0d0
weight = 0d0; weight_mpi = 0d0
psi = 0d0; vpsi= 0d0
valley_k_nd= 0d0
valley_plus= .False.; valley_plus_mpi= .False.
do ik= 1+cpuid, knv3, num_cpu
k = k3points(:, ik)
! calculation bulk hamiltonian
Hamk_bulk= 0d0
call ham_bulk_atomicgauge(k, Hamk_bulk)
!> diagonalization by call zheev in lapack
W= 0d0
call eigensystem_c('V', 'U', Num_wann ,Hamk_bulk, W)
!> get the fourier transform of a valley operator
call valley_k_atomicgauge(k, valley_k)
eigv(:, ik)= W
!> check the degeneracy of each band
IE=1
do while (ie.le.Num_wann)
ND=1
if (ie+ND.le.Num_wann) then
do while ((ie+ND).le.Num_wann .and. (W(ie+ND)- W(ie)).lt.tolde)
if (ie+ND .ge. Num_wann) exit
ND= ND+1
enddo
endif
!> if the degeneracy is larger than 1, we need to calculate the matrix
valley_k_nd= 0d0
do ie1= 1, ND
psi1= hamk_bulk(:, IE+ie1-1)
do ie2= 1, ND
psi2= hamk_bulk(:, IE+ie2-1)
vpsi=0d0
call zgemv('N', Num_wann, Num_wann, One_complex, valley_k, Num_wann, psi2, 1, zzero, vpsi, 1)
valley_k_nd(ie1, ie2)= zdotc(Num_wann, psi1, 1, vpsi, 1)
enddo
!if (abs(W(IE+ie1-1)/eV2Hartree)<2d0) &
!write( *, '(a, 2i5, 200f8.3)') "ND, ie1: ", ND, ie1, valley_k_nd(ie1, 1:ND)
enddo
!> diagonalize the matrix
VL = 0d0; VR= 0d0
if (ND>1) then
call zgeev_sys(ND, valley_k_nd(1:ND, 1:ND), valley_eig(1:ND),'N',VL(1:ND, 1:ND),"V",VR(1:ND, 1:ND) )
do ie1= 1, ND
weight(IE+ie1-1, ik) = real(valley_eig(ie1))
enddo
else
valley_eig(1)= valley_k_nd(1, 1)
weight(IE, ik) = real(valley_k_nd(1, 1))
endif
! if (abs(W(IE+ie1-1)/eV2Hartree)<2d0) &
! write(*, '(a, 2i5, a, 200f8.3)'), 'ND, ie', ND, ie, ' valley_eig', real(valley_eig(1:ND))
! if (abs(W(IE+ie1-1)/eV2Hartree)<2d0) &
! print *, ' '
!> get new eigenvector
!do ie1= 1, ND
! psi= 0d0
! do ie2= 1, ND
! psi= psi+ VR(ie2, ie1)* ham_bulk(:, IE+ie2-1)
! enddo
!enddo
!> if the degeneracy is larger than 1, we need to calculate the matrix
IE= IE+ ND
enddo
do ie=1, Num_wann
if (weight(ie, ik)>0) valley_plus(ie, ik)=.true.
enddo
enddo ! ik
#if defined (MPI)
call mpi_allreduce(eigv,eigv_mpi,size(eigv),&
mpi_dp,mpi_sum,mpi_cmw,ierr)
call mpi_allreduce(weight, weight_mpi,size(weight),&
mpi_dp,mpi_sum,mpi_cmw,ierr)
call mpi_allreduce(valley_plus, valley_plus_mpi,size(valley_plus),&
mpi_logical,mpi_lor,mpi_cmw,ierr)
#else
eigv_mpi= eigv
weight_mpi= weight
valley_plus_mpi= valley_plus
#endif
eigv_mpi= eigv_mpi/eV2Hartree
outfileindex= outfileindex+ 1
if (cpuid==0)then
open(unit=outfileindex, file='bulkek.dat')
do i=1, Num_wann
do ik=1, knv3
write(outfileindex, '(200F16.8)')k3len(ik)*Angstrom2atomic,eigv_mpi(i, ik), &
weight_mpi(i, ik)
enddo
write(outfileindex, *)' '
enddo
close(outfileindex)
endif
outfileindex= outfileindex+ 1
if (cpuid==0)then
open(unit=outfileindex, file='bulkek_valley_plus.dat')
do i=1, Num_wann
do ik=1, knv3
if (valley_plus_mpi(i, ik)) then
write(outfileindex, '(200F16.8)')k3len(ik)*Angstrom2atomic,eigv_mpi(i, ik), &
weight_mpi(i, ik)
endif
enddo
write(outfileindex, *)' '
enddo
close(outfileindex)
endif
outfileindex= outfileindex+ 1
if (cpuid==0)then
open(unit=outfileindex, file='bulkek_valley_minus.dat')
do i=1, Num_wann
do ik=1, knv3
if (.not.valley_plus_mpi(i, ik)) then
write(outfileindex, '(200F16.8)')k3len(ik)*Angstrom2atomic,eigv_mpi(i, ik), &
weight_mpi(i, ik)
endif
enddo
write(outfileindex, *)' '
enddo
close(outfileindex)
endif
!> minimum and maximum value of energy bands
emin= minval(eigv_mpi)-0.5d0
emax= maxval(eigv_mpi)+0.5d0
call generate_ek_kpath_gnu('bulkek.dat', 'bulkek.gnu', 'bulkek.pdf', &
emin, emax, knv3, Nk3lines, &
k3line_name, k3line_stop, k3len)
deallocate(W)
deallocate(Hamk_bulk)
deallocate( eigv )
deallocate( eigv_mpi)
deallocate( weight )
deallocate( weight_mpi)
return
end subroutine ek_bulk_line_valley
!>> calculate energy band levels at given kpoints
subroutine ek_bulk_point_mode
use wmpi
use para
implicit none
integer :: ik, i, j, knv3, ierr
real(dp) :: k(3)
real(Dp), allocatable :: W(:)
! Hamiltonian of bulk system
complex(Dp), allocatable :: Hamk_bulk(:, :)
! eigen value of H
real(dp), allocatable :: eigv(:,:)
real(dp), allocatable :: eigv_mpi(:,:)
real(dp), allocatable :: weight(:,:,:)
real(dp), allocatable :: weight_mpi(:,:,:)
knv3= Nk3_point_mode
allocate( W(Num_wann))
allocate( eigv (Num_wann, knv3))
allocate( eigv_mpi(Num_wann, knv3))
allocate( Hamk_bulk (Num_wann,Num_wann))
allocate( weight (Num_wann,Num_wann, knv3))
allocate( weight_mpi(Num_wann,Num_wann, knv3))
eigv = 0d0
weight = 0d0
eigv_mpi= 0d0
weight_mpi = 0d0
do ik= 1+cpuid, Nk3_point_mode, num_cpu
if (cpuid==0) write(stdout, *)'# BulkBand in point mode, ik, knv3 ', ik, knv3
k = k3points_pointmode_direct(:, ik)
!> calculation bulk hamiltonian
Hamk_bulk= 0d0
call ham_bulk_latticegauge(k, Hamk_bulk)
!call ham_bulk (k, Hamk_bulk)
!> diagonalization by call zheev in lapack
W= 0d0
call eigensystem_c( 'V', 'U', Num_wann ,Hamk_bulk, W)
eigv(:, ik)= W
do i=1, Num_wann !> band
if (SOC==0) then
do j=1, Num_wann !> projector
weight(j, i, ik)= (abs(Hamk_bulk(j, i))**2)
enddo ! j
else
do j=1, Num_wann !> projector
weight(j, i, ik)= abs(Hamk_bulk(j, i))**2
enddo ! j
endif
enddo ! i
enddo ! ik
#if defined (MPI)
call mpi_allreduce(eigv,eigv_mpi,size(eigv),&
mpi_dp,mpi_sum,mpi_cmw,ierr)
call mpi_allreduce(weight, weight_mpi,size(weight),&
mpi_dp,mpi_sum,mpi_cmw,ierr)
#else
eigv_mpi= eigv
weight_mpi= weight
#endif
eigv_mpi= eigv_mpi/eV2Hartree
weight= weight_mpi/maxval(weight_mpi)*255d0
outfileindex= outfileindex+ 1
if (cpuid==0)then
open(unit=outfileindex, file='bulkek-pointsmode.dat')
do ik=1, Nk3_point_mode
write(outfileindex, '(a, i10)')'# No. of k point', ik
write(outfileindex, '("#",a9,100a10)')'k1', 'k2', 'k3', 'kx', 'ky', 'kz'
write(outfileindex, '(100f10.6)')k3points_pointmode_direct(:, ik), k3points_pointmode_cart(:, ik)
write(outfileindex, '("#", a11, a19, a)')'band index', 'Eigenvalue', ' orbital weights (0-255)'
do i=1, Num_wann
write(outfileindex, '(i12, f19.10, 1000i5)')i, eigv_mpi(i, ik), &
int(weight(:, i, ik))
enddo
write(outfileindex, *)' '
enddo
close(outfileindex)
endif
return
end subroutine ek_bulk_point_mode
subroutine ek_bulk_plane_C2yT
! Calculate bulk's energy band using wannier TB method for a given k plane
! Copyright (c) 2017 QuanSheng Wu. All rights reserved.
! Revised by QS.Wu on Sep 19 2017 @EPFL, Switzerland
use wmpi
use para
implicit none
integer :: ik, i, j, ib, ik1, ik2
integer :: knv3
integer :: ierr
integer :: nwann
integer :: nband_min
integer :: nband_max
integer :: nband_store
real(dp) :: time_start, time_end
real(Dp) :: k(3), kxyz(3)
real(Dp), allocatable :: W(:), D(:)
real(dp) :: kxmin, kxmax, kymin, kymax
real(dp), allocatable :: kxy(:,:)
real(dp), allocatable :: kxy_shape(:,:)
real(dp), allocatable :: kxy_plane(:,:)
! Hamiltonian of bulk system
complex(Dp), allocatable :: Hamk_bulk(:, :)
real(Dp), allocatable :: eigenvectors(:, :, :)
real(Dp), allocatable :: eigenvectors_mpi(:, :, :)
! eigen value of H
real(dp), allocatable :: gap(:)
real(dp), allocatable :: gap_mpi(:)
real(dp), allocatable :: eigv(:,:)
real(dp), allocatable :: eigv_mpi(:,:)
complex(dp), allocatable :: U(:, :)
complex(dp), allocatable :: sqrt_C2yT(:, :)
complex(dp), allocatable :: psi_tilde(:, :)
allocate(D(Num_wann), U(Num_wann, Num_wann))
D=0d0; U=0d0
!call TakagiFactor(Num_wann, C2yT, num_wann, D, U, num_wann, 0, 1)
!write(*, *)'real(C2yT)'
!do i=1, num_wann
! write(*, '(100f6.2)') real(C2yT(i, :))
!enddo
!write(*, *)'imag(C2yT)'
!do i=1, num_wann
! write(*, '(100f6.2)') aimag(C2yT(i, :))
!enddo
!write(*, *)'D'
!do i=1, num_wann
! write(*, '(100f6.2)') D(i)
!enddo
!write(*, *)'real(U)'
!do i=1, num_wann
! write(*, '(100f6.2)') real(U(i, :))
!enddo
!write(*, *)'imag(U)'
!do i=1, num_wann
! write(*, '(100f6.2)') aimag(U(i, :))
!enddo
!stop
if (.not.Symmetry_Import_calc) stop "Please set Symmetry_Import_calc=T in the input.dat"
allocate(sqrt_C2yT(Num_wann, Num_wann))
allocate(psi_tilde(Num_wann, Num_wann))
psi_tilde= 0d0
sqrt_C2yT= 0d0
do i=1, Num_wann
sqrt_C2yT(i, i)= sqrt(C2yT(i, i))
enddo
nband_min= Numoccupied- 1
nband_max= Numoccupied+ 2
if (nband_min< 1) nband_min= 1
if (nband_max> Num_wann) nband_max= Num_wann
nband_store= nband_max- nband_min+ 1
knv3= nk1*Nk2
allocate(W(Num_wann))
allocate(Hamk_bulk(Num_wann, Num_wann))
allocate(eigenvectors(Num_wann, 2, knv3))
allocate(eigenvectors_mpi(Num_wann, 2, knv3))
allocate( kxy(3, nk1*Nk2))
allocate( kxy_shape(3, nk1*Nk2))
allocate( kxy_plane(3, nk1*Nk2))
allocate( eigv (nband_store, knv3))
allocate( eigv_mpi(nband_store, knv3))
eigv = 0d0
eigv_mpi= 0d0
eigenvectors= 0d0
eigenvectors_mpi= 0d0
kxy=0d0
kxy_shape=0d0
kxy_plane=0d0
if (Nk1<2 .or. Nk2<2) stop 'ERROR: I refuse to do this job because you give me so small Nk1 and Nk2'
if (Numoccupied> Num_wann) stop 'ERROR: please set correct Numoccupied, it should be small than num_wann'
ik =0
do i= 1, Nk1
do j= 1, Nk2
ik =ik +1
kxy(:, ik)= K3D_start+ K3D_vec1*(i-1)/dble(Nk1-1)+ K3D_vec2*(j-1)/dble(Nk2-1) &
-(K3D_vec1+K3D_vec2)/2d0
kxy_shape(:, ik)= kxy(1, ik)* Origin_cell%Kua+ kxy(2, ik)* Origin_cell%Kub+ kxy(3, ik)* Origin_cell%Kuc
call rotate_k3_to_kplane(kxy_shape(:, ik), kxy_plane(:, ik))
enddo
enddo
time_start= 0d0
time_end= 0d0
do ik= 1+cpuid, knv3, num_cpu
if (cpuid==0.and. mod(ik/num_cpu, 500)==0) &
write(stdout, '(a, i12, a, i12, a, f10.2, a)') &
'ek_bulk_plane, ik ', ik, ' knv3',knv3, ' time left', &
(knv3-ik)*(time_end- time_start)/num_cpu, ' s'
call now(time_start)
k = kxy(:, ik)
call direct_cart_rec(k, kxyz)
! calculation bulk hamiltonian
Hamk_bulk= 0d0
call ham_bulk_atomicgauge(k, Hamk_bulk)
!> diagonalization by call zheev in lapack
W= 0d0
call eigensystem_c( 'V', 'U', Num_wann ,Hamk_bulk, W)
call mat_mul(Num_wann, sqrt_C2yT, Hamk_bulk, psi_tilde)
eigenvectors(:, 1:2, ik)= real(psi_tilde(:, Numoccupied:Numoccupied+1))
!write(*, *)'psi real'
!do i=1, num_wann
! write(*, '(100f6.2)') real(Hamk_bulk(i, :))
!enddo
!write(*, *)'psi imag'
!do i=1, num_wann
! write(*, '(100f6.2)') aimag(Hamk_bulk(i, :))
!enddo
!write(*, *)'psi_tilde real'
!do i=1, num_wann
! write(*, '(100f6.2)') real(psi_tilde(i, :))
!enddo
!write(*, *)'psi_tilde imag'
!do i=1, num_wann
! write(*, '(100f6.2)') aimag(psi_tilde(i, :))
!enddo
!stop
eigv(:, ik)= W(nband_min:nband_max)
call now(time_end)
enddo ! ik
#if defined (MPI)
call mpi_allreduce(eigv,eigv_mpi,size(eigv),&
mpi_dp,mpi_sum,mpi_cmw,ierr)
call mpi_allreduce(eigenvectors, eigenvectors_mpi,size(eigenvectors),&
mpi_dp,mpi_sum,mpi_cmw,ierr)
#else
eigv_mpi= eigv
#endif
eigv_mpi= eigv_mpi/eV2Hartree
!> write out the data in gnuplot format
outfileindex= outfileindex+ 1
if (cpuid==0)then
open(unit=outfileindex, file='eigenvectors_plane_band1.txt')
do i=1, num_wann
ik=0
do ik1=1, Nk1
do ik2=1, Nk2-1
ik=ik+1
write(outfileindex, '(2000f19.9)', advance='no')eigenvectors_mpi(i, 1, ik)
enddo
ik=ik+1
write(outfileindex, '(2000f19.9)', advance='yes')eigenvectors_mpi(i, 1, ik)
enddo
write(outfileindex, *)' '
enddo
close(outfileindex)
endif
!> write out the data in gnuplot format
outfileindex= outfileindex+ 1
if (cpuid==0)then
open(unit=outfileindex, file='eigenvectors_plane_band2.txt')
do i=1, num_wann
ik=0
do ik1=1, Nk1
do ik2=1, Nk2-1
ik=ik+1
write(outfileindex, '(2000f19.9)', advance='no')eigenvectors_mpi(i, 2, ik)
enddo
ik=ik+1
write(outfileindex, '(2000f19.9)', advance='yes')eigenvectors_mpi(i, 2, ik)
enddo
write(outfileindex, *)' '
enddo
close(outfileindex)
endif
!> write out the data in gnuplot format
outfileindex= outfileindex+ 1
if (cpuid==0)then
open(unit=outfileindex, file='bulkek_plane.dat')
write(outfileindex, '(1000a19)')'# kx', 'ky', 'kz', 'k1', 'k2', 'k3', &
'E(Numoccupied-1)', 'E(Numoccupied)' , 'E(Numoccupied+1)', 'E(Numoccupied+2)'
do ik=1, knv3
write(outfileindex, '(1000f19.9)')kxy_shape(:, ik)*Angstrom2atomic, &
kxy_plane(:, ik)*Angstrom2atomic, eigv_mpi(:, ik)
if (mod(ik, nk2)==0) write(outfileindex, *)' '
enddo
close(outfileindex)
endif
!> write out the data in gnuplot format
outfileindex= outfileindex+ 1
if (cpuid==0)then
open(unit=outfileindex, file='bulkek_plane-matlab.dat')
write(outfileindex, '(1000a19)')'% kx', 'ky', 'kz', 'k1', 'k2', &
'E(Numoccupied-1)', 'E(Numoccupied)' , 'E(Numoccupied+1)', 'E(Numoccupied+2)'
do ik=1, knv3
write(outfileindex, '(1000f19.9)')kxy_shape(:, ik)*Angstrom2atomic, &
kxy_plane(:, ik)*Angstrom2atomic, eigv_mpi(:, ik)
enddo
close(outfileindex)
endif
!> write out a script that can be used for gnuplot
outfileindex= outfileindex+ 1
if (cpuid==0)then
open(unit=outfileindex, file='bulkek_plane.gnu')
write(outfileindex, '(a)')"set encoding iso_8859_1"
write(outfileindex, '(a)')'#set terminal postscript enhanced color'
write(outfileindex, '(a)')"#set output 'bulkek_plane.eps'"
write(outfileindex, '(3a)')'set terminal png truecolor enhanced', &
' size 1920, 1680 font ",36"'
write(outfileindex, '(a)')"set output 'bulkek_plane.png'"
write(outfileindex, '(a)')'set palette rgbformulae 33,13,10'
write(outfileindex, '(a)')'unset key'
write(outfileindex, '(a)')'set pm3d'
write(outfileindex, '(a)')'set origin 0.2, 0'
write(outfileindex, '(a)')'set size 0.8, 1'
write(outfileindex, '(a)')'set border lw 3'
write(outfileindex, '(a)')'#set xtics font ",24"'
write(outfileindex, '(a)')'#set ytics font ",24"'
write(outfileindex, '(a)')'set size ratio -1'
write(outfileindex, '(a)')'set xtics'
write(outfileindex, '(a)')'set ytics'
write(outfileindex, '(a)')'set view 80,60'
write(outfileindex, '(a)')'set xlabel "k_1"'
write(outfileindex, '(a)')'set ylabel "k_2"'
write(outfileindex, '(a)')'set zlabel "Energy (eV)" rotate by 90'
write(outfileindex, '(a)')'unset colorbox'
write(outfileindex, '(a)')'set autoscale fix'
write(outfileindex, '(a)')'set pm3d interpolate 4,4'
write(outfileindex, '(2a)')"splot 'bulkek_plane.dat' u 4:5:8 w pm3d, \"
write(outfileindex, '(2a)')" 'bulkek_plane.dat' u 4:5:9 w pm3d"
close(outfileindex)
endif ! cpuid
deallocate(W)
deallocate(Hamk_bulk)
deallocate( kxy)
deallocate( kxy_shape)
deallocate( kxy_plane)
deallocate( eigv )
deallocate( eigv_mpi)
return
end subroutine ek_bulk_plane_C2yT
subroutine ek_bulk_plane
! Calculate bulk's energy band using wannier TB method for a given k plane
! Copyright (c) 2017 QuanSheng Wu. All rights reserved.
! Revised by QS.Wu on Sep 19 2017 @EPFL, Switzerland
! This subroutine is usefull for Dirac cone plot
use wmpi
use para
implicit none
integer :: ik, i, j, ib
integer :: knv3
integer :: ierr
integer :: nwann
integer :: nband_min
integer :: nband_max
integer :: nband_store
real(dp) :: time_start, time_end
real(Dp) :: k(3)
real(Dp), allocatable :: W(:)
real(dp) :: kxmin, kxmax, kymin, kymax
real(dp), allocatable :: kxy(:,:)
real(dp), allocatable :: kxy_shape(:,:)
real(dp), allocatable :: kxy_plane(:,:)
! Hamiltonian of bulk system
complex(Dp), allocatable :: Hamk_bulk(:, :)
! eigen value of H
real(dp), allocatable :: gap(:)
real(dp), allocatable :: gap_mpi(:)
real(dp), allocatable :: eigv(:,:)
real(dp), allocatable :: eigv_mpi(:,:)
nband_min= Numoccupied- 1
nband_max= Numoccupied+ 2
if (nband_min< 1) nband_min= 1
if (nband_max> Num_wann) nband_max= Num_wann
nband_store= nband_max- nband_min+ 1
knv3= nk1*Nk2
allocate(W(Num_wann))
allocate(Hamk_bulk(Num_wann, Num_wann))
allocate( kxy(3, nk1*Nk2))
allocate( kxy_shape(3, nk1*Nk2))
allocate( kxy_plane(3, nk1*Nk2))
allocate( eigv (nband_store, knv3))
allocate( eigv_mpi(nband_store, knv3))
eigv = 0d0
eigv_mpi= 0d0
kxy=0d0
kxy_shape=0d0
kxy_plane=0d0
if (Nk1<2 .or. Nk2<2) stop 'ERROR: I refuse to do this job because you give me so small Nk1 and Nk2'
if (Numoccupied> Num_wann) stop 'ERROR: please set correct Numoccupied, it should be small than num_wann'
ik =0
do i= 1, Nk1
do j= 1, Nk2
ik =ik +1
kxy(:, ik)= K3D_start+ K3D_vec1*(i-1)/dble(Nk1-1)+ K3D_vec2*(j-1)/dble(Nk2-1) &
-(K3D_vec1+K3D_vec2)/2d0
kxy_shape(:, ik)= kxy(1, ik)* Origin_cell%Kua+ kxy(2, ik)* Origin_cell%Kub+ kxy(3, ik)* Origin_cell%Kuc
call rotate_k3_to_kplane(kxy_shape(:, ik), kxy_plane(:, ik))
enddo
enddo
time_start= 0d0
time_end= 0d0
do ik= 1+cpuid, knv3, num_cpu
if (cpuid==0.and. mod(ik/num_cpu, 500)==0) &
write(stdout, '(a, i12, a, i12, a, f10.2, a)') &
'ek_bulk_plane, ik ', ik, ' knv3',knv3, ' time left', &
(knv3-ik)*(time_end- time_start)/num_cpu, ' s'
call now(time_start)
k = kxy(:, ik)
! generate bulk Hamiltonian
Hamk_bulk= 0d0
if (index(KPorTB, 'KP')/=0)then
call ham_bulk_kp(k, Hamk_bulk)
else
!> deal with phonon system
if (index(Particle,'phonon')/=0.and.LOTO_correction) then
call ham_bulk_LOTO(k, Hamk_bulk)
else
call ham_bulk_latticegauge(k, Hamk_bulk)
!call ham_bulk_atomicgauge(k, Hamk_bulk)
endif
endif
!> diagonalization by call zheev in lapack
W= 0d0
call eigensystem_c( 'N', 'U', Num_wann ,Hamk_bulk, W)
eigv(:, ik)= W(nband_min:nband_max)
call now(time_end)
enddo ! ik
#if defined (MPI)
call mpi_allreduce(eigv,eigv_mpi,size(eigv),&
mpi_dp,mpi_sum,mpi_cmw,ierr)
#else
eigv_mpi= eigv
#endif
if (index(Particle,'phonon')/=0) then
eigv_mpi = eigv_mpi - MINVAL(eigv_mpi)
endif
!> deal with phonon system
if (index(Particle,'phonon')/=0) then
do ik=1, knv3
do j=1, Num_wann
eigv_mpi(j, ik)= sqrt(abs(eigv_mpi(j, ik)))*sign(1d0, eigv_mpi(j, ik))
!eigv_mpi(j, ik)= (abs(eigv_mpi(j, ik)))*sign(1d0, eigv_mpi(j, ik))
enddo
enddo
endif
eigv_mpi= eigv_mpi/eV2Hartree
!> write out the data in gnuplot format
outfileindex= outfileindex+ 1
if (cpuid==0)then
open(unit=outfileindex, file='bulkek_plane.dat')
write(outfileindex, '(1000a19)')'# kx', 'ky', 'kz', 'k1', 'k2', 'k3', &
'E(Numoccupied-1)', 'E(Numoccupied)' , 'E(Numoccupied+1)', 'E(Numoccupied+2)'
do ik=1, knv3
write(outfileindex, '(1000f19.9)')kxy_shape(:, ik)*Angstrom2atomic, &
kxy_plane(:, ik)*Angstrom2atomic, eigv_mpi(:, ik)
if (mod(ik, nk2)==0) write(outfileindex, *)' '
enddo
close(outfileindex)
endif
!> write out the data in gnuplot format
outfileindex= outfileindex+ 1
if (cpuid==0)then
open(unit=outfileindex, file='bulkek_plane-matlab.dat')
write(outfileindex, '(1000a19)')'% kx', 'ky', 'kz', 'k1', 'k2', &
'E(Numoccupied-1)', 'E(Numoccupied)' , 'E(Numoccupied+1)', 'E(Numoccupied+2)'
do ik=1, knv3
write(outfileindex, '(1000f19.9)')kxy_shape(:, ik)*Angstrom2atomic, &
kxy_plane(:, ik)*Angstrom2atomic, eigv_mpi(:, ik)
enddo
close(outfileindex)
endif
!> write out a script that can be used for gnuplot
outfileindex= outfileindex+ 1
if (cpuid==0)then
open(unit=outfileindex, file='bulkek_plane.gnu')
write(outfileindex, '(a)')"set encoding iso_8859_1"
write(outfileindex, '(a)')'#set terminal postscript enhanced color'
write(outfileindex, '(a)')"#set output 'bulkek_plane.eps'"
write(outfileindex, '(3a)')'set terminal png truecolor enhanced', &
' size 1920, 1680 font ",36"'
write(outfileindex, '(a)')"set output 'bulkek_plane.png'"
write(outfileindex, '(a)')'set palette rgbformulae 33,13,10'
write(outfileindex, '(a)')'unset key'
write(outfileindex, '(a)')'set pm3d'
write(outfileindex, '(a)')'set origin 0.2, 0'
write(outfileindex, '(a)')'set size 0.8, 1'
write(outfileindex, '(a)')'set border lw 3'
write(outfileindex, '(a)')'#set xtics font ",24"'
write(outfileindex, '(a)')'#set ytics font ",24"'
write(outfileindex, '(a)')'set size ratio -1'
write(outfileindex, '(a)')'set ticslevel 0'
write(outfileindex, '(a)')'unset xtics'
write(outfileindex, '(a)')'unset ytics'
write(outfileindex, '(a)')'set view 80,60'
write(outfileindex, '(a)')'set xlabel "k_1"'
write(outfileindex, '(a)')'set ylabel "k_2"'
write(outfileindex, '(a)')'set zlabel "Energy (eV)" rotate by 90'
write(outfileindex, '(a)')'unset colorbox'
write(outfileindex, '(a)')'set autoscale fix'
write(outfileindex, '(a)')'set pm3d interpolate 4,4'
write(outfileindex, '(2a)')"splot 'bulkek_plane.dat' u 4:5:8 w pm3d, \"
write(outfileindex, '(2a)')" 'bulkek_plane.dat' u 4:5:9 w pm3d"
close(outfileindex)
endif ! cpuid
deallocate(W)
deallocate(Hamk_bulk)
deallocate( kxy)
deallocate( kxy_shape)
deallocate( kxy_plane)
deallocate( eigv )
deallocate( eigv_mpi)
return
end subroutine ek_bulk_plane
subroutine ek_bulk_cube
! Calculate bulk's energy band using wannier TB method for a given k cube
! Revised by QS.Wu on Feb 18 2019 @EPFL, Switzerland
! Under the licence GPL V3
use wmpi
use para
implicit none
integer :: ik, i, j, l, ib, knv3, ierr, nwann
integer :: nband_min, nband_max, nband_store