Coverage for gpaw/test/sic/test_lcaosic.py: 83%
29 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
1import pytest
3from gpaw import GPAW
4import numpy as np
7@pytest.mark.old_gpaw_only
8@pytest.mark.sic
9def test_lcaosic(in_tmp_dir, gpw_files):
10 """
11 Test Perdew-Zunger Self-Interaction
12 Correction in LCAO mode using ETDM
13 :param in_tmp_dir:
14 :return:
15 """
17 # Water molecule:
18 calc = GPAW(gpw_files['h2o_lcaosic'])
19 H2O = calc.atoms
20 H2O.calc = calc
21 e = H2O.get_potential_energy()
22 f = H2O.get_forces()
24 assert e == pytest.approx(-12.16352, abs=1e-3)
26 f2 = np.array([[-4.21747862, -4.63118948, 0.00303988],
27 [5.66636141, -0.51037693, -0.00049136],
28 [-1.96478031, 5.4043045, -0.0006107]])
29 assert f2 == pytest.approx(f, abs=0.1)
31 numeric = False
32 if numeric:
33 from gpaw.test import calculate_numerical_forces
34 f_num = calculate_numerical_forces(H2O, 0.001)
35 print('Numerical forces')
36 print(f_num)
37 print(f - f_num, np.abs(f - f_num).max())
39 calc.write('h2o.gpw', mode='all')
40 from gpaw import restart
41 H2O, calc = restart('h2o.gpw', txt='-')
42 H2O.positions += 1.0e-6
43 f3 = H2O.get_forces()
44 niter = calc.get_number_of_iterations()
45 assert niter == pytest.approx(4, abs=3)
46 assert f2 == pytest.approx(f3, abs=0.1)