Skip to content

Commit 88fa196

Browse files
committed
Block RDKit logs if sanitation problems appear
1 parent 877efed commit 88fa196

File tree

1 file changed

+8
-2
lines changed
  • src/biotite/interface/rdkit

1 file changed

+8
-2
lines changed

src/biotite/interface/rdkit/mol.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
__author__ = "Patrick Kunzmann, Simon Mathis"
77
__all__ = ["to_mol", "from_mol"]
88

9+
import copy
910
import numbers
1011
import warnings
1112
from collections import defaultdict
1213
import numpy as np
1314
import rdkit.Chem.AllChem as Chem
1415
from rdkit.Chem import SanitizeFlags
16+
from rdkit.rdBase import BlockLogs
1517
from biotite.interface.version import requires_version
1618
from biotite.interface.warning import LossyConversionWarning
1719
from biotite.structure.atoms import AtomArray, AtomArrayStack
@@ -320,7 +322,10 @@ def from_mol(mol, conformer_id=None, add_hydrogen=None):
320322
if add_hydrogen is None:
321323
add_hydrogen = not _has_explicit_hydrogen(mol)
322324
if add_hydrogen:
323-
Chem.SanitizeMol(mol, SanitizeFlags.SANITIZE_ADJUSTHS)
325+
mol = copy.deepcopy(mol)
326+
with BlockLogs():
327+
# Avoid modifying the input molecule
328+
Chem.SanitizeMol(mol, SanitizeFlags.SANITIZE_ADJUSTHS)
324329
mol = Chem.AddHs(mol, addCoords=False, addResidueInfo=False)
325330

326331
rdkit_atoms = mol.GetAtoms()
@@ -427,7 +432,8 @@ def from_mol(mol, conformer_id=None, add_hydrogen=None):
427432
# Copy as 'Kekulize()' modifies the molecule in-place
428433
mol = Chem.Mol(mol)
429434
try:
430-
Chem.Kekulize(mol)
435+
with BlockLogs():
436+
Chem.Kekulize(mol)
431437
except Chem.KekulizeException:
432438
warnings.warn(
433439
"Kekulization failed, "

0 commit comments

Comments
 (0)