Skip to content

PermuteMolfileText drops implicit hydrogens #311

Closed

Description

@fbaensch-beilstein

PermuteMolfileText loses implicit hydrogens, so the invariance test compares permutations of a different (H-stripped) structure instead of the input.

Reproduce

Methanol, no options, libinchi built from dev (7621fc0):

original:  rc 0  InChI=1S/CH4O/c1-2/h2H,1H3
permuted:  rc 1  InChI=1S/CO/c1-2

Permuted molfile:


  InChIV10

  2  1  0  0  0  0  0  0  0  0  1 V2000
    1.0000    0.0000    0.0000 O   0  0  0     0  1  0  0  0  0
    0.0000    0.0000    0.0000 C   0  0  0     0  1  0  0  0  0
  1  2  1  0  0  0  0
M  END
$$$$

The valence field (vvv) is written as 1 for both atoms, so the reader adds no implicit H.

Cause

PermuteMolfileText reads the input with bDoNotAddH = 1 (INCHI-1-SRC/INCHI_BASE/src/permutation_util.c, the 0, 1, 1, 0, 0 arguments to CreateOrigInpDataFromMolfile), so num_H is never filled. OrigAtData_WriteToSDfile then correctly writes the valence from the explicit bonds only. The writer is not the problem: it is also used by -OutputSDF, where num_H is filled.

Scale

Over the CI set with the PR #310 wrapper (10 permutations per molfile): 3599 of 4186 molfiles with a valid original give a different InChI after permutation. With only that argument changed to 0, 1, 0, 0, 0, 7 differ, and those 7 are exactly the invariance failures recorded in #310.

Fix

Pass bDoNotAddH = 0 in PermuteMolfileText, and add a test that permutation of a molfile with implicit H gives the same InChI as the original.

Present since the function was added in 41b256a. The invariance test did not notice because, until #310, it could not read any permuted molfile.

Activity

  1. added a commit that references this issue on Nov 10, 2026
    3039bf6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNewly reported, awaiting maintainer review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions