Skip to main content

🔎 molspotter

PyPI version Supported Python versions License: MIT Tests Ruff

Identify silly molecules — molecules containing substructures (Morgan fingerprint bits) that were never observed in a reference set of "sound" molecules. molspotter handles loading pretrained spotters, scoring and visualizing silly bits, and building your own spotters from any molecular file format.

✨ Features

  • 🎯 Silliness scoring — any Morgan fingerprint bit of a query molecule absent from the reference set counts as "silly"; get a binary flag or a continuous fraction of silly bits.
  • 📦 Three ready-to-use pretrained spotters — trained on ChEMBL (v32), ExCAPE-DB, and Papyrus (v05.6), loadable by name.
  • 🧪 Build your own spotter — grow a reference set from a SMILES string, an RDKit molecule (or list thereof), or an entire file.
  • 📁 Multi-format streaming I/O — SMILES, SDF, MOL, MOL2 and Maestro files, transparently reading .gz/.bz2/.xz-compressed inputs without loading everything into memory.
  • 🖼️ Visualize silly bits — highlight the exact atoms/bonds responsible for a molecule's silly score.
  • 💾 Portable spotter files — save and reload spotters as compact, LZMA-compressed JSON files.
  • 💻 Command-line interface — create and score spotters directly from the shell.

✍️ Disclaimer

This repository is based on the awesome silly_walks work of Patrick Walters.

📦 Installation

pip install molspotter

Or from source:

git clone https://github.com/OlivierBeq/molspotter.git
pip install ./molspotter

🛠️ Requirements

💡 Usage

Quickstart

from molspotter import SillyMolSpotter
from rdkit import Chem

sms = SillyMolSpotter.from_pretrained('chembl')

mol = Chem.MolFromSmiles('C=C=C1CN(C)CCN1Cc5ccc(C(=O)Nc4ccc(C)c(Nc3nccc(c2cccnc2)n3)c4)cc5')
sms.score_mol(mol)
# 1

Scoring molecules

A molecule is scored against the bits of Morgan fingerprint observed in the spotter's reference set. Two flavors of score are available:

Score Call Range Meaning
Binary sms.score_mol(mol) {0, 1} 1 if any bit of the molecule is silly, 0 otherwise.
Continuous sms.score_mol(mol, binary=False) [0.0, 1.0] Fraction of silly bits: $score = \frac{n_{silly\ bits}}{n_{on\ bits}}$
sms.score_mol(mol, binary=False)
# 0.023809523809523808

A continuous score of 0.0 means the molecule contains no silly bit at all, while 1.0 means every bit of the molecule is silly.

Visualizing silly bits

Highlight the substructures responsible for a molecule's score:

img = sms.show_mol(mol)

Silly bits highlighted in the molecular structure

Building a custom spotter

Instantiate an empty spotter and grow its reference set from a file, a single molecule, or a SMILES string:

sms = SillyMolSpotter(fp_radius=2)  # radius of the Morgan fingerprint

sms.add_file('PATH_TO_MOLECULAR_FILE')
sms.add_mol(mol)
sms.add_smiles('c1ccccc1')

Saving and loading spotters

Spotters are persisted as compact, LZMA-compressed files:

sms.save('PATH_TO_SAVE_SPOTTER_TO')

sms2 = SillyMolSpotter.from_file('PATH_TO_SAVED_SPOTTER')

Command-line interface

Create a spotter

molspotter create -o examples/chembl_drugs.sp -i examples/chembl_drugs.sd
Option Required Description
-o, --outfile ✅ Path to save the spotter to.
-r, --radius Radius of the Morgan fingerprint (default: 1).
-i, --input ✅ Input file(s) to parse and add to the spotter. Repeatable.

Score with a spotter

molspotter score -s chembl -i examples/chembl_drugs.sd
molspotter score -s examples/chembl_drugs.sp -i examples/chembl_drugs.sd -o scores.txt
Option Required Description
-s, --spotter ✅ Path to a saved spotter, or one of chembl, excape, papyrus.
-i, --input ✅ Input file(s) containing molecules to score. Repeatable.
-o, --output File to write scores to, one per line. Prints to stdout if omitted.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

📚 API Documentation

SillyMolSpotter

SillyMolSpotter(fp_radius)

Spotter identifying silly molecules from the Morgan fingerprint bits of a reference set.

Parameters

  • fp_radius : int Radius of the Morgan fingerprinter used to identify silly bits.

Class methods

Method Description
from_pretrained(name) Load one of the bundled pretrained spotters: 'chembl', 'excape' or 'papyrus' (case-insensitive).
from_file(filepath) Load a spotter previously saved with save.

Instance methods

Method Description
add_mol(mol) Add an RDKit Chem.Mol, or list thereof, to the reference set.
add_smiles(smiles) Add a SMILES string, or list thereof, to the reference set.
add_file(filepath) Parse a molecular file and add its content to the reference set.
score_mol(mol, binary=True) Score an RDKit Chem.Mol, or list thereof (see Scoring molecules).
show_mol(mol, raise_error=False, molsPerRow=3, subImgSize=(500, 300), useSVG=False, returnPNG=False, **kwargs) Render the molecule with its silly bits highlighted.
save(filepath) (alias: to_file) Save the spotter to disk as an LZMA-compressed file.

MolSupplier

MolSupplier(source=None, supplier=None, format=None, compression=None, **kwargs)

Iterable, context-managed molecular reader handling multiple formats and compressions, with an optional tqdm progress bar.

Parameters

  • source : str | file-like Filename or file-like object. Format and compression are auto-detected from the filename unless a file-like object is supplied, in which case format must be provided.
  • supplier : Iterable[Chem.Mol] An existing molecular supplier (e.g. rdkit.Chem.ForwardSDMolSupplier) to wrap directly.
  • format : str One of 'smi', 'mae', 'sd', 'mol2', 'mol'.
  • compression : str One of 'lzma', 'zlib', 'bz2'.
  • kwargs Forwarded to the underlying RDKit supplier; may also include total (expected molecule count) and show_progress (bool) to control the progress bar shown while iterating.

Metadata

Release files for molspotter 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for molspotter 1.0.0
File Size Uploaded Provenance Actions
molspotter-1.0.0.tar.gz 280.8 kB Without provenance Details for molspotter-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for molspotter 1.0.0
File Interpreter ABI Platform Actions
molspotter-1.0.0-py3-none-any.whl Python 3 none any Details for molspotter-1.0.0-py3-none-any.whl

Total release size: 555.7 kB

Release files / molspotter-1.0.0.tar.gz

Download URL molspotter-1.0.0.tar.gz
Size 280.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2caddf92e68abe5cb3f1aa8ca652dcbec4a9104776a16b4a59c94b0c8aaccc09
BLAKE2b-256 checksum
How to use checksums
bd3687e34198133ed7be5b84d63c5e1b18be5fd5f5e81f8964332913d70f004c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / molspotter-1.0.0-py3-none-any.whl

Download URL molspotter-1.0.0-py3-none-any.whl
Size 274.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d8ef73a01a280edb94775d1f99ae7774935d606801de8f9f7fb5e3bd9fbb4ca3
BLAKE2b-256 checksum
How to use checksums
d157ddf7697d32e0b7f189900497f3d87f6b6bbc78e0145ebbb9220a56cf6e22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Security for molspotter 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page