def SplitMolComplexAllSites(oms, inmol, splitCovalent): lig = oechem.OEGraphMol() prot = oechem.OEGraphMol() wat = oechem.OEGraphMol() other = oechem.OEGraphMol() if splitCovalent: # @ <SNIPPET-SPLIT-MOL-COMPLEX-ALL-SITES-SPLIT> opt = oechem.OESplitMolComplexOptions() allSites = 0 opt.ResetFilters(allSites) opt.SetSplitCovalent() # @ </SNIPPET-SPLIT-MOL-COMPLEX-ALL-SITES-SPLIT> if oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opt): WriteResultMols(oms, lig, prot, wat, other) else: # @ <SNIPPET-SPLIT-MOL-COMPLEX-ALL-SITES> opt = oechem.OESplitMolComplexOptions() allSites = 0 opt.ResetFilters(allSites) # @ </SNIPPET-SPLIT-MOL-COMPLEX-ALL-SITES> if oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opt): WriteResultMols(oms, lig, prot, wat, other)
def SplitMolComplex(oms, inmol, splitCovalent, separateResidues): # limiting lig, prot and wat to just near the first binding site # (a very common pattern) lig = oechem.OEGraphMol() prot = oechem.OEGraphMol() wat = oechem.OEGraphMol() other = oechem.OEGraphMol() if not splitCovalent and not separateResidues: # @ <SNIPPET-SPLIT-MOL-COMPLEX-SIMPLE> # for input molecule inmol ... lig = oechem.OEGraphMol() prot = oechem.OEGraphMol() wat = oechem.OEGraphMol() other = oechem.OEGraphMol() if oechem.OESplitMolComplex(lig, prot, wat, other, inmol): # work with the output molecules lig, prot, ... # @ </SNIPPET-SPLIT-MOL-COMPLEX-SIMPLE> WriteResultMols(oms, lig, prot, wat, other) elif splitCovalent and not separateResidues: # @ <SNIPPET-SPLIT-MOL-COMPLEX-SPLIT-COVALENT> # given input and output molecules ... opt = oechem.OESplitMolComplexOptions() opt.SetSplitCovalent() if oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opt): # ... # @ </SNIPPET-SPLIT-MOL-COMPLEX-SPLIT-COVALENT> WriteResultMols(oms, lig, prot, wat, other) elif not splitCovalent and separateResidues: # @ <SNIPPET-SPLIT-MOL-COMPLEX-SEPARATE-RES> opt = oechem.OESplitMolComplexOptions() opt.SetSeparateResidues() if not oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opt): oechem.OEThrow.Fatal("Unable to split mol complex from %s" % inmol.GetTitle()) # @ </SNIPPET-SPLIT-MOL-COMPLEX-SEPARATE-RES> else: WriteResultMols(oms, lig, prot, wat, other) else: # @ <SNIPPET-SPLIT-MOL-COMPLEX-OPTIONS> opt = oechem.OESplitMolComplexOptions() opt.SetSplitCovalent(splitCovalent) opt.SetSeparateResidues(separateResidues) if not oechem.OESplitMolComplex(lig, prot, wat, other, inmol, opt): oechem.OEThrow.Fatal("Unable to split mol complex from %s" % inmol.GetTitle()) # @ </SNIPPET-SPLIT-MOL-COMPLEX-OPTIONS> else: WriteResultMols(oms, lig, prot, wat, other)
def _prepare_ligand_template( self, ligand_template: pd.Series, kinase_domain: oechem.OEGraphMol ) -> oechem.OEGraphMol: """ Prepare a PDB structure containing the ligand template of interest. Parameters ---------- ligand_template: pd.Series A data series containing entries 'pdb', 'chain', 'ligand' and 'alt'. kinase_domain: oechem.OEGraphMol An OpenEye molecule holding the kinase domain the ligand template structure should be superposed to. Returns ------- : oechem.OEGraphMol An OpenEye molecule holding the prepared ligand structure. """ from openeye import oechem from ..modeling.OEModeling import ( read_molecules, select_chain, select_altloc, remove_non_protein, superpose_proteins, ) from ..utils import FileDownloader logging.debug("Interpreting structure ...") ligand_template_structure = PDBProtein(ligand_template.pdb) if not ligand_template_structure.path.is_file(): logging.debug(f"Downloading PDB entry {ligand_template.pdb} ...") FileDownloader.rcsb_structure_pdb(ligand_template.pdb) logging.debug("Reading structure ...") ligand_template_structure = read_molecules(ligand_template_structure.path)[0] logging.debug("Selecting chain ...") ligand_template_structure = select_chain(ligand_template_structure, ligand_template.chain) logging.debug("Selecting alternate location ...") ligand_template_structure = select_altloc(ligand_template_structure, ligand_template.alt) logging.debug("Removing everything but protein, water and ligand of interest ...") ligand_template_structure = remove_non_protein( ligand_template_structure, exceptions=[ligand_template.ligand], remove_water=False ) logging.debug("Superposing structure on kinase domain ...") ligand_template_structure = superpose_proteins(kinase_domain, ligand_template_structure) logging.debug("Adding hydrogens ...") oechem.OEPlaceHydrogens(ligand_template_structure) split_options = oechem.OESplitMolComplexOptions() logging.debug("Extracting ligand ...") ligand_template_structure = list( oechem.OEGetMolComplexComponents( ligand_template_structure, split_options, split_options.GetLigandFilter() ) )[0] return ligand_template_structure
def SplitMolComplexIterAllSitesLigName(oms, mol, ligName): # @ <SNIPPET-SPLIT-MOL-COMPLEX-ITER-LIGNAME-AND-ALL-SITES> opt = oechem.OESplitMolComplexOptions(ligName) allSites = 0 opt.ResetFilters(allSites) for frag in oechem.OEGetMolComplexComponents(mol, opt): # ... # @ </SNIPPET-SPLIT-MOL-COMPLEX-ITER-LIGNAME-AND-ALL-SITES> oechem.OEWriteMolecule(oms, frag)
def SplitMolComplexIterLigName(oms, mol, ligName): # the ligand has been identified by name # @ <SNIPPET-SPLIT-MOL-COMPLEX-ITER-LIGNAME> # for input molecule mol and string ligName ... opt = oechem.OESplitMolComplexOptions(ligName) for frag in oechem.OEGetMolComplexComponents(mol, opt): # ... # @ </SNIPPET-SPLIT-MOL-COMPLEX-ITER-LIGNAME> oechem.OEWriteMolecule(oms, frag)
def split(mol): """ This function splits the passed system in protein, ligand, water and excipients Parameters: ---------- mol : oechem.OEMol The bio-molecular system to split 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 pf = oechem.OEMolComplexFilterFactory(oechem.OEMolComplexFilterCategory_Protein) # The ligand filter is set to recognize just the ligand lf = oechem.OEMolComplexFilterFactory(oechem.OEMolComplexFilterCategory_Ligand) # The water filter is set to recognize just water molecules wf = oechem.OEMolComplexFilterFactory(oechem.OEMolComplexFilterCategory_Water) opt.SetProteinFilter(pf) opt.SetLigandFilter(lf) opt.SetWaterFilter(wf) # Splitting the system if not oechem.OESplitMolComplex(lig, prot, wat, other, mol, opt): oechem.OEThrow.Fatal('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 get_protein_and_ligands(protein, ligand, itf): if (itf.HasString("-complex")): # separate ligand and protein in complex iname = itf.GetString("-complex") ifs = oechem.oemolistream() if not ifs.open(iname): oechem.OEThrow.Fatal("Cannot open input complex file!") complexmol = oechem.OEGraphMol() if not oechem.OEReadMolecule(ifs, complexmol): oechem.OEThrow.Fatal("Unable to read complex from %s" % iname) if not oechem.OEHasResidues(complexmol): oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All) sopts = oechem.OESplitMolComplexOptions() oechem.OESetupSplitMolComplexOptions(sopts, itf) if not split_complex(protein, ligand, sopts, complexmol): oechem.OEThrow.Fatal("Cannot separate complex!") else: # read ligand and protein from separate files pname = itf.GetString("-protein") ifs = oechem.oemolistream() if not ifs.open(pname): oechem.OEThrow.Fatal("Cannot open input protein file!") if not oechem.OEReadMolecule(ifs, protein): oechem.OEThrow.Fatal("Unable to read protein from %s" % pname) lname = itf.GetString("-ligand") ifs = oechem.oemolistream() if not ifs.open(lname): oechem.OEThrow.Fatal("Cannot open input ligand file!") if not oechem.OEReadMolecule(ifs, ligand): oechem.OEThrow.Fatal("Unable to read ligand from %s" % lname) 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 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 SplitMolComplexIter(oms, mol): # limiting lig, prot and wat to just near the first binding site # (a very common pattern) # @ <SNIPPET-SPLIT-MOL-COMPLEX-ITER-SIMPLE> # for input molecule mol ... for frag in oechem.OEGetMolComplexComponents(mol): # ... # @ </SNIPPET-SPLIT-MOL-COMPLEX-ITER-SIMPLE> oechem.OEWriteMolecule(oms, frag) # other api points illustrated below # @ <SNIPPET-SPLIT-MOL-COMPLEX-SPLIT-COVALENT> opt = oechem.OESplitMolComplexOptions() opt.SetSplitCovalent() # @ </SNIPPET-SPLIT-MOL-COMPLEX-SPLIT-COVALENT> # @ <SNIPPET-SPLIT-MOL-FILTER-SURFACE-WATERS> site = 1 surfaceWaters = True opt.ResetFilters(site, surfaceWaters) opt.SetMaxSurfaceWaterDist(8.0)
def SplitMolComplexIterFilter(oms, mol): # @ <SNIPPET-SPLIT-MOL-COMPLEX-ADD-COFACTOR> db = oechem.OEResidueCategoryData() db.AddToDB(oechem.OEResidueDatabaseCategory_Cofactor, "MTQ") cat = oechem.OEMolComplexCategorizer() cat.SetResidueCategoryData(db) opt = oechem.OESplitMolComplexOptions() opt.SetCategorizer(cat) # @ </SNIPPET-SPLIT-MOL-COMPLEX-ADD-COFACTOR> # @ <SNIPPET-SPLIT-MOL-COMPLEX-ITER-FILTER> # for input molecule mol and options opt ... for l in oechem.OEGetMolComplexComponents(mol, opt, opt.GetLigandFilter()): # ... # @ </SNIPPET-SPLIT-MOL-COMPLEX-ITER-FILTER> oechem.OEWriteMolecule(oms, l) # @ <SNIPPET-SPLIT-MOL-COMPLEX-EXAMPLE-FILTER> ofilter = opt.GetOtherFilter() # @ </SNIPPET-SPLIT-MOL-COMPLEX-EXAMPLE-FILTER> rs = oechem.OERoles() ofilter(rs)
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() 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 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, 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 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(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(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(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()