def split_complex(protein, ligand, sopts, complexmol): water = oechem.OEGraphMol() other = oechem.OEGraphMol() pfilter = sopts.GetProteinFilter() wfilter = sopts.GetWaterFilter() sopts.SetProteinFilter(oechem.OEOrRoleSet(pfilter, wfilter)) filter = oechem.OEMolComplexFilterCategory_Nothing sopts.SetWaterFilter(oechem.OEMolComplexFilterFactory(filter)) oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts) return ligand.NumAtoms() != 0 and protein.NumAtoms() != 0
def SplitMolComplexCombineFilters(oms, inmol): lig = oechem.OEGraphMol() prot = oechem.OEGraphMol() wat = oechem.OEGraphMol() other = oechem.OEGraphMol() # @ <SNIPPET-SPLIT-MOL-COMPLEX-COMBINE-FILTERS> opt = oechem.OESplitMolComplexOptions() p = opt.GetProteinFilter() w = opt.GetWaterFilter() opt.SetProteinFilter(oechem.OEOrRoleSet(p, w)) opt.SetWaterFilter( oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Nothing)) # @ </SNIPPET-SPLIT-MOL-COMPLEX-COMBINE-FILTERS> if oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opt): WriteResultMols(oms, lig, prot, wat, other)
def split(complex, ligand_res_name='LIG'): """ This function splits the passed system in protein, ligand, water and excipients Parameters: ---------- complex : oechem.OEMol The bio-molecular complex to split ligand_res_name : Python string The ligand residue name used to recognize the ligand Output: ------- protein : oechem.OEMol The split protein ligand : oechem.OEMol The split ligand wat : oechem.OEMol The spit water other : oechem.OEMol The excipients """ # Set empty molecule containers prot = oechem.OEMol() lig = oechem.OEMol() wat = oechem.OEMol() other = oechem.OEMol() # Define the Filter options before the splitting opt = oechem.OESplitMolComplexOptions() # The protein filter is set to avoid that multiple # chains are separated during the splitting and peptide # molecules are recognized as ligands pf = oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Protein) peptide = oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Peptide) protein_filter = oechem.OEOrRoleSet(pf, peptide) opt.SetProteinFilter(protein_filter) # The ligand filter is set to recognize just the ligand lf = oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Ligand) not_protein_filter = oechem.OENotRoleSet(protein_filter) ligand_filter = oechem.OEAndRoleSet(lf, not_protein_filter) opt.SetLigandFilter(ligand_filter) # The water filter is set to recognize just water molecules wf = oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Water) opt.SetWaterFilter(wf) # Set Category cat = oechem.OEMolComplexCategorizer() cat.AddLigandName(ligand_res_name) opt.SetCategorizer(cat) # Splitting the system if not oechem.OESplitMolComplex(lig, prot, wat, other, complex, opt): raise ValueError('Unable to split the complex') # At this point prot contains the protein, lig contains the ligand, # wat contains the water and excipients contains the excipients return prot, lig, wat, other
def split(system, ligand_res_name='LIG'): """ This function splits the passed molecule in components and tracks the mapping between the original molecule and the split components. The mapping is created as separated atom component index sets. Parameters: ----------- system: OEMol The system to split in components. The components are: the protein atoms, the protein carbon alpha atoms the water atoms, the ion atoms, the cofactor atoms Returns: -------- dic_set: python dictionary The sysetm is splitted in a dictionary with token words as keys and for value the related atom set. The token keywords are: protein, ca_protein, ligand, water, ions, cofactors, system """ # Define Empty sets lig_set = set() prot_set = set() ca_prot_set = set() wat_set = set() excp_set = set() ion_set = set() # cofactor_set = set() # system_set = set() # Atom Bond Set vector used to contains the whole system frags = oechem.OEAtomBondSetVector() # Define Options for the Filter opt = oechem.OESplitMolComplexOptions() # The protein filter is set to avoid that multiple # chains are separated during the splitting and peptide # molecules are recognized as ligands pf = oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Protein) peptide = oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Peptide) protein_filter = oechem.OEOrRoleSet(pf, peptide) opt.SetProteinFilter(protein_filter) # The ligand filter is set to recognize just the ligand lf = oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Ligand) not_protein_filter = oechem.OENotRoleSet(protein_filter) ligand_filter = oechem.OEAndRoleSet(lf, not_protein_filter) opt.SetLigandFilter(ligand_filter) # The water filter is set to recognize just water molecules wf = oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Water) opt.SetWaterFilter(wf) # Set Category cat = oechem.OEMolComplexCategorizer() cat.AddLigandName(ligand_res_name) opt.SetCategorizer(cat) # Define the system fragments if not oechem.OEGetMolComplexFragments(frags, system, opt): raise ValueError('Unable to generate the system fragments') # Set empty OEMol containers prot = oechem.OEMol() lig = oechem.OEMol() wat = oechem.OEMol() excp = oechem.OEMol() # Split the protein from the system atommap = oechem.OEAtomArray(system.GetMaxAtomIdx()) if not oechem.OECombineMolComplexFragments( prot, frags, opt, opt.GetProteinFilter(), atommap): raise ValueError('Unable to split the Protein') # Populate the protein set and the protein carbon alpha set pred = oechem.OEIsAlphaCarbon() for sys_at in system.GetAtoms(): sys_idx = sys_at.GetIdx() at_idx = atommap[sys_idx] if at_idx: prot_set.add(sys_idx) at = system.GetAtom(oechem.OEHasAtomIdx(sys_idx)) if pred(at): ca_prot_set.add(sys_idx) # print(sys_idx, '->', at_idx) # Split the ligand from the system atommap = oechem.OEAtomArray(system.GetMaxAtomIdx()) if not oechem.OECombineMolComplexFragments( lig, frags, opt, opt.GetLigandFilter(), atommap): raise ValueError('Unable to split the Ligand') # Populate the ligand set for sys_at in system.GetAtoms(): sys_idx = sys_at.GetIdx() at_idx = atommap[sys_idx] if at_idx: lig_set.add(sys_idx) # print(sys_idx, '->', at_idx) # Split the water from the system atommap = oechem.OEAtomArray(system.GetMaxAtomIdx()) if not oechem.OECombineMolComplexFragments( wat, frags, opt, opt.GetWaterFilter(), atommap): raise ValueError('Unable to split the Water') # Populate the water set for sys_at in system.GetAtoms(): sys_idx = sys_at.GetIdx() at_idx = atommap[sys_idx] if at_idx: wat_set.add(sys_idx) # print(sys_idx, '->', at_idx) # Split the excipients from the system atommap = oechem.OEAtomArray(system.GetMaxAtomIdx()) if not oechem.OECombineMolComplexFragments( excp, frags, opt, opt.GetOtherFilter(), atommap): raise ValueError('Unable to split the Excipients') # Populate the excipient set for sys_at in system.GetAtoms(): sys_idx = sys_at.GetIdx() at_idx = atommap[sys_idx] if at_idx: excp_set.add(sys_idx) # print(sys_idx, '->', at_idx) # Create the ions set for exc_idx in excp_set: atom = system.GetAtom(oechem.OEHasAtomIdx(exc_idx)) if atom.GetDegree() == 0: ion_set.add(exc_idx) # Create the cofactor set cofactor_set = excp_set - ion_set # Create the system set system_set = prot_set | lig_set | excp_set | wat_set if len(system_set) != system.NumAtoms(): raise ValueError("The total system atom number {} is different " "from its set representation {}".format( system.NumAtoms(), system_set)) # The dictionary is used to link the token keywords to the created molecule sets dic_set = { 'ligand': lig_set, 'protein': prot_set, 'ca_protein': ca_prot_set, 'water': wat_set, 'ions': ion_set, 'cofactors': cofactor_set, 'system': system_set } return dic_set
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 split(complex, ligand_res_name='LIG'): """ This function splits the passed system in protein, ligand, water and excipients. Parameters: ---------- complex : oechem.OEMol The bio-molecular complex to split ligand_res_name : Python string The ligand residue name used to recognize the ligand Output: ------- protein : oechem.OEMol The split protein ligand : oechem.OEMol The split ligand wat : oechem.OEMol The spit water cofactors : oechem.OEMol The cofactors lipids : oechem.OEMol The lipids metals : oechem.OEMol The metals excipients : oechem.OEMol The excipients """ # Set empty molecule containers protein = oechem.OEMol() ligand = oechem.OEMol() water = oechem.OEMol() other = oechem.OEMol() # Define the Filter options before the splitting opt = oechem.OESplitMolComplexOptions() # The protein filter is set to avoid that multiple # chains are separated during the splitting and peptide # molecules are recognized as ligands pf = oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Protein) peptide = oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Peptide) protein_filter = oechem.OEOrRoleSet(pf, peptide) opt.SetProteinFilter(protein_filter) # The ligand filter is set to recognize just the ligand lf = oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Ligand) not_protein_filter = oechem.OENotRoleSet(protein_filter) ligand_filter = oechem.OEAndRoleSet(lf, not_protein_filter) opt.SetLigandFilter(ligand_filter) # The water filter is set to recognize just water molecules wf = oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Water) opt.SetWaterFilter(wf) # Set Category cat = oechem.OEMolComplexCategorizer() cat.AddLigandName(ligand_res_name) opt.SetCategorizer(cat) # Splitting the system if not oechem.OESplitMolComplex(ligand, protein, water, other, complex, opt): raise ValueError('Unable to split the complex') cofactors = oechem.OEMol() lipids = oechem.OEMol() metals = oechem.OEMol() excipients = oechem.OEMol() # Splitting the subsystem if other.NumAtoms(): opt_other = oechem.OESplitMolComplexOptions() lipid_filter = oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Lipid) opt_other.SetProteinFilter(lipid_filter) cofactor_filter = oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Cofactor) opt_other.SetLigandFilter(cofactor_filter) metal_filter = oechem.OEMolComplexFilterFactory( oechem.OEMolComplexFilterCategory_Metal) opt_other.SetWaterFilter(metal_filter) # Set Category cat_other = oechem.OEMolComplexCategorizer() opt_other.SetCategorizer(cat_other) if not oechem.OESplitMolComplex(cofactors, lipids, metals, excipients, other, opt_other): raise ValueError('Unable to split the Subcategories') return protein, ligand, water, cofactors, lipids, metals, excipients
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)