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

[DNM] Allow "experimental-auto" idivf #1823

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
21 changes: 20 additions & 1 deletion openff/toolkit/typing/engines/smirnoff/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,25 @@ def _linear_inter_or_extrapolate(points_dict, x_query):
return k


def _idivf_validator(value) -> Callable:
"""
Fairly hacky converter/validator for (proper torsion) idivf.

Accepted values are "experimental-auto" or any int. Anything that can be
passed to `int()` without error is cast to int.
"""
try:
# gobble up float or int
return int(value)
except ValueError:
if not isinstance(value, str):
raise SMIRNOFFSpecError("Invalid idivf type {type(value)=}")
if value != "experimental-auto":
raise SMIRNOFFSpecError(f"Invalid idivf value {value}")

return value


# TODO: This is technically a validator, not a converter, but ParameterAttribute doesn't support them yet
# (it'll be easy if we switch to use the attrs library).
def _allow_only(allowed_values):
Expand Down Expand Up @@ -2592,7 +2611,7 @@ class ProperTorsionType(ParameterType):
periodicity = IndexedParameterAttribute(converter=int)
phase = IndexedParameterAttribute(unit=unit.degree)
k = IndexedParameterAttribute(default=None, unit=unit.kilocalorie / unit.mole)
idivf = IndexedParameterAttribute(default=None, converter=float)
idivf = IndexedParameterAttribute(default=None, converter=_idivf_validator)

# fractional bond order params
k_bondorder = IndexedMappedParameterAttribute(
Expand Down
Loading