-
Notifications
You must be signed in to change notification settings - Fork 19
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
OpenMMSolvation: Support for non-cubic boxes and defined box properties #673
Merged
Merged
Changes from 38 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
5fad809
Update system creation for new solvent component options
IAlibay aba7c26
Merge branch 'main' into noncubic-solvent
IAlibay a1426f6
temporary changes
IAlibay 281b329
Lots of docstring
IAlibay aa96a26
bit more settings update
IAlibay 467bfa9
Merge branch 'solvation-prep' into noncubic-solvent
IAlibay 0a04aa8
few more merge conflicts
IAlibay 61084d8
bit more fixing
IAlibay bfe8a13
box vector validation
IAlibay caabe57
Add extra validators
IAlibay d21dea7
Add validator method
IAlibay 81dea38
Update system creation to use new settings
IAlibay f3b3e68
settings validation tests
IAlibay 6caaf73
add all the tests
IAlibay 0d77162
fix tokenization
IAlibay 7c93107
pin gufe
IAlibay b3abd27
Merge branch 'main' into noncubic-solvent
IAlibay dd20b4d
pin minimum version of openmm
IAlibay a702c8f
shim to pin gufe for now
IAlibay b80ad7d
Merge branch 'main' into noncubic-solvent
IAlibay fa096cd
remove gufe pin
IAlibay 8ac0ce8
unpin gufe in ci
IAlibay 1d7bd6a
re-generate results
IAlibay e51afd1
update keys
IAlibay 6df8e98
add missing tests
IAlibay 59c28fb
Merge branch 'main' into noncubic-solvent
IAlibay fadbe0c
mapping instead of dict
IAlibay bd42ecf
Merge branch 'main' into noncubic-solvent
IAlibay bfa226c
fix tests
IAlibay 75b9e9b
update slow test for settings changes
IAlibay 1cc7652
Merge branch 'main' into noncubic-solvent
IAlibay 3ae0168
Merge branch 'main' into noncubic-solvent
IAlibay 9911207
Update test_solvation_afe_tokenization.py
IAlibay 2a63486
Update openfe/tests/protocols/test_rfe_tokenization.py
IAlibay 051fb2f
Merge branch 'main' into noncubic-solvent
IAlibay 3d7cade
Apply suggestions from code review
IAlibay ac71463
Merge branch 'main' into noncubic-solvent
mikemhenry 7a9d6f9
Merge branch 'main' into noncubic-solvent
IAlibay a90bd69
Add news entry
IAlibay 80d2a74
Merge branch 'main' into noncubic-solvent
IAlibay a9d8fb5
Merge branch 'main' into noncubic-solvent
mikemhenry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,8 @@ | |
|
||
from typing import Optional, Literal | ||
from openff.units import unit | ||
from openff.models.types import FloatQuantity | ||
from openff.models.types import FloatQuantity, ArrayQuantity | ||
from openff.interchange.components._packmol import _box_vectors_are_in_reduced_form | ||
|
||
from gufe.settings import ( | ||
Settings, | ||
|
@@ -26,38 +27,183 @@ | |
|
||
class BaseSolvationSettings(SettingsBaseModel): | ||
""" | ||
Base class for SolvationSettings objects | ||
Base class for SolvationSettings objects. | ||
""" | ||
class Config: | ||
arbitrary_types_allowed = True | ||
|
||
|
||
class OpenMMSolvationSettings(BaseSolvationSettings): | ||
"""Settings for controlling how a system is solvated using OpenMM tooling | ||
"""Settings for controlling how a system is solvated using OpenMM tooling. | ||
|
||
Defining the number of waters | ||
----------------------------- | ||
|
||
The number of waters is controlled by either: | ||
a) defining a solvent padding (``solvent_padding``) in combination | ||
with a box shape | ||
b) defining the number of solvent molecules | ||
(``number_of_solvent_molecules``) | ||
alongside the box shape (``box_shape``) | ||
c) defining the box directly either through the box vectors | ||
(``box_vectors``) or rectangular box lengths (``box_size``) | ||
|
||
When using ``solvent_padding``, ``box_vectors``, or ``box_size``, | ||
the exact number of waters added is determined automatically by OpenMM | ||
through :meth:`openmm.app.Modeller.addSolvent` internal heuristics. | ||
Briefly, the necessary volume required by a single water is estimated | ||
and then the defined target cell is packed with waters avoiding clashes | ||
with existing solutes and box edges. | ||
|
||
|
||
Defining the periodic cell size | ||
------------------------------- | ||
|
||
The periodic cell size is defined by one, and only one, of the following: | ||
* ``solvent_padding`` in combination with ``box_shape``, | ||
* ``number_of_solvent_molecules`` in combination with ``box_shape``, | ||
* ``box_vectors``, | ||
* ``box_size`` | ||
|
||
When using ``number_of_solvent_molecules``, the size of the cell is | ||
defined by :meth:`openmm.app.Modeller.addSolvent` internal heuristics, | ||
automatically selecting a padding value that is large enough to contain | ||
the number of waters based on a geometric estimate of the volume required | ||
by each water molecule. | ||
|
||
|
||
Defining the periodic cell shape | ||
--------------------------------- | ||
|
||
The periodic cell shape is defined by one, and only one, of the following: | ||
* ``box_shape``, | ||
* ``box_vectors``, | ||
* ``box_size`` | ||
|
||
Default settings will create a cubic box, although more space efficient | ||
shapes (e.g. ``dodecahedrons``) are recommended to improve simulation | ||
performance. | ||
|
||
|
||
Notes | ||
----- | ||
* The number of water molecules added will be affected by the number of | ||
ions defined in SolventComponent. For example, the value of | ||
``number_of_solvent_molecules`` is the sum of the number of counterions | ||
added and the number of water molecules added. | ||
* Solvent addition does not account for any pre-existing waters explicitly | ||
defined in the :class:`openfe.ChemicalSystem`. Any waters will be added | ||
in addition to those pre-existing waters. | ||
* No solvation will happen if a SolventComponent is not passed. | ||
|
||
|
||
See Also | ||
-------- | ||
:mod:`openmm.app.Modeller` | ||
Base class for SolvationSettings objects | ||
""" | ||
solvent_model: Literal['tip3p', 'spce', 'tip4pew', 'tip5p'] = 'tip3p' | ||
""" | ||
Force field water model to use when solvating and defining the model | ||
properties (e.g. adding virtual site particles). | ||
|
||
Allowed values are; `tip3p`, `spce`, `tip4pew`, and `tip5p`. | ||
""" | ||
solvent_padding: Optional[FloatQuantity['nanometer']] = 1.2 * unit.nanometer | ||
""" | ||
Minimum distance from any solute bounding sphere to the edge of the box. | ||
|
||
Note | ||
---- | ||
No solvation will happen if a SolventComponent is not passed. | ||
* Cannot be defined alongside ``number_of_solvent_molecules``, | ||
``box_size``, or ``box_vectors``. | ||
""" | ||
box_shape: Optional[Literal['cube', 'dodecahedron', 'octahedron']] = 'cube' | ||
""" | ||
The shape of the periodic box to create. | ||
|
||
Notes | ||
----- | ||
* Must be one of `cube`, `dodecahedron`, or `octahedron`. | ||
* Cannot be defined alongside ``box_vectors`` or ``box_size``. | ||
""" | ||
solvent_model: Literal['tip3p', 'spce', 'tip4pew', 'tip5p'] = 'tip3p' | ||
number_of_solvent_molecules: Optional[int] = None | ||
""" | ||
Force field water model to use. | ||
Allowed values are; `tip3p`, `spce`, `tip4pew`, and `tip5p`. | ||
The number of solvent molecules (water + ions) to add. | ||
|
||
Note | ||
---- | ||
* Cannot be defined alongside ``solvent_padding``, ``box_size``, | ||
or ``box_vectors``. | ||
""" | ||
box_vectors: Optional[ArrayQuantity['nanometer']] = None | ||
""" | ||
`OpenMM reduced form box vectors <http://docs.openmm.org/latest/userguide/theory/05_other_features.html#periodic-boundary-conditions>`. | ||
|
||
solvent_padding: FloatQuantity['nanometer'] = 1.2 * unit.nanometer | ||
"""Minimum distance from any solute atoms to the solvent box edge.""" | ||
Notes | ||
----- | ||
* Cannot be defined alongside ``solvent_padding``, | ||
``number_of_solvent_molecules``, or ``box_size``. | ||
|
||
See Also | ||
-------- | ||
:mod:`openff.interchange.components.interchange` | ||
:mod:`openff.interchange.components._packmol` | ||
""" | ||
box_size: Optional[ArrayQuantity['nanometer']] = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This inherits the name from OpenMM, it's not amazingly named. I.e. if you know what it is in OpenMM this makes sense, but if you don't then it may not... |
||
""" | ||
X, Y, and Z lengths of the unit cell for a rectangular box. | ||
|
||
Notes | ||
----- | ||
* Cannot be defined alongside ``solvent_padding``, | ||
``number_of_solvent_molecules``, or ``box_vectors``. | ||
""" | ||
|
||
@validator('box_vectors') | ||
def supported_vectors(cls, v): | ||
if v is not None: | ||
if not _box_vectors_are_in_reduced_form(v): | ||
errmsg = f"box_vectors: {v} are not in OpenMM reduced form" | ||
raise ValueError(errmsg) | ||
return v | ||
|
||
@validator('solvent_padding') | ||
def is_positive_distance(cls, v): | ||
# these are time units, not simulation steps | ||
if v is None: | ||
return v | ||
|
||
if not v.is_compatible_with(unit.nanometer): | ||
raise ValueError("solvent_padding must be in distance units " | ||
"(i.e. nanometers)") | ||
if v < 0: | ||
errmsg = "solvent_padding must be a positive value" | ||
raise ValueError(errmsg) | ||
|
||
return v | ||
|
||
@validator('number_of_solvent_molecules') | ||
def positive_solvent_number(cls, v): | ||
if v is None: | ||
return v | ||
|
||
if v <= 0: | ||
errmsg = f"number_of_solvent molecules: {v} must be positive" | ||
raise ValueError(errmsg) | ||
|
||
return v | ||
|
||
@validator('box_size') | ||
def box_size_properties(cls, v): | ||
if v is None: | ||
return v | ||
|
||
if v.shape != (3, ): | ||
errmsg = (f"box_size must be a 1-D array of length 3 " | ||
f"got {v} with shape {v.shape}") | ||
raise ValueError(errmsg) | ||
|
||
return v | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we document the min version of OpenMM we support? Or which versions?
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 do not, but we should!