Skip to content

Commit

Permalink
Update QCSubmit for removal of ChemicalEnvironment class in OFFTK >0.…
Browse files Browse the repository at this point in the history
…14.1 (#231)

* unpin openff-toolkit

* remove use of openff.toolkit.typing.chemistry

* also unpin openff-toolkit for psi4 tests

* add failing test raising SMIRKS error for no toolkit

* pass by checking for toolkits in exception
  • Loading branch information
ntBre authored Aug 16, 2023
1 parent feb7539 commit 48943d8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion devtools/conda-envs/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies:

# openmmforcefields brings in the full toolkit; if that is ever re-packaged
# this should be changed to openff-toolkit-base
- openff-toolkit == 0.14.0
- openff-toolkit >= 0.14.0
- openff-units >=0.2.1
- pydantic =1
- pyyaml
Expand Down
2 changes: 1 addition & 1 deletion devtools/conda-envs/psi4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies:

### Core dependencies.

- openff-toolkit-base == 0.14.0
- openff-toolkit-base >= 0.14.0
- openff-units >=0.2.1
- rdkit
- pydantic =1
Expand Down
10 changes: 9 additions & 1 deletion openff/qcsubmit/tests/test_workflow_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ def test_smarts_filter_validator():
Make sure the validator is checking the allowed and filtered fields have valid smirks strings.
"""

from openff.toolkit.typing.chemistry import SMIRKSParsingError
from openff.toolkit.utils.exceptions import SMIRKSParsingError

with pytest.raises(ValidationError):
workflow_components.SmartsFilter(
Expand All @@ -901,6 +901,14 @@ def test_smarts_filter_validator():
# good smarts with no tagged atoms.
workflow_components.SmartsFilter(allowed_substructures=["[C]=[C]"])

from openff.toolkit.utils import ToolkitRegistry
from openff.toolkit.utils.toolkit_registry import _toolkit_registry_manager

# this test is the same as above, but without any toolkit available
with pytest.raises(ValueError):
with _toolkit_registry_manager(ToolkitRegistry()):
workflow_components.SmartsFilter(allowed_substructures=["[C]=[C]"])

# a good search string
smart_filter = workflow_components.SmartsFilter(
allowed_substructures=["[C:1]=[C:2]"]
Expand Down
40 changes: 25 additions & 15 deletions openff/qcsubmit/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
from typing import List, Tuple, Union

import qcelemental as qcel
from openff.toolkit import Molecule
from openff.toolkit import topology as off
from openff.toolkit.typing.chemistry.environment import (
ChemicalEnvironment,
SMIRKSParsingError,
)
from openff.toolkit.utils.exceptions import SMIRKSParsingError

from openff.qcsubmit.constraints import Constraints
from openff.qcsubmit.exceptions import (
Expand Down Expand Up @@ -288,14 +286,26 @@ def check_environments(environment: str) -> str:
"""

# try and make a new chemical environment checking for parse errors
_ = ChemicalEnvironment(smirks=environment)

# check for numeric tags in the environment
if re.search(":[0-9]]+", environment) is not None:
return environment

else:
raise SMIRKSParsingError(
"The smarts pattern passed had no tagged atoms please tag the atoms in the "
"substructure you wish to include/exclude."
)
try:
_ = Molecule().chemical_environment_matches(environment)
# check for numeric tags in the environment
if re.search(":[0-9]]+", environment) is not None:
return environment
except ValueError as e:
# only catch an error like 'No registered toolkits can provide the
# capability "find_smarts_matches" for args...' it would be nice for
# chemical_environment_matches to raise a more specific exception, but
# it just raises a ValueError
s = str(e)
if (
'capability "find_smarts_matches"' not in s
or "Available toolkits are: []" in s
):
raise e

# we've either already returned successfully, raised an unrelated
# exception, or failed to parse the smirks
raise SMIRKSParsingError(
"The smarts pattern passed had no tagged atoms please tag the atoms in the "
"substructure you wish to include/exclude."
)

0 comments on commit 48943d8

Please sign in to comment.