Repository navigation
fix: add useRandomCoords to embed long chains - #141
Merged
Merged
Conversation
RDKit's default embedding starts from eigenvectors of the distance matrix, which fails for long chains (n-alkanes from C56 on, depending on the seed). smiles2conformers, smiles2atoms and rdkit2ase take useRandomCoords to start from random coordinates instead, and the CLI takes --random-coords. The default is unchanged, so seeded structures stay the same; the embedding error now suggests random coordinates. rdkit2ase checks the embedding and raises the same ValueError instead of RDKit's "Bad Conformer Id". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Removed note about embedding long n-alkanes from RDKit's default coordinates.
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.
Closes #140.
What
smiles2conformers,smiles2atomsandrdkit2asetakeuseRandomCoords: bool = False, which RDKit receives unchanged.molify smiles2atomstakes--random-coords. The RDKit call and the conformer-count check move into one unexported helper,molify.utils.embed_conformers.Why
RDKit starts each embedding from eigenvectors of the distance matrix. For long chains that step fails on every attempt (
INITIAL_COORDSin RDKit's failure counts), so retrying doesn't help. Random starting coordinates embed them. RDKit 2026.03.6, 5 seeds,maxAttempts=1000:useRandomCoords=TrueWhy opt-in, not the default or an automatic retry
For ordinary molecules RDKit's default is the better choice. Random starts are 1.5–6× slower for cubane, norbornane, ibuprofen, 18-crown-6 and a C24 ring. They also give higher median MMFF energies before optimisation for flexible rings: 219 vs 195 kcal/mol for 18-crown-6, 83 vs 64 for the C24 ring.
pruneRmsThreshconflicts with the conformer-count check, the CLI can't express it, and type checking is lost.Behaviour changes
rdkit embedded 0 of 1 conformers of 'CCC…'; random starting coordinates often embed large molecules.rdkit2aseraises thatValueErrorinstead of RDKit'sValueError: Bad Conformer Idwhen embedding fails. It now embeds throughEmbedMultipleConfs(numConfs=1, maxAttempts=0), which gives the same coordinates as the previousEmbedMoleculecall on the molecules I compared.Not in this PR
The issue also suggests letting
rdkit2asekeep a conformer the molecule already has. That changes behaviour in its own way and is left for a separate issue.Checks
uv run pytest: 618 passed, 49 skipped (vesinnot installed).uvx prek --all-files: passes.🤖 Generated with Claude Code