Skip to content

Mol

Class for handling SMILES strings and RDKit mol objects.

MoleculeRecord(smiles, identifier='')

Enhanced class for managing SMILES strings and RDKit mol objects.

Handles all molecule-related operations including validation, conversion, neutralization, and hydrogen management.

Initialize a MoleculeRecord.

PARAMETER DESCRIPTION
smiles

SMILES string representation of the molecule

TYPE: str

identifier

Optional unique identifier for the molecule

TYPE: str DEFAULT: ''

RAISES DESCRIPTION
ValueError

If smiles is not a valid string

identifier = identifier

Unique identifier for molecule

mol

Get the RDKit mol object, creating it if necessary.

smiles = smiles

Current SMILES after any processing

smiles_original = smiles

Original SMILES used to initialize this MoleculeRecord

__eq__(other)

Check equality based on canonical SMILES.

__hash__()

Hash based on canonical SMILES.

__repr__()

Detailed string representation of the molecule.

__str__()

String representation of the molecule.

add_hydrogens(mol)

Add explicit hydrogens to a molecule.

PARAMETER DESCRIPTION
mol

RDKit mol object

TYPE: Mol

RETURNS DESCRIPTION
Mol | None

Mol object with explicit hydrogens or None if failed

copy()

Create a deep copy of this MoleculeRecord.

RETURNS DESCRIPTION
MoleculeRecord

New MoleculeRecord instance

get_atom_count()

Get the number of atoms in the molecule.

RETURNS DESCRIPTION
int

Number of atoms, or 0 if mol is invalid

get_canonical_smiles(isomeric=True)

Get canonical SMILES representation.

PARAMETER DESCRIPTION
isomeric

Whether to include stereochemistry information

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
str | None

Canonical SMILES string or None if conversion fails

get_heavy_atom_count()

Get the number of heavy (non-hydrogen) atoms in the molecule.

RETURNS DESCRIPTION
int

Number of heavy atoms, or 0 if mol is invalid

get_neutralized(smiles)

get_substructure_matches(pattern)

Get all matches of a substructure pattern.

PARAMETER DESCRIPTION
pattern

SMARTS string or RDKit mol object to search for

TYPE: str | Mol

RETURNS DESCRIPTION
list[tuple[int, ...]]

List of tuples containing atom indices for each match

has_substructure(pattern)

Check if molecule contains a specific substructure.

PARAMETER DESCRIPTION
pattern

SMARTS string or RDKit mol object to search for

TYPE: str | Mol

RETURNS DESCRIPTION
bool

True if substructure is found, False otherwise

is_atom_protected(mol, atom_idx)

Check if an atom is protected.

PARAMETER DESCRIPTION
mol

RDKit mol object

TYPE: Mol

atom_idx

Atom index to check

TYPE: int

RETURNS DESCRIPTION
bool

True if atom is protected, False otherwise

is_valid()

Check if the current SMILES represents a valid molecule.

RETURNS DESCRIPTION
bool

True if valid, False otherwise

make_canonical(isomeric=True)

neutralize()

Neutralize the molecule using the neutralizer.

RETURNS DESCRIPTION

True if neutralization was successful, False otherwise

prepare_for_protonation()

Prepare molecule for protonation site detection.

RETURNS DESCRIPTION
Mol

Prepared RDKit mol object or None if preparation fails

process_azides()

Process azide patterns in SMILES string.

PARAMETER DESCRIPTION
smiles

Input SMILES string

RETURNS DESCRIPTION
None

SMILES string with processed azides

protect_atoms(mol, atom_indices)

Set the protected property on specified atoms to 1.

PARAMETER DESCRIPTION
mol

RDKit mol object

TYPE: Mol

atom_indices

List of atom indices to protect

TYPE: list[int]

RETURNS DESCRIPTION
Mol

The same mol object (modified in place)

refresh_mol_from_smiles()

Refresh the mol object from current SMILES string.

RETURNS DESCRIPTION
bool

True if successful, False otherwise

remove_hydrogens(mol)

Remove explicit hydrogens from a molecule.

PARAMETER DESCRIPTION
mol

RDKit mol object

TYPE: Mol

RETURNS DESCRIPTION
Mol | None

Mol object without explicit hydrogens or None if failed

to_mol()

Convert current SMILES to a RDKit Mol object.

RETURNS DESCRIPTION
Mol | None

RDKit Mol object or None if conversion fails

to_mol_silenced(smiles)

Capture RDKit stderr output and return mol object with error messages.

PARAMETER DESCRIPTION
smiles

SMILES string to convert

TYPE: str

RETURNS DESCRIPTION
dict[str, Any]

Dictionary with 'mol' (RDKit Mol or None)

to_mol_with_hs()

Get RDKit mol object with explicit hydrogens.

RETURNS DESCRIPTION
Mol | None

RDKit Mol object with explicit hydrogens or None if conversion fails

unprotect_atoms(mol)

Set the protected property on all atoms to 0.

PARAMETER DESCRIPTION
mol

RDKit mol object to unprotect

TYPE: Mol

RETURNS DESCRIPTION
Mol

The same mol object (modified in place)

update_smiles_from_mol(mol=None)

Update SMILES string from RDKit mol object.

PARAMETER DESCRIPTION
mol

Optional mol object to use. If None, uses self.mol

TYPE: Mol | None DEFAULT: None

RETURNS DESCRIPTION
bool

True if successful, False otherwise