def main(argv=[__name__]): if len(argv) != 4: oechem.OEThrow.Usage("%s <refmol> <fitmol> <outfile>" % argv[0]) reffs = oechem.oemolistream() if not reffs.open(argv[1]): oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1]) if not oechem.OEIs3DFormat(reffs.GetFormat()): oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates") refmol = oechem.OEGraphMol() if not oechem.OEReadMolecule(reffs, refmol): oechem.OEThrow.Fatal("Unable to read molecule in %s" % argv[1]) if not refmol.GetDimension() == 3: oechem.OEThrow.Fatal("%s doesn't have 3D coordinates" % refmol.GetTitle()) fitfs = oechem.oemolistream() if not fitfs.open(argv[2]): oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[2]) if not oechem.OEIs3DFormat(fitfs.GetFormat()): oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates") ofs = oechem.oemolostream() if not ofs.open(argv[3]): oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[3]) if not oechem.OEIs3DFormat(ofs.GetFormat()): oechem.OEThrow.Fatal("Invalid output format: need 3D coordinates") oechem.OEWriteConstMolecule(ofs, refmol) oechem.OESuppressHydrogens(refmol) for fitmol in fitfs.GetOEGraphMols(): if not fitmol.GetDimension() == 3: oechem.OEThrow.Warning("%s doesn't have 3D coordinates" % fitmol.GetTitle()) continue MCSAlign(refmol, fitmol, ofs)
def main(argv=[__name__]): if len(argv) != 5: oechem.OEThrow.Usage("%s <refmol> <fitmol> <outfile> <smarts>" % argv[0]) reffs = oechem.oemolistream() if not reffs.open(argv[1]): oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1]) if not oechem.OEIs3DFormat(reffs.GetFormat()): oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates") refmol = oechem.OEGraphMol() if not oechem.OEReadMolecule(reffs, refmol): oechem.OEThrow.Fatal("Unable to read molecule in %s" % argv[1]) if not refmol.GetDimension() == 3: oechem.OEThrow.Fatal("%s doesn't have 3D coordinates" % refmol.GetTitle()) fitfs = oechem.oemolistream() if not fitfs.open(argv[2]): oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[2]) if not oechem.OEIs3DFormat(fitfs.GetFormat()): oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates") ofs = oechem.oemolostream() if not ofs.open(argv[3]): oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[3]) if not oechem.OEIs3DFormat(ofs.GetFormat()): oechem.OEThrow.Fatal("Invalid output format: need 3D coordinates") oechem.OEWriteConstMolecule(ofs, refmol) ss = oechem.OESubSearch() if not ss.Init(argv[4]): oechem.OEThrow.Fatal("Unable to parse SMARTS: %s" % argv[4]) oechem.OEPrepareSearch(refmol, ss) if not ss.SingleMatch(refmol): oechem.OEThrow.Fatal("SMARTS fails to match refmol") for fitmol in fitfs.GetOEGraphMols(): if not fitmol.GetDimension() == 3: oechem.OEThrow.Warning("%s doesn't have 3D coordinates" % fitmol.GetTitle()) continue oechem.OEPrepareSearch(fitmol, ss) if not ss.SingleMatch(fitmol): oechem.OEThrow.Warning("SMARTS fails to match fitmol %s" % fitmol.GetTitle()) continue SmartsAlign(refmol, fitmol, ss, ofs)
def main(argv=[__name__]): if len(argv) != 3: oechem.OEThrow.Usage("%s <infile> <outfile>" % argv[0]) ifs = oechem.oemolistream() if not ifs.open(argv[1]): oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1]) ofs = oechem.oemolostream() if not ofs.open(argv[2]): oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[2]) if not oechem.OEIs3DFormat(ofs.GetFormat()): oechem.OEThrow.Fatal("Invalid output file format for 3D coordinates!") omegaOpts = oeomega.OEMacrocycleOmegaOptions() mcomega = oeomega.OEMacrocycleOmega(omegaOpts) for mol in ifs.GetOEMols(): oechem.OEThrow.Info("Title: %s" % mol.GetTitle()) ret_code = mcomega.Build(mol) if ret_code == oeomega.OEOmegaReturnCode_Success: oechem.OEWriteMolecule(ofs, mol) else: oechem.OEThrow.Warning("%s: %s" % (mol.GetTitle(), oeomega.OEGetOmegaError(ret_code))) return 0
def ReadMolecule(filename): mol = oechem.OEGraphMol() ifs = oechem.oemolistream() if not ifs.open(filename): oechem.OEThrow.Fatal("Unable to open %s for reading", filename) if not oechem.OEIs3DFormat(ifs.GetFormat()): oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates") if not oechem.OEReadMolecule(ifs, mol): oechem.OEThrow.Fatal("Unable to read a molecule from %s", filename) return mol
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData) if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to interpret command line!") # @ <SNIPPET-ALTLOCFACT-FLAVOR> ims = oechem.oemolistream() ims.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_ALTLOC) # @ </SNIPPET-ALTLOCFACT-FLAVOR> inputFile = itf.GetString("-in") if not ims.open(inputFile): oechem.OEThrow.Fatal("Unable to open %s for reading." % inputFile) if not oechem.OEIs3DFormat(ims.GetFormat()): oechem.OEThrow.Fatal("%s is not in a 3D format." % inputFile) mol = oechem.OEGraphMol() if not oechem.OEReadMolecule(ims, mol): oechem.OEThrow.Fatal("Unable to read %s." % inputFile) if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) # @ <SNIPPET-ALTLOCFACT-PRIMARY> alf = oechem.OEAltLocationFactory(mol) if alf.GetGroupCount() != 0: alf.MakePrimaryAltMol(mol) # @ </SNIPPET-ALTLOCFACT-PRIMARY> # @ <SNIPPET-PLACE-HYDROGENS-BASIC> if oechem.OEPlaceHydrogens(mol): # ... # @ </SNIPPET-PLACE-HYDROGENS-BASIC> print("success") # @ <SNIPPET-PLACE-HYDROGENS-OPTIONS> opt = oechem.OEPlaceHydrogensOptions() opt.SetStandardizeBondLen(False) # @ </SNIPPET-PLACE-HYDROGENS-OPTIONS> # @ <SNIPPET-PLACE-HYDROGENS-DETAILS> # given molecule mol and OEPlaceHydrogensOptions opt... details = oechem.OEPlaceHydrogensDetails() if oechem.OEPlaceHydrogens(mol, details, opt): print(details.Describe()) # @ </SNIPPET-PLACE-HYDROGENS-DETAILS> ims.close()
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData) if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to interpret command line!") ims = oechem.oemolistream() ims.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_ALTLOC) inputFile = itf.GetString("-in") if not ims.open(inputFile): oechem.OEThrow.Fatal("Unable to open %s for reading." % inputFile) if not oechem.OEIs3DFormat(ims.GetFormat()): oechem.OEThrow.Fatal("%s is not in a 3D format." % inputFile) mol = oechem.OEGraphMol() if not oechem.OEReadMolecule(ims, mol): oechem.OEThrow.Fatal("Unable to read %s." % inputFile) if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) alf = oechem.OEAltLocationFactory(mol) if alf.GetGroupCount() != 0: alf.MakePrimaryAltMol(mol) # in our example, we will select the first histidine selectedResidue = oechem.OEResidue() for atom in mol.GetAtoms(): res = oechem.OEAtomGetResidue(atom) if oechem.OEGetResidueIndex(res) == oechem.OEResidueIndex_HIS: selectedResidue = res break # @ <SNIPPET-PLACE-HYDROGENS-PRED> # given predicate IsSameResidue, residue selectedResidue and molecule mol... opt = oechem.OEPlaceHydrogensOptions() opt.SetNoFlipPredicate(IsSameResidue(selectedResidue)) if oechem.OEPlaceHydrogens(mol, opt): # selectedResidue will not be flipped... # @ </SNIPPET-PLACE-HYDROGENS-PRED> print("success") ims.close()
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()
# or its use. from __future__ import print_function import sys from openeye import oechem from openeye import oezap if len(sys.argv) != 2: oechem.OEThrow.Usage("%s <molfile>" % sys.argv[0]) mol = oechem.OEGraphMol() ifs = oechem.oemolistream() if not ifs.open(sys.argv[1]): oechem.OEThrow.Fatal("Unable to open %s for reading", sys.argv[1]) if not oechem.OEIs3DFormat(ifs.GetFormat()): oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates") oechem.OEReadMolecule(ifs, mol) oechem.OEAssignBondiVdWRadii(mol) oechem.OEMMFFAtomTypes(mol) oechem.OEMMFF94PartialCharges(mol) # @ <SNIPPET-GetArea-Molecule> area = oezap.OEArea() a = area.GetArea(mol) print("Molecule area =", a) # @ </SNIPPET-GetArea-Molecule> # @ <SNIPPET-GetArea-Atoms> atomArea = oechem.OEFloatArray(mol.GetMaxAtomIdx())