-
Notifications
You must be signed in to change notification settings - Fork 103
Implement NAGLChargesHandler #2048
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
d25a1a3
initial implementation of NAGLChargesHandler
j-wags 10db658
have testing env use naglcharges interchange branch
j-wags 5f02826
implement doi and hash fields
j-wags de0f3df
add tests
j-wags 58e3335
fix tests
j-wags 37b6417
add docstring
j-wags 47496ae
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 831bc8b
force use of nagl for test
j-wags 858d893
fix whitespace
j-wags 4dfe8e1
add doi and file_hash to nagltoolkitwrapper.assign_partial_charges, s…
j-wags 8153199
raise specific error for blank/none model_file values
j-wags d1878fb
improve docstring
j-wags 787c089
test with new openff-nagl-models
j-wags 5981249
update nagl test for bad suffix error
j-wags 9b095f9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a16a426
update toolkit registry check to use types rather than repr
j-wags 1788c64
add compatibility checks for doi and hash fields, add tests
j-wags 706c84c
lint
j-wags 3b5687f
move imports to top of file
j-wags 0df39aa
thread naglcharges handler into inits for correct import paths and docs
j-wags 800c2f1
remove commented code
j-wags ec518e7
have tests run without interchange branch
j-wags ae283a8
point to nagl-models main branch for pip installs
j-wags ad9b5a0
update expected error message in test
j-wags c4a370c
revert tests to using conda packages
j-wags 62c0edb
revert other test envs
j-wags 78cfcdd
Merge branch 'main' into naglcharges-handler
j-wags c37ab5a
Merge remote-tracking branch 'origin' into naglcharges-handler
j-wags fc431e2
update releasenotes
j-wags 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ | |
| "LibraryChargeHandler", | ||
| "LibraryChargeType", | ||
| "MappedParameterAttribute", | ||
| "NAGLChargesHandler", | ||
| "NotEnoughPointsForInterpolationError", | ||
| "ParameterAttribute", | ||
| "ParameterHandler", | ||
|
|
@@ -3253,6 +3254,102 @@ def find_matches(self, entity, unique=False): | |
| unique=unique, | ||
| ) | ||
|
|
||
| class NAGLChargesHandler(_NonbondedHandler): | ||
| """ParameterHandler for applying partial charges from a pretrained NAGL model. | ||
|
|
||
| This handler processes the NAGLCharges section of SMIRNOFF force fields, which | ||
| specifies a pre-trained NAGL model for computing | ||
| partial charges on molecules. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| model_file : str | ||
| Path to the PyTorch model file (e.g., "openff-gnn-am1bcc-0.1.0-rc.3.pt"). | ||
| This is the model that will be used for charge assignment. | ||
| model_file_hash : str, optional | ||
| SHA-256 hash of the model file for integrity verification. When provided, | ||
| the hash will be validated against the actual model file. | ||
| digital_object_identifier : str, optional | ||
| Zenodo DOI that can be used to retrieve the model file if it's not found | ||
| locally. Must point to a Zenodo record with an attached file matching | ||
| the model_file name. | ||
| version : str, optional | ||
| The version of the NAGLCharges section specification. | ||
| skip_version_check : bool, optional, default=False | ||
| If True, skips validation of the version parameter and sets it to the highest | ||
| supported version. | ||
| allow_cosmetic_attributes : bool, optional, default=False | ||
| If True, allows non-specification attributes to be present. | ||
|
|
||
| Examples | ||
| -------- | ||
| Create a handler with just the model file: | ||
|
|
||
| >>> handler = NAGLChargesHandler( | ||
| ... model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| ... skip_version_check=True | ||
| ... ) | ||
|
|
||
| Create a handler with hash verification: | ||
|
|
||
| >>> handler = NAGLChargesHandler( | ||
| ... model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| ... model_file_hash="144ed56e46c5b3ad80157b342c8c0f8f7340e4d382a678e30dd300c811646bd0", | ||
| ... skip_version_check=True | ||
| ... ) | ||
|
|
||
| Create a handler with DOI for model retrieval: | ||
|
|
||
| >>> handler = NAGLChargesHandler( | ||
| ... model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| ... digital_object_identifier="10.5072/zenodo.203601", | ||
| ... skip_version_check=True | ||
| ... ) | ||
|
|
||
| Notes | ||
| ----- | ||
| NAGLChargesHandler compatibility is determined solely by the model_file parameter. Two | ||
| handlers are compatible if and only if they specify the same model_file, | ||
| regardless of the values of model_file_hash or digital_object_identifier. | ||
|
|
||
| The actual model loading, hash verification, and DOI-based retrieval are | ||
| handled by the openff-nagl-models package, not by this handler directly. | ||
| """ | ||
|
|
||
| _TAGNAME = "NAGLCharges" | ||
| _DEPENDENCIES = [vdWHandler, ElectrostaticsHandler, LibraryChargeHandler] | ||
| _INFOTYPE = None # No separate parameter types; just a model path | ||
| _MAX_SUPPORTED_SECTION_VERSION = Version("0.3") | ||
| model_file = ParameterAttribute(converter=str) | ||
| model_file_hash = ParameterAttribute(default=None, converter=str) | ||
| digital_object_identifier = ParameterAttribute(default=None, converter=str) | ||
|
|
||
| def check_handler_compatibility( | ||
| self, | ||
| other_handler: "NAGLChargesHandler", | ||
| assume_missing_is_default: bool = True, | ||
| ): | ||
|
mattwthompson marked this conversation as resolved.
|
||
| """ | ||
| Checks whether this ParameterHandler encodes compatible physics as another ParameterHandler. This is | ||
| called if a second handler is attempted to be initialized for the same tag. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| other_handler | ||
| The handler to compare to. | ||
| assume_missing_is_default | ||
|
|
||
| Raises | ||
| ------ | ||
| IncompatibleParameterError if handler_kwargs are incompatible with existing parameters. | ||
| """ | ||
| if self.model_file != other_handler.model_file: | ||
| raise IncompatibleParameterError("Attempted to initialize two NAGLCharges sections with different " | ||
| "model_files: " | ||
| f"{self.model_file=} is not identical to {other_handler.model_file=}") | ||
|
|
||
|
|
||
|
|
||
|
|
||
| class ToolkitAM1BCCHandler(_NonbondedHandler): | ||
| """Handle SMIRNOFF ``<ToolkitAM1BCC>`` tags | ||
|
|
@@ -3261,7 +3358,7 @@ class ToolkitAM1BCCHandler(_NonbondedHandler): | |
| """ | ||
|
|
||
| _TAGNAME = "ToolkitAM1BCC" # SMIRNOFF tag name to process | ||
| _DEPENDENCIES = [vdWHandler, ElectrostaticsHandler, LibraryChargeHandler] | ||
|
Member
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. For better or worse, Interchange does not use this and I don't think anything else does |
||
| _DEPENDENCIES = [vdWHandler, ElectrostaticsHandler, LibraryChargeHandler, NAGLChargesHandler] | ||
| _KWARGS = ["toolkit_registry"] # Kwargs to catch when create_force is called | ||
|
|
||
| def check_handler_compatibility( | ||
|
|
@@ -3382,6 +3479,7 @@ def find_matches(self, entity, unique=False): | |
| return matches | ||
|
|
||
|
|
||
|
|
||
| class GBSAHandler(ParameterHandler): | ||
| """Handle SMIRNOFF ``<GBSA>`` tags | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.