Coverage for gpaw/test/directopt/test_mom_directopt_lcao_spinpaired.py: 100%
19 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
2import pytest
3from gpaw import GPAW
4from gpaw.mom import prepare_mom_calculation
5from gpaw.directmin.tools import excite
8@pytest.mark.mom
9@pytest.mark.do
10def test_mom_directopt_lcao_spinpaired(in_tmp_dir, gpw_files):
11 calc = GPAW(gpw_files['c2h4_do_lcao'])
12 atoms = calc.atoms
13 atoms.calc = calc
15 f_sn = excite(calc, 0, 0, spin=(0, 0))
16 f_sn[0] /= 2
18 prepare_mom_calculation(calc, atoms, f_sn)
19 # This fails if the memory of the search direction
20 # algorithm is not erased
21 e = atoms.get_potential_energy()
23 calc.wfs.occupations.initialize_reference_orbitals()
24 calc.wfs.calculate_occupation_numbers(calc.density.fixed)
26 # These fail if the OccupationsMOM.numbers are not updated correctly
27 assert np.all(calc.get_occupation_numbers() <= 2.0)
28 assert e == pytest.approx(-21.38257404436053, abs=0.01)