Example #1
0
def main(argv=[__name__]):
    if len(argv) != 4:
        oechem.OEThrow.Usage("%s <prot-infile> <lig-infile> <max-distance>" %
                             argv[0])

    ifs = oechem.oemolistream()
    if not ifs.open(argv[1]):
        oechem.OEThrow.Fatal("Unable to open protein %s for reading" % argv[1])

    prot = oechem.OEGraphMol()
    oechem.OEReadMolecule(ifs, prot)
    if not oechem.OEHasResidues(prot):
        oechem.OEPerceiveResidues(prot, oechem.OEPreserveResInfo_All)

    ifs = oechem.oemolistream()
    if not ifs.open(argv[2]):
        oechem.OEThrow.Fatal("Unable to open ligand %s for reading" % argv[2])

    lig = oechem.OEGraphMol()
    oechem.OEReadMolecule(ifs, lig)
    if not oechem.OEHasResidues(lig):
        oechem.OEPerceiveResidues(lig, oechem.OEPreserveResInfo_All)

    maxgap = float(argv[3])

    PrintCloseContacts(prot, lig, maxgap)
Example #2
0
def ResHist(ifs):
    nrmol = 0
    mol = oechem.OEGraphMol()
    while oechem.OEReadMolecule(ifs, mol):
        nrmol += 1
        print("==============================")
        print("Molecule: %d Title: %s" % (nrmol, mol.GetTitle()))

        nrres = 0
        resmap = {}
        if not oechem.OEHasResidues(mol):
            oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)
        hv = oechem.OEHierView(mol)
        for res in hv.GetResidues():
            nrres += 1
            name = res.GetOEResidue().GetName()
            if name in resmap:
                resmap[name] += 1
            else:
                resmap[name] = 1

    sortedres = sorted(resmap.keys())
    for name in sortedres:
        percent = 100.0*float(resmap[name])/float(nrres)
        print("%3s %3d  %4.1f %%" % (name, resmap[name], percent))
Example #3
0
def CisCheck(ifs):
    nrmol = 0
    nrcis = 0
    mol = oechem.OEGraphMol()
    while oechem.OEReadMolecule(ifs, mol):
        nrmol += 1
        print("===========================================================")
        print("Molecule: %s   Title: %s" % (nrmol, mol.GetTitle()))
        if not oechem.OEHasResidues(mol):
            oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)
        hv = oechem.OEHierView(mol)
        resiter = oechem.ConstOEHierResidueIter()
        resiter = hv.GetResidues()
        while (resiter.IsValid()):
            res = resiter.Target()
            resiter.Next()
            if not oechem.OEIsStandardProteinResidue(res):
                continue
            torsion = oechem.OEGetTorsion(res, oechem.OEProtTorType_Omega)
            if torsion != -100.0:
                if torsion < math.pi / 2.0 and torsion > -math.pi / 2.0:
                    if resiter.IsValid():
                        nextres = resiter.Target()
                        oenextres = nextres.GetOEResidue()
                        if oechem.OEGetResidueIndex(
                                oenextres) == oechem.OEResidueIndex_PRO:
                            continue
                    nrcis += 1
                    oeres = res.GetOEResidue()
                    print("%s %s %2d omega torsion = %.2f degree" %
                          (oeres.GetName(), oeres.GetChainID(),
                           oeres.GetResidueNumber(),
                           torsion * oechem.cvar.Rad2Deg))
        print(" %d cis amide bond(s) identified\n" % nrcis)
Example #4
0
def ResCount(ifs):
    nrmol = 0
    mol = oechem.OEGraphMol()
    while oechem.OEReadMolecule(ifs, mol):
        nrmol += 1
        nratom = 0
        nrwat = 0
        nrres = 0
        nrfrag = 0
        nrchain = 0
        if not oechem.OEHasResidues(mol):
            oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)
        hv = oechem.OEHierView(mol)
        for chain in hv.GetChains():
            nrchain += 1
            for frag in chain.GetFragments():
                nrfrag += 1
                for res in frag.GetResidues():
                    nrres += 1
                    if oechem.OEGetResidueIndex(res.GetOEResidue()) == oechem.OEResidueIndex_HOH:
                        nrwat += 1
                    else:
                        for atom in res.GetAtoms():
                            nratom += 1

        print("===============================================")
        print("Molecule : %d Title: %s" % (nrmol, mol.GetTitle()))
        print("Chains   : %d" % nrchain)
        print("Fragments: %d" % nrfrag)
        print("Residues : %d (%d waters)" % (nrres, nrwat))
        print("Atoms    : %d" % nratom)
Example #5
0
def main(argv=[__name__]):
    if len(argv) != 3:
        oechem.OEThrow.Usage("%s <molfile.pdb> <out.srf>" % argv[0])

    mol = oechem.OEGraphMol()
    ifs = oechem.oemolistream(argv[1])
    oechem.OEReadMolecule(ifs, mol)
    if not oechem.OEHasResidues(mol):
        oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)

    serials = {}
    for atom in mol.GetAtoms():
        res = oechem.OEAtomGetResidue(atom)
        serials[res.GetSerialNumber()] = atom

    outsurf = oespicoli.OESurface()
    center = oechem.OEFloatArray(3)
    for line in open(argv[1]):
        if line.startswith("ANISOU"):
            serno, factors = ParseFactors(line)
            if serno in serials:
                mol.GetCoords(serials[serno], center)
                surf = GetEllipsoidalSurface(center, factors)
                oespicoli.OEAddSurfaces(outsurf, surf)

    oespicoli.OEWriteSurface(argv[2], outsurf)
def set_serial(molecule, chainid, first_serial):
    import oechem
    if not oechem.OEHasResidues(molecule):
        oechem.OEPerceiveResidues(molecule, oechem.OEPreserveResInfo_All)
    for atom in molecule.GetAtoms():
        residue = oechem.OEAtomGetResidue(atom)
        residue.SetExtChainID(chainid)
        serial_number = residue.GetSerialNumber()
        residue.SetSerialNumber(serial_number + first_serial)
Example #7
0
def MakeAlpha(ifs, ofs):
    phival = math.pi / -3.0
    psival = math.pi / -3.0
    chival = math.pi
    nrphis = 0
    nrpsis = 0
    nrchis = 0
    mol = oechem.OEGraphMol()
    while oechem.OEReadMolecule(ifs, mol):
        if not oechem.OEHasResidues(mol):
            oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)
        # remove cross-links
        for bond in mol.GetBonds():
            if bond.GetBgn().GetAtomicNum() == oechem.OEElemNo_S and \
               bond.GetEnd().GetAtomicNum() == oechem.OEElemNo_S:
                mol.DeleteBond(bond)

        oechem.OEFindRingAtomsAndBonds(mol)
        hv = oechem.OEHierView(mol)
        for res in hv.GetResidues():
            if not oechem.OEIsStandardProteinResidue(res):
                continue

            # set psi and phi angles
            if not oechem.OESetTorsion(res, oechem.OEProtTorType_Phi, phival):
                oeres = res.GetOEResidue()
                print("Unable to set phi for %s %d" %
                      (oeres.GetName(), oeres.GetResidueNumber()))
            else:
                nrphis += 1

            if not oechem.OESetTorsion(res, oechem.OEProtTorType_Psi, psival):
                oeres = res.GetOEResidue()
                print("Unable to set psi for %s %d" %
                      (oeres.GetName(), oeres.GetResidueNumber()))
            else:
                nrpsis += 1

            # set chis
            if oechem.OEGetResidueIndex(
                    res.GetOEResidue().GetName()) == oechem.OEResidueIndex_PRO:
                continue  # It does not make sense to set Proline chi angles to 180

            for chi in oechem.OEGetChis(res):
                if not oechem.OESetTorsion(res, chi, chival):
                    oeres = res.GetOEResidue()
                    print("Unable to set chi %s for %s %d" %
                          (oechem.OEGetProteinTorsionName(chi),
                           oeres.GetName(), oeres.GetResidueNumber()))
                else:
                    nrchis += 1
        oechem.OEWriteMolecule(ofs, mol)

    print(nrphis, " phi  torsion angle set to ", phival * oechem.cvar.Rad2Deg)
    print(nrpsis, " psi  torsion angle set to ", psival * oechem.cvar.Rad2Deg)
    print(nrchis, " chis torsion angle set to ", chival * oechem.cvar.Rad2Deg)
def PrintAltGroupInfo(mol):
    if not oechem.OEHasResidues(mol):
        oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)

    alf = oechem.OEAltLocationFactory(mol)  # create factory for mol

    print("%s\t(%s groups)" % (mol.GetTitle(), alf.GetGroupCount()))

    for grp in alf.GetGroups():
        print("\t%s locs:%s" %
              (grp.GetLocationCount(), alf.GetLocationCodes(grp)))
Example #9
0
def main(argv=[__name__]):
    if len(argv) != 2:
        oechem.OEThrow.Usage("%s <mol-infile>" % argv[0])

    ims = oechem.oemolistream()
    if not ims.open(argv[1]):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])

    for mol in ims.GetOEGraphMols():
        if not oechem.OEHasResidues(mol):
            oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)
        CalcResCounts(mol)
def PrintGroups(mol):
    """summarize alternate location group info"""
    if not oechem.OEHasResidues(mol):
        oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)

    alf = oechem.OEAltLocationFactory(mol)

    print("%s\t(%s groups)" % (mol.GetTitle(), alf.GetGroupCount()))

    for grp in alf.GetGroups():
        print("\t%s locs:%s" %
              (grp.GetLocationCount(), alf.GetLocationCodes(grp)))
Example #11
0
def PrintResidues(mol):
    """list alternate location code and occupancy by group and residue"""
    if not oechem.OEHasResidues(mol):
        oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)

    alf = oechem.OEAltLocationFactory(mol)

    print("%s - %d alternate location groups:" %
          (mol.GetTitle(), alf.GetGroupCount()))

    for grp in alf.GetGroups():
        print("%d) %d alternate locations" %
              (grp.GetGroupID() + 1, grp.GetLocationCount()),
              end=" ")

        prev = oechem.OEResidue()
        prevCodes = ""
        sumOcc = []
        atNum = []

        for atom in alf.GetAltAtoms(grp):
            res = oechem.OEAtomGetResidue(atom)
            if not oechem.OESameResidue(res, prev):
                for i, code in enumerate(prevCodes):
                    print("%c(%.0f%c) " %
                          (code, (sumOcc[i] * 100.0) / atNum[i], "%"),
                          end=" ")
                print()
                prevCodes = ""
                sumOcc = []
                atNum = []

                print("\t%s%d%c chain '%c': " %
                      (res.GetName(), res.GetResidueNumber(),
                       res.GetInsertCode(), res.GetChainID()),
                      end=" ")
                prev = res

            code = res.GetAlternateLocation()
            whichCode = prevCodes.find(code)
            if whichCode < 0:
                prevCodes += code
                sumOcc.append(res.GetOccupancy())
                atNum.append(1)
            else:
                sumOcc[whichCode] += res.GetOccupancy()
                atNum[whichCode] += 1

        for i, code in enumerate(prevCodes):
            print("%c(%.0f%c) " % (code, (sumOcc[i] * 100.0) / atNum[i], "%"),
                  end=" ")
        print()
Example #12
0
def LoopOverResAtoms(ims):
    for mol in ims.GetOEGraphMols():
        # @ <SNIPPET-PERCEIVE-RES>
        if not oechem.OEHasResidues(mol):
            oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)
        # @ </SNIPPET-PERCEIVE-RES>

        # @ <SNIPPET-RES-ATOMS-CORE>
        hv = oechem.OEHierView(mol)
        hres = hv.GetResidue("A", "LEU", 27)
        for atom in hres.GetAtoms():  # only this residue's atoms
            res = oechem.OEAtomGetResidue(atom)
            print(res.GetSerialNumber(), atom.GetName())
Example #13
0
def BackBone(ifs, ofs):
    adjustHCount = True
    mol = oechem.OEGraphMol()
    backboneMol = oechem.OEGraphMol()

    while oechem.OEReadMolecule(ifs, mol):
        if not oechem.OEHasResidues(mol):
            oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)
        aiter = mol.GetAtoms(oechem.OEIsBackboneAtom())
        member = oechem.OEIsAtomMember(aiter)

        oechem.OESubsetMol(backboneMol, mol, member, adjustHCount)
        oechem.OEWriteMolecule(ofs, backboneMol)
Example #14
0
def main(argv=[__name__]):

    itf = oechem.OEInterface(InterfaceData)

    if not oechem.OEParseCommandLine(itf, argv):
        oechem.OEThrow.Fatal("Unable to interpret command line!")

    # @ <SNIPPET-ALTLOCFACT-FLAVOR>
    ims = oechem.oemolistream()
    ims.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_ALTLOC)
    # @ </SNIPPET-ALTLOCFACT-FLAVOR>

    inputFile = itf.GetString("-in")
    if not ims.open(inputFile):
        oechem.OEThrow.Fatal("Unable to open %s for reading." % inputFile)

    if not oechem.OEIs3DFormat(ims.GetFormat()):
        oechem.OEThrow.Fatal("%s is not in a 3D format." % inputFile)

    mol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ims, mol):
        oechem.OEThrow.Fatal("Unable to read %s." % inputFile)

    if not oechem.OEHasResidues(mol):
        oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)

    # @ <SNIPPET-ALTLOCFACT-PRIMARY>
    alf = oechem.OEAltLocationFactory(mol)
    if alf.GetGroupCount() != 0:
        alf.MakePrimaryAltMol(mol)
    # @ </SNIPPET-ALTLOCFACT-PRIMARY>

    # @ <SNIPPET-PLACE-HYDROGENS-BASIC>
    if oechem.OEPlaceHydrogens(mol):
        # ...
        # @ </SNIPPET-PLACE-HYDROGENS-BASIC>
        print("success")

    # @ <SNIPPET-PLACE-HYDROGENS-OPTIONS>
    opt = oechem.OEPlaceHydrogensOptions()
    opt.SetStandardizeBondLen(False)
    # @ </SNIPPET-PLACE-HYDROGENS-OPTIONS>

    # @ <SNIPPET-PLACE-HYDROGENS-DETAILS>
    # given molecule mol and OEPlaceHydrogensOptions opt...
    details = oechem.OEPlaceHydrogensDetails()
    if oechem.OEPlaceHydrogens(mol, details, opt):
        print(details.Describe())
    # @ </SNIPPET-PLACE-HYDROGENS-DETAILS>

    ims.close()
def CalcResCounts(mol):
    if not oechem.OEHasResidues(mol):
        oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)
    resCt = 0
    hetCt = 0
    prevRes = oechem.OEResidue()
    for atom in mol.GetAtoms():
        thisRes = oechem.OEAtomGetResidue(atom)
        if not oechem.OESameResidue(prevRes, thisRes):
            resCt += 1
            if thisRes.IsHetAtom():
                hetCt += 1
            prevRes = thisRes
    print("Molecule: %s" % mol.GetTitle())
    print("Residues: %d (%d hets)" % (resCt, hetCt))
Example #16
0
def main(argv=[__name__]):

    itf = oechem.OEInterface(InterfaceData)

    if not oechem.OEParseCommandLine(itf, argv):
        oechem.OEThrow.Fatal("Unable to interpret command line!")

    ims = oechem.oemolistream()
    ims.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_ALTLOC)

    inputFile = itf.GetString("-in")
    if not ims.open(inputFile):
        oechem.OEThrow.Fatal("Unable to open %s for reading." % inputFile)

    if not oechem.OEIs3DFormat(ims.GetFormat()):
        oechem.OEThrow.Fatal("%s is not in a 3D format." % inputFile)

    mol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ims, mol):
        oechem.OEThrow.Fatal("Unable to read %s." % inputFile)

    if not oechem.OEHasResidues(mol):
        oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)

    alf = oechem.OEAltLocationFactory(mol)
    if alf.GetGroupCount() != 0:
        alf.MakePrimaryAltMol(mol)

    # in our example, we will select the first histidine
    selectedResidue = oechem.OEResidue()
    for atom in mol.GetAtoms():
        res = oechem.OEAtomGetResidue(atom)
        if oechem.OEGetResidueIndex(res) == oechem.OEResidueIndex_HIS:
            selectedResidue = res
            break

    # @ <SNIPPET-PLACE-HYDROGENS-PRED>
    # given predicate IsSameResidue, residue selectedResidue and molecule mol...
    opt = oechem.OEPlaceHydrogensOptions()
    opt.SetNoFlipPredicate(IsSameResidue(selectedResidue))

    if oechem.OEPlaceHydrogens(mol, opt):
        # selectedResidue will not be flipped...
        # @ </SNIPPET-PLACE-HYDROGENS-PRED>
        print("success")

    ims.close()
Example #17
0
def get_protein_and_ligands(protein, ligand, itf):

    if (itf.HasString("-complex")):

        # separate ligand and protein in complex

        iname = itf.GetString("-complex")

        ifs = oechem.oemolistream()
        if not ifs.open(iname):
            oechem.OEThrow.Fatal("Cannot open input complex file!")

        complexmol = oechem.OEGraphMol()
        if not oechem.OEReadMolecule(ifs, complexmol):
            oechem.OEThrow.Fatal("Unable to read complex from %s" % iname)

        if not oechem.OEHasResidues(complexmol):
            oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All)

        sopts = oechem.OESplitMolComplexOptions()
        oechem.OESetupSplitMolComplexOptions(sopts, itf)

        if not split_complex(protein, ligand, sopts, complexmol):
            oechem.OEThrow.Fatal("Cannot separate complex!")
    else:

        # read ligand and protein from separate files

        pname = itf.GetString("-protein")

        ifs = oechem.oemolistream()
        if not ifs.open(pname):
            oechem.OEThrow.Fatal("Cannot open input protein file!")

        if not oechem.OEReadMolecule(ifs, protein):
            oechem.OEThrow.Fatal("Unable to read protein from %s" % pname)

        lname = itf.GetString("-ligand")

        ifs = oechem.oemolistream()
        if not ifs.open(lname):
            oechem.OEThrow.Fatal("Cannot open input ligand file!")

        if not oechem.OEReadMolecule(ifs, ligand):
            oechem.OEThrow.Fatal("Unable to read ligand from %s" % lname)

    return ligand.NumAtoms() != 0 and protein.NumAtoms() != 0
def PrintLocations(mol, hideAtoms):
    """list alternate location codes and atom info (unless hideAtoms is True)"""
    if not oechem.OEHasResidues(mol):
        oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)

    alf = oechem.OEAltLocationFactory(mol)

    print("%s" % mol.GetTitle())

    print("grp-cnt=%d" % alf.GetGroupCount(), end=" ")
    if alf.GetGroupCount() > 0:
        print("{")
    else:
        print()

    for grp in alf.GetGroups():
        print(" grp=%d loc-cnt=%d grp-codes='%s'" %
              (grp.GetGroupID(), grp.GetLocationCount(),
               alf.GetLocationCodes(grp)))
        for loc in grp.GetLocations():
            print(" grp=%d loc=%d loc-codes='%s'" %
                  (loc.GetGroupID(), loc.GetLocationID(),
                   alf.GetLocationCodes(loc)),
                  end=" ")
            if not hideAtoms:
                print("[", end=" ")
            num_atoms = 0
            for atom in alf.GetAltAtoms(loc):
                num_atoms += 1
                if not hideAtoms:
                    res = oechem.OEAtomGetResidue(atom)
                    print("%s:%c:%s%d%c:c%cm%d;" %
                          (atom.GetName(), res.GetAlternateLocation(),
                           res.GetName(), res.GetResidueNumber(),
                           res.GetInsertCode(), res.GetChainID(),
                           res.GetModelNumber()),
                          end=" ")
            if not hideAtoms:
                print("]", end=" ")
            print(num_atoms)

    if alf.GetGroupCount() > 0:
        print("}")
Example #19
0
def Rename(ims, oms):
    for mol in ims.GetOEGraphMols():
        # @ <SNIPPET-PERCEIVE-RES>
        if not oechem.OEHasResidues(mol):
            oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)
        # @ </SNIPPET-PERCEIVE-RES>
        # @ <SNIPPET-MSE-TO-MET-CORE>
        for atom in mol.GetAtoms():
            thisRes = oechem.OEAtomGetResidue(atom)
            if oechem.OEGetResidueIndex(thisRes) == oechem.OEResidueIndex_MSE:
                thisRes.SetName("MET")  # modify res properties
                thisRes.SetHetAtom(False)
                oechem.OEAtomSetResidue(atom, thisRes)  # store updated residue

                if atom.GetAtomicNum() == oechem.OEElemNo_Se:
                    atom.SetAtomicNum(
                        oechem.OEElemNo_S)  # fix atom type & name
                    atom.SetName(" SD ")
        # @ </SNIPPET-MSE-TO-MET-CORE>
        oechem.OEWriteMolecule(oms, mol)
Example #20
0
def SubSetRes(ifs, ofs, chainid, resname, resnum):
    adjustHCount = True
    mol = oechem.OEGraphMol()
    while oechem.OEReadMolecule(ifs, mol):
        if not oechem.OEHasResidues(mol):
            oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)
        hv = oechem.OEHierView(mol)
        res = hv.GetResidue(chainid, resname, resnum)
        if res.GetOEResidue().GetName() is None:
            oechem.OEThrow.Fatal("Failed to find residue")
        atomiter = res.GetAtoms()
        member = oechem.OEIsAtomMember(atomiter)
        resmol = oechem.OEGraphMol()
        oechem.OESubsetMol(resmol, mol, member, adjustHCount)
        if chainid == " ":
            resmol.SetTitle("%s %d" % (resname, resnum))
        else:
            resmol.SetTitle("%s %s %d" % (resname, chainid, resnum))

        oechem.OEWriteMolecule(ofs, resmol)
Example #21
0
def PrintStates(mol):
    """list alternate location state information"""
    if not oechem.OEHasResidues(mol):
        oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)

    alf = oechem.OEAltLocationFactory(mol)

    print("%s\t%d groups" % (mol.GetTitle(), alf.GetGroupCount()), end=" ")

    tot = 1
    totexp = 0.0
    for grp in alf.GetGroups():
        tot *= grp.GetLocationCount()
        totexp += math.log10(grp.GetLocationCount())

    if totexp > 7.0:
        print("\tover 10^%.0f states" % totexp)
        print("too many states to enumerate")
    else:
        print("\t%d states" % tot)
        locs = [grp.GetLocations() for grp in alf.GetGroups()]
        EnumerateStates(alf, locs, 0, len(locs))
Example #22
0
    def __init__(self, ipf, keepAlts=F, verbose=T):
        self.ipf = ipf
        self.keepAlts = keepAlts
        self.verbose = verbose

        flavor = oechem.OEIFlavor_PDB_Default
        ims = oechem.oemolistream()
        ims.SetFlavor(oechem.OEFormat_PDB, flavor)

        if not ims.open(self.ipf):
            oechem.OEThrow.Fatal("Unable to open %s for reading." % self.ipf)

        if not oechem.OEIs3DFormat(ims.GetFormat()):
            oechem.OEThrow.Fatal("%s is not in a 3D format." % self.ipf)

        iftp = oechem.OEGetFileType(oechem.OEGetFileExtension(self.ipf))
        if (iftp == oechem.OEFormat_PDB) and not self.keepAlts:
            oechem.OEThrow.Verbose(
                "Default processing of alt locations (keep just 'A' and ' ').")

        inmol = oechem.OEGraphMol()
        if not oechem.OEReadMolecule(ims, inmol):
            oechem.OEThrow.Fatal("Unable to read %s." % self.ipf)

        ims.close()

        if (inmol.NumAtoms() == 0):
            oechem.OEThrow.Fatal("Input molecule %s contains no atoms." %
                                 self.ipf)

        if inmol.GetTitle() == "":
            inmol.SetTitle(ipf[:-4])

        oechem.OEThrow.Verbose("Processing %s." % inmol.GetTitle())
        if not oechem.OEHasResidues(inmol):
            oechem.OEPerceiveResidues(inmol, oechem.OEPreserveResInfo_All)

        self.inmol = inmol
        self.mol = inmol.CreateCopy()
Example #23
0
def ShowPhiPsi(ifs):
    nrmol = 0
    mol = oechem.OEGraphMol()
    while oechem.OEReadMolecule(ifs, mol):
        nrmol += 1
        print("================================================")
        print("Molecule: %d  Title: %s" % (nrmol, mol.GetTitle()))

        if not oechem.OEHasResidues(mol):
            oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)
        hv = oechem.OEHierView(mol)

        for res in hv.GetResidues():
            if not oechem.OEIsStandardProteinResidue(res):
                continue

            phi = oechem.OEGetPhi(res)
            psi = oechem.OEGetPsi(res)

            oeres = res.GetOEResidue()
            print("  %s %s %d (PHI=%.2f, PSI=%.2f)" % (oeres.GetName(),
                                                       oeres.GetChainID(),
                                                       oeres.GetResidueNumber(),
                                                       phi, psi))
Example #24
0
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oechem.OEConfigureSplitMolComplexOptions(
        itf, oechem.OESplitMolComplexSetup_LigName)

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    iname = itf.GetString("-complex")

    ifs = oechem.oemolistream()
    if not ifs.open(iname):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % iname)

    complexmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, complexmol):
        oechem.OEThrow.Fatal("Unable to read molecule from %s" % iname)

    if not oechem.OEHasResidues(complexmol):
        oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All)

    # Separate ligand and protein

    sopts = oechem.OESplitMolComplexOptions()
    oechem.OESetupSplitMolComplexOptions(sopts, itf)

    ligand = oechem.OEGraphMol()
    protein = oechem.OEGraphMol()
    water = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    pfilter = sopts.GetProteinFilter()
    wfilter = sopts.GetWaterFilter()
    sopts.SetProteinFilter(oechem.OEOrRoleSet(pfilter, wfilter))
    sopts.SetWaterFilter(
        oechem.OEMolComplexFilterFactory(
            oechem.OEMolComplexFilterCategory_Nothing))

    oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts)

    if ligand.NumAtoms() == 0:
        oechem.OEThrow.Fatal("Cannot separate complex!")

    # Perceive interactions

    asite = oechem.OEInteractionHintContainer(protein, ligand)
    if not oechem.OEIsValidActiveSite(asite):
        oechem.OEThrow.Fatal("Cannot initialize active site!")

    oechem.OEPerceiveInteractionHints(asite)

    print("Number of interactions:", asite.NumInteractions())
    for itype in oechem.OEGetActiveSiteInteractionHintTypes():
        numinters = asite.NumInteractions(
            oechem.OEHasInteractionHintType(itype))
        if numinters == 0:
            continue
        print("%d %s :" % (numinters, itype.GetName()))

        inters = [
            s for s in asite.GetInteractions(
                oechem.OEHasInteractionHintType(itype))
        ]
        print("\n".join(sorted(GetInteractionString(s) for s in inters)))

    print("\nResidue interactions:")
    for res in oechem.OEGetResidues(
            asite.GetMolecule(oechem.OEProteinInteractionHintComponent())):
        PrintResidueInteractions(asite, res)

    print("\nLigand atom interactions:")
    for atom in asite.GetMolecule(
            oechem.OELigandInteractionHintComponent()).GetAtoms():
        PrintLigandAtomInteractions(asite, atom)
Example #25
0
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oedepict.OEConfigureImageWidth(itf, 600.0)
    oedepict.OEConfigureImageHeight(itf, 600.0)
    oedepict.OEConfigure2DMolDisplayOptions(itf, oedepict.OE2DMolDisplaySetup_AromaticStyle)
    oechem.OEConfigureSplitMolComplexOptions(itf, oechem.OESplitMolComplexSetup_LigName)

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    iname = itf.GetString("-complex")
    oname = itf.GetString("-out")

    ifs = oechem.oemolistream()
    if not ifs.open(iname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    ext = oechem.OEGetFileExtension(oname)
    if not oedepict.OEIsRegisteredImageFile(ext):
        oechem.OEThrow.Fatal("Unknown image type!")

    ofs = oechem.oeofstream()
    if not ofs.open(oname):
        oechem.OEThrow.Fatal("Cannot open output file!")

    complexmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, complexmol):
        oechem.OEThrow.Fatal("Unable to read molecule from %s" % iname)

    if not oechem.OEHasResidues(complexmol):
        oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All)

    # Separate ligand and protein

    sopts = oechem.OESplitMolComplexOptions()
    oechem.OESetupSplitMolComplexOptions(sopts, itf)

    ligand = oechem.OEGraphMol()
    protein = oechem.OEGraphMol()
    water = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts)

    if ligand.NumAtoms() == 0:
        oechem.OEThrow.Fatal("Cannot separate complex!")

    # Calculate average BFactor of the whole complex

    avgbfactor = GetAverageBFactor(complexmol)

    # Calculate minimum and maximum BFactor of the ligand and its environment

    minbfactor, maxbfactor = GetMinAndMaxBFactor(ligand, protein)

    # Attach to each ligand atom the average BFactor of the nearby protein atoms

    stag = "avg residue BFfactor"
    itag = oechem.OEGetTag(stag)
    SetAverageBFactorOfNearbyProteinAtoms(ligand, protein, itag)

    oechem.OEThrow.Info("Average BFactor of the complex = %+.3f" % avgbfactor)
    oechem.OEThrow.Info("Minimum BFactor of the ligand and its environment = %+.3f" % minbfactor)
    oechem.OEThrow.Info("Maximum BFactor of the ligand and its environment = %+.3f" % maxbfactor)

    # Create image

    imagewidth, imageheight = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight(itf)
    image = oedepict.OEImage(imagewidth, imageheight)

    mframe = oedepict.OEImageFrame(image, imagewidth,
                                   imageheight * 0.90, oedepict.OE2DPoint(0.0, 0.0))
    lframe = oedepict.OEImageFrame(image, imagewidth, imageheight * 0.10,
                                   oedepict.OE2DPoint(0.0, imageheight * 0.90))

    opts = oedepict.OE2DMolDisplayOptions(mframe.GetWidth(), mframe.GetHeight(),
                                          oedepict.OEScale_AutoScale)
    oedepict.OESetup2DMolDisplayOptions(opts, itf)
    opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_WhiteMonochrome)

    # Create BFactor color gradient

    colorg = oechem.OELinearColorGradient()
    colorg.AddStop(oechem.OEColorStop(0.0, oechem.OEDarkBlue))
    colorg.AddStop(oechem.OEColorStop(10.0, oechem.OELightBlue))
    colorg.AddStop(oechem.OEColorStop(25.0, oechem.OEYellowTint))
    colorg.AddStop(oechem.OEColorStop(50.0, oechem.OERed))
    colorg.AddStop(oechem.OEColorStop(100.0, oechem.OEDarkRose))

    # Prepare ligand for depiction

    oegrapheme.OEPrepareDepictionFrom3D(ligand)
    arcfxn = BFactorArcFxn(colorg, itag)
    for atom in ligand.GetAtoms():
        oegrapheme.OESetSurfaceArcFxn(ligand, atom, arcfxn)
    opts.SetScale(oegrapheme.OEGetMoleculeSurfaceScale(ligand, opts))

    # Render ligand and visualize BFactor

    disp = oedepict.OE2DMolDisplay(ligand, opts)
    colorbfactor = ColorLigandAtomByBFactor(colorg)
    oegrapheme.OEAddGlyph(disp, colorbfactor, oechem.OEIsTrueAtom())
    oegrapheme.OEDraw2DSurface(disp)
    oedepict.OERenderMolecule(mframe, disp)

    # Draw color gradient

    opts = oegrapheme.OEColorGradientDisplayOptions()
    opts.SetColorStopPrecision(1)
    opts.AddMarkedValue(avgbfactor)
    opts.SetBoxRange(minbfactor, maxbfactor)

    oegrapheme.OEDrawColorGradient(lframe, colorg, opts)

    oedepict.OEWriteImage(oname, image)

    return 0
from openeye import oechem

if len(sys.argv) != 2:
    oechem.OEThrow.Usage("%s <mol-infile>" % sys.argv[0])

ims = oechem.oemolistream()
if not ims.open(sys.argv[1]):
    oechem.OEThrow.Fatal("Unable to open %s for reading" % sys.argv[1])

# @ <SNIPPET-ALTLOCFACT-MAKEALTMOL-FLAVOR>
ims.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_ALTLOC)
# @ </SNIPPET-ALTLOCFACT-MAKEALTMOL-FLAVOR>

for mol in ims.GetOEGraphMols():
    if not oechem.OEHasResidues(mol):
        oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All)

    # @ <SNIPPET-ALTLOCFACT-MAKEALTMOL-ALF>
    alf = oechem.OEAltLocationFactory(mol)
    # @ </SNIPPET-ALTLOCFACT-MAKEALTMOL-ALF>
    print("# atoms original.. %d" % alf.GetSourceMol().GetMaxAtomIdx())

    atom = alf.GetAltAtoms()
    if atom.IsValid():
        # @ <SNIPPET-ALTLOCFACT-MAKEALTMOL-SSMOL>
        # given OEAltLocationFactory alf and OEAtomBaseIter atom ...
        loc = alf.GetLocation(atom.next(), 'B')
        ssmol = oechem.OEGraphMol()
        if alf.MakeAltMol(ssmol, loc):
            # use the subset mol...
Example #27
0
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oedepict.OEConfigureImageWidth(itf, 900.0)
    oedepict.OEConfigureImageHeight(itf, 600.0)
    oedepict.OEConfigure2DMolDisplayOptions(
        itf, oedepict.OE2DMolDisplaySetup_AromaticStyle)
    oechem.OEConfigureSplitMolComplexOptions(
        itf, oechem.OESplitMolComplexSetup_LigName)

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    iname = itf.GetString("-complex")
    oname = itf.GetString("-out")

    ifs = oechem.oemolistream()
    if not ifs.open(iname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    ext = oechem.OEGetFileExtension(oname)
    if not oedepict.OEIsRegisteredImageFile(ext):
        oechem.OEThrow.Fatal("Unknown image type!")

    ofs = oechem.oeofstream()
    if not ofs.open(oname):
        oechem.OEThrow.Fatal("Cannot open output file!")

    complexmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, complexmol):
        oechem.OEThrow.Fatal("Unable to read molecule from %s" % iname)

    if not oechem.OEHasResidues(complexmol):
        oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All)

    # Separate ligand and protein

    sopts = oechem.OESplitMolComplexOptions()
    oechem.OESetupSplitMolComplexOptions(sopts, itf)

    ligand = oechem.OEGraphMol()
    protein = oechem.OEGraphMol()
    water = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    pfilter = sopts.GetProteinFilter()
    wfilter = sopts.GetWaterFilter()
    sopts.SetProteinFilter(oechem.OEOrRoleSet(pfilter, wfilter))
    sopts.SetWaterFilter(
        oechem.OEMolComplexFilterFactory(
            oechem.OEMolComplexFilterCategory_Nothing))

    oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts)

    if ligand.NumAtoms() == 0:
        oechem.OEThrow.Fatal("Cannot separate complex!")

    # Perceive interactions

    asite = oechem.OEInteractionHintContainer(protein, ligand)
    if not asite.IsValid():
        oechem.OEThrow.Fatal("Cannot initialize active site!")
    asite.SetTitle(ligand.GetTitle())

    oechem.OEPerceiveInteractionHints(asite)

    oegrapheme.OEPrepareActiveSiteDepiction(asite)

    # Depict active site with interactions

    width, height = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight(
        itf)
    image = oedepict.OEImage(width, height)

    cframe = oedepict.OEImageFrame(image, width * 0.80, height,
                                   oedepict.OE2DPoint(0.0, 0.0))
    lframe = oedepict.OEImageFrame(image, width * 0.20, height,
                                   oedepict.OE2DPoint(width * 0.80, 0.0))

    opts = oegrapheme.OE2DActiveSiteDisplayOptions(cframe.GetWidth(),
                                                   cframe.GetHeight())
    oedepict.OESetup2DMolDisplayOptions(opts, itf)

    adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)
    oegrapheme.OERenderActiveSite(cframe, adisp)

    lopts = oegrapheme.OE2DActiveSiteLegendDisplayOptions(10, 1)
    oegrapheme.OEDrawActiveSiteLegend(lframe, adisp, lopts)

    oedepict.OEWriteImage(oname, image)

    return 0