Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix silent error when running NotImplemented functions #6

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/atomate2/ase/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ def run_ase(
A previous calculation directory to copy output files from. Unused, just
added to match the method signature of other makers.
"""
return NotImplemented
raise NotImplementedError

@property
def calculator(self) -> Calculator:
"""ASE calculator, method to be implemented in subclasses."""
return NotImplemented
raise NotImplementedError


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion src/atomate2/ase/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def _callback(dyn: MolecularDynamics = md_runner) -> None:
@property
def calculator(self) -> Calculator:
"""ASE calculator, to be overwritten by user."""
return NotImplemented
raise NotImplementedError


@dataclass
Expand Down
3 changes: 3 additions & 0 deletions src/atomate2/forcefields/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ def ase_calculator(calculator_meta: str | dict, **kwargs: Any) -> Calculator | N
calc_cls = MontyDecoder().decode(json.dumps(calculator_meta))
calculator = calc_cls(**kwargs)

if calculator is None:
raise ValueError("Could not create ASE calculator.")

return calculator


Expand Down
5 changes: 5 additions & 0 deletions tests/forcefields/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def test_ext_load(force_field: str):
assert calc_from_decode.parameters == calc_from_preset.parameters == {}


def test_raises_error():
with pytest.raises(ValueError, match="Could not create"):
ase_calculator("not_a_calculator")


def test_m3gnet_pot():
import matgl
from matgl.ext.ase import PESCalculator
Expand Down
Loading