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, batchBUses Batch.from_data_list to combine variable-sized molecule and protein graphs into mini-batches. section 11.5.5

