Coverage for gpaw/test/directopt/test_constraints_directopt_lcao_sic.py: 97%
33 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-19 00:19 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-19 00:19 +0000
1import pytest
3from gpaw import GPAW
4import numpy as np
5from gpaw.mpi import world
8@pytest.mark.old_gpaw_only
9@pytest.mark.do
10def test_constraints_directopt_lcao_sic(in_tmp_dir, gpw_files):
11 """
12 test Perdew-Zunger Self-Interaction
13 Correction in LCAO mode using DirectMin
14 :param in_tmp_dir:
15 :return:
16 """
17 if world.size == 8:
18 pytest.skip('See #1406')
19 calc = GPAW(gpw_files['h2o_cdo_lcao_sic'])
20 H2O = calc.atoms
21 H2O.calc = calc
23 test_restart = True
24 if test_restart:
25 from gpaw import restart
26 calc.write('h2o.gpw', mode='all')
27 H2O, calc = restart('h2o.gpw', txt='-')
28 H2O.calc.results.pop('energy')
29 H2O.calc.scf.converged = False
30 calc.set(eigensolver={'name': 'etdm-lcao',
31 'functional': {'name': 'PZ-SIC',
32 'scaling_factor': (0.5, 0.5)},
33 'need_init_orbs': False})
34 e = H2O.get_potential_energy()
35 niter = calc.get_number_of_iterations()
36 assert niter == pytest.approx(3, abs=3)
37 assert e == pytest.approx(-12.16353, abs=1.0e-3)
39 homo = 3
40 lumo = 4
41 a = 0.5 * np.pi
42 c = calc.wfs.kpt_u[0].C_nM.copy()
43 calc.wfs.kpt_u[0].C_nM[homo] = np.cos(a) * c[homo] + np.sin(a) * c[lumo]
44 calc.wfs.kpt_u[0].C_nM[lumo] = np.cos(a) * c[lumo] - np.sin(a) * c[homo]
46 calc.set(eigensolver={'name': 'etdm-lcao',
47 'functional': {'name': 'PZ-SIC',
48 'scaling_factor': (0.5, 0.5)},
49 'constraints': [[[homo], [lumo]]],
50 'need_init_orbs': False})
52 e = H2O.get_potential_energy()
54 assert e == pytest.approx(24.24718, abs=0.1)