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)
def to_pdf(molecules, oname, rows=5, cols=3): itf = oechem.OEInterface() PageByPage = True 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) for mol in molecules: cell = report.NewCell() oedepict.OEPrepareDepiction(mol) disp = oedepict.OE2DMolDisplay(mol, opts) oedepict.OERenderMolecule(cell, disp) oedepict.OEDrawCurvedBorder(cell, oedepict.OELightGreyPen, 10.0) oedepict.OEWriteReport(oname, report)
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
def to_pdf(molecules, bond_map_idx, fname, rows=3, cols=2, align=None): """ Generate PDF of list of oemols or SMILES Parameters ---------- molecules : list of OEMols These mols need to have map indices on bond of interest and WBO attached to that bond's data fname : str Name of PDF rows : int How many rows of molecules per page cols : int How many columns of molecule per page bond_map_idx : tuple of bond to highlight align: oemol molecule to align all other molecules in the 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) if align: if isinstance(align, str): ref_mol = oechem.OEGraphMol() oechem.OESmilesToMol(ref_mol, align) elif isinstance(align, (oechem.OEMol, oechem.OEMolBase, oechem.OEGraphMol)): ref_mol = align oedepict.OEPrepareDepiction(ref_mol) for i, mol in enumerate(molecules): cell = report.NewCell() mol_copy = oechem.OEMol(mol) oedepict.OEPrepareDepiction(mol_copy, False, True) atom_bond_set = oechem.OEAtomBondSet() a1 = mol_copy.GetAtom(oechem.OEHasMapIdx(bond_map_idx[0])) a2 = mol_copy.GetAtom(oechem.OEHasMapIdx(bond_map_idx[1])) b = mol_copy.GetBond(a1, a2) opts.SetBondPropertyFunctor(fragmenter.chemi.LabelWibergBondOrder()) atom_bond_set.AddAtom(a1) atom_bond_set.AddAtom(a2) atom_bond_set.AddBond(b) hstyle = oedepict.OEHighlightStyle_BallAndStick hcolor = oechem.OEColor(oechem.OELightBlue) overlaps = oegraphsim.OEGetFPOverlap( ref_mol, mol_copy, oegraphsim.OEGetFPType(oegraphsim.OEFPType_Tree)) oedepict.OEPrepareMultiAlignedDepiction(mol_copy, ref_mol, overlaps) disp = oedepict.OE2DMolDisplay(mol_copy, opts) oedepict.OEAddHighlighting(disp, hcolor, hstyle, atom_bond_set) oedepict.OERenderMolecule(cell, disp) oedepict.OEDrawCurvedBorder(cell, oedepict.OELightGreyPen, 10.0) oedepict.OEWriteReport(fname, report)
if len(sys.argv) != 2: oechem.OEThrow.Usage("%s <protein>" % sys.argv[0]) protein = ImportProtein(sys.argv[1]) # @ <SNIPPET-RENDER-RAMA> image = oedepict.OEImage(800, 600) ramaplot = oegrapheme.OERamachandranPlot() ramaplot.AddMolecule(protein) oegrapheme.OERenderRamachandranPlot(image, ramaplot) # @ </SNIPPET-RENDER-RAMA> oedepict.OEDrawCurvedBorder(image, oedepict.OELightGreyPen, 10.0) oedepict.OEWriteImage("RenderRamachandranPlot.svg", image) # @ <SNIPPET-RENDER-RAMA-GENERAL> image = oedepict.OEImage(800, 600) ramaplot = oegrapheme.OERamachandranPlot() ramaplot.AddMolecule(protein) oegrapheme.OERenderRamachandranPlot(image, ramaplot, oechem.OERamaType_General) # @ </SNIPPET-RENDER-RAMA-GENERAL> oedepict.OEDrawCurvedBorder(image, oedepict.OELightGreyPen, 10.0) oedepict.OEWriteImage("RenderRamachandranPlot-General.png", image) oedepict.OEAddInteractiveIcon(image, oedepict.OEIconLocation_TopRight, 0.50) oedepict.OEWriteImage("RenderRamachandranPlot-General.svg", image)
# 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> oedepict.OEWriteImage("OEDrawCurvedBorder.pdf", image)
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