liveBook · Manning

PyTorch Geometric

As explained in Build AI Drug Discovery Pipelines

PyTorch Geometric is an open-source extension library for PyTorch that provides data structures and operators for geometric deep learning on graphs and related domains.

PyTorch Geometric is a PyTorch extension for representing molecules and proteins as graphs and training geometric deep-learning models for drug-target affinity. It supplies graph data structures and efficient batching for inputs whose node and edge counts vary. section 11.5.5 section 11.8

A typical graph-data workflow uses:

  • Data objects store node features in x, sparse COO connectivity in edge_index, and optional targets such as affinity values. section 11.5.5
  • A custom Dataset retrieves each drug-protein pair and its ground-truth affinity for training or evaluation. section 11.5.5
  • The DataLoader combines variable-sized graphs into one disconnected graph, concatenates features and edges, and uses a batch vector to recover graph membership. section 11.5.5
  • Separate graph-processing streams respect the different structures and scales of molecules and proteins before their representations are fused. section 11.8
from torch_geometric.data import Data
GCNData_mol = Data(
    x=torch.Tensor(features),
    edge_index=torch.LongTensor(edge_index).transpose(1, 0),
    y=torch.FloatTensor([affinity_value])
)

Use the listing to construct a molecular Data object from node features, COO edge indices, and an affinity target. section 11.5.5

from torch_geometric.data import Batch
def collate(data_list):
    batchA = Batch.from_data_list([data[-1] for data in data_list])
    batchB = Batch.from_data_list([data[0] for data in data_list])
    return batchA, batchB

Use the batching helper to combine separate molecule and protein graph collections into GPU-ready Batch objects. section 11.5.5

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Explains Data objects, COO edges, custom datasets, disconnected-graph batching, and dual-stream processing, without detailing library internals.
Examples
Uses molecular and protein Data objects, atom and residue features, paired graph batches, and affinity targets.
What it assumes
Assumes graph representations and PyTorch tensor handling while teaching graph-specific storage and batching.
What you can do after
Apply it via PyTorch Geometric to construct, collate, and process variable-sized molecular and protein graphs.
How it connects
Connects graph neural networks, message passing, GCN, GAT, GIN, drug-target affinity, and PyTorch DataLoader workflows.

Also explained in

Compare how 3 books explain PyTorch Geometric →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI Drug Discovery Pipelines. The section links point to the parts of the book it draws on.