def decode(self, tree_vec, mol_vec, prob_decode):
    (pred_root, pred_nodes) = self.decoder.decode(tree_vec, prob_decode)
    for (i, node) in enumerate(pred_nodes):
        node.nid = (i + 1)
        node.is_leaf = (len(node.neighbors) == 1)
        if (len(node.neighbors) > 1):
            set_atommap(node.mol, node.nid)
    tree_mess = self.jtnn([pred_root])[0]
    cur_mol = copy_edit_mol(pred_root.mol)
    global_amap = ([{}] + [{} for node in pred_nodes])
    global_amap[1] = {atom.GetIdx(): atom.GetIdx() for atom in cur_mol.GetAtoms()}
    cur_mol = self.dfs_assemble(tree_mess, mol_vec, pred_nodes, cur_mol, global_amap, [], pred_root, None, prob_decode)
    if (cur_mol is None):
        return None
    cur_mol = cur_mol.GetMol()
    set_atommap(cur_mol)
    cur_mol = Chem.MolFromSmiles(Chem.MolToSmiles(cur_mol))
    if (cur_mol is None):
        return None
    if (self.use_stereo == False):
        return Chem.MolToSmiles(cur_mol)
    smiles2D = Chem.MolToSmiles(cur_mol)
    stereo_cands = decode_stereo(smiles2D)
    if (len(stereo_cands) == 1):
        return stereo_cands[0]
    stereo_vecs = self.mpn(mol2graph(stereo_cands))
    stereo_vecs = self.G_mean(stereo_vecs)
    scores = nn.CosineSimilarity()(stereo_vecs, mol_vec)
    (_, max_id) = scores.max(dim=0)
    return stereo_cands[max_id.data.item()]
def decode(self, tree_vec, mol_vec, prob_decode):
    (pred_root, pred_nodes) = self.decoder.decode(tree_vec, prob_decode)
    for (i, node) in enumerate(pred_nodes):
        node.nid = (i + 1)
        node.is_leaf = (len(node.neighbors) == 1)
        if (len(node.neighbors) > 1):
            set_atommap(node.mol, node.nid)
    tree_mess = self.jtnn([pred_root])[0]
    cur_mol = copy_edit_mol(pred_root.mol)
    global_amap = ([{}] + [{} for node in pred_nodes])
    global_amap[1] = {atom.GetIdx(): atom.GetIdx() for atom in cur_mol.GetAtoms()}
    cur_mol = self.dfs_assemble(tree_mess, mol_vec, pred_nodes, cur_mol, global_amap, [], pred_root, None, prob_decode)
    if (cur_mol is None):
        return None
    cur_mol = cur_mol.GetMol()
    set_atommap(cur_mol)
    cur_mol = Chem.MolFromSmiles(Chem.MolToSmiles(cur_mol))
    if (cur_mol is None):
        return None
    if (self.use_stereo == False):
        return Chem.MolToSmiles(cur_mol)
    smiles2D = Chem.MolToSmiles(cur_mol)
    stereo_cands = decode_stereo(smiles2D)
    if (len(stereo_cands) == 1):
        return stereo_cands[0]
    stereo_vecs = self.mpn(mol2graph(stereo_cands))
    stereo_vecs = self.G_mean(stereo_vecs)
    scores = nn.CosineSimilarity()(stereo_vecs, mol_vec)
    (_, max_id) = scores.max(dim=0)
    return stereo_cands[max_id.data.item()]