Coverage for gpaw/test/mgga/test_mgga_restart.py: 100%

32 statements  

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

1import pytest 

2from ase import Atom, Atoms 

3from gpaw import GPAW 

4 

5 

6@pytest.mark.mgga 

7def test_mgga_mgga_restart(in_tmp_dir): 

8 fname = 'H2_PBE.gpw' 

9 fwfname = 'H2_wf_PBE.gpw' 

10 txt = None 

11 txt = '-' 

12 

13 s = Atoms([Atom('H'), Atom('H', [0, 0, 1])]) 

14 s.center(vacuum=3.) 

15 s.calc = GPAW(xc={'name': 'PBE', 'stencil': 1}, 

16 mode='fd', 

17 h=.3, 

18 convergence={'density': 1e-4, 'eigenstates': 1e-6}) 

19 s.get_potential_energy() 

20 s.calc.write(fname) 

21 s.calc.write(fwfname, 'all') 

22 

23 # full information 

24 calc = GPAW(fwfname, txt=txt) 

25 E_PBE = calc.get_potential_energy(s) 

26 dE = calc.get_xc_difference({'name': 'TPSS', 'stencil': 1}) 

27 E_1 = E_PBE + dE 

28 print('E PBE, TPSS=', E_PBE, E_1) 

29 

30 # no wfs 

31 calc = GPAW(fname, txt=txt) 

32 E_PBE_no_wfs = calc.get_potential_energy(s) 

33 dE = calc.get_xc_difference({'name': 'TPSS', 'stencil': 1}) 

34 E_2 = E_PBE_no_wfs + dE 

35 print('E PBE, TPSS=', E_PBE_no_wfs, E_2) 

36 

37 print('diff=', E_1 - E_2) 

38 assert abs(E_1 - E_2) < 0.005 

39 

40 energy_tolerance = 0.002 

41 assert E_PBE == pytest.approx(-5.341, abs=energy_tolerance) 

42 assert E_PBE_no_wfs == pytest.approx(-5.33901, abs=energy_tolerance) 

43 assert E_1 == pytest.approx(-5.57685, abs=energy_tolerance) 

44 assert E_2 == pytest.approx(-5.57685, abs=energy_tolerance)