Skip to main content

A Python package wrapping several chemical structure filtering, rendering and standardization utilities.

Project description

Flag issues, standardize, and visualize molecular structures with ease.

Imports: isort Code style: black Ruff License: MIT Workflow Docs

A collection of chemical filters, with some support for data visualization and analysis. Supported filters include:

  • RDKit's structural alert filters* including BMS, Dundee, Glaxo, Inpharmatica, LINT, MLSMR, PAINS, and SureChEMBL FilterCatalogs;
  • Purchasability filters based on molbloom;
  • SMARTS-like Peptide filters as implemented in PepSift;
  • Silly molecules filters as implemented in molspotter;

*Note: RDKit's implementation these chemical filters is only available from rdkit version 2023.03.1 onwards. Check here for the release notes.

Overview:

The different filtering classes are implemented with a similar API, where get_(flagging|scoring)_df run all the filters available for that class and return a dataframe with all the results. In case of the RdkitFilters implementation, a few visualization methods are available to render the molecules, substructure matches, and molecular grids.

See available filters and visualization methods below:

Installation

The base package includes RDKit filters and visualization:

pip install chem-filters

Some features require additional dependencies, available as extras:

Extra Includes Required for
allfilters pepsift, molspotter, molbloom Peptide, silly molecule, and purchasability filters
standardizers papyrus_structure_pipeline, molvs Molecular standardization
full All of the above All features
# Install with all filters
pip install "chem-filters[allfilters]"

# Install everything
pip install "chem-filters[full]"

Alternatively, install directly from the GitHub repository:

pip install git+https://github.com/David-Araripe/chemFilters.git
pip install "chem-filters[full] @ git+https://github.com/David-Araripe/chemFilters.git"

Documentation

chemFilters' documentation is available on readthedocs (RTD) here!

Filtering Compounds

RdkitFilters

from chemFilters import RdkitFilters
from rdkit import Chem

mols = [
    Chem.MolFromSmiles("CCC1=[O+][Cu-3]2([O+]=C(CC)C1)[O+]=C(CC)CC(CC)=[O+]2"),
    Chem.MolFromSmiles("CC1=C2C(=COC(C)C2C)C(O)=C(C(=O)O)C1=O"),
    Chem.MolFromSmiles("CCOP(=O)(Nc1cccc(Cl)c1)OCC"),
    Chem.MolFromSmiles("Nc1ccc(C=Cc2ccc(N)cc2S(=O)(=O)O)c(S(=O)(=O)O)c1"),
]

rdkit_filter = RdkitFilters(filter_type='ALL', from_smi=False)
filtered_df = rdkit_filter.get_flagging_df(mols)

Purchasability filters

from chemFilters import MolbloomFilters
bloom_filter = MolbloomFilters(from_smi=False, standardize=False)
bloom_filter.get_flagging_df(mols)

Silly molecules filters

from chemFilters import SillyMolFilters
silly_filter = SillyMolFilters(from_smi=False)
silly_filter.get_scoring_df(mols)

Peptide filters

from chemFilters import PeptideFilters
pep_filter = PeptideFilters(from_smi=False)
pep_filter.get_flagging_df(mols)

Core filters

The package also has an implementation that allows applying all available filters at once. This implementation is also used in the CLI version of the package. For further configuration options, check the CLI help.

from chemFilters.core import CoreFilters

smiles = [
    "CCC1=[O+][Cu-3]2([O+]=C(CC)C1)[O+]=C(CC)CC(CC)=[O+]2",
    "CC1=C2C(=COC(C)C2C)C(O)=C(C(=O)O)C1=O",
    "CCOP(=O)(Nc1cccc(Cl)c1)OCC",
    "Nc1ccc(C=Cc2ccc(N)cc2S(=O)(=O)O)c(S(=O)(=O)O)c1",
]

core_filter = CoreFilters()
filtered_df = core_filter(smiles)

CLI

After installing the package, the CLI can be used to filter datasets. The CLI has the following options:

usage: chemFilters [-h] -i INPUT [-c COL_NAME] -o OUTPUT [--rdkit-filter] [--no-rdkit-filter]
                   [--rdkit-subset RDKIT_SUBSET] [--rdkit-valtype RDKIT_VALTYPE] [--pep-filter] [--no-pep-filter]
                   [--silly-filter] [--no-silly-filter] [--bloom-filter] [--no-bloom-filter] [--std-mols]
                   [--no-std-mols] [--std-method STD_METHOD] [--n-jobs N_JOBS] [--chunk-size CHUNK_SIZE]

Where --<name>-filter and --no-<name>-filter enables and disables the implemented filters. Same goes for the parameter --std-mols, that enables the molecular standardization according to --std-method.

Visualization

Rendering a grid of molecules;

from rdkit import Chem
from chemFilters.img_render import MolPlotter, MolGridPlotter

mols = [
    Chem.MolFromSmiles("CCC1=[O+][Cu-3]2([O+]=C(CC)C1)[O+]=C(CC)CC(CC)=[O+]2"),
    Chem.MolFromSmiles("CC1=C2C(=COC(C)C2C)C(O)=C(C(=O)O)C1=O"),
    Chem.MolFromSmiles("CCOP(=O)(Nc1cccc(Cl)c1)OCC"),
    Chem.MolFromSmiles("Nc1ccc(C=Cc2ccc(N)cc2S(=O)(=O)O)c(S(=O)(=O)O)c1"),
]
labels = [f"Molecule {i}" for i in range(1, len(mols) + 1)]

# Initialize grid plotter instance
grid_plotter = MolGridPlotter(from_smi=False, font_name="Telex-Regular")

img = grid_plotter.mol_grid_png(mols[:4], n_cols=2, labels=labels)
display(img)

drawing

Rendering substructure matches:

chemFilter = RdkitFilters(filter_type="ALL")
filter_names, description, substructs = chemFilter.filter_mols(mols)

grid_plotter = MolGridPlotter(
    from_smi=False, font_name="Telex-Regular", size=(250, 250)
)

img = grid_plotter.mol_structmatch_grid_png(mols, substructs=substructs, n_cols=2)
display(img)

drawing

Rendering substructure matches with colors:

from chemFilters import RdkitFilters
import matplotlib.pyplot as plt

chemFilter = RdkitFilters(filter_type="NIH")
filter_names, description, substructs = chemFilter.filter_mols(mols)

plotter = MolPlotter(
    from_smi=False, label_font_size=20, size=(350, 350), font_name="Telex-Regular"
)
img = plotter.render_with_colored_matches(
    mols[0],
    descriptions=description[0],
    substructs=substructs[0],
    label=labels[0],
    alpha=0.3,
)

plt.imshow(img)
ax = plt.gca()  # get current axis
ax.set_axis_off()
plotter.colored_matches_legend(description[0], substructs[0], ax=ax)
fig = plt.gcf()  # get current figure
fig.savefig(  # save matplotlib figure
    "figures/colored_matches.png", bbox_inches="tight", dpi=150, facecolor="white"
)

drawing

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chem_filters-1.0.0.tar.gz (764.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chem_filters-1.0.0-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

Details for the file chem_filters-1.0.0.tar.gz.

File metadata

  • Download URL: chem_filters-1.0.0.tar.gz
  • Upload date:
  • Size: 764.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for chem_filters-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ac28e0584e41f483e194c0aacfc8849164f8f5cd545737294778637061b0ef8c
MD5 217e3fe5590a7aea55f05e43c43cdced
BLAKE2b-256 69375ae800b6321d3ad8f5ea39d6782cec302eb3d9a99e743a8edc6c924af19d

See more details on using hashes here.

File details

Details for the file chem_filters-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: chem_filters-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 35.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for chem_filters-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e792ff572254c7fbc1ef78c36ea059dd53c2154c8476fe89c22b95347a64f3df
MD5 c93c00822a4c7ad259721bacc4f8eb80
BLAKE2b-256 d30eb76e2a2366c18bb53c2ca94a877632afb01aade9aa273c3022afae9bbf09

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page