Coverage for gpaw/test/test_muffintinpot.py: 100%

25 statements  

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

1import pytest 

2from gpaw.mpi import world 

3from ase import Atoms 

4from gpaw import GPAW 

5 

6from gpaw.utilities.kspot import AllElectronPotential 

7pytestmark = pytest.mark.skipif(world.size > 1, 

8 reason='world.size > 1') 

9 

10 

11@pytest.mark.old_gpaw_only 

12def test_muffintinpot(in_tmp_dir): 

13 if 1: 

14 be = Atoms(symbols='Be', positions=[(0, 0, 0)]) 

15 be.center(vacuum=5) 

16 calc = GPAW(mode='fd', 

17 gpts=(64, 64, 64), 

18 xc='LDA', 

19 nbands=1) # 0.1 required for accuracy 

20 be.calc = calc 

21 e = be.get_potential_energy() 

22 

23 energy_tolerance = 0.001 

24 assert e == pytest.approx(0.00246471, abs=energy_tolerance) 

25 

26 # be, calc = restart("be.gpw") 

27 AllElectronPotential(calc).write_spherical_ks_potentials('bepot.txt') 

28 f = open('bepot.txt') 

29 lines = f.readlines() 

30 f.close() 

31 mmax = 0 

32 for l in lines: 

33 mmax = max(abs(eval(l.split(' ')[3])), mmax) 

34 

35 print("Max error: ", mmax) 

36 assert mmax < 0.009