Пример #1
0
 def test_pairwise_ring_info(self):
   from rdkit import Chem
   mol = Chem.MolFromSmiles("c1ccccc1")
   predict_dict = rdkit_utils.compute_pairwise_ring_info(mol)
   assert all(pair == [(6, True)] for pair in predict_dict.values())
   mol = Chem.MolFromSmiles("c1c2ccccc2ccc1")
   predict_dict = rdkit_utils.compute_pairwise_ring_info(mol)
   assert all(pair == [(6, True)] for pair in predict_dict.values())
   mol = Chem.MolFromSmiles("CN=C=O")
   predict_dict = rdkit_utils.compute_pairwise_ring_info(mol)
   assert not predict_dict
    def _pagtn_edge_featurizer(self,
                               mol: RDKitMol) -> Tuple[np.ndarray, np.ndarray]:
        """Calculate bond features from RDKit mol object.

    Parameters
    ----------
    mol: rdkit.Chem.rdchem.Mol
      RDKit mol object.

    Returns
    -------
    np.ndarray
      Source and Destination node indexes of each bond.
    np.ndarray
      numpy vector of bond features.
    """
        n_atoms = mol.GetNumAtoms()
        # To get the shortest paths between two nodes.
        paths_dict = compute_all_pairs_shortest_path(mol)
        # To get info if two nodes belong to the same ring.
        rings_dict = compute_pairwise_ring_info(mol)
        # Featurizer
        feats = []
        src = []
        dest = []
        for i in range(n_atoms):
            for j in range(n_atoms):
                src.append(i)
                dest.append(j)

                if (i, j) not in paths_dict:
                    feats.append(np.zeros(7 * self.max_length + 7))
                    continue
                ring_info = rings_dict.get(self.ordered_pair(i, j), [])
                feats.append(
                    self._edge_features(mol, paths_dict[(i, j)], ring_info))

        return np.array([src, dest], dtype=np.int), np.array(feats,
                                                             dtype=np.float)