Skip to content

Molecule.to_inchi does not fall back through wrapped toolkits as expected #2172

Description

@mattwthompson

Describe the bug

When calling Molecule.to_inchi() without special arguments or toolkit registry management, I expect it to iterated through wrapped toolkits until it finds one that provide the method (without a failure) and return the result. Instead, I observe that it does not fall back to using the RDKit after OpenEye's OEMolToInChI fails.

To Reproduce
This can be reproduced with any molecule larger than 1024 atoms; RDKit includes InChI's "large molecule" support but OpenEye does not, on the sketchy evaluation that it's experimental. That alone is its own issue, the problem for the OpenFF user is the fallback behavior in the OpenFF Toolkit.

from openff.toolkit import Molecule

from openff.toolkit.utils.toolkits import (
    toolkit_registry_manager,
    RDKitToolkitWrapper,
    OpenEyeToolkitWrapper,
    GLOBAL_TOOLKIT_REGISTRY,
)


for tag, backend in zip(
    [
        "RDKit",
        "OpenEye",
        "Global",
    ],
    [
        RDKitToolkitWrapper(),
        OpenEyeToolkitWrapper(),
        GLOBAL_TOOLKIT_REGISTRY,
    ],
):
    print(f"Testing with {tag} toolkit registry...")

    with toolkit_registry_manager(backend):
        try:
            inchi = Molecule.from_smiles(342 * "C").to_inchi()

            # just make sure it isn't accidentally an empty string or something
            assert len(inchi) > 10

            print("\t\t... Success! made an InChI!")
        except Exception as e:
            print("\t\t... Failure! did NOT make an InChI!")
            print(type(e), str(e))

    print()

Output

$ python repro.py
Testing with RDKit toolkit registry...
		... Success! made an InChI!

Testing with OpenEye toolkit registry...
Warning: OECreateInChI: InChI only supports molecules with between 1 and 1023 atoms! (note: large molecule support is experimental)
		... Failure! did NOT make an InChI!
<class 'openff.toolkit.utils.exceptions.EmptyInChiError'> OEChem failed to generate an InChI for the molecule.

Testing with Global toolkit registry...
Warning: OECreateInChI: InChI only supports molecules with between 1 and 1023 atoms! (note: large molecule support is experimental)
		... Failure! did NOT make an InChI!
<class 'openff.toolkit.utils.exceptions.EmptyInChiError'> OEChem failed to generate an InChI for the molecule.

Computing environment (please complete the following information):

  • Operating system
  • Output of running conda list

Additional context

The case of OEMolToInChI / OEMolToSTDInChI returning an empty string is actually handled; I land here in that case

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions