8
8
import math
9
9
from dptb .utils .make_kpoints import kmesh_sampling_negf
10
10
import time
11
+ import logging
11
12
13
+ log = logging .getLogger (__name__ )
12
14
13
15
def fermi_dirac (e , mu , beta ):
14
16
return 1 / (1 + torch .exp (beta * (e - mu )))
@@ -32,7 +34,7 @@ def cal_cond(model, data, e_fermi, mesh_grid, emax, num_val=None, gap_corr=0, nu
32
34
data = model .idp (data )
33
35
data = model (data )
34
36
35
- print ('application of the model is done' )
37
+ log . info ('application of the model is done' )
36
38
37
39
KB = 8.617333262e-5
38
40
beta = 1 / (KB * T )
@@ -48,7 +50,7 @@ def cal_cond(model, data, e_fermi, mesh_grid, emax, num_val=None, gap_corr=0, nu
48
50
num_loop = math .ceil (tot_numk / nk_per_loop )
49
51
omegas = torch .linspace (0 ,emax ,num_omega , dtype = torch .float64 )
50
52
51
- print ('tot_numk:' ,tot_numk , 'nk_per_loop:' ,nk_per_loop , 'num_loop:' ,num_loop )
53
+ log . info ('tot_numk:' ,tot_numk , 'nk_per_loop:' ,nk_per_loop , 'num_loop:' ,num_loop )
52
54
53
55
ac_cond = np .zeros ((len (omegas )),dtype = np .complex128 )
54
56
ac_cond_ik = np .zeros ((len (omegas )),dtype = np .complex128 )
@@ -58,8 +60,8 @@ def cal_cond(model, data, e_fermi, mesh_grid, emax, num_val=None, gap_corr=0, nu
58
60
59
61
for ik in range (num_loop ):
60
62
t_start = time .time ()
61
- print ('<><><><><' * 5 )
62
- print (f'loop { ik + 1 } in { num_loop } circles' )
63
+ log . info ('<><><><><' * 5 )
64
+ log . info (f'loop { ik + 1 } in { num_loop } circles' )
63
65
istart = ik * nk_per_loop
64
66
iend = min ((ik + 1 ) * nk_per_loop , tot_numk )
65
67
kpoints_ = kpoints [istart :iend ]
@@ -72,18 +74,19 @@ def cal_cond(model, data, e_fermi, mesh_grid, emax, num_val=None, gap_corr=0, nu
72
74
# Hamiltonian = data['hamiltonian'].detach().to(torch.complex128)
73
75
# dhdk = {k: v.detach().to(torch.complex128) for k, v in dhdk.items()}
74
76
75
- print (f' - get H and dHdk ...' )
77
+ log . info (f' - get H and dHdk ...' )
76
78
77
79
eigs , eigv = torch .linalg .eigh (data ['hamiltonian' ])
78
80
79
- if num_val is not None :
81
+ if num_val is not None and abs (gap_corr ) > 1e-3 :
82
+ log .info (f' - gap correction is applied with { gap_corr } ' )
80
83
assert num_val > 0
81
84
assert eigs [:,num_val ].min () - eigs [:,num_val - 1 ].max () > 1e-3 , f'the gap between the VBM { num_val - 1 } and the CBM { num_val } is too small'
82
- if abs ( gap_corr ) > 1e-3 :
83
- print ( f' - gap correction is applied { gap_corr } ' )
84
- eigs [:,: num_val ] = eigs [:,: num_val ] - gap_corr / 2
85
- eigs [:, num_val :] = eigs [:, num_val :] + gap_corr / 2
86
- print (f' - diagonalization of H ...' )
85
+
86
+ eigs [:,: num_val ] = eigs [:,: num_val ] - gap_corr / 2
87
+ eigs [:,num_val : ] = eigs [:,num_val :] + gap_corr / 2
88
+
89
+ log . info (f' - diagonalization of H ...' )
87
90
88
91
dh1 = eigv .conj ().transpose (1 ,2 ) @ dhdk [direction [0 ]] @ eigv
89
92
if direction [0 ] == direction [1 ]:
@@ -94,7 +97,7 @@ def cal_cond(model, data, e_fermi, mesh_grid, emax, num_val=None, gap_corr=0, nu
94
97
p1p2 = dh1 * dh2 .transpose (1 ,2 )
95
98
96
99
97
- print (f' - get p matrix from dHdk ...' )
100
+ log . info (f' - get p matrix from dHdk ...' )
98
101
99
102
p1p2 .to (torch .complex128 )
100
103
eigs .to (torch .float64 )
@@ -119,14 +122,14 @@ def cal_cond(model, data, e_fermi, mesh_grid, emax, num_val=None, gap_corr=0, nu
119
122
ac_cond = ac_cond + ac_cond_ik
120
123
ac_cond_linhard = ac_cond_linhard + ac_cond_linhard_ik
121
124
122
- print (f' - get ac_cond ...' )
125
+ log . info (f' - get ac_cond ...' )
123
126
t_end = time .time ()
124
- print (f'time cost: { t_end - t_start :.4f} s in loop { ik + 1 } ' )
127
+ log . info (f'time cost: { t_end - t_start :.4f} s in loop { ik + 1 } ' )
125
128
126
- volume = data ['cell' ][0 ] @(data ['cell' ][1 ].cross (data ['cell' ][2 ]))
127
- prefactor = g_s * 1j / (volume .numpy ())
129
+ ac_cond = 1.0j * ac_cond * np .pi
130
+ volume = data ['cell' ][0 ] @ (data ['cell' ][1 ].cross (data ['cell' ][2 ],dim = 0 ))
131
+ prefactor = 2 * g_s * 1j / (volume .numpy ())
128
132
ac_cond = ac_cond * prefactor
129
- ac_cond .imag = - ac_cond .imag * np .pi
130
133
ac_cond_linhard = ac_cond_linhard * prefactor
131
134
132
135
return omegas , ac_cond , ac_cond_linhard
0 commit comments