Coverage for gpaw/test/ext_potential/test_step.py: 100%
21 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 pytest
3from ase import Atoms
5from gpaw import GPAW
6from gpaw.external import StepPotentialz
9@pytest.mark.old_gpaw_only
10def test_He():
11 a = 3
12 b = 3 * a
13 atoms = Atoms('He', positions=[(a, a, a)],
14 cell=(2 * a, 2 * a, b))
16 c00 = GPAW(mode='fd', charge=1)
17 atoms.calc = c00
18 atoms.get_potential_energy()
20 # apply potential where the atom is
21 constant = -5
22 c10 = GPAW(mode='fd',
23 charge=1,
24 external=StepPotentialz(b / 2, value_left=constant))
25 atoms.calc = c10
26 atoms.get_potential_energy()
28 # the total energy is shifted for charged systems
29 assert c00.get_potential_energy() == pytest.approx(
30 c10.get_potential_energy() + constant, 1e-4)
32 # apply potential where there is no atom
33 c01 = GPAW(mode='fd',
34 charge=1,
35 external=StepPotentialz(b / 2, value_right=constant))
36 atoms.calc = c01
37 atoms.get_potential_energy()
39 # the total energy should be the same as without the potential
40 assert c00.get_potential_energy() == pytest.approx(
41 c01.get_potential_energy(), 1e-4)