Skip to content

molecule #

Functions:

  • mol_to_smiles

    Convert a molecule to a SMILES string with atom mapping.

mol_to_smiles #

mol_to_smiles(mol: Mol, canonical: bool = True) -> str

Convert a molecule to a SMILES string with atom mapping.

Parameters:

  • mol (Mol) –

    The molecule to convert.

  • canonical (bool, default: True ) –

    Whether to canonicalize the atom ordering prior to assigning map indices.

Returns:

  • str

    The SMILES string.

Source code in descent/utils/molecule.py
def mol_to_smiles(mol: "Chem.Mol", canonical: bool = True) -> str:
    """Convert a molecule to a SMILES string with atom mapping.

    Args:
        mol: The molecule to convert.
        canonical: Whether to canonicalize the atom ordering prior to assigning
            map indices.

    Returns:
        The SMILES string.
    """
    from rdkit import Chem

    mol = Chem.AddHs(mol)

    if canonical:
        order = Chem.CanonicalRankAtoms(mol, includeChirality=True)
        mol = Chem.RenumberAtoms(mol, list(order))

    for atom in mol.GetAtoms():
        atom.SetAtomMapNum(atom.GetIdx() + 1)

    return Chem.MolToSmiles(mol)