Skip to content

BUG: mismanagement of MLFF enum in ase_calculator #1205

@gpetretto

Description

@gpetretto

Describe the bug
This is probably a minor issue, since most of the ase calculators are managed through subclasses of the ForceFieldMDMaker, however the ase_calculator does not work as expected from the definition of the API, since passing an MLFF instance is not properly recognized.
The reason is this check:

if isinstance(calculator_meta, str | MLFF) and calculator_meta in map(str, MLFF):

Since str(MLFF.MACE) gives 'MLFF.MACE', this check translates in something like MLFF.MACE in ["MLFF.FACE", ...] which resolves to False.

Overall the ForceFieldMDMaker works because it always converts MLFF to a string:

str(self.force_field_name), # make mypy happy

I am not opening a PR because I am not sure how you would rather address this. In principle changing the code so that it accepts the string "MACE" instead of "MLFF.MACE" may be a backward incompatible change.

To Reproduce

from atomate2.forcefields import MLFF
from atomate2.forcefields.utils import ase_calculator

ase_calculator(MLFF.MACE) # raises an error: ValueError: Could not create ASE calculator for MLFF.MACE.
ase_calculator("MACE") # raises an error: ValueError: Could not create ASE calculator for MLFF.MACE.
ase_calculator(str(MLFF.MACE)) # works
ase_calculator("MLFF.MACE") # works

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions