Coverage for gpaw/test/new/test_write.py: 100%
23 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-12 00:18 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-12 00:18 +0000
1import pytest
2from ase.build import molecule
3from gpaw.new.ase_interface import GPAW
6@pytest.mark.parametrize('mode', ['pw', 'lcao', 'fd'])
7@pytest.mark.parametrize('kpts', [False, True])
8def test_write_new_single(mode, kpts, in_tmp_dir):
9 atoms = molecule('H2')
10 atoms.center(vacuum=2.0)
11 if kpts:
12 atoms.pbc = True
13 atoms.calc = GPAW(mode=mode, kpts=(2, 1, 1), txt=None)
14 else:
15 atoms.calc = GPAW(mode=mode, txt=None)
16 atoms.get_potential_energy()
18 # write
19 atoms.calc.write('h2.gpw', mode='all', precision='single')
20 dft1 = atoms.calc.dft
21 # load
22 calc = GPAW('h2.gpw')
23 dft2 = calc.dft
24 assert dft1.density.nt_sR.data == pytest.approx(dft2.density.nt_sR.data)
25 assert dft1.potential.vt_sR.data == pytest.approx(
26 dft2.potential.vt_sR.data)
27 for wfs1, wfs2 in zip(dft1.ibzwfs, dft2.ibzwfs):
28 if mode == 'lcao':
29 assert wfs1.C_nM.data == pytest.approx(wfs2.C_nM.data)
30 else:
31 assert wfs1.psit_nX.data == pytest.approx(wfs2.psit_nX.data)