Skip to content

Commit

Permalink
VS handler fix for 0.10.6 (#1470)
Browse files Browse the repository at this point in the history
* allowing to subclass VirtualSiteHandler

* Update openff/toolkit/typing/engines/smirnoff/forcefield.py

Co-authored-by: Matt Thompson <matt.thompson@openforcefield.org>

* PR1470 to pass tests

* qcportal >= 0.15

* Update environments of 0.10.x line

* A test case checking if the _find_matches is treated as a list.

* black

Co-authored-by: Matt Thompson <matt.thompson@openforcefield.org>
Co-authored-by: Matthew W. Thompson <mattwthompson@protonmail.com>
  • Loading branch information
3 people authored Nov 29, 2022
1 parent 5887e1f commit 6197dcf
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
4 changes: 2 additions & 2 deletions devtools/conda-envs/openeye.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ dependencies:
- msgpack-python
- xmltodict
- qcelemental
- qcportal
- qcportal >= 0.15
- qcengine
- mdtraj
- openff-interchange
- openff-interchange < 0.2
- python-constraint
4 changes: 2 additions & 2 deletions devtools/conda-envs/rdkit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ dependencies:
- msgpack-python
- xmltodict
- qcelemental
- qcportal
- qcportal >= 0.15
- qcengine
- mdtraj
- openff-interchange
- openff-interchange < 0.2
- python-constraint
4 changes: 2 additions & 2 deletions devtools/conda-envs/test_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ dependencies:
- bson
- msgpack-python
- qcelemental
- qcportal
- qcportal >= 0.15
- qcengine
- openff-interchange
- openff-interchange < 0.2
# Typing
- mypy
- typing-extensions
Expand Down
7 changes: 4 additions & 3 deletions examples/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ dependencies:
- notebook
- gromacs
- qcelemental
- qcportal
- qcportal >= 0.15
- qcengine
- openmmforcefields
# Below are dependencies of the toolkit; they are listed here as a reference
- mdtraj
- numpy
- openmm
- openff-forcefields >=2.0.0
- openff-interchange >=0.1.3
- openff-forcefields >= 2
- openff-interchange < 0.2
- gromacs
- lammps
- ambertools
- ipywidgets =7
27 changes: 27 additions & 0 deletions openff/toolkit/tests/test_forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -2224,6 +2224,33 @@ def test_issue_1216(self):
)
force_field.label_molecules(Molecule.from_smiles("CF").to_topology())

def test_issue_1422(self):
"""Inherited plugin VirtualSite handlers should be detected
and treated like VirtualSites
https://github.com/openforcefield/openff-toolkit/issues/1422
"""

class PluginVirtualSites(VirtualSiteHandler):
_TAGNAME = "InheritedTestVirtualSites"

def _find_matches(
self,
entity: Topology,
transformed_dict_cls=dict,
unique=False,
) -> Dict[Tuple[int], List[ParameterHandler._Match]]:
return {
(0,): [
ParameterHandler._Match(None, None),
ParameterHandler._Match(None, None),
]
}

force_field = ForceField()
force_field.get_parameter_handler("InheritedTestVirtualSites")
force_field.label_molecules(Molecule.from_smiles("CO").to_topology())


def generate_monatomic_ions():
return (
Expand Down
5 changes: 2 additions & 3 deletions openff/toolkit/typing/engines/smirnoff/forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -1489,9 +1489,6 @@ def label_molecules(self, topology):
for tag, parameter_handler in self._parameter_handlers.items():
param_is_list = False

if type(parameter_handler) == VirtualSiteHandler:
param_is_list = True

matches = parameter_handler.find_matches(top_mol)
# Remove the chemical environment matches from the
# matched results.
Expand All @@ -1506,6 +1503,8 @@ def label_molecules(self, topology):
# Now make parameter_matches into a dict mapping
# match objects to ParameterTypes

param_is_list = isinstance(parameter_handler, VirtualSiteHandler)

if param_is_list:
for match in matches:
parameter_matches[match] = [
Expand Down

0 comments on commit 6197dcf

Please sign in to comment.