def stereo(self, mol_batch, mol_vec):
    (stereo_cands, batch_idx) = ([], [])
    labels = []
    for (i, mol_tree) in enumerate(mol_batch):
        cands = mol_tree.stereo_cands
        if (len(cands) == 1):
            continue
        if (mol_tree.smiles3D not in cands):
            cands.append(mol_tree.smiles3D)
        stereo_cands.extend(cands)
        batch_idx.extend(([i] * len(cands)))
        labels.append((cands.index(mol_tree.smiles3D), len(cands)))
    if (len(labels) == 0):
        return (create_var(torch.zeros(1)), 1.0)
    batch_idx = create_var(torch.LongTensor(batch_idx))
    stereo_cands = self.mpn(mol2graph(stereo_cands))
    stereo_cands = self.G_mean(stereo_cands)
    stereo_labels = mol_vec.index_select(0, batch_idx)
    scores = torch.nn.CosineSimilarity()(stereo_cands, stereo_labels)
    (st, acc) = (0, 0)
    all_loss = []
    for (label, le) in labels:
        cur_scores = scores.narrow(0, st, le)
        if (cur_scores.data[label] >= cur_scores.max().data[0]):
            acc += 1
        label = create_var(torch.LongTensor([label]))
        all_loss.append(self.stereo_loss(cur_scores.view(1, (- 1)), label))
        st += le
    all_loss = (sum(all_loss) / len(labels))
    return (all_loss, ((acc * 1.0) / len(labels)))
def stereo(self, mol_batch, mol_vec):
    (stereo_cands, batch_idx) = ([], [])
    labels = []
    for (i, mol_tree) in enumerate(mol_batch):
        cands = mol_tree.stereo_cands
        if (len(cands) == 1):
            continue
        if (mol_tree.smiles3D not in cands):
            cands.append(mol_tree.smiles3D)
        stereo_cands.extend(cands)
        batch_idx.extend(([i] * len(cands)))
        labels.append((cands.index(mol_tree.smiles3D), len(cands)))
    if (len(labels) == 0):
        return (create_var(torch.zeros(1)), 1.0)
    batch_idx = create_var(torch.LongTensor(batch_idx))
    stereo_cands = self.mpn(mol2graph(stereo_cands))
    stereo_cands = self.G_mean(stereo_cands)
    stereo_labels = mol_vec.index_select(0, batch_idx)
    scores = torch.nn.CosineSimilarity()(stereo_cands, stereo_labels)
    (st, acc) = (0, 0)
    all_loss = []
    for (label, le) in labels:
        cur_scores = scores.narrow(0, st, le)
        if (cur_scores.data[label] >= cur_scores.max().data[0]):
            acc += 1
        label = create_var(torch.LongTensor([label]))
        all_loss.append(self.stereo_loss(cur_scores.view(1, (- 1)), label))
        st += le
    all_loss = (sum(all_loss) / len(labels))
    return (all_loss, ((acc * 1.0) / len(labels)))