Coverage for gpaw/test/generic/test_move_across_cell.py: 95%
21 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-20 00:19 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-20 00:19 +0000
1import pytest
2from ase.build import molecule
4from gpaw import GPAW, Davidson, MixerSum
6# Move atom infinitesimally across cell border and test that SCF loop is still
7# well converged afterwards. If it is /not/ well converged, then the code
8# which compensates for discontinuity of phases is probably broken.
11@pytest.mark.parametrize(
12 'params',
13 [dict(mode='pw',
14 eigensolver=Davidson(3)),
15 dict(mode='pw',
16 eigensolver=Davidson(3),
17 parallel={'gpu': True}),
18 # pw + lcao extrapolation is currently broken (PWLFC lacks integrate2):
19 # dict(mode='pw', experimental={'reuse_wfs_method': 'lcao'}),
20 dict(mode='fd', h=0.3,
21 eigensolver=Davidson(3),
22 experimental={'reuse_wfs_method': 'lcao'}),
23 dict(mode='lcao', basis='sz(dzp)', h=0.3)])
24def test_generic_move_across_cell(gpaw_new, params):
25 params.update(
26 xc='oldLDA',
27 # make sure MixerSum works for spin-paired system also:
28 mixer=MixerSum(0.7),
29 kpts=[1, 1, 2])
30 if not gpaw_new and 'parallel' in params:
31 params.pop('parallel')
32 calc = GPAW(**params)
33 atoms = molecule('H2O', vacuum=2.5)
34 atoms.pbc = 1
36 # Translate O to corner:
37 atoms.positions -= atoms.positions[0, None, :]
39 # Be sure that we are on the positive axis:
41 atoms.calc = calc
43 eps = 1e-12
44 atoms.positions[0, :] = eps
45 atoms.get_potential_energy()
46 atoms.positions[0, 2] -= 2 * eps
47 atoms.get_potential_energy()
49 # We should be within the convergence criterion.
50 # It runs a minimum of three iterations:
51 if gpaw_new:
52 assert calc.dft.scf_loop.niter == 2
53 else:
54 assert calc.scf.niter == 3