scikit-fingerprints

repository·master·Indexed 18 days ago

https://github.com/mlcil/scikit-fingerprints

A scikit-learn compatible library for efficient molecular fingerprinting and chemoinformatics. It provides tools to convert SMILES strings into machine-learning-ready features, including over 30 fingerprint types (e.g., ECFP, MACCS), 30+ molecular filters, 14 similarity and distance measures, and 11 applicability domain checks. The library supports integration with sklearn.pipeline.Pipeline and includes built-in benchmark datasets from MoleculeNet and Therapeutics Data Commons.

Tokens
23.7K
Snippets
62
Records
98
Agent score
63%

What's inside scikit-fingerprints

  1. Key features of scikit-fingerprints

    master

    The library provides a comprehensive suite of tools for chemoinformatics:

    • Molecular Fingerprints: Over 30 types (e.g., ECFP, Avalon, MACCS, Mordred, PubChem) with a uniform .transform() API.
    • Molecular Filters: Over 30 substructural and physicochemical filters (e.g., Lipinski Rule of 5, PAINS, REOS).
    • Similarity & Distance Measures: 14 measures (e.g., Tanimoto, Dice, MCS) compatible with distance-based models like kNN, UMAP, and HDBSCAN.
    • Applicability Domain Checks: 11 methods (e.g., kNN, centroid distance, TOPKAT) to evaluate model reliability.
    • Benchmark Datasets: Built-in support for MoleculeNet, Therapeutics Data Commons, MoleculeACE, and LRGB, including built-in train-test splits.
    • scikit-learn Integration: Native support for Pipeline, FeatureUnion, GridSearchCV, and more.
  2. Use TDC molecular dataset loaders in skfp.datasets.tdc

    master

    The skfp.datasets.tdc module provides access to molecular datasets from the Therapeutics Data Commons (TDC). It is organized into submodules based on the type of biological or chemical property being measured: ADME, HTS, and Toxicity.

    To use these datasets, you can call specific loader functions from the appropriate submodule. The module also provides utility functions for loading full benchmarks or specific data splits.

    from skfp.datasets.tdc import adme, hts, tox
    
    # Example: Loading an ADME dataset
    data = adme.load_caco2_wang()
    
    # Example: Loading a Toxicity dataset
    data = tox.load_ames()
    
    # Example: Loading an HTS dataset
    data = hts.load_sarscov2_3clpro_diamond()
  3. Use molecular filters in skfp.filters

    master

    The skfp.filters module provides a collection of classes used to compute molecular filters. These filters are typically used in drug discovery and cheminformatics workflows to screen molecules based on specific physicochemical properties or structural criteria (e.g., Lipinski's Rule of Five, drug-likeness, or toxicity patterns).

    Available filter classes include:

    • Physicochemical Property Filters: MolecularWeightFilter, RuleOfFiveFilter, RuleOfThreeFilter, RuleOfTwoFilter, RuleOfFourFilter, RuleOfVeberFilter, RuleOfXuFilter.
    • Drug-likeness & Lead-likeness Filters: ZINCDruglikeFilter, FAF4DruglikeFilter, FAF4LeadlikeFilter, GlaxoFilter, GSKFilter, PfizerFilter, REOSFilter.
    • Substructure & Pattern Filters: PAINSFilter (Pan-Assay Interference Compounds), BrenkFilter, BMSFilter, LINTFilter.
    • Database/Source Specific Filters: SureChEMBLFilter, ZINCBasicFilter, NIHFilter, NIBRFilter.
    • Other Specialized Filters: GhoseFilter, HaoFilter, InpharmaticaFilter, MLSMRFilter, OpreaFilter, TiceHerbicidesFilter, TiceInsecticidesFilter, ValenceDiscoveryFilter.
  4. Check applicability domain using skfp.applicability_domain

    master

    The skfp.applicability_domain module provides several classes to determine if a new data point falls within the applicability domain (AD) of a trained model. This is used to assess the reliability of model predictions based on how similar the input data is to the training set.

    Available checkers include:

    • BoundingBoxADChecker: Checks if points fall within the axis-aligned bounding box of the training data.
    • ConvexHullADChecker: Checks if points fall within the convex hull of the training data.
    • DistanceToCentroidADChecker: Measures distance to the training data centroid.
    • HotellingT2TestADChecker: Uses Hotelling's T² test for multivariate outlier detection.
    • KNNADChecker: Uses K-Nearest Neighbors to assess local density/similarity.
    • LeverageADChecker: Uses leverage values to identify influential/outlier points.
    • PCABoundingBoxADChecker: Checks bounds within a reduced PCA subspace.
    • ProbStdADChecker: Uses probability and standard deviation metrics.
    • ResponseVariableRangeADChecker: Checks if the response variable falls within the training range.
    • StandardDeviationADChecker: Uses standard deviation thresholds.
    • TOPKATADChecker: Implements the TOPKAT method for AD assessment.
  5. Compute molecular descriptors using skfp.descriptors

    master
    The skfp.descriptors module provides functions to compute various molecular descriptors categorized into three main types: Charge, Constitutional, and Topological descriptors. These descriptors can be used to characterize the chemical properties and structural features of molecules.
  6. Extend scikit-fingerprints by inheriting from base classes

    master

    The skfp.bases module provides several abstract base classes designed for developers to implement custom functionalities. If you need to create a custom filtering mechanism, a new fingerprinting method, a preprocessing step, or a substructure-based fingerprint, you should inherit from the corresponding base class to ensure compatibility with the rest of the library's ecosystem.

    Available base classes for extension:

    • BaseFilter: For implementing custom filtering logic.
    • BaseFingerprintTransformer: For creating custom fingerprinting transformations.
    • BasePreprocessor: For implementing custom data preprocessing steps.
    • BaseSubstructureFingerprint: For implementing custom substructure-based fingerprinting methods.
  7. Quickstart: Generate 3D fingerprints using conformers

    master

    Fingerprints that rely on molecular conformers (3D-based) have their requires_conformers attribute set to True. To use these, you must first transform SMILES into molecule objects using MolFromSmilesTransformer and then generate conformers using ConformerGenerator before calling .transform() on the fingerprint.

    from skfp.preprocessing import ConformerGenerator, MolFromSmilesTransformer
    from skfp.fingerprints import WHIMFingerprint
    
    smiles_list = ["O=S(=O)(O)CCS(=O)(=O)O", "O=C(O)c1ccccc1O"]
    
    mol_from_smiles = MolFromSmilesTransformer()
    conf_gen = ConformerGenerator()
    fp = WHIMFingerprint()
    print(fp.requires_conformers)  # True
    
    mols_list = mol_from_smiles.transform(smiles_list)
    mols_list = conf_gen.transform(mols_list)
    
    X = fp.transform(mols_list)
    print(X)
  8. Quickstart: Generate fingerprints from SMILES

    master

    For most topological or 2D-based fingerprints, you can pass a list of SMILES strings directly to the .transform() method of the fingerprint object.

    from skfp.fingerprints import AtomPairFingerprint
    
    smiles_list = ["O=S(=O)(O)CCS(=O)(=O)O", "O=C(O)c1ccccc1O"]
    
    atom_pair_fingerprint = AtomPairFingerprint()
    
    X = atom_pair_fingerprint.transform(smiles_list)
    print(X)
  9. Install scikit-fingerprints

    master

    You can install scikit-fingerprints from PyPI using pip or uv.

    To include support for neural fingerprints (embeddings from pretrained neural networks), install the [neural] optional dependency.

    Supported Python versions: 3.10 to 3.13.

    # Standard installation
    pip install scikit-fingerprints
    
    # Installation with neural fingerprint support
    pip install "scikit-fingerprints[neural]"
    
    # Install bleeding-edge features from GitHub
    pip install git+https://github.com/MLCIL/scikit-fingerprints.git
  10. Install scikit-fingerprints via pip

    master

    You can install the core library using pip. If you need to use neural fingerprints (such as CLAMP), you must install the neural extra, which includes PyTorch (torch).

    # Standard installation
    pip install scikit-fingerprints
    
    # Installation with neural fingerprint support (includes PyTorch)
    pip install "scikit-fingerprints[neural]"
  11. Load ASAP Discovery-OpenADMET challenge datasets

    master

    The skfp.datasets.asap module provides loaders for the ASAP Discovery-OpenADMET challenge datasets. You can load the full benchmark, specific datasets, or predefined splits using the following functions:

    • load_asap_benchmark: Loads the complete benchmark.
    • load_asap_dataset: Loads a specific dataset.
    • load_asap_splits: Loads the dataset according to predefined splits.

    Additionally, the module provides specialized loaders for individual ADMET properties:

    • load_hlm: Human Liver Microsomes
    • load_ksol: Kinetic Solubility
    • load_logd: LogD
    • load_mdr1_mdckii: MDR1-MDCKII permeability
    • load_mlm: Mouse Liver Microsomes
    • load_pic50_sars_cov_2: pIC50 for SARS-CoV-2
    • load_pic50_mers_cov: pIC50 for MERS-CoV
    from skfp.datasets.asap import load_asap_benchmark, load_hlm
    
    # Example: Load the full benchmark
    benchmark = load_asap_benchmark()
    
    # Example: Load a specific property dataset
    hlm_data = load_hlm()
  12. Learn molecular ML fundamentals via workshops

    master

    If you are new to molecular machine learning (ML) and molecular fingerprints, you can use the molecular_ml_workshops resource. These workshops provide ground-up introductions to RDKit, scikit-fingerprints, and their practical applications.

    https://github.com/j-adamczyk/molecular_ml_workshops