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)
| 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. |
nothing calls this directly
no test coverage detected