Coverage for gpaw/xc/gllb/c_xc.py: 100%

39 statements  

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

1import numpy as np 

2from gpaw.xc import XC 

3from gpaw.xc.gllb.contribution import Contribution 

4 

5 

6class C_XC(Contribution): 

7 def __init__(self, weight, functional): 

8 Contribution.__init__(self, weight) 

9 self.xc = XC(functional) 

10 

11 def get_name(self): 

12 return 'XC' 

13 

14 def get_desc(self): 

15 desc = self.xc.get_description() 

16 return self.xc.name if desc is None else desc 

17 

18 def initialize(self, density, hamiltonian, wfs): 

19 Contribution.initialize(self, density, hamiltonian, wfs) 

20 self.vt_sg = self.finegd.empty(self.nspins) 

21 self.e_g = self.finegd.empty() 

22 

23 def initialize_1d(self, ae): 

24 Contribution.initialize_1d(self, ae) 

25 self.v_g = np.zeros(self.ae.N) 

26 

27 def calculate(self, e_g, n_sg, v_sg): 

28 self.e_g[:] = 0.0 

29 self.vt_sg[:] = 0.0 

30 self.xc.calculate(self.finegd, n_sg, self.vt_sg, self.e_g) 

31 v_sg += self.weight * self.vt_sg 

32 e_g += self.weight * self.e_g 

33 

34 def calculate_energy_and_derivatives(self, setup, D_sp, H_sp, a, 

35 addcoredensity=True): 

36 E = self.xc.calculate_paw_correction(setup, D_sp, H_sp, True, a) 

37 E += setup.xc_correction.e_xc0 

38 return E 

39 

40 def add_xc_potential_and_energy_1d(self, v_g): 

41 self.v_g[:] = 0.0 

42 Exc = self.xc.calculate_spherical(self.ae.rgd, 

43 self.ae.n.reshape((1, -1)), 

44 self.v_g.reshape((1, -1))) 

45 v_g += self.weight * self.v_g 

46 return self.weight * Exc 

47 

48 def add_smooth_xc_potential_and_energy_1d(self, vt_g): 

49 self.v_g[:] = 0.0 

50 Exc = self.xc.calculate_spherical(self.ae.rgd, 

51 self.ae.nt.reshape((1, -1)), 

52 self.v_g.reshape((1, -1))) 

53 vt_g += self.weight * self.v_g 

54 return self.weight * Exc