Skip to main content

Integration of rdkit functionality into sklearn pipelines.

Project description

MolPipeline

MolPipeline is a Python package providing RDKit functionality in a Scikit-learn like fashion.

Background

The open-source package scikit-learn provides a large variety of machine learning algorithms and data processing tools, among which is the Pipeline class, allowing users to prepend custom data processing steps to the machine learning model. MolPipeline extends this concept to the field of chemoinformatics by wrapping default functionalities of RDKit, such as reading and writing SMILES strings or calculating molecular descriptors from a molecule-object.

A notable difference to the Pipeline class of scikit-learn is that the Pipline from MolPipeline allows for instances to fail during processing without interrupting the whole pipeline. Such behaviour is useful when processing large datasets, where some SMILES strings might not encode valid molecules or some descriptors might not be calculable for certain molecules.

Publications

The publication is freely available here.

Installation

pip install molpipeline

Usage

See the notebooks folder for basic and advanced examples of how to use Molpipeline.

A basic example of how to use MolPipeline to create a fingerprint-based model is shown below (see also the notebook):

from molpipeline import Pipeline
from molpipeline.any2mol import AutoToMol
from molpipeline.mol2any import MolToMorganFP
from molpipeline.mol2mol import (
    ElementFilter,
    SaltRemover,
)

from sklearn.ensemble import RandomForestRegressor

# set up pipeline
pipeline = Pipeline([
      ("auto2mol", AutoToMol()),                                     # reading molecules
      ("element_filter", ElementFilter()),                           # standardization
      ("salt_remover", SaltRemover()),                               # standardization
      ("morgan2_2048", MolToMorganFP(n_bits=2048, radius=2)),        # fingerprints and featurization
      ("RandomForestRegressor", RandomForestRegressor())             # machine learning model
    ],
    n_jobs=4)

# fit the pipeline
pipeline.fit(X=["CCCCCC", "c1ccccc1"], y=[0.2, 0.4])
# make predictions from SMILES strings
pipeline.predict(["CCC"])
# output: array([0.29])

Molpipeline also provides custom estimators for standard cheminformatics tasks that can be integrated into pipelines, like clustering for scaffold splits (see also the notebook):

from molpipeline.estimators import MurckoScaffoldClustering

scaffold_smiles = [
    "Nc1ccccc1",
    "Cc1cc(Oc2nccc(CCC)c2)ccc1",
    "c1ccccc1",
]
linear_smiles = ["CC", "CCC", "CCCN"]

# run the scaffold clustering
scaffold_clustering = MurckoScaffoldClustering(
    make_generic=False, linear_molecules_strategy="own_cluster", n_jobs=16
)
scaffold_clustering.fit_predict(scaffold_smiles + linear_smiles)
# output: array([1., 0., 1., 2., 2., 2.])

License

This software is licensed under the MIT license. See the LICENSE file for details.

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

molpipeline-0.8.3.tar.gz (91.5 kB view details)

Uploaded Source

Built Distribution

molpipeline-0.8.3-py3-none-any.whl (132.2 kB view details)

Uploaded Python 3

File details

Details for the file molpipeline-0.8.3.tar.gz.

File metadata

  • Download URL: molpipeline-0.8.3.tar.gz
  • Upload date:
  • Size: 91.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for molpipeline-0.8.3.tar.gz
Algorithm Hash digest
SHA256 0120c23cd79d31e22adc2290be9f59cc1718861f7ec9b26a6e6a442fda0c1486
MD5 a57a687831f9c47a6c2aec659805ba66
BLAKE2b-256 b4b90fc16d06410fba32a759e4f35d96dd3222b81c51d04ba547f95f414f57fa

See more details on using hashes here.

File details

Details for the file molpipeline-0.8.3-py3-none-any.whl.

File metadata

  • Download URL: molpipeline-0.8.3-py3-none-any.whl
  • Upload date:
  • Size: 132.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for molpipeline-0.8.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d857c9abb488a5137882a1cf8aa0d82ca069b0713bcecfb3a1eaa3fa0adcc8c0
MD5 6b31bea0569a01180c2fe43fe7dc6e58
BLAKE2b-256 9d911764b7f4d3a3e7cb4d571d25aa561ef28422f2f391b7ca7c42ffb815e863

See more details on using hashes here.

Supported by

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