Example #1
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)
Example #2
0
def OEAddLabel_Predicate(disp):
    ringhighlight = oedepict.OEHighlightByBallAndStick(oechem.OELightGreen)
    oedepict.OEAddHighlighting(disp, ringhighlight,
                               oechem.OEAtomIsInRing(), oechem.OEBondIsInRing())
    ringlabel = oedepict.OEHighlightLabel("ring", oechem.OELightGreen)
    oedepict.OEAddLabel(disp, ringlabel, oechem.OEAtomIsInRing())

    chainhighlight = oedepict.OEHighlightByBallAndStick(oechem.OEBlueTint)
    oedepict.OEAddHighlighting(disp, chainhighlight,
                               oechem.OEAtomIsInChain(), oechem.OEBondIsInChain())
    chainlabel = oedepict.OEHighlightLabel("chain", oechem.OEBlueTint)
    oedepict.OEAddLabel(disp, chainlabel, oechem.OEAtomIsInChain())
Example #3
0
def OEAddLabel_OEAtomBondSet(disp):
    mol = disp.GetMolecule()

    ringset = oechem.OEAtomBondSet(mol.GetAtoms(oechem.OEAtomIsInRing()),
                                   mol.GetBonds(oechem.OEBondIsInRing()))
    ringhighlight = oedepict.OEHighlightByBallAndStick(oechem.OELightGreen)
    oedepict.OEAddHighlighting(disp, ringhighlight, ringset)
    ringlabel = oedepict.OEHighlightLabel("ring", oechem.OELightGreen)
    oedepict.OEAddLabel(disp, ringlabel, ringset)

    chainset = oechem.OEAtomBondSet(mol.GetAtoms(oechem.OEAtomIsInChain()),
                                    mol.GetBonds(oechem.OEBondIsInChain()))
    chainhighlight = oedepict.OEHighlightByBallAndStick(oechem.OEBlueTint)
    oedepict.OEAddHighlighting(disp, chainhighlight, chainset)
    chainlabel = oedepict.OEHighlightLabel("chain", oechem.OEBlueTint)
    oedepict.OEAddLabel(disp, chainlabel, chainset)
Example #4
0
def OEAddLabel_OEMatch(disp):
    subs = oechem.OESubSearch("a1aaaaa1")
    unique = True
    highlightstyle = oedepict.OEHighlightByBallAndStick(oechem.OELightGreen)
    for match in subs.Match(disp.GetMolecule(), unique):
        oedepict.OEAddHighlighting(disp, highlightstyle, match)
        label = oedepict.OEHighlightLabel("aromatic", oechem.OELightGreen)
        oedepict.OEAddLabel(disp, label, match)
Example #5
0
def DepictMoleculesWithLabel(smiles, ss, highlight, label, basefilename):

    mol = oechem.OEGraphMol()
    oechem.OESmilesToMol(mol, smiles)
    oedepict.OEPrepareDepiction(mol)
    opts = oedepict.OE2DMolDisplayOptions(220, 160, oedepict.OEScale_AutoScale)
    opts.SetTitleLocation(oedepict.OETitleLocation_Hidden)
    disp = oedepict.OE2DMolDisplay(mol, opts)

    unique = True
    for match in ss.Match(mol, unique):
        oedepict.OEAddHighlighting(disp, highlight, match)
        oedepict.OEAddLabel(disp, label, match)

    image = oedepict.OEImage(disp.GetWidth(), disp.GetHeight())
    oedepict.OERenderMolecule(image, disp)

    oedepict.OEWriteImage(basefilename + ".png", image)
    oedepict.OEWriteImage(basefilename + ".pdf", image)
Example #6
0
def visualize_mols(smiles,
                   fname,
                   rows,
                   cols,
                   bond_idx,
                   wbos,
                   colors,
                   align_to=0):
    """
    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))
        print(minscale)

    print(minscale)
    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
        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_Bold, 12,
        #                       oedepict.OEAlignment_Default, oechem.OEBlack)
        bond_label = oedepict.OEHighlightLabel("{:.2f}".format((wbos[i])),
                                               hcolor)
        bond_label.SetFontScale(1.4)
        #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))
Example #7
0
        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)

# Write out images
oedepict.OEWriteImage("MolWithWedgeChart.svg", image)
oedepict.OEWriteImage("MolWithWedgeChart.png", image)