MCPcopy
hub / github.com/dmlc/dgl / __getitem__

Method __getitem__

python/dgl/data/qm9.py:180–219  ·  view source on GitHub ↗

r"""Get graph and label by index Parameters ---------- idx : int Item index Returns ------- dgl.DGLGraph The graph contains: - ``ndata['R']``: the coordinates of each atom - ``ndata['Z']``: the atomic

(self, idx)

Source from the content-addressed store, hash-verified

178 return self.label.shape[1]
179
180 def __getitem__(self, idx):
181 r"""Get graph and label by index
182
183 Parameters
184 ----------
185 idx : int
186 Item index
187
188 Returns
189 -------
190 dgl.DGLGraph
191 The graph contains:
192
193 - ``ndata['R']``: the coordinates of each atom
194 - ``ndata['Z']``: the atomic number
195
196 Tensor
197 Property values of molecular graphs
198 """
199 label = F.tensor(self.label[idx], dtype=F.data_type_dict["float32"])
200 n_atoms = self.N[idx]
201 R = self.R[self.N_cumsum[idx] : self.N_cumsum[idx + 1]]
202 dist = np.linalg.norm(R[:, None, :] - R[None, :, :], axis=-1)
203 adj = sp.csr_matrix(dist <= self.cutoff) - sp.eye(
204 n_atoms, dtype=np.bool_
205 )
206 adj = adj.tocoo()
207 u, v = F.tensor(adj.row), F.tensor(adj.col)
208 g = dgl_graph((u, v))
209 g = to_bidirected(g)
210 g.ndata["R"] = F.tensor(R, dtype=F.data_type_dict["float32"])
211 g.ndata["Z"] = F.tensor(
212 self.Z[self.N_cumsum[idx] : self.N_cumsum[idx + 1]],
213 dtype=F.data_type_dict["int64"],
214 )
215
216 if self._transform is not None:
217 g = self._transform(g)
218
219 return g, label
220
221 def __len__(self):
222 r"""Number of graphs in the dataset.

Callers

nothing calls this directly

Calls 1

to_bidirectedFunction · 0.50

Tested by

no test coverage detected