Ejemplo n.º 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)
Ejemplo n.º 2
0
def png_atoms_labeled(smiles, fname):
    """Write out png file of molecule with atoms labeled with their index.

    Parameters
    ----------
    smiles: str
        SMILES
    fname: str
        absolute path and filename for png

    """

    mol = oechem.OEGraphMol()
    oechem.OESmilesToMol(mol, smiles)
    oedepict.OEPrepareDepiction(mol)

    width, height = 300, 200

    opts = oedepict.OE2DMolDisplayOptions(width, height,
                                          oedepict.OEScale_AutoScale)
    opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx())
    opts.SetAtomPropLabelFont(oedepict.OEFont(oechem.OEDarkGreen))

    disp = oedepict.OE2DMolDisplay(mol, opts)
    return oedepict.OERenderMolecule(fname, disp)
Ejemplo n.º 3
0
def main(argv=[__name__]):

    itf = oechem.OEInterface(InterfaceData)
    oedepict.OEConfigureReportOptions(itf)
    oedepict.OEConfigurePrepareDepictionOptions(itf)
    oedepict.OEConfigure2DMolDisplayOptions(itf)

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

    iname = itf.GetString("-in")
    ifs = oechem.oemolistream()
    ifs.SetConfTest(oechem.OEAbsoluteConfTest())  # VTL
    if not ifs.open(iname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    oname = itf.GetString("-out")
    ext = oechem.OEGetFileExtension(oname)
    if ext != "pdf":
        oechem.OEThrow.Fatal("Output must be PDF format.")

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

    if itf.HasString("-ringdict"):
        rdfname = itf.GetString("-ringdict")
        if not oechem.OEInit2DRingDictionary(rdfname):
            oechem.OEThrow.Warning("Cannot use user-defined ring dictionary!")

    ropts = oedepict.OEReportOptions()
    oedepict.OESetupReportOptions(ropts, itf)
    ropts.SetFooterHeight(25.0)
    report = oedepict.OEReport(ropts)

    popts = oedepict.OEPrepareDepictionOptions()
    oedepict.OESetupPrepareDepictionOptions(popts, itf)

    dopts = oedepict.OE2DMolDisplayOptions()
    oedepict.OESetup2DMolDisplayOptions(dopts, itf)
    dopts.SetDimensions(report.GetCellWidth(), report.GetCellHeight(),
                        oedepict.OEScale_AutoScale)

    for mol in ifs.GetOEMols():  # VTL ignore confs; dont use GetOEGraphMols
        print(mol.GetTitle())  # VTL
        cell = report.NewCell()
        oedepict.OEPrepareDepiction(mol, popts)
        disp = oedepict.OE2DMolDisplay(mol, dopts)
        oedepict.OERenderMolecule(cell, disp)

    font = oedepict.OEFont(oedepict.OEFontFamily_Default,
                           oedepict.OEFontStyle_Bold, 12,
                           oedepict.OEAlignment_Center, oechem.OEBlack)
    for pagenum, footer in enumerate(report.GetFooters()):
        text = "Page %d of %d" % (pagenum + 1, report.NumPages())
        oedepict.OEDrawTextToCenter(footer, text, font)

    oedepict.OEWriteReport(ofs, ext, report)

    return 0
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
    def _assignDisplayOptions(self):
        if self._params["labelAtomCIPStereo"]:
            #
            self._opts.SetAtomStereoStyle(
                oedepict.OEAtomStereoStyle_Display_All)
            # self._opts.SetAtomStereoStyle(oedepict.OEAtomStereoStyle_Display_CIPAtomStereo)

        if self._params["labelBondCIPStereo"]:
            # will include bowties for undefined stereo
            # self._opts.SetBondStereoStyle(oedepict.OEBondStereoStyle_Display_All)
            self._opts.SetBondStereoStyle(
                oedepict.OEBondStereoStyle_Display_CIPBondStereo)
            self._opts.SetAtomPropLabelFontScale(0.650)

        if self._params["labelAtomIndex"]:
            self._opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx())
            self._opts.SetAtomPropLabelFont(oedepict.OEFont(
                oechem.OEDarkGreen))
            self._opts.SetAtomPropLabelFontScale(0.650)

        if self._params["labelBondIndex"]:
            self._opts.SetBondPropertyFunctor(oedepict.OEDisplayBondIdx())
            self._opts.SetBondPropLabelFont(oedepict.OEFont(oechem.OEDarkBlue))

        if self._params["labelAtomName"]:
            atomlabel = LabelAtoms()
            self._opts.SetAtomPropertyFunctor(atomlabel)
            self._opts.SetAtomPropLabelFont(oedepict.OEFont(
                oechem.OEDarkGreen))
            self._opts.SetAtomPropLabelFontScale(0.650)

        if self._params["bondDisplayWidth"] is not None:
            pen = oedepict.OEPen(oechem.OEBlack, oechem.OEBlack,
                                 oedepict.OEFill_On,
                                 self._params["bondDisplayWidth"])
            self._opts.SetDefaultBondPen(pen)
            # remove for the moment.  not supported on all platforms
            # self._opts.SetBondWidthScaling(False)
        #
        # 5.0 is minimum size -
        self._opts.SetTitleHeight(5.0)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
def png_atoms_labeled(smiles,
                      fname,
                      map_idx=True,
                      width=600,
                      height=400,
                      label_scale=2.0,
                      scale_bondwidth=True):
    """Write out png file of molecule with atoms labeled with their map index.

    Parameters
    ----------
    smiles: str
        SMILES
    fname: str
        absolute path and filename for png
    map_idx: bool
        If True, lable atoms with map index instead of atom index. If set to True, input SMILES must have map indices.

    """

    mol = oechem.OEGraphMol()
    oechem.OESmilesToMol(mol, smiles)
    oedepict.OEPrepareDepiction(mol)
    opts = oedepict.OE2DMolDisplayOptions(width, height,
                                          oedepict.OEScale_AutoScale)

    if map_idx:
        # check if molecule has map
        if not cmiles.utils.has_atom_map(mol):
            raise ValueError(
                "Input SMILES must have atom maps to display map indices in image"
            )
        opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomMapIdx())
        opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomMapIdx())
    if not map_idx:
        opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx())

    opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomMapIdx())
    opts.SetAtomPropLabelFont(oedepict.OEFont(oechem.OEDarkGreen))
    opts.SetAtomPropLabelFontScale(label_scale)
    opts.SetBondWidthScaling(scale_bondwidth)

    disp = oedepict.OE2DMolDisplay(mol, opts)
    return oedepict.OERenderMolecule(fname, disp)
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
opts.SetAtomColor(oechem.OEElemNo_N, oechem.OEColor(0, 0,
                                                    80))  # very dark blue
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-COLOR>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomColor")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-COLOR-STYLE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_BlackMonochrome)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-COLOR-STYLE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomColorStyle")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-LABEL-FONT>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
font = oedepict.OEFont()
font.SetFamily(oedepict.OEFontFamily_Courier)
font.SetStyle(oedepict.OEFontStyle_Bold)
opts.SetAtomLabelFont(font)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-LABEL-FONT>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomLabelFont")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-LABEL-FONT-SCALE>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
opts = oedepict.OE2DMolDisplayOptions(width, height, scale)
opts.SetAtomLabelFontScale(1.5)
# @ </SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-LABEL-FONT-SCALE>
DepictMolecules(opts, smiles, "OE2DMolDisplayOptions_SetAtomLabelFontScale")

# @ <SNIPPET-OE2DMOLDISPLAY-OPTIONS-ATOM-PROP-LABEL-FONT>
width, height, scale = 300.0, 200.0, oedepict.OEScale_AutoScale
Ejemplo n.º 11
0
def visualize_phenyls(smiles, fname, rows, cols, bond_idx, wbos, colors):
    """
    Visualize molecules with highlighted bond and labeled with WBO
    Parameters
    ----------
    smiles : list of SMILES to visualize. Torsion atoms should have map indices (1, 2, 3, 4)
    fname : str
        filename
    rows : int
    cols : int
    bond_idx : tuple of atom maps of bond to highlight. Since all torsions are mapped with (1, 2, 3, 4), the same tuple
    is used for all SMILES.
    wbos : list of floats
    colors : list of hex values for colors

    """
    itf = oechem.OEInterface()

    ropts = oedepict.OEReportOptions(rows, cols)
    ropts.SetHeaderHeight(25)
    ropts.SetFooterHeight(25)
    ropts.SetCellGap(2)
    ropts.SetPageMargins(10)
    report = oedepict.OEReport(ropts)

    cellwidth, cellheight = report.GetCellWidth(), report.GetCellHeight()
    opts = oedepict.OE2DMolDisplayOptions(cellwidth, cellheight,
                                          oedepict.OEScale_AutoScale)
    oedepict.OESetup2DMolDisplayOptions(opts, itf)

    # align to first molecule
    ref_mol = oechem.OEGraphMol()
    oechem.OESmilesToMol(ref_mol, smiles[0])
    oedepict.OEPrepareDepiction(ref_mol)

    mols = []
    minscale = float("inf")
    for s in smiles:
        mol = oechem.OEMol()
        oechem.OESmilesToMol(mol, s)
        mols.append(mol)
        oedepict.OEPrepareDepiction(mol, False, True)
        minscale = min(minscale, oedepict.OEGetMoleculeScale(mol, opts))
        opts.SetScale(minscale)

    print(minscale)
    opts.SetScale(minscale)

    for i, mol in enumerate(mols):
        cell = report.NewCell()
        #mol = oechem.OEMol()
        #oechem.OESmilesToMol(mol, s)
        #oedepict.OEPrepareDepiction(mol, False, True)

        bond = get_bond(mol, bond_idx)
        atom_bond_set = oechem.OEAtomBondSet()
        atom_bond_set.AddAtoms([bond.GetBgn(), bond.GetEnd()])
        atom_bond_set.AddBond(bond)

        hstyle = oedepict.OEHighlightStyle_BallAndStick
        hcolor = oechem.OEColor(colors[i])

        overlaps = oegraphsim.OEGetFPOverlap(
            ref_mol, mol, oegraphsim.OEGetFPType(oegraphsim.OEFPType_Tree))
        oedepict.OEPrepareMultiAlignedDepiction(mol, ref_mol, overlaps)

        disp = oedepict.OE2DMolDisplay(mol, opts)
        oedepict.OEAddHighlighting(disp, hcolor, hstyle, atom_bond_set)

        font = oedepict.OEFont(oedepict.OEFontFamily_Default,
                               oedepict.OEFontStyle_Default, 24,
                               oedepict.OEAlignment_Default, oechem.OEBlack)
        bond_label = oedepict.OEHighlightLabel("{:.2f}".format(wbos[i]),
                                               hcolor)
        bond_label.SetFontScale(4.0)
        bond_label.SetFont(font)
        oedepict.OEAddLabel(disp, bond_label, atom_bond_set)
        oedepict.OERenderMolecule(cell, disp)
        #oedepict.OEDrawCurvedBorder(cell, oedepict.OELightGreyPen, 10.0)

    return (oedepict.OEWriteReport(fname, report))
Ejemplo n.º 12
0
# 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 oechem
from openeye import oedepict

# @ <SNIPPET-BOND-PROP-INDEX>
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cc(N)cc(S(=O)(=O)O)c1")
oedepict.OEPrepareDepiction(mol)

width, height = 300, 200

opts = oedepict.OE2DMolDisplayOptions(width, height,
                                      oedepict.OEScale_AutoScale)
opts.SetBondPropertyFunctor(oedepict.OEDisplayBondIdx())
opts.SetBondPropLabelFont(oedepict.OEFont(oechem.OEDarkBlue))

disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule("BondPropIndex.png", disp)
# @ </SNIPPET-BOND-PROP-INDEX>
oedepict.OERenderMolecule("BondPropIndex.pdf", disp)
Ejemplo n.º 13
0
def visualize_mols(smiles,
                   fname,
                   rows,
                   cols,
                   bond_idx,
                   wbos,
                   colors,
                   align_to=0,
                   circle=None):
    """
    Visualize molecules with highlighted bond and labeled with WBO
    Parameters
    ----------
    smiles : list of SMILES to visualize.
        bond atoms should have map indices
    fname : str
        filename
    rows : int
    cols : int
    bond_idx : tuple of atom maps of bond to highlight.
    wbos : list of floats
    colors : list of hex values for colors
    align_to: int, optional, default 0
        index for which molecule to align to. If zero, will align to first molecules in SMILES list

    """
    itf = oechem.OEInterface()

    ropts = oedepict.OEReportOptions(rows, cols)
    ropts.SetHeaderHeight(25)
    ropts.SetFooterHeight(25)
    ropts.SetCellGap(2)
    ropts.SetPageMargins(10)
    report = oedepict.OEReport(ropts)

    cellwidth, cellheight = report.GetCellWidth(), report.GetCellHeight()
    opts = oedepict.OE2DMolDisplayOptions(cellwidth, cellheight,
                                          oedepict.OEScale_AutoScale)
    oedepict.OESetup2DMolDisplayOptions(opts, itf)

    # align to chosen molecule
    ref_mol = oechem.OEGraphMol()
    oechem.OESmilesToMol(ref_mol, smiles[align_to])
    oedepict.OEPrepareDepiction(ref_mol)

    mols = []
    minscale = float("inf")
    for s in smiles:
        mol = oechem.OEMol()
        oechem.OESmilesToMol(mol, s)
        mols.append(mol)
        oedepict.OEPrepareDepiction(mol, False, True)
        minscale = min(minscale, oedepict.OEGetMoleculeScale(mol, opts))

    opts.SetScale(minscale)
    for i, mol in enumerate(mols):

        cell = report.NewCell()
        oedepict.OEPrepareDepiction(mol, False, True)
        bond = get_bond(mol, bond_idx)
        atom_bond_set = oechem.OEAtomBondSet()
        atom_bond_set.AddAtoms([bond.GetBgn(), bond.GetEnd()])
        atom_bond_set.AddBond(bond)

        hstyle = oedepict.OEHighlightStyle_BallAndStick
        if i == 3:
            hcolor = oechem.OERed
        else:
            hcolor = oechem.OEColor(*colors[i])

        overlaps = oegraphsim.OEGetFPOverlap(
            ref_mol, mol, oegraphsim.OEGetFPType(oegraphsim.OEFPType_Tree))
        oedepict.OEPrepareMultiAlignedDepiction(mol, ref_mol, overlaps)

        #opts.SetBondPropLabelFontScale(4.0)
        disp = oedepict.OE2DMolDisplay(mol, opts)
        oedepict.OEAddHighlighting(disp, hcolor, hstyle, atom_bond_set)

        font = oedepict.OEFont(oedepict.OEFontFamily_Default,
                               oedepict.OEFontStyle_Default, 24,
                               oedepict.OEAlignment_Default, oechem.OEBlack)
        bond_label = oedepict.OEHighlightLabel("{:.2f}".format(wbos[i]),
                                               hcolor)
        bond_label.SetFontScale(4.0)
        bond_label.SetFont(font)

        # generate circle
        atom_bond_set_circle = oechem.OEAtomBondSet()
        if circle is not None:
            color = oechem.OEColor(*colors[i])
            highlight = oedepict.OEHighlightByCogwheel(color)
            highlight.SetBallRadiusScale(5.0)
            for m in circle:
                print(m)
                if m == 1:
                    continue
                atom = mol.GetAtom(oechem.OEHasMapIdx(m))
                print(atom)
                atom_bond_set_circle.AddAtom(atom)
            for bond_tuple in itertools.combinations(circle, 2):
                bond_test = get_bond(mol, bond_tuple)
                if bond_test:
                    atom_bond_set_circle.AddBond(bond_test)

            #highlight.SetColor(color)
            oedepict.OEAddHighlighting(disp, highlight, atom_bond_set_circle)

        oedepict.OEAddLabel(disp, bond_label, atom_bond_set)
        oedepict.OERenderMolecule(cell, disp)
        # oedepict.OEDrawCurvedBorder(cell, oedepict.OELightGreyPen, 10.0)

    return (oedepict.OEWriteReport(fname, report))
from openeye import oechem
from openeye import oedepict

# @ <SNIPPET-DEPICT-MOL-WITH-HYPERLINK>
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "OC(=O)c1ccccc1")
oedepict.OEPrepareDepiction(mol)

width, height = 150.0, 150.0
image = oedepict.OEImage(width, height)
opts = oedepict.OE2DMolDisplayOptions(width, height,
                                      oedepict.OEScale_AutoScale)
opts.SetTitleLocation(oedepict.OETitleLocation_Bottom)

# associate font with URI

font = oedepict.OEFont(oedepict.OEFontFamily_Default,
                       oedepict.OEFontStyle_Default, 10,
                       oedepict.OEAlignment_Center, oechem.OEBlue)
font.SetHyperlink("http://www.eyesopen.com/oedepict-tk")

opts.SetTitleFont(font)
mol.SetTitle("Generated by OEDepict")

disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule(image, disp)

oedepict.OEWriteImage("DepictMolWithHyperlink.pdf", image)
oedepict.OEWriteImage("DepictMolWithHyperlink.svg", image)
# @ </SNIPPET-DEPICT-MOL-WITH-HYPERLINK>
Ejemplo n.º 15
0
pen = oedepict.OEPen(oechem.OEBlack, oechem.OEDarkBlue, oedepict.OEFill_Off, 2.0)
tableopts.SetCellBorderPen(pen)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETCELLBORDERPEN>
WriteTable(tableopts, "OEImageTableOptions_SetCellBorderPen")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETCELLCOLOR>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
evenrow = True
tableopts.SetCellColor(oechem.OELightGrey, not evenrow)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETCELLCOLOR>
WriteTable(tableopts, "OEImageTableOptions_SetCellColor")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETCELLFONT>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
font = oedepict.OEFont(oedepict.OEFontFamily_Default,
                       oedepict.OEFontStyle_Italic | oedepict.OEFontStyle_Bold,
                       8, oedepict.OEAlignment_Left, oechem.OEDarkRed)
tableopts.SetCellFont(font)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETCELLFONT>
WriteTable(tableopts, "OEImageTableOptions_SetCellFont")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETHEADER>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
tableopts.SetHeader(False)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETHEADER>
WriteTable(tableopts, "OEImageTableOptions_SetHeader")

# @ <SNIPPET-OEIMAGETABLEOPTIONS-SETHEADERCOLOR>
tableopts = oedepict.OEImageTableOptions(4, 4, oedepict.OEImageTableStyle_MediumBlue)
tableopts.SetHeaderColor(oechem.OELightGrey)
# @ </SNIPPET-OEIMAGETABLEOPTIONS-SETHEADERCOLOR>
Ejemplo n.º 16
0
                      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)

        starting_angle += WEDGE_WIDTH

# Draw circle round R atom on top of pie chart center
pen = oedepict.OEPen(OEWhite, OEBlack, oedepict.OEFill_On, 1)
glyph = oegrapheme.OEAtomGlyphCircle(pen, oegrapheme.OECircleStyle_Default,
                                     1.5)
oegrapheme.OEAddGlyph(mdisp, glyph, oechem.OEHasMapIdx(1))

# Render molecule
oedepict.OERenderMolecule(image, mdisp)
Ejemplo n.º 17
0
# or its use.

from openeye import oechem
from openeye import oedepict

# @ <SNIPPET-TOGGLEATOMTEXT>
width, height = 400, 200
image = oedepict.OEImage(width, height)

mol = oechem.OEGraphMol()
smiles = "Cc1cccnc1/C=C/[C@H](C(=O)O)O"
oechem.OESmilesToMol(mol, smiles)
oedepict.OEPrepareDepiction(mol)

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

font = oedepict.OEFont(oedepict.OEFontFamily_Default,
                       oedepict.OEFontStyle_Default, 12,
                       oedepict.OEAlignment_Center, oechem.OEDarkRed)

for adisp in disp.GetAtomDisplays():
    atom = adisp.GetAtom()
    toggletext = "atom idx=%s" % atom.GetIdx()
    oedepict.OEDrawSVGToggleText(disp, adisp, toggletext, font)

oedepict.OERenderMolecule("ToggleAtomText.svg", disp)
# @ </SNIPPET-TOGGLEATOMTEXT>
Ejemplo n.º 18
0
# 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 oechem
from openeye import oedepict

# @ <SNIPPET-ATOM-PROP-INDEX>
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1cc(N)cc(S(=O)(=O)O)c1")
oedepict.OEPrepareDepiction(mol)

width, height = 300, 200

opts = oedepict.OE2DMolDisplayOptions(width, height,
                                      oedepict.OEScale_AutoScale)
opts.SetAtomPropertyFunctor(oedepict.OEDisplayAtomIdx())
opts.SetAtomPropLabelFont(oedepict.OEFont(oechem.OEDarkGreen))

disp = oedepict.OE2DMolDisplay(mol, opts)
oedepict.OERenderMolecule("AtomPropIndex.png", disp)
# @ </SNIPPET-ATOM-PROP-INDEX>
oedepict.OERenderMolecule("AtomPropIndex.pdf", disp)