Skip to content

from_rdmol

from_rdmol(mol: Any) -> GraphData

Converts an RDKit molecule (rdkit.Chem.Mol) to a GraphData, with the features of PyG's from_rdmol.

Each atom has 9 categorical features, the indices in the lists of x_map of its atomic number, chirality, total degree, formal charge, total number of hydrogens, number of radical electrons, hybridization, aromaticity and ring membership. Each bond gives two directed edges, with 3 categorical features: the indices in the lists of e_map of its type, stereo configuration and conjugation. The edges are sorted by source then destination node, as in PyG.

Parameters:

Name Type Description Default
mol Any

The RDKit molecule.

required

Returns:

Type Description
GraphData

The graph, with node_features of shape [num_atoms, 9] and

GraphData

edge_features of shape [num_edges, 3] (both int32, PyG

GraphData

uses int64) and an int32 edge_index.

Source code in mlx_graphs/utils/smiles.py
def from_rdmol(mol: Any) -> "GraphData":
    r"""Converts an RDKit molecule (``rdkit.Chem.Mol``) to a
    :class:`~mlx_graphs.data.GraphData`, with the features of PyG's
    ``from_rdmol``.

    Each atom has 9 categorical features, the indices in the lists of
    :data:`x_map` of its atomic number, chirality, total degree, formal
    charge, total number of hydrogens, number of radical electrons,
    hybridization, aromaticity and ring membership. Each bond gives two
    directed edges, with 3 categorical features: the indices in the lists of
    :data:`e_map` of its type, stereo configuration and conjugation. The edges
    are sorted by source then destination node, as in PyG.

    Args:
        mol: The RDKit molecule.

    Returns:
        The graph, with ``node_features`` of shape ``[num_atoms, 9]`` and
        ``edge_features`` of shape ``[num_edges, 3]`` (both ``int32``, PyG
        uses ``int64``) and an ``int32`` ``edge_index``.
    """
    from mlx_graphs.data import GraphData

    arrays = _rdmol_arrays(mol)
    return GraphData(**{k: mx.array(v) for k, v in arrays.items()})

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