Coverage for gpaw/test/eigen/test_cg.py: 100%

21 statements  

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

1from ase import Atom, Atoms 

2from gpaw import GPAW 

3import pytest 

4 

5 

6@pytest.mark.legacy 

7def test_eigen_cg(): 

8 a = 4.05 

9 d = a / 2**0.5 

10 bulk = Atoms([Atom('Al', (0, 0, 0)), 

11 Atom('Al', (0.5, 0.5, 0.5))], 

12 pbc=True) 

13 bulk.set_cell((d, d, a), scale_atoms=True) 

14 h = 0.25 

15 base_params = dict( 

16 mode='fd', 

17 h=h, 

18 nbands=2 * 8, 

19 kpts=(2, 2, 2), 

20 convergence={'energy': 1e-5}) 

21 calc = GPAW(**base_params) 

22 bulk.calc = calc 

23 e0 = bulk.get_potential_energy() 

24 calc = GPAW(**base_params, eigensolver='cg') 

25 bulk.calc = calc 

26 e1 = bulk.get_potential_energy() 

27 assert e0 == pytest.approx(e1, abs=5.e-5) 

28 

29 energy_tolerance = 0.001 

30 assert e0 == pytest.approx(-6.97626, abs=energy_tolerance) 

31 assert e1 == pytest.approx(-6.97627, abs=energy_tolerance)