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.

Download files

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

Source Distribution

molspotter-1.0.0.tar.gz (280.8 kB view details)

Uploaded Source

Built Distribution

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

molspotter-1.0.0-py3-none-any.whl (274.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: molspotter-1.0.0.tar.gz
  • Upload date:
  • Size: 280.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for molspotter-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2caddf92e68abe5cb3f1aa8ca652dcbec4a9104776a16b4a59c94b0c8aaccc09
MD5 c7acc0fcdbeeff287728e8e56ba566e8
BLAKE2b-256 bd3687e34198133ed7be5b84d63c5e1b18be5fd5f5e81f8964332913d70f004c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: molspotter-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 274.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for molspotter-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8ef73a01a280edb94775d1f99ae7774935d606801de8f9f7fb5e3bd9fbb4ca3
MD5 2fdd19d5c9e8c8d807068d20550d7169
BLAKE2b-256 d157ddf7697d32e0b7f189900497f3d87f6b6bbc78e0145ebbb9220a56cf6e22

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

0.0.2

2 files

0.0.1

2 files

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