Coverage for gpaw/test/fileio/test_refine.py: 100%

19 statements  

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

1"""Test automatically write out of restart files""" 

2 

3import pytest 

4from ase import Atoms 

5 

6from gpaw import GPAW 

7 

8 

9@pytest.mark.old_gpaw_only 

10def test_fileio_refine(in_tmp_dir): 

11 restart_wf = 'gpaw-restart-wf.gpw' 

12 # H2 

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

14 H.center(vacuum=2.0) 

15 

16 if 1: 

17 calc = GPAW(mode='fd', 

18 nbands=2, 

19 convergence={'eigenstates': 0.001, 

20 'energy': 0.1, 

21 'density': 0.1}) 

22 H.calc = calc 

23 H.get_potential_energy() 

24 calc.write(restart_wf, 'all') 

25 

26 # refine the result directly 

27 H.calc = calc.new(convergence={'energy': 0.00001}) 

28 Edirect = H.get_potential_energy() 

29 

30 # refine the result after reading from a file 

31 H = GPAW(restart_wf, convergence={'energy': 0.00001}).get_atoms() 

32 Erestart = H.get_potential_energy() 

33 

34 print(Edirect, Erestart) 

35 # Note: the different density mixing introduces small differences 

36 assert Edirect == pytest.approx(Erestart, abs=4e-5)