def CreateScaleReportLayout(opts, scale): opts = ScaleReportOptions(opts, scale) report = oedepict.OEReport(opts) borderpen = oedepict.OEPen(oechem.OEGrey, oechem.OEGrey, oedepict.OEFill_Off, 1.0) first = report.NewBody() oedepict.OEDrawBorder(first, borderpen) nrgridpages = 1 for p in range(0, nrgridpages): for c in range(0, report.NumRowsPerPage() * report.NumColsPerPage()): cell = report.NewCell() oedepict.OEDrawBorder(cell, borderpen) for page in report.GetPages(): oedepict.OEDrawBorder(page, oedepict.OEBlackPen) if opts.GetHeaderHeight() > 0.0: for header in report.GetHeaders(): oedepict.OEDrawBorder(header, borderpen) if opts.GetFooterHeight() > 0.0: for footer in report.GetFooters(): oedepict.OEDrawBorder(footer, borderpen) return report
def prepare(self): """[summary] # OESuppressHydrogens(self.__oeMol, retainPolar=False,retainStereo=True,retainIsotope=True) oechem.OESuppressHydrogens(self.__oeMol) """ self.__setupImage() for idx, cell in enumerate(self.__grid.GetCells()): ccId, oeMol, title = self._molTitleList[idx] logger.debug("Preparing %s %r", ccId, title) # if self._params["suppressHydrogens"]: # mol = oeMol.getGraphMolSuppressH() # OESuppressHydrogens(self.__oeMol, retainPolar=False,retainStereo=True,retainIsotope=True) mol = oechem.OESuppressHydrogens(oechem.OEGraphMol(oeMol)) else: mol = oeMol # if self.__useTitle and title: mol.SetTitle(title) self._opts.SetTitleHeight(5.0) else: mol.SetTitle("") # # oedepict.OEPrepareDepiction(mol) self._opts.SetDimensions(cell.GetWidth(), cell.GetHeight(), oedepict.OEScale_AutoScale) self._assignDisplayOptions() disp = oedepict.OE2DMolDisplay(mol, self._opts) oedepict.OERenderMolecule(cell, disp) if self._params["cellBorders"]: oedepict.OEDrawBorder(cell, oedepict.OEPen(oedepict.OEBlackPen))
def CreateGrid(image): rows, cols = 3, 3 grid = oedepict.OEImageGrid(image, rows, cols) grid.SetCellGap(5) grid.SetMargins(0) for cell in grid.GetCells(): oedepict.OEDrawBorder(cell, oedepict.OERedPen) return grid
def draw_frag_pdf(frag_dict, scaffold=None, pdf_filename='fragments.pdf'): from openeye import oechem, oedepict import re itf = oechem.OEInterface() PageByPage = True suppress_h = True rows = 7 cols = 5 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_Default * 0.5) opts.SetAromaticStyle(oedepict.OEAromaticStyle_Circle) pen = oedepict.OEPen(oechem.OEBlack, oechem.OEBlack, oedepict.OEFill_On, 1.0) opts.SetDefaultBondPen(pen) oedepict.OESetup2DMolDisplayOptions(opts, itf) if scaffold: oemol = oechem.OEGraphMol() scaffold_smi = re.sub(r"\(\[R([1-9])+]\)", r"([*])", scaffold.smiles) oechem.OESmilesToMol(oemol, scaffold_smi) cell = report.NewCell() mol = oechem.OEMol(oemol) mol.SetTitle(f'{scaffold.smiles}') oedepict.OEPrepareDepiction(mol, False, suppress_h) disp = oedepict.OE2DMolDisplay(mol, opts) oedepict.OERenderMolecule(cell, disp) headerpen = oedepict.OEPen(oechem.OEWhite, oechem.OELightGrey, oedepict.OEFill_Off, 1.0) oedepict.OEDrawBorder(cell, headerpen) for rx, smis in frag_dict.items(): for idx, smi in enumerate(smis): if smi != None: # Create oemol oemol = oechem.OEGraphMol() oechem.OESmilesToMol(oemol, smi) # Render molecule cell = report.NewCell() mol = oechem.OEMol(oemol) mol.SetTitle(f'R{rx} #{idx+1}') oedepict.OEPrepareDepiction(mol, False, suppress_h) disp = oedepict.OE2DMolDisplay(mol, opts) oedepict.OERenderMolecule(cell, disp) oedepict.OEWriteReport(pdf_filename, report)
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)
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 CreateReportLayout(): rows, cols = 3, 2 reportopts = oedepict.OEReportOptions(rows, cols) reportopts.SetPageWidth(100.0) reportopts.SetPageHeight(150.0) reportopts.SetPageMargins(5.0) reportopts.SetCellGap(5.0) reportopts.SetHeaderHeight(15.0) reportopts.SetFooterHeight(15.0) report = oedepict.OEReport(reportopts) borderpen = oedepict.OEPen(oechem.OELightGrey, oechem.OELightGrey, oedepict.OEFill_Off, 1.0) first = report.NewBody() oedepict.OEDrawBorder(first, borderpen) nrgridpages = 3 for p in range(0, nrgridpages): for c in range(0, report.NumRowsPerPage() * report.NumColsPerPage()): cell = report.NewCell() oedepict.OEDrawBorder(cell, borderpen) last = report.NewBody() oedepict.OEDrawBorder(last, borderpen) for page in report.GetPages(): oedepict.OEDrawBorder(page, oedepict.OEBlackPen) for header in report.GetHeaders(): oedepict.OEDrawBorder(header, borderpen) for footer in report.GetFooters(): oedepict.OEDrawBorder(footer, borderpen) return report
def oedepict_pdf(all_probe_mols, subdir): """ Generate a PDF report of all molecules together, color-coded by parameter ID and labeled with parameter ID and SMILES tag. Parameters ---------- all_probe_mols: key is string of a parameter id to be probed; value is a list of oegraphmols with this parameter id subdir : string Name of subdirectory in which to save results.pdf file """ multi = oedepict.OEMultiPageImageFile(oedepict.OEPageOrientation_Landscape, oedepict.OEPageSize_US_Letter) image = multi.NewPage() opts = oedepict.OE2DMolDisplayOptions() rows, cols = 4, 4 grid = oedepict.OEImageGrid(image, rows, cols) grid.SetCellGap(20) grid.SetMargins(20) citer = grid.GetCells() colors = list(oechem.OEGetContrastColors()) for i, (param, mol_list) in enumerate(all_probe_mols.items()): pen = oedepict.OEPen(oechem.OEWhite, colors[i], oedepict.OEFill_Off, 4.0) for mol in mol_list: # go to next page if not citer.IsValid(): image = multi.NewPage() grid = oedepict.OEImageGrid(image, rows, cols) grid.SetCellGap(20) grid.SetMargins(20) citer = grid.GetCells() cell = citer.Target() mol.SetTitle(f"{param} {oechem.OEGetSDData(mol, 'SMILES QCArchive')}") oedepict.OEPrepareDepiction(mol) opts.SetDimensions(cell.GetWidth(), cell.GetHeight(), oedepict.OEScale_AutoScale) disp = oedepict.OE2DMolDisplay(mol, opts) oedepict.OERenderMolecule(cell, disp) oedepict.OEDrawBorder(cell, pen) citer.Next() oedepict.OEWriteMultiPageImage(f"{subdir}/results.pdf", multi)
def DepictMolecules(opts, smiles, basefilename, drawborder=False): mol = oechem.OEGraphMol() oechem.OESmilesToMol(mol, smiles) oedepict.OEPrepareDepiction(mol) disp = oedepict.OE2DMolDisplay(mol, opts) image = oedepict.OEImage(disp.GetWidth(), disp.GetHeight()) oedepict.OERenderMolecule(image, disp) if drawborder: oedepict.OEDrawBorder(image, oedepict.OELightGreyPen) oedepict.OEWriteImage(basefilename + ".png", image) oedepict.OEWriteImage(basefilename + ".pdf", image)
def prepare(self): self.__setupImage() rows = self._params["gridRows"] cols = self._params["gridCols"] grid = oedepict.OEImageGrid(self.__image, rows, cols) citer = grid.GetCells() for ccId, oeMol, title in self._molTitleList: logger.debug("Preparing %s %r", ccId, title) if not citer.IsValid(): # go to next page self.__image = self.__multi.NewPage() grid = oedepict.OEImageGrid(self.__image, rows, cols) grid.SetCellGap(self._params["cellGap"]) grid.SetMargins(self._params["cellMargin"]) citer = grid.GetCells() cell = citer.Target() # if self._params["suppressHydrogens"]: # mol = oeMol.getGraphMolSuppressH() # OESuppressHydrogens(self.__oeMol, retainPolar=False,retainStereo=True,retainIsotope=True) mol = oechem.OESuppressHydrogens(oechem.OEGraphMol(oeMol)) else: mol = oeMol if self.__useTitle and title: mol.SetTitle(title) self._opts.SetTitleHeight(5.0) else: mol.SetTitle("") # # oedepict.OEPrepareDepiction(mol) self._opts.SetDimensions(cell.GetWidth(), cell.GetHeight(), oedepict.OEScale_AutoScale) self._assignDisplayOptions() disp = oedepict.OE2DMolDisplay(mol, self._opts) oedepict.OERenderMolecule(cell, disp) oedepict.OEDrawBorder(cell, oedepict.OEPen(oedepict.OEBlackPen)) citer.Next()
def WriteTable(tableoptions, basefilename): image = oedepict.OEImage(300, 200) table = oedepict.OEImageTable(image, tableoptions) for idx, cell in enumerate(table.GetHeaderCells()): table.DrawText(cell, "(header %d)" % (idx + 1)) for idx, cell in enumerate(table.GetStubColumnCells()): table.DrawText(cell, "(stub %d)" % (idx + 1)) onlybody = True for row in range(1, table.NumRows(onlybody) + 1): for col in range(1, table.NumColumns(onlybody) + 1): cell = table.GetBodyCell(row, col) table.DrawText(cell, "(body %d, %d)" % (row, col)) oedepict.OEDrawBorder(image, oedepict.OELightGreyPen) oedepict.OEWriteImage(basefilename + ".png", image) oedepict.OEWriteImage(basefilename + ".pdf", image)
# 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. import sys from openeye import oechem from openeye import oedepict from openeye import oegrapheme ############################################################### # USED TO GENERATE CODE SNIPPETS FOR THE GRAPHEME DOCUMENTATION ############################################################### if len(sys.argv) != 2: oechem.OEThrow.Usage("%s <design unit>" % sys.argv[0]) filename = sys.argv[1] # @ <SNIPPET-DRAW-IRIDIUM-DATA> du = oechem.OEDesignUnit() if not oechem.OEReadDesignUnit(filename, du): oechem.OEThrow.Fatal("Cannot read design unit!") image = oedepict.OEImage(250, 250) oegrapheme.OEDrawIridiumData(image, du) oedepict.OEDrawBorder(image, oedepict.OELightGreyPen) oedepict.OEWriteImage("DrawIridiumData.svg", image) # @ </SNIPPET-DRAW-IRIDIUM-DATA> oedepict.OEWriteImage("DrawIridiumData.pdf", image)
# 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-OEDrawBorder> width, height = 100, 50 image = oedepict.OEImage(width, height) pen = oedepict.OEPen(oechem.OEWhite, oechem.OELightGreen, oedepict.OEFill_Off, 4.0) oedepict.OEDrawBorder(image, pen) oedepict.OEWriteImage("OEDrawBorder.png", image) # @ </SNIPPET-OEDrawBorder> oedepict.OEWriteImage("OEDrawBorder.pdf", image) # @ <SNIPPET-OEDrawCurvedBorder> width, height = 100, 50 image = oedepict.OEImage(width, height) pen = oedepict.OEPen(oechem.OEWhite, oechem.OELightGreen, oedepict.OEFill_Off, 4.0) oedepict.OEDrawCurvedBorder(image, pen, 15) oedepict.OEWriteImage("OEDrawCurvedBorder.png", image) # @ </SNIPPET-OEDrawCurvedBorder>
def DepictMoleculeWithFragmentCombinations(report, mol, frags, opts): #fragcombs, opts): """ This function was taken from https://docs.eyesopen.com/toolkits/cookbook/python/depiction/enumfrags.html with some modification """ stag = "fragment idx" itag = oechem.OEGetTag(stag) for fidx, frag in enumerate(frags): for bond in frags[frag].GetBonds(): bond.SetData(itag, fidx) # setup depiction styles nrfrags = len(frags) colors = [c for c in oechem.OEGetLightColors()] if len(colors) < nrfrags: colors = [c for c in oechem.OEGetColors(oechem.OEYellowTint, oechem.OEDarkOrange, nrfrags)] bondglyph = ColorBondByFragmentIndex(colors, itag) lineWidthScale = 0.75 fadehighlight = oedepict.OEHighlightByColor(oechem.OEGrey, lineWidthScale) # depict each fragment combinations for frag in frags: cell = report.NewCell() disp = oedepict.OE2DMolDisplay(mol, opts) fragatoms = oechem.OEIsAtomMember(frags[frag].GetAtoms()) fragbonds = oechem.OEIsBondMember(frags[frag].GetBonds()) notfragatoms = oechem.OENotAtom(fragatoms) notfragbonds = oechem.OENotBond(fragbonds) oedepict.OEAddHighlighting(disp, fadehighlight, notfragatoms, notfragbonds) bond = mol.GetBond(oechem.OEHasBondIdx(frag)) atomBondSet = oechem.OEAtomBondSet() atomBondSet.AddBond(bond) atomBondSet.AddAtom(bond.GetBgn()) atomBondSet.AddAtom(bond.GetEnd()) hstyle = oedepict.OEHighlightStyle_BallAndStick hcolor = oechem.OEColor(oechem.OELightBlue) oedepict.OEAddHighlighting(disp, hcolor, hstyle, atomBondSet) #oegrapheme.OEAddGlyph(disp, bondglyph, fragbonds) oedepict.OERenderMolecule(cell, disp) # depict original fragmentation in each header cellwidth, cellheight = report.GetHeaderWidth(), report.GetHeaderHeight() opts.SetDimensions(cellwidth, cellheight, oedepict.OEScale_AutoScale) opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_WhiteMonochrome) bondlabel = LabelBondOrder() opts.SetBondPropertyFunctor(bondlabel) disp = oedepict.OE2DMolDisplay(mol, opts) #oegrapheme.OEAddGlyph(disp, bondglyph, oechem.IsTrueBond()) headerpen = oedepict.OEPen(oechem.OEWhite, oechem.OELightGrey, oedepict.OEFill_Off, 2.0) for header in report.GetHeaders(): oedepict.OERenderMolecule(header, disp) oedepict.OEDrawBorder(header, headerpen)
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData) oedepict.OEConfigureReportOptions(itf) oedepict.OEConfigure2DMolDisplayOptions(itf) oedepict.OEConfigureHighlightParams(itf) if not oechem.OEParseCommandLine(itf, argv): return 1 qname = itf.GetString("-query") tname = itf.GetString("-target") oname = itf.GetString("-out") ext = oechem.OEGetFileExtension(oname) if not oedepict.OEIsRegisteredMultiPageImageFile(ext): oechem.OEThrow.Fatal("Unknown multipage image type!") qfile = oechem.oemolistream() if not qfile.open(qname): oechem.OEThrow.Fatal("Cannot open mdl query file!") if qfile.GetFormat() != oechem.OEFormat_MDL and qfile.GetFormat( ) != oechem.OEFormat_SDF: oechem.OEThrow.Fatal("Query file has to be an MDL file!") ifs = oechem.oemolistream() if not ifs.open(tname): oechem.OEThrow.Fatal("Cannot open target input file!") depictquery = oechem.OEGraphMol() if not oechem.OEReadMDLQueryFile(qfile, depictquery): oechem.OEThrow.Fatal("Cannot read query molecule!") oedepict.OEPrepareDepiction(depictquery) queryopts = oechem.OEMDLQueryOpts_Default | oechem.OEMDLQueryOpts_SuppressExplicitH qmol = oechem.OEQMol() oechem.OEBuildMDLQueryExpressions(qmol, depictquery, queryopts) ss = oechem.OESubSearch() if not ss.Init(qmol): oechem.OEThrow.Fatal("Cannot initialize substructure search!") hstyle = oedepict.OEGetHighlightStyle(itf) hcolor = oedepict.OEGetHighlightColor(itf) align = itf.GetBool("-align") ropts = oedepict.OEReportOptions() oedepict.OESetupReportOptions(ropts, itf) ropts.SetHeaderHeight(140.0) report = oedepict.OEReport(ropts) dopts = oedepict.OE2DMolDisplayOptions() oedepict.OESetup2DMolDisplayOptions(dopts, itf) cellwidth, cellheight = report.GetCellWidth(), report.GetCellHeight() dopts.SetDimensions(cellwidth, cellheight, oedepict.OEScale_AutoScale) unique = True for mol in ifs.GetOEGraphMols(): oechem.OEPrepareSearch(mol, ss) miter = ss.Match(mol, unique) if not miter.IsValid(): continue # no match alignres = oedepict.OEAlignmentResult(miter.Target()) if align: alignres = oedepict.OEPrepareAlignedDepiction(mol, ss) else: oedepict.OEPrepareDepiction(mol) cell = report.NewCell() disp = oedepict.OE2DMolDisplay(mol, dopts) if alignres.IsValid(): oedepict.OEAddHighlighting(disp, hcolor, hstyle, alignres) oedepict.OERenderMolecule(cell, disp) oedepict.OEDrawBorder(cell, oedepict.OELightGreyPen) # render query structure in each header headwidth, headheight = report.GetHeaderWidth(), report.GetHeaderHeight() dopts.SetDimensions(headwidth, headheight, oedepict.OEScale_AutoScale) disp = oedepict.OE2DMolDisplay(depictquery, dopts) for header in report.GetHeaders(): oedepict.OERenderMolecule(header, disp) oedepict.OEDrawBorder(header, oedepict.OELightGreyPen) oedepict.OEWriteReport(oname, report) return 0
opts = oedepict.OE2DMolDisplayOptions() rows, cols = 2, 2 grid = oedepict.OEImageGrid(image, rows, cols) grid.SetCellGap(20) grid.SetMargins(20) citer = grid.GetCells() for smi in smiles: if not citer.IsValid(): # go to next page image = multi.NewPage() grid = oedepict.OEImageGrid(image, rows, cols) grid.SetCellGap(20) grid.SetMargins(20) citer = grid.GetCells() cell = citer.Target() mol = oechem.OEGraphMol() oechem.OESmilesToMol(mol, smi) oedepict.OEPrepareDepiction(mol) opts.SetDimensions(cell.GetWidth(), cell.GetHeight(), oedepict.OEScale_AutoScale) disp = oedepict.OE2DMolDisplay(mol, opts) oedepict.OERenderMolecule(cell, disp) oedepict.OEDrawBorder(cell, oedepict.OEPen(oedepict.OERedPen)) citer.Next() oedepict.OEWriteMultiPageImage("MultiPage.pdf", multi) # @ </SNIPPET-MULTIPAGE>
return grid 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