Coverage for gpaw/test/xc/test_pbe_pw91.py: 100%

35 statements  

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

1from math import pi 

2import numpy as np 

3import pytest 

4from gpaw.xc.libxc import LibXC 

5 

6 

7@pytest.mark.libxc 

8def test_xc_pbe_pw91(): 

9 x0 = LibXC('LDA_X') 

10 

11 def f0(xc, rs, s): 

12 n = 3 / (4 * pi * rs**3) 

13 third = 1.0 / 3.0 

14 kF = (3 * pi**2 * n)**third 

15 a2 = (2 * kF * n * s)**2 

16 e = np.zeros(1) 

17 xc.calculate(e, 

18 np.array([[n]]), np.zeros((1, 1)), 

19 np.array([[a2]]), np.zeros((1, 1))) 

20 exc = n * e[0] 

21 x0.calculate(e, np.array([[n]]), np.zeros((1, 1))) 

22 ex0 = n * e[0] 

23 return exc / ex0 

24 

25 def f1(xc, rs, s): 

26 n = 3 / (4 * pi * rs**3) 

27 # na = 2 * n 

28 third = 1.0 / 3.0 

29 kF = (3 * pi**2 * n)**third 

30 a2 = (2 * kF * n * s)**2 

31 e = np.zeros(1) 

32 xc.calculate(e, 

33 np.array([[n], [0]]), np.zeros((2, 1)), 

34 np.array([[a2], [0], [0]]), np.zeros((3, 1))) 

35 exc = n * e[0] 

36 x0.calculate(e, np.array([[n]]), np.zeros((1, 1))) 

37 ex0 = n * e[0] 

38 return exc / ex0 

39 

40 pbe = LibXC('PBE') 

41 pw91 = LibXC('PW91') 

42 assert abs(f0(pbe, 2, 3) - 1.58) < 0.01 

43 assert abs(f1(pbe, 2, 3) - 1.88) < 0.01 

44 assert abs(f0(pw91, 2, 3) - 1.60) < 0.01 

45 assert abs(f1(pw91, 2, 3) - 1.90) < 0.01