Skip to content

MoleculeNet

MoleculeNet(
    name: str,
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
    from_smiles: Optional[Callable[[str], GraphData]] = None,
)

Bases: PackedGraphsMixin, Dataset

The MoleculeNet benchmark collection from the "MoleculeNet: A Benchmark for Molecular Machine Learning" paper, containing datasets of physical chemistry, biophysics and physiology.

The molecules are given as SMILES strings and converted to graphs with from_smiles() (which requires rdkit): each graph has int32 node_features of shape [num_atoms, 9] and edge_features of shape [num_edges, 3] (categorical atom and bond features, see x_map and e_map), the SMILES string in smiles and the float32 targets in graph_labels, of shape [1, num_tasks], with NaN for missing labels (classification targets are 0.0 / 1.0).

This dataset follows the implementation of PyG and reads the same raw files, without requiring PyTorch. The graphs are the same, in the same order (with int32 instead of int64 indices and features). Molecules without atoms (e.g. SMILES strings that RDKit cannot parse) are skipped, with a warning, so the number of graphs depends slightly on the RDKit version (e.g. 2,039 graphs for BBBP, 7,823 for Tox21 and 41,120 for HIV with RDKit 2026.9, as in PyG).

Name #graphs #nodes (avg) #edges (avg) #features #tasks
ESOL 1,128 ~13.3 ~27.4 9 1
FreeSolv 642 ~8.7 ~16.8 9 1
Lipophilicity 4,200 ~27.0 ~59.0 9 1
PCBA 437,929 ~26.0 ~56.2 9 128
MUV 93,087 ~24.2 ~52.6 9 17
HIV 41,127 ~25.5 ~54.9 9 1
BACE 1,513 ~34.1 ~73.7 9 1
BBBP 2,050 ~23.9 ~51.6 9 1
Tox21 7,831 ~18.6 ~38.6 9 12
ToxCast 8,597 ~18.7 ~38.4 9 617
SIDER 1,427 ~33.6 ~70.7 9 27
ClinTox 1,484 ~26.1 ~55.5 9 2

Parameters:

Name Type Description Default
name str

The name of the dataset (case insensitive): "ESOL", "FreeSolv", "Lipo", "PCBA", "MUV", "HIV", "BACE", "BBBP", "Tox21", "ToxCast", "SIDER" or "ClinTox".

required
base_dir Optional[str]

Directory where to store dataset files. Default is in the local directory .mlx_graphs_data/.

None
pre_transform Optional[Callable]

A function/transform applied to each graph once, before it is saved.

None
transform Optional[Callable]

A function/transform applied to each graph at every access.

None
from_smiles Optional[Callable[[str], GraphData]]

A function converting a SMILES string to a GraphData, to use another featurization. Default: from_smiles().

None

Example:

from mlx_graphs.datasets import MoleculeNet

dataset = MoleculeNet("ESOL")
>>> ESOL(num_graphs=1128)

dataset[0]
>>> GraphData(
        edge_index(shape=(2, 68), int32)
        node_features(shape=(32, 9), int32)
        edge_features(shape=(68, 3), int32)
        graph_labels(shape=(1, 1), float32)
        smiles=OCC3OC(OCC2OC(OC(C#N)c1ccccc1)C(O)C(O)C2O)C(O)C(O)C3O )

Attributes:

Name Type Description
display_name str

The name of the dataset as in the MoleculeNet paper, e.g.

Source code in mlx_graphs/datasets/molecule_net.py
def __init__(
    self,
    name: str,
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
    from_smiles: Optional[Callable[[str], GraphData]] = None,
):
    key = name.lower()
    if key not in self.names:
        raise ValueError(
            f"Unknown MoleculeNet dataset '{name}' "
            f"(available: {[v[0] for v in self.names.values()]})"
        )
    self.from_smiles = from_smiles
    super().__init__(
        name=key,
        base_dir=base_dir,
        pre_transform=pre_transform,
        transform=transform,
    )

display_name property

display_name: str

The name of the dataset as in the MoleculeNet paper, e.g. "ESOL".

from mlx_graphs.datasets import MoleculeNet · mlx_graphs/datasets/molecule_net.py