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