From aaf14455b5048cd295352973e4d8f7655bea5db2 Mon Sep 17 00:00:00 2001 From: Emmanuel Noutahi Date: Mon, 6 May 2024 11:59:26 -0400 Subject: [PATCH] start adding spacialscore --- env.yml | 4 ++-- medchem/complexity/_calc.py | 20 ++++++++++++++++++++ medchem/complexity/_filter.py | 4 +++- pyproject.toml | 10 +++++----- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/env.yml b/env.yml index 5073505..80aacb6 100644 --- a/env.yml +++ b/env.yml @@ -15,8 +15,8 @@ dependencies: - networkx # Chemistry - - rdkit - - datamol >=0.10 + - rdkit >=2023.09.3 + - datamol >=0.12 # Optional - lilly-medchem-rules diff --git a/medchem/complexity/_calc.py b/medchem/complexity/_calc.py index 7e0459e..066c88c 100644 --- a/medchem/complexity/_calc.py +++ b/medchem/complexity/_calc.py @@ -1,5 +1,6 @@ import math +import contextlib from rdkit.Chem.rdmolops import GetMolFrags from rdkit.Chem.rdmolops import FindPotentialStereo from rdkit.Chem import FindMolChiralCenters @@ -299,3 +300,22 @@ def TWC(mol: dm.Mol, log10: bool = True): except ValueError: return float("nan") return twc + + +def SPS(mol: dm.Mol, normalize=True): + """Calculates the SpacialScore descriptor, as described in: + [1] Krzyzanowski, A.; Pahl, A.; Grigalunas, M.; Waldmann, H. Spacial Scoreā”€A Comprehensive Topological Indicator for Small-Molecule Complexity. J. Med. Chem. 2023. https://doi.org/10.1021/acs.jmedchem.3c00689. + + Args: + normalize: whether to normalize the score by the number of heavy atoms (nSPS). + """ + + score = None + with contextlib.suppress(ImportError): + mol = dm.to_mol(mol) + from rdkit.Chem import SpacialScore + + score = SpacialScore.SPS(mol, normalize=normalize) + if score is None: + raise ValueError("SpacialScore is not available in your RDKit version, please update to 2023.09.1") + return score diff --git a/medchem/complexity/_filter.py b/medchem/complexity/_filter.py index 85f0f22..261f834 100644 --- a/medchem/complexity/_filter.py +++ b/medchem/complexity/_filter.py @@ -15,6 +15,7 @@ from ._calc import BaroneCT from ._calc import SMCM from ._calc import TWC +from ._calc import SPS class ComplexityFilter: @@ -39,7 +40,8 @@ class ComplexityFilter: "whitlock": WhitlockCT, # whitlock complexity index "barone": BaroneCT, # barone complexity index "smcm": SMCM, # synthetic and molecular complexity - "twc": TWC, # Total walk count complexity + "twc": TWC, # Total walk count complexity, + "spacialscore": SPS, } def __init__( diff --git a/pyproject.toml b/pyproject.toml index dc2cbcd..b512390 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ dependencies = [ "pandas", "networkx", "datamol >=0.10", - "rdkit", + "rdkit >=2023.09.3", ] [project.scripts] @@ -87,17 +87,17 @@ omit = ["medchem/__init__.py", "medchem/_version.py"] output = "coverage.xml" [tool.ruff] -ignore = [ +lint.ignore = [ "E501", # Never enforce `E501` (line length violations). ] -line-length = 110 +line-length = 120 target-version = "py311" -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "__init__.py" = [ "F401", # imported but unused "E402", # Module level import not at top of file ] -[tool.ruff.pycodestyle] +[tool.ruff.lint.pycodestyle] max-doc-length = 150