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

Un-vendor toolkit_registry_manager #722

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from 4 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
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,
mattwthompson marked this conversation as resolved.
Show resolved Hide resolved
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_backend = toolkit_registry_manager(
toolkit_registry=ToolkitRegistry(
toolkit_precedence=[
RDKitToolkitWrapper(),
AmberToolsToolkitWrapper(),
BuiltInToolkitWrapper(),
]
)
)
Loading