openforcefield / openff-toolkit

The Open Forcefield Toolkit provides implementations of the SMIRNOFF format, parameterization engine, and other tools. Documentation available at http://open-forcefield-toolkit.readthedocs.io
http://openforcefield.org
MIT License
311 stars 90 forks source link

to_inchi() returns empty string on failure #1897

Closed lilyminium closed 2 months ago

lilyminium commented 3 months ago

Describe the bug

"[H:5][S:3]#[N+:2][S:1][H:4]" is a molecule that cannot be turned into an InChI due to what looks like an internal software error in the inchi code itself. However, the toolkit returns an empty string upon this failure instead of raising an error, which can be problematic when mass-converting a bunch of molecules while being unaware that this can happen.

To Reproduce

from openff.toolkit import Molecule
from openff.toolkit.utils import OpenEyeToolkitWrapper, RDKitToolkitWrapper

Molecule.from_mapped_smiles("[H:5][S:3]#[N+:2][S:1][H:4]").to_inchi(toolkit_registry=OpenEyeToolkitWrapper())
Molecule.from_mapped_smiles("[H:5][S:3]#[N+:2][S:1][H:4]").to_inchi(toolkit_registry=RDKitToolkitWrapper())

Output

Both toolkits yield warnings along the lines of Warning: No description(-9995), but the OpenFF toolkit still returns an empty string. Could we please raise an error if there's an empty string, just to really warn the user?

Computing environment (please complete the following information):

Additional context

mattwthompson commented 3 months ago

Could we please raise an error if there's an empty string, just to really warn the user?

I've done this in #1898 - do we care about the same thing for InChi keys as well?

lilyminium commented 3 months ago

Thanks for the quick fix @mattwthompson!!

I haven't checked the behaviour of inchi key but as a user I'd like to see an error there as well for similar reasons.