#684 Update default ToolkitRegistry() beahvior

Open Matt Thompson mattwthompson

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 1 of 3 files from the diff.

@@ -38,6 +38,7 @@
Loading
38 38
    "OpenEyeToolkitWrapper",
39 39
    "RDKitToolkitWrapper",
40 40
    "AmberToolsToolkitWrapper",
41 +
    "BuiltInToolkitWrapper",
41 42
    "ToolkitRegistry",
42 43
    "GLOBAL_TOOLKIT_REGISTRY",
43 44
    "OPENEYE_AVAILABLE",
@@ -4638,83 +4639,81 @@
Loading
4638 4639
    Register toolkits in a specified order, skipping if unavailable
4639 4640
4640 4641
    >>> from openforcefield.utils.toolkits import ToolkitRegistry
4641 -
    >>> toolkit_registry = ToolkitRegistry()
4642 4642
    >>> toolkit_precedence = [OpenEyeToolkitWrapper, RDKitToolkitWrapper, AmberToolsToolkitWrapper]
4643 -
    >>> for toolkit in toolkit_precedence:
4644 -
    ...     if toolkit.is_available():
4645 -
    ...         toolkit_registry.register_toolkit(toolkit)
4643 +
    >>> toolkit_registry = ToolkitRegistry(toolkit_precedence)
4644 +
    >>> toolkit_registry
4645 +
    ToolkitRegistry containing OpenEye Toolkit, The RDKit, AmberTools
4646 4646
4647 -
    Register specified toolkits, raising an exception if one is unavailable
4647 +
    Register all available toolkits (in the order OpenEye, RDKit, AmberTools, built-in)
4648 4648
4649 -
    >>> toolkit_registry = ToolkitRegistry()
4650 -
    >>> toolkits = [OpenEyeToolkitWrapper, AmberToolsToolkitWrapper]
4651 -
    >>> for toolkit in toolkits:
4652 -
    ...     toolkit_registry.register_toolkit(toolkit)
4653 -
4654 -
    Register all available toolkits in arbitrary order
4655 -
4656 -
    >>> from openforcefield.utils import all_subclasses
4657 -
    >>> toolkits = all_subclasses(ToolkitWrapper)
4658 -
    >>> for toolkit in toolkit_precedence:
4659 -
    ...     if toolkit.is_available():
4660 -
    ...         toolkit_registry.register_toolkit(toolkit)
4649 +
    >>> toolkits = [OpenEyeToolkitWrapper, RDKitToolkitWrapper, AmberToolsToolkitWrapper, BuiltInToolkitWrapper]
4650 +
    >>> toolkit_registry = ToolkitRegistry(toolkit_precedence=toolkits)
4651 +
    >>> toolkit_registry
4652 +
    ToolkitRegistry containing OpenEye Toolkit, The RDKit, AmberTools, Built-in Toolkit
4661 4653
4662 4654
    Retrieve the global singleton toolkit registry, which is created when this module is imported from all available
4663 4655
    toolkits:
4664 4656
4665 4657
    >>> from openforcefield.utils.toolkits import GLOBAL_TOOLKIT_REGISTRY as toolkit_registry
4666 -
    >>> available_toolkits = toolkit_registry.registered_toolkits
4658 +
    >>> toolkit_registry
4659 +
    ToolkitRegistry containing OpenEye Toolkit, The RDKit, AmberTools, Built-in Toolkit
4660 +
4661 +
    Note that this will contain different ToolkitWrapper objects based on what toolkits
4662 +
    are currently installed.
4667 4663
4668 4664
    .. warning :: This API is experimental and subject to change.
4669 4665
    """
4670 4666
4671 4667
    def __init__(
4672 4668
        self,
4673 -
        register_imported_toolkit_wrappers=False,
4674 -
        toolkit_precedence=None,
4669 +
        toolkit_precedence=[],
4675 4670
        exception_if_unavailable=True,
4671 +
        _register_imported_toolkit_wrappers=False,
4676 4672
    ):
4677 4673
        """
4678 4674
        Create an empty toolkit registry.
4679 4675
4680 4676
        Parameters
4681 4677
        ----------
4682 -
        register_imported_toolkit_wrappers : bool, optional, default=False
4683 -
            If True, will attempt to register all imported ToolkitWrapper subclasses that can be found, in no particular
4684 -
             order.
4685 -
        toolkit_precedence : list, optional, default=None
4678 +
        toolkit_precedence : list, default=[]
4686 4679
            List of toolkit wrapper classes, in order of desired precedence when performing molecule operations. If
4687 -
            None, defaults to [OpenEyeToolkitWrapper, RDKitToolkitWrapper, AmberToolsToolkitWrapper].
4680 +
            None, no toolkits will be registered.
4681 +
4688 4682
        exception_if_unavailable : bool, optional, default=True
4689 4683
            If True, an exception will be raised if the toolkit is unavailable
4690 4684
4691 -
        """
4685 +
        _register_imported_toolkit_wrappers : bool, optional, default=False
4686 +
            If True, will attempt to register all imported ToolkitWrapper subclasses that can be
4687 +
            found in the order of toolkit_precedence, if specified. If toolkit_precedence is not
4688 +
            specified, the default order is [OpenEyeToolkitWrapper, RDKitToolkitWrapper,
4689 +
            AmberToolsToolkitWrapper, BuiltInToolkitWrapper].
4692 4690
4691 +
        """
4693 4692
        self._toolkits = list()
4694 4693
4695 -
        if toolkit_precedence is None:
4696 -
            toolkit_precedence = [
4697 -
                OpenEyeToolkitWrapper,
4698 -
                RDKitToolkitWrapper,
4699 -
                AmberToolsToolkitWrapper,
4700 -
                BuiltInToolkitWrapper,
4701 -
            ]
4694 +
        toolkits_to_register = list()
4702 4695
4703 -
        if register_imported_toolkit_wrappers:
4704 -
            # TODO: The precedence ordering of any non-specified remaining wrappers will be arbitrary.
4705 -
            # How do we fix this?
4706 -
            # Note: The precedence of non-specifid wrappers may be determined by the order in which
4707 -
            # they were defined
4696 +
        if _register_imported_toolkit_wrappers:
4697 +
            if toolkit_precedence is None:
4698 +
                toolkit_precedence = [
4699 +
                    OpenEyeToolkitWrapper,
4700 +
                    RDKitToolkitWrapper,
4701 +
                    AmberToolsToolkitWrapper,
4702 +
                    BuiltInToolkitWrapper,
4703 +
                ]
4708 4704
            all_importable_toolkit_wrappers = all_subclasses(ToolkitWrapper)
4709 -
            for toolkit in all_importable_toolkit_wrappers:
4710 -
                if toolkit in toolkit_precedence:
4711 -
                    continue
4712 -
                toolkit_precedence.append(toolkit)
4705 +
            for toolkit in toolkit_precedence:
4706 +
                if toolkit in all_importable_toolkit_wrappers:
4707 +
                    toolkits_to_register.append(toolkit)
4708 +
        else:
4709 +
            if toolkit_precedence:
4710 +
                toolkits_to_register = toolkit_precedence
4713 4711
4714 -
        for toolkit in toolkit_precedence:
4715 -
            self.register_toolkit(
4716 -
                toolkit, exception_if_unavailable=exception_if_unavailable
4717 -
            )
4712 +
        if toolkits_to_register:
4713 +
            for toolkit in toolkits_to_register:
4714 +
                self.register_toolkit(
4715 +
                    toolkit, exception_if_unavailable=exception_if_unavailable
4716 +
                )
4718 4717
4719 4718
    @property
4720 4719
    def registered_toolkits(self):
@@ -4891,7 +4890,7 @@
Loading
4891 4890
4892 4891
        >>> from openforcefield.topology import Molecule
4893 4892
        >>> molecule = Molecule.from_smiles('Cc1ccccc1')
4894 -
        >>> toolkit_registry = ToolkitRegistry(register_imported_toolkit_wrappers=True)
4893 +
        >>> toolkit_registry = ToolkitRegistry([OpenEyeToolkitWrapper, RDKitToolkitWrapper, AmberToolsToolkitWrapper])
4895 4894
        >>> method = toolkit_registry.resolve('to_smiles')
4896 4895
        >>> smiles = method(molecule)
4897 4896
@@ -4948,7 +4947,7 @@
Loading
4948 4947
4949 4948
        >>> from openforcefield.topology import Molecule
4950 4949
        >>> molecule = Molecule.from_smiles('Cc1ccccc1')
4951 -
        >>> toolkit_registry = ToolkitRegistry(register_imported_toolkit_wrappers=True)
4950 +
        >>> toolkit_registry = ToolkitRegistry([OpenEyeToolkitWrapper, RDKitToolkitWrapper])
4952 4951
        >>> smiles = toolkit_registry.call('to_smiles', molecule)
4953 4952
4954 4953
        """
@@ -4993,7 +4992,13 @@
Loading
4993 4992
# Create global toolkit registry, where all available toolkits are registered
4994 4993
# TODO: Should this be all lowercase since it's not a constant?
4995 4994
GLOBAL_TOOLKIT_REGISTRY = ToolkitRegistry(
4996 -
    register_imported_toolkit_wrappers=True, exception_if_unavailable=False
4995 +
    toolkit_precedence=[
4996 +
        OpenEyeToolkitWrapper,
4997 +
        RDKitToolkitWrapper,
4998 +
        AmberToolsToolkitWrapper,
4999 +
        BuiltInToolkitWrapper,
5000 +
    ],
5001 +
    exception_if_unavailable=False,
4997 5002
)
4998 5003
4999 5004
# =============================================================================================

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
openforcefield 0.01% 86.40%
Project Totals (18 files) 86.40%
Loading