Coverage for gpaw/response/gamma_int.py: 94%

34 statements  

« prev     ^ index     » next       coverage.py v7.7.1, created at 2025-07-09 00:21 +0000

1from collections.abc import Sequence 

2 

3import numpy as np 

4from ase.dft.kpoints import monkhorst_pack 

5 

6 

7class GammaIntegral(Sequence): 

8 def __init__(self, coulomb, qpd): 

9 self.coulomb = coulomb 

10 self.qpd = qpd 

11 self.integral_domain = GammaIntegralDomain( 

12 coulomb.truncation, coulomb.kd, qpd) 

13 

14 def __len__(self): 

15 return len(self.integral_domain) 

16 

17 def __getitem__(self, q): 

18 qweight, qf_v = self.integral_domain[q] 

19 sqrtV_G = self.coulomb.sqrtV(qpd=self.qpd, q_v=qf_v) 

20 

21 def chi0_mapping(chi0_GG, chi0_vv, chi0_xvG): 

22 out_GG = chi0_GG.copy() 

23 out_GG[0, :] = qf_v @ chi0_xvG[0] 

24 out_GG[:, 0] = qf_v @ chi0_xvG[1] 

25 out_GG[0, 0] = qf_v @ chi0_vv @ qf_v 

26 return out_GG 

27 

28 return qweight, sqrtV_G, chi0_mapping 

29 

30 

31class GammaIntegralDomain(Sequence): 

32 def __init__(self, truncation, kd, qpd): 

33 N = 4 

34 N_c = np.array([N, N, N]) 

35 if truncation is not None: 

36 # Only average periodic directions if trunction is used 

37 N_c[kd.N_c == 1] = 1 

38 qf_qc = monkhorst_pack(N_c) / kd.N_c 

39 qf_qc *= 1.0e-6 

40 # XXX previously symmetry was used in Gamma integrator. 

41 # This was not correct, as explained in #709. 

42 self.qweight = 1. / np.prod(N_c) 

43 self.qf_qv = 2 * np.pi * (qf_qc @ qpd.gd.icell_cv) 

44 

45 def __len__(self): 

46 return len(self.qf_qv) 

47 

48 def __getitem__(self, q): 

49 return self.qweight, self.qf_qv[q]