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

Force no oechem #479

Merged
merged 3 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion openfe/protocols/openmm_rfe/equil_rfe_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
system_validation, settings_validation, system_creation
)
from . import _rfe_utils
from ...utils import without_oechem_backend

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -679,7 +680,9 @@ def run(self, *, dry=False, verbose=True,
def _execute(
self, ctx: gufe.Context, **kwargs,
) -> dict[str, Any]:
outputs = self.run(scratch_basepath=ctx.scratch, shared_basepath=ctx.shared)
with without_oechem_backend():
Copy link
Contributor

@IAlibay IAlibay Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we might need to review this a bit later, I suspect we'll run into trouble when we start offering folks the ability to choose what charge derivation method they can have (for example if they want elf charges)

outputs = self.run(scratch_basepath=ctx.scratch,
shared_basepath=ctx.shared)

return {
'repeat_id': self._inputs['repeat_id'],
Expand Down
17 changes: 17 additions & 0 deletions openfe/tests/utils/test_remove_oechem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This code is part of OpenFE and is licensed under the MIT license.
# For details, see https://github.com/OpenFreeEnergy/openfe
from openfe.utils import without_oechem_backend
from openff.toolkit import GLOBAL_TOOLKIT_REGISTRY, OpenEyeToolkitWrapper


def test_remove_oechem():
original_tks = GLOBAL_TOOLKIT_REGISTRY.registered_toolkits
original_n_tks = len(GLOBAL_TOOLKIT_REGISTRY.registered_toolkits)

with without_oechem_backend():
for tk in GLOBAL_TOOLKIT_REGISTRY.registered_toolkits:
assert not isinstance(tk, OpenEyeToolkitWrapper)
assert len(GLOBAL_TOOLKIT_REGISTRY.registered_toolkits) == original_n_tks
for ref_tk, tk in zip(original_tks,
GLOBAL_TOOLKIT_REGISTRY.registered_toolkits):
assert isinstance(tk, type(ref_tk))
1 change: 1 addition & 0 deletions openfe/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

from . import custom_typing
from .optional_imports import requires_package
from .remove_oechem import without_oechem_backend
28 changes: 28 additions & 0 deletions openfe/utils/remove_oechem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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 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)
Loading