Coverage for gpaw/test/ofdft/test_ofdft_pbc.py: 100%

25 statements  

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

1import pytest 

2from ase.build import bulk 

3from gpaw import GPAW 

4from gpaw.mixer import Mixer 

5from gpaw.test import gen 

6 

7 

8@pytest.mark.ofdft 

9@pytest.mark.libxc 

10def test_ofdft_ofdft_pbc(in_tmp_dir): 

11 symbol = 'C' 

12 result = -224.206 

13 electrons = 48 

14 

15 xcname = 'LDA_K_TF+LDA_X' 

16 g = gen(symbol, xcname=xcname, scalarrel=False, orbital_free=True) 

17 h = 0.14 

18 a = 2.8 

19 atoms = bulk(symbol, 'diamond', a=a, cubic=True) # Generate diamond 

20 mixer = Mixer(0.1, 5) 

21 

22 calc = GPAW(mode='fd', 

23 h=h, 

24 xc=xcname, 

25 setups={'C': g}, 

26 maxiter=120, 

27 eigensolver='cg', 

28 mixer=mixer) 

29 

30 atoms.calc = calc 

31 

32 e = atoms.get_potential_energy() 

33 

34 n = calc.get_all_electron_density() 

35 

36 dv = atoms.get_volume() / calc.get_number_of_grid_points().prod() 

37 I = n.sum() * dv / 2**3 

38 

39 assert I == pytest.approx(electrons, abs=1.0e-6) 

40 assert e == pytest.approx(result, abs=1.0e-2)