-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ebbcbe
commit 83dc8b4
Showing
1 changed file
with
18 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
] | ||
) | ||
) |