def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData) if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to interpret command line!") ifs = oechem.oemolistream() inputFile = itf.GetString("-in") if not ifs.open(inputFile): oechem.OEThrow.Fatal("Unable to open %s for reading" % inputFile) ofs = oechem.oemolostream() outFile = itf.GetString("-out") if not ofs.open(outFile): oechem.OEThrow.Fatal("Unable to open %s for writing" % outFile) chargeName = itf.GetString("-method") mol = oechem.OEMol() while oechem.OEReadMolecule(ifs, mol): if not AssignChargesByName(mol, chargeName): oechem.OEThrow.Warning("Unable to assign %s charges to mol %s" % (chargeName, mol.GetTitle())) oechem.OEWriteMolecule(ofs, mol) ifs.close() ofs.close()
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData, argv) haskeep = itf.HasString("-keep") hasremove = itf.HasString("-remove") hasclear = itf.GetBool("-clearAll") numoption = 0 for hasoption in [haskeep, hasremove, hasclear]: if hasoption: numoption += 1 if numoption != 1: oechem.OEThrow.Usage( "Need to pick one from -keep, -remove, or -clearAll") ifs = oechem.oemolistream() if not ifs.open(itf.GetString("-i")): oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-i")) if not oechem.OEIsSDDataFormat(ifs.GetFormat()): oechem.OEThrow.Fatal( "Only works for input file formats that support SD data (sdf,oeb,csv)" ) ofs = oechem.oemolostream() if not ofs.open(itf.GetString("-o")): oechem.OEThrow.Fatal("Unable to open %s for writing" % itf.GetString("-o")) if not oechem.OEIsSDDataFormat(ofs.GetFormat()): oechem.OEThrow.Fatal( "Only works for output file formats that support SD data \ (sdf,oeb,csv)") ModProps(itf, ifs, ofs)
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData) if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to interpret command line!") MMPAnalyzeProbe(itf)
def main(argv=[__name__]): # import configuration file itf = oechem.OEInterface() oechem.OEConfigure(itf, InterfaceData) # add configuration for image size and display options oedepict.OEConfigureImageOptions(itf) oedepict.OEConfigure2DMolDisplayOptions(itf) if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to interpret command line!") ifname = itf.GetString("-in") ofname = itf.GetString("-out") ifs = oechem.oemolistream(ifname) mol = oechem.OEGraphMol() oechem.OEReadMolecule(ifs, mol) oedepict.OEPrepareDepiction(mol) width, height = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight(itf) opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale) # set up display options from command line parameters oedepict.OESetup2DMolDisplayOptions(opts, itf) disp = oedepict.OE2DMolDisplay(mol, opts) oedepict.OERenderMolecule(ofname, disp)
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData, argv) ifs = oechem.oemolistream() if not ifs.open(itf.GetString("-i")): oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-i")) ofs = oechem.oemolostream(".ism") if itf.HasString("-o"): if not ofs.open(itf.GetString("-o")): oechem.OEThrow.Fatal("Unable to open %s for writing" % itf.GetString("-o")) minhac = float("-inf") if itf.HasInt("-minhac"): minhac = itf.GetInt("-minhac") maxhac = float("inf") if itf.HasInt("-maxhac"): maxhac = itf.GetInt("-maxhac") minwt = float("-inf") if itf.HasDouble("-minwt"): minwt = itf.GetDouble("-minwt") maxwt = float("inf") if itf.HasDouble("-maxwt"): maxwt = itf.GetDouble("-maxwt") for mol in ifs.GetOEMols(): if not IsMoleculeInHeavyAtomCountRange(minhac, maxhac, mol): continue if not IsMoleculeInMolWtRange(minwt, maxwt, mol): continue oechem.OEWriteMolecule(ofs, mol)
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData) if not oechem.OEParseCommandLine(itf, argv): return 1 imstr = oechem.oemolistream(itf.GetString("-in")) omstr = oechem.oemolostream(itf.GetString("-out")) receptors = [] for receptor_filename in itf.GetStringList("-receptors"): receptor = oechem.OEGraphMol() if not oedocking.OEReadReceptorFile(receptor, receptor_filename): oechem.OEThrow.Fatal("Unable to read receptor from %s" % receptor_filename) receptors.append(receptor) poser = oedocking.OEPosit() for receptor in receptors: poser.AddReceptor(receptor) for mcmol in imstr.GetOEMols(): print("posing", mcmol.GetTitle()) result = oedocking.OESinglePoseResult() ret_code = poser.Dock(result, mcmol) if ret_code == oedocking.OEDockingReturnCode_Success: posedMol = result.GetPose() oechem.OESetSDData(posedMol, poser.GetName(), str(result.GetProbability())) oechem.OESetSDData(posedMol, "Receptor Index", str(result.GetReceptorIndex())) oechem.OEWriteMolecule(omstr, posedMol) else: errMsg = oedocking.OEDockingReturnCodeGetName(ret_code) oechem.OEThrow.Warning("%s: %s" % (mcmol.GetTitle(), errMsg)) return 0
def main(argv=(__name__)): """ the protein should have charges and radii but the ligand need not """ itf = oechem.OEInterface() if not oechem.OEConfigure(itf, InterfaceData): oechem.OEThrow.Fatal("Problem configuring OEInterface!") if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to parse command line") ligFile = itf.GetString("-l") ims = oechem.oemolistream() if not ims.open(ligFile): oechem.OEThrow.Fatal("Unable to open %s for reading" % ligFile) lig = oechem.OEGraphMol() oechem.OEReadMolecule(ims, lig) contextFile = itf.GetString("-p") ims = oechem.oemolistream() if not ims.open(contextFile): oechem.OEThrow.Fatal("Unable to open %s for reading" % contextFile) prot = oechem.OEGraphMol() oechem.OEReadMolecule(ims, prot) outputFile = itf.GetString("-o") oms = oechem.oemolostream() if not oms.open(outputFile): oechem.OEThrow.Fatal("Unable to open %s for writing" % outputFile) GenerateSzmapProbes(oms, itf.GetDouble("-prob"), lig, prot)
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData) oemolprop.OEConfigureFilterParams(itf) if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to interpret command line!") iname = itf.GetString("-in") ifs = oechem.oemolistream() if not ifs.open(iname): oechem.OEThrow.Fatal("Cannot open input file!") ftype = oemolprop.OEGetFilterType(itf) filt = oemolprop.OEFilter(ftype) ver = itf.GetInt("-verbose") oechem.OEThrow.SetLevel(ver) ostr = oechem.oeosstream() pwnd = False filt.SetTable(ostr, pwnd) headers = ostr.str().split(b'\t') ostr.clear() # remove the header row from the stream for mol in ifs.GetOEGraphMols(): filt(mol) fields = ostr.str().decode("UTF-8").split('\t') ostr.clear() # remove this row from the stream tmpdct = dict(zip(headers, fields)) print(mol.GetTitle(), tmpdct[b"Lipinski violations"])
def main(argv=[__name__]): itf = oechem.OEInterface(Interface, argv) oechem.OEWriteSettings(itf) # Create the Krige object krige = oestats.OEMolKrige() # Add the training molecules to the Krige imstr = oechem.oemolistream(itf.GetString("-train")) for mol in imstr.GetOEMols(): mw = oechem.OECalculateMolecularWeight(mol) krige.AddTraining(mol, mw) imstr.close() # Train the Krige on the molecules we added krige.Train() # Krige for MW of the test molecules, and compare to actual MW imstr.open(itf.GetString("-test")) for mol in imstr.GetOEMols(): result = krige.GetResult(mol) if not result.Valid(): continue krigeMW = result.GetResponse() print("Krige MW %f, Actual MW %f" % (krigeMW, oechem.OECalculateMolecularWeight(mol))) print("Finished")
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData, argv) if itf.HasFloat("-p") and itf.HasInt("-n"): oechem.OEThrow.Usage("Give only one option, -p or -n") ifs = oechem.oemolistream() if not ifs.open(itf.GetString("-i")): oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-i")) ofs = oechem.oemolostream(".ism") if itf.HasString("-o"): if not ofs.open(itf.GetString("-o")): oechem.OEThrow.Fatal("Unable to open %s for writing" % itf.GetString("-o")) if itf.HasInt("-seed"): rand = Random(itf.GetInt("-seed")) else: rand = Random() if itf.HasInt("-n"): RandomizeN(ifs, ofs, itf.GetInt("-n"), rand) elif itf.HasFloat("-p"): RandomizePercent(ifs, ofs, itf.GetFloat("-p"), rand) else: Randomize(ifs, ofs, rand)
def main(argv=[__name__]): itf = oechem.OEInterface() if not SetupInterface(argv, itf): return 1 zap = oezap.OEZap() zap.SetInnerDielectric(itf.GetFloat("-epsin")) zap.SetOuterDielectric(itf.GetFloat("-epsout")) zap.SetGridSpacing(itf.GetFloat("-grid_spacing")) zap.SetBoundarySpacing(itf.GetFloat("-buffer")) mol = oechem.OEGraphMol() ifs = oechem.oemolistream() if not ifs.open(itf.GetString("-in")): oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-in")) oechem.OEReadMolecule(ifs, mol) oechem.OEAssignBondiVdWRadii(mol) oechem.OEMMFFAtomTypes(mol) oechem.OEMMFF94PartialCharges(mol) zap.SetMolecule(mol) grid = oegrid.OEScalarGrid() if zap.CalcPotentialGrid(grid): if itf.GetBool("-mask"): oegrid.OEMaskGridByMolecule(grid, mol) oegrid.OEWriteGrid(itf.GetString("-out"), grid) return 0
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData, argv) haslist = itf.HasString("-list") hastitle = itf.HasString("-title") if not (haslist ^ hastitle): oechem.OEThrow.Usage("Must give either -list or -title") ifs = oechem.oemolistream() if not ifs.open(itf.GetString("-i")): oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-i")) ofs = oechem.oemolostream() if not ofs.open(itf.GetString("-o")): oechem.OEThrow.Fatal("Unable to open %s for writing" % itf.GetString("-o")) # collect names nameset = set() if itf.HasString("-list"): try: lfs = open(itf.GetString("-list")) except IOError: oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-list")) for name in lfs.readlines(): name = name.strip() nameset.add(name) elif itf.HasString("-title"): nameset.add(itf.GetString("-title")) if len(nameset) == 0: oechem.OEThrow.Fatal("No titles requested") MolExtract(ifs, ofs, nameset)
def ToPdf(mol, oname, frags):#, fragcombs): """ Parameters ---------- mol: charged OEMolGraph oname: str Output file name Returns ------- """ itf = oechem.OEInterface() oedepict.OEPrepareDepiction(mol) ropts = oedepict.OEReportOptions() oedepict.OESetupReportOptions(ropts, itf) ropts.SetFooterHeight(25.0) ropts.SetHeaderHeight(ropts.GetPageHeight() / 4.0) report = oedepict.OEReport(ropts) # setup decpiction options opts = oedepict.OE2DMolDisplayOptions() oedepict.OESetup2DMolDisplayOptions(opts, itf) cellwidth, cellheight = report.GetCellWidth(), report.GetCellHeight() opts.SetDimensions(cellwidth, cellheight, oedepict.OEScale_AutoScale) opts.SetTitleLocation(oedepict.OETitleLocation_Hidden) opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_WhiteMonochrome) opts.SetAtomLabelFontScale(1.2) DepictMoleculeWithFragmentCombinations(report, mol, frags, opts) return oedepict.OEWriteReport(oname, report)
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData, argv) ifname = itf.GetString("-in") ofname = itf.GetString("-out") ifs = oechem.oemolistream() if not ifs.open(ifname): oechem.OEThrow.Fatal("Unable to open %s for reading" % ifname) if not oechem.OEIs2DFormat(ifs.GetFormat()): oechem.OEThrow.Fatal("Invalid input format: need 2D coordinates") ofs = oechem.oemolostream() if not ofs.open(ofname): oechem.OEThrow.Fatal("Unable to open %s for writing" % ofname) if not oechem.OEIs2DFormat(ofs.GetFormat()): oechem.OEThrow.Fatal( "Invalid output format: unable to write 2D coordinates") nrrings = 0 for mol in ifs.GetOEGraphMols(): for ring in oechem.OEExtractRingTemplates(mol): nrrings += 1 oechem.OEWriteMolecule(ofs, ring) oechem.OEThrow.Info("%d number of ring templates extracted" % nrrings)
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
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData, argv) if not (itf.HasInt("-num") ^ itf.HasInt("-size")): oechem.OEThrow.Fatal( "Number of chunks (-num) or the size of each chunk (-size)" " must be specified and are mutually exclusive.") ifs = oechem.oemolistream() if not ifs.open(itf.GetString("-i")): oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-i")) ifs.SetConfTest(oechem.OEIsomericConfTest(False)) outbase, ext = os.path.splitext(itf.GetString("-o")) if ext == '': oechem.OEThrow.Fatal("Failed to find file extension") if ext == '.gz': outbase, ext = os.path.splitext(outbase) ext = ext + '.gz' if itf.HasInt("-num"): nparts = itf.GetInt("-num") SplitNParts(ifs, nparts, outbase, ext) else: chunksize = itf.GetInt("-size") SplitChunk(ifs, chunksize, outbase, ext)
def main(argv=(__name__)): """ the protein should have charges and radii but the ligand need not """ itf = oechem.OEInterface() if not oechem.OEConfigure(itf, InterfaceData): oechem.OEThrow.Fatal("Problem configuring OEInterface!") if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to parse command line") ligFile = itf.GetString("-l") ims = oechem.oemolistream() if not ims.open(ligFile): oechem.OEThrow.Fatal("Unable to open %s for reading" % ligFile) lig = oechem.OEGraphMol() oechem.OEReadMolecule(ims, lig) contextFile = itf.GetString("-p") ims = oechem.oemolistream() if not ims.open(contextFile): oechem.OEThrow.Fatal("Unable to open %s for reading" % contextFile) prot = oechem.OEGraphMol() oechem.OEReadMolecule(ims, prot) highRes = itf.GetBool("-high_res") GetSzmapEnergies(lig, prot, highRes)
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData, argv) cutoff = itf.GetFloat("-cutoff") ofs = oechem.oemolostream() if not ofs.open(itf.GetString("-clusters")): oechem.OEThrow.Fatal("Unable to open '%s'" % itf.GetString("-clusters")) if ofs.GetFormat() != oechem.OEFormat_OEB: oechem.OEThrow.Fatal("Output file must be OEB") sdtag = "TanimotoComboFromHead" if itf.GetBool("-shapeOnly"): sdtag = "ShapeTanimotoFromHead" getter = GetScoreGetter(itf.GetBool("-shapeOnly")) cluster = ShapeCluster(itf.GetString("-dbase"), cutoff, itf.GetBool("-shapeOnly")) # do the clustering while cluster.HasRemainingMolecules(): clusterHead = cluster.GetNextClusterHead() print("Searching for neighbors of %s" % clusterHead.GetTitle()) for nbrMol, score in cluster.GetCluster(clusterHead): oechem.OESetSDData(nbrMol, sdtag, "%.4f" % getter(score)) score.Transform(nbrMol) clusterHead.AddData(nbrMol.GetTitle(), nbrMol) oechem.OEWriteMolecule(ofs, clusterHead) return 0
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData, argv) isomeric = itf.GetBool("-isomeric") kekule = itf.GetBool("-kekule") from3d = itf.GetBool("-from3d") if from3d: isomeric = True ifs = oechem.oemolistream() ifile = itf.GetString("-i") if not ifs.open(ifile): oechem.OEThrow.Fatal("Unable to open %s for reading" % ifile) if itf.HasString("-o"): ofile = itf.GetString("-o") try: ofs = open(ofile, 'w') except Exception: oechem.OEThrow.Fatal("Unable to open %s for writing" % ofile) else: ofs = sys.stdout mol = oechem.OEGraphMol() while oechem.OEReadMolecule(ifs, mol): if from3d: oechem.OE3DToInternalStereo(mol) smi = CanSmi(mol, isomeric, kekule) if mol.GetTitle(): smi += (" %s" % mol.GetTitle()) ofs.write("%s\n" % smi)
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData) if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to interpret command line!") iname = itf.GetString("-i") oname = itf.GetString("-o") ims = oechem.oemolistream() if not ims.open(iname): oechem.OEThrow.Fatal("Cannot open input file!") oms = oechem.oemolostream() if not oms.open(oname): oechem.OEThrow.Fatal("Cannot open output file!") inmol = oechem.OEGraphMol() if not oechem.OEReadMolecule(ims, inmol): oechem.OEThrow.Fatal("Cannot read input file!") allSites = itf.GetBool("-a") splitCovalent = itf.GetBool("-c") separateResidues = itf.GetBool("-s") combineFilters = itf.GetBool("-pw") if combineFilters: SplitMolComplexCombineFilters(oms, inmol) elif allSites: SplitMolComplexAllSites(oms, inmol, splitCovalent) else: SplitMolComplex(oms, inmol, splitCovalent, separateResidues) oms.close()
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData) oemedchem.OEConfigureMatchedPairIndexOptions(itf) if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to interpret command line!") SerializeInput(itf)
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData) oemedchem.OEConfigureMCSFragDatabaseOptions(itf) if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to interpret command line!") MCSFragIndex(itf)
def main(argv=[__name__]): itf = oechem.OEInterface() oechem.OEConfigure(itf, InterfaceData) oedepict.OEConfigureImageWidth(itf, 400.0) oedepict.OEConfigureImageHeight(itf, 400.0) oedepict.OEConfigureImageGridParams(itf) oedepict.OEConfigurePrepareDepictionOptions(itf) oedepict.OEConfigure2DMolDisplayOptions(itf) if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to interpret command line!") 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!") width, height = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight( itf) image = oedepict.OEImage(width, height) rows = oedepict.OEGetImageGridNumRows(itf) cols = oedepict.OEGetImageGridNumColumns(itf) grid = oedepict.OEImageGrid(image, rows, cols) popts = oedepict.OEPrepareDepictionOptions() oedepict.OESetupPrepareDepictionOptions(popts, itf) dopts = oedepict.OE2DMolDisplayOptions() oedepict.OESetup2DMolDisplayOptions(dopts, itf) dopts.SetDimensions(grid.GetCellWidth(), grid.GetCellHeight(), oedepict.OEScale_AutoScale) celliter = grid.GetCells() for iname in itf.GetStringList("-in"): ifs = oechem.oemolistream() if not ifs.open(iname): oechem.OEThrow.Warning("Cannot open %s input file!" % iname) continue for mol in ifs.GetOEGraphMols(): if not celliter.IsValid(): break oedepict.OEPrepareDepiction(mol, popts) disp = oedepict.OE2DMolDisplay(mol, dopts) oedepict.OERenderMolecule(celliter.Target(), disp) celliter.Next() oedepict.OEWriteImage(ofs, ext, image) return 0
def smiles_to_image_grid_mod( smiles: set, output_path: str, cols: int = 8, cell_width: int = 200, cell_height: int = 200, ): from openeye import oechem, oedepict itf = oechem.OEInterface() PageByPage = True suppress_h = True rows = math.ceil(len(smiles) / cols) image = oedepict.OEImage(cell_width * cols, cell_height * rows) grid = oedepict.OEImageGrid(image, rows, cols) opts = oedepict.OE2DMolDisplayOptions( grid.GetCellWidth(), grid.GetCellHeight(), oedepict.OEScale_AutoScale ) opts.SetAromaticStyle(oedepict.OEAromaticStyle_Circle) opts.SetTitleLocation(oedepict.OETitleLocation_Bottom) for i, (smi, cell) in enumerate(zip(smiles, grid.GetCells())): mol = oechem.OEGraphMol() oechem.OESmilesToMol(mol, smi) center_bond = [] for atom in mol.GetAtoms(): if atom.GetMapIdx() >0: center_bond.append(atom.GetIdx()) # print(smi, center_bond) assert len(center_bond) == 2 oedepict.OEPrepareDepiction(mol, False, suppress_h) disp = oedepict.OE2DMolDisplay(mol, opts) # Highlight element of interest class NoAtom(oechem.OEUnaryAtomPred): def __call__(self, atom): return False class NoBond(oechem.OEUnaryBondPred): def __call__(self, bond): return False class CentralBondInTorsion(oechem.OEUnaryBondPred): def __call__(self, bond): return (bond.GetBgn().GetIdx() in center_bond) and (bond.GetEnd().GetIdx() in center_bond) atoms = mol.GetAtoms(NoAtom()) bonds = mol.GetBonds(CentralBondInTorsion()) abset = oechem.OEAtomBondSet(atoms, bonds) oedepict.OEAddHighlighting(disp, oechem.OEColor(oechem.OEMandarin), oedepict.OEHighlightStyle_BallAndStick, abset) oedepict.OERenderMolecule(cell, disp) oedepict.OEWriteImage(output_path, image)
def main(argv=[__name__]): itf = oechem.OEInterface(Interface, argv) totalmols = 0 for fname in itf.GetStringList("-i"): totalmols += MolCount(fname) print("===========================================================") print("Total %d molecules" % totalmols)
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData, argv) if not itf.HasString("-smirks") and not itf.HasString("-rxn"): oechem.OEThrow.Fatal( "Please provide SMIRKS string or MDL reaction file") if itf.HasString("-smirks") and itf.HasString("-rxn"): oechem.OEThrow.Fatal( "Please provide only SMIRKS string or MDL reaction file") reaction = oechem.OEQMol() if itf.HasString("-smirks"): smirks = itf.GetString("-smirks") if not oechem.OEParseSmirks(reaction, smirks): oechem.OEThrow.Fatal("Unable to parse SMIRKS: %s" % smirks) else: rxn = itf.GetString("-rxn") rfile = oechem.oemolistream(rxn) opt = oechem.OEMDLQueryOpts_ReactionQuery | oechem.OEMDLQueryOpts_SuppressExplicitH if not oechem.OEReadMDLReactionQueryFile(rfile, reaction, opt): oechem.OEThrow.Fatal("Unable to read reaction file: %s" % rxn) relax = itf.GetBool("-relax") unique = itf.GetBool("-unique") implicitH = itf.GetBool("-implicitH") valcorrect = itf.GetBool("-valence") isomeric = itf.GetBool("-isomeric") libgen = oechem.OELibraryGen() if not libgen.Init(reaction, not relax): oechem.OEThrow.Fatal("failed to initialize library generator") libgen.SetValenceCorrection(valcorrect) libgen.SetExplicitHydrogens(not implicitH) libgen.SetClearCoordinates(True) ofs = oechem.oemolostream(".smi") if itf.HasString("-product"): ofs.open(itf.GetString("-product")) nrReacts = 0 while itf.HasString("-reactants", nrReacts): fileName = itf.GetString("-reactants", nrReacts) if nrReacts >= libgen.NumReactants(): oechem.OEThrow.Fatal("Number of reactant files exceeds number of \ reactants specified in reaction") ifs = oechem.oemolistream() if not ifs.open(fileName): oechem.OEThrow.Fatal("Unable to read %s reactant file" % fileName) for mol in ifs.GetOEGraphMols(): libgen.AddStartingMaterial(mol, nrReacts, unique) nrReacts += 1 if nrReacts != libgen.NumReactants(): oechem.OEThrow.Fatal("Reactions requires %d reactant files!" % libgen.NumReactants()) LibGen(libgen, ofs, unique, isomeric)
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData, argv) if not itf.GetBool("-verbose"): oechem.OEThrow.SetLevel(oechem.OEErrorLevel_Warning) rfname = itf.GetString("-ref") ifname = itf.GetString("-in") automorph = itf.GetBool("-automorph") heavy = itf.GetBool("-heavyonly") overlay = itf.GetBool("-overlay") ifs = oechem.oemolistream() if not ifs.open(rfname): oechem.OEThrow.Fatal("Unable to open %s for reading" % rfname) rmol = oechem.OEGraphMol() if not oechem.OEReadMolecule(ifs, rmol): oechem.OEThrow.Fatal("Unable to read reference molecule") ifs = oechem.oemolistream() if not ifs.open(ifname): oechem.OEThrow.Fatal("Unable to open %s for reading" % ifname) ofs = oechem.oemolostream() if itf.HasString("-out"): ofname = itf.GetString("-out") if not ofs.open(ofname): oechem.OEThrow.Fatal("Unable to open %s for writing" % ofname) if not overlay: oechem.OEThrow.Warning( "Output is the same as input when overlay is false") for mol in ifs.GetOEMols(): oechem.OEThrow.Info(mol.GetTitle()) rmsds = oechem.OEDoubleArray(mol.GetMaxConfIdx()) rmtx = oechem.OEDoubleArray(9 * mol.GetMaxConfIdx()) tmtx = oechem.OEDoubleArray(3 * mol.GetMaxConfIdx()) # perform RMSD for all confomers oechem.OERMSD(rmol, mol, rmsds, automorph, heavy, overlay, rmtx, tmtx) for conf in mol.GetConfs(): cidx = conf.GetIdx() oechem.OEThrow.Info("Conformer %i : rmsd = %f" % (cidx, rmsds[cidx])) if itf.GetBool("-overlay"): oechem.OERotate(conf, rmtx[cidx * 9:cidx * 9 + 9]) oechem.OETranslate(conf, tmtx[cidx * 3:cidx * 3 + 3]) if itf.HasString("-out"): oechem.OEWriteMolecule(ofs, mol) return 0
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData, argv) if not (itf.HasDouble("-min") or itf.HasDouble("-max")): oechem.OEThrow.Fatal("Please set a filter value with -min or -max") ifs = oechem.oemolistream() if not ifs.open(itf.GetString("-i")): oechem.OEThrow.Fatal("Unable to open %s for reading" % itf.GetString("-i")) if not oechem.OEIsSDDataFormat(ifs.GetFormat()): oechem.OEThrow.Fatal( "Only works for input file formats that support SD data (sdf,oeb,csv)" ) ofs = oechem.oemolostream() if not ofs.open(itf.GetString("-o")): oechem.OEThrow.Fatal("Unable to open %s for writing" % itf.GetString("-i")) if not oechem.OEIsSDDataFormat(ofs.GetFormat()): oechem.OEThrow.Fatal( "Only works for output file formats that support SD data \ (sdf,oeb,csv)") tag = itf.GetString("-tag") minval = float("-inf") if itf.HasDouble("-min"): minval = itf.GetDouble("-min") maxval = float("inf") if itf.HasDouble("-max"): maxval = itf.GetDouble("-max") for mol in ifs.GetOEGraphMols(): if not oechem.OEHasSDData(mol, tag): oechem.OEThrow.Warning("Unable to find %s tag on %s" % (tag, mol.GetTitle())) continue value = oechem.OEGetSDData(mol, tag) try: tagvalue = float(value) except ValueError: oechem.OEThrow.Warning("Failed to convert (%s) to a number in %s" % (value, mol.GetTitle())) continue if tagvalue < minval: continue if tagvalue > maxval: continue oechem.OEWriteMolecule(ofs, mol)
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData, argv) # Set up best overlay to the query molecule qfs = oechem.oemolistream() if not qfs.open(itf.GetString("-q")): oechem.OEThrow.Fatal("Unable to open %s" % itf.GetString("-q")) qmol = oechem.OEMol() oechem.OEReadMolecule(qfs, qmol) # Set up overlap to protein exclusion volume efs = oechem.oemolistream() if not efs.open(itf.GetString("-e")): oechem.OEThrow.Fatal("Unable to open %s" % itf.GetString("-e")) emol = oechem.OEMol() oechem.OEReadMolecule(efs, emol) evol = oeshape.OEExactShapeFunc() evol.SetupRef(emol) # open database and output streams ifs = oechem.oemolistream() if not ifs.open(itf.GetString("-d")): oechem.OEThrow.Fatal("Unable to open %s" % itf.GetString("-d")) ofs = oechem.oemolostream() if not ofs.open(itf.GetString("-o")): oechem.OEThrow.Fatal("Unable to open %s" % itf.GetString("-o")) print("Title Combo Rescore") for mol in ifs.GetOEMols(): res = oeshape.OEROCSResult() oeshape.OEROCSOverlay(res, qmol, mol) outmol = res.GetOverlayConf() # calculate overlap with protein eres = oeshape.OEOverlapResults() evol.Overlap(outmol, eres) frac = eres.GetOverlap() / eres.GetFitSelfOverlap() rescore = res.GetTanimotoCombo() - frac # attach data to molecule and write it oechem.OESetSDData(outmol, "TanimotoCombo", "%-.3f" % res.GetTanimotoCombo()) oechem.OESetSDData(outmol, "Exclusion Volume", "%-.3f" % eres.overlap) oechem.OESetSDData(outmol, "Fraction Overlap", "%-.3f" % frac) oechem.OESetSDData(outmol, "Rescore", "%-.3f" % rescore) oechem.OEWriteMolecule(ofs, outmol) print("%-20s %.3f %.3f" % (outmol.GetTitle(), res.GetTanimotoCombo(), rescore))
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)