def SetupStream(strm, format): format = format.strip('.') ftype = oechem.OEGetFileType(format) if ftype == oechem.OEFormat_UNDEFINED: raise ValueError("Unsupported file format sent to server '%s'" % format) strm.SetFormat(ftype) strm.Setgz(oechem.OEIsGZip(format)) return strm
def SetupInterface(argv, itf): oechem.OEConfigure(itf, InterfaceData) if oechem.OECheckHelp(itf, argv): return False if not oechem.OEParseCommandLine(itf, argv): return False if not oechem.OEIsReadable( oechem.OEGetFileType( oechem.OEGetFileExtension(itf.GetString("-in")))): oechem.OEThrow.Warning("%s is not a readable input file" % itf.GetString("-in")) return False if not oechem.OEIsWriteable( oechem.OEGetFileType( oechem.OEGetFileExtension(itf.GetString("-out")))): oechem.OEThrow.Warning("%s is not a writable output file" % itf.GetString("-out")) return False return True
def main(argv=[__name__]): if len(argv) != 3: oechem.OEThrow.Usage("%s <input> <output>" % argv[0]) # input - preserve rotor-offset-compression ifs = oechem.oemolistream() ihand = ifs.GetBinaryIOHandler() ihand.Clear() oechem.OEInitHandler(ihand, oechem.OEBRotCompressOpts(), oechem.OEBRotCompressOpts()) ifname = argv[1] if not ifs.open(ifname): oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1]) # output ofname = argv[2] oformt = oechem.OEGetFileType(oechem.OEGetFileExtension(ofname)) if oformt != oechem.OEFormat_OEB: oechem.OEThrow.Fatal("Output file format much be OEB") ofs = oechem.oemolostream() if not ofs.open(ofname): oechem.OEThrow.Fatal("Unable to open %s for writing" % ofname) iss = oechem.oeisstream(COLOR_FORCE_FIELD) cff = oeshape.OEColorForceField() if not cff.Init(iss): oechem.OEThrow.Fatal("Unable to initialize OEColorForceField") dots = oechem.OEDots(10000, 200, "molecules") for mol in ifs.GetOEMols(): oefastrocs.OEPrepareFastROCSMol(mol, cff) oechem.OEWriteMolecule(ofs, mol) dots.Update() dots.Total() ofs.close() print("Indexing %s" % ofname) if not oechem.OECreateMolDatabaseIdx(ofname): oechem.OEThrow.Fatal("Failed to index %s" % argv[2]) return 0
def __init__(self, ipf, keepAlts=F, verbose=T): self.ipf = ipf self.keepAlts = keepAlts self.verbose = verbose flavor = oechem.OEIFlavor_PDB_Default ims = oechem.oemolistream() ims.SetFlavor(oechem.OEFormat_PDB, flavor) if not ims.open(self.ipf): oechem.OEThrow.Fatal("Unable to open %s for reading." % self.ipf) if not oechem.OEIs3DFormat(ims.GetFormat()): oechem.OEThrow.Fatal("%s is not in a 3D format." % self.ipf) iftp = oechem.OEGetFileType(oechem.OEGetFileExtension(self.ipf)) if (iftp == oechem.OEFormat_PDB) and not self.keepAlts: oechem.OEThrow.Verbose( "Default processing of alt locations (keep just 'A' and ' ').") inmol = oechem.OEGraphMol() if not oechem.OEReadMolecule(ims, inmol): oechem.OEThrow.Fatal("Unable to read %s." % self.ipf) ims.close() if (inmol.NumAtoms() == 0): oechem.OEThrow.Fatal("Input molecule %s contains no atoms." % self.ipf) if inmol.GetTitle() == "": inmol.SetTitle(ipf[:-4]) oechem.OEThrow.Verbose("Processing %s." % inmol.GetTitle()) if not oechem.OEHasResidues(inmol): oechem.OEPerceiveResidues(inmol, oechem.OEPreserveResInfo_All) self.inmol = inmol self.mol = inmol.CreateCopy()
# 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. # @ <SNIPPET> from openeye import oechem import sys if len(sys.argv) != 4: oechem.OEThrow.Usage("%s <input> <output> <title>" % sys.argv[0]) moldb = oechem.OEMolDatabase() if not moldb.Open(sys.argv[1]): oechem.OEThrow.Fatal("Unable to open %s" % sys.argv[1]) if moldb.GetFormat() != oechem.OEGetFileType( oechem.OEGetFileExtension(sys.argv[2])): oechem.OEThrow.Fatal( "Output format does not match input format: %s != %s" % (oechem.OEGetFileExtension( sys.argv[1]), oechem.OEGetFileExtension(sys.argv[2]))) ofs = oechem.oemolostream() if not ofs.open(sys.argv[2]): oechem.OEThrow.Fatal("Unable to open %s for writing" % sys.argv[2]) title = sys.argv[3] for idx in range(moldb.GetMaxMolIdx()): if moldb.GetTitle(idx) == title: moldb.WriteMolecule(ofs, idx) # @ </SNIPPET>