Fix bond breaking (#46)

Co-authored-by: Tim Lorsbach <tim@lorsba.ch>
Reviewed-on: enviPath/enviPy#46
This commit is contained in:
2025-08-15 09:06:07 +12:00
parent 1267ca8ace
commit 3308d47071
4 changed files with 17 additions and 18 deletions

View File

@ -12,6 +12,7 @@ from rdkit.Chem import MACCSkeys
from rdkit.Chem import rdChemReactions
from rdkit.Chem.Draw import rdMolDraw2D
from rdkit.Chem.MolStandardize import rdMolStandardize
from rdkit.Chem.rdmolops import GetMolFrags
from rdkit.Contrib.IFG import ifg
logger = logging.getLogger(__name__)
@ -223,7 +224,7 @@ class FormatConverter(object):
return False
@staticmethod
def apply(smiles: str, smirks: str, preprocess_smiles: bool = True, bracketize: bool = False,
def apply(smiles: str, smirks: str, preprocess_smiles: bool = True, bracketize: bool = True,
standardize: bool = True, kekulize: bool = True) -> List['ProductSet']:
logger.debug(f'Applying {smirks} on {smiles}')
@ -252,8 +253,10 @@ class FormatConverter(object):
for product in product_set:
try:
Chem.SanitizeMol(product)
product = FormatConverter.standardize(Chem.MolToSmiles(product))
product = GetMolFrags(product, asMols=True)
for p in product:
p = FormatConverter.standardize(Chem.MolToSmiles(p))
prods.append(p)
# if kekulize:
# # from rdkit.Chem import MolStandardize
@ -278,13 +281,12 @@ class FormatConverter(object):
# # bond.SetIsAromatic(False)
# Chem.Kekulize(product)
prods.append(product)
except ValueError as e:
logger.error(f'Sanitizing and converting failed:\n{e}')
continue
# TODO doc!
if len(prods) and len(prods) == len(product_set):
if len(prods):
ps = ProductSet(prods)
pss.add(ps)