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: Returns a subgraph of `nodes` indicies.
  
  Parameters
  ----------
  nodes : list, iterable
      A list of node indices to be included in the subgraph.
  
  Returns
  -------
  subgraph_data : GraphData
      A new GraphData object containing the subgraph induced on `nodes`.
  
  Example
  -------
  >>> import numpy as np
  >>> from deepchem.feat.graph_data import GraphData
  >>> 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, 3)
  >>> graph_data = GraphData(node_features, edge_index, edge_features)
  >>> nodes = [0, 2, 4]
  >>> subgraph_data, node_mapping = graph_data.subgraph(nodes)
docstr_tok: ["Returns","a","subgraph","of","`","nodes","`","indicies",".","Parameters","--","--","--","--","--","nodes",":","list",",","iterable","A","list","of","node","indices","to","be","included","in","the","subgraph",".","Returns","--","--","--","-","subgraph_data",":","GraphData","A","new","GraphData","object","containing","the","subgraph","induced","on","`","nodes","`",".","Example","--","--","--","-",">",">",">","import","numpy","as","np",">",">",">","from","deepchem.feat.graph_data","import","GraphData",">",">",">","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",",","3",")",">",">",">","graph_data","=","GraphData","(","node_features",",","edge_index",",","edge_features",")",">",">",">","nodes","=","[","0",",","2",",","4","]",">",">",">","subgraph_data",",","node_mapping","=","graph_data.subgraph","(","nodes",")"]
code: def subgraph(self, nodes):
      """Returns a subgraph of `nodes` indicies.
  
      Parameters
      ----------
      nodes : list, iterable
          A list of node indices to be included in the subgraph.
  
      Returns
      -------
      subgraph_data : GraphData
          A new GraphData object containing the subgraph induced on `nodes`.
  
      Example
      -------
      >>> import numpy as np
      >>> from deepchem.feat.graph_data import GraphData
      >>> 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, 3)
      >>> graph_data = GraphData(node_features, edge_index, edge_features)
      >>> nodes = [0, 2, 4]
      >>> subgraph_data, node_mapping = graph_data.subgraph(nodes)
      """
      nodes = set(nodes)
      if not nodes.issubset(range(self.num_nodes)):
          raise ValueError("Some nodes are not in the original graph")
  
      # Create a mapping from the original node indices to the new node indices
      node_mapping = {
          old_idx: new_idx for new_idx, old_idx in enumerate(nodes)
      }
  
      # Filter and reindex node features
      subgraph_node_features = self.node_features[list(nodes)]
  
      # Filter and reindex edge indices and edge features
      subgraph_edge_indices = []
      subgraph_edge_features = []
      if self.edge_features is not None:
          for i in range(self.num_edges):
              src, dest = self.edge_index[:, i]
              if src in nodes and dest in nodes:
                  subgraph_edge_indices.append(
                      (node_mapping[src], node_mapping[dest])
                  )
                  subgraph_edge_features.append(self.edge_features[i])
  
      subgraph_edge_index = np.array(
          subgraph_edge_indices, dtype=np.int64
      ).T
      subgraph_edge_features = np.array(subgraph_edge_features)
  
      subgraph_data = GraphData(
          node_features=subgraph_node_features,
          edge_index=subgraph_edge_index,
          edge_features=subgraph_edge_features,
          **self.kwargs,
      )
  
      return subgraph_data, node_mapping
  
file_path: deepchem/deepchem/feat/graph_data.py
imports: from typing import Optional, Sequence
  import numpy
label_desc: Use image node_id 6 for calling the GraphData obj's underlying member method code with example usage: obj.subgraph(nodes) and returns: subgraph_data,  node_mapping