File: test_nsteps.py

package info (click to toggle)
python-ase 3.26.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (31 lines) | stat: -rw-r--r-- 680 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# fmt: off
import pytest

from ase.build import bulk
from ase.calculators.emt import EMT
from ase.optimize import BFGS


@pytest.fixture()
def opt():
    atoms = bulk('Au', cubic=True)
    atoms.rattle(stdev=0.12345, seed=42)
    atoms.calc = EMT()
    with BFGS(atoms) as opt:
        yield opt


@pytest.mark.parametrize('steps', [0, 1, 4])
def test_nsteps(opt, steps):
    """Test if the number of iterations is as expected.

    For opt.irun(steps=n), the number of iterations should be n + 1,
    including 0 and n.
    """
    irun = opt.irun(fmax=0, steps=steps)

    for _ in range(steps + 1):
        next(irun)

    with pytest.raises(StopIteration):
        next(irun)