Esempio n. 1
0
def test_distance():
    mol1 = oddt.toolkit.readstring('sdf', ASPIRIN_SDF)
    d = distance(mol1.coords, mol1.coords)
    n_atoms = len(mol1.coords)
    assert d.shape, (n_atoms == n_atoms)
    assert_array_equal(d[np.eye(len(mol1.coords), dtype=bool)], np.zeros(n_atoms))

    d = distance(mol1.coords, mol1.coords.mean(axis=0).reshape(1, 3))
    assert d.shape, (n_atoms == 1)
    ref_dist = [[3.556736951371501], [2.2058040428631056], [2.3896002745745415],
                [1.6231668718498249], [0.7772981740050453], [2.0694947503940004],
                [2.8600587871157184], [2.9014207091233857], [2.1850791695403564],
                [0.9413368403116871], [1.8581710293650173], [2.365629642108773],
                [2.975007440512798]]
    assert_array_almost_equal(d, ref_dist)
Esempio n. 2
0
def calc_halogen_bond_interactions(protein,
                                   mol,
                                   key_inters_defs,
                                   mol_key_inters,
                                   filter_strict=False):
    protein_atoms, ligand_atoms, strict = oddt.interactions.halogenbonds(
        protein, mol)
    inters = {}
    for p, l, s in zip(protein_atoms, ligand_atoms, strict):
        if s or not filter_strict:
            c = get_canonical_residue(p)
            dist = spatial.distance(np.array([p['coords']]),
                                    np.array([l['coords']]))[0][0]
            p_coords = (p['coords'][0].item(), p['coords'][1].item(),
                        p['coords'][2].item())
            l_coords = (l['coords'][0].item(), l['coords'][1].item(),
                        l['coords'][2].item())
            t = interactions.Interaction(c, p_coords, l_coords, dist,
                                         l['id'].item())
            if c in inters:
                current_value = inters[c]
                if dist < current_value.distance:
                    inters[c] = t
            else:
                inters[c] = t
                if key_inters_defs and c in key_inters_defs:
                    mol_key_inters.append(interactions.I_TYPE_HALOGEN + ':' +
                                          c)

    if inters:
        return interactions.InteractionType(interactions.I_NAME_HALOGEN,
                                            list(inters.values()))
    else:
        return None
Esempio n. 3
0
def calc_pi_stacking_interactions(protein,
                                  mol,
                                  key_inters_defs,
                                  mol_key_inters,
                                  filter_strict=False):
    protein_atoms, ligand_atoms, strict_parallel, strict_perpendicular = oddt.interactions.pi_stacking(
        protein, mol)
    inters = {}
    for p, l, s1, s2 in zip(protein_atoms, ligand_atoms, strict_parallel,
                            strict_perpendicular):
        if (s1 or s2) or not filter_strict:
            c = get_canonical_residue(p)
            dist = spatial.distance(np.array([p['centroid']]),
                                    np.array([l['centroid']]))[0][0]
            p_coords = (p['centroid'][0].item(), p['centroid'][1].item(),
                        p['centroid'][2].item())
            l_coords = (l['centroid'][0].item(), l['centroid'][1].item(),
                        l['centroid'][2].item())
            t = interactions.Interaction(c, p_coords, l_coords, dist, None)

            if c in inters:
                current_value = inters[c]
                if dist < current_value.distance:
                    inters[c] = t
            else:
                inters[c] = t
                if key_inters_defs and c in key_inters_defs:
                    mol_key_inters.append(interactions.I_TYPE_PI_STACKING +
                                          ':' + c)

    if inters:
        return interactions.InteractionType(interactions.I_NAME_PI_STACKING,
                                            list(inters.values()))
    else:
        return None
Esempio n. 4
0
def close_contacts(x, y, cutoff, x_column='coords', y_column='coords',
                   cutoff_low=0.):
    """Returns pairs of atoms which are within close contac distance cutoff.
    The cutoff is semi-inclusive, i.e (cutoff_low, cutoff].

    Parameters
    ----------
    x, y : atom_dict-type numpy array
        Atom dictionaries generated by oddt.toolkit.Molecule objects.

    cutoff : float
        Cutoff distance for close contacts

    x_column, ycolumn : string, (default='coords')
        Column containing coordinates of atoms (or pseudo-atoms,
        i.e. ring centroids)

    cutoff_low : float (default=0.)
        Lower bound of contacts to find (exclusive). Zero by default.
        .. versionadded:: 0.6

    Returns
    -------
    x_, y_ : atom_dict-type numpy array
        Aligned pairs of atoms in close contact for further processing.
    """
    if len(x[x_column]) > 0 and len(x[x_column]) > 0:
        d = distance(x[x_column], y[y_column])
        index = np.argwhere((d > cutoff_low) & (d <= cutoff))
        return x[index[:, 0]], y[index[:, 1]]
    else:
        return x[[]], y[[]]
Esempio n. 5
0
def calc_salt_bridge_interactions(protein,
                                  mol,
                                  key_inters_defs,
                                  mol_key_inters,
                                  exact_protein=False,
                                  exact_ligand=False):
    inters = {}
    protein_atoms, ligand_atoms = oddt.interactions.salt_bridges(
        protein, mol, mol1_exact=exact_protein, mol2_exact=exact_ligand)
    for p, l in zip(protein_atoms, ligand_atoms):
        c = get_canonical_residue(p)
        dist = spatial.distance(np.array([p['coords']]),
                                np.array([l['coords']]))[0][0]
        p_coords = (p['coords'][0].item(), p['coords'][1].item(),
                    p['coords'][2].item())
        l_coords = (l['coords'][0].item(), l['coords'][1].item(),
                    l['coords'][2].item())
        t = interactions.Interaction(c, p_coords, l_coords, dist,
                                     l['id'].item())
        if c in inters:
            current_value = inters[c]
            if dist < current_value.distance:
                inters[c] = t
        else:
            inters[c] = t
            if key_inters_defs and c in key_inters_defs:
                mol_key_inters.append(interactions.I_TYPE_SALT_BRIDGE + ':' +
                                      c)

    if inters:
        return interactions.InteractionType(interactions.I_NAME_SALT_BRIDGE,
                                            list(inters.values()))
    else:
        return None
Esempio n. 6
0
def close_contacts(x, y, cutoff, x_column = 'coords', y_column = 'coords'):
    """ Returns pairs of atoms which are within close contac distance cutoff.
        
        Parameters
        ----------
            x, y : atom_dict-type numpy array
                Atom dictionaries generated by oddt.toolkit.Molecule objects.
            
            cutoff : float
                Cutoff distance for close contacts
            
            x_column, ycolumn : string, (default='coords')
                Column containing coordinates of atoms (or pseudo-atoms, i.e. ring centroids)
        
        Returns
        -------
            x_, y_ : atom_dict-type numpy array
                Aligned pairs of atoms in close contact for further processing.
    """
    if len(x[x_column]) > 0 and len(x[x_column]) > 0:
        d = distance(x[x_column], y[y_column])
        index = np.argwhere((d > 0) & (d <= cutoff))
        return x[index[:,0]], y[index[:,1]]
    else:
        return x[[]], y[[]]
Esempio n. 7
0
    def score_intra(self, coords = None):
        if coords is None:
            coords = self.lig_dict['coords']
        # Intra-molceular
        r = distance(coords, coords)
        d = (r - self.lig_dict['radius'][:,np.newaxis] - self.lig_dict['radius'][np.newaxis,:])

        mask = self.lig_distant_members & (r < 8)

        intra=[]
        # Gauss 1
        intra.append(np.exp(-(d[mask]/0.5)**2).sum())
        # Gauss 2
        intra.append(np.exp(-((d[mask]-3.)/2.)**2).sum())
        # Repiulsion
        intra.append((d[(d < 0) & mask]**2).sum())

        # Hydrophobic
        if not 'hyd' in self.mask_intra:
            self.mask_intra['hyd'] = (self.lig_dict['ishydrophobe'] | self.lig_dict['ishalogen'])[:,np.newaxis] * (self.lig_dict['ishydrophobe'] | self.lig_dict['ishalogen'])[np.newaxis,:]
        mask_hyd = mask & self.mask_intra['hyd']
        d_hyd = d[mask_hyd]
        intra.append((d_hyd <= 0.5).sum() + (1.5 - d_hyd[(0.5 < d_hyd) & (d_hyd < 1.5)]).sum())

        # H-Bonding
        if not 'da' in self.mask_intra:
            self.mask_intra['da'] = (self.lig_dict['isdonor'] | self.lig_dict['ismetal'])[...,np.newaxis]*self.lig_dict['isacceptor'][np.newaxis,...]
        if not 'ad' in self.mask_intra:
            self.mask_intra['ad'] = self.lig_dict['isacceptor'][...,np.newaxis]*(self.lig_dict['isdonor'] | self.lig_dict['ismetal'])[np.newaxis,...]
        d_h = d[mask & (self.mask_intra['da'] | self.mask_intra['ad'])]
        intra.append((d_h <= -0.7).sum() + (d_h[(-0.7 < d_h) & (d_h < 0)]/-0.7).sum())

        return np.array(intra)
Esempio n. 8
0
def close_contacts(x, y, cutoff, x_column='coords', y_column='coords'):
    """ Returns pairs of atoms which are within close contac distance cutoff.
        
        Parameters
        ----------
            x, y : atom_dict-type numpy array
                Atom dictionaries generated by oddt.toolkit.Molecule objects.
            
            cutoff : float
                Cutoff distance for close contacts
            
            x_column, ycolumn : string, (default='coords')
                Column containing coordinates of atoms (or pseudo-atoms, i.e. ring centroids)
        
        Returns
        -------
            x_, y_ : atom_dict-type numpy array
                Aligned pairs of atoms in close contact for further processing.
    """
    if len(x[x_column]) > 0 and len(x[x_column]) > 0:
        d = distance(x[x_column], y[y_column])
        index = np.argwhere((d > 0) & (d <= cutoff))
        return x[index[:, 0]], y[index[:, 1]]
    else:
        return x[[]], y[[]]
Esempio n. 9
0
def calc_hydrogen_bond_interactions(protein,
                                    mol,
                                    key_inters_defs,
                                    mol_key_inters,
                                    filter_strict=False,
                                    exact_protein=False,
                                    exact_ligand=False):
    """ Calculate H-bond interactions

    Parameters:
    protein (Molecule): The protein
    mol (Molecule): The ligand to test
    key_inters_defs (List): Optional list of key H-bond interactions
    mol_key_inters (List): List to add the key H-bond interactions to
    filter_strict (Bool): Whether to use strict matching

    Returns:
    InteractionType: The interactions
    """

    # first apply a fix that's needed to handle the mis-assignment of donor atoms for a particular tautomeric
    # form: nc[n;H1]. See https://groups.google.com/g/oddt/c/fqzmhSqprw8/m/nmaaUlCDAgAJ
    # mol.atom_dict.setflags(write=True)
    # matches = oddt.toolkit.Smarts('[n;H0]').findall(mol)
    # for (idx,) in matches:
    #     # idx assumes 0 based indexing e.g. RDKit. OBabel uses 1 based indexing.
    #     mol.atom_dict['isdonor'][idx] = False
    # mol.atom_dict.setflags(write=False)
    # end of fix

    protein_atoms, ligand_atoms, strict = oddt.interactions.hbonds(
        protein, mol, mol1_exact=exact_protein, mol2_exact=exact_ligand)
    inters = {}

    for p, l, s in zip(protein_atoms, ligand_atoms, strict):
        if s or not filter_strict:
            c = get_canonical_hbond(p)
            dist = spatial.distance(np.array([p['coords']]),
                                    np.array([l['coords']]))[0][0]
            p_coords = (p['coords'][0].item(), p['coords'][1].item(),
                        p['coords'][2].item())
            l_coords = (l['coords'][0].item(), l['coords'][1].item(),
                        l['coords'][2].item())
            t = interactions.Interaction(c, p_coords, l_coords, dist,
                                         l['id'].item())
            if c in inters:
                current_value = inters[c]
                if dist < current_value.distance:
                    inters[c] = t
            else:
                inters[c] = t
                if key_inters_defs and c in key_inters_defs:
                    mol_key_inters.append(interactions.I_TYPE_HBOND + ':' + c)
    if inters:
        # print('  found', len(inters), 'h-bonds')
        return interactions.InteractionType(interactions.I_NAME_HBOND,
                                            list(inters.values()))
    else:
        return None
Esempio n. 10
0
def test_distance():
    mol1 = oddt.toolkit.readstring('sdf', ASPIRIN_SDF)
    d = distance(mol1.coords, mol1.coords)
    n_atoms = len(mol1.coords)
    assert_equal(d.shape, (n_atoms, n_atoms))
    assert_array_equal(d[np.eye(len(mol1.coords), dtype=bool)],
                       np.zeros(n_atoms))

    d = distance(mol1.coords, mol1.coords.mean(axis=0).reshape(1, 3))
    assert_equal(d.shape, (n_atoms, 1))
    ref_dist = [[3.556736951371501], [2.2058040428631056
                                      ], [2.3896002745745415],
                [1.6231668718498249], [0.7772981740050453
                                       ], [2.0694947503940004],
                [2.8600587871157184], [2.9014207091233857],
                [2.1850791695403564], [0.9413368403116871],
                [1.8581710293650173], [2.365629642108773], [2.975007440512798]]
    assert_array_almost_equal(d, ref_dist)
Esempio n. 11
0
def calc_hydrophobic_interactions(protein, mol, key_inters_defs,
                                  mol_key_inters):
    """ Calculate hydrophobic interactions.
    ODDT generates hydrophobic interactions for all pairs of atoms that are within the specification which results in
    multiple interactions between the same hydrophobic region of the ligand and protein.
    We reduce those down to a single interaction, the one that is the shortest.
    ODDT also seems to generate hydrophobic interactions that are complete duplicates, and the de-duplication process
    removes these as well.

    Parameters:
    protein (Molecule): The protein
    mol (Molecule): The ligand to test
    key_inters_defs (List): Optional list of key H-bond interactions
    mol_key_inters (List): List to add the key H-bond interactions to

    Returns:
    InteractionType: The interactions
    """
    inters = {}
    protein_atoms, ligand_atoms = oddt.interactions.hydrophobic_contacts(
        protein, mol)
    for p, l in zip(protein_atoms, ligand_atoms):
        c = get_canonical_residue(p)
        dist = spatial.distance(np.array([p['coords']]),
                                np.array([l['coords']]))[0][0]
        p_coords = (p['coords'][0].item(), p['coords'][1].item(),
                    p['coords'][2].item())
        l_coords = (l['coords'][0].item(), l['coords'][1].item(),
                    l['coords'][2].item())
        t = interactions.Interaction(c, p_coords, l_coords, dist,
                                     l['id'].item())
        if c in inters:
            current_value = inters[c]
            if dist < current_value.distance:
                inters[c] = t
        else:
            inters[c] = t
            if key_inters_defs and c in key_inters_defs:
                mol_key_inters.append(interactions.I_TYPE_HYDROPHOBIC + ':' +
                                      c)

    if inters:
        # print('  found', len(inters), 'hydrophobics')
        return interactions.InteractionType(interactions.I_NAME_HYDROPHOBIC,
                                            list(inters.values()))
    else:
        return None
Esempio n. 12
0
    def score_inter(self, coords=None):
        if coords is None:
            coords = self.lig_dict['coords']

        # Inter-molecular
        r = distance(self.rec_dict['coords'], coords)
        d = (r - self.rec_dict['radius'][:, np.newaxis] -
             self.lig_dict['radius'][np.newaxis, :])
        mask = r < 8

        inter = []
        # Gauss 1
        inter.append(np.exp(-(d[mask] / 0.5)**2).sum())
        # Gauss 2
        inter.append(np.exp(-((d[mask] - 3.) / 2.)**2).sum())
        # Repiulsion
        inter.append((d[(d < 0) & mask]**2).sum())

        # Hydrophobic
        if 'hyd' not in self.mask_inter:
            self.mask_inter['hyd'] = (
                (self.rec_dict['ishydrophobe']
                 | self.rec_dict['ishalogen'])[:, np.newaxis] *
                (self.lig_dict['ishydrophobe']
                 | self.lig_dict['ishalogen'])[np.newaxis, :])
        mask_hyd = mask & self.mask_inter['hyd']
        d_hyd = d[mask_hyd]
        inter.append((d_hyd <= 0.5).sum() +
                     (1.5 - d_hyd[(0.5 < d_hyd) & (d_hyd < 1.5)]).sum())

        # H-Bonding
        if 'da' not in self.mask_inter:
            self.mask_inter['da'] = (
                (self.rec_dict['isdonor']
                 | self.rec_dict['ismetal'])[:, np.newaxis] *
                self.lig_dict['isacceptor'][np.newaxis, :])
        if 'ad' not in self.mask_inter:
            self.mask_inter['ad'] = (
                self.rec_dict['isacceptor'][:, np.newaxis] *
                (self.lig_dict['isdonor']
                 | self.lig_dict['ismetal'])[np.newaxis, :])
        d_h = d[mask & (self.mask_inter['da'] | self.mask_inter['ad'])]
        inter.append((d_h <= -0.7).sum() +
                     (d_h[(-0.7 < d_h) & (d_h < 0)] / -0.7).sum())

        return np.array(inter)
Esempio n. 13
0
    def score_intra(self, coords=None):
        if coords is None:
            coords = self.lig_dict['coords']
        # Intra-molceular
        r = distance(coords, coords)
        d = (r - self.lig_dict['radius'][:, np.newaxis] - self.lig_dict['radius'][np.newaxis, :])

        mask = self.lig_distant_members & (r < 8)

        intra = []
        # Gauss 1
        intra.append(np.exp(-(d[mask] / 0.5)**2).sum())
        # Gauss 2
        intra.append(np.exp(-((d[mask] - 3.) / 2.)**2).sum())
        # Repiulsion
        intra.append((d[(d < 0) & mask]**2).sum())

        # Hydrophobic
        if 'hyd' not in self.mask_intra:
            self.mask_intra['hyd'] = ((self.lig_dict['ishydrophobe'] | self.lig_dict['ishalogen'])[:, np.newaxis] *
                                      (self.lig_dict['ishydrophobe'] | self.lig_dict['ishalogen'])[np.newaxis, :])
        mask_hyd = mask & self.mask_intra['hyd']
        d_hyd = d[mask_hyd]
        intra.append((d_hyd <= 0.5).sum() + (1.5 - d_hyd[(0.5 < d_hyd) & (d_hyd < 1.5)]).sum())

        # H-Bonding
        if 'da' not in self.mask_intra:
            self.mask_intra['da'] = ((self.lig_dict['isdonor'] | self.lig_dict['ismetal'])[..., np.newaxis] *
                                     self.lig_dict['isacceptor'][np.newaxis, ...])
        if 'ad' not in self.mask_intra:
            self.mask_intra['ad'] = (self.lig_dict['isacceptor'][..., np.newaxis] *
                                     (self.lig_dict['isdonor'] | self.lig_dict['ismetal'])[np.newaxis, ...])
        d_h = d[mask & (self.mask_intra['da'] | self.mask_intra['ad'])]
        intra.append((d_h <= -0.7).sum() + (d_h[(-0.7 < d_h) & (d_h < 0)] / -0.7).sum())

        return np.array(intra)
Esempio n. 14
0
def close_contacts(x,
                   y,
                   cutoff,
                   x_column='coords',
                   y_column='coords',
                   cutoff_low=0.):
    """Returns pairs of atoms which are within close contac distance cutoff.
    The cutoff is semi-inclusive, i.e (cutoff_low, cutoff].

    Parameters
    ----------
    x, y : atom_dict-type numpy array
        Atom dictionaries generated by oddt.toolkit.Molecule objects.

    cutoff : float
        Cutoff distance for close contacts

    x_column, ycolumn : string, (default='coords')
        Column containing coordinates of atoms (or pseudo-atoms,
        i.e. ring centroids)

    cutoff_low : float (default=0.)
        Lower bound of contacts to find (exclusive). Zero by default.
        .. versionadded:: 0.6

    Returns
    -------
    x_, y_ : atom_dict-type numpy array
        Aligned pairs of atoms in close contact for further processing.
    """
    if len(x[x_column]) > 0 and len(x[x_column]) > 0:
        d = distance(x[x_column], y[y_column])
        index = np.argwhere((d > cutoff_low) & (d <= cutoff))
        return x[index[:, 0]], y[index[:, 1]]
    else:
        return x[[]], y[[]]
Esempio n. 15
0
 def peakmem_distance_protein(self):
     distance(self.protein.coords, self.protein.coords)
Esempio n. 16
0
def detect_secondary_structure(res_dict):
    """Detect alpha helices and beta sheets in res_dict by phi and psi angles"""
    first = res_dict[:-1]
    second = res_dict[1:]
    psi = dihedral(first['N'], first['CA'], first['C'], second['N'])
    phi = dihedral(first['C'], second['N'], second['CA'], second['C'])
    d = second['id'] - first['id']

    # Alpha helices
    res_mask_alpha = (
        ((phi > -145) & (phi < -35) & (psi > -70) & (psi < 50) & (d == 1))
    )  # alpha
    res_mask_alpha = np.union1d(np.argwhere(res_mask_alpha),
                                np.argwhere(res_mask_alpha))
    # Ignore groups smaller than 3
    for mask_group in np.split(
            res_mask_alpha,
            np.argwhere(np.diff(res_mask_alpha) != 1).flatten() + 1):
        if len(mask_group) >= 3:
            res_dict['isalpha'][mask_group] = True
    # Alpha helices have to form H-Bonds
    hbond_dist_mask = np.abs(
        res_dict[res_dict['isalpha']]['id'] -
        res_dict[res_dict['isalpha']]['id'][:, np.newaxis]) >= 3
    hbond_mask = distance(res_dict[res_dict['isalpha']]['N'],
                          res_dict[res_dict['isalpha']]['O']) < 3.5
    p_mask = ((hbond_mask & hbond_dist_mask).any(axis=0) |
              (hbond_mask & hbond_dist_mask).any(axis=1))
    res_dict['isalpha'][np.argwhere(
        res_dict['isalpha']).flatten()[~p_mask]] = False
    # Ignore groups smaller than 3
    res_mask_alpha = np.argwhere(res_dict['isalpha']).flatten()
    for mask_group in np.split(
            res_mask_alpha,
            np.argwhere(np.diff(res_mask_alpha) != 1).flatten() + 1):
        if 0 < len(mask_group) < 3:
            res_dict['isalpha'][mask_group] = False

    # Beta sheets
    res_mask_beta = (
        ((phi >= -180) & (phi < -40) & (psi <= 180) & (psi > 90) & (d == 1)) |
        ((phi >= -180) & (phi < -70) & (psi <= -165) & (d == 1)))  # beta
    res_mask_beta = np.union1d(np.argwhere(res_mask_beta),
                               np.argwhere(res_mask_beta))
    # Ignore groups smaller than 3
    for mask_group in np.split(
            res_mask_beta,
            np.argwhere(np.diff(res_mask_beta) != 1).flatten() + 1):
        if len(mask_group) >= 3:
            res_dict['isbeta'][mask_group] = True
    # Beta strands have to be alongside eachother
    res_dist_mask = np.abs(res_dict[res_dict['isbeta']]['id'] -
                           res_dict[res_dict['isbeta']]['id'][:,
                                                              np.newaxis]) >= 4
    hbond_mask = distance(res_dict[res_dict['isbeta']]['N'],
                          res_dict[res_dict['isbeta']]['O']) < 3.5
    ca_mask = distance(res_dict[res_dict['isbeta']]['CA'],
                       res_dict[res_dict['isbeta']]['CA']) < 4.5
    p_mask = ((hbond_mask & res_dist_mask).any(axis=0) |
              (hbond_mask & res_dist_mask).any(axis=1) |
              (ca_mask & res_dist_mask).any(axis=0))
    res_dict['isbeta'][np.argwhere(
        res_dict['isbeta']).flatten()[~p_mask]] = False
    # Ignore groups smaller than 3
    res_mask_beta = np.argwhere(res_dict['isbeta']).flatten()
    for mask_group in np.split(
            res_mask_beta,
            np.argwhere(np.diff(res_mask_beta) != 1).flatten() + 1):
        if 0 < len(mask_group) < 3:
            res_dict['isbeta'][mask_group] = False

    return res_dict
Esempio n. 17
0
File: common.py Progetto: oddt/oddt
def detect_secondary_structure(res_dict):
    """Detect alpha helices and beta sheets in res_dict by phi and psi angles"""
    first = res_dict[:-1]
    second = res_dict[1:]
    psi = dihedral(first['N'], first['CA'], first['C'], second['N'])
    phi = dihedral(first['C'], second['N'], second['CA'], second['C'])
    d = second['id'] - first['id']

    # Alpha helices
    res_mask_alpha = (((phi > -145) & (phi < -35) &
                       (psi > -70) & (psi < 50) & (d == 1)))  # alpha
    res_mask_alpha = np.union1d(np.argwhere(res_mask_alpha),
                                np.argwhere(res_mask_alpha))

    # Ignore groups smaller than 3
    for mask_group in np.split(res_mask_alpha, np.argwhere(np.diff(res_mask_alpha) != 1).flatten() + 1):
        if len(mask_group) >= 3:
            res_dict['isalpha'][mask_group] = True

    # Alpha helices have to form H-Bonds
    hbond_dist_mask = np.abs(res_dict[res_dict['isalpha']]['resnum'] -
                             res_dict[res_dict['isalpha']]['resnum'][:, np.newaxis]) >= 3
    hbond_mask = distance(res_dict[res_dict['isalpha']]['N'],
                          res_dict[res_dict['isalpha']]['O']) < 3.5
    p_mask = ((hbond_mask & hbond_dist_mask).any(axis=0) |
              (hbond_mask & hbond_dist_mask).any(axis=1))
    res_dict['isalpha'][np.argwhere(res_dict['isalpha']).flatten()[~p_mask]] = False

    # Ignore groups smaller than 3
    res_mask_alpha = np.argwhere(res_dict['isalpha']).flatten()
    for mask_group in np.split(res_mask_alpha, np.argwhere(np.diff(res_mask_alpha) != 1).flatten() + 1):
        if 0 < len(mask_group) < 3:
            res_dict['isalpha'][mask_group] = False

    # Beta sheets
    res_mask_beta = (((phi >= -180) & (phi < -40) &
                      (psi <= 180) & (psi > 90) & (d == 1)) |
                     ((phi >= -180) & (phi < -70) &
                      (psi <= -165) & (d == 1)))  # beta
    res_mask_beta = np.union1d(np.argwhere(res_mask_beta),
                               np.argwhere(res_mask_beta))

    # Ignore groups smaller than 3
    for mask_group in np.split(res_mask_beta, np.argwhere(np.diff(res_mask_beta) != 1).flatten() + 1):
        if len(mask_group) >= 3:
            res_dict['isbeta'][mask_group] = True

    # Beta strands have to be alongside eachother
    res_dist_mask = np.abs(res_dict[res_dict['isbeta']]['resnum'] -
                           res_dict[res_dict['isbeta']]['resnum'][:, np.newaxis]) >= 4
    hbond_mask = distance(res_dict[res_dict['isbeta']]['N'],
                          res_dict[res_dict['isbeta']]['O']) < 3.5
    ca_mask = distance(res_dict[res_dict['isbeta']]['CA'],
                       res_dict[res_dict['isbeta']]['CA']) < 4.5
    p_mask = ((hbond_mask & res_dist_mask).any(axis=0) |
              (hbond_mask & res_dist_mask).any(axis=1) |
              (ca_mask & res_dist_mask).any(axis=0))
    res_dict['isbeta'][np.argwhere(res_dict['isbeta']).flatten()[~p_mask]] = False

    # Ignore groups smaller than 3
    res_mask_beta = np.argwhere(res_dict['isbeta']).flatten()
    for mask_group in np.split(res_mask_beta, np.argwhere(np.diff(res_mask_beta) != 1).flatten() + 1):
        if 0 < len(mask_group) < 3:
            res_dict['isbeta'][mask_group] = False

    return res_dict
Esempio n. 18
0
 def peakmem_distance_complex(self):
     for mol in self.mols:
         distance(mol.coords, self.protein.coords)
Esempio n. 19
0
 def peakmem_distance_mol(self):
     for mol in self.mols:
         distance(mol.coords, mol.coords)
Esempio n. 20
0
 def time_distance_mol(self):
     for mol in self.mols:
         distance(mol.coords, mol.coords)
Esempio n. 21
0
 def peakmem_distance_protein(self):
     distance(self.protein.coords, self.protein.coords)
Esempio n. 22
0
 def time_distance_protein(self):
     distance(self.protein.coords, self.protein.coords)
Esempio n. 23
0
def calc_pi_cation_interactions(protein,
                                mol,
                                key_inters_defs,
                                mol_key_inters,
                                filter_strict=False,
                                exact_protein=False,
                                exact_ligand=False):
    """
    Pi-cation calculations are directional so are run in both directions (protein->ligand and ligand-> protein).
    Hence this method runs the pi_cation() calculation twice.
    :param protein:
    :param mol:
    :param key_inters_defs:
    :param mol_key_inters:
    :param filter_strict:
    :param exact_protein:
    :param exact_ligand:
    :return:
    """
    inters = {}
    # first treat the protein as the pi and the ligand as the cation
    rings, cation, strict = oddt.interactions.pi_cation(
        protein, mol, cation_exact=exact_ligand)
    for ring, cat, s in zip(rings, cation, strict):
        if s or not filter_strict:
            dist = spatial.distance(np.array([ring['centroid']]),
                                    np.array([cat['coords']]))[0][0]
            c = get_canonical_residue(ring)
            p_coords = (ring['centroid'][0].item(), ring['centroid'][1].item(),
                        ring['centroid'][2].item())
            l_coords = (cat['coords'][0].item(), cat['coords'][1].item(),
                        cat['coords'][2].item())
            t = interactions.Interaction(c, p_coords, l_coords, dist, None)

            if c in inters:
                current_value = inters[c]
                if dist < current_value.distance:
                    inters[c] = t
            else:
                inters[c] = t
                if key_inters_defs and c in key_inters_defs:
                    mol_key_inters.append(interactions.I_TYPE_PI_CATION + ':' +
                                          c)

    # now with the ligand as the pi and the protein as the cation
    rings, cation, strict = oddt.interactions.pi_cation(
        mol, protein, cation_exact=exact_protein)
    for ring, cat, s in zip(rings, cation, strict):
        if s or not filter_strict:
            dist = spatial.distance(np.array([ring['centroid']]),
                                    np.array([cat['coords']]))[0][0]
            c = get_canonical_residue(ring)
            p_coords = (cat['coords'][0].item(), cat['coords'][1].item(),
                        cat['coords'][2].item())
            l_coords = (ring['centroid'][0].item(), ring['centroid'][1].item(),
                        ring['centroid'][2].item())
            t = interactions.Interaction(c, p_coords, l_coords, dist, None)

            if c in inters:
                current_value = inters[c]
                if dist < current_value.distance:
                    inters[c] = t
            else:
                inters[c] = t
                if key_inters_defs and c in key_inters_defs:
                    mol_key_inters.append(interactions.I_TYPE_PI_CATION + ':' +
                                          c)

    if inters:
        return interactions.InteractionType(interactions.I_NAME_PI_CATION,
                                            list(inters.values()))
    else:
        return None
Esempio n. 24
0
 def peakmem_distance_complex(self):
     for mol in self.mols:
         distance(mol.coords, self.protein.coords)
Esempio n. 25
0
 def peakmem_distance_mol(self):
     for mol in self.mols:
         distance(mol.coords, mol.coords)
Esempio n. 26
0
 def time_distance_mol(self):
     for mol in self.mols:
         distance(mol.coords, mol.coords)
Esempio n. 27
0
 def time_distance_protein(self):
     distance(self.protein.coords, self.protein.coords)