Coverage for gpaw/test/test_multipoleH2O.py: 100%

24 statements  

« prev     ^ index     » next       coverage.py v7.7.1, created at 2025-07-20 00:19 +0000

1import numpy as np 

2import pytest 

3from ase.build import molecule 

4from ase.parallel import parprint 

5 

6from gpaw import GPAW 

7from gpaw.analyse.multipole import Multipole 

8from gpaw.utilities.adjust_cell import adjust_cell 

9 

10 

11@pytest.mark.old_gpaw_only 

12def test_multipoleH2O(in_tmp_dir): 

13 h = 0.3 

14 

15 s = molecule('H2O') 

16 adjust_cell(s, 3., h) 

17 

18 gpwname = 'H2O_h' + str(h) + '.gpw' 

19 s.calc = GPAW(mode='fd', h=h, charge=0, txt=None) 

20 s.get_potential_energy() 

21 s.calc.write(gpwname) 

22 

23 dipole_c = s.get_dipole_moment() 

24 parprint('Dipole', dipole_c) 

25 

26 center = np.array([1, 1, 1]) * 50. 

27 mp = Multipole(center, s.calc, lmax=2) 

28 q_L = mp.expand(-s.calc.density.rhot_g) 

29 parprint('Multipole', q_L) 

30 

31 # The dipole moment is independent of the center 

32 assert dipole_c[2] == pytest.approx(q_L[2], abs=1e-10) 

33 

34 mp.to_file(s.calc, mode='w')