Skip to content

QM9

QM9(
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
)

Bases: PackedGraphsMixin, Dataset

The QM9 dataset from the "MoleculeNet: A Benchmark for Molecular Machine Learning" paper, consisting of about 130,000 small organic molecules (up to 9 heavy atoms among C, O, N and F) with 19 regression targets.

Each molecule includes the 3D coordinates of the atoms of its low-energy conformation, and the atom features of the "Neural Message Passing for Quantum Chemistry" paper. Each graph has:

  • node_features: float32 [num_atoms, 11], the one-hot atom type (H, C, N, O, F), atomic number, aromaticity, sp / sp2 / sp3 hybridization and number of hydrogens;
  • z: int32 [num_atoms], the atomic numbers;
  • pos: float32 [num_atoms, 3], the coordinates (in Å);
  • edge_index and edge_features (float32 [num_edges, 4], the one-hot bond type: single, double, triple, aromatic);
  • graph_labels: float32 [1, 19], the targets below;
  • name (e.g. "gdb_1"), idx (index in the raw data) and, when processed with RDKit, smiles.
Target Property Description Unit
0 \(\mu\) Dipole moment D
1 \(\alpha\) Isotropic polarizability \({a_0}^3\)
2 \(\epsilon_{\textrm{HOMO}}\) Highest occupied molecular orbital energy eV
3 \(\epsilon_{\textrm{LUMO}}\) Lowest unoccupied molecular orbital energy eV
4 \(\Delta \epsilon\) Gap between HOMO and LUMO eV
5 \(\langle R^2 \rangle\) Electronic spatial extent \({a_0}^2\)
6 ZPVE Zero point vibrational energy eV
7 \(U_0\) Internal energy at 0K eV
8 \(U\) Internal energy at 298.15K eV
9 \(H\) Enthalpy at 298.15K eV
10 \(G\) Free energy at 298.15K eV
11 \(c_{\textrm{v}}\) Heat capacity at 298.15K cal/(mol K)
12 \(U_0^{\textrm{ATOM}}\) Atomization energy at 0K eV
13 \(U^{\textrm{ATOM}}\) Atomization energy at 298.15K eV
14 \(H^{\textrm{ATOM}}\) Atomization enthalpy at 298.15K eV
15 \(G^{\textrm{ATOM}}\) Atomization free energy at 298.15K eV
16 \(A\) Rotational constant GHz
17 \(B\) Rotational constant GHz
18 \(C\) Rotational constant GHz

This dataset follows the implementation of PyG: if rdkit is installed, the raw SDF files are processed (as PyG does with RDKit), otherwise PyG's pre-processed version of the dataset is read (without PyTorch). Both give the same graphs, except for the smiles attribute that is only available with RDKit.

#graphs #nodes (avg) #edges (avg) #features #tasks Download
130,831 ~18.0 ~37.3 11 19 45 MB (raw) / 57 MB (pre-processed)

Parameters:

Name Type Description Default
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 QM9

dataset = QM9()
>>> QM9(num_graphs=130831)

dataset[0]
>>> GraphData(
        edge_index(shape=(2, 8), int32)
        node_features(shape=(5, 11), float32)
        edge_features(shape=(8, 4), float32)
        graph_labels(shape=(1, 19), float32)
        z(shape=(5,), int32)
        pos(shape=(5, 3), float32)
        smiles=[H]C([H])([H])[H]
        name=gdb_1
        idx=0)

# target 7 (U0), e.g. for SchNet
z, pos, y = dataset[0].z, dataset[0].pos, dataset[0].graph_labels[:, 7]

Methods:

Name Description
mean

The mean of the target target over the dataset.

std

The (unbiased) standard deviation of the target target over the

atomref

The reference single-atom properties for the target target

Source code in mlx_graphs/datasets/qm9.py
def __init__(
    self,
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
):
    super().__init__(
        name="QM9",
        base_dir=base_dir,
        pre_transform=pre_transform,
        transform=transform,
    )

mean

mean(target: int) -> float

The mean of the target target over the dataset.

Source code in mlx_graphs/datasets/qm9.py
def mean(self, target: int) -> float:
    """The mean of the target ``target`` over the dataset."""
    return float(self._labels(target).mean())

std

std(target: int) -> float

The (unbiased) standard deviation of the target target over the dataset.

Source code in mlx_graphs/datasets/qm9.py
def std(self, target: int) -> float:
    """The (unbiased) standard deviation of the target ``target`` over the
    dataset."""
    return float(self._labels(target).std(ddof=1))

atomref

atomref(target: int) -> Optional[array]

The reference single-atom properties for the target target (indexed by atomic number), of shape [100, 1], or None if the target has none (only targets 6 to 11 have one). Used as the atomref of SchNet.

Source code in mlx_graphs/datasets/qm9.py
def atomref(self, target: int) -> Optional[mx.array]:
    """The reference single-atom properties for the target ``target``
    (indexed by atomic number), of shape ``[100, 1]``, or ``None`` if the
    target has none (only targets 6 to 11 have one). Used as the
    ``atomref`` of :class:`~mlx_graphs.nn.SchNet`."""
    if target not in _ATOMREFS:
        return None
    out = np.zeros(100, dtype=np.float32)
    out[[1, 6, 7, 8, 9]] = _ATOMREFS[target]
    return mx.array(out.reshape(-1, 1))

from mlx_graphs.datasets import QM9 · mlx_graphs/datasets/qm9.py