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

13 statements  

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

1from ase.units import Bohr 

2from gpaw.new.ase_interface import GPAW 

3from gpaw.utilities.dipole import dipole_matrix_elements_from_calc 

4 

5 

6def test_dipole_me(gpw_files): 

7 """Check dipole matrix-elements for H2 molecule.""" 

8 calc = GPAW(gpw_files['h2_pw']) 

9 

10 # Method 1: evaluate all-electron wave functions on fine grid: 

11 psi0, psi1 = ( 

12 calc.dft.ibzwfs.get_all_electron_wave_function(n) 

13 for n in [0, 1]) 

14 if psi0 is not None: 

15 d1_v = (psi0 * psi1).moment() * Bohr 

16 

17 # Method 2: use pseudo wave function + PAW corrections: 

18 d2_nnv = dipole_matrix_elements_from_calc(calc, n1=0, n2=2)[0] 

19 

20 assert abs(d2_nnv[0, 0] - calc.atoms.cell.sum(0) / 2).max() < 0.04 

21 assert abs(d2_nnv[1, 1] - calc.atoms.cell.sum(0) / 2).max() < 0.04 

22 if psi0 is not None: 

23 assert abs(d2_nnv[0, 1] - d1_v).max() < 1e-3