Miscellaneous Utilities
- smi2mol_with_errors(smi)[source]
Parse SMILES and return any associated errors or warnings
RDKit writes parse errors to file descriptor 2 (C++ stderr), which is not captured by assigning to
sys.stderr, so the descriptor itself is temporarily redirected to a pipe while parsing.Warning
File descriptor 2 is process-wide, so this function is not thread-safe: concurrent calls, or anything else writing to stderr while a call is in flight, will cross-contaminate. The pipe is also only drained after parsing returns, so output larger than the OS pipe buffer (typically 64 KB) would block. A single SMILES is far below that, but parsing is best kept to one thread.
- count_fragments(mol)[source]
Count the number of fragments in a molecule
- Parameters:
mol (
Mol) – RDKit molecule- Return type:
- Returns:
number of fragments
- get_largest_fragment(mol)[source]
Return the fragment with the largest number of atoms
- Parameters:
mol (
Mol) – RDKit molecule- Raises:
ValueError – if mol is None or contains no atoms, and so has no fragments
- Return type:
Mol- Returns:
RDKit molecule with the largest number of atoms
- taylor_butina_clustering(fp_list, dist_cutoff=0.65)[source]
Cluster a set of fingerprints using the RDKit Taylor-Butina implementation
- demo_block_logs()[source]
An example of another way to turn off RDKit logging
- Return type:
- Returns:
None
- boxplot_base64_image(dist, x_lim=(0, 10))[source]
Plot a distribution as a seaborn boxplot and save the resulting image as a base64 image.
- mol_to_base64_image(mol, target='html', pattern_mol=None, width=300, height=150)[source]
Convert an RDKit molecule to a base64 encoded image string, optionally highlighting atoms matching a SMARTS pattern.
- Parameters:
- Return type:
- Returns:
Base64 encoded image string.
- smi_to_base64_image(smiles, target='html', width=300, height=150)[source]
Convert a SMILES string to a base64 encoded image string.
- remove_dummy_atoms(mol)[source]
Remove dummy atoms (atomic number 0) from an RDKit molecule.
- Parameters:
mol (
Mol) – RDKit molecule from which to remove dummy atoms.- Returns:
RDKit molecule with dummy atoms removed.
- Return type:
Mol
- align_mols_to_template(template_smiles, smiles_list)[source]
Aligns a list of molecules to a template molecule defined by its SMILES string.
Removes dummy atoms (atomic number 0) from the template, generates 2D coordinates, and aligns each molecule in the input list to the template structure.
- Parameters:
template_smiles – SMILES string of the template molecule.
smiles_list – List of SMILES strings to align.
- Returns:
List of aligned RDKit molecule objects.