Add MolFromInchiAndAuxInfo to restore original atom order from AuxInfo#9158
Merged
greglandrum merged 2 commits intordkit:masterfrom Mar 13, 2026
Merged
Conversation
Add a new function that reconstructs molecules from InChI + AuxInfo strings, restoring the original atom ordering and 2D/3D coordinates from the /N: and /rC: AuxInfo layers. Includes comprehensive tests for round-tripping, stereo preservation, coordinate restoration, edge cases, and multi-fragment molecules. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
greglandrum
requested changes
Mar 12, 2026
Member
greglandrum
left a comment
There was a problem hiding this comment.
Thanks for the contribution @rodyarantes!
I don't really know the auxinfo format, and I didn't dig into the regexes (:shudder:) but it looks like your tests are covering things nicely.
One small suggestion to simplify a test, but otherwise this looks good!
Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
Member
|
Thanks @rodyarantes! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
MolFromInchiAndAuxInfo(inchi, auxinfo, ...)toinchi.py— the inverse of the existingMolToInchiAndAuxInfo. It reconstructs a molecule from an InChI string and its AuxInfo, restoring:/N:(atom numbering) layer/rC:(coordinate) layerThis enables lossless round-tripping of molecules through InChI when the AuxInfo is preserved, which is useful for workflows where atom identity and spatial layout must survive serialization.
New public API
MolFromInchiAndAuxInfo(inchi, auxinfo, sanitize=True, removeHs=True, logLevel=None, treatWarningAsError=False)→Chem.rdchem.MolInternal helpers added
_parse_auxinfo_coordinates(auxinfo)— parses/rC:layer into[(x,y,z), ...]_parse_auxinfo_atom_order(auxinfo)— parses/N:layer into 0-based index list_attach_conformer(mol, coords, is_3d)— adds a conformer from parsed coordinates_build_inverse_permutation(atom_order, size)— builds the permutation array forRenumberAtomsEdge cases handled
Noneor empty AuxInfo → falls back toMolFromInchibehaviorNone/N:layer)/rC:(standard InChI output format)removeHs=TruevsFalseatom count mismatchesUsage examples
Basic round-trip preserving atom order
Round-trip with coordinate preservation
Graceful degradation
Test plan
Tests are in
rdkit/Chem/UnitTestInchi.pyunderTestMolFromInchiAndAuxInfo:test0RoundTripAtomOrder— atom ordering preserved for multiple SMILEStest1StereoPreservation— stereochemistry preserved through round-triptest2NoneAuxInfo/test3EmptyAuxInfo— graceful fallback with missing AuxInfotest4InvalidInchi— returnsNonefor invalid InChItest5MultiFragmentAuxInfo— handles semicolon-separated fragmentstest6CoordinateRestoration— 2D conformer restored, trailing semicolons handledtest7EmptyCoordinates/test7bAllZeroCoordinates— no conformer for empty/zero coordstest8CoordinateAtomOrderMatch— per-atom symbol + coordinate verificationTo run: