Accept non-kekulisable molecules. (#9167)

Co-authored-by: David Cosgrove <david@cozchemix.co.uk>
This commit is contained in:
David Cosgrove
2026-03-13 14:33:41 +00:00
committed by GitHub
parent 6f58d21f29
commit 61773ad0e9

View File

@@ -73,7 +73,15 @@ None'''
else:
# py3Dmol does not currently support v3k mol files, so
# we can only provide those with "smaller" molecules
mb = Chem.MolToMolBlock(mol, confId=confId)
try:
mb = Chem.MolToMolBlock(mol, confId=confId)
except Chem.AtomKekulizeException:
# The bonding is likely to be wrong, but it would be good
# to see something.
p = Chem.rdmolfiles.MolWriterParams()
p.kekulize = False
mb = Chem.MolToMolBlock(mol, confId=confId, params=p)
view.addModel(mb, 'sdf')
if drawAs is None:
drawAs = drawing_type_3d
@@ -545,3 +553,4 @@ def UninstallIPythonRenderer():
InstallIPythonRenderer()