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: Convert to PyTorch Geometric graph modified data instance
  
  .. note::
      This method requires PyTorch Geometric to be installed.
  
  Parameters
  ----------
  values: Sequence[np.ndarray]
      Mappings from ``_MapperDMPNN`` helper class for a molecule
  
  Returns
  -------
  torch_geometric.data.Data
      Modified Graph data for PyTorch Geometric (``_ModData``)
docstr_tok: ["Convert","to","PyTorch","Geometric","graph","modified","data","instance","..","note",":",":","This","method","requires","PyTorch","Geometric","to","be","installed",".","Parameters","--","--","--","--","--","values",":","Sequence","[","np.ndarray","]","Mappings","from","``","_MapperDMPNN","``","helper","class","for","a","molecule","Returns","--","--","--","-","torch_geometric.data.Data","Modified","Graph","data","for","PyTorch","Geometric","(","``","_ModData","``",")"]
code: def _to_pyg_graph(self, values: Sequence[np.ndarray]) -> _ModData:
      """Convert to PyTorch Geometric graph modified data instance
  
      .. note::
          This method requires PyTorch Geometric to be installed.
  
      Parameters
      ----------
      values: Sequence[np.ndarray]
          Mappings from ``_MapperDMPNN`` helper class for a molecule
  
      Returns
      -------
      torch_geometric.data.Data
          Modified Graph data for PyTorch Geometric (``_ModData``)
      """
  
      # atom feature matrix with shape [number of atoms, number of features]
      atom_features: np.ndarray
  
      # concatenated feature vector which contains concatenation of initial atom and bond features
      f_ini_atoms_bonds: np.ndarray
  
      # mapping from atom index to list of indicies of incoming bonds
      atom_to_incoming_bonds: np.ndarray
  
      # mapping that maps bond index to 'array of indices of the bonds'
      # incoming at the initial atom of the bond (excluding the reverse bonds)
      mapping: np.ndarray
  
      # array of global molecular features
      global_features: np.ndarray
  
      (
          atom_features,
          f_ini_atoms_bonds,
          atom_to_incoming_bonds,
          mapping,
          global_features,
      ) = values
  
      t_atom_features: torch.Tensor = (
          torch.from_numpy(atom_features).float().to(device=self.device)
      )
      t_f_ini_atoms_bonds: torch.Tensor = (
          torch.from_numpy(f_ini_atoms_bonds)
          .float()
          .to(device=self.device)
      )
      t_atom_to_incoming_bonds: torch.Tensor = torch.from_numpy(
          atom_to_incoming_bonds
      ).to(device=self.device)
      t_mapping: torch.Tensor = torch.from_numpy(mapping).to(
          device=self.device
      )
      t_global_features: torch.Tensor = (
          torch.from_numpy(global_features)
          .float()
          .to(device=self.device)
      )
  
      return _ModData(
          required_inc=len(t_f_ini_atoms_bonds),
          atom_features=t_atom_features,
          f_ini_atoms_bonds=t_f_ini_atoms_bonds,
          atom_to_incoming_bonds=t_atom_to_incoming_bonds,
          mapping=t_mapping,
          global_features=t_global_features,
      )
  
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 2 for calling the DMPNNModel obj's underlying member method code with example usage: obj._to_pyg_graph(values) and returns: _ModData