Skip to content

Update for OpenMMForceFields 0.16, refactor validation and add tests - #394

Open
j-wags wants to merge 6 commits into
mainfrom
update-for-ommffs-015
Open

Update for OpenMMForceFields 0.16, refactor validation and add tests#394
j-wags wants to merge 6 commits into
mainfrom
update-for-ommffs-015

Conversation

@j-wags

@j-wags j-wags commented Jul 28, 2026

Copy link
Copy Markdown
Member

OpenMMForceFields 0.16.0 has a major update of SMIRNOFFTemplateGenerator which, among other things, makes all "shorthand" forcefields (eg openff-1.1.0) be routed to their unconstrained variant (as opposed to blanket-deleting the Constraints section from all SMIRNOFF forcefields) and no longer accepts the shorthand openff_unconstrained-1.1.0 (rather it must be openff_unconstrained-1.1.0.offxml).

This PR replaces some previously- logic which removed the .offxml suffix from user-input force field names, and refactors the validation logic, with AI adding tests based on the edge cases encountered during the refactor.

Status

  • Ready to go

@j-wags j-wags changed the title Update for OpenMMForceFields 015 Update for OpenMMForceFields 0.16 Jul 28, 2026
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.24%. Comparing base (f9b0d3f) to head (9f83496).

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@j-wags j-wags changed the title Update for OpenMMForceFields 0.16 Update for OpenMMForceFields 0.16, refactor validation and add tests Jul 28, 2026
@j-wags
j-wags marked this pull request as ready for review July 28, 2026 23:05

@Yoshanuikabundi Yoshanuikabundi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 major blocking issues: the psi4 tests are now skipped which I don't believe was intended, and the method lowercasing raises a confusing error (and mangles filenames that may be case sensitive). I think the psi4 tests will demonstrate the other blocking comment.

Non-blocking stuff is just odd phrasing in docstrings and a possible breaking change that you might want to address.

This also needs a release history note before merging.

Comment thread .github/workflows/CI.yml
Comment on lines +40 to +41
#- os: ubuntu-latest
# conda-env: psi4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BLOCKING: Did you mean to leave this in?

Comment on lines +252 to +253
The default (psi4) QCSpec, and any other non-"openmm" program, must never
even attempt to import openmmforcefields: it's an optional dependency, and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NON-BLOCKING: This test can't establish that no attempt is made to import openmmforcefields, only that a missing import error doesn't propagate up.

Comment on lines +575 to +585
allowed_methods = {
"smirnoff": list(get_available_force_fields())
+ SMIRNOFFTemplateGenerator.INSTALLED_FORCEFIELDS,
"antechamber": GAFFTemplateGenerator.INSTALLED_FORCEFIELDS,
}[basis]
if method not in allowed_methods:
raise QCSpecificationError(
f"The method {method} is not supported for the program {program} with "
f"basis {basis}, please choose from {allowed_methods}"
)
method = method.lower()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BLOCKING: method is made lowercase on line 561, but allowed_methods can load upper case names from get_available_force_fields(), leading to the very confusing:

>>> QCSpec(method="openff-1.0.0-RC1.offxml", basis="smirnoff", program="openmm")
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    QCSpec(method="openff-1.0.0-RC1.offxml", basis="smirnoff", program="openmm")
    ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/joshmitchell/Documents/openff/openff-qcsubmit/openff/qcsubmit/common_structures.py", line 581, in __init__
    raise QCSpecificationError(
    ...<2 lines>...
    )
openff.qcsubmit.exceptions.QCSpecificationError: The method openff-1.0.0-rc1.offxml is not supported for the program openmm with basis smirnoff, please choose from [<--snip-->]

I don't think its as simple as just lower casing everything in allowed_methods either, because they're filenames and most file systems are case sensitive. I question both the method.lower() in line 561 and the redundant one on line 585 - surely force field names are case sensitive?

Comment on lines +169 to +179
def test_bare_unconstrained_method_rejected():
"""
"openff_unconstrained-X.Y.Z" (no .offxml extension) is not a name that
openmmforcefields' SMIRNOFFTemplateGenerator recognizes: it isn't in the
curated shorthand list (bare "openff-X.Y.Z" names, which already resolve
to the unconstrained variant) and it isn't a valid filename on its own.
This should be rejected here, rather than passing validation and later
failing deep inside SystemGenerator with a confusing error.
"""
with pytest.raises(QCSpecificationError):
QCSpec(method="openff_unconstrained-1.0.0", basis="smirnoff", program="openmm")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NON-BLOCKING: I think this behavior may make old serialized-to-disk QCSpecs unreadable - they could be serialized as "openff_unconstrained-X.Y.Z" which is now an error. May or may not be a problem.

Comment on lines +178 to +179
with pytest.raises(QCSpecificationError):
QCSpec(method="openff_unconstrained-1.0.0", basis="smirnoff", program="openmm")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BLOCKING: I think this test (possibly some others too) fails if openmmtools isn't installed - the method name isn't checked (as tested by test_openmm_validation_skipped_without_openmmforcefields()) and so it doesn't raise.

@j-wags j-wags self-assigned this Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants