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, batchBUse the batching helper to combine separate molecule and protein graph collections into GPU-ready Batch objects. section 11.5.5


