Skip to content

Commit

Permalink
Un-vendor toolkit_registry_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwthompson committed Feb 13, 2024
1 parent 9ebbcbe commit 83dc8b4
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions openfe/utils/remove_oechem.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
# This code is part of OpenFE and is licensed under the MIT license.
# For details, see https://github.com/OpenFreeEnergy/openfe
from openff.toolkit import GLOBAL_TOOLKIT_REGISTRY, OpenEyeToolkitWrapper
from openff.toolkit.utils.toolkit_registry import ToolkitUnavailableException
from openff.toolkit.utils.toolkit_registry import (
ToolkitRegistry,
toolkit_registry_manager,
)
from openff.toolkit.utils.toolkits import (
AmberToolsToolkitWrapper,
BuiltInToolkitWrapper,
RDKitToolkitWrapper,
)

from contextlib import contextmanager


@contextmanager
def without_oechem_backend():
"""For temporarily removing oechem from openff's toolkit registry"""
current_toolkits = [type(tk)
for tk in GLOBAL_TOOLKIT_REGISTRY.registered_toolkits]

try:
GLOBAL_TOOLKIT_REGISTRY.deregister_toolkit(OpenEyeToolkitWrapper())
except ToolkitUnavailableException:
pass

try:
yield None
finally:
# this is order dependent; we want to prepend OEChem back to first
while GLOBAL_TOOLKIT_REGISTRY.registered_toolkits:
GLOBAL_TOOLKIT_REGISTRY.deregister_toolkit(
GLOBAL_TOOLKIT_REGISTRY.registered_toolkits[0])
for tk in current_toolkits:
GLOBAL_TOOLKIT_REGISTRY.register_toolkit(tk)
without_oechem = toolkit_registry_manager(
toolkit_registry=ToolkitRegistry(
toolkit_precedence=[
RDKitToolkitWrapper(),
AmberToolsToolkitWrapper(),
BuiltInToolkitWrapper(),
]
)
)

0 comments on commit 83dc8b4

Please sign in to comment.