Skip to content

ZINC

ZINC(
    subset: bool = False,
    split: ZINC_SPLITS = "train",
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
)

Bases: PackedGraphsMixin, Dataset

The ZINC dataset from the ZINC database and the "Automatic Chemical Design Using a Data-Driven Continuous Representation of Molecules" paper, containing about 250,000 molecular graphs with up to 38 heavy atoms.

The task is to regress the penalized logP (also called constrained solubility), given by y = logP - SAS - cycles, where logP is the water-octanol partition coefficient, SAS the synthetic accessibility score and cycles the number of cycles with more than six atoms.

Each graph has int32 node_features of shape [num_atoms, 1] (the atom type, 28 types), int32 edge_features of shape [num_edges] (the bond type: 1 single, 2 double, 3 triple) and a float32 graph_labels of shape [1].

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).

Name #graphs #nodes (avg) #edges (avg) #features Download
ZINC Full 249,456 ~23.2 ~49.8 1 384 MB
ZINC Subset 12,000 ~23.2 ~49.8 1 384 MB

The full dataset has 220,011 / 24,445 / 5,000 and the subset 10,000 / 1,000 / 1,000 train / val / test graphs.

Parameters:

Name Type Description Default
subset bool

If True, loads the subset of 12,000 graphs of the "Benchmarking Graph Neural Networks" paper. Default: False

False
split ZINC_SPLITS

The split to load, "train", "val" or "test". Default: "train"

'train'
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

Example:

from mlx_graphs.datasets import ZINC

dataset = ZINC(subset=True, split="train")
>>> ZINC(num_graphs=10000)

dataset[0]
>>> GraphData(
        edge_index(shape=(2, 64), int32)
        node_features(shape=(29, 1), int32)
        edge_features(shape=(64,), int32)
        graph_labels(shape=(1,), float32))
Source code in mlx_graphs/datasets/zinc.py
def __init__(
    self,
    subset: bool = False,
    split: ZINC_SPLITS = "train",
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
):
    if split not in ("train", "val", "test"):
        raise ValueError(
            f"Split '{split}' found, but expected 'train', 'val' or 'test'"
        )
    self.subset = subset
    self.split = split
    super().__init__(
        name="ZINC",
        base_dir=base_dir,
        pre_transform=pre_transform,
        transform=transform,
    )

from mlx_graphs.datasets import ZINC · mlx_graphs/datasets/zinc.py