Пример #1
0
def featurize_contacts_ecfp(
        frag1: Tuple,
        frag2: Tuple,
        pairwise_distances: np.ndarray = None,
        cutoff: float = 4.5,
        ecfp_degree: int = 2) -> Tuple[Dict[int, str], Dict[int, str]]:
    """Computes ECFP dicts for pairwise interaction between two molecular fragments.

  Parameters
  ----------
  frag1: Tuple
    A tuple of (coords, mol) returned by `load_molecule`.
  frag2: Tuple
    A tuple of (coords, mol) returned by `load_molecule`.
  pairwise_distances: np.ndarray
    Array of pairwise fragment-fragment distances (Angstroms)
  cutoff: float
    Cutoff distance for contact consideration
  ecfp_degree: int
    ECFP radius

  Returns
  -------
  Tuple of dictionaries of ECFP contact fragments
  """
    if pairwise_distances is None:
        pairwise_distances = compute_pairwise_distances(frag1[0], frag2[0])
    # contacts is of form (x_coords, y_coords), a tuple of 2 lists
    contacts = np.nonzero((pairwise_distances < cutoff))
    # contacts[0] is the x_coords, that is the frag1 atoms that have
    # nonzero contact.
    frag1_atoms = set([int(c) for c in contacts[0].tolist()])
    # contacts[1] is the y_coords, the frag2 atoms with nonzero contacts
    frag2_atoms = set([int(c) for c in contacts[1].tolist()])

    frag1_ecfp_dict = compute_all_ecfp(frag1[1],
                                       indices=frag1_atoms,
                                       degree=ecfp_degree)
    frag2_ecfp_dict = compute_all_ecfp(frag2[1],
                                       indices=frag2_atoms,
                                       degree=ecfp_degree)

    return (frag1_ecfp_dict, frag2_ecfp_dict)
def compute_splif_features_in_range(frag1: Tuple,
                                    frag2: Tuple,
                                    pairwise_distances: np.ndarray,
                                    contact_bin: List,
                                    ecfp_degree: int = 2) -> Dict:
    """Computes SPLIF features for close atoms in molecular complexes.

  Finds all frag1 atoms that are > contact_bin[0] and <
  contact_bin[1] away from frag2 atoms. Then, finds the ECFP
  fingerprints for the contacting atoms. Returns a dictionary
  mapping (frag1_index_i, frag2_index_j) --> (frag1_ecfp_i,
  frag2_ecfp_j)

  Parameters
  ----------
  frag1: Tuple
    A tuple of (coords, mol) returned by `load_molecule`.
  frag2: Tuple
    A tuple of (coords, mol) returned by `load_molecule`.
  contact_bins: np.ndarray
    Ranges of pair distances which are placed in separate bins.
  pairwise_distances: np.ndarray
    Array of pairwise fragment-fragment distances (Angstroms)
  ecfp_degree: int
    ECFP radius
  """
    contacts = np.nonzero((pairwise_distances > contact_bin[0])
                          & (pairwise_distances < contact_bin[1]))
    frag1_atoms = set([int(c) for c in contacts[0].tolist()])
    contacts = zip(contacts[0], contacts[1])

    frag1_ecfp_dict = compute_all_ecfp(frag1[1],
                                       indices=frag1_atoms,
                                       degree=ecfp_degree)
    frag2_ecfp_dict = compute_all_ecfp(frag2[1], degree=ecfp_degree)
    splif_dict = {
        contact: (frag1_ecfp_dict[contact[0]], frag2_ecfp_dict[contact[1]])
        for contact in contacts
    }
    return splif_dict