-
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
Changes from all commits
d25a1a3
10db658
5f02826
de0f3df
58e3335
37b6417
47496ae
831bc8b
858d893
4dfe8e1
8153199
d1878fb
787c089
5981249
9b095f9
a16a426
1788c64
706c84c
3b5687f
0df39aa
800c2f1
ec518e7
ae283a8
ad9b5a0
c4a370c
62c0edb
78cfcdd
c37ab5a
fc431e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| from openff.toolkit import ForceField, Molecule, Quantity, Topology, unit | ||
| from openff.toolkit._tests.mocking import VirtualSiteMocking | ||
| from openff.toolkit._tests.utils import does_not_raise | ||
| from openff.toolkit.typing.engines.smirnoff import NAGLChargesHandler | ||
| from openff.toolkit.typing.engines.smirnoff.parameters import ( | ||
| AngleHandler, | ||
| BondHandler, | ||
|
|
@@ -2722,6 +2723,201 @@ def test_charge_increment_one_ci_missing(self): | |
| ], | ||
| ) | ||
|
|
||
| class TestNAGLChargesHandler: | ||
| def test_nagl_charges_handler_serialization(self): | ||
| handler = NAGLChargesHandler(model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", skip_version_check=True) | ||
| assert handler.model_file == "openff-gnn-am1bcc-0.1.0-rc.3.pt" | ||
| handler_dict = handler.to_dict() | ||
| assert handler_dict["model_file"] == "openff-gnn-am1bcc-0.1.0-rc.3.pt" | ||
|
|
||
| def test_nagl_charges_handler_with_optional_fields(self): | ||
| # Test with model_file_hash | ||
| handler = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| model_file_hash="144ed56e46c5b3ad80157b342c8c0f8f7340e4d382a678e30dd300c811646bd0", | ||
| skip_version_check=True | ||
| ) | ||
| assert handler.model_file == "openff-gnn-am1bcc-0.1.0-rc.3.pt" | ||
| assert handler.model_file_hash == "144ed56e46c5b3ad80157b342c8c0f8f7340e4d382a678e30dd300c811646bd0" | ||
| assert handler.digital_object_identifier is None | ||
|
|
||
| # Test with digital_object_identifier | ||
| handler = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| digital_object_identifier="10.5072/zenodo.203601", | ||
| skip_version_check=True | ||
| ) | ||
| assert handler.model_file == "openff-gnn-am1bcc-0.1.0-rc.3.pt" | ||
| assert handler.model_file_hash is None | ||
| assert handler.digital_object_identifier == "10.5072/zenodo.203601" | ||
|
|
||
| # Test with both optional fields | ||
| handler = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| model_file_hash="144ed56e46c5b3ad80157b342c8c0f8f7340e4d382a678e30dd300c811646bd0", | ||
| digital_object_identifier="10.5072/zenodo.203601", | ||
| skip_version_check=True | ||
| ) | ||
| assert handler.model_file == "openff-gnn-am1bcc-0.1.0-rc.3.pt" | ||
| assert handler.model_file_hash == "144ed56e46c5b3ad80157b342c8c0f8f7340e4d382a678e30dd300c811646bd0" | ||
| assert handler.digital_object_identifier == "10.5072/zenodo.203601" | ||
|
|
||
| def test_nagl_charges_handler_serialization_with_optional_fields(self): | ||
| # Test serialization with all fields | ||
| handler = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| model_file_hash="144ed56e46c5b3ad80157b342c8c0f8f7340e4d382a678e30dd300c811646bd0", | ||
| digital_object_identifier="10.5072/zenodo.203601", | ||
| skip_version_check=True | ||
| ) | ||
| handler_dict = handler.to_dict() | ||
| assert handler_dict["model_file"] == "openff-gnn-am1bcc-0.1.0-rc.3.pt" | ||
| assert handler_dict["model_file_hash"] == "144ed56e46c5b3ad80157b342c8c0f8f7340e4d382a678e30dd300c811646bd0" | ||
| assert handler_dict["digital_object_identifier"] == "10.5072/zenodo.203601" | ||
|
|
||
| # Test deserialization via constructor | ||
| handler_from_dict = NAGLChargesHandler(**handler_dict) | ||
| assert handler_from_dict.model_file == "openff-gnn-am1bcc-0.1.0-rc.3.pt" | ||
| assert handler_from_dict.model_file_hash == "144ed56e46c5b3ad80157b342c8c0f8f7340e4d382a678e30dd300c811646bd0" | ||
| assert handler_from_dict.digital_object_identifier == "10.5072/zenodo.203601" | ||
|
|
||
| def test_nagl_charges_handler_compatibility(self): | ||
| # Test compatible handlers (same model_file) | ||
| handler1 = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| skip_version_check=True | ||
| ) | ||
| handler2 = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| model_file_hash="144ed56e46c5b3ad80157b342c8c0f8f7340e4d382a678e30dd300c811646bd0", | ||
| skip_version_check=True | ||
| ) | ||
| # Should not raise exception | ||
| handler1.check_handler_compatibility(handler2) | ||
|
|
||
| # Test incompatible handlers (different model_file) | ||
| handler3 = NAGLChargesHandler( | ||
| model_file="different-model-file.pt", | ||
| skip_version_check=True | ||
| ) | ||
| with pytest.raises(IncompatibleParameterError, match="different model_files"): | ||
| handler1.check_handler_compatibility(handler3) | ||
|
|
||
| def test_nagl_charges_handler_defaults(self): | ||
| # Test that optional fields default to None | ||
| handler = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| skip_version_check=True | ||
| ) | ||
| assert handler.model_file_hash is None | ||
| assert handler.digital_object_identifier is None | ||
|
|
||
| def test_nagl_charges_handler_hash_compatibility(self): | ||
| """Test compatibility checks for model_file_hash""" | ||
| # Test compatible handlers with same hash | ||
| handler1 = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| model_file_hash="144ed56e46c5b3ad80157b342c8c0f8f7340e4d382a678e30dd300c811646bd0", | ||
| skip_version_check=True | ||
| ) | ||
| handler2 = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| model_file_hash="144ed56e46c5b3ad80157b342c8c0f8f7340e4d382a678e30dd300c811646bd0", | ||
| skip_version_check=True | ||
| ) | ||
| # Should not raise exception | ||
| handler1.check_handler_compatibility(handler2) | ||
|
|
||
| # Test incompatible handlers with different hashes | ||
| handler3 = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| model_file_hash="different_hash_value", | ||
| skip_version_check=True | ||
| ) | ||
| with pytest.raises(IncompatibleParameterError, match="different model_file_hash values"): | ||
| handler1.check_handler_compatibility(handler3) | ||
|
|
||
| # Test compatibility when only one handler has hash (should be compatible) | ||
| handler4 = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| skip_version_check=True | ||
| ) | ||
| # Should not raise exception | ||
| handler1.check_handler_compatibility(handler4) | ||
| handler4.check_handler_compatibility(handler1) | ||
|
|
||
| def test_nagl_charges_handler_doi_compatibility(self): | ||
| """Test compatibility checks for digital_object_identifier""" | ||
| # Test compatible handlers with same DOI | ||
| handler1 = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| digital_object_identifier="10.5072/zenodo.203601", | ||
| skip_version_check=True | ||
| ) | ||
| handler2 = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| digital_object_identifier="10.5072/zenodo.203601", | ||
| skip_version_check=True | ||
| ) | ||
| # Should not raise exception | ||
| handler1.check_handler_compatibility(handler2) | ||
|
|
||
| # Test incompatible handlers with different DOIs | ||
| handler3 = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| digital_object_identifier="10.5072/zenodo.999999", | ||
| skip_version_check=True | ||
| ) | ||
| with pytest.raises(IncompatibleParameterError, match="different digital_object_identifier values"): | ||
| handler1.check_handler_compatibility(handler3) | ||
|
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. (not blocking) Might be worth symmetrizing each of these, though really unlikely to be an issue |
||
|
|
||
| # Test compatibility when only one handler has DOI (should be compatible) | ||
| handler4 = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| skip_version_check=True | ||
| ) | ||
| # Should not raise exception | ||
| handler1.check_handler_compatibility(handler4) | ||
| handler4.check_handler_compatibility(handler1) | ||
|
|
||
| def test_nagl_charges_handler_combined_compatibility(self): | ||
| """Test compatibility checks with both hash and DOI""" | ||
| # Test compatible handlers with same hash and DOI | ||
| handler1 = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| model_file_hash="144ed56e46c5b3ad80157b342c8c0f8f7340e4d382a678e30dd300c811646bd0", | ||
| digital_object_identifier="10.5072/zenodo.203601", | ||
| skip_version_check=True | ||
| ) | ||
| handler2 = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| model_file_hash="144ed56e46c5b3ad80157b342c8c0f8f7340e4d382a678e30dd300c811646bd0", | ||
| digital_object_identifier="10.5072/zenodo.203601", | ||
| skip_version_check=True | ||
| ) | ||
| # Should not raise exception | ||
| handler1.check_handler_compatibility(handler2) | ||
|
|
||
| # Test incompatible with same hash but different DOI | ||
| handler3 = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| model_file_hash="144ed56e46c5b3ad80157b342c8c0f8f7340e4d382a678e30dd300c811646bd0", | ||
| digital_object_identifier="10.5072/zenodo.999999", | ||
| skip_version_check=True | ||
| ) | ||
| with pytest.raises(IncompatibleParameterError, match="different digital_object_identifier values"): | ||
| handler1.check_handler_compatibility(handler3) | ||
|
|
||
| # Test incompatible with different hash but same DOI | ||
| handler4 = NAGLChargesHandler( | ||
| model_file="openff-gnn-am1bcc-0.1.0-rc.3.pt", | ||
| model_file_hash="different_hash_value", | ||
| digital_object_identifier="10.5072/zenodo.203601", | ||
| skip_version_check=True | ||
| ) | ||
| with pytest.raises(IncompatibleParameterError, match="different model_file_hash values"): | ||
| handler1.check_handler_compatibility(handler4) | ||
|
Comment on lines
+2918
to
+2919
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. (not blocking) if the DOI and hash are BOTH non-matching one will be part of the error message and the other won't be. If it's trivial, it might be useful to include both in the error message. Either way, might be worth having a test that encodes which of them are included in the error message |
||
|
|
||
|
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. (certainly not blocking) the earlier tests looked at combinations of optional arguments missing but in ways that could be combined. A marginal add would be those cases in this test, but not particularly important |
||
|
|
||
| class TestGBSAHandler: | ||
| def test_create_default_gbsahandler(self): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.