Skip to main content

hypothesis-rdkit

A strategy to generate random molecules for the hypothesis testing framework. It uses a collection of fragments generated from the ChEMBL database to construct plausible molecular graphs. The fragments were mined using the BRICS method.

demo

Installation

pip install -U hypothesis-rdkit
# or
conda install -c conda-forge hypothesis-rdkit

Usage

The module hypothesis-rdkit provides a strategy for generating RDKit molecules. During the installation of the package, this strategy is linked to the rdkit.Chem.Mol type:

from hypothesis import given
from rdkit.Chem import Mol

@given(...)
def test_molecule_method(mol : Mol):
    # mol is a randomly generated molecule
    assert mol.GetNumAtoms() > 0

You can use the mols strategy directly for further customization:

from hypothesis import given
from hypothesis_rdkit import mols
from rdkit.Chem import GetMolFrags, Mol
from rdkit.Chem.rdMolDescriptors import CalcNumRotatableBonds

@given(mols(n_connected_components=2, max_rotatable_bonds=5, n_conformers=10))
def test_molecule_mixtures(mol : Mol):
    frags = GetMolFrags(mol, asMols=True)
    assert len(frags) == 2

    for frag in frags:
        assert CalcNumRotatableBonds(frag) <= 5

    assert mol.GetNumConformers() <= 10

There are also strategies to generate molecules in SMILES, mol block or InChI representation accepting the same parameters as mols:

from hypothesis import given
from hypothesis_rdkit import smiles, mol_blocks, inchis
from rdkit.Chem import MolFromSmiles, MolFromMolBlock, MolFromInchi

@given(smiles())
def test_smiles(smiles : str):
    mol = MolFromSmiles(smiles)
    assert mol is not None and mol.GetNumAtoms() > 0

@given(mol_blocks())
def test_mol_block(mol_block : str):
    mol = MolFromMolBlock(mol_block)
    assert mol is not None and mol.GetNumAtoms() > 0

@given(inchis())
def test_inchi(inchi : str):
    mol = MolFromInchi(inchi)
    assert mol is not None and mol.GetNumAtoms() > 0

Development

All fragment files are generated during a test run (pytest) in the user data directory. On Linux, this is ~/.local/share/hypothesis_rdkit/{version}/.

Release files for hypothesis-rdkit 0.6.1

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

Source distribution (sdist)

Source distribution for hypothesis-rdkit 0.6.1
File Size Uploaded
hypothesis-rdkit-0.6.1.tar.gz 50.9 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for hypothesis-rdkit 0.6.1
File Interpreter ABI Platform
hypothesis_rdkit-0.6.1-py3-none-any.whl Python 3 none any Details

Total release size: 101.9 MB

Release files / hypothesis-rdkit-0.6.1.tar.gz

Download URL hypothesis-rdkit-0.6.1.tar.gz
Size 50.9 MB
Tags Source
SHA-256 checksum
How to use checksums
82e873915f32519cb0170a7c6cc89543380ba898262e82829f49b6113480da17
BLAKE2b-256 checksum
How to use checksums
c247c0a0b53f10422c5f46dc66c99bbd812ae41dbd1dc0c0d11cf9346a82c815
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.12

Release files / hypothesis_rdkit-0.6.1-py3-none-any.whl

Download URL hypothesis_rdkit-0.6.1-py3-none-any.whl
Size 51.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
4b7fbc47ffad2bdbd2df382888acce0f3013d3ccd16f69facf4c7336eade1aaa
BLAKE2b-256 checksum
How to use checksums
187fd0cdbe909270fb378b5e454660215ad5585f0c2285e12019a0a5e9ac17af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.12

Release history Release notifications | RSS feed

This release

0.6.1 This release

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

1 release file

0.5.1

1 release file

0.5

1 release file

0.4

1 release file

0.1

2 release 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