Coverage for gpaw/test/lcao/test_bulk.py: 100%
33 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
1import numpy as np
2from ase import Atoms
3from gpaw import GPAW
4import pytest
7def test_lcao_bulk(in_tmp_dir):
8 bulk = Atoms('Li', pbc=True)
9 k = 4
10 g = 8
11 calc = GPAW(gpts=(g, g, g), kpts=(k, k, k),
12 mode='lcao', basis='dzp')
13 bulk.calc = calc
14 e = []
15 niter = []
16 A = [2.6, 2.65, 2.7, 2.75, 2.8]
17 for a in A:
18 bulk.set_cell((a, a, a))
19 e.append(bulk.get_potential_energy())
20 niter.append(calc.get_number_of_iterations())
22 a = np.roots(np.polyder(np.polyfit(A, e, 2), 1))[0]
23 print('a =', a)
24 assert a == pytest.approx(2.6378, abs=0.0003)
26 e_ref = [-1.8677343236247692, -1.8690343169380492, -1.8654175796625045,
27 -1.8566274574918875, -1.8432374955346396]
28 niter_ref = [6, 6, 6, 6, 6]
30 print(e)
31 energy_tolerance = 0.0003
32 niter_tolerance = 0
34 for i in range(len(A)):
35 assert e[i] == pytest.approx(e_ref[i], abs=energy_tolerance)
36 assert niter[i] == pytest.approx(niter_ref[i], abs=niter_tolerance)
38 wf1 = calc.get_pseudo_wave_function(kpt=3, band=0)
39 calc.write('Li', mode='all')
40 calc2 = GPAW('Li')
41 # calc2.initialize_positions()
42 wf2 = calc2.get_pseudo_wave_function(kpt=3, band=0)
43 assert abs(wf1 - wf2).max() == pytest.approx(0, abs=1e-9)