class_docstr: Directed Message Passing Neural Network
  
  This class implements the Directed Message Passing Neural Network (D-MPNN) [1]_.
  
  The DMPNN model has 2 phases, message-passing phase and read-out phase.
  
  - The goal of the message-passing phase is to generate 'hidden states of all the atoms in the molecule' using encoders.
  - Next in read-out phase, the features are passed into feed-forward neural network to get the task-based prediction.
  
  For additional information:
  
  - `Mapper class <https://github.com/deepchem/deepchem/blob/31676cc2497d5f2de65d648c09fc86191b594501/deepchem/models/torch_models/dmpnn.py#L10-L92>`_
  - `Encoder layer class <https://github.com/deepchem/deepchem/blob/31676cc2497d5f2de65d648c09fc86191b594501/deepchem/models/torch_models/layers.py#L1223-L1374>`_
  - `Feed-Forward class <https://github.com/deepchem/deepchem/blob/31676cc2497d5f2de65d648c09fc86191b594501/deepchem/models/torch_models/layers.py#L689-L700>`_
  
  Example
  -------
  >>> import deepchem as dc
  >>> import os
  >>> model_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  >>> input_file = os.path.join(model_dir, 'tests/assets/freesolv_sample_5.csv')
  >>> loader = dc.data.CSVLoader(tasks=['y'], feature_field='smiles', featurizer=dc.feat.DMPNNFeaturizer())
  >>> dataset = loader.create_dataset(input_file)
  >>> model = DMPNNModel()
  >>> out = model.fit(dataset, nb_epoch=1)
  
  References
  ----------
  .. [1] Analyzing Learned Molecular Representations for Property Prediction https://arxiv.org/pdf/1904.01561.pdf
class_docstr_tok: ["Directed","Message","Passing","Neural","Network","This","class","implements","the","Directed","Message","Passing","Neural","Network","(","D-MPNN",")","[","1","]","_",".","The","DMPNN","model","has","2","phases",",","message-passing","phase","and","read-out","phase",".","-","The","goal","of","the","message-passing","phase","is","to","generate","'hidden","states","of","all","the","atoms","in","the","molecule","'","using","encoders",".","-","Next","in","read-out","phase",",","the","features","are","passed","into","feed-forward","neural","network","to","get","the","task-based","prediction",".","For","additional","information",":","-","`","Mapper","class","<","https",":","\/\/github.com\/deepchem\/deepchem\/blob\/31676cc2497d5f2de65d648c09fc86191b594501\/deepchem\/models\/torch_models\/dmpnn.py","#","L10-L92",">","`","_","-","`","Encoder","layer","class","<","https",":","\/\/github.com\/deepchem\/deepchem\/blob\/31676cc2497d5f2de65d648c09fc86191b594501\/deepchem\/models\/torch_models\/layers.py","#","L1223-L1374",">","`","_","-","`","Feed-Forward","class","<","https",":","\/\/github.com\/deepchem\/deepchem\/blob\/31676cc2497d5f2de65d648c09fc86191b594501\/deepchem\/models\/torch_models\/layers.py","#","L689-L700",">","`","_","Example","--","--","--","-",">",">",">","import","deepchem","as","dc",">",">",">","import","os",">",">",">","model_dir","=","os.path.dirname","(","os.path.dirname","(","os.path.abspath","(","__file__",")",")",")",">",">",">","input_file","=","os.path.join","(","model_dir",",","'tests\/assets\/freesolv_sample_5.csv","'",")",">",">",">","loader","=","dc.data.CSVLoader","(","tasks=","[","'","y","'","]",",","feature_field='smiles","'",",","featurizer=dc.feat.DMPNNFeaturizer","(",")",")",">",">",">","dataset","=","loader.create_dataset","(","input_file",")",">",">",">","model","=","DMPNNModel","(",")",">",">",">","out","=","model.fit","(","dataset",",","nb_epoch=1",")","References","--","--","--","--","--","..","[","1","]","Analyzing","Learned","Molecular","Representations","for","Property","Prediction","https",":","\/\/arxiv.org\/pdf\/1904.01561.pdf"]
docstr: Initialize the DMPNNModel class.
  
  Parameters
  ----------
  mode: str, default 'regression'
      The model type - classification or regression.
  n_classes: int, default 3
      The number of classes to predict (used only in classification mode).
  n_tasks: int, default 1
      The number of tasks.
  batch_size: int, default 1
      The number of datapoints in a batch.
  global_features_size: int, default 0
      Size of the global features vector, based on the global featurizers used during featurization.
  use_default_fdim: bool
      If `True`, self.atom_fdim and self.bond_fdim are initialized using values from the GraphConvConstants class.
      If `False`, self.atom_fdim and self.bond_fdim are initialized from the values provided.
  atom_fdim: int
      Dimension of atom feature vector.
  bond_fdim: int
      Dimension of bond feature vector.
  enc_hidden: int
      Size of hidden layer in the encoder layer.
  depth: int
      No of message passing steps.
  bias: bool
      If `True`, dense layers will use bias vectors.
  enc_activation: str
      Activation function to be used in the encoder layer.
      Can choose between 'relu' for ReLU, 'leakyrelu' for LeakyReLU, 'prelu' for PReLU,
      'tanh' for TanH, 'selu' for SELU, and 'elu' for ELU.
  enc_dropout_p: float
      Dropout probability for the encoder layer.
  aggregation: str
      Aggregation type to be used in the encoder layer.
      Can choose between 'mean', 'sum', and 'norm'.
  aggregation_norm: Union[int, float]
      Value required if `aggregation` type is 'norm'.
  ffn_hidden: int
      Size of hidden layer in the feed-forward network layer.
  ffn_activation: str
      Activation function to be used in feed-forward network layer.
      Can choose between 'relu' for ReLU, 'leakyrelu' for LeakyReLU, 'prelu' for PReLU,
      'tanh' for TanH, 'selu' for SELU, and 'elu' for ELU.
  ffn_layers: int
      Number of layers in the feed-forward network layer.
  ffn_dropout_p: float
      Dropout probability for the feed-forward network layer.
  ffn_dropout_at_input_no_act: bool
      If true, dropout is applied on the input tensor. For single layer, it is not passed to an activation function.
  kwargs: Dict
      kwargs supported by TorchModel
docstr_tok: ["Initialize","the","DMPNNModel","class",".","Parameters","--","--","--","--","--","mode",":","str",",","default","'regression'","The","model","type","-","classification","or","regression",".","n_classes",":","int",",","default","3","The","number","of","classes","to","predict","(","used","only","in","classification","mode",")",".","n_tasks",":","int",",","default","1","The","number","of","tasks",".","batch_size",":","int",",","default","1","The","number","of","datapoints","in","a","batch",".","global_features_size",":","int",",","default","0","Size","of","the","global","features","vector",",","based","on","the","global","featurizers","used","during","featurization",".","use_default_fdim",":","bool","If","`","True","`",",","self.atom_fdim","and","self.bond_fdim","are","initialized","using","values","from","the","GraphConvConstants","class",".","If","`","False","`",",","self.atom_fdim","and","self.bond_fdim","are","initialized","from","the","values","provided",".","atom_fdim",":","int","Dimension","of","atom","feature","vector",".","bond_fdim",":","int","Dimension","of","bond","feature","vector",".","enc_hidden",":","int","Size","of","hidden","layer","in","the","encoder","layer",".","depth",":","int","No","of","message","passing","steps",".","bias",":","bool","If","`","True","`",",","dense","layers","will","use","bias","vectors",".","enc_activation",":","str","Activation","function","to","be","used","in","the","encoder","layer",".","Can","choose","between","'relu","'","for","ReLU",",","'leakyrelu","'","for","LeakyReLU",",","'prelu","'","for","PReLU",",","'tanh","'","for","TanH",",","'selu","'","for","SELU",",","and","'elu","'","for","ELU",".","enc_dropout_p",":","float","Dropout","probability","for","the","encoder","layer",".","aggregation",":","str","Aggregation","type","to","be","used","in","the","encoder","layer",".","Can","choose","between","'mean","'",",","'sum","'",",","and","'norm","'",".","aggregation_norm",":","Union","[","int",",","float","]","Value","required","if","`","aggregation","`","type","is","'norm","'",".","ffn_hidden",":","int","Size","of","hidden","layer","in","the","feed-forward","network","layer",".","ffn_activation",":","str","Activation","function","to","be","used","in","feed-forward","network","layer",".","Can","choose","between","'relu","'","for","ReLU",",","'leakyrelu","'","for","LeakyReLU",",","'prelu","'","for","PReLU",",","'tanh","'","for","TanH",",","'selu","'","for","SELU",",","and","'elu","'","for","ELU",".","ffn_layers",":","int","Number","of","layers","in","the","feed-forward","network","layer",".","ffn_dropout_p",":","float","Dropout","probability","for","the","feed-forward","network","layer",".","ffn_dropout_at_input_no_act",":","bool","If","true",",","dropout","is","applied","on","the","input","tensor",".","For","single","layer",",","it","is","not","passed","to","an","activation","function",".","kwargs",":","Dict","kwargs","supported","by","TorchModel"]
code: def __init__(
      self,
      mode: str = "regression",
      n_classes: int = 3,
      n_tasks: int = 1,
      batch_size: int = 1,
      global_features_size: int = 0,
      use_default_fdim: bool = True,
      atom_fdim: int = 133,
      bond_fdim: int = 14,
      enc_hidden: int = 300,
      depth: int = 3,
      bias: bool = False,
      enc_activation: str = "relu",
      enc_dropout_p: float = 0.0,
      aggregation: str = "mean",
      aggregation_norm: Union[int, float] = 100,
      ffn_hidden: int = 300,
      ffn_activation: str = "relu",
      ffn_layers: int = 3,
      ffn_dropout_p: float = 0.0,
      ffn_dropout_at_input_no_act: bool = True,
      **kwargs,
  ):
      """Initialize the DMPNNModel class.
  
      Parameters
      ----------
      mode: str, default 'regression'
          The model type - classification or regression.
      n_classes: int, default 3
          The number of classes to predict (used only in classification mode).
      n_tasks: int, default 1
          The number of tasks.
      batch_size: int, default 1
          The number of datapoints in a batch.
      global_features_size: int, default 0
          Size of the global features vector, based on the global featurizers used during featurization.
      use_default_fdim: bool
          If `True`, self.atom_fdim and self.bond_fdim are initialized using values from the GraphConvConstants class.
          If `False`, self.atom_fdim and self.bond_fdim are initialized from the values provided.
      atom_fdim: int
          Dimension of atom feature vector.
      bond_fdim: int
          Dimension of bond feature vector.
      enc_hidden: int
          Size of hidden layer in the encoder layer.
      depth: int
          No of message passing steps.
      bias: bool
          If `True`, dense layers will use bias vectors.
      enc_activation: str
          Activation function to be used in the encoder layer.
          Can choose between 'relu' for ReLU, 'leakyrelu' for LeakyReLU, 'prelu' for PReLU,
          'tanh' for TanH, 'selu' for SELU, and 'elu' for ELU.
      enc_dropout_p: float
          Dropout probability for the encoder layer.
      aggregation: str
          Aggregation type to be used in the encoder layer.
          Can choose between 'mean', 'sum', and 'norm'.
      aggregation_norm: Union[int, float]
          Value required if `aggregation` type is 'norm'.
      ffn_hidden: int
          Size of hidden layer in the feed-forward network layer.
      ffn_activation: str
          Activation function to be used in feed-forward network layer.
          Can choose between 'relu' for ReLU, 'leakyrelu' for LeakyReLU, 'prelu' for PReLU,
          'tanh' for TanH, 'selu' for SELU, and 'elu' for ELU.
      ffn_layers: int
          Number of layers in the feed-forward network layer.
      ffn_dropout_p: float
          Dropout probability for the feed-forward network layer.
      ffn_dropout_at_input_no_act: bool
          If true, dropout is applied on the input tensor. For single layer, it is not passed to an activation function.
      kwargs: Dict
          kwargs supported by TorchModel
      """
      model: nn.Module = DMPNN(
          mode=mode,
          n_classes=n_classes,
          n_tasks=n_tasks,
          global_features_size=global_features_size,
          use_default_fdim=use_default_fdim,
          atom_fdim=atom_fdim,
          bond_fdim=bond_fdim,
          enc_hidden=enc_hidden,
          depth=depth,
          bias=bias,
          enc_activation=enc_activation,
          enc_dropout_p=enc_dropout_p,
          aggregation=aggregation,
          aggregation_norm=aggregation_norm,
          ffn_hidden=ffn_hidden,
          ffn_activation=ffn_activation,
          ffn_layers=ffn_layers,
          ffn_dropout_p=ffn_dropout_p,
          ffn_dropout_at_input_no_act=ffn_dropout_at_input_no_act,
      )
  
      if mode == "regression":
          loss: Loss = L2Loss()
          output_types: List[str] = ["prediction"]
      elif mode == "classification":
          loss = SparseSoftmaxCrossEntropy()
          output_types = ["prediction", "loss"]
      super(DMPNNModel, self).__init__(
          model,
          loss=loss,
          output_types=output_types,
          batch_size=batch_size,
          **kwargs,
      )
  
imports: import numpy
  import torch
  import torch.nn
  from deepchem.models.losses import Loss, L2Loss, SparseSoftmaxCrossEntropy
  from deepchem.models.torch_models import layers
  from deepchem.models.torch_models import TorchModel
  from torch_geometric.data import Data, Batch
  from deepchem.feat import GraphData
  from deepchem.data import Dataset
  from typing import Union, List, Sequence, Optional, Iterable, Tuple
label_desc: Use image node_id 1 to create a new DMPNNModel object from inherited base classes: TorchModel with example: obj = DMPNNModel(mode, n_classes, n_tasks, batch_size, global_features_size, use_default_fdim, atom_fdim, bond_fdim, enc_hidden, depth, bias, enc_activation, enc_dropout_p, aggregation, aggregation_norm, ffn_hidden, ffn_activation, ffn_layers, ffn_dropout_p, ffn_dropout_at_input_no_act)