Batch.from_data_list combines variable-sized graph Data objects into one disconnected graph for efficient neural-network processing. Instead of padding molecules or proteins to a common size, it concatenates their nodes and adjusts edge indices. section 11.5.5
The resulting batch preserves graph membership through:
- Stacked node features: three graphs with 10, 15, and 12 atoms produce 37 nodes. section 11.5.5
- Adjusted edge indices that reference nodes in the combined graph. section 11.5.5
- A batch vector labeling every node with its original graph, enabling separate graph-level pooling. 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 Batch.from_data_list in a collate function to batch molecular and protein graphs separately before affinity prediction. section 11.5.5
