Coverage for gpaw/test/lcao/test_fd2lcao_restart.py: 100%

26 statements  

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

1"""Test read/write of restart files between fd and lcao mode""" 

2import os 

3 

4import pytest 

5from ase import Atom, Atoms 

6 

7from gpaw import GPAW, FermiDirac, restart 

8 

9 

10@pytest.mark.old_gpaw_only 

11def test_lcao_fd2lcao_restart(in_tmp_dir): 

12 energy_tolerance = 0.001 

13 

14 if not os.path.isfile('Na4_fd.gpw'): 

15 # Do grid kpts calculation 

16 a = 3.31 

17 atoms = Atoms([Atom('Na', (i * a, 0, 0)) 

18 for i in range(4)], pbc=(1, 0, 0)) 

19 atoms.center(vacuum=3.5) 

20 atoms.center(vacuum=a / 2, axis=0) 

21 

22 calc = GPAW(mode='fd', 

23 nbands=-3, 

24 h=0.3, 

25 setups={'Na': '1'}, 

26 xc={'name': 'PBE', 'stencil': 1}, 

27 occupations=FermiDirac(width=0.1), 

28 kpts=(3, 1, 1), 

29 # basis='dzp', 

30 txt='Na4_fd.txt') 

31 atoms.calc = calc 

32 etot_fd = atoms.get_potential_energy() 

33 print('Etot:', etot_fd, 'eV in fd-mode') 

34 calc.write('Na4_fd.gpw') 

35 del atoms, calc 

36 

37 assert etot_fd == pytest.approx(-1.99055, abs=energy_tolerance) 

38 

39 if os.path.isfile('Na4_fd.gpw'): 

40 # LCAO calculation based on grid kpts calculation 

41 atoms, calc = restart('Na4_fd.gpw', 

42 # basis='dzp', 

43 mode='lcao', 

44 txt='Na4_lcao.txt') 

45 etot_lcao = atoms.get_potential_energy() 

46 print('Etot:', etot_lcao, 'eV in lcao-mode') 

47 calc.write('Na4_lcao.gpw') 

48 del atoms, calc 

49 

50 assert etot_lcao == pytest.approx(-1.9616, abs=energy_tolerance)