code: def __init__(self, smiles):
      self.nodes_dict = {}
  
      if smiles is None:
          self.graph = dgl.graph(([], []))
          return
  
      self.smiles = smiles
      self.mol = get_mol(smiles)
  
      # Stereo Generation
      mol = Chem.MolFromSmiles(smiles)
      self.smiles3D = Chem.MolToSmiles(mol, isomericSmiles=True)
      self.smiles2D = Chem.MolToSmiles(mol)
      self.stereo_cands = decode_stereo(self.smiles2D)
  
      # cliques: a list of list of atom indices
      cliques, edges = tree_decomp(self.mol)
      root = 0
      for i, c in enumerate(cliques):
          cmol = get_clique_mol(self.mol, c)
          csmiles = get_smiles(cmol)
          self.nodes_dict[i] = dict(
              smiles=csmiles,
              mol=get_mol(csmiles),
              clique=c,
          )
          if min(c) == 0:
              root = i
  
      # The clique with atom ID 0 becomes root
      if root > 0:
          for attr in self.nodes_dict[0]:
              self.nodes_dict[0][attr], self.nodes_dict[root][attr] = (
                  self.nodes_dict[root][attr],
                  self.nodes_dict[0][attr],
              )
  
      src = np.zeros((len(edges) * 2,), dtype="int")
      dst = np.zeros((len(edges) * 2,), dtype="int")
      for i, (_x, _y) in enumerate(edges):
          x = 0 if _x == root else root if _x == 0 else _x
          y = 0 if _y == root else root if _y == 0 else _y
          src[2 * i] = x
          dst[2 * i] = y
          src[2 * i + 1] = y
          dst[2 * i + 1] = x
      self.graph = dgl.graph((src, dst), num_nodes=len(cliques))
  
      for i in self.nodes_dict:
          self.nodes_dict[i]["nid"] = i + 1
          if (
              self.graph.out_degrees(i) > 1
          ):  # Leaf node mol is not marked
              set_atommap(
                  self.nodes_dict[i]["mol"], self.nodes_dict[i]["nid"]
              )
          self.nodes_dict[i]["is_leaf"] = self.graph.out_degrees(i) == 1
  
file_path: dgl/examples/pytorch/jtnn/jtnn/mol_tree_nx.py
imports: import dgl
  import numpy
  import rdkit.Chem
  from .chemutils import decode_stereo, enum_assemble_nx, get_clique_mol, get_mol, get_smiles, set_atommap, tree_decomp
label_desc: Use image node_id 1 to create a new DGLMolTree object from inherited base classes: object with example: obj = DGLMolTree(smiles)