Skip to content

Fall back through toolkits for InChI conversion methods#2202

Open
gaoflow wants to merge 1 commit into
openforcefield:mainfrom
gaoflow:fix-2172-inchi-toolkit-fallback
Open

Fall back through toolkits for InChI conversion methods#2202
gaoflow wants to merge 1 commit into
openforcefield:mainfrom
gaoflow:fix-2172-inchi-toolkit-fallback

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 15, 2026

Copy link
Copy Markdown

Description

Molecule.to_inchi, Molecule.to_inchikey, and Molecule.from_inchi call ToolkitRegistry.call(...) without raise_exception_types=[], so they get the default behavior of re-raising the first toolkit's exception instead of continuing to the next registered toolkit. As a result the documented toolkit precedence/fallback never happens for InChI conversion: per #2172, OpenEye refuses InChI generation for molecules with more than 1024 atoms (which RDKit supports), but the registry propagates OpenEye's error rather than falling back to RDKit.

Fix

Pass raise_exception_types=[] at these three call sites, matching the convention already used throughout the rest of the Molecule API (e.g. assign_partial_charges, and as the test suite documents: "the Molecule API passes raise_exception_types=[] to ToolkitRegistry.call"). A higher-precedence toolkit that raises is now skipped in favor of the next one; if every registered toolkit fails, ToolkitRegistry.call still raises a single aggregate ValueError describing each failure.

Testing

Added TestToolkitRegistry::test_inchi_methods_fall_back_through_toolkits, which registers a stub wrapper whose InChI methods always raise ahead of RDKitToolkitWrapper and asserts that to_inchi, to_inchikey, and from_inchi skip the failing wrapper and succeed via RDKit. The test fails on main (the first toolkit's ValueError propagates) and passes with this change; it runs offline with only RDKit (no OpenEye needed). All existing InChI tests continue to pass.

Closes #2172.


Prepared with AI assistance under my direction; I reviewed and tested the change.

`Molecule.to_inchi`, `to_inchikey`, and `from_inchi` called
`ToolkitRegistry.call` without `raise_exception_types=[]`, so they used the
default behavior of re-raising the first toolkit's exception instead of
falling back to the next registered toolkit. For example, OpenEye refuses
InChI generation for molecules larger than 1024 atoms, but the registry never
fell back to RDKit, which supports them.

Pass `raise_exception_types=[]` at these call sites, matching the convention
already used by the rest of the Molecule API, so a higher-precedence toolkit
that raises is skipped in favor of the next one. A single aggregate ValueError
is still raised if every toolkit fails.

Closes openforcefield#2172.
@gaoflow gaoflow requested a review from j-wags as a code owner June 15, 2026 15:46
@j-wags

j-wags commented Jun 19, 2026

Copy link
Copy Markdown
Member

Thanks @gaoflow - This looks promising. However because it is substantially AI generated, and because reviewing this PR will take about as much effort as making the changes myself, I'm just going to keep this at the same level of priority as the underlying issue. So I will review this when the underlying issue is actioned in our normal task planning.

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.

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

2 participants