liveBook · Manning

PyTorch Geometric Data

As explained in Build AI Drug Discovery Pipelines

A PyTorch Geometric Data object is a container for graph node features, connectivity indices, labels, and optional graph attributes.

A PyTorch Geometric Data object represents one graph in a drug–target affinity pipeline. It keeps node features, connectivity, and an affinity label together so a graph neural network can consume molecular or protein data. section 11.5.5

A typical molecular graph stores:

  • x: a tensor of node or atom features. section 11.5.5
  • edge_index: integer connectivity indices, transposed into PyTorch Geometric’s expected layout. section 11.5.5
  • y: a tensor containing the measured affinity label. section 11.5.5
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])
)

Constructs a graph object from node features, edge indices, and one drug–target affinity value. 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

Uses Batch.from_data_list to combine variable-sized molecule and protein graphs into mini-batches. section 11.5.5

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Defines core fields and batching needs, but stops short of graph neural network architecture details.
Examples
Uses atom features, edge indices, affinity labels, and paired molecule–protein graphs with different sizes.
What it assumes
Assumes tensor-based features and labels while demonstrating graph-specific storage for variable-sized inputs.
What you can do after
Operate/configure graph samples and mini-batches for affinity-model training.
How it connects
Connects graph representation with molecular graphs, protein graphs, DataLoader batching, and graph neural networks.

Also explained in

Compare how 2 books explain PyTorch Geometric Data →

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.