Skip to content

Commit 38b7e24

Browse files
roshkjrdwhswensonroshan
authored
Fixes error in 2D depiction due to RDKIt update (#35)
* Add adjustDegree = False to adjust query params This fixes an issue that changed between RDKit 2024.9.6 and 2025.3.1. Details in rdkit/rdkit#8592 * Update tests for NumPy 2.0+ compatibility * Update pyproject.toml and poetry.lock for 2025-07 * 🐛 Add depitions to results only if they are successful * 🎨 make templates to be None for failed DepictionResult * 🎨 make the rdkit 2d depiction using coordgen library explicit * ✨ Add rdkit depictions * 📝 update changelog * 🔖 bump version number --------- Co-authored-by: David W.H. Swenson <dwhs@hyperblazer.net> Co-authored-by: roshan <roshan@ebi.ac.uk>
1 parent 81f3c9e commit 38b7e24

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## RELEASE 1.0.0 - Sep 4, 2025
4+
5+
### Features
6+
* Support for RDKit 2025 and NumPy 2.0
7+
* Uses both coordgen library and the default RDKit functionality to generate 2D depictions
8+
39
## RELEASE 0.8.6 - Oct 28, 2024
410

511
### Features

pdbeccdutils/core/depictions.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from pdbeccdutils.helpers.mol_tools import fix_conformer
3434
from pdbeccdutils.utils import config
3535
from rdkit import Chem, Geometry
36-
from rdkit.Chem import AllChem, rdCoordGen
36+
from rdkit.Chem import AllChem, rdCoordGen, rdDepictor
3737
from scipy.spatial import KDTree
3838

3939

@@ -101,6 +101,7 @@ def depict_molecule(
101101

102102
templateMol = Chem.RWMol(temp_mol).GetMol()
103103
pubchemMol = Chem.RWMol(temp_mol).GetMol()
104+
rdkitMolCd = Chem.RWMol(temp_mol).GetMol()
104105
rdkitMol = Chem.RWMol(temp_mol).GetMol()
105106
results = []
106107

@@ -110,11 +111,14 @@ def depict_molecule(
110111
else None
111112
)
112113
template_res = self._get_2D_by_template(templateMol) if self.templates else []
114+
rdkit_res_cd = self._get_2D_by_rdkit_coordgen(rdkitMolCd)
113115
rdkit_res = self._get_2D_by_rdkit(rdkitMol)
114116

115-
if pubchem_res is not None:
117+
if (pubchem_res is not None) and (pubchem_res.source.name == 'PubChem'):
116118
results.append(pubchem_res)
117-
if rdkit_res is not None:
119+
if rdkit_res_cd.source.name == 'RDKit':
120+
results.append(rdkit_res_cd)
121+
if rdkit_res.source.name == 'RDKit':
118122
results.append(rdkit_res)
119123

120124
results = results + template_res
@@ -129,7 +133,7 @@ def depict_molecule(
129133

130134
return DepictionResult(
131135
source=DepictionSource.Failed,
132-
template_name="",
136+
template_name=None,
133137
mol=None,
134138
score=float("inf"),
135139
)
@@ -180,6 +184,30 @@ def _load_template(self, path):
180184

181185
return mol
182186

187+
def _get_2D_by_rdkit_coordgen(self, mol):
188+
"""
189+
Get depiction done using solely the default RDKit coordgen functionality.
190+
191+
Args:
192+
mol (rdkit.Chem.rdchem.Mol): Mol to be depicted
193+
194+
Returns:
195+
DepictionResult: Depiction with some usefull metadata
196+
"""
197+
try:
198+
rdCoordGen.AddCoords(mol, self.coordgen_params)
199+
flaws = DepictionValidator(mol).depiction_score()
200+
return DepictionResult(
201+
source=DepictionSource.RDKit, template_name=None, mol=mol, score=flaws
202+
)
203+
except Exception:
204+
return DepictionResult(
205+
source=DepictionSource.Failed,
206+
template_name=None,
207+
mol=None,
208+
score=float("inf"),
209+
)
210+
183211
def _get_2D_by_rdkit(self, mol):
184212
"""
185213
Get depiction done using solely the default RDKit functionality.
@@ -191,7 +219,8 @@ def _get_2D_by_rdkit(self, mol):
191219
DepictionResult: Depiction with some usefull metadata
192220
"""
193221
try:
194-
rdCoordGen.AddCoords(mol, self.coordgen_params)
222+
rdDepictor.SetPreferCoordGen(False)
223+
rdDepictor.Compute2DCoords(mol, useRingTemplates=True)
195224
flaws = DepictionValidator(mol).depiction_score()
196225
return DepictionResult(
197226
source=DepictionSource.RDKit, template_name=None, mol=mol, score=flaws

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pdbeccdutils"
3-
version = "0.8.6"
3+
version = "1.0.0"
44
description = "Toolkit to parse and process small molecules in wwPDB"
55
authors = ["Protein Data Bank in Europe <pdbehelp@ebi.ac.uk>"]
66
license = "Apache License 2.0."

0 commit comments

Comments
 (0)