chemistry
RDKit-backed molecular helpers (SMILES, SELFIES, fingerprints, properties).
- exception drugs.chemistry.RDKitNotAvailable
Bases:
RuntimeErrorRaised when RDKit-dependent functionality is requested but unavailable.
- exception drugs.chemistry.SELFIESNotAvailable
Bases:
RuntimeErrorRaised when SELFIES dependency is missing.
- drugs.chemistry.mol_from_smiles(smiles: str, *, sanitize: bool = True) Any | None
Parse a SMILES string into an RDKit molecule, handling errors gracefully.
When RDKit is unavailable, returns the SMILES string so downstream helpers can fall back to hashed fingerprints and lightweight heuristics.
- drugs.chemistry.to_selfies(smiles: str) str | None
Convert SMILES to SELFIES, returning
Nonewhen conversion fails.
- drugs.chemistry.molecular_fingerprint(mol: Any, *, method: str = 'morgan', n_bits: int = 2048, radius: int = 2, use_features: bool = False) ndarray
Generate a molecular fingerprint as a numpy array of bits.
If RDKit is unavailable, a deterministic hashed fingerprint derived from SMILES is returned instead.
- drugs.chemistry.fingerprint_similarity(fp_a: ndarray, fp_b: ndarray, *, metric: str = 'tanimoto') float
Compute similarity between two bit vectors using common coefficients.
- drugs.chemistry.rdkit_properties(mol: Any) Dict[str, Any]
Compute common RDKit-derived molecular properties.
When RDKit is missing, returns a placeholder structure with
Nonevalues and Lipinski checks skipped. This allows downstream code to continue running while reporting the absence of cheminformatics features.
- drugs.chemistry.lipinski_violations(mol: Any) List[str]
Return a list of violated Lipinski rules for the molecule.
- drugs.chemistry.synthetic_accessibility(mol: Any) float | None
Estimate synthetic accessibility score (lower is easier).
- drugs.chemistry.require_rdkit() None