Beispiel #1
0
def PoseInteractionsSVG(md_components, width=400, height=300):
    """Generate a OEGrapheme interaction plot for a protein-ligand complex.
    The input protein may have other non-protein components as well so
    the input protein is first split into components to isolate the protein
    only for the plot. This may have to be changed if other components need
    to be included in the plot.
    """
    # # perceive residue hierarchy of total system
    # if not oechem.OEHasResidues(proteinOrig):
    #     oechem.OEPerceiveResidues(proteinOrig, oechem.OEPreserveResInfo_All)
    #     print('Perceiving residues')

    # split the total system into components
    #protein, ligandPsuedo, water, other = oeommutils.split(proteinOrig)

    protein = md_components.get_protein
    ligand = md_components.get_ligand

    # make the OEHintInteractionContainer
    asite = oechem.OEInteractionHintContainer(protein, ligand)
    if not asite.IsValid():
        oechem.OEThrow.Fatal("Cannot initialize active site!")
    # do the perceiving
    oechem.OEPerceiveInteractionHints(asite)
    # set the depiction options
    opts = oegrapheme.OE2DActiveSiteDisplayOptions(width, height)
    opts.SetRenderInteractiveLegend(True)
    magnifyresidue = 1.0
    opts.SetSVGMagnifyResidueInHover(magnifyresidue)
    # make the depiction
    oegrapheme.OEPrepareActiveSiteDepiction(asite)
    adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)
    # make the image
    image = oedepict.OEImage(width, height)
    oegrapheme.OERenderActiveSite(image, adisp)
    # Add a legend
    #iconscale = 0.5
    #oedepict.OEAddInteractiveIcon(image, oedepict.OEIconLocation_TopRight, iconscale)
    svgBytes = oedepict.OEWriteImageToString("svg", image)

    svgString = svgBytes.decode("utf-8")

    return svgString
Beispiel #2
0
    mol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, mol):
        oechem.OEThrow.Fatal("Unable to read molecule in %s" % filename)

    return mol


if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <receptor> <ligand>" % sys.argv[0])

receptor = ImportMolecule(sys.argv[1])
ligand = ImportMolecule(sys.argv[2])

asite = oechem.OEInteractionHintContainer(receptor, ligand)
oechem.OEPerceiveInteractionHints(asite)
oegrapheme.OEPrepareActiveSiteDepiction(asite)

# @ <SNIPPET-OERENDERACTIVESITE-IMAGE-ADISP>
# initializing asite oechem.OEInteractionHintContainer(receptor, ligand) object

image = oedepict.OEImage(800.0, 600.0)
opts = oegrapheme.OE2DActiveSiteDisplayOptions(image.GetWidth(), image.GetHeight())
opts.SetRenderInteractiveLegend(True)
adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)

oegrapheme.OERenderActiveSite(image, adisp)
oedepict.OEWriteImage("OERenderActiveSite-image-adisp.svg", image)
# @ </SNIPPET-OERENDERACTIVESITE-IMAGE-ADISP>
oedepict.OEWriteImage("OERenderActiveSite-image-adisp.pdf", image)
Beispiel #3
0
########################################################################
#
########################################################################

if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <receptor> <ligand>" % sys.argv[0])

receptor = ImportMolecule(sys.argv[1])
ligand = ImportMolecule(sys.argv[2])

asite = oechem.OEInteractionHintContainer(receptor, ligand)
asite.SetTitle(ligand.GetTitle())
oechem.OEPerceiveInteractionHints(asite)
oegrapheme.OEPrepareActiveSiteDepiction(asite)

opts = oegrapheme.OE2DActiveSiteDisplayOptions(600, 400)
adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)
OEAddHighlighting_Predicate(adisp)

oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-Predicate.png", adisp)
oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-Predicate.pdf", adisp)

adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)
OEAddHighlighting_AtomAndBondPredicate(adisp)
oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-AtomAndBondPredicate.png", adisp)
oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-AtomAndBondPredicate.pdf", adisp)

adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)
OEAddHighlighting_OEMatch(adisp)
oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-OEMatch.png", adisp)
oegrapheme.OERenderActiveSite("OEAddHighlighting-ActiveSite-OEMatch.pdf", adisp)
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
Beispiel #5
0
    if not ifs.open(filename):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % filename)

    mol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, mol):
        oechem.OEThrow.Fatal("Unable to read molecule in %s" % filename)

    return mol


if len(sys.argv) != 3:
    oechem.OEThrow.Usage("%s <receptor> <ligand>" % sys.argv[0])

receptor = ImportMolecule(sys.argv[1])
ligand = ImportMolecule(sys.argv[2])

asite = oechem.OEInteractionHintContainer(receptor, ligand)
oechem.OEPerceiveInteractionHints(asite)
oegrapheme.OEPrepareActiveSiteDepiction(asite)

# @ <SNIPPET-OERENDERACTIVESITE-FNAME-ADISP>
# initializing asite oechem.OEInteractionHintContainer(receptor, ligand) object

opts = oegrapheme.OE2DActiveSiteDisplayOptions(800.0, 600.0)
opts.SetRenderInteractiveLegend(True)
adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)

oegrapheme.OERenderActiveSite("OERenderActiveSite-fname-adisp.svg", adisp)
# @ </SNIPPET-OERENDERACTIVESITE-FNAME-ADISP>
oegrapheme.OERenderActiveSite("OERenderActiveSite-fname-adisp.pdf", adisp)
Beispiel #6
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
        | oechem.OESplitMolComplexSetup_CovLig)

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

    if itf.HasString("-complex") and (itf.HasString("-protein")
                                      or itf.HasString("-ligand")):
        oechem.OEThrow.Warning("Only complex in %s file fill be used!" %
                               itf.GetString("-complex"))

    if not (itf.HasString("-complex")) ^ (itf.HasString("-protein")
                                          and itf.HasString("-ligand")):
        oechem.OEThrow.Fatal(
            "Please specify either complex or ligand and protein input files!")

    oname = itf.GetString("-out")

    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!")

    # initialize protein and ligand

    protein = oechem.OEGraphMol()
    ligand = oechem.OEGraphMol()
    if not get_protein_and_ligands(protein, ligand, itf):
        oechem.OEThrow.Fatal("Cannot initialize protein and/or ligand!")

    # depict active site with interactions

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

    interactive_legend = False
    magnify_residue = 1.0

    if ext == 'svg':
        interactive_legend = itf.GetBool("-interactive-legend")
        magnify_residue = itf.GetFloat("-magnify-residue")

    cwidth, cheight = width, height
    if not interactive_legend:
        cwidth = cwidth * 0.8

    opts = oegrapheme.OE2DActiveSiteDisplayOptions(cwidth, cheight)
    oedepict.OESetup2DMolDisplayOptions(opts, itf)

    opts.SetRenderInteractiveLegend(interactive_legend)
    opts.SetSVGMagnifyResidueInHover(magnify_residue)

    if interactive_legend:
        depict_complex(image, protein, ligand, opts)
    else:
        main_frame = oedepict.OEImageFrame(
            image, width * 0.80, height, oedepict.OE2DPoint(width * 0.2, 0.0))
        legend_frame = oedepict.OEImageFrame(
            image, width * 0.20, height, oedepict.OE2DPoint(width * 0.0, 0.0))
        depict_complex(main_frame, protein, ligand, opts, legend_frame)

    if ext == 'svg' and (interactive_legend or magnify_residue > 1.0):
        iconscale = 0.5
        oedepict.OEAddInteractiveIcon(image, oedepict.OEIconLocation_TopRight,
                                      iconscale)
    oedepict.OEDrawCurvedBorder(image, oedepict.OELightGreyPen, 10.0)

    oedepict.OEWriteImage(oname, image)

    return 0