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

27 statements  

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

1from ase import Atoms 

2from gpaw import GPAW 

3import pytest 

4from gpaw.xc.tools import vxc 

5 

6 

7def test_xc_degeneracy(): 

8 a = 5.0 

9 d = 1.0 

10 x = d / 3**0.5 

11 atoms = Atoms('CH4', 

12 [(0.0, 0.0, 0.0), 

13 (x, x, x), 

14 (-x, -x, x), 

15 (x, -x, -x), 

16 (-x, x, -x)], 

17 cell=(a, a, a), 

18 pbc=False) 

19 

20 atoms.positions[:] += a / 2 

21 params = dict( 

22 mode='fd', h=0.25, nbands=4, convergence={'eigenstates': 7.8e-10}) 

23 atoms.calc = GPAW(**params) 

24 energy = atoms.get_potential_energy() 

25 

26 # The three eigenvalues e[1], e[2], and e[3] must be degenerate: 

27 e = atoms.calc.get_eigenvalues() 

28 print(e[1] - e[3]) 

29 assert e[1] == pytest.approx(e[3], abs=9.3e-8) 

30 

31 energy_tolerance = 0.002 

32 assert energy == pytest.approx(-23.631, abs=energy_tolerance) 

33 

34 gs = atoms.calc.gs_adapter() 

35 

36 # Calculate non-selfconsistent PBE eigenvalues: 

37 epbe0 = e[:2] - vxc(gs, n2=2)[0, 0] + vxc(gs, 'PBE', n2=2)[0, 0] 

38 

39 # Calculate selfconsistent PBE eigenvalues: 

40 atoms.calc = GPAW(**params, xc='PBE') 

41 energy = atoms.get_potential_energy() 

42 epbe = atoms.calc.get_eigenvalues() 

43 

44 de = epbe[1] - epbe[0] 

45 de0 = epbe0[1] - epbe0[0] 

46 print(de, de0) 

47 assert de == pytest.approx(de0, abs=0.001)