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

Add requires_openeye decorators when oechem is used #275

Closed
wants to merge 12 commits into from

Conversation

mattwthompson
Copy link
Member

Description

This PR attempts to fix #271 by checking for an OpenEye license when oechem is used and failing out with a descriptive error message. I haven't put the work into testing it in a live run, but the minimal behavior should follow this script:

from openff.utilities.utilities import requires_oe_module

@requires_oe_module("oechem")
def hello():
    from openeye import oechem
    print("hello")

hello()

Running (with openeye-toolkits installed) and mucking with the license path:

$ python script.py && mv ~/.oe_license.txt /tmp && python script.py
hello
LICENSE: Could not open license file specified by OE_LICENSE environment variable "/Users/mattthompson/.oe_license.txt"
LICENSE: Could not open license file "oe_license.txt" in local directory
LICENSE: N.B. OE_DIR environment variable is not set
LICENSE: No product keys!
Traceback (most recent call last):
  File "/Users/mattthompson/software/openff-bespokefit/script.py", line 8, in <module>
    hello()
  File "/Users/mattthompson/mambaforge/envs/openff-toolkit-test/lib/python3.10/site-packages/openff/utilities/utilities.py", line 80, in wrapper
    return function(*args, **kwargs)
  File "/Users/mattthompson/mambaforge/envs/openff-toolkit-test/lib/python3.10/site-packages/openff/utilities/utilities.py", line 123, in wrapper
    raise MissingOptionalDependencyError(
openff.utilities.exceptions.MissingOptionalDependencyError: The required openeye.oechem module could not be imported. This is due to a missing license.

I couldn't find other cases in which an openeye.* API is actually called, just this bit I don't understand and here, where it's tracked for provenance, it could possibly be useful to also check that it's licensed. That's not related to the original issue so I didn't change that.

Todos

Notable points that this PR has either accomplished or will accomplish.

  • Check for a license when oechem is called
  • Check other calls

Status

  • Ready to go

@mattwthompson mattwthompson changed the title Add requires_openeye decorators when openeye Add requires_openeye decorators when oechem is used Jul 13, 2023
@jthorton
Copy link
Contributor

Thanks @mattwthompson, I think we just need to catch this new exception here and here for this to work and ill give it a test run!

@mattwthompson
Copy link
Member Author

Ah, I see, I guess that's why the tests were failing

@codecov
Copy link

codecov bot commented Jul 13, 2023

Codecov Report

Merging #275 (420383c) into main (6050dba) will decrease coverage by 0.19%.
The diff coverage is 100.00%.

Additional details and impacted files

@mattwthompson mattwthompson marked this pull request as ready for review July 13, 2023 14:56
@jthorton
Copy link
Contributor

My test run didn't go to plan I originally saw this coming from the branch in #272 where the worker and server were running different environments and I think this PR will fix that, but in testing, I have to use them in the same environment with the license file path edited and a new error from fragmenter appears related to the same thing.

Testing command

openff-bespoke executor run --smiles             "CC(=O)NC1=CC=C(C=C1)O" \
                            --workflow           "default"               \
                            --output             "acetaminophen.json"    \
                            --output-force-field "acetaminophen.offxml"  \
                            --n-qc-compute-workers 2                     \
                            --qc-compute-n-cores   1                     \
                            --default-qc-spec xtb gfn2xtb none

Error

{"smiles": "[C:1]([C:2](=[O:3])[N:4]([c:5]1[c:6]([H:7])[c:8]([H:9])[c:10]([O:11][H:12])[c:13]([H:14])[c:15]1[H:16])[H:17])([H:18])([H:19])[H:20]", "stages": [{"type": "qc-generation", "status": "waiting", "error": null}, {
"type": "optimization", "status": "waiting", "error": null}, {"type": "fragmentation", "status": "errored", "error": "{\"type\": \"ValueError\", \"message\": \"No registered toolkits can provide the capability \\\"to_opene
ye\\\" for args \\\"(Molecule with name '' and SMILES '[H][O][c]1[c]([H])[c]([H])[c]([N]([H])[C](=[O])[C]([H])([H])[H])[c]([H])[c]1[H]',)\\\" and kwargs \\\"{'aromaticity_model': 'OEAroModel_MDL'}\\\"\\nAvailable toolkits 
are: [ToolkitWrapper around The RDKit version 2023.03.2, ToolkitWrapper around AmberTools version 22.0, ToolkitWrapper around Built-in Toolkit version None]\\n\", \"traceback\": \"Traceback (most recent call last):\\n  Fil
e \\\"/home/b6056633/micromamba/envs/bespokefit/lib/python3.9/site-packages/celery/app/trace.py\\\", line 477, in trace_task\\n    R = retval = fun(*args, **kwargs)\\n  File \\\"/home/b6056633/micromamba/envs/bespokefit/li
b/python3.9/site-packages/celery/app/trace.py\\\", line 760, in __protected_call__\\n    return self.run(*args, **kwargs)\\n  File \\\"/home/b6056633/programs/openff-bespokefit/openff/bespokefit/executor/services/fragmente
r/worker.py\\\", line 36, in fragment\\n    fragmenter.fragment(molecule, target_bond_smarts=target_bond_smarts)\\n  File \\\"/home/b6056633/micromamba/envs/bespokefit/lib/python3.9/site-packages/openff/fragmenter/fragment
.py\\\", line 916, in fragment\\n    result = self._fragment(molecule, target_bond_smarts)\\n  File \\\"/home/b6056633/micromamba/envs/bespokefit/lib/python3.9/site-packages/openff/fragmenter/fragment.py\\\", line 1019, in
 _fragment\\n    fragments = {\\n  File \\\"/home/b6056633/micromamba/envs/bespokefit/lib/python3.9/site-packages/openff/fragmenter/fragment.py\\\", line 1020, in <dictcomp>\\n    bond: self._build_fragment(\\n  File \\\"/
home/b6056633/micromamba/envs/bespokefit/lib/python3.9/site-packages/openff/fragmenter/fragment.py\\\", line 1191, in _build_fragment\\n    fragment, has_new_stereocenter = cls._atom_bond_set_to_mol(\\n  File \\\"/home/b60
56633/micromamba/envs/bespokefit/lib/python3.9/site-packages/openff/fragmenter/fragment.py\\\", line 391, in _atom_bond_set_to_mol\\n    fragment = extract_fragment(parent, atoms, bonds)\\n  File \\\"/home/b6056633/microma
mba/envs/bespokefit/lib/python3.9/site-packages/openff/fragmenter/chemi.py\\\", line 488, in extract_fragment\\n    fragment = _extract_oe_fragment(molecule, atom_indices, bond_indices)\\n  File \\\"/home/b6056633/micromam
ba/envs/bespokefit/lib/python3.9/site-packages/openff/fragmenter/chemi.py\\\", line 397, in _extract_oe_fragment\\n    oe_molecule = molecule.to_openeye()\\n  File \\\"/home/b6056633/micromamba/envs/bespokefit/lib/python3.
9/site-packages/openff/toolkit/topology/molecule.py\\\", line 5048, in to_openeye\\n    return toolkit_registry.call(\\n  File \\\"/home/b6056633/micromamba/envs/bespokefit/lib/python3.9/site-packages/openff/toolkit/utils/
toolkit_registry.py\\\", line 370, in call\\n    raise ValueError(msg)\\nValueError: No registered toolkits can provide the capability \\\"to_openeye\\\" for args \\\"(Molecule with name '' and SMILES '[H][O][c]1[c]([H])[c
]([H])[c]([N]([H])[C](=[O])[C]([H])([H])[H])[c]([H])[c]1[H]',)\\\" and kwargs \\\"{'aromaticity_model': 'OEAroModel_MDL'}\\\"\\nAvailable toolkits are: [ToolkitWrapper around The RDKit version 2023.03.2, ToolkitWrapper aro
und AmberTools version 22.0, ToolkitWrapper around Built-in Toolkit version None]\\n\\n\"}"}], "results": null}

I think this indicates we need to use these decorators here as well.

@mattwthompson
Copy link
Member Author

I've opened openforcefield/openff-fragmenter#164 to try to fix that; the branch there is openeye-license

@mattwthompson
Copy link
Member Author

That branch should be working now, but you'll have to bump openff-utilities =0.1.9

@j-wags j-wags marked this pull request as draft August 9, 2023 20:13
@mattwthompson
Copy link
Member Author

Blocked in some capacity by a new QCSubmit

@j-wags
Copy link
Member

j-wags commented Aug 23, 2023

This should now be unblocked by QCSubmit 0.5.0 (re-enables compatibility with legacy QCF)

@mattwthompson
Copy link
Member Author

Blocked by leeping/forcebalance#285

@j-wags
Copy link
Member

j-wags commented Oct 13, 2023

I think this is superseded by #286, @mattwthompson or @jthorton could you confirm? If so (and this is resolved) I'd recommend a BespokeFit 0.2.3 release on Monday, which relaxes pins in the bespokefit conda recipe to allow the use of latest ForceBalance and OFFTK.

@jthorton
Copy link
Contributor

I think we still want the openeye decorators in this PR as well.

@j-wags
Copy link
Member

j-wags commented Oct 16, 2023

Ahh, apologies. I missed that detail. Please feel free to revert my PR if you'd like to have that all go in at once!

@mattwthompson
Copy link
Member Author

I'm still having troubles with this - maybe my patch to Fragmenter didn't do what it needed it to do?

(bespokefit) [openff-bespokefit] openff-bespoke executor launch &
[1] 34821
(bespokefit) [openff-bespokefit] LICENSE: Could not open license file specified by OE_LICENSE environment variable "/Users/mattthompson/.oe_license.txt"
LICENSE: Could not open license file "oe_license.txt" in local directory
LICENSE: N.B. OE_DIR environment variable is not set
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!

──────────────────────────────── OpenFF Bespoke ────────────────────────────────

⠸ launching the bespoke executorLICENSE: Could not open license file specified by OE_LICENSE environment variable "/Users/mattthompson/.oe_license.txt"
LICENSE: Could not open license file "oe_license.txt" in local directory
LICENSE: N.B. OE_DIR environment variable is not set
LICENSE: No product keys!
⠼ launching the bespoke executorLICENSE: Could not open license file specified by OE_LICENSE environment variable "/Users/mattthompson/.oe_license.txt"
LICENSE: Could not open license file "oe_license.txt" in local directory
LICENSE: N.B. OE_DIR environment variable is not set
LICENSE: No product keys!
LICENSE: Could not open license file specified by OE_LICENSE environment variable "/Users/mattthompson/.oe_license.txt"
LICENSE: Could not open license file "oe_license.txt" in local directory
LICENSE: N.B. OE_DIR environment variable is not set
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: Could not open license file specified by OE_LICENSE environment variable "/Users/mattthompson/.oe_license.txt"
LICENSE: Could not open license file "oe_license.txt" in local directory
LICENSE: N.B. OE_DIR environment variable is not set
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
⠴ launching the bespoke executorLICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
⠴ launching the bespoke executorLICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
[✓] bespoke executor launched
(bespokefit) [openff-bespokefit] openff-bespoke executor submit --smiles 'CC(=O)NC1=CC=C(C=C1)O' --workflow debug
LICENSE: Could not open license file specified by OE_LICENSE environment variable "/Users/mattthompson/.oe_license.txt"
LICENSE: Could not open license file "oe_license.txt" in local directory
LICENSE: N.B. OE_DIR environment variable is not set
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!

──────────────────────────────── OpenFF Bespoke ────────────────────────────────

1. preparing the bespoke workflow

[✓] 1 molecules found
[✓] fitting schemas generated

2. submitting the workflow

[✓] the following workflows were submitted
┏━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━┳━━━━━━┓
┃ ID ┃ SMILES             ┃ NAME ┃ FILE ┃
┡━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━╇━━━━━━┩
│ 7  │ CC(=O)Nc1ccc(O)cc1 │      │      │
└────┴────────────────────┴──────┴──────┘
(bespokefit) [openff-bespokefit] openff-bespoke executor watch --id 7
LICENSE: Could not open license file specified by OE_LICENSE environment variable "/Users/mattthompson/.oe_license.txt"
LICENSE: Could not open license file "oe_license.txt" in local directory
LICENSE: N.B. OE_DIR environment variable is not set
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!

──────────────────────────────── OpenFF Bespoke ────────────────────────────────

[x] fragmentation failed

 {"type": "ValueError", "message": "No registered toolkits can provide the
 capability \"to_openeye\" for args \"(Molecule with name '' and SMILES
 '[H][O]1([H])([H])([N]([H])[C](=[O])[C]([H])([H])[H])([H])1[H]',)\" and kwargs
 \"{'aromaticity_model': 'OEAroModel_MDL'}\"\nAvailable toolkits are:
 [ToolkitWrapper around The RDKit version 2023.09.1, ToolkitWrapper around
 AmberTools version 22.0, ToolkitWrapper around Built-in Toolkit version
 None]\n", "traceback": "Traceback (most recent call last):\n  File
 \"/Users/mattthompson/mambaforge/envs/bespokefit/lib/python3.9/site-packages/ce
 lery/app/trace.py\", line 477, in trace_task\n    R = retval = fun(*args,
 **kwargs)\n  File
 \"/Users/mattthompson/mambaforge/envs/bespokefit/lib/python3.9/site-packages/ce
 lery/app/trace.py\", line 760, in __protected_call__\n    return
 self.run(*args, **kwargs)\n  File
 \"/Users/mattthompson/software/openff-bespokefit/openff/bespokefit/executor/ser
 vices/fragmenter/worker.py\", line 36, in fragment\n
 fragmenter.fragment(molecule, target_bond_smarts=target_bond_smarts)\n  File
 \"/Users/mattthompson/mambaforge/envs/bespokefit/lib/python3.9/site-packages/op
 enff/fragmenter/fragment.py\", line 916, in fragment\n    result =
 self._fragment(molecule, target_bond_smarts)\n  File
 \"/Users/mattthompson/mambaforge/envs/bespokefit/lib/python3.9/site-packages/op
 enff/fragmenter/fragment.py\", line 1019, in _fragment\n    fragments = {\n
 File
 \"/Users/mattthompson/mambaforge/envs/bespokefit/lib/python3.9/site-packages/op
 enff/fragmenter/fragment.py\", line 1020, in <dictcomp>\n    bond:
 self._build_fragment(\n  File
 \"/Users/mattthompson/mambaforge/envs/bespokefit/lib/python3.9/site-packages/op
 enff/fragmenter/fragment.py\", line 1191, in _build_fragment\n    fragment,
 has_new_stereocenter = cls._atom_bond_set_to_mol(\n  File
 \"/Users/mattthompson/mambaforge/envs/bespokefit/lib/python3.9/site-packages/op
 enff/fragmenter/fragment.py\", line 391, in _atom_bond_set_to_mol\n    fragment
 = extract_fragment(parent, atoms, bonds)\n  File
 \"/Users/mattthompson/mambaforge/envs/bespokefit/lib/python3.9/site-packages/op
 enff/fragmenter/chemi.py\", line 488, in extract_fragment\n    fragment =
 _extract_oe_fragment(molecule, atom_indices, bond_indices)\n  File
 \"/Users/mattthompson/mambaforge/envs/bespokefit/lib/python3.9/site-packages/op
 enff/fragmenter/chemi.py\", line 397, in _extract_oe_fragment\n    oe_molecule
 = molecule.to_openeye()\n  File
 \"/Users/mattthompson/mambaforge/envs/bespokefit/lib/python3.9/site-packages/op
 enff/toolkit/topology/molecule.py\", line 5048, in to_openeye\n    return
 toolkit_registry.call(\n  File
 \"/Users/mattthompson/mambaforge/envs/bespokefit/lib/python3.9/site-packages/op
 enff/toolkit/utils/toolkit_registry.py\", line 370, in call\n    raise
 ValueError(msg)\nValueError: No registered toolkits can provide the capability
 \"to_openeye\" for args \"(Molecule with name '' and SMILES
 '[H][O]1([H])([H])([N]([H])[C](=[O])[C]([H])([H])[H])([H])1[H]',)\" and kwargs
 \"{'aromaticity_model': 'OEAroModel_MDL'}\"\nAvailable toolkits are:
 [ToolkitWrapper around The RDKit version 2023.09.1, ToolkitWrapper around
 AmberTools version 22.0, ToolkitWrapper around Built-in Toolkit version
 None]\n\n"}
(bespokefit) [openff-bespokefit] conda list openff                     12:34:46  ☁  openeye-decorators ☂ ✭
# packages in environment at /Users/mattthompson/mambaforge/envs/bespokefit:
#
# Name                    Version                   Build  Channel
openff-amber-ff-ports     0.0.3              pyh6c4a22f_0    conda-forge
openff-bespokefit         0.2.2+36.g420383c           dev_0    <develop>
openff-forcefields        2023.08.0          pyh1a96a4e_0    conda-forge
openff-fragmenter-base    0.2.1              pyhd8ed1ab_0    conda-forge
openff-interchange        0.3.10             pyhd8ed1ab_0    conda-forge
openff-interchange-base   0.3.10             pyhd8ed1ab_0    conda-forge
openff-models             0.1.1              pyhca7485f_0    conda-forge
openff-qcsubmit           0.5.0              pyhd8ed1ab_0    conda-forge
openff-toolkit            0.14.4             pyhd8ed1ab_1    conda-forge
openff-toolkit-base       0.14.4             pyhd8ed1ab_1    conda-forge
openff-units              0.2.1              pyh1a96a4e_0    conda-forge
openff-utilities          0.1.11             pyhd8ed1ab_0    conda-forge

@mattwthompson
Copy link
Member Author

This has gone stale; if we run into this again it can be revived.

@mattwthompson mattwthompson deleted the openeye-decorators branch September 9, 2024 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Having Openeye installed with no license kills the server
3 participants