class_docstr: GraphData class
  
  This data class is almost same as `torch_geometric.data.Data
  <https://pytorch-geometric.readthedocs.io/en/latest/modules/data.html#torch_geometric.data.Data>`_.
  
  Attributes
  ----------
  node_features: np.ndarray
      Node feature matrix with shape [num_nodes, num_node_features]
  edge_index: np.ndarray, dtype int
      Graph connectivity in COO format with shape [2, num_edges]
  edge_features: np.ndarray, optional (default None)
      Edge feature matrix with shape [num_edges, num_edge_features]
  node_pos_features: np.ndarray, optional (default None)
      Node position matrix with shape [num_nodes, num_dimensions].
  num_nodes: int
      The number of nodes in the graph
  num_node_features: int
      The number of features per node in the graph
  num_edges: int
      The number of edges in the graph
  num_edges_features: int, optional (default None)
      The number of features per edge in the graph
  
  Examples
  --------
  >>> import numpy as np
  >>> node_features = np.random.rand(5, 10)
  >>> edge_index = np.array([[0, 1, 2, 3, 4], [1, 2, 3, 4, 0]], dtype=np.int64)
  >>> edge_features = np.random.rand(5, 5)
  >>> global_features = np.random.random(5)
  >>> graph = GraphData(node_features, edge_index, edge_features, z=global_features)
  >>> graph
  GraphData(node_features=[5, 10], edge_index=[2, 5], edge_features=[5, 5], z=[5])
class_docstr_tok: ["GraphData","class","This","data","class","is","almost","same","as","`","torch_geometric.data.Data","<","https",":","\/\/pytorch-geometric.readthedocs.io\/en\/latest\/modules\/data.html","#","torch_geometric.data.Data",">","`","_",".","Attributes","--","--","--","--","--","node_features",":","np.ndarray","Node","feature","matrix","with","shape","[","num_nodes",",","num_node_features","]","edge_index",":","np.ndarray",",","dtype","int","Graph","connectivity","in","COO","format","with","shape","[","2",",","num_edges","]","edge_features",":","np.ndarray",",","optional","(","default","None",")","Edge","feature","matrix","with","shape","[","num_edges",",","num_edge_features","]","node_pos_features",":","np.ndarray",",","optional","(","default","None",")","Node","position","matrix","with","shape","[","num_nodes",",","num_dimensions","]",".","num_nodes",":","int","The","number","of","nodes","in","the","graph","num_node_features",":","int","The","number","of","features","per","node","in","the","graph","num_edges",":","int","The","number","of","edges","in","the","graph","num_edges_features",":","int",",","optional","(","default","None",")","The","number","of","features","per","edge","in","the","graph","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","node_features","=","np.random.rand","(","5",",","10",")",">",">",">","edge_index","=","np.array","(","[","[","0",",","1",",","2",",","3",",","4","]",",","[","1",",","2",",","3",",","4",",","0","]","]",",","dtype=np.int64",")",">",">",">","edge_features","=","np.random.rand","(","5",",","5",")",">",">",">","global_features","=","np.random.random","(","5",")",">",">",">","graph","=","GraphData","(","node_features",",","edge_index",",","edge_features",",","z=global_features",")",">",">",">","graph","GraphData","(","node_features=","[","5",",","10","]",",","edge_index=","[","2",",","5","]",",","edge_features=","[","5",",","5","]",",","z=","[","5","]",")"]
docstr: Convert to DGL graph data instance
  
  Returns
  -------
  dgl.DGLGraph
      Graph data for DGL
  self_loop: bool
      Whether to add self loops for the nodes, i.e. edges from nodes
      to themselves. Default to False.
  
  Note
  ----
  This method requires DGL to be installed.
docstr_tok: ["Convert","to","DGL","graph","data","instance","Returns","--","--","--","-","dgl.DGLGraph","Graph","data","for","DGL","self_loop",":","bool","Whether","to","add","self","loops","for","the","nodes",",","i.e",".","edges","from","nodes","to","themselves",".","Default","to","False",".","Note","--","--","This","method","requires","DGL","to","be","installed","."]
code: def to_dgl_graph(self, self_loop: bool = False):
      """Convert to DGL graph data instance
  
      Returns
      -------
      dgl.DGLGraph
          Graph data for DGL
      self_loop: bool
          Whether to add self loops for the nodes, i.e. edges from nodes
          to themselves. Default to False.
  
      Note
      ----
      This method requires DGL to be installed.
      """
      try:
          import dgl
          import torch
      except ModuleNotFoundError:
          raise ImportError(
              "This function requires DGL to be installed."
          )
  
      src = self.edge_index[0]
      dst = self.edge_index[1]
  
      g = dgl.graph(
          (torch.from_numpy(src).long(), torch.from_numpy(dst).long()),
          num_nodes=self.num_nodes,
      )
      g.ndata["x"] = torch.from_numpy(self.node_features).float()
  
      if self.node_pos_features is not None:
          g.ndata["pos"] = torch.from_numpy(
              self.node_pos_features
          ).float()
          g.edata["d"] = (
              torch.norm(
                  g.ndata["pos"][g.edges()[0]]
                  - g.ndata["pos"][g.edges()[1]],
                  p=2,
                  dim=-1,
              )
              .unsqueeze(-1)
              .detach()
          )
      if self.edge_features is not None:
          g.edata["edge_attr"] = torch.from_numpy(
              self.edge_features
          ).float()
  
      if self_loop:
          # This assumes that the edge features for self loops are full-zero tensors
          # In the future we may want to support featurization for self loops
          g.add_edges(
              np.arange(self.num_nodes), np.arange(self.num_nodes)
          )
  
      return g
  
file_path: deepchem/deepchem/feat/graph_data.py
imports: from typing import Optional, Sequence
  import numpy
label_desc: Use image node_id 4 for calling the GraphData obj's underlying member method code with example usage: obj.to_dgl_graph(_loop) and returns: g