-
Notifications
You must be signed in to change notification settings - Fork 86
Remove CMMRemover (if present) in SMIRNOFFTemplateGenerator #367
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
Conversation
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #367 +/- ##
==========================================
+ Coverage 69.57% 69.75% +0.18%
==========================================
Files 5 5
Lines 825 830 +5
==========================================
+ Hits 574 579 +5
Misses 251 251 ☔ View full report in Codecov by Sentry. |
| for f_idx in range(system.getNumForces()): | ||
| force = system.getForce(f_idx) | ||
| if "CMMotionRemover" in str(force): | ||
| system.removeForce(f_idx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little safer - hard to expect multiple CMM removers, but this is modifying a list while iterating over it. Not sure what happens if, for example, the force is listed last
| system.removeForce(f_idx) | |
| break | |
| system.removeForce(f_idx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loop in reverse order from system.getNumForces()-1 down to 0. That way the indices will still be correct if you remove one.
The best way to check the force type is if isinstance(force, CMMotionRemover).
Why are you removing CMMotionRemovers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check here flags it as a custom force:
openmmforcefields/openmmforcefields/generators/template_generators.py
Lines 1116 to 1131 in 7a32d2d
| supported_forces = { | |
| "NonbondedForce", | |
| "HarmonicAngleForce", | |
| "HarmonicBondForce", | |
| "PeriodicTorsionForce", | |
| } | |
| # Compile forces into a dict | |
| forces = dict() | |
| for force in system.getForces(): | |
| force_name = force.__class__.__name__ | |
| if force_name in forces: | |
| raise ForceException(f"Two instances of force {force_name} appear in System") | |
| if force_name not in supported_forces: | |
| raise ForceException(f"Custom forces not supported. Found force of type {force_name}.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That means you should fix the check, not remove the force. The default for createSystem() is removeCMMotion=True. This change would break it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check happens when generating the residue template from OpenFF tooling, not the system that's ultimately passed to the user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would need to look at the code more closely, but what happens if when iterating over system.getForces() you just continue if the force is CMMotionRemover? That should keep it out of the forces dict?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so if we go with my idea, CMMotionRemover won't end up in the ffxml when you call generate_residue_template -- is that a problem? If it is, then all we need to do is write CMMotionRemover into the ffxml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're considering two approaches:
- (the initial approach of this PR) Delete
CMMotionRemoverfrom OpenFF-generated systems during template generation - ("@mikemhenry's approach") Skip over
CMMotionRemoversinOpenMMSystemMixin.convert_system_to_ffxml
I've tried both of these locally and approach 1 seems like a better idea, since
- the new behavior is narrowly applied only to OpenFF-generated systems rather than affecting all mixins
- approach 2 also requires changing a test of all template generators since it also compared the Force objects on two generated systems.
@peastman Thanks for the code tips, I'll add those.
Why are you removing CMMotionRemovers?
The CMMotionRemover started getting added to OpenFF-generated OpenMM systems in the Interchange 0.4.2 release yesterday. This broke SMIRNOFFTemplateGenerator since it wasn't expecting the new Force when creating residue templates.
The default for createSystem() is removeCMMotion=True.
My understanding is that the change proposed in this PR does not interact with that behavior. This is just cleaning up the generation of templates. The actual inclusion of the CMMotionRemover in the final system is still dependent on the removeCMMotion argument to createSystem .
If there are no objections, I'll advance this PR along the lines of approach 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strong preference for 1
for more information, see https://pre-commit.ci
epretti
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Since Matt has also approved, I will go ahead and merge.
Uh oh!
There was an error while loading. Please reload this page.