Skip to content

Fix vsite fits#315

Merged
leeping merged 77 commits into
leeping:masterfrom
lilyminium:fix-vsite-fits
Apr 3, 2026
Merged

Fix vsite fits#315
leeping merged 77 commits into
leeping:masterfrom
lilyminium:fix-vsite-fits

Conversation

@lilyminium

@lilyminium lilyminium commented Mar 5, 2026

Copy link
Copy Markdown
Collaborator

This PR enables ForceBalance to optimize virtual site (v-site) parameters in SMIRNOFF force fields. Previously, the code raised a hard NotImplementedError for any SMIRNOFF system with virtual sites. This PR removes that block and implements the full pipeline needed for v-site parameter fitting. As usual I've tried to add explanatory comments to code changes.

This is rebased off of #312 so the earlier commits aren't relevant -- as usual would recommend squash-merging over merging this though!

Biggest changes

  • I added some new test files, these are the primary culprit for the 200k added lines. I can compress the targets if that's easier.
  • added a select_virtual_site_parameter to get virtual site parameters from OpenFF infrastructure
  • undid the commenting of unit_str so we can use parameter_eval and get parameters with units
  • fixed pgrad updating by scanning virtual site keys properly and getting SMIRKS properly
  • allowed pickling of Versions with protocol 0, this was recently erroring due to packaging version 26.0
  • Changed the behaviour of Evaluator_SMIRNOFF to not block on target submission, but target retrieval instead -- otherwise every other target has to wait until Evlauator is done before running.

New tests
I added two tests:

  1. studies/028: testing whether co-optimizing water and another molecule vdW would execute without erroring when fit pure water Liquid properties, AbInitio clusters, and Evaluator mixture properties. Unfortunately this is actually very slow, ~20 min to execute.
  2. studies/029: testing agreement of OpenMM and OpenFF gradients for TIP4P and TIP5P

@lilyminium

Copy link
Copy Markdown
Collaborator Author

2073.84s call src/tests/test_system.py::TestEvaluatorWaterVSiteStudy::test_water_vsite_study

Ohhhh, that's not good.

@lilyminium

Copy link
Copy Markdown
Collaborator Author

It's now down to 1300 seconds, which is still quite long -- maybe this test should be skipped for speed reasons.

@@ -0,0 +1,291 @@
import pytest

has_openff_toolkit = True

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This entire file just tests the new vsite parsing and assignment logic.

Comment thread src/tests/test_system.py

class TestEvaluatorBromineStudy(ForceBalanceSystemTest):

class EvaluatorServerMixin:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Refactor the Evaluator tests to not repeat so much

Comment thread src/forcefield.py
value_str, unit_str = quantity_str[:res.end()], quantity_str[res.end():]
# LPW 2023-01-23: Behavior of parameter unit string for "evaluated" parameter is undefined.
unit_str = ""
# unit_str = ""

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixes parameter_eval

Comment thread src/openmmio.py
vsprm.append(_openmm.OutOfPlaneSite_getWeight12(vs))
vsprm.append(_openmm.OutOfPlaneSite_getWeight13(vs))
vsprm.append(_openmm.OutOfPlaneSite_getWeightCross(vs))
elif vstype == 'LocalCoordinatesSite':

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

OpenFF vsites are convereted to localcoordinatesites

@lilyminium lilyminium marked this pull request as ready for review March 6, 2026 06:58
Comment thread devtools/conda-envs/test_env.yaml Outdated

- pip:
# install branch of evaluator
- git+https://github.com/openforcefield/openff-evaluator.git@fix-vsite-fits

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We will aim to get this merged and into a release ASAP, but this branch needed to be developed in tandem with the Evaluator one for testing to work (hence the same name)

Comment thread src/evaluator_io.py
self._pending_estimate_request.results(
True, polling_interval=self._options.polling_interval
)[0] is None
self._pending_estimate_request.results(False)[0] is None

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Having this blocking request here originally meant that other targets had to wait until Evaluator was done computing to even start -- which can be a while ...

Comment thread src/evaluator_io.py
Comment on lines +774 to +786
# Block until the Evaluator computation is finished. This is intentionally
# placed here (not in submit_jobs) so that Work Queue tasks submitted by other
# targets can run concurrently while we wait.
estimation_results, _ = self._pending_estimate_request.results(
True, polling_interval=self._options.polling_interval
)
if estimation_results is None:
raise RuntimeError(
"No `EvaluatorServer` could be found to retrieve results from. "
"Please double check that a server is running, and that the connection "
"settings specified in the input script are correct."
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I moved (and added the same runtimeerror check) this from the submit_jobs function above.

@leeping leeping merged commit d2cea4b into leeping:master Apr 3, 2026
71 of 72 checks passed
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