Coverage for gpaw/test/generic/test_bulk.py: 100%
24 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
1from ase import Atom, Atoms
2from gpaw import GPAW
3import pytest
4import numpy as np
7def test_generic_bulk():
8 bulk = Atoms([Atom('Li')], pbc=True)
9 k = 4
10 g = 8
11 calc = GPAW(mode='fd', gpts=(g, g, g), kpts=(k, k, k), nbands=2)
12 bulk.calc = calc
13 a = np.linspace(2.6, 2.8, 5)
14 e = []
15 for x in a:
16 bulk.set_cell((x, x, x))
17 e1 = bulk.get_potential_energy()
18 e.append(e1)
20 fit = np.polyfit(a, e, 2)
21 a0 = np.roots(np.polyder(fit, 1))[0]
22 e0 = np.polyval(fit, a0)
23 print('a,e =', a0, e0)
24 assert a0 == pytest.approx(2.641, abs=0.001)
25 assert e0 == pytest.approx(-1.98357, abs=0.0002)
27 energy_tolerance = 0.0002
28 assert e1 == pytest.approx(-1.96157, abs=energy_tolerance)