code: def mol2graph(mol_batch):
      padding = torch.zeros(ATOM_FDIM + BOND_FDIM)
      fatoms, fbonds = [], [padding]  # Ensure bond is 1-indexed
      in_bonds, all_bonds = [], [(-1, -1)]  # Ensure bond is 1-indexed
      scope = []
      total_atoms = 0
  
      for smiles in mol_batch:
          mol = get_mol(smiles)
          # mol = Chem.MolFromSmiles(smiles)
          n_atoms = mol.GetNumAtoms()
          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
  
              b = len(all_bonds)
              all_bonds.append((x, y))
              fbonds.append(
                  torch.cat([fatoms[x], bond_features(bond)], 0)
              )
              in_bonds[y].append(b)
  
              b = len(all_bonds)
              all_bonds.append((y, x))
              fbonds.append(
                  torch.cat([fatoms[y], bond_features(bond)], 0)
              )
              in_bonds[x].append(b)
  
          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(1, total_bonds):
          x, y = all_bonds[b1]
          for i, b2 in enumerate(in_bonds[x]):
              if all_bonds[b2][0] != y:
                  bgraph[b1, i] = b2
  
      return fatoms, fbonds, agraph, bgraph, scope
  
file_path: DIG/dig/ggraph/method/JTVAE/fast_jtnn/mpn.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  import rdkit.Chem
  from .nnutils import *
  from .chemutils import get_mol
label_desc: Use image node_id 4 for calling a global function with example usage: mol2graph(mol_batch) and returns: fatoms,  fbonds,  agraph,  bgraph,  scope