class_docstr: MatErials Graph Network for Molecules and Crystals
  
  MatErials Graph Network [1]_ are Graph Networks [2]_ which are used for property prediction
  in molecules and crystals. The model implements multiple layers of Graph Network as
  MEGNetBlocks and then combines the node properties and edge properties of all nodes
  and edges via a Set2Set layer. The combines information is used with the global
  features of the material/molecule for property prediction tasks.
  
  Example
  -------
  >>> import deepchem as dc
  >>> from deepchem.models import MEGNetModel
  >>> from deepchem.utils.fake_data_generator import FakeGraphGenerator as FGG
  >>> graphs = FGG(global_features=4, num_classes=10).sample(n_graphs=20)
  >>> model = dc.models.MEGNetModel(n_node_features=5, n_edge_features=3, n_global_features=4, n_blocks=3, is_undirected=True, residual_connection=True, mode='classification', n_classes=10, batch_size=16)
  >>> training_loss = model.fit(graphs)
  
  References
  ----------
  .. [1] Chen, Chi, et al. "Graph networks as a universal machine learning framework for molecules and crystals." Chemistry of Materials 31.9 (2019): 3564-3572.
  .. [2] Battaglia, Peter W., et al. "Relational inductive biases, deep learning, and graph networks." arXiv preprint arXiv:1806.01261 (2018).
  Note
  ----
  The model requires PyTorch-Geometric to be installed.
docstr: Parameters
  ----------
  n_node_features: int
      Number of features in a node
  n_edge_features: int
      Number of features in a edge
  n_global_features: int
      Number of global features
  n_blocks: int
      Number of GraphNetworks block to use in update
  is_undirected: bool, optional (default True)
      True when the model is used on undirected graphs otherwise false
  residual_connection: bool, optional (default True)
      If True, the layer uses a residual connection during training
  n_tasks: int, default 1
      The number of tasks
  mode: str, default 'regression'
      The model type - classification or regression
  n_classes: int, default 2
      The number of classes to predict (used only in classification mode).
  kwargs: Dict
      kwargs supported by TorchModel
docstr_tok: ["Parameters","--","--","--","--","--","n_node_features",":","int","Number","of","features","in","a","node","n_edge_features",":","int","Number","of","features","in","a","edge","n_global_features",":","int","Number","of","global","features","n_blocks",":","int","Number","of","GraphNetworks","block","to","use","in","update","is_undirected",":","bool",",","optional","(","default","True",")","True","when","the","model","is","used","on","undirected","graphs","otherwise","false","residual_connection",":","bool",",","optional","(","default","True",")","If","True",",","the","layer","uses","a","residual","connection","during","training","n_tasks",":","int",",","default","1","The","number","of","tasks","mode",":","str",",","default","'regression'","The","model","type","-","classification","or","regression","n_classes",":","int",",","default","2","The","number","of","classes","to","predict","(","used","only","in","classification","mode",")",".","kwargs",":","Dict","kwargs","supported","by","TorchModel"]
code: def __init__(
      self,
      n_node_features: int = 32,
      n_edge_features: int = 32,
      n_global_features: int = 32,
      n_blocks: int = 1,
      is_undirected: bool = True,
      residual_connection: bool = True,
      mode: str = "regression",
      n_classes: int = 2,
      n_tasks: int = 1,
      **kwargs,
  ):
      """
      Parameters
      ----------
      n_node_features: int
          Number of features in a node
      n_edge_features: int
          Number of features in a edge
      n_global_features: int
          Number of global features
      n_blocks: int
          Number of GraphNetworks block to use in update
      is_undirected: bool, optional (default True)
          True when the model is used on undirected graphs otherwise false
      residual_connection: bool, optional (default True)
          If True, the layer uses a residual connection during training
      n_tasks: int, default 1
          The number of tasks
      mode: str, default 'regression'
          The model type - classification or regression
      n_classes: int, default 2
          The number of classes to predict (used only in classification mode).
      kwargs: Dict
          kwargs supported by TorchModel
      """
      model = MEGNet(
          n_node_features=n_node_features,
          n_edge_features=n_edge_features,
          n_global_features=n_global_features,
          n_blocks=n_blocks,
          is_undirected=is_undirected,
          residual_connection=residual_connection,
          mode=mode,
          n_classes=n_classes,
          n_tasks=n_tasks,
      )
      if mode == "regression":
          loss: Loss = L2Loss()
          output_types = ["prediction"]
      elif mode == "classification":
          loss = SparseSoftmaxCrossEntropy()
          output_types = ["prediction", "loss"]
      super(MEGNetModel, self).__init__(
          model, loss=loss, output_types=output_types, **kwargs
      )
  
file_path: deepchem/deepchem/models/torch_models/megnet.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  from deepchem.models.losses import Loss, L2Loss, SparseSoftmaxCrossEntropy
  from deepchem.models.torch_models.layers import GraphNetwork
  from deepchem.models.torch_models import TorchModel
label_desc: Use image node_id 1 to create a new MEGNetModel object from inherited base classes: TorchModel with example: obj = MEGNetModel(n_node_features, n_edge_features, n_global_features, n_blocks, is_undirected, residual_connection, mode, n_classes, n_tasks)