forked from wannier-developers/wannier90
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathberry.F90
2062 lines (1882 loc) · 84.9 KB
/
berry.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
!-*- mode: F90 -*-!
!------------------------------------------------------------!
! This file is distributed as part of the Wannier90 code and !
! under the terms of the GNU General Public License. See the !
! file `LICENSE' in the root directory of the Wannier90 !
! distribution, or http://www.gnu.org/copyleft/gpl.txt !
! !
! The webpage of the Wannier90 code is www.wannier.org !
! !
! The Wannier90 code is hosted on GitHub: !
! !
! https://github.com/wannier-developers/wannier90 !
!------------------------------------------------------------!
! ---------------------------------------------------------------
module w90_berry
!! This module computes various "Berry phase" related properties
!!
!! Key REFERENCES
!!
!! * WYSV06 = PRB 74, 195118 (2006) (anomalous Hall conductivity - AHC)
!! * YWVS07 = PRB 75, 195121 (2007) (Kubo frequency-dependent conductivity)
!! * LVTS12 = PRB 85, 014435 (2012) (orbital magnetization and AHC)
!! * CTVR06 = PRB 74, 024408 (2006) ( " " )
!! * IATS18 = arXiv:1804.04030 (2018) (nonlinear shift current)
!! * QZYZ18 = PRB 98, 214402 (2018) (spin Hall conductivity - SHC)
! ---------------------------------------------------------------
!
! * Undocumented, works for limited purposes only:
! reading k-points and weights from file
use w90_constants, only: dp
implicit none
private
public :: berry_main, berry_get_imf_klist, berry_get_imfgh_klist, berry_get_sc_klist, &
berry_get_shc_klist!, berry_alpha_S, berry_alpha_beta_S, berry_beta_S
! Pseudovector <--> Antisymmetric tensor
!
! x <--> (y,z)
! y <--> (z,x)
! z <--> (x,y)
!
integer, dimension(3), parameter :: alpha_A = (/2, 3, 1/)
integer, dimension(3), parameter :: beta_A = (/3, 1, 2/)
! Independent components of a symmetric tensor
!
! 1 <--> xx
! 2 <--> yy
! 3 <--> zz
! 4 <--> xy
! 5 <--> xz
! 6 <--> yz
!
integer, dimension(6), parameter :: alpha_S = (/1, 2, 3, 1, 1, 2/)
integer, dimension(6), parameter :: beta_S = (/1, 2, 3, 2, 3, 3/)
integer, dimension(6), parameter, public :: berry_alpha_S = alpha_S
integer, dimension(6), parameter, public:: berry_beta_S = beta_S
! integer, dimension(3,3) , parameter, public:: berry_alpha_beta_S= (/ (/1,4,5/), (/ 4,2,6 /) , (/ 5,6,3 /) /)
integer, parameter, public:: berry_alpha_beta_S(3, 3) = reshape((/1, 4, 5, 4, 2, 6, 5, 6, 3/), (/3, 3/))
!(/ (/1,4,5/), (/ 4,2,6 /) , (/ 5,6,3 /) /)
contains
!===========================================================!
! PUBLIC PROCEDURES !
!===========================================================!
subroutine berry_main
!============================================================!
! !
!! Computes the following quantities:
!! (i) Anomalous Hall conductivity (from Berry curvature)
!! (ii) Complex optical conductivity (Kubo-Greenwood) & JDOS
!! (iii) Orbital magnetization
!! (iv) Nonlinear shift current
!! (v) Spin Hall conductivity
! !
!============================================================!
use w90_constants, only: dp, cmplx_0, cmplx_i, elem_charge_SI, hbar_SI, &
eV_au, bohr, pi, eV_seconds
use w90_comms, only: on_root, num_nodes, my_node_id, comms_reduce
use w90_io, only: io_error, stdout, io_file_unit, seedname, &
io_stopwatch
use w90_postw90_common, only: nrpts, irvec, num_int_kpts_on_node, int_kpts, &
weight
use w90_parameters, only: timing_level, iprint, num_wann, berry_kmesh, &
berry_curv_adpt_kmesh, &
berry_curv_adpt_kmesh_thresh, &
wanint_kpoint_file, cell_volume, transl_inv, &
berry_task, berry_curv_unit, spin_decomp, &
kubo_nfreq, kubo_freq_list, nfermi, &
fermi_energy_list, shc_freq_scan, &
kubo_adpt_smr, kubo_adpt_smr_fac, &
kubo_adpt_smr_max, kubo_smr_fixed_en_width, &
scissors_shift, num_valence_bands, &
shc_bandshift, shc_bandshift_firstband, shc_bandshift_energyshift
use w90_get_oper, only: get_HH_R, get_AA_R, get_BB_R, get_CC_R, &
get_SS_R, get_SHC_R
real(kind=dp), allocatable :: adkpt(:, :)
! AHC and orbital magnetization, calculated for a list of Fermi levels
!
! First index labels J0,J1,J2 terms, second labels the Cartesian component
!
real(kind=dp) :: imf_k_list(3, 3, nfermi), imf_list(3, 3, nfermi), imf_list2(3, 3, nfermi)
real(kind=dp) :: img_k_list(3, 3, nfermi), img_list(3, 3, nfermi)
real(kind=dp) :: imh_k_list(3, 3, nfermi), imh_list(3, 3, nfermi)
real(kind=dp) :: ahc_list(3, 3, nfermi)
real(kind=dp) :: LCtil_list(3, 3, nfermi), ICtil_list(3, 3, nfermi), &
Morb_list(3, 3, nfermi)
real(kind=dp) :: imf_k_list_dummy(3, 3, nfermi) ! adaptive refinement of AHC
! shift current
real(kind=dp), allocatable :: sc_k_list(:, :, :)
real(kind=dp), allocatable :: sc_list(:, :, :)
! Complex optical conductivity, dividided into Hermitean and
! anti-Hermitean parts
!
complex(kind=dp), allocatable :: kubo_H_k(:, :, :)
complex(kind=dp), allocatable :: kubo_H(:, :, :)
complex(kind=dp), allocatable :: kubo_AH_k(:, :, :)
complex(kind=dp), allocatable :: kubo_AH(:, :, :)
! decomposition into up-up, down-down and spin-flip transitions
complex(kind=dp), allocatable :: kubo_H_k_spn(:, :, :, :)
complex(kind=dp), allocatable :: kubo_H_spn(:, :, :, :)
complex(kind=dp), allocatable :: kubo_AH_k_spn(:, :, :, :)
complex(kind=dp), allocatable :: kubo_AH_spn(:, :, :, :)
! Joint density of states
!
real(kind=dp), allocatable :: jdos_k(:)
real(kind=dp), allocatable :: jdos(:)
! decomposition into up-up, down-down and spin-flip transitions
real(kind=dp), allocatable :: jdos_k_spn(:, :)
real(kind=dp), allocatable :: jdos_spn(:, :)
! Spin Hall conductivity
real(kind=dp), allocatable :: shc_fermi(:), shc_k_fermi(:)
complex(kind=dp), allocatable :: shc_freq(:), shc_k_freq(:)
! for fermi energy scan, adaptive kmesh
real(kind=dp), allocatable :: shc_k_fermi_dummy(:)
real(kind=dp) :: kweight, kweight_adpt, kpt(3), kpt_ad(3), &
db1, db2, db3, fac, freq, rdum, vdum(3)
integer :: n, i, j, k, jk, ikpt, if, ispn, ierr, loop_x, loop_y, loop_z, &
loop_xyz, loop_adpt, adpt_counter_list(nfermi), ifreq, &
file_unit
character(len=24) :: file_name
logical :: eval_ahc, eval_morb, eval_kubo, not_scannable, eval_sc, eval_shc
logical :: ladpt_kmesh
if (nfermi == 0) call io_error( &
'Must specify one or more Fermi levels when berry=true')
if (timing_level > 1 .and. on_root) call io_stopwatch('berry: prelims', 1)
! Mesh spacing in reduced coordinates
!
db1 = 1.0_dp/real(berry_kmesh(1), dp)
db2 = 1.0_dp/real(berry_kmesh(2), dp)
db3 = 1.0_dp/real(berry_kmesh(3), dp)
eval_ahc = .false.
eval_morb = .false.
eval_kubo = .false.
eval_sc = .false.
eval_shc = .false.
if (index(berry_task, 'ahc') > 0) eval_ahc = .true.
if (index(berry_task, 'morb') > 0) eval_morb = .true.
if (index(berry_task, 'kubo') > 0) eval_kubo = .true.
if (index(berry_task, 'sc') > 0) eval_sc = .true.
if (index(berry_task, 'shc') > 0) eval_shc = .true.
! Wannier matrix elements, allocations and initializations
!
if (eval_ahc) then
call get_HH_R
call get_AA_R
imf_list = 0.0_dp
adpt_counter_list = 0
endif
if (eval_morb) then
call get_HH_R
call get_AA_R
call get_BB_R
call get_CC_R
imf_list2 = 0.0_dp
img_list = 0.0_dp
imh_list = 0.0_dp
endif
! List here berry_tasks that assume nfermi=1
!
not_scannable = eval_kubo .or. (eval_shc .and. shc_freq_scan)
if (not_scannable .and. nfermi .ne. 1) call io_error( &
'The berry_task(s) you chose require that you specify a single ' &
//'Fermi energy: scanning the Fermi energy is not implemented')
if (eval_kubo) then
call get_HH_R
call get_AA_R
allocate (kubo_H_k(3, 3, kubo_nfreq))
allocate (kubo_H(3, 3, kubo_nfreq))
allocate (kubo_AH_k(3, 3, kubo_nfreq))
allocate (kubo_AH(3, 3, kubo_nfreq))
allocate (jdos_k(kubo_nfreq))
allocate (jdos(kubo_nfreq))
kubo_H = cmplx_0
kubo_AH = cmplx_0
jdos = 0.0_dp
if (spin_decomp) then
call get_SS_R
allocate (kubo_H_k_spn(3, 3, 3, kubo_nfreq))
allocate (kubo_H_spn(3, 3, 3, kubo_nfreq))
allocate (kubo_AH_k_spn(3, 3, 3, kubo_nfreq))
allocate (kubo_AH_spn(3, 3, 3, kubo_nfreq))
allocate (jdos_k_spn(3, kubo_nfreq))
allocate (jdos_spn(3, kubo_nfreq))
kubo_H_spn = cmplx_0
kubo_AH_spn = cmplx_0
jdos_spn = 0.0_dp
endif
endif
if (eval_sc) then
call get_HH_R
call get_AA_R
allocate (sc_k_list(3, 6, kubo_nfreq))
allocate (sc_list(3, 6, kubo_nfreq))
sc_k_list = 0.0_dp
sc_list = 0.0_dp
endif
if (eval_shc) then
call get_HH_R
call get_AA_R
call get_SS_R
call get_SHC_R
if (shc_freq_scan) then
allocate (shc_freq(kubo_nfreq))
allocate (shc_k_freq(kubo_nfreq))
shc_freq = 0.0_dp
shc_k_freq = 0.0_dp
else
allocate (shc_fermi(nfermi))
allocate (shc_k_fermi(nfermi))
allocate (shc_k_fermi_dummy(nfermi))
shc_fermi = 0.0_dp
shc_k_fermi = 0.0_dp
!only used for fermiscan & adpt kmesh
shc_k_fermi_dummy = 0.0_dp
adpt_counter_list = 0
endif
endif
if (on_root) then
write (stdout, '(/,/,1x,a)') &
'Properties calculated in module b e r r y'
write (stdout, '(1x,a)') &
'------------------------------------------'
if (eval_ahc) write (stdout, '(/,3x,a)') &
'* Anomalous Hall conductivity'
if (eval_morb) write (stdout, '(/,3x,a)') '* Orbital magnetization'
if (eval_kubo) then
if (spin_decomp) then
write (stdout, '(/,3x,a)') &
'* Complex optical conductivity and its spin-decomposition'
write (stdout, '(/,3x,a)') &
'* Joint density of states and its spin-decomposition'
else
write (stdout, '(/,3x,a)') '* Complex optical conductivity'
write (stdout, '(/,3x,a)') '* Joint density of states'
endif
endif
if (eval_sc) write (stdout, '(/,3x,a)') &
'* Shift current'
if (eval_shc) then
write (stdout, '(/,3x,a)') '* Spin Hall Conductivity'
if (shc_freq_scan) then
write (stdout, '(/,3x,a)') ' Frequency scan'
else
write (stdout, '(/,3x,a)') ' Fermi energy scan'
endif
endif
if (transl_inv) then
if (eval_morb) &
call io_error('transl_inv=T disabled for morb')
write (stdout, '(/,1x,a)') &
'Using a translationally-invariant discretization for the'
write (stdout, '(1x,a)') &
'band-diagonal Wannier matrix elements of r, etc.'
endif
if (timing_level > 1) then
call io_stopwatch('berry: prelims', 2)
call io_stopwatch('berry: k-interpolation', 1)
endif
end if !on_root
! Set up adaptive refinement mesh
!
allocate (adkpt(3, berry_curv_adpt_kmesh**3), stat=ierr)
if (ierr /= 0) call io_error('Error in allocating adkpt in berry')
ikpt = 0
!
! OLD VERSION (only works correctly for odd grids including original point)
!
! do i=-(berry_curv_adpt_kmesh-1)/2,(berry_curv_adpt_kmesh-1)/2
! do j=-(berry_curv_adpt_kmesh-1)/2,(berry_curv_adpt_kmesh-1)/2
! do k=-(berry_curv_adpt_kmesh-1)/2,(berry_curv_adpt_kmesh-1)/2
! ikpt=ikpt+1
! adkpt(1,ikpt)=i*db1/berry_curv_adpt_kmesh
! adkpt(2,ikpt)=j*db2/berry_curv_adpt_kmesh
! adkpt(3,ikpt)=k*db3/berry_curv_adpt_kmesh
! end do
! end do
! end do
!
! NEW VERSION (both even and odd grids)
!
do i = 0, berry_curv_adpt_kmesh - 1
do j = 0, berry_curv_adpt_kmesh - 1
do k = 0, berry_curv_adpt_kmesh - 1
ikpt = ikpt + 1
adkpt(1, ikpt) = db1*((i + 0.5_dp)/berry_curv_adpt_kmesh - 0.5_dp)
adkpt(2, ikpt) = db2*((j + 0.5_dp)/berry_curv_adpt_kmesh - 0.5_dp)
adkpt(3, ikpt) = db3*((k + 0.5_dp)/berry_curv_adpt_kmesh - 0.5_dp)
end do
end do
end do
! Loop over interpolation k-points
!
if (wanint_kpoint_file) then
! NOTE: still need to specify berry_kmesh in the input file
!
! - Must use the correct nominal value in order to
! correctly set up adaptive smearing in kubo
if (on_root) write (stdout, '(/,1x,a,i10,a)') &
'Reading interpolation grid from file kpoint.dat: ', &
sum(num_int_kpts_on_node), ' points'
! Loop over k-points on the irreducible wedge of the Brillouin
! zone, read from file 'kpoint.dat'
!
do loop_xyz = 1, num_int_kpts_on_node(my_node_id)
kpt(:) = int_kpts(:, loop_xyz)
kweight = weight(loop_xyz)
kweight_adpt = kweight/berry_curv_adpt_kmesh**3
! .
! ***BEGIN COPY OF CODE BLOCK 1***
!
if (eval_ahc) then
call berry_get_imf_klist(kpt, imf_k_list)
do if = 1, nfermi
vdum(1) = sum(imf_k_list(:, 1, if))
vdum(2) = sum(imf_k_list(:, 2, if))
vdum(3) = sum(imf_k_list(:, 3, if))
if (berry_curv_unit == 'bohr2') vdum = vdum/bohr**2
rdum = sqrt(dot_product(vdum, vdum))
if (rdum > berry_curv_adpt_kmesh_thresh) then
adpt_counter_list(if) = adpt_counter_list(if) + 1
do loop_adpt = 1, berry_curv_adpt_kmesh**3
! Using imf_k_list here would corrupt values for other
! frequencies, hence dummy. Only if-th element is used
call berry_get_imf_klist(kpt(:) + adkpt(:, loop_adpt), &
imf_k_list_dummy)
imf_list(:, :, if) = imf_list(:, :, if) &
+ imf_k_list_dummy(:, :, if)*kweight_adpt
end do
else
imf_list(:, :, if) = imf_list(:, :, if) + imf_k_list(:, :, if)*kweight
endif
enddo
end if
if (eval_morb) then
call berry_get_imfgh_klist(kpt, imf_k_list, img_k_list, imh_k_list)
imf_list2 = imf_list2 + imf_k_list*kweight
img_list = img_list + img_k_list*kweight
imh_list = imh_list + imh_k_List*kweight
endif
if (eval_kubo) then
if (spin_decomp) then
call berry_get_kubo_k(kpt, kubo_H_k, kubo_AH_k, jdos_k, &
kubo_H_k_spn, kubo_AH_k_spn, jdos_k_spn)
else
call berry_get_kubo_k(kpt, kubo_H_k, kubo_AH_k, jdos_k)
endif
kubo_H = kubo_H + kubo_H_k*kweight
kubo_AH = kubo_AH + kubo_AH_k*kweight
jdos = jdos + jdos_k*kweight
if (spin_decomp) then
kubo_H_spn = kubo_H_spn + kubo_H_k_spn*kweight
kubo_AH_spn = kubo_AH_spn + kubo_AH_k_spn*kweight
jdos_spn = jdos_spn + jdos_k_spn*kweight
endif
endif
if (eval_sc) then
call berry_get_sc_klist(kpt, sc_k_list)
sc_list = sc_list + sc_k_list*kweight
end if
!
! ***END COPY OF CODE BLOCK 1***
if (eval_shc) then
! print calculation progress, from 0%, 10%, ... to 100%
! Note the 1st call to berry_get_shc_klist will be much longer
! than later calls due to the time spent on
! berry_get_shc_klist -> wham_get_eig_deleig ->
! pw90common_fourier_R_to_k -> ws_translate_dist
call berry_print_progress(loop_xyz, 1, num_int_kpts_on_node(my_node_id), 1)
if (.not. shc_freq_scan) then
call berry_get_shc_klist(kpt, shc_k_fermi=shc_k_fermi)
!check whether needs to tigger adpt kmesh or not.
!Since the calculated shc_k at one Fermi energy can be reused
!by all the Fermi energies, if we find out that at a specific
!Fermi energy shc_k(if) > thresh, then we will update shc_k at
!all the Fermi energies as well.
!This also avoids repeated calculation if shc_k(if) > thresh
!is satisfied at more than one Fermi energy.
ladpt_kmesh = .false.
!if adpt_kmesh==1, no need to calculate on the same kpt again.
!This happens if adpt_kmesh==1 while adpt_kmesh_thresh is low.
if (berry_curv_adpt_kmesh > 1) then
do if = 1, nfermi
rdum = abs(shc_k_fermi(if))
if (berry_curv_unit == 'bohr2') rdum = rdum/bohr**2
if (rdum > berry_curv_adpt_kmesh_thresh) then
adpt_counter_list(1) = adpt_counter_list(1) + 1
ladpt_kmesh = .true.
exit
endif
enddo
else
ladpt_kmesh = .false.
end if
if (ladpt_kmesh) then
do loop_adpt = 1, berry_curv_adpt_kmesh**3
!Using shc_k here would corrupt values for other
!kpt, hence dummy. Only if-th element is used.
call berry_get_shc_klist(kpt(:) + adkpt(:, loop_adpt), &
shc_k_fermi=shc_k_fermi_dummy)
shc_fermi = shc_fermi + kweight_adpt*shc_k_fermi_dummy
end do
else
shc_fermi = shc_fermi + kweight*shc_k_fermi
end if
else ! freq_scan, no adaptive kmesh
call berry_get_shc_klist(kpt, shc_k_freq=shc_k_freq)
shc_freq = shc_freq + kweight*shc_k_freq
end if
end if
end do !loop_xyz
else ! Do not read 'kpoint.dat'. Loop over a regular grid in the full BZ
kweight = db1*db2*db3
kweight_adpt = kweight/berry_curv_adpt_kmesh**3
do loop_xyz = my_node_id, PRODUCT(berry_kmesh) - 1, num_nodes
loop_x = loop_xyz/(berry_kmesh(2)*berry_kmesh(3))
loop_y = (loop_xyz - loop_x*(berry_kmesh(2) &
*berry_kmesh(3)))/berry_kmesh(3)
loop_z = loop_xyz - loop_x*(berry_kmesh(2)*berry_kmesh(3)) &
- loop_y*berry_kmesh(3)
kpt(1) = loop_x*db1
kpt(2) = loop_y*db2
kpt(3) = loop_z*db3
! ***BEGIN CODE BLOCK 1***
!
if (eval_ahc) then
call berry_get_imf_klist(kpt, imf_k_list)
do if = 1, nfermi
vdum(1) = sum(imf_k_list(:, 1, if))
vdum(2) = sum(imf_k_list(:, 2, if))
vdum(3) = sum(imf_k_list(:, 3, if))
if (berry_curv_unit == 'bohr2') vdum = vdum/bohr**2
rdum = sqrt(dot_product(vdum, vdum))
if (rdum > berry_curv_adpt_kmesh_thresh) then
adpt_counter_list(if) = adpt_counter_list(if) + 1
do loop_adpt = 1, berry_curv_adpt_kmesh**3
! Using imf_k_list here would corrupt values for other
! frequencies, hence dummy. Only if-th element is used
call berry_get_imf_klist(kpt(:) + adkpt(:, loop_adpt), &
imf_k_list_dummy)
imf_list(:, :, if) = imf_list(:, :, if) &
+ imf_k_list_dummy(:, :, if)*kweight_adpt
end do
else
imf_list(:, :, if) = imf_list(:, :, if) + imf_k_list(:, :, if)*kweight
endif
enddo
end if
if (eval_morb) then
call berry_get_imfgh_klist(kpt, imf_k_list, img_k_list, imh_k_list)
imf_list2 = imf_list2 + imf_k_list*kweight
img_list = img_list + img_k_list*kweight
imh_list = imh_list + imh_k_List*kweight
endif
if (eval_kubo) then
if (spin_decomp) then
call berry_get_kubo_k(kpt, kubo_H_k, kubo_AH_k, jdos_k, &
kubo_H_k_spn, kubo_AH_k_spn, jdos_k_spn)
else
call berry_get_kubo_k(kpt, kubo_H_k, kubo_AH_k, jdos_k)
endif
kubo_H = kubo_H + kubo_H_k*kweight
kubo_AH = kubo_AH + kubo_AH_k*kweight
jdos = jdos + jdos_k*kweight
if (spin_decomp) then
kubo_H_spn = kubo_H_spn + kubo_H_k_spn*kweight
kubo_AH_spn = kubo_AH_spn + kubo_AH_k_spn*kweight
jdos_spn = jdos_spn + jdos_k_spn*kweight
endif
endif
if (eval_sc) then
call berry_get_sc_klist(kpt, sc_k_list)
sc_list = sc_list + sc_k_list*kweight
end if
!
! ***END CODE BLOCK 1***
if (eval_shc) then
! print calculation progress, from 0%, 10%, ... to 100%
! Note the 1st call to berry_get_shc_klist will be much longer
! than later calls due to the time spent on
! berry_get_shc_klist -> wham_get_eig_deleig ->
! pw90common_fourier_R_to_k -> ws_translate_dist
call berry_print_progress(loop_xyz, my_node_id, PRODUCT(berry_kmesh) - 1, num_nodes)
if (.not. shc_freq_scan) then
call berry_get_shc_klist(kpt, shc_k_fermi=shc_k_fermi)
!check whether needs to tigger adpt kmesh or not.
!Since the calculated shc_k at one Fermi energy can be reused
!by all the Fermi energies, if we find out that at a specific
!Fermi energy shc_k(if) > thresh, then we will update shc_k at
!all the Fermi energies as well.
!This also avoids repeated calculation if shc_k(if) > thresh
!is satisfied at more than one Fermi energy.
ladpt_kmesh = .false.
!if adpt_kmesh==1, no need to calculate on the same kpt again.
!This happens if adpt_kmesh==1 while adpt_kmesh_thresh is low.
if (berry_curv_adpt_kmesh > 1) then
do if = 1, nfermi
rdum = abs(shc_k_fermi(if))
if (berry_curv_unit == 'bohr2') rdum = rdum/bohr**2
if (rdum > berry_curv_adpt_kmesh_thresh) then
adpt_counter_list(1) = adpt_counter_list(1) + 1
ladpt_kmesh = .true.
exit
endif
enddo
else
ladpt_kmesh = .false.
end if
if (ladpt_kmesh) then
do loop_adpt = 1, berry_curv_adpt_kmesh**3
!Using shc_k here would corrupt values for other
!kpt, hence dummy. Only if-th element is used.
call berry_get_shc_klist(kpt(:) + adkpt(:, loop_adpt), &
shc_k_fermi=shc_k_fermi_dummy)
shc_fermi = shc_fermi + kweight_adpt*shc_k_fermi_dummy
end do
else
shc_fermi = shc_fermi + kweight*shc_k_fermi
end if
else ! freq_scan, no adaptive kmesh
call berry_get_shc_klist(kpt, shc_k_freq=shc_k_freq)
shc_freq = shc_freq + kweight*shc_k_freq
end if
end if
end do !loop_xyz
end if !wanint_kpoint_file
! Collect contributions from all nodes
!
if (eval_ahc) then
call comms_reduce(imf_list(1, 1, 1), 3*3*nfermi, 'SUM')
call comms_reduce(adpt_counter_list(1), nfermi, 'SUM')
endif
if (eval_morb) then
call comms_reduce(imf_list2(1, 1, 1), 3*3*nfermi, 'SUM')
call comms_reduce(img_list(1, 1, 1), 3*3*nfermi, 'SUM')
call comms_reduce(imh_list(1, 1, 1), 3*3*nfermi, 'SUM')
end if
if (eval_kubo) then
call comms_reduce(kubo_H(1, 1, 1), 3*3*kubo_nfreq, 'SUM')
call comms_reduce(kubo_AH(1, 1, 1), 3*3*kubo_nfreq, 'SUM')
call comms_reduce(jdos(1), kubo_nfreq, 'SUM')
if (spin_decomp) then
call comms_reduce(kubo_H_spn(1, 1, 1, 1), 3*3*3*kubo_nfreq, 'SUM')
call comms_reduce(kubo_AH_spn(1, 1, 1, 1), 3*3*3*kubo_nfreq, 'SUM')
call comms_reduce(jdos_spn(1, 1), 3*kubo_nfreq, 'SUM')
endif
endif
if (eval_sc) then
call comms_reduce(sc_list(1, 1, 1), 3*6*kubo_nfreq, 'SUM')
end if
if (eval_shc) then
if (shc_freq_scan) then
call comms_reduce(shc_freq(1), kubo_nfreq, 'SUM')
else
call comms_reduce(shc_fermi(1), nfermi, 'SUM')
call comms_reduce(adpt_counter_list(1), nfermi, 'SUM')
end if
end if
if (on_root) then
if (timing_level > 1) call io_stopwatch('berry: k-interpolation', 2)
write (stdout, '(1x,a)') ' '
if (eval_ahc .and. berry_curv_adpt_kmesh .ne. 1) then
if (.not. wanint_kpoint_file) write (stdout, '(1x,a28,3(i0,1x))') &
'Regular interpolation grid: ', berry_kmesh
write (stdout, '(1x,a28,3(i0,1x))') 'Adaptive refinement grid: ', &
berry_curv_adpt_kmesh, berry_curv_adpt_kmesh, berry_curv_adpt_kmesh
if (berry_curv_unit == 'ang2') then
write (stdout, '(1x,a28,a17,f6.2,a)') &
'Refinement threshold: ', 'Berry curvature >', &
berry_curv_adpt_kmesh_thresh, ' Ang^2'
elseif (berry_curv_unit == 'bohr2') then
write (stdout, '(1x,a28,a17,f6.2,a)') &
'Refinement threshold: ', 'Berry curvature >', &
berry_curv_adpt_kmesh_thresh, ' bohr^2'
endif
if (nfermi == 1) then
if (wanint_kpoint_file) then
write (stdout, '(1x,a30,i5,a,f5.2,a)') &
' Points triggering refinement: ', &
adpt_counter_list(1), '(', &
100*real(adpt_counter_list(1), dp) &
/sum(num_int_kpts_on_node), '%)'
else
write (stdout, '(1x,a30,i5,a,f5.2,a)') &
' Points triggering refinement: ', &
adpt_counter_list(1), '(', &
100*real(adpt_counter_list(1), dp)/product(berry_kmesh), '%)'
endif
endif
elseif (eval_shc) then
if (berry_curv_adpt_kmesh .ne. 1) then
if (.not. wanint_kpoint_file) write (stdout, '(1x,a28,3(i0,1x))') &
'Regular interpolation grid: ', berry_kmesh
if (.not. shc_freq_scan) then
write (stdout, '(1x,a28,3(i0,1x))') &
'Adaptive refinement grid: ', &
berry_curv_adpt_kmesh, berry_curv_adpt_kmesh, berry_curv_adpt_kmesh
if (berry_curv_unit == 'ang2') then
write (stdout, '(1x,a28,f12.2,a)') &
'Refinement threshold: ', &
berry_curv_adpt_kmesh_thresh, ' Ang^2'
elseif (berry_curv_unit == 'bohr2') then
write (stdout, '(1x,a28,f12.2,a)') &
'Refinement threshold: ', &
berry_curv_adpt_kmesh_thresh, ' bohr^2'
endif
if (wanint_kpoint_file) then
write (stdout, '(1x,a30,i8,a,f6.2,a)') &
' Points triggering refinement: ', adpt_counter_list(1), '(', &
100*real(adpt_counter_list(1), dp)/sum(num_int_kpts_on_node), '%)'
else
write (stdout, '(1x,a30,i8,a,f6.2,a)') &
' Points triggering refinement: ', adpt_counter_list(1), '(', &
100*real(adpt_counter_list(1), dp)/product(berry_kmesh), '%)'
endif
endif
else
if (.not. wanint_kpoint_file) write (stdout, '(1x,a20,3(i0,1x))') &
'Interpolation grid: ', berry_kmesh(1:3)
endif
write (stdout, '(a)') ''
if (kubo_adpt_smr) then
write (stdout, '(1x,a)') 'Using adaptive smearing'
write (stdout, '(7x,a,f8.3)') 'adaptive smearing prefactor ', kubo_adpt_smr_fac
write (stdout, '(7x,a,f8.3,a)') 'adaptive smearing max width ', kubo_adpt_smr_max, ' eV'
else
write (stdout, '(1x,a)') 'Using fixed smearing'
write (stdout, '(7x,a,f8.3,a)') 'fixed smearing width ', &
kubo_smr_fixed_en_width, ' eV'
endif
write (stdout, '(a)') ''
if (abs(scissors_shift) > 1.0e-7_dp) then
write (stdout, '(1X,A,I0,A,G18.10,A)') "Using scissors_shift to shift energy bands with index > ", &
num_valence_bands, " by ", scissors_shift, " eV."
endif
if (shc_bandshift) then
write (stdout, '(1X,A,I0,A,G18.10,A)') "Using shc_bandshift to shift energy bands with index >= ", &
shc_bandshift_firstband, " by ", shc_bandshift_energyshift, " eV."
endif
else
if (.not. wanint_kpoint_file) write (stdout, '(1x,a20,3(i0,1x))') &
'Interpolation grid: ', berry_kmesh(1:3)
endif
if (eval_ahc) then
!
! --------------------------------------------------------------------
! At this point imf contains
!
! (1/N) sum_k Omega_{alpha beta}(k),
!
! an approximation to
!
! V_c.int dk/(2.pi)^3 Omega_{alpha beta}(k) dk
!
! (V_c is the cell volume). We want
!
! sigma_{alpha beta}=-(e^2/hbar) int dk/(2.pi)^3 Omega(k) dk
!
! Hence need to multiply by -(e^2/hbar.V_c).
! To get a conductivity in units of S/cm,
!
! (i) Divide by V_c to obtain (1/N) sum_k omega(k)/V_c, with units
! of [L]^{-1} (Berry curvature Omega(k) has units of [L]^2)
! (ii) [L] = Angstrom. Multiply by 10^8 to convert to (cm)^{-1}
! (iii) Multiply by -e^2/hbar in SI, with has units ofconductance,
! (Ohm)^{-1}, or Siemens (S), to get the final result in S/cm
!
! ===========================
! fac = -e^2/(hbar.V_c*10^-8)
! ===========================
!
! with 'V_c' in Angstroms^3, and 'e', 'hbar' in SI units
! --------------------------------------------------------------------
!
fac = -1.0e8_dp*elem_charge_SI**2/(hbar_SI*cell_volume)
ahc_list(:, :, :) = imf_list(:, :, :)*fac
if (nfermi > 1) then
write (stdout, '(/,1x,a)') &
'---------------------------------'
write (stdout, '(1x,a)') &
'Output data files related to AHC:'
write (stdout, '(1x,a)') &
'---------------------------------'
file_name = trim(seedname)//'-ahc-fermiscan.dat'
write (stdout, '(/,3x,a)') '* '//file_name
file_unit = io_file_unit()
open (file_unit, FILE=file_name, STATUS='UNKNOWN', FORM='FORMATTED')
endif
do if = 1, nfermi
if (nfermi > 1) write (file_unit, '(4(F12.6,1x))') &
fermi_energy_list(if), sum(ahc_list(:, 1, if)), &
sum(ahc_list(:, 2, if)), sum(ahc_list(:, 3, if))
write (stdout, '(/,1x,a18,F10.4)') 'Fermi energy (ev):', &
fermi_energy_list(if)
if (nfermi > 1) then
if (wanint_kpoint_file) then
write (stdout, '(1x,a30,i5,a,f5.2,a)') &
' Points triggering refinement: ', &
adpt_counter_list(if), '(', &
100*real(adpt_counter_list(if), dp) &
/sum(num_int_kpts_on_node), '%)'
else
write (stdout, '(1x,a30,i5,a,f5.2,a)') &
' Points triggering refinement: ', &
adpt_counter_list(if), '(', &
100*real(adpt_counter_list(if), dp) &
/product(berry_kmesh), '%)'
endif
endif
write (stdout, '(/,1x,a)') &
'AHC (S/cm) x y z'
if (iprint > 1) then
write (stdout, '(1x,a)') &
'=========='
write (stdout, '(1x,a9,2x,3(f10.4,1x))') 'J0 term :', &
ahc_list(1, 1, if), ahc_list(1, 2, if), ahc_list(1, 3, if)
write (stdout, '(1x,a9,2x,3(f10.4,1x))') 'J1 term :', &
ahc_list(2, 1, if), ahc_list(2, 2, if), ahc_list(2, 3, if)
write (stdout, '(1x,a9,2x,3(f10.4,1x))') 'J2 term :', &
ahc_list(3, 1, if), ahc_list(3, 2, if), ahc_list(3, 3, if)
write (stdout, '(1x,a)') &
'-------------------------------------------'
write (stdout, '(1x,a9,2x,3(f10.4,1x),/)') 'Total :', &
sum(ahc_list(:, 1, if)), sum(ahc_list(:, 2, if)), &
sum(ahc_list(:, 3, if))
else
write (stdout, '(1x,a10,1x,3(f10.4,1x),/)') '==========', &
sum(ahc_list(:, 1, if)), sum(ahc_list(:, 2, if)), &
sum(ahc_list(:, 3, if))
endif
enddo
if (nfermi > 1) close (file_unit)
endif
if (eval_morb) then
!
! --------------------------------------------------------------------
! At this point X=img_ab(:)-fermi_energy*imf_ab(:) and
! Y=imh_ab(:)-fermi_energy*imf_ab(:)
! contain, eg,
!
! (1/N) sum_k X(k), where X(k)=-2*Im[g(k)-E_F.f(k)]
!
! This is an approximation to
!
! V_c.int dk/(2.pi)^3 X(k) dk
!
! (V_c is the cell volume). We want a magnetic moment per cell,
! in units of the Bohr magneton. The magnetization-like quantity is
!
! \tilde{M}^LC=-(e/2.hbar) int dk/(2.pi)^3 X(k) dk
!
! So we take X and
!
! (i) The summand is an energy in eV times a Berry curvature in
! Ang^2. To convert to a.u., divide by 27.2 and by 0.529^2
! (ii) Multiply by -(e/2.hbar)=-1/2 in atomic units
! (iii) At this point we have a magnetic moment (per cell) in atomic
! units. 1 Bohr magneton = 1/2 atomic unit, so need to multiply
! by 2 to convert it to Bohr magnetons
! --------------------------------------------------------------------
!
fac = -eV_au/bohr**2
if (nfermi > 1) then
write (stdout, '(/,1x,a)') &
'---------------------------------'
write (stdout, '(1x,a)') &
'Output data files related to the orbital magnetization:'
write (stdout, '(1x,a)') &
'---------------------------------'
file_name = trim(seedname)//'-morb-fermiscan.dat'
write (stdout, '(/,3x,a)') '* '//file_name
file_unit = io_file_unit()
open (file_unit, FILE=file_name, STATUS='UNKNOWN', FORM='FORMATTED')
endif
do if = 1, nfermi
LCtil_list(:, :, if) = (img_list(:, :, if) &
- fermi_energy_list(if)*imf_list2(:, :, if))*fac
ICtil_list(:, :, if) = (imh_list(:, :, if) &
- fermi_energy_list(if)*imf_list2(:, :, if))*fac
Morb_list(:, :, if) = LCtil_list(:, :, if) + ICtil_list(:, :, if)
if (nfermi > 1) write (file_unit, '(4(F12.6,1x))') &
fermi_energy_list(if), sum(Morb_list(1:3, 1, if)), &
sum(Morb_list(1:3, 2, if)), sum(Morb_list(1:3, 3, if))
write (stdout, '(/,/,1x,a,F12.6)') 'Fermi energy (ev) =', &
fermi_energy_list(if)
write (stdout, '(/,/,1x,a)') &
'M_orb (bohr magn/cell) x y z'
if (iprint > 1) then
write (stdout, '(1x,a)') &
'======================'
write (stdout, '(1x,a22,2x,3(f10.4,1x))') 'Local circulation :', &
sum(LCtil_list(1:3, 1, if)), sum(LCtil_list(1:3, 2, if)), &
sum(LCtil_list(1:3, 3, if))
write (stdout, '(1x,a22,2x,3(f10.4,1x))') &
'Itinerant circulation:', &
sum(ICtil_list(1:3, 1, if)), sum(ICtil_list(1:3, 2, if)), &
sum(ICtil_list(1:3, 3, if))
write (stdout, '(1x,a)') &
'--------------------------------------------------------'
write (stdout, '(1x,a22,2x,3(f10.4,1x),/)') 'Total :', &
sum(Morb_list(1:3, 1, if)), sum(Morb_list(1:3, 2, if)), &
sum(Morb_list(1:3, 3, if))
else
write (stdout, '(1x,a22,2x,3(f10.4,1x),/)') &
'======================', &
sum(Morb_list(1:3, 1, if)), sum(Morb_list(1:3, 2, if)), &
sum(Morb_list(1:3, 3, if))
endif
enddo
if (nfermi > 1) close (file_unit)
endif
! -----------------------------!
! Complex optical conductivity !
! -----------------------------!
!
if (eval_kubo) then
!
! Convert to S/cm
fac = 1.0e8_dp*elem_charge_SI**2/(hbar_SI*cell_volume)
kubo_H = kubo_H*fac
kubo_AH = kubo_AH*fac
if (spin_decomp) then
kubo_H_spn = kubo_H_spn*fac
kubo_AH_spn = kubo_AH_spn*fac
endif
!
write (stdout, '(/,1x,a)') &
'----------------------------------------------------------'
write (stdout, '(1x,a)') &
'Output data files related to complex optical conductivity:'
write (stdout, '(1x,a)') &
'----------------------------------------------------------'
!
! Symmetric: real (imaginary) part is Hermitean (anti-Hermitean)
!
do n = 1, 6
i = alpha_S(n)
j = beta_S(n)
file_name = trim(seedname)//'-kubo_S_'// &
achar(119 + i)//achar(119 + j)//'.dat'
file_name = trim(file_name)
file_unit = io_file_unit()
write (stdout, '(/,3x,a)') '* '//file_name
open (file_unit, FILE=file_name, STATUS='UNKNOWN', FORM='FORMATTED')
do ifreq = 1, kubo_nfreq
if (spin_decomp) then
write (file_unit, '(9E16.8)') real(kubo_freq_list(ifreq), dp), &
real(0.5_dp*(kubo_H(i, j, ifreq) + kubo_H(j, i, ifreq)), dp), &
aimag(0.5_dp*(kubo_AH(i, j, ifreq) + kubo_AH(j, i, ifreq))), &
real(0.5_dp*(kubo_H_spn(i, j, 1, ifreq) &
+ kubo_H_spn(j, i, 1, ifreq)), dp), &
aimag(0.5_dp*(kubo_AH_spn(i, j, 1, ifreq) &
+ kubo_AH_spn(j, i, 1, ifreq))), &
real(0.5_dp*(kubo_H_spn(i, j, 2, ifreq) &
+ kubo_H_spn(j, i, 2, ifreq)), dp), &
aimag(0.5_dp*(kubo_AH_spn(i, j, 2, ifreq) &
+ kubo_AH_spn(j, i, 2, ifreq))), &
real(0.5_dp*(kubo_H_spn(i, j, 3, ifreq) &
+ kubo_H_spn(j, i, 3, ifreq)), dp), &
aimag(0.5_dp*(kubo_AH_spn(i, j, 3, ifreq) &
+ kubo_AH_spn(j, i, 3, ifreq)))
else
write (file_unit, '(3E16.8)') real(kubo_freq_list(ifreq), dp), &
real(0.5_dp*(kubo_H(i, j, ifreq) + kubo_H(j, i, ifreq)), dp), &
aimag(0.5_dp*(kubo_AH(i, j, ifreq) + kubo_AH(j, i, ifreq)))
endif
enddo
close (file_unit)
enddo
!
! Antisymmetric: real (imaginary) part is anti-Hermitean (Hermitean)
!
do n = 1, 3
i = alpha_A(n)
j = beta_A(n)
file_name = trim(seedname)//'-kubo_A_'// &
achar(119 + i)//achar(119 + j)//'.dat'
file_name = trim(file_name)
file_unit = io_file_unit()
write (stdout, '(/,3x,a)') '* '//file_name
open (file_unit, FILE=file_name, STATUS='UNKNOWN', FORM='FORMATTED')
do ifreq = 1, kubo_nfreq
if (spin_decomp) then
write (file_unit, '(9E16.8)') real(kubo_freq_list(ifreq), dp), &
real(0.5_dp*(kubo_AH(i, j, ifreq) - kubo_AH(j, i, ifreq)), dp), &
aimag(0.5_dp*(kubo_H(i, j, ifreq) - kubo_H(j, i, ifreq))), &
real(0.5_dp*(kubo_AH_spn(i, j, 1, ifreq) &
- kubo_AH_spn(j, i, 1, ifreq)), dp), &
aimag(0.5_dp*(kubo_H_spn(i, j, 1, ifreq) &
- kubo_H_spn(j, i, 1, ifreq))), &
real(0.5_dp*(kubo_AH_spn(i, j, 2, ifreq) &
- kubo_AH_spn(j, i, 2, ifreq)), dp), &
aimag(0.5_dp*(kubo_H_spn(i, j, 2, ifreq) &
- kubo_H_spn(j, i, 2, ifreq))), &
real(0.5_dp*(kubo_AH_spn(i, j, 3, ifreq) &
- kubo_AH_spn(j, i, 3, ifreq)), dp), &
aimag(0.5_dp*(kubo_H_spn(i, j, 3, ifreq) &
- kubo_H_spn(j, i, 3, ifreq)))
else
write (file_unit, '(3E16.8)') real(kubo_freq_list(ifreq), dp), &
real(0.5_dp*(kubo_AH(i, j, ifreq) - kubo_AH(j, i, ifreq)), dp), &
aimag(0.5_dp*(kubo_H(i, j, ifreq) - kubo_H(j, i, ifreq)))
endif
enddo
close (file_unit)
enddo
!
! Joint density of states
!
file_name = trim(seedname)//'-jdos.dat'
write (stdout, '(/,3x,a)') '* '//file_name
file_unit = io_file_unit()
open (file_unit, FILE=file_name, STATUS='UNKNOWN', FORM='FORMATTED')