Coverage for gpaw/test/test_fixocc.py: 100%
34 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-08 00:17 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-08 00:17 +0000
1from ase.build import molecule
2from ase.parallel import parprint
3from gpaw import GPAW
4from gpaw.utilities.adjust_cell import adjust_cell
5import pytest
8def test_fixocc():
9 h = 0.4
10 box = 2
11 nbands = 2
12 txt = '-'
13 txt = None
15 H2 = molecule('H2')
16 adjust_cell(H2, box, h)
17 convergence = {'energy': 0.01, 'eigenstates': 0.001, 'density': 0.01}
19 base_kwargs = dict(
20 mode='fd',
21 h=h,
22 nbands=nbands,
23 convergence=convergence,
24 txt=txt)
26 if 1:
27 # test ZeroKelvin vs FixedOccupations
28 c = GPAW(**base_kwargs, occupations={'width': 0.0})
29 H2.calc = c
30 E_zk = H2.get_potential_energy()
32 c = GPAW(**base_kwargs,
33 occupations=dict(name='fixed', numbers=[[1, 0]]))
34 H2.calc = c
35 E_fo = H2.get_potential_energy()
36 parprint(E_zk, E_fo)
37 assert E_zk == pytest.approx(E_fo, abs=1.e-10)
39 if 1:
40 # test spin-paired vs spin-polarized
41 c = GPAW(**base_kwargs,
42 occupations={'name': 'fixed', 'numbers': [[0.5, 0.5]]})
43 H2.calc = c
44 E_ns = H2.get_potential_energy()
45 if 1:
46 c = GPAW(**base_kwargs,
47 spinpol=True,
48 occupations={'name': 'fixed', 'numbers': [[0.5, 0.5]] * 2})
49 H2.calc = c
50 E_sp = H2.get_potential_energy()
51 parprint(E_ns, E_sp)
52 assert E_ns == pytest.approx(E_sp, abs=1.e-6)