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

1import pytest 

2 

3from ase import Atoms 

4 

5from gpaw import GPAW 

6from gpaw.external import StepPotentialz 

7 

8 

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)) 

15 

16 c00 = GPAW(mode='fd', charge=1) 

17 atoms.calc = c00 

18 atoms.get_potential_energy() 

19 

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() 

27 

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) 

31 

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() 

38 

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)