Skip to content
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

Fail OpenEye checks if installed but not licensed #164

Merged
merged 4 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion devtools/conda-envs/test_env.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: test
name: openff-fragmenter-test

channels:
- conda-forge
Expand All @@ -10,6 +10,7 @@ dependencies:
- python

- openff-toolkit-base >=0.11.0
- openff-utilities >=0.1.9
- ambertools
- rdkit
- pydantic
Expand Down
17 changes: 15 additions & 2 deletions openff/fragmenter/chemi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from openff.fragmenter.utils import get_atom_index, get_map_index
from openff.toolkit.topology import Molecule
from openff.toolkit.utils import LicenseError, ToolkitUnavailableException
from openff.utilities import MissingOptionalDependencyError, requires_oe_module

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -164,6 +165,7 @@ def find_ring_systems(molecule: Molecule) -> Dict[int, int]:
return ring_systems


@requires_oe_module("oechem")
def _find_oe_stereocenters(
molecule: Molecule,
) -> Tuple[List[int], List[Tuple[int, int]]]:
Expand Down Expand Up @@ -277,7 +279,12 @@ def find_stereocenters(molecule: Molecule) -> Tuple[List[int], List[Tuple[int, i

try:
stereogenic_atoms, stereogenic_bonds = _find_oe_stereocenters(molecule)
except (ModuleNotFoundError, ToolkitUnavailableException, LicenseError):
except (
ModuleNotFoundError,
ToolkitUnavailableException,
LicenseError,
MissingOptionalDependencyError,
):
stereogenic_atoms, stereogenic_bonds = _find_rd_stereocenters(molecule)

return stereogenic_atoms, stereogenic_bonds
Expand Down Expand Up @@ -379,6 +386,7 @@ def _extract_rd_fragment(
return fragment


@requires_oe_module("oechem")
def _extract_oe_fragment(
molecule: Molecule, atom_indices: Set[int], bond_indices: Set[Tuple[int, int]]
) -> Molecule:
Expand Down Expand Up @@ -471,7 +479,12 @@ def extract_fragment(

try:
fragment = _extract_oe_fragment(molecule, atom_indices, bond_indices)
except (ModuleNotFoundError, ToolkitUnavailableException, LicenseError):
except (
ModuleNotFoundError,
ToolkitUnavailableException,
LicenseError,
MissingOptionalDependencyError,
):
fragment = _extract_rd_fragment(molecule, atom_indices, bond_indices)

# Sanity check that all atoms are still bonded
Expand Down
8 changes: 7 additions & 1 deletion openff/fragmenter/depiction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
from openff.fragmenter.fragment import BondTuple, FragmentationResult
from openff.fragmenter.utils import get_map_index
from openff.toolkit.topology import Molecule
from openff.utilities import MissingOptionalDependencyError, requires_oe_module
from pkg_resources import resource_filename


@requires_oe_module("oechem")
def _oe_fragment_predicates(map_indices: Collection[int]):
"""Returns an atom and bond predicate which matches atoms whose map index
appears in the specified ``map_indices`` collection"""
Expand Down Expand Up @@ -43,6 +45,7 @@ def CreateCopy(self):
return PredicateAtoms(map_indices), PredicateBonds(map_indices)


@requires_oe_module("oedepict")
def _oe_wbo_label_display(bond_tuples: Collection[BondTuple]):
"""Returns a ``OEDisplayBondPropBase`` subclass which will label bonds with the
specified map indices with their WBO values if present.
Expand Down Expand Up @@ -75,6 +78,7 @@ def CreateCopy(self):
return LabelWibergBondOrder(bond_tuples)


@requires_oe_module("oedepict")
def _oe_render_parent(
parent: Molecule,
rotor_bonds: Optional[Collection[BondTuple]] = None,
Expand Down Expand Up @@ -113,6 +117,8 @@ def _oe_render_parent(
return svg_contents.decode()


@requires_oe_module("oedepict")
@requires_oe_module("oechem")
def _oe_render_fragment(
parent: Molecule,
fragment: Molecule,
Expand Down Expand Up @@ -328,7 +334,7 @@ def depict_fragments(
for bond_tuple, fragment in fragments.items()
]

except ModuleNotFoundError:
except (ModuleNotFoundError, MissingOptionalDependencyError):
header_svg = _rd_render_parent(parent)
fragment_svg = [
_rd_render_fragment(parent, fragment, bond_tuple)
Expand Down
5 changes: 3 additions & 2 deletions openff/fragmenter/tests/test_chemi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
ToolkitRegistry,
)
from openff.units import unit
from openff.utilities import MissingOptionalDependencyError


def test_assign_elf10_am1_bond_orders():
Expand Down Expand Up @@ -151,7 +152,7 @@ def test_find_stereocenters(smiles, expected_atoms, expected_bonds, find_method)

try:
stereogenic_atoms, stereogenic_bonds = find_method(molecule)
except ModuleNotFoundError as e:
except (ModuleNotFoundError, MissingOptionalDependencyError) as e:
pytest.skip(str(e))

assert stereogenic_atoms == expected_atoms
Expand Down Expand Up @@ -202,7 +203,7 @@ def test_extract_fragment(smiles, atoms, bonds, expected, extract_method):

try:
fragment = extract_method(molecule, atoms, bonds)
except ModuleNotFoundError as e:
except (ModuleNotFoundError, MissingOptionalDependencyError) as e:
pytest.skip(str(e))

expected_fragment = Molecule.from_smiles(expected)
Expand Down
5 changes: 3 additions & 2 deletions openff/fragmenter/tests/test_depiction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
)
from openff.fragmenter.fragment import Fragment, FragmentationResult
from openff.toolkit.topology import Molecule
from openff.utilities import MissingOptionalDependencyError


@pytest.mark.parametrize("draw_function", [_oe_render_parent, _rd_render_parent])
Expand All @@ -21,7 +22,7 @@ def test_xx_render_parent(draw_function):
"[C:1]([H:5])([H:6])([H:7])[C:2]([H:8])([H:9])[C:3]([H:10])([H:11])[C:4]([H:12])([H:13])([H:14])"
)
)
except ModuleNotFoundError as e:
except (ModuleNotFoundError, MissingOptionalDependencyError) as e:
pytest.skip(str(e))

assert isinstance(svg_contents, str)
Expand All @@ -41,7 +42,7 @@ def test_xx_render_fragment(draw_function):
(1, 2),
)

except ModuleNotFoundError as e:
except (ModuleNotFoundError, MissingOptionalDependencyError) as e:
pytest.skip(str(e))

assert isinstance(svg_contents, str)
Expand Down