forked from enviPath/enviPy
[Fix] Canonicalize SMILES when checking overlaps in smiles_covered_by (#443)
Co-authored-by: Tim Lorsbach <tim@lorsba.ch> Reviewed-on: enviPath/enviPy#443
This commit is contained in:
@ -68,6 +68,8 @@ class PredictionResult(object):
|
||||
|
||||
|
||||
class FormatConverter(object):
|
||||
tautomer_enumerator = rdMolStandardize.TautomerEnumerator()
|
||||
|
||||
@staticmethod
|
||||
def mass(smiles):
|
||||
return Descriptors.MolWt(FormatConverter.from_smiles(smiles))
|
||||
@ -240,8 +242,9 @@ class FormatConverter(object):
|
||||
Chem.RemoveStereochemistry(res_mol)
|
||||
|
||||
if canonicalize_tautomers:
|
||||
te = rdMolStandardize.TautomerEnumerator() # idem
|
||||
res_mol = te.Canonicalize(res_mol)
|
||||
tautomers = FormatConverter.tautomer_enumerator.Enumerate(res_mol)
|
||||
if len(tautomers) >= 1:
|
||||
res_mol = FormatConverter.tautomer_enumerator.PickCanonical(tautomers)
|
||||
|
||||
return Chem.MolToSmiles(res_mol, kekuleSmiles=True)
|
||||
|
||||
@ -389,7 +392,7 @@ class FormatConverter(object):
|
||||
prods.append(p)
|
||||
|
||||
except ValueError as e:
|
||||
logger.error(f"Sanitizing and converting failed:\n{e}")
|
||||
logger.debug(f"Sanitizing and converting failed:\n{e}")
|
||||
continue
|
||||
|
||||
if len(prods):
|
||||
@ -397,7 +400,8 @@ class FormatConverter(object):
|
||||
pss.add(ps)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Applying {smirks} on {smiles} failed:\n{e}")
|
||||
logger.debug(f"Applying {smirks} on {smiles} failed:\n{e}")
|
||||
pass
|
||||
|
||||
return list(pss)
|
||||
|
||||
@ -482,8 +486,10 @@ class FormatConverter(object):
|
||||
if standardize:
|
||||
for smi in l_smiles:
|
||||
try:
|
||||
smi = FormatConverter.standardize(
|
||||
smi, remove_stereo=True, canonicalize_tautomers=canonicalize_tautomers
|
||||
smi = FormatConverter.canonicalize(
|
||||
FormatConverter.standardize(
|
||||
smi, remove_stereo=True, canonicalize_tautomers=canonicalize_tautomers
|
||||
)
|
||||
)
|
||||
except Exception:
|
||||
# :shrug:
|
||||
@ -497,8 +503,12 @@ class FormatConverter(object):
|
||||
if standardize:
|
||||
for smi in r_smiles:
|
||||
try:
|
||||
smi = FormatConverter.standardize(
|
||||
smi, remove_stereo=True, canonicalize_tautomers=canonicalize_tautomers
|
||||
smi = FormatConverter.canonicalize(
|
||||
FormatConverter.standardize(
|
||||
smi,
|
||||
remove_stereo=True,
|
||||
canonicalize_tautomers=canonicalize_tautomers,
|
||||
)
|
||||
)
|
||||
except Exception:
|
||||
# :shrug:
|
||||
|
||||
Reference in New Issue
Block a user