code: def tensorize(cand_batch, mess_dict):
      fatoms, fbonds = [], []
      in_bonds, all_bonds = [], []
      total_atoms = 0
      total_mess = len(mess_dict) + 1  # must include vec(0) padding
      scope = []
  
      for smiles, all_nodes, ctr_node in cand_batch:
          mol = Chem.MolFromSmiles(smiles)
          # The original jtnn version kekulizes. Need to revisit why it is necessary
          Chem.Kekulize(mol)
          n_atoms = mol.GetNumAtoms()
          ctr_bid = ctr_node.idx
  
          for atom in mol.GetAtoms():
              fatoms.append(atom_features(atom))
              in_bonds.append([])
  
          for bond in mol.GetBonds():
              a1 = bond.GetBeginAtom()
              a2 = bond.GetEndAtom()
              x = a1.GetIdx() + total_atoms
              y = a2.GetIdx() + total_atoms
              # Here x_nid,y_nid could be 0
              x_nid, y_nid = a1.GetAtomMapNum(), a2.GetAtomMapNum()
              x_bid = all_nodes[x_nid - 1].idx if x_nid > 0 else -1
              y_bid = all_nodes[y_nid - 1].idx if y_nid > 0 else -1
  
              bfeature = bond_features(bond)
  
              # bond idx offseted by total_mess
              b = total_mess + len(all_bonds)
              all_bonds.append((x, y))
              fbonds.append(torch.cat([fatoms[x], bfeature], 0))
              in_bonds[y].append(b)
  
              b = total_mess + len(all_bonds)
              all_bonds.append((y, x))
              fbonds.append(torch.cat([fatoms[y], bfeature], 0))
              in_bonds[x].append(b)
  
              if x_bid >= 0 and y_bid >= 0 and x_bid != y_bid:
                  if (x_bid, y_bid) in mess_dict:
                      mess_idx = mess_dict[(x_bid, y_bid)]
                      in_bonds[y].append(mess_idx)
                  if (y_bid, x_bid) in mess_dict:
                      mess_idx = mess_dict[(y_bid, x_bid)]
                      in_bonds[x].append(mess_idx)
  
          scope.append((total_atoms, n_atoms))
          total_atoms += n_atoms
  
      total_bonds = len(all_bonds)
      fatoms = torch.stack(fatoms, 0)
      fbonds = torch.stack(fbonds, 0)
      agraph = torch.zeros(total_atoms, MAX_NB).long()
      bgraph = torch.zeros(total_bonds, MAX_NB).long()
  
      for a in range(total_atoms):
          for i, b in enumerate(in_bonds[a]):
              agraph[a, i] = b
  
      for b1 in range(total_bonds):
          x, y = all_bonds[b1]
          # b2 is offseted by total_mess
          for i, b2 in enumerate(in_bonds[x]):
              if b2 < total_mess or all_bonds[b2 - total_mess][0] != y:
                  bgraph[b1, i] = b2
  
      return (fatoms, fbonds, agraph, bgraph, scope)
  
file_path: DIG/dig/ggraph/method/JTVAE/fast_jtnn/jtmpn.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  import rdkit.Chem
  from .nnutils import create_var, index_select_ND
label_desc: Use image node_id 3 for calling the JTMPN obj's underlying member method code with example usage: obj.tensorize(cand_batch, mess_dict) and returns: fatoms,  fbonds,  agraph,  bgraph,  scope