Exemple #1
0
def delete_shell(core_mol, del_mol, cut_off, in_out='in'):
    """
    This function deletes molecules present in the passed argument
    del_mol that are far (in_out=out) or close (in_out=in) than the
    selected cutoff distance (in A) from the passed molecules core_mol

    Parameters:
    -----------
    core_mol: OEMol molecule
        The core molecules
    del_mol: OEMol molecule
        The molecules to be deleted if their distances from the core_mol
        molecules are greater or closer that the selected cutoff distance
    cut_off: python float number
        The threshold distance in A used to mark atom for deletion
    in_out: python string
        A flag used to select if delete molecules far or close than
        the cutoff distance from the core_mol

    Return:
    -------
    reset_del: copy of del_mol where atoms have been deleted with
        reset atom indexes
    """

    if in_out not in ['in', 'out']:
        raise ValueError(
            "The passed in_out parameter is not recognized: {}".format(in_out))

    # Copy the passed molecule to delete in
    to_del = oechem.OEMol(del_mol)

    # Create a OE bit vector mask for each atoms of the
    # molecule to delete
    bv = oechem.OEBitVector(to_del.GetMaxAtomIdx())
    bv.NegateBits()

    # Create the Nearest neighbours
    nn = oechem.OENearestNbrs(to_del, cut_off)
    for nbrs in nn.GetNbrs(core_mol):
        # bv.SetBitOff(nbrs.GetBgn().GetIdx())
        for atom in oechem.OEGetResidueAtoms(nbrs.GetBgn()):
            bv.SetBitOff(atom.GetIdx())

    # Invert selection mask
    if in_out == 'in':
        bv.NegateBits()

    pred = oechem.OEAtomIdxSelected(bv)
    for atom in to_del.GetAtoms(pred):
        to_del.DeleteAtom(atom)

    # It is necessary to reset the atom indexes of the molecule with
    # delete atoms to avoid possible mismatching
    reset_del = oechem.OEMol(to_del)

    return reset_del
Exemple #2
0
def LigandProteinCloseContacts(prot, lig, maxgap):
    """atoms in the protein within maxgap Angstroms of the ligand"""

    oechem.OESuppressHydrogens(prot)
    oechem.OESuppressHydrogens(lig)

    DropLigandFromProtein(prot, lig)

    nn = oechem.OENearestNbrs(prot, maxgap)

    return list(nn.GetNbrs(lig))
Exemple #3
0
def check_shell(core_mol, check_mol, cutoff):
    """
    This function checks if at least one atomic distance from the passed
    check_mol molecule to the core_mol molecule is less than the selected
    cutoff distance in A.

    Parameters:
    -----------
    core_mol: OEMol molecule
        The core molecule
    check_mol: OEMol molecule
        The molecule to be checked if inside or outside a shell
        surrounding the core_mole with radius equal to the cutoff
        threshold
    cut_off: python float number
        The threshold distance in A used to mark atom inside or outside
        the shell

    Return:
    -------
    in_out: python boolean
         True if at least one of check_mol atom distance from core_mole
         is less than the selected cutoff threshold
    """

    # Create a OE bit vector mask for each atoms of the
    # molecule to be checked
    bv = oechem.OEBitVector(check_mol.GetMaxAtomIdx())

    # Create the Nearest neighbours
    nn = oechem.OENearestNbrs(check_mol, cutoff)

    # Check neighbours setting the atom bit mask
    for nbrs in nn.GetNbrs(core_mol):
        bv.SetBitOn(nbrs.GetBgn().GetIdx())

    # Create predicate based on the atom bit mask
    pred = oechem.OEAtomIdxSelected(bv)

    # Checking flag
    in_out = False

    # If just one chem_mol atom is inside the cutoff distance return True
    for atom in check_mol.GetAtoms(pred):
        in_out = True
        break

    return in_out
Exemple #4
0
def SetAverageBFactorOfNearbyProteinAtoms(ligand, protein, itag, maxdistance=4.0):

    nn = oechem.OENearestNbrs(protein, maxdistance)
    for latom in ligand.GetAtoms(oechem.OEIsHeavy()):
        sumbfactor = 0.0
        neighs = []
        for neigh in nn.GetNbrs(latom):
            ratom = neigh.GetBgn()
            res = oechem.OEAtomGetResidue(ratom)
            if ConsiderResidueAtom(ratom, res):
                sumbfactor += res.GetBFactor()
                neighs.append(ratom)

        avgbfactor = 0.0
        if len(neighs) > 0:
            avgbfactor = sumbfactor / len(neighs)
        latom.SetDoubleData(itag, avgbfactor)
Exemple #5
0
def GetMinAndMaxBFactor(ligand, protein, maxdistance=4.0):

    minbfactor = float("inf")
    maxbfactor = float("-inf")

    # Ligand atoms
    for latom in ligand.GetAtoms(oechem.OEIsHeavy()):
        res = oechem.OEAtomGetResidue(latom)
        minbfactor = min(minbfactor, res.GetBFactor())
        maxbfactor = max(maxbfactor, res.GetBFactor())

    # Protein atoms close to ligand atoms
    nn = oechem.OENearestNbrs(protein, maxdistance)
    for latom in ligand.GetAtoms(oechem.OEIsHeavy()):
        for neigh in nn.GetNbrs(latom):
            ratom = neigh.GetBgn()
            res = oechem.OEAtomGetResidue(ratom)
            if ConsiderResidueAtom(ratom, res):
                minbfactor = min(minbfactor, res.GetBFactor())
                maxbfactor = max(maxbfactor, res.GetBFactor())

    return minbfactor, maxbfactor
Exemple #6
0
        def around(dist, ls):
            """
            This function select atom not far than the threshold distance from
            the current selection. The threshold distance is in Angstrom

            selection can be:
            mask = '5.0 around ligand'
            """
            # at = system.GetAtom(oechem.OEHasAtomIdx(idx))

            # Atom set selection
            atom_set_around = set()

            # Create a OE bit vector mask for each atoms
            bv_around = oechem.OEBitVector(system.GetMaxAtomIdx())

            # Set the mask atom
            for at in system.GetAtoms():
                if at.GetIdx() in ls:
                    bv_around.SetBitOn(at.GetIdx())

            # Predicate
            pred = oechem.OEAtomIdxSelected(bv_around)

            # Create the system molecule based on the atom mask
            molecules = oechem.OEMol()
            oechem.OESubsetMol(molecules, system, pred)

            # Create the Nearest neighbours
            nn = oechem.OENearestNbrs(system, float(dist))

            for nbrs in nn.GetNbrs(molecules):
                for atom in oechem.OEGetResidueAtoms(nbrs.GetBgn()):
                    if atom.GetIdx() in ls:
                        continue
                    atom_set_around.add(atom.GetIdx())

            return atom_set_around
Exemple #7
0
def DropLigandFromProtein(prot, lig):
    """delete atoms from the protein w/same coords as the ligand
    as well as any waters"""

    approximatelyTheSame = 0.05
    nn = oechem.OENearestNbrs(prot, approximatelyTheSame)

    # mark ligand atoms for deletion
    bv = oechem.OEBitVector(prot.GetMaxAtomIdx())
    for nbrs in nn.GetNbrs(lig):
        r1 = oechem.OEAtomGetResidue(nbrs.GetBgn())
        r2 = oechem.OEAtomGetResidue(nbrs.GetEnd())
        if r1.GetModelNumber() == r2.GetModelNumber():
            bv.SetBitOn(nbrs.GetBgn().GetIdx())

    # mark waters for deletion too
    for atom in prot.GetAtoms():
        res = oechem.OEAtomGetResidue(atom)
        if oechem.OEGetResidueIndex(res) == oechem.OEResidueIndex_HOH:
            bv.SetBitOn(atom.GetIdx())

    pred = oechem.OEAtomIdxSelected(bv)
    for atom in prot.GetAtoms(pred):
        prot.DeleteAtom(atom)
 def __init__(self, prot_mol, cutoff=2.0):
     self.near_nbr = oechem.OENearestNbrs(prot_mol, cutoff)
     self.cutoff = cutoff