Пример #1
0
def draw_reference_dihedral(image, group, itag, center, radius):
    """
    Draws dihedral angle of the reference molecule.
    :type image: oedepict.OEImageBase
    :type group: oechem.OEGroupBase
    :type itag: int
    :type center: oedepict.OE2DPoint
    :type radius: float
    """

    if not group.HasData(itag):
        return
    angle = group.GetData(itag)
    v = oedepict.OE2DPoint(0.0, -1.0)
    bgn = oedepict.OELengthenVector(oedepict.OERotateVector(v, angle),
                                    radius / 6.0)
    end = oedepict.OELengthenVector(oedepict.OERotateVector(v, angle),
                                    radius / 3.0)
    redpen = oedepict.OEPen(oechem.OERed, oechem.OERed, oedepict.OEFill_Off,
                            2.0)
    image.DrawLine(center + bgn, center + end, redpen)

    fontsize = int(math.floor(radius * 0.12))
    font = oedepict.OEFont(oedepict.OEFontFamily_Default,
                           oedepict.OEFontStyle_Bold, fontsize,
                           oedepict.OEAlignment_Center, oechem.OERed)

    dim = radius / 2.5
    textframe = oedepict.OEImageFrame(
        image, dim, dim, center - oedepict.OE2DPoint(dim / 2.0, dim / 2.0))
    oedepict.OEDrawTextToCenter(textframe, "{:.1f}".format(angle), font)
Пример #2
0
def draw_dihedral_circle(image, center, radius, nrbins, nrconfs):
    """
    Draws the base radial histogram.
    :type image: oedepict.OEImageBase
    :type center: oedepict.OE2DPoint
    :type radius: float
    :type nrbins: int
    :type nrconfs: int
    """

    grey = oechem.OEColor(210, 210, 210)
    pen = oedepict.OEPen(grey, grey, oedepict.OEFill_On, 1.0)
    image.DrawCircle(center, radius, pen)

    linegrey = oechem.OEColor(220, 220, 220)
    linepen = oedepict.OEPen(linegrey, linegrey, oedepict.OEFill_On, 1.0)

    angleinc = 360.0 / float(nrbins)

    v = oedepict.OE2DPoint(0.0, -1.0)
    for i in range(0, nrbins):
        end = oedepict.OELengthenVector(
            oedepict.OERotateVector(v, i * angleinc), radius)
        image.DrawLine(center, center + end, linepen)

    fontsize = int(math.floor(radius * 0.1))
    font = oedepict.OEFont(oedepict.OEFontFamily_Default,
                           oedepict.OEFontStyle_Bold, fontsize,
                           oedepict.OEAlignment_Center, oechem.OEBlack)

    for i in range(0, 4):
        angle = i * 90.0
        end = oedepict.OELengthenVector(oedepict.OERotateVector(v, angle),
                                        radius * 1.20)
        text = '{:.1f}'.format(angle)
        dim = radius / 2.5
        textframe = oedepict.OEImageFrame(
            image, dim, dim,
            center + end - oedepict.OE2DPoint(dim / 2.0, dim / 2.0))
        oedepict.OEDrawTextToCenter(textframe, text, font)

    minradius = radius / 3.0
    whitepen = oedepict.OEPen(oechem.OEWhite, oechem.OEWhite,
                              oedepict.OEFill_On, 1.0,
                              oedepict.OEStipple_NoLine)
    image.DrawCircle(center, minradius, whitepen)

    font.SetSize(int(fontsize * 1.5))
    top = oedepict.OE2DPoint(image.GetWidth() / 2.0, -10.0)
    image.DrawText(top, 'torsion histogram', font)
    top = oedepict.OE2DPoint(image.GetWidth() / 2.0, -30.0)

    image.DrawText(top, 'MM: blue; ANI: red', font)

    bottom = oedepict.OE2DPoint(image.GetWidth() / 2.0,
                                image.GetHeight() + 26.0)
    image.DrawText(bottom, 'number of conformations: {}'.format(nrconfs), font)
Пример #3
0
def OEAddLabel_OEImage(image):

    label = oedepict.OEHighlightLabel("Hello!")
    oedepict.OEAddLabel(image, oedepict.OE2DPoint(50, 50), label)

    label.SetBoundingBoxPen(oedepict.OETransparentPen)
    oedepict.OEAddLabel(image, oedepict.OE2DPoint(100, 50), label)

    label.SetBoundingBoxPen(oedepict.OELightGreyPen)
    oedepict.OEAddLabel(image, oedepict.OE2DPoint(150, 50), label)
Пример #4
0
def DrawHelloWorld(image, font):

    w = image.GetWidth()
    h = image.GetHeight()
    image.Clear(oechem.OEWhite)

    pen = oedepict.OEPen()
    image.DrawRectangle(oedepict.OE2DPoint(1.0, 1.0),
                        oedepict.OE2DPoint(w - 1.0, h - 1.0), pen)

    image.DrawText(oedepict.OE2DPoint(w / 2.0, h / 2.0), "Hello World!", font)
Пример #5
0
def DrawQuadraticBezier():
    # @ <SNIPPET-DRAW-QUADRATIC-BEZIER>
    image = oedepict.OEImage(100, 100)

    b = oedepict.OE2DPoint(20, 70)
    e = oedepict.OE2DPoint(80, 70)
    c = b + oedepict.OE2DPoint(30, -80)

    pen = oedepict.OEPen(oechem.OELightGreen, oechem.OEBlack,
                         oedepict.OEFill_On, 2.0)
    image.DrawQuadraticBezier(b, c, e, pen)
    # @ </SNIPPET-DRAW-QUADRATIC-BEZIER>
    oedepict.OEWriteImage("DrawQuadraticBezier.png", image)
    oedepict.OEWriteImage("DrawQuadraticBezier.pdf", image)
Пример #6
0
def DrawCubicBezier():
    # @ <SNIPPET-CUBIC-BEZIER>
    image = oedepict.OEImage(100, 100)

    b = oedepict.OE2DPoint(20, 70)
    e = oedepict.OE2DPoint(60, 70)
    c1 = b + oedepict.OE2DPoint(50, -60)
    c2 = e + oedepict.OE2DPoint(50, -60)

    pen = oedepict.OEPen(oechem.OELightGreen, oechem.OEBlack,
                         oedepict.OEFill_On, 2.0)
    image.DrawCubicBezier(b, c1, c2, e, pen)

    # @ </SNIPPET-CUBIC-BEZIER>
    oedepict.OEWriteImage("DrawCubicBezier.png", image)
    oedepict.OEWriteImage("DrawCubicBezier.pdf", image)
Пример #7
0
def DepictMoleculesWithData(report, mollist, iname, tags, opts):
    from openeye import oechem
    from openeye import oedepict

    for mol in mollist:
        # render molecule
        cell = report.NewCell()
        oedepict.OEPrepareDepiction(mol)
        disp = oedepict.OE2DMolDisplay(mol, opts)
        oedepict.OERenderMolecule(cell, disp)
        oedepict.OEDrawCurvedBorder(cell, oedepict.OELightGreyPen, 10.0)

        # render corresponding data
        cell = report.NewCell()
        RenderData(cell, mol, tags)

    # add input filnename to headers
    headerfont = oedepict.OEFont(
        oedepict.OEFontFamily_Default,
        oedepict.OEFontStyle_Default,
        12,
        oedepict.OEAlignment_Center,
        oechem.OEBlack,
    )
    headerpos = oedepict.OE2DPoint(report.GetHeaderWidth() / 2.0,
                                   report.GetHeaderHeight() / 2.0)

    for header in report.GetHeaders():
        header.DrawText(headerpos, iname, headerfont)

    # add page number to footers
    footerfont = oedepict.OEFont(
        oedepict.OEFontFamily_Default,
        oedepict.OEFontStyle_Default,
        12,
        oedepict.OEAlignment_Center,
        oechem.OEBlack,
    )
    footerpos = oedepict.OE2DPoint(report.GetFooterWidth() / 2.0,
                                   report.GetFooterHeight() / 2.0)

    for pageidx, footer in enumerate(report.GetFooters()):
        footer.DrawText(footerpos, "- %d -" % (pageidx + 1), footerfont)
Пример #8
0
def HighlightCell(cell, idx):

    font = oedepict.OEFont(oedepict.OEFontFamily_Default,
                           oedepict.OEFontStyle_Default, 10,
                           oedepict.OEAlignment_Center, oechem.OEBlack)
    color = oechem.OEColor(oechem.OELightGrey)
    borderpen = oedepict.OEPen(color, color, oedepict.OEFill_On, 1.0)

    oedepict.OEDrawBorder(cell, borderpen)
    p = oedepict.OE2DPoint(cell.GetWidth() / 2.0,
                           cell.GetHeight() / 2.0 + font.GetSize() / 2.0)
    cell.DrawText(p, "(%d)" % idx, font)
def DrawFigure(image, pen):

    w = image.GetWidth()
    h = image.GetHeight()
    image.Clear(oechem.OEWhite)

    a = oedepict.OE2DPoint(10.0, 10.0)
    b = oedepict.OE2DPoint(w - 10, h - 10.0)
    image.DrawRectangle(a, b, pen)

    a = oedepict.OE2DPoint(20.0, 20.0)
    b = oedepict.OE2DPoint(w - 20, h - 20.0)
    image.DrawLine(a, b, pen)

    a = oedepict.OE2DPoint(60.0, 20.0)
    b = oedepict.OE2DPoint(20.0, 60.0)
    image.DrawLine(a, b, pen)
Пример #10
0
def DrawPolygon():
    # @ <SNIPPET-DRAW-POLYGON>
    image = oedepict.OEImage(100, 100)

    polygon = []
    polygon.append(oedepict.OE2DPoint(20, 20))
    polygon.append(oedepict.OE2DPoint(40, 40))
    polygon.append(oedepict.OE2DPoint(60, 20))
    polygon.append(oedepict.OE2DPoint(80, 40))
    polygon.append(oedepict.OE2DPoint(80, 80))
    polygon.append(oedepict.OE2DPoint(20, 80))

    pen = oedepict.OEPen(oechem.OELightGreen, oechem.OEBlack,
                         oedepict.OEFill_On, 2.0)
    image.DrawPolygon(polygon, pen)
    # @ </SNIPPET-DRAW-POLYGON>
    oedepict.OEWriteImage("DrawPolygon.png", image)
    oedepict.OEWriteImage("DrawPolygon.pdf", image)
Пример #11
0
def draw_color_gradient(image, colorg):
    """
    Draws the color gradient used to color the circle in the middle of
    the rotatable bond.
    :type image: oedepict.OEImageBase
    :type colorg: oechem.OEColorGradientBase
    """

    width, height = image.GetWidth(), image.GetHeight()
    frame = oedepict.OEImageFrame(
        image, width * 0.8, height * 0.8,
        oedepict.OE2DPoint(width * 0.1, height * 0.1))

    opts = oegrapheme.OEColorGradientDisplayOptions()
    opts.SetColorStopPrecision(1)
    opts.SetColorStopLabelFontScale(0.5)
    opts.SetColorStopVisibility(False)

    opts.AddLabel(
        oegrapheme.OEColorGradientLabel(colorg.GetMinValue(), "rigid"))
    opts.AddLabel(
        oegrapheme.OEColorGradientLabel(colorg.GetMaxValue(), "flexible"))

    oegrapheme.OEDrawColorGradient(frame, colorg, opts)
Пример #12
0
def DrawPath():
    # @ <SNIPPET-DRAW-PATH>
    image = oedepict.OEImage(100, 100)

    path = oedepict.OE2DPath(oedepict.OE2DPoint(20, 80))
    path.AddLineSegment(oedepict.OE2DPoint(80, 80))
    path.AddLineSegment(oedepict.OE2DPoint(80, 40))
    path.AddCurveSegment(oedepict.OE2DPoint(80,
                                            10), oedepict.OE2DPoint(20, 10),
                         oedepict.OE2DPoint(20, 40))

    pen = oedepict.OEPen(oechem.OELightGreen, oechem.OEBlack,
                         oedepict.OEFill_On, 2.0)
    image.DrawPath(path, pen)

    # @ </SNIPPET-DRAW-PATH>
    oedepict.OEWriteImage("DrawPath.png", image)
    oedepict.OEWriteImage("DrawPath.pdf", image)

    # @ <SNIPPET-GET-PATH-POINTS>
    for p in path.GetPoints():
        pos = p.GetPoint()
        print(" %.1f %.1f %d" % (pos.GetX(), pos.GetY(), p.GetPointType()))
Пример #13
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
Пример #14
0
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall OpenEye be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oedepict

width, height = 100, 100
image = oedepict.OEImage(width, height)

# @ <SNIPPET-CREATE-CLASS>
svg_group_circ = image.NewSVGGroup("circle")
svg_group_rect = image.NewSVGGroup("rectangle")
svg_class_objs = image.NewSVGClass("object")

svg_group_circ.AddSVGClass(svg_class_objs)
svg_group_rect.AddSVGClass(svg_class_objs)

image.PushGroup(svg_group_circ)
image.DrawCircle(oedepict.OEGetCenter(image), 30, oedepict.OERedBoxPen)
image.PopGroup(svg_group_circ)

image.PushGroup(svg_group_rect)
image.DrawRectangle(oedepict.OE2DPoint(10, 10), oedepict.OE2DPoint(90, 90),
                    oedepict.OELightGreyPen)
image.PopGroup(svg_group_rect)

oedepict.OEWriteImage("CreateSVGClass.svg", image)
# @ </SNIPPET-CREATE-CLASS>
Пример #15
0
        radius = (n_ring - ring_num) * RADIUS_BASE

        if isinstance(value, str) and ">" in value:
            value_for_color = 100
        else:
            value_for_color = value
        gradient = gradients[ring_num]
        color = gradient.GetColorAt(value_for_color)
        pen = oedepict.OEPen(color, oechem.OEBlack, oedepict.OEFill_On, 1.0)

        layer.DrawPie(r_coords, starting_angle, starting_angle + WEDGE_WIDTH,
                      radius, pen)

        # Write value in segment - based on
        # https://docs.eyesopen.com/toolkits/cookbook/python/_downloads/properties2img.py
        p = oedepict.OE2DPoint(0, -radius * 0.75)
        midangle = (starting_angle + starting_angle + WEDGE_WIDTH) / 2.0
        rad = math.radians(midangle)
        cosrad = math.cos(rad)
        sinrad = math.sin(rad)
        txt_coord = r_coords + oedepict.OE2DPoint(
            cosrad * p.GetX() - sinrad * p.GetY(),
            sinrad * p.GetX() + cosrad * p.GetY())

        fontsize = int(SEGMENT_LABEL_SCALE_FACTOR * math.sqrt(radius))
        font = oedepict.OEFont(oedepict.OEFontFamily_Default,
                               oedepict.OEFontStyle_Bold, fontsize,
                               oedepict.OEAlignment_Center, oechem.OEBlack)
        label = oedepict.OEHighlightLabel(str(value), font)
        label.SetBoundingBoxPen(oedepict.OETransparentPen)
        oedepict.OEAddLabel(layer, txt_coord, label)
Пример #16
0
def draw_dihedral_histogram(image, histogram, histogram_ref, center, radius,
                            nrbins, nrconfs):
    """
    Draws the radial histogram of a torsional angle.
    :type image: oedepict.OEImageBase
    :type histogram: list(int)
    :type center: oedepict.OE2DPoint
    :type radius: float
    :type nrbins: int
    :type nrconfs: int
    :type nrbins: int
    """

    minradius = radius / 3.0
    maxvalue = max(max(histogram), max(histogram_ref))
    radiusinc = (radius - minradius) / maxvalue

    angleinc = 360.0 / float(nrbins)

    valuepen = oedepict.OEPen(oechem.OERoyalBlue, oechem.OERoyalBlue,
                              oedepict.OEFill_On, 2.0)

    maxvalue = 0
    maxvalueidx = 0
    for i in range(0, len(histogram)):
        value = histogram[i]
        if value == 0:
            continue

        if value > maxvalue:
            maxvalue = value
            maxvalueidx = i

        arcradius = value * radiusinc + minradius
        if arcradius < 1.0:
            continue

        bgnangle = i * angleinc
        endangle = (i + 1) * angleinc

        image.DrawPie(center, bgnangle, endangle, arcradius, valuepen)

    valuepen = oedepict.OEPen(oechem.OERed, oechem.OERed, oedepict.OEFill_Off,
                              2.0)
    for i in range(0, len(histogram_ref)):
        value = histogram_ref[i]
        if value == 0:
            continue

        if value > maxvalue:
            maxvalue = value
            maxvalueidx = i

        arcradius = value * radiusinc + minradius
        if arcradius < 1.0:
            continue

        bgnangle = i * angleinc
        endangle = (i + 1) * angleinc

        image.DrawPie(center, bgnangle, endangle, arcradius, valuepen)

    percent = maxvalue / (nrconfs / 100.0)

    whitepen = oedepict.OEPen(oechem.OEWhite, oechem.OEWhite,
                              oedepict.OEFill_On, 0.2,
                              oedepict.OEStipple_NoLine)
    image.DrawCircle(center, minradius, whitepen)

    fontsize = int(math.floor(radius * 0.1))
    font = oedepict.OEFont(oedepict.OEFontFamily_Default,
                           oedepict.OEFontStyle_Bold, fontsize,
                           oedepict.OEAlignment_Center, oechem.OEWhite)
    angle = maxvalueidx * angleinc
    if angle >= 180.0:
        angle += angleinc * 0.3
    else:
        angle += angleinc * 0.7
    textangle = get_text_angle(angle)
    v = oedepict.OE2DPoint(0.0, -1.0)
    pos = oedepict.OELengthenVector(oedepict.OERotateVector(v, angle),
                                    radius * 0.80)
    font.SetRotationAngle(textangle)
    image.DrawText(center + pos, "{:.1f}%".format(percent * 100), font)
Пример #17
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
Пример #18
0
def main(argv=[__name__]):
    """
    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    if not oechem.OEParseCommandLine(itf, argv):
        return 1

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

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

  
    ## INPUT PARAMETERS
    #########################################################
    #########################################################
    
    mm = 'tyk2/og_pdbs'
    qml = 'tyk2/forward_snapshots'
    phase = 'solvent'
    which_ligand = 'old'
    dir_name = iname
    ligand_pdbs_mm = glob.glob(f"{mm}/{dir_name}/{which_ligand}*{phase}.pdb")
    print(len(ligand_pdbs_mm))
    ligand_pdbs_qml = glob.glob(f"{qml}/{dir_name}/{which_ligand}*{phase}.pdb")
    print(len(ligand_pdbs_qml))

    #d = np.load('full_data_dict.npy', allow_pickle=True)
    from_ligand, to_ligand = iname.replace('from', '').replace('to', '').replace('lig', '')
    print(from_ligand)
    print(to_ligand)
    #key1 = (1, 8)
    #key2 = ('solvent', which_ligand)
    #########################################################
    #########################################################

    #d = d.flatten()[0]
    #work = d[key1][key2]
    #print(work)

    
    for i, (mm_pdb_path, ani_pdb_path) in enumerate(zip(ligand_pdbs_mm, ligand_pdbs_qml)):
        print(mm_pdb_path, ani_pdb_path)
        if i == 0:
            MM_mol = createOEMolFromSDF(mm_pdb_path, 0)
            ANI_mol = createOEMolFromSDF(ani_pdb_path, 0)
        else:
            # there absolutely must be a better/faster way of doing this because this is ugly and slow
            MM_mol.NewConf(createOEMolFromSDF(mm_pdb_path, 0))
            ANI_mol.NewConf(createOEMolFromSDF(ani_pdb_path, 0))
"""
    ofs = oechem.oeofstream()
    oname = f"tor_out"
    ext = oechem.OEGetFileExtension(oname)

    mm_pdb_path = f"og_lig0_solvent.pdb"
    ani_pdb_path = f"forward_lig0.solvent.pdb"
    MM_mol = createOEMolFromSDF(mm_pdb_path, 0)
    ANI_mol = createOEMolFromSDF(ani_pdb_path, 0)

    mol = MM_mol
    mol2 = ANI_mol

    for m in [mol, mol2]:
        oechem.OESuppressHydrogens(m)
        oechem.OECanonicalOrderAtoms(m)
        oechem.OECanonicalOrderBonds(m)
        m.Sweep()

    refmol = None

    stag = "dihedral_histogram"
    itag = oechem.OEGetTag(stag)

    nrbins = 20

    print(mol.NumConfs())
    print(mol2.NumConfs())

    get_dihedrals(mol, itag)
    set_dihedral_histograms(mol, itag, nrbins)

    get_dihedrals(mol2, itag)
    #set_weighted_dihedral_histograms(mol2, itag, work, nrbins)
    set_dihedral_histograms(mol2, itag, nrbins)

    width, height = 800, 400
    image = oedepict.OEImage(width, height)

    moffset = oedepict.OE2DPoint(0, 0)
    mframe = oedepict.OEImageFrame(image, width * 0.70, height, moffset)
    doffset = oedepict.OE2DPoint(mframe.GetWidth(), height * 0.30)
    dframe = oedepict.OEImageFrame(image, width * 0.30, height * 0.5, doffset)

    flexibility = True
    colorg = get_color_gradient(nrbins, flexibility)

    opts = oedepict.OE2DMolDisplayOptions(mframe.GetWidth(),
                                          mframe.GetHeight(),
                                          oedepict.OEScale_AutoScale)

    depict_dihedrals(mframe, dframe, mol, mol2, refmol, opts, itag, nrbins,
                     colorg)

    if flexibility:
        lopts = oedepict.OELegendLayoutOptions(
            oedepict.OELegendLayoutStyle_HorizontalTopLeft,
            oedepict.OELegendColorStyle_LightBlue,
            oedepict.OELegendInteractiveStyle_Hover)
        lopts.SetButtonWidthScale(1.2)
        lopts.SetButtonHeightScale(1.2)
        lopts.SetMargin(oedepict.OEMargin_Right, 40.0)
        lopts.SetMargin(oedepict.OEMargin_Bottom, 80.0)

        legend = oedepict.OELegendLayout(image, "Legend", lopts)

        legend_area = legend.GetLegendArea()
        draw_color_gradient(legend_area, colorg)

        oedepict.OEDrawLegendLayout(legend)

    iconscale = 0.5
    oedepict.OEAddInteractiveIcon(image, oedepict.OEIconLocation_TopRight,
                                  iconscale)
    oedepict.OEDrawCurvedBorder(image, oedepict.OELightGreyPen, 10.0)

    oedepict.OEWriteImage(ofs, ext, image)

    return 0
Пример #19
0
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable OpenEye offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall OpenEye be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oedepict

# @ <SNIPPET-DRAW-LINE>
width, height = 100, 100
# Create image
image = oedepict.OEImage(width, height)

# Draw line with default pen
bgn = oedepict.OE2DPoint(10.0, 10.0)
end = oedepict.OE2DPoint(90.0, 90.0)
image.DrawLine(bgn, end, oedepict.OEBlackPen)

# Write image to SVG file
oedepict.OEWriteImage("DrawLine.svg", image)
# @ </SNIPPET-DRAW-LINE>
oedepict.OEWriteImage("DrawLine.png", image)
oedepict.OEWriteImage("DrawLine.pdf", image)
Пример #20
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
Пример #21
0
# @ <SNIPPET-IMAGE-FRAME>
def DrawMolecule(image, mol, width, height, offset):

    frame = oedepict.OEImageFrame(image, width, height, offset)

    oedepict.OEDrawBorder(frame, oedepict.OELightGreyPen)

    opts = oedepict.OE2DMolDisplayOptions(width, height,
                                          oedepict.OEScale_AutoScale)
    disp = oedepict.OE2DMolDisplay(mol, opts)

    clearbackground = True
    oedepict.OERenderMolecule(frame, disp, not clearbackground)


image = oedepict.OEImage(400, 400)

mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "C1CC(O)CNC1")
oedepict.OEPrepareDepiction(mol)

DrawMolecule(image, mol, 60, 60, oedepict.OE2DPoint(50.0, 40.0))
DrawMolecule(image, mol, 180, 180, oedepict.OE2DPoint(180.0, 120.0))
DrawMolecule(image, mol, 80, 80, oedepict.OE2DPoint(300.0, 20.0))
DrawMolecule(image, mol, 50, 50, oedepict.OE2DPoint(150.0, 320.0))
DrawMolecule(image, mol, 20, 20, oedepict.OE2DPoint(360.0, 360.0))

oedepict.OEWriteImage("ImageFrame.png", image)
# @ </SNIPPET-IMAGE-FRAME>
oedepict.OEWriteImage("ImageFrame.pdf", image)
Пример #22
0
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall OpenEye be
# liable for any damages or liability in connection with the Sample Code
# or its use.

from openeye import oedepict

width, height = 200, 100
image = oedepict.OEImage(width, height)

# @ <SNIPPET-ADD-SVG-HOVER>
hover_area = image.NewSVGGroup("hover_area")
target_area = image.NewSVGGroup("hover_target_area")

oedepict.OEAddSVGHover(hover_area, target_area)

image.PushGroup(hover_area)
image.DrawRectangle(oedepict.OE2DPoint(30, 30), oedepict.OE2DPoint(70, 70),
                    oedepict.OERedBoxPen)
image.PopGroup(hover_area)

image.PushGroup(target_area)
image.DrawCircle(oedepict.OE2DPoint(150, 50), 30, oedepict.OEBlueBoxPen)
image.PopGroup(target_area)

oedepict.OEAddInteractiveIcon(image)

oedepict.OEWriteImage("AddSVGHover.svg", image)
# @ <SNIPPET-ADD-SVG-HOVER>
Пример #23
0
pen = oedepict.OEPen(oechem.OEColor(225, 200, 200), oechem.OERed,
                     oedepict.OEFill_On, 1.0)

image = oedepict.OEImage(100, 100)
image.Clear(oechem.OELightGrey)
grid = CreateGrid(image)

i = 1
# @ <SNIPPET-OEIMAGEGRID-GETCELLS-ALL>
for cell in grid.GetCells():
    pass
    # @ </SNIPPET-OEIMAGEGRID-GETCELLS-ALL>
    oedepict.OEDrawBorder(cell, pen)
    font = oedepict.OEFont()
    c = oedepict.OE2DPoint(cell.GetWidth(), cell.GetHeight() + font.GetSize())
    cell.DrawText(c / 2.0, "(%d)" % i, font)
    i += 1

oedepict.OEWriteImage("ImageGridIter-all.png", image)
oedepict.OEWriteImage("ImageGridIter-all.pdf", image)

image = oedepict.OEImage(100, 100)
image.Clear(oechem.OELightGrey)
grid = CreateGrid(image)

i = 1
# @ <SNIPPET-OEIMAGEGRID-GETCELLS-ROW>
row = 2
for cell in grid.GetCells(row, 0):
    pass