def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData) oechem.OEConfigureSplitMolComplexOptions(itf) if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to interpret command line!") iname = itf.GetString("-in") oname = itf.GetString("-out") ims = oechem.oemolistream() if not itf.GetUnsignedInt("-modelnum") == 1: ims.SetFlavor( oechem.OEFormat_PDB, oechem.OEGetDefaultIFlavor(oechem.OEFormat_PDB) & ~oechem.OEIFlavor_PDB_ENDM) 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!") opts = oechem.OESplitMolComplexOptions() oechem.OESetupSplitMolComplexOptions(opts, itf) if itf.GetBool("-verbose"): # don't bother counting sites unless we're going to print them numSites = oechem.OECountMolComplexSites(inmol, opts) oechem.OEThrow.SetLevel(oechem.OEErrorLevel_Verbose) oechem.OEThrow.Verbose("sites %d" % numSites) for frag in oechem.OEGetMolComplexComponents(inmol, opts): oechem.OEThrow.Verbose("frag %s" % frag.GetTitle()) oechem.OEWriteMolecule(oms, frag) oms.close()
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData) oechem.OEConfigureSplitMolComplexOptions(itf) if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to interpret command line!") if itf.GetBool("-verbose"): oechem.OEThrow.SetLevel(oechem.OEErrorLevel_Verbose) iname = itf.GetString("-in") oname = itf.GetString("-out") ims = oechem.oemolistream() if not itf.GetUnsignedInt("-modelnum") == 1: ims.SetFlavor(oechem.OEFormat_PDB, oechem.OEGetDefaultIFlavor(oechem.OEFormat_PDB) & ~oechem.OEIFlavor_PDB_ENDM) 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!") opts = oechem.OESplitMolComplexOptions() oechem.OESetupSplitMolComplexOptions(opts, itf) if itf.GetBool("-verbose"): # don't bother counting sites unless we're going to print them numSites = oechem.OECountMolComplexSites(inmol, opts) oechem.OEThrow.SetLevel(oechem.OEErrorLevel_Verbose) oechem.OEThrow.Verbose("sites %d" % numSites) lig = oechem.OEGraphMol() prot = oechem.OEGraphMol() wat = oechem.OEGraphMol() other = oechem.OEGraphMol() if not oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opts): oechem.OEThrow.Fatal("Unable to split mol complex from %s" % iname) if not lig.NumAtoms() == 0: oechem.OEThrow.Verbose(" lig %s" % lig.GetTitle()) oechem.OEWriteMolecule(oms, lig) if not prot.NumAtoms() == 0: oechem.OEThrow.Verbose(" prot %s" % prot.GetTitle()) oechem.OEWriteMolecule(oms, prot) if not wat.NumAtoms() == 0: oechem.OEThrow.Verbose(" wat %s" % wat.GetTitle()) oechem.OEWriteMolecule(oms, wat) if not other.NumAtoms() == 0: oechem.OEThrow.Verbose("other %s" % other.GetTitle()) oechem.OEWriteMolecule(oms, other) oms.close()
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) if not oechem.OEParseCommandLine(itf, argv): return 1 iname = itf.GetString("-complex") oname = itf.GetString("-out") ifs = oechem.oemolistream() if not ifs.open(iname): oechem.OEThrow.Fatal("Cannot open input file!") 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!") complexmol = oechem.OEGraphMol() if not oechem.OEReadMolecule(ifs, complexmol): oechem.OEThrow.Fatal("Unable to read molecule from %s" % iname) if not oechem.OEHasResidues(complexmol): oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All) # Separate ligand and protein sopts = oechem.OESplitMolComplexOptions() oechem.OESetupSplitMolComplexOptions(sopts, itf) ligand = oechem.OEGraphMol() protein = oechem.OEGraphMol() water = oechem.OEGraphMol() other = oechem.OEGraphMol() pfilter = sopts.GetProteinFilter() wfilter = sopts.GetWaterFilter() sopts.SetProteinFilter(oechem.OEOrRoleSet(pfilter, wfilter)) sopts.SetWaterFilter( oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Nothing)) oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts) if ligand.NumAtoms() == 0: oechem.OEThrow.Fatal("Cannot separate complex!") # Perceive interactions asite = oechem.OEInteractionHintContainer(protein, ligand) if not asite.IsValid(): oechem.OEThrow.Fatal("Cannot initialize active site!") asite.SetTitle(ligand.GetTitle()) oechem.OEPerceiveInteractionHints(asite) oegrapheme.OEPrepareActiveSiteDepiction(asite) # Depict active site with interactions width, height = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight( itf) image = oedepict.OEImage(width, height) cframe = oedepict.OEImageFrame(image, width * 0.80, height, oedepict.OE2DPoint(0.0, 0.0)) lframe = oedepict.OEImageFrame(image, width * 0.20, height, oedepict.OE2DPoint(width * 0.80, 0.0)) opts = oegrapheme.OE2DActiveSiteDisplayOptions(cframe.GetWidth(), cframe.GetHeight()) oedepict.OESetup2DMolDisplayOptions(opts, itf) adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts) oegrapheme.OERenderActiveSite(cframe, adisp) lopts = oegrapheme.OE2DActiveSiteLegendDisplayOptions(10, 1) oegrapheme.OEDrawActiveSiteLegend(lframe, adisp, lopts) oedepict.OEWriteImage(oname, image) return 0
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData) oechem.OEConfigureSplitMolComplexOptions(itf) if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to interpret command line!") if itf.GetBool("-verbose"): oechem.OEThrow.SetLevel(oechem.OEErrorLevel_Verbose) iname = itf.GetString("-in") oname = itf.GetString("-out") ims = oechem.oemolistream() if not itf.GetUnsignedInt("-modelnum") == 1: ims.SetFlavor( oechem.OEFormat_PDB, oechem.OEGetDefaultIFlavor(oechem.OEFormat_PDB) & ~oechem.OEIFlavor_PDB_ENDM) 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!") mol = oechem.OEGraphMol() if not oechem.OEReadMolecule(ims, mol): oechem.OEThrow.Fatal("Cannot read input file!") if itf.GetBool("-verbose"): oechem.OEThrow.SetLevel(oechem.OEErrorLevel_Verbose) opt = oechem.OESplitMolComplexOptions() oechem.OESetupSplitMolComplexOptions(opt, itf) # @ <SNIPPET-SPLIT-MOL-COMPLEX-LOWLEVEL-FRAGMENT> # for input molecule mol and options opt ... frags = oechem.OEAtomBondSetVector() if oechem.OEGetMolComplexFragments(frags, mol, opt): # ... # @ </SNIPPET-SPLIT-MOL-COMPLEX-LOWLEVEL-FRAGMENT> oechem.OEThrow.Verbose("Able to fragment mol complex from %s" % iname) else: oechem.OEThrow.Fatal("Unable to fragment mol complex from %s" % iname) # @ <SNIPPET-SPLIT-MOL-COMPLEX-LOWLEVEL-COMBINE> # for options opt and OEAtomBondSetVector frags produced earlier ... numSites = oechem.OECountMolComplexSites(frags) oechem.OEThrow.Verbose("sites %d" % numSites) lig = oechem.OEGraphMol() ligfilter = opt.GetLigandFilter() if not oechem.OECombineMolComplexFragments(lig, frags, opt, ligfilter): oechem.OEThrow.Warning("Unable to combine ligand frags from %s" % mol.GetTitle()) protComplex = oechem.OEGraphMol() p = opt.GetProteinFilter() w = opt.GetWaterFilter() if not oechem.OECombineMolComplexFragments(protComplex, frags, opt, oechem.OEOrRoleSet(p, w)): oechem.OEThrow.Warning("Unable to combine complex frags from %s" % mol.GetTitle()) # @ </SNIPPET-SPLIT-MOL-COMPLEX-LOWLEVEL-COMBINE> if not lig.NumAtoms() == 0: oechem.OEThrow.Verbose(" lig %s" % lig.GetTitle()) oechem.OEWriteMolecule(oms, lig) if not protComplex.NumAtoms() == 0: oechem.OEThrow.Verbose(" prot %s" % protComplex.GetTitle()) oechem.OEWriteMolecule(oms, protComplex) oms.close()
def main(argv=[__name__]): itf = oechem.OEInterface() oechem.OEConfigure(itf, InterfaceData) oedepict.OEConfigureImageWidth(itf, 600.0) oedepict.OEConfigureImageHeight(itf, 600.0) oedepict.OEConfigure2DMolDisplayOptions(itf, oedepict.OE2DMolDisplaySetup_AromaticStyle) oechem.OEConfigureSplitMolComplexOptions(itf, oechem.OESplitMolComplexSetup_LigName) if not oechem.OEParseCommandLine(itf, argv): return 1 iname = itf.GetString("-complex") oname = itf.GetString("-out") ifs = oechem.oemolistream() if not ifs.open(iname): oechem.OEThrow.Fatal("Cannot open input file!") 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!") complexmol = oechem.OEGraphMol() if not oechem.OEReadMolecule(ifs, complexmol): oechem.OEThrow.Fatal("Unable to read molecule from %s" % iname) if not oechem.OEHasResidues(complexmol): oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All) # Separate ligand and protein sopts = oechem.OESplitMolComplexOptions() oechem.OESetupSplitMolComplexOptions(sopts, itf) ligand = oechem.OEGraphMol() protein = oechem.OEGraphMol() water = oechem.OEGraphMol() other = oechem.OEGraphMol() oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts) if ligand.NumAtoms() == 0: oechem.OEThrow.Fatal("Cannot separate complex!") # Calculate average BFactor of the whole complex avgbfactor = GetAverageBFactor(complexmol) # Calculate minimum and maximum BFactor of the ligand and its environment minbfactor, maxbfactor = GetMinAndMaxBFactor(ligand, protein) # Attach to each ligand atom the average BFactor of the nearby protein atoms stag = "avg residue BFfactor" itag = oechem.OEGetTag(stag) SetAverageBFactorOfNearbyProteinAtoms(ligand, protein, itag) oechem.OEThrow.Info("Average BFactor of the complex = %+.3f" % avgbfactor) oechem.OEThrow.Info("Minimum BFactor of the ligand and its environment = %+.3f" % minbfactor) oechem.OEThrow.Info("Maximum BFactor of the ligand and its environment = %+.3f" % maxbfactor) # Create image imagewidth, imageheight = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight(itf) image = oedepict.OEImage(imagewidth, imageheight) mframe = oedepict.OEImageFrame(image, imagewidth, imageheight * 0.90, oedepict.OE2DPoint(0.0, 0.0)) lframe = oedepict.OEImageFrame(image, imagewidth, imageheight * 0.10, oedepict.OE2DPoint(0.0, imageheight * 0.90)) opts = oedepict.OE2DMolDisplayOptions(mframe.GetWidth(), mframe.GetHeight(), oedepict.OEScale_AutoScale) oedepict.OESetup2DMolDisplayOptions(opts, itf) opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_WhiteMonochrome) # Create BFactor color gradient colorg = oechem.OELinearColorGradient() colorg.AddStop(oechem.OEColorStop(0.0, oechem.OEDarkBlue)) colorg.AddStop(oechem.OEColorStop(10.0, oechem.OELightBlue)) colorg.AddStop(oechem.OEColorStop(25.0, oechem.OEYellowTint)) colorg.AddStop(oechem.OEColorStop(50.0, oechem.OERed)) colorg.AddStop(oechem.OEColorStop(100.0, oechem.OEDarkRose)) # Prepare ligand for depiction oegrapheme.OEPrepareDepictionFrom3D(ligand) arcfxn = BFactorArcFxn(colorg, itag) for atom in ligand.GetAtoms(): oegrapheme.OESetSurfaceArcFxn(ligand, atom, arcfxn) opts.SetScale(oegrapheme.OEGetMoleculeSurfaceScale(ligand, opts)) # Render ligand and visualize BFactor disp = oedepict.OE2DMolDisplay(ligand, opts) colorbfactor = ColorLigandAtomByBFactor(colorg) oegrapheme.OEAddGlyph(disp, colorbfactor, oechem.OEIsTrueAtom()) oegrapheme.OEDraw2DSurface(disp) oedepict.OERenderMolecule(mframe, disp) # Draw color gradient opts = oegrapheme.OEColorGradientDisplayOptions() opts.SetColorStopPrecision(1) opts.AddMarkedValue(avgbfactor) opts.SetBoxRange(minbfactor, maxbfactor) oegrapheme.OEDrawColorGradient(lframe, colorg, opts) oedepict.OEWriteImage(oname, image) return 0
def main(argv=[__name__]): itf = oechem.OEInterface() oechem.OEConfigure(itf, InterfaceData) oechem.OEConfigureSplitMolComplexOptions( itf, oechem.OESplitMolComplexSetup_LigName) if not oechem.OEParseCommandLine(itf, argv): return 1 iname = itf.GetString("-complex") ifs = oechem.oemolistream() if not ifs.open(iname): oechem.OEThrow.Fatal("Unable to open %s for reading" % iname) complexmol = oechem.OEGraphMol() if not oechem.OEReadMolecule(ifs, complexmol): oechem.OEThrow.Fatal("Unable to read molecule from %s" % iname) if not oechem.OEHasResidues(complexmol): oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All) # Separate ligand and protein sopts = oechem.OESplitMolComplexOptions() oechem.OESetupSplitMolComplexOptions(sopts, itf) ligand = oechem.OEGraphMol() protein = oechem.OEGraphMol() water = oechem.OEGraphMol() other = oechem.OEGraphMol() pfilter = sopts.GetProteinFilter() wfilter = sopts.GetWaterFilter() sopts.SetProteinFilter(oechem.OEOrRoleSet(pfilter, wfilter)) sopts.SetWaterFilter( oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Nothing)) oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts) if ligand.NumAtoms() == 0: oechem.OEThrow.Fatal("Cannot separate complex!") # Perceive interactions asite = oechem.OEInteractionHintContainer(protein, ligand) if not oechem.OEIsValidActiveSite(asite): oechem.OEThrow.Fatal("Cannot initialize active site!") oechem.OEPerceiveInteractionHints(asite) print("Number of interactions:", asite.NumInteractions()) for itype in oechem.OEGetActiveSiteInteractionHintTypes(): numinters = asite.NumInteractions( oechem.OEHasInteractionHintType(itype)) if numinters == 0: continue print("%d %s :" % (numinters, itype.GetName())) inters = [ s for s in asite.GetInteractions( oechem.OEHasInteractionHintType(itype)) ] print("\n".join(sorted(GetInteractionString(s) for s in inters))) print("\nResidue interactions:") for res in oechem.OEGetResidues( asite.GetMolecule(oechem.OEProteinInteractionHintComponent())): PrintResidueInteractions(asite, res) print("\nLigand atom interactions:") for atom in asite.GetMolecule( oechem.OELigandInteractionHintComponent()).GetAtoms(): PrintLigandAtomInteractions(asite, atom)
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
def main(argv=[__name__]): itf = oechem.OEInterface(InterfaceData) oechem.OEConfigureSplitMolComplexOptions(itf) if not oechem.OEParseCommandLine(itf, argv): oechem.OEThrow.Fatal("Unable to interpret command line!") opts = oechem.OESplitMolComplexOptions() oechem.OESetupSplitMolComplexOptions(opts, itf) # @ </SNIPPET-SPLIT-MOL-COMPLEX-ITF> iname = itf.GetString("-in") oname = itf.GetString("-out") ims = oechem.oemolistream() if not itf.GetUnsignedInt("-modelnum") == 1: ims.SetFlavor( oechem.OEFormat_PDB, oechem.OEGetDefaultIFlavor(oechem.OEFormat_PDB) & ~oechem.OEIFlavor_PDB_ENDM) 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!") bfixTitles = (oms.GetFormat() == oechem.OEFormat_SDF) sTitleSDTag = "TITLE" inmol = oechem.OEGraphMol() if not oechem.OEReadMolecule(ims, inmol): oechem.OEThrow.Fatal("Cannot read input file!") lig = oechem.OEGraphMol() prot = oechem.OEGraphMol() wat = oechem.OEGraphMol() other = oechem.OEGraphMol() if not oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opts): oechem.OEThrow.Fatal("Unable to split mol complex from %s" % iname) if not lig.NumAtoms() == 0: if bfixTitles: FixSDFTitle(sTitleSDTag, lig) oechem.OEWriteMolecule(oms, lig) if not prot.NumAtoms() == 0: if bfixTitles: FixSDFTitle(sTitleSDTag, prot) oechem.OEWriteMolecule(oms, prot) if not wat.NumAtoms() == 0: if bfixTitles: FixSDFTitle(sTitleSDTag, wat) oechem.OEWriteMolecule(oms, wat) if not other.NumAtoms() == 0: if bfixTitles: FixSDFTitle(sTitleSDTag, other) oechem.OEWriteMolecule(oms, other) oms.close()