class_docstr: Crystal Graph Convolutional Neural Network (CGCNN).
  
  This model takes arbitary crystal structures as an input, and predict material properties
  using the element information and connection of atoms in the crystal. If you want to get
  some material properties which has a high computational cost like band gap in the case
  of DFT, this model may be useful. This model is one of variants of Graph Convolutional
  Networks. The main differences between other GCN models are how to construct graphs and
  how to update node representations. This model defines the crystal graph from structures
  using distances between atoms. The crystal graph is an undirected multigraph which is defined
  by nodes representing atom properties and edges representing connections between atoms
  in a crystal. And, this model updates the node representations using both neighbor node
  and edge representations. Please confirm the detail algorithms from [1]_.
  
  Examples
  --------
  >>> import deepchem as dc
  >>> from pymatgen.core import Lattice, Structure
  >>> lattice = Lattice.cubic(4.2)
  >>> structure = Structure(lattice, ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]])
  >>> featurizer = dc.feat.CGCNNFeaturizer()
  >>> cgcnn_feat = featurizer.featurize([structure])[0]
  >>> print(type(cgcnn_feat))
  <class 'deepchem.feat.graph_data.GraphData'>
  >>> cgcnn_dgl_feat = cgcnn_feat.to_dgl_graph()
  >>> print(type(cgcnn_dgl_feat))
  <class 'dgl.heterograph.DGLGraph'>
  >>> model = dc.models.CGCNN(mode='regression', n_tasks=2)
  >>> out = model(cgcnn_dgl_feat)
  >>> print(type(out))
  <class 'torch.Tensor'>
  >>> out.shape == (1, 2)
  True
  
  References
  ----------
  .. [1] Xie, Tian, and Jeffrey C. Grossman. "Crystal graph convolutional neural networks
      for an accurate and interpretable prediction of material properties." Physical review letters
      120.14 (2018): 145301.
  
  Notes
  -----
  This class requires DGL and PyTorch to be installed.
class_docstr_tok: ["Crystal","Graph","Convolutional","Neural","Network","(","CGCNN",")",".","This","model","takes","arbitary","crystal","structures","as","an","input",",","and","predict","material","properties","using","the","element","information","and","connection","of","atoms","in","the","crystal",".","If","you","want","to","get","some","material","properties","which","has","a","high","computational","cost","like","band","gap","in","the","case","of","DFT",",","this","model","may","be","useful",".","This","model","is","one","of","variants","of","Graph","Convolutional","Networks",".","The","main","differences","between","other","GCN","models","are","how","to","construct","graphs","and","how","to","update","node","representations",".","This","model","defines","the","crystal","graph","from","structures","using","distances","between","atoms",".","The","crystal","graph","is","an","undirected","multigraph","which","is","defined","by","nodes","representing","atom","properties","and","edges","representing","connections","between","atoms","in","a","crystal",".","And",",","this","model","updates","the","node","representations","using","both","neighbor","node","and","edge","representations",".","Please","confirm","the","detail","algorithms","from","[","1","]","_",".","Examples","--","--","--","--",">",">",">","import","deepchem","as","dc",">",">",">","from","pymatgen.core","import","Lattice",",","Structure",">",">",">","lattice","=","Lattice.cubic","(","4.2",")",">",">",">","structure","=","Structure","(","lattice",",","[","``","Cs","''",",","``","Cl","''","]",",","[","[","0",",","0",",","0","]",",","[","0.5",",","0.5",",","0.5","]","]",")",">",">",">","featurizer","=","dc.feat.CGCNNFeaturizer","(",")",">",">",">","cgcnn_feat","=","featurizer.featurize","(","[","structure","]",")","[","0","]",">",">",">","print","(","type","(","cgcnn_feat",")",")","<","class","'deepchem.feat.graph_data.GraphData","'",">",">",">",">","cgcnn_dgl_feat","=","cgcnn_feat.to_dgl_graph","(",")",">",">",">","print","(","type","(","cgcnn_dgl_feat",")",")","<","class","'dgl.heterograph.DGLGraph","'",">",">",">",">","model","=","dc.models.CGCNN","(","mode='regression","'",",","n_tasks=2",")",">",">",">","out","=","model","(","cgcnn_dgl_feat",")",">",">",">","print","(","type","(","out",")",")","<","class","'torch.Tensor","'",">",">",">",">","out.shape","==","(","1",",","2",")","True","References","--","--","--","--","--","..","[","1","]","Xie",",","Tian",",","and","Jeffrey","C.","Grossman",".","``","Crystal","graph","convolutional","neural","networks","for","an","accurate","and","interpretable","prediction","of","material","properties",".","''","Physical","review","letters","120.14","(","2018",")",":","145301",".","Notes","--","--","-","This","class","requires","DGL","and","PyTorch","to","be","installed","."]
docstr: Parameters
  ----------
  in_node_dim: int, default 92
      The length of the initial node feature vectors. The 92 is
      based on length of vectors in the atom_init.json.
  hidden_node_dim: int, default 64
      The length of the hidden node feature vectors.
  in_edge_dim: int, default 41
      The length of the initial edge feature vectors. The 41 is
      based on default setting of CGCNNFeaturizer.
  num_conv: int, default 3
      The number of convolutional layers.
  predictor_hidden_feats: int, default 128
      The size for hidden representations in the output MLP predictor.
  n_tasks: int, default 1
      The number of the output size.
  mode: str, default 'regression'
      The model type, 'classification' or 'regression'.
  n_classes: int, default 2
      The number of classes to predict (only used in classification mode).
docstr_tok: ["Parameters","--","--","--","--","--","in_node_dim",":","int",",","default","92","The","length","of","the","initial","node","feature","vectors",".","The","92","is","based","on","length","of","vectors","in","the","atom_init.json",".","hidden_node_dim",":","int",",","default","64","The","length","of","the","hidden","node","feature","vectors",".","in_edge_dim",":","int",",","default","41","The","length","of","the","initial","edge","feature","vectors",".","The","41","is","based","on","default","setting","of","CGCNNFeaturizer",".","num_conv",":","int",",","default","3","The","number","of","convolutional","layers",".","predictor_hidden_feats",":","int",",","default","128","The","size","for","hidden","representations","in","the","output","MLP","predictor",".","n_tasks",":","int",",","default","1","The","number","of","the","output","size",".","mode",":","str",",","default","'regression'","The","model","type",",","'classification","'","or","'regression","'",".","n_classes",":","int",",","default","2","The","number","of","classes","to","predict","(","only","used","in","classification","mode",")","."]
code: def __init__(
      self,
      in_node_dim: int = 92,
      hidden_node_dim: int = 64,
      in_edge_dim: int = 41,
      num_conv: int = 3,
      predictor_hidden_feats: int = 128,
      n_tasks: int = 1,
      mode: str = "regression",
      n_classes: int = 2,
  ):
      """
      Parameters
      ----------
      in_node_dim: int, default 92
          The length of the initial node feature vectors. The 92 is
          based on length of vectors in the atom_init.json.
      hidden_node_dim: int, default 64
          The length of the hidden node feature vectors.
      in_edge_dim: int, default 41
          The length of the initial edge feature vectors. The 41 is
          based on default setting of CGCNNFeaturizer.
      num_conv: int, default 3
          The number of convolutional layers.
      predictor_hidden_feats: int, default 128
          The size for hidden representations in the output MLP predictor.
      n_tasks: int, default 1
          The number of the output size.
      mode: str, default 'regression'
          The model type, 'classification' or 'regression'.
      n_classes: int, default 2
          The number of classes to predict (only used in classification mode).
      """
      try:
          import dgl
      except:
          raise ImportError("This class requires DGL to be installed.")
      super(CGCNN, self).__init__()
      if mode not in ["classification", "regression"]:
          raise ValueError(
              "mode must be either 'classification' or 'regression'"
          )
  
      self.n_tasks = n_tasks
      self.mode = mode
      self.n_classes = n_classes
      self.embedding = nn.Linear(in_node_dim, hidden_node_dim)
      self.conv_layers = nn.ModuleList(
          [
              CGCNNLayer(
                  hidden_node_dim=hidden_node_dim,
                  edge_dim=in_edge_dim,
                  batch_norm=True,
              )
              for _ in range(num_conv)
          ]
      )
      self.pooling = dgl.mean_nodes
      self.fc = nn.Linear(hidden_node_dim, predictor_hidden_feats)
      if self.mode == "regression":
          self.out = nn.Linear(predictor_hidden_feats, n_tasks)
      else:
          self.out = nn.Linear(
              predictor_hidden_feats, n_tasks * n_classes
          )
  
file_path: deepchem/deepchem/models/torch_models/cgcnn.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  from deepchem.models.losses import Loss, L2Loss, SparseSoftmaxCrossEntropy
  from deepchem.models.torch_models.torch_model import TorchModel
label_desc: Use image node_id 1 to create a new CGCNN object from inherited base classes: nn with example: obj = CGCNN(in_node_dim, hidden_node_dim, in_edge_dim, num_conv, predictor_hidden_feats, n_tasks, mode, n_classes)