Skip to content

Commit

Permalink
Updates for Interchange 0.4.0/Pydantic v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwthompson committed Sep 3, 2024
1 parent fffc9eb commit 9c73bf8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 2 additions & 5 deletions openff/toolkit/_tests/test_forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from openff.units.openmm import from_openmm, to_openmm
from openmm import NonbondedForce, Platform, XmlSerializer, app
from openmm import unit as openmm_unit
from pydantic import ValidationError

from openff.toolkit import unit
from openff.toolkit._tests.create_molecules import (
Expand Down Expand Up @@ -4028,15 +4029,11 @@ def test_fractional_bondorder_invalid_interpolation_method(self):
# This error will be either from v1 of the package (if v1 is installed)
# or the faked v1 API (if v2 is installed). Ensure the v1 error or a
# mimick of it is imported
try:
from pydantic.v1 import ValidationError
except ImportError:
from pydantic import ValidationError

# If important, this can be a custom exception instead of a verbose ValidationError
with pytest.raises(
ValidationError,
match="given=invalid method name",
match="Input should be 'linear'.*input_value='invalid method name'",
):
forcefield.create_openmm_system(
topology,
Expand Down
8 changes: 5 additions & 3 deletions openff/toolkit/typing/engines/smirnoff/forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ def get_partial_charges(self, molecule: "Molecule", **kwargs: Any) -> Quantity:
"""
from openff.interchange import Interchange

from openff.toolkit import Molecule, unit
from openff.toolkit import Molecule

if not isinstance(molecule, Molecule):
raise ValueError(
Expand All @@ -1412,9 +1412,11 @@ def get_partial_charges(self, molecule: "Molecule", **kwargs: Any) -> Quantity:
c.m
for c in Interchange.from_smirnoff(
force_field=self, topology=[molecule], **kwargs
)["Electrostatics"].charges.values()
)["Electrostatics"]
._get_charges()
.values()
],
unit.elementary_charge,
"elementary_charge",
)

def __getitem__(self, val: Union[str, ParameterHandler]) -> ParameterHandler:
Expand Down

0 comments on commit 9c73bf8

Please sign in to comment.