Skip to content

Commit

Permalink
Fix ASE test for changed SumCalculator API
Browse files Browse the repository at this point in the history
  • Loading branch information
awvwgk committed Jun 7, 2024
1 parent 944cba7 commit c6bb18e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions python/dftd3/test_ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# You should have received a copy of the Lesser GNU General Public License
# along with s-dftd3. If not, see <https://www.gnu.org/licenses/>.

from typing import Iterator

import numpy as np
import pytest
from pytest import approx, raises
Expand All @@ -27,6 +29,12 @@
ase = None


def get_calcs(calc) -> Iterator[ase.calculators.calculator.Calculator]:
if hasattr(calc, "mixer"):
calc = calc.mixer
yield from calc.calcs


@pytest.mark.skipif(ase is None, reason="requires ase")
def test_ase_scand4():
thr = 1.0e-6
Expand Down Expand Up @@ -54,7 +62,7 @@ def test_ase_scand4():

atoms.calc = DFTD3(method="SCAN", damping="d3bj").add_calculator(EMT())
assert atoms.get_potential_energy() == approx(3.6452960962398406, abs=thr)
energies = [calc.get_potential_energy() for calc in atoms.calc.calcs]
energies = [calc.get_potential_energy() for calc in get_calcs(atoms.calc)]
assert energies == approx([-0.03880921894019244, 3.684105315180033], abs=thr)


Expand Down Expand Up @@ -87,5 +95,5 @@ def test_ase_tpssd4():

atoms.calc = DFTD3(method="TPSS", damping="d3zero").add_calculator(EMT())
assert atoms.get_potential_energy() == approx(4.963774668847532, abs=thr)
energies = [calc.get_potential_energy() for calc in atoms.calc.calcs]
energies = [calc.get_potential_energy() for calc in get_calcs(atoms.calc)]
assert energies == approx([-0.14230914516094673, 5.106083814008478], abs=thr)

0 comments on commit c6bb18e

Please sign in to comment.