Skip to content

to_smiles

to_smiles(data: GraphData, kekulize: bool = False) -> str

Converts a GraphData with the features of from_smiles() to a (canonical, isomeric) SMILES string, as PyG's to_smiles.

Parameters:

Name Type Description Default
data GraphData

The molecular graph.

required
kekulize bool

Whether to convert the aromatic bonds to single and double bonds. Default: False

False

Returns:

Type Description
str

The SMILES string.

Source code in mlx_graphs/utils/smiles.py
def to_smiles(data: "GraphData", kekulize: bool = False) -> str:
    r"""Converts a :class:`~mlx_graphs.data.GraphData` with the features of
    :func:`from_smiles` to a (canonical, isomeric) SMILES string, as PyG's
    ``to_smiles``.

    Args:
        data: The molecular graph.
        kekulize: Whether to convert the aromatic bonds to single and double
            bonds. Default: ``False``

    Returns:
        The SMILES string.
    """
    Chem, _ = _import_rdkit()
    mol = to_rdmol(data, kekulize=kekulize)
    return Chem.MolToSmiles(mol, isomericSmiles=True)

from mlx_graphs.utils import to_smiles · mlx_graphs/utils/smiles.py