Repository navigation
fix: decide MI metal-bond disconnection per fragment - #309
Merged
Merged
Conversation
MolecularInorganicsPreprocessing perceived ring systems with MarkRingSystemsInp(at, num_at, 0), which walks only the fragment that contains atom 0, so the chelate-ring protection never applied to metals in later fragments and the result depended on atom order (#305). Ring systems are now perceived in every fragment, with ring-system IDs kept unique across fragments. The decision tree is evaluated per fragment: a reason to keep metal bonds in one fragment no longer keeps the metal bonds of unrelated fragments in the same input, and the "all metals terminal" exception is checked per fragment. Each fragment now gives the same result as when it is the only one in the input. MI also clears the ring-system fields it set before returning. Fixes #305
…ecisions Eight multi-fragment records change (CaPlus, Example-Feature4, HillSort, _Elements_C, _Elements_C2, _Tech_Man_Table04a, salt02, test3.002): salt fragments that were kept connected only because another fragment in the same record had to be kept are now split as they are on their own.
Contributor
|
Good analysis and implementation |
gblanke02
reviewed
Nov 5, 2026
gblanke02
left a comment
Contributor
There was a problem hiding this comment.
The described modifications should be implemented
… into fix/305-mi-per-fragment # Conflicts: # INCHI-1-TEST/tests/test_unit/test_molecularInorganics.cpp
nnuk
reviewed
Nov 5, 2026
MarkRingSystemsInp() allocates work arrays for all atoms on every call, and it was called once per fragment, including fragments without a metal and inputs without any metal. Only fragments with a metal are perceived now; the chelate check compares a metal's ring system with atoms of its own fragment only, and atoms of skipped fragments keep nRingSystem 0, which never matches a perceived ID. Output is unchanged (0 regression diffs). A new test with a Li on the octyl-THF fragment guards the ring-ID offset, since the metal-free octyl-THF is no longer perceived. Refs #305
Unit Test Coverage ReportCoverage Regression Summary
Find details on the base coverage at https://iupac-inchi.github.io/InChI/coverage/index.html Find details on this PR's coverage by downloading coverage-reports-42351888397 and opening html/index.html |
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.
Fixes #305
Problem
MolecularInorganicsPreprocessingperceived ring systems withMarkRingSystemsInp(at, num_at, 0). That walks only the fragment containing atom 0, so chelate-ring protection never applied to metals in later fragments, and the result depended on atom order. Example from #305: the Ti chelate oftest_MI_Issue244_TitaniumComplex_1is kept, but with a water inserted as atom 1 it is disconnected.Change
MolecularInorganicsMarkFragments()labels each fragment and callsMarkRingSystemsInponce per fragment, shifting ring-system IDs so they stay unique across fragments. MI clears the ring fields again before returning.keep_all_metal_bondsflag for the whole input: any reason to keep a metal bond (non-single or stereo bond, valence, bond table, link to another metal, chelate ring) kept every metal bond in the input, including those in unrelated fragments. Fixing (1) alone would have made a ring in one fragment protect all others. The flag is now per fragment, and the "all metals terminal" exception is checked per fragment. Each fragment now gives the same result as when it is the only one in the input. Before cf3d805 the decision was made per metal.Results
Regression reference
inchi.sdfreference regenerated; 8 records change, 0 inmcule.sdf. All are multi-fragment test collections where a salt fragment was kept connected only because another fragment in the same record had to be kept:The complexes in these records stay connected as before. Checked: NaCl, AgF, CH₃Cs and CH₃Fr alone give the same InChI on #306 and here.
Tests
Seven new unit tests in
test_molecularInorganics.cpp:TiChelate_water_first,NaOMe_then_TiChelate,TiChelate_then_NaOMe,PdCl2_NaOMe(all fail on #306);OctylTHF_TiOMe4, which guards the ring-ID offset (fails when the offset is removed);TerminalAg2F_TiOMe4, which covers the per-fragment "all metals terminal" exception (fails with an input-wide flag); andChargedPassSplitsFragments, which checks that fragments are found after the charge-separated pass (fails when they are found before it). Unit, executable, meta, multithreading, regression and invariance tests pass locally.#306 follow-up merged in
The #306 branch, including its follow-up commits (a CuCl charged/neutral test, and charged non-Group-1/2 metal bonds that the bond table cuts, e.g. Ag(+)-F(-), now rejected with an error), is merged into this branch (merge commit 3b4e116, no rebase). Full test battery rerun after the merge: unit, executable, meta, multithreading, regression (0 diffs) and invariance pass.