code: def rdkit_mol2graph(mol, khop, with_3d=False):
      # atoms
      atom_features_list = []
      for atom in mol.GetAtoms():
          atom_features_list.append(atom_to_feature_vector(atom))
  
      atom_features_float_list = [
          [] for i in range(len(atom_features_list))
      ]
      # extra atom features
      ring_size = get_ring_size(mol)
      partial_charge = get_partial_charge(mol)
      valence = get_valence_of_out_shell(mol)
      van_der_waals_radis = get_van_der_waals_radis(mol)
      for i in range(len(mol.GetAtoms())):
          atom_features_list[i].extend(ring_size[i])
          atom_features_list[i].append(valence[i])
  
          atom_features_float_list[i].append(partial_charge[i])
          atom_features_float_list[i].append(van_der_waals_radis[i])
  
      x = np.array(atom_features_list, dtype=np.int64)
      x_float = np.array(atom_features_float_list, dtype=np.float)
  
      # bonds
      num_bond_features = 4  # bond type, bond stereo, is_conjugated
      if len(mol.GetBonds()) == 0:  # mol has bonds
          edge_index = np.empty((2, 0), dtype=np.int64)
          edge_attr = np.empty((0, num_bond_features), dtype=np.int64)
      else:
          # real edges
          edges_list = []
          edge_features_list = []
          for bond in mol.GetBonds():
              i = bond.GetBeginAtomIdx()
              j = bond.GetEndAtomIdx()
  
              # ###########
              # # DEBUG
              # conf = mol.GetConformer()
              # v1 = np.array([conf.GetAtomPosition(i).x, conf.GetAtomPosition(i).y, conf.GetAtomPosition(i).z])
              # v2 = np.array([conf.GetAtomPosition(j).x, conf.GetAtomPosition(j).y, conf.GetAtomPosition(j).z])
              # print('bl', np.linalg.norm(v1 - v2))
              # ###########
  
              edge_feature = bond_to_feature_vector(bond)
              edge_feature.append(1)
  
              # add edges in both directions
              edges_list.append((i, j))
              edge_features_list.append(edge_feature)
              edges_list.append((j, i))
              edge_features_list.append(edge_feature)
  
          # data.edge_index: Graph connectivity in COO format with shape [2, num_edges]
          edge_index = np.array(edges_list, dtype=np.int64).T
  
          # data.edge_attr: Edge feature matrix with shape [num_edges, num_edge_features]
          edge_attr = np.array(edge_features_list, dtype=np.int64)
  
      graph = dict()
      graph["edge_index"] = edge_index
      graph["edge_feat"] = edge_attr
      graph["node_feat"] = x
      graph["node_feat_float"] = x_float
      graph["num_nodes"] = len(x)
      graph["num_edges"] = edge_index.shape[1]
  
      graph = gen_context_id(graph)
  
      if with_3d:
          graph = parse_3dpos(graph, mol, khop, gen_aux_task=True)
  
      return graph
  
imports: import numpy
  import rdkit
  from rdkit import Chem
  from rdkit.Chem import AllChem
  import rdkit.Chem.rdPartialCharges
  from ogb.utils.features import allowable_features, atom_to_feature_vector, atom_feature_vector_to_dict, bond_feature_vector_to_dict
  from local_feature import bond_to_feature_vector, get_bond_feature_dims
  from copy import deepcopy
  import hashlib
label_desc: Use image node_id 10 for calling a global function with example usage: rdkit_mol2graph(mol, khop, with_3d) and returns: graph