Skip to content

get_tmc_mol: keep input atom order and coordinates - #8

Open
rpinho wants to merge 1 commit into
rowansci:masterfrom
rpinho:fix-tmc-atom-order
Open

rpinho wants to merge 1 commit into
rowansci:masterfrom
rpinho:fix-tmc-atom-order

Conversation

@rpinho

@rpinho rpinho commented Nov 16, 2026

Copy link
Copy Markdown

There's a bug in get_tmc_mol: the SMILES round trips that fix up the transition-metal chemistry renumber the atoms, so the result isn't in input order, even though the docstring says it is. With remove_Hs=False the supplied hydrogen coordinates are also replaced by generated ones.

to_rdkit([30, 17, 17], [[0, 0, 0], [2.2, 0, 0], [-2.2, 0, 0]]) (ZnCl2) returns atoms [17, 30, 17]. For a zinc-ammonia complex with explicit hydrogens, the returned H positions are 0.35-0.50 Å from the ones supplied. Any input with a transition metal goes through this path with default settings.

This keeps the existing chemistry corrections, matches the corrected molecule back to the input atoms with the existing __origIdx properties, restores input order, and puts back every supplied coordinate. If no complete match is found it raises, which to_rdkit reports as its existing SteamrollConversionError, instead of returning atoms in the wrong order.

Test: tests/test_tmc_atom_order.py (ZnCl2, and zinc-ammonia in two input orders, with and without H removal) goes from 5 failed, 1 passed to 6 passed. The six existing transition-metal fixtures (ferrocene, UCl6, PdCl2(MeCN)2 and others) all come back with input atom order and coordinates. ruff, ty and the release smoke tests pass; the full suite passes (100), apart from an intermittent native RDKit EHT crash that also happens on main.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N

@rpinho

rpinho commented Nov 19, 2026

Copy link
Copy Markdown
Author

Let me know if you have any thoughts on this one.

This branch has not been deployed

No deployments
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.

1 participant