Coverage for gpaw/test/corehole/test_h2o_dks.py: 100%
33 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
1import pytest
2from ase.build import molecule
4from gpaw import GPAW, FermiDirac, PoissonSolver
5from gpaw.test import gen
8@pytest.mark.old_gpaw_only
9def test_corehole_h2o_dks():
10 def xc(name):
11 return {'name': name, 'stencil': 1}
13 # Generate setup for oxygen with a core-hole:
14 s = gen('O', name='fch1s', xcname='PBE', corehole=(1, 0, 1.0))
16 atoms = molecule('H2O')
17 atoms.center(vacuum=2.5)
19 params = dict(mode='fd',
20 xc=xc('PBE'),
21 poissonsolver=PoissonSolver('fd',
22 use_charge_center=True))
23 atoms.calc = GPAW(**params)
24 e1 = atoms.get_potential_energy() + atoms.calc.get_reference_energy()
26 atoms[0].magmom = 1
27 atoms.calc = GPAW(charge=-1,
28 setups={'O': s},
29 occupations=FermiDirac(0.0, fixmagmom=True),
30 **params)
31 e2 = atoms.get_potential_energy() + atoms.calc.get_reference_energy()
33 atoms[0].magmom = 0
34 atoms.calc = GPAW(charge=0,
35 setups={'O': s},
36 occupations=FermiDirac(0.0, fixmagmom=True),
37 spinpol=True,
38 **params)
39 e3 = atoms.get_potential_energy() + atoms.calc.get_reference_energy()
41 print('Energy difference %.3f eV' % (e2 - e1))
42 print('XPS %.3f eV' % (e3 - e1))
44 print(e2 - e1)
45 print(e3 - e1)
46 assert abs(e2 - e1 - 533.070) < 0.001
47 assert abs(e3 - e1 - 538.549) < 0.001
49 energy_tolerance = 0.02
50 print(e1)
51 print(e2)
52 print(e3)
53 assert e1 == pytest.approx(-2080.3651, abs=energy_tolerance)
54 assert e2 == pytest.approx(-1547.2944, abs=energy_tolerance)
55 assert e3 == pytest.approx(-1541.8152, abs=energy_tolerance)