Coverage for gpaw/test/gllb/test_variants.py: 100%

30 statements  

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

1import numpy as np 

2import pytest 

3from ase.build import bulk 

4from gpaw import GPAW 

5from gpaw.test import gen 

6 

7 

8def run(xc): 

9 setup_name = {'GLLBLDA': 'LDA', 'GLLBPBE': 'PBE', 'GLLBM': 'GLLB'}.get(xc, 

10 xc) 

11 if setup_name in ['GLLB', 'GLLBC', 'GLLBCP86', 'GLLBNORESP']: 

12 gen('Si', xcname=setup_name, write_xml=True) 

13 

14 atoms = bulk('Si') 

15 calc = GPAW(mode='lcao', 

16 basis='sz(dzp)', 

17 h=0.3, 

18 nbands=8, 

19 xc=xc, 

20 convergence={'density': 1e-5}, 

21 kpts={'size': (1, 1, 1), 'gamma': True}, 

22 txt=f'{xc}.out') 

23 atoms.calc = calc 

24 atoms.get_potential_energy() 

25 eig_n = calc.get_eigenvalues(kpt=0) 

26 return eig_n 

27 

28 

29@pytest.mark.gllb 

30@pytest.mark.libxc 

31@pytest.mark.parametrize('xc', ['GLLBLDA', 'GLLBPBE']) 

32def test_wrappers(xc, in_tmp_dir, add_cwd_to_setup_paths): 

33 eig_n = run(xc) 

34 

35 # Check values against regular xc 

36 ref_eig_n = run({'GLLBLDA': 'LDA', 'GLLBPBE': 'PBE'}[xc]) 

37 assert np.allclose(eig_n, ref_eig_n, rtol=0, atol=1e-8), \ 

38 f'{xc} error = {np.max(np.abs(eig_n - ref_eig_n))}' 

39 

40 

41refs = {'GLLB': 

42 [-7.39405717, 5.01549354, 5.01549354, 5.01636595, 7.96095802, 

43 7.96095802, 7.96694721, 8.88669699], 

44 'GLLBM': 

45 [-5.74729132, 6.72606263, 6.72626409, 6.72626409, 9.58974119, 

46 9.58974119, 9.59459313, 10.37720714], 

47 'GLLBC': 

48 [-8.69990692, 3.74307763, 3.74449328, 3.74449328, 6.62701764, 

49 6.62701764, 6.63089065, 7.63596163], 

50 'GLLBCP86': 

51 [-8.85224195, 3.61988450, 3.62088667, 3.62088667, 6.49494071, 

52 6.49494071, 6.49896814, 7.43709444], 

53 'GLLBNORESP': 

54 [-11.08041529, 1.29983637, 1.30174632, 1.30174632, 3.22508733, 

55 3.95890694, 3.95890694, 3.96210188], 

56 'GLLBSC': 

57 [-8.30692283, 4.08893353, 4.08969201, 4.08969201, 7.08814258, 

58 7.08814258, 7.09267773, 8.05448801], 

59 'GLLBSCM': 

60 [-6.64285287, 5.81684766, 5.81869048, 5.81869048, 8.73473982, 

61 8.73473982, 8.73812616, 9.56188223] 

62 } 

63 

64 

65@pytest.mark.gllb 

66@pytest.mark.libxc 

67@pytest.mark.parametrize('xc', ['GLLB', 'GLLBM', 'GLLBC', 

68 'GLLBCP86', 'GLLBNORESP', 

69 'GLLBSC', 'GLLBSCM']) 

70def test_eigenvalues(xc, in_tmp_dir, add_cwd_to_setup_paths): 

71 eig_n = run(xc) 

72 ref_eig_n = refs[xc] 

73 assert np.allclose(eig_n, ref_eig_n, rtol=0, atol=2e-5), \ 

74 f'{xc} error = {np.max(np.abs(eig_n - ref_eig_n))}'