Coverage for gpaw/test/generic/test_IP_oxygen.py: 100%

23 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 import Atoms 

4from gpaw import GPAW 

5 

6 

7def test_generic_IP_oxygen(): 

8 a = 6.0 

9 O = Atoms('O', 

10 [(a / 2, a / 2 + 0.5, a / 2)], 

11 magmoms=[2], 

12 pbc=False, 

13 cell=(a, a + 1, a)) 

14 O.calc = GPAW(mode='fd', gpts=(32, 36, 32), nbands=4) 

15 e0 = O.get_potential_energy() 

16 

17 O.calc = GPAW(mode='fd', gpts=(32, 36, 32), nbands=4, charge=1) 

18 

19 e1 = O.get_potential_energy() 

20 

21 h0 = -26.43361787 

22 l0 = np.inf 

23 h1 = -35.55077324 

24 l1 = -20.81227577 

25 assert O.calc.get_homo_lumo(0) == pytest.approx([h0, l0], rel=0.001) 

26 assert O.calc.get_homo_lumo(1) == pytest.approx([h1, l1], rel=0.001) 

27 assert O.calc.get_homo_lumo() == pytest.approx([h0, l1], rel=0.001) 

28 

29 print(e1 - e0) 

30 assert abs(e1 - e0 - 13.989) < 0.04 

31 

32 energy_tolerance = 0.004 

33 assert e0 == pytest.approx(-1.88477, abs=energy_tolerance) 

34 assert e1 == pytest.approx(12.11080, abs=energy_tolerance) 

35 

36 # The first ionization energy for LDA oxygen is from this paper: 

37 # In-Ho Lee, Richard M. Martin, Phys. Rev. B 56 7197 (1997)