def main(argv=[__name__]): if len(argv) != 4: oechem.OEThrow.Usage("%s <prot-infile> <lig-infile> <max-distance>" % argv[0]) ifs = oechem.oemolistream() if not ifs.open(argv[1]): oechem.OEThrow.Fatal("Unable to open protein %s for reading" % argv[1]) prot = oechem.OEGraphMol() oechem.OEReadMolecule(ifs, prot) if not oechem.OEHasResidues(prot): oechem.OEPerceiveResidues(prot, oechem.OEPreserveResInfo_All) ifs = oechem.oemolistream() if not ifs.open(argv[2]): oechem.OEThrow.Fatal("Unable to open ligand %s for reading" % argv[2]) lig = oechem.OEGraphMol() oechem.OEReadMolecule(ifs, lig) if not oechem.OEHasResidues(lig): oechem.OEPerceiveResidues(lig, oechem.OEPreserveResInfo_All) maxgap = float(argv[3]) PrintCloseContacts(prot, lig, maxgap)
def ResHist(ifs): nrmol = 0 mol = oechem.OEGraphMol() while oechem.OEReadMolecule(ifs, mol): nrmol += 1 print("==============================") print("Molecule: %d Title: %s" % (nrmol, mol.GetTitle())) nrres = 0 resmap = {} if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) hv = oechem.OEHierView(mol) for res in hv.GetResidues(): nrres += 1 name = res.GetOEResidue().GetName() if name in resmap: resmap[name] += 1 else: resmap[name] = 1 sortedres = sorted(resmap.keys()) for name in sortedres: percent = 100.0*float(resmap[name])/float(nrres) print("%3s %3d %4.1f %%" % (name, resmap[name], percent))
def main(argv=[__name__]): if len(argv) != 3: oechem.OEThrow.Usage("%s <molfile.pdb> <out.srf>" % argv[0]) mol = oechem.OEGraphMol() ifs = oechem.oemolistream(argv[1]) oechem.OEReadMolecule(ifs, mol) if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) serials = {} for atom in mol.GetAtoms(): res = oechem.OEAtomGetResidue(atom) serials[res.GetSerialNumber()] = atom outsurf = oespicoli.OESurface() center = oechem.OEFloatArray(3) for line in open(argv[1]): if line.startswith("ANISOU"): serno, factors = ParseFactors(line) if serno in serials: mol.GetCoords(serials[serno], center) surf = GetEllipsoidalSurface(center, factors) oespicoli.OEAddSurfaces(outsurf, surf) oespicoli.OEWriteSurface(argv[2], outsurf)
def ResCount(ifs): nrmol = 0 mol = oechem.OEGraphMol() while oechem.OEReadMolecule(ifs, mol): nrmol += 1 nratom = 0 nrwat = 0 nrres = 0 nrfrag = 0 nrchain = 0 if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) hv = oechem.OEHierView(mol) for chain in hv.GetChains(): nrchain += 1 for frag in chain.GetFragments(): nrfrag += 1 for res in frag.GetResidues(): nrres += 1 if oechem.OEGetResidueIndex(res.GetOEResidue()) == oechem.OEResidueIndex_HOH: nrwat += 1 else: for atom in res.GetAtoms(): nratom += 1 print("===============================================") print("Molecule : %d Title: %s" % (nrmol, mol.GetTitle())) print("Chains : %d" % nrchain) print("Fragments: %d" % nrfrag) print("Residues : %d (%d waters)" % (nrres, nrwat)) print("Atoms : %d" % nratom)
def CisCheck(ifs): nrmol = 0 nrcis = 0 mol = oechem.OEGraphMol() while oechem.OEReadMolecule(ifs, mol): nrmol += 1 print("===========================================================") print("Molecule: %s Title: %s" % (nrmol, mol.GetTitle())) if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) hv = oechem.OEHierView(mol) resiter = oechem.ConstOEHierResidueIter() resiter = hv.GetResidues() while (resiter.IsValid()): res = resiter.Target() resiter.Next() if not oechem.OEIsStandardProteinResidue(res): continue torsion = oechem.OEGetTorsion(res, oechem.OEProtTorType_Omega) if torsion != -100.0: if torsion < math.pi / 2.0 and torsion > -math.pi / 2.0: if resiter.IsValid(): nextres = resiter.Target() oenextres = nextres.GetOEResidue() if oechem.OEGetResidueIndex( oenextres) == oechem.OEResidueIndex_PRO: continue nrcis += 1 oeres = res.GetOEResidue() print("%s %s %2d omega torsion = %.2f degree" % (oeres.GetName(), oeres.GetChainID(), oeres.GetResidueNumber(), torsion * oechem.cvar.Rad2Deg)) print(" %d cis amide bond(s) identified\n" % nrcis)
def _pmdStructureToOEMol(self): top = self.structure.topology pos = self.structure.positions molecule = oeommtools.openmmTop_to_oemol(top, pos, verbose=False) oechem.OEPerceiveResidues(molecule) oechem.OEFindRingAtomsAndBonds(molecule) return molecule
def set_serial(molecule, chainid, first_serial): import oechem if not oechem.OEHasResidues(molecule): oechem.OEPerceiveResidues(molecule, oechem.OEPreserveResInfo_All) for atom in molecule.GetAtoms(): residue = oechem.OEAtomGetResidue(atom) residue.SetExtChainID(chainid) serial_number = residue.GetSerialNumber() residue.SetSerialNumber(serial_number + first_serial)
def MakeAlpha(ifs, ofs): phival = math.pi / -3.0 psival = math.pi / -3.0 chival = math.pi nrphis = 0 nrpsis = 0 nrchis = 0 mol = oechem.OEGraphMol() while oechem.OEReadMolecule(ifs, mol): if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) # remove cross-links for bond in mol.GetBonds(): if bond.GetBgn().GetAtomicNum() == oechem.OEElemNo_S and \ bond.GetEnd().GetAtomicNum() == oechem.OEElemNo_S: mol.DeleteBond(bond) oechem.OEFindRingAtomsAndBonds(mol) hv = oechem.OEHierView(mol) for res in hv.GetResidues(): if not oechem.OEIsStandardProteinResidue(res): continue # set psi and phi angles if not oechem.OESetTorsion(res, oechem.OEProtTorType_Phi, phival): oeres = res.GetOEResidue() print("Unable to set phi for %s %d" % (oeres.GetName(), oeres.GetResidueNumber())) else: nrphis += 1 if not oechem.OESetTorsion(res, oechem.OEProtTorType_Psi, psival): oeres = res.GetOEResidue() print("Unable to set psi for %s %d" % (oeres.GetName(), oeres.GetResidueNumber())) else: nrpsis += 1 # set chis if oechem.OEGetResidueIndex( res.GetOEResidue().GetName()) == oechem.OEResidueIndex_PRO: continue # It does not make sense to set Proline chi angles to 180 for chi in oechem.OEGetChis(res): if not oechem.OESetTorsion(res, chi, chival): oeres = res.GetOEResidue() print("Unable to set chi %s for %s %d" % (oechem.OEGetProteinTorsionName(chi), oeres.GetName(), oeres.GetResidueNumber())) else: nrchis += 1 oechem.OEWriteMolecule(ofs, mol) print(nrphis, " phi torsion angle set to ", phival * oechem.cvar.Rad2Deg) print(nrpsis, " psi torsion angle set to ", psival * oechem.cvar.Rad2Deg) print(nrchis, " chis torsion angle set to ", chival * oechem.cvar.Rad2Deg)
def PrintAltGroupInfo(mol): if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) alf = oechem.OEAltLocationFactory(mol) # create factory for mol print("%s\t(%s groups)" % (mol.GetTitle(), alf.GetGroupCount())) for grp in alf.GetGroups(): print("\t%s locs:%s" % (grp.GetLocationCount(), alf.GetLocationCodes(grp)))
def main(argv=[__name__]): if len(argv) != 2: oechem.OEThrow.Usage("%s <mol-infile>" % argv[0]) ims = oechem.oemolistream() if not ims.open(argv[1]): oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1]) for mol in ims.GetOEGraphMols(): if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) CalcResCounts(mol)
def update_residue_identifiers( structure: oechem.OEGraphMol, keep_protein_residue_ids: bool = True) -> oechem.OEGraphMol: """ Updates the atom, residue and chain ids of the given molecular structure. All residues become part of chain A. Atom ids will start from 1. Residue will start from 1, except protein residue ids are fixed. This is especially useful, if molecules were merged, which can result in overlapping atom and residue ids as well as separate chains. Parameters ---------- structure: oechem.OEGraphMol The OpenEye molecule structure for updating atom and residue ids. keep_protein_residue_ids: bool If the protein residues should be kept. Returns ------- structure: oechem.OEGraphMol The OpenEye molecule structure with updated atom and residue ids. """ # update residue ids residue_number = 0 hierarchical_view = oechem.OEHierView(structure) for hv_residue in hierarchical_view.GetResidues(): residue = hv_residue.GetOEResidue() residue.SetChainID("A") if not residue.IsHetAtom() and keep_protein_residue_ids: if residue.GetName() == "NME" and residue.GetResidueNumber( ) == residue_number: # NME residues may have same id as preceding residue residue_number += 1 else: # catch protein residue id if those should not be touched residue_number = residue.GetResidueNumber() else: # change residue id residue_number += 1 residue.SetResidueNumber(residue_number) for atom in hv_residue.GetAtoms(): oechem.OEAtomSetResidue(atom, residue) # update residue identifiers, except atom names, residue ids, # residue names, fragment number, chain id and record type preserved_info = (oechem.OEPreserveResInfo_ResidueNumber | oechem.OEPreserveResInfo_ResidueName | oechem.OEPreserveResInfo_HetAtom | oechem.OEPreserveResInfo_AtomName | oechem.OEPreserveResInfo_FragmentNumber | oechem.OEPreserveResInfo_ChainID) oechem.OEPerceiveResidues(structure, preserved_info) return structure
def PrintGroups(mol): """summarize alternate location group info""" if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) alf = oechem.OEAltLocationFactory(mol) print("%s\t(%s groups)" % (mol.GetTitle(), alf.GetGroupCount())) for grp in alf.GetGroups(): print("\t%s locs:%s" % (grp.GetLocationCount(), alf.GetLocationCodes(grp)))
def PrintResidues(mol): """list alternate location code and occupancy by group and residue""" if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) alf = oechem.OEAltLocationFactory(mol) print("%s - %d alternate location groups:" % (mol.GetTitle(), alf.GetGroupCount())) for grp in alf.GetGroups(): print("%d) %d alternate locations" % (grp.GetGroupID() + 1, grp.GetLocationCount()), end=" ") prev = oechem.OEResidue() prevCodes = "" sumOcc = [] atNum = [] for atom in alf.GetAltAtoms(grp): res = oechem.OEAtomGetResidue(atom) if not oechem.OESameResidue(res, prev): for i, code in enumerate(prevCodes): print("%c(%.0f%c) " % (code, (sumOcc[i] * 100.0) / atNum[i], "%"), end=" ") print() prevCodes = "" sumOcc = [] atNum = [] print("\t%s%d%c chain '%c': " % (res.GetName(), res.GetResidueNumber(), res.GetInsertCode(), res.GetChainID()), end=" ") prev = res code = res.GetAlternateLocation() whichCode = prevCodes.find(code) if whichCode < 0: prevCodes += code sumOcc.append(res.GetOccupancy()) atNum.append(1) else: sumOcc[whichCode] += res.GetOccupancy() atNum[whichCode] += 1 for i, code in enumerate(prevCodes): print("%c(%.0f%c) " % (code, (sumOcc[i] * 100.0) / atNum[i], "%"), end=" ") print()
def LoopOverResAtoms(ims): for mol in ims.GetOEGraphMols(): # @ <SNIPPET-PERCEIVE-RES> if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) # @ </SNIPPET-PERCEIVE-RES> # @ <SNIPPET-RES-ATOMS-CORE> hv = oechem.OEHierView(mol) hres = hv.GetResidue("A", "LEU", 27) for atom in hres.GetAtoms(): # only this residue's atoms res = oechem.OEAtomGetResidue(atom) print(res.GetSerialNumber(), atom.GetName())
def BackBone(ifs, ofs): adjustHCount = True mol = oechem.OEGraphMol() backboneMol = oechem.OEGraphMol() while oechem.OEReadMolecule(ifs, mol): if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) aiter = mol.GetAtoms(oechem.OEIsBackboneAtom()) member = oechem.OEIsAtomMember(aiter) oechem.OESubsetMol(backboneMol, mol, member, adjustHCount) oechem.OEWriteMolecule(ofs, backboneMol)
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 run_create_mol2_pdb(**kwargs): nmol = kwargs['nmol'] input_txt = kwargs['input'] resname = kwargs['resname'] density = kwargs['density'] tries = kwargs['tries'] # Disable Gromacs backup file creation os.environ['GMX_MAXBACKUP'] = "-1" smiles_string = open(input_txt).readlines()[0].strip() print("The following SMILES string will be converted: %s" % smiles_string) # create a new molecule oemol = oechem.OEGraphMol() # convert the SMILES string into a molecule if oechem.OESmilesToMol(oemol, smiles_string): # do something interesting with mol pass else: print("SMILES string was invalid!") # Add explicit oechem.OEAddExplicitHydrogens(oemol) # Generate a single conformer oemol = openmoltools.openeye.generate_conformers(oemol, max_confs=1) # Modify residue names oechem.OEPerceiveResidues(oemol, oechem.OEPreserveResInfo_All) for atom in oemol.GetAtoms(): thisRes = oechem.OEAtomGetResidue(atom) thisRes.SetName(resname) # Write output files ofs = oechem.oemolostream() output_fnms = ['%s.mol2' % resname, '%s.pdb' % resname] for output_fnm in output_fnms: if not ofs.open(output_fnm): oechem.OEThrow.Fatal("Unable to create %s" % output_fnm) oechem.OEWriteMolecule(ofs, oemol) print("-=# Output #=- Created %s containing single molecule" % output_fnm) grams_per_mole = CalculateMolecularWeight(oemol) boxlen = CalculateBoxSize(nmol, grams_per_mole, density) GenerateBox('%s.pdb' % resname, '%s-box.pdb' % resname, boxlen, nmol, tries)
def CalcResCounts(mol): if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) resCt = 0 hetCt = 0 prevRes = oechem.OEResidue() for atom in mol.GetAtoms(): thisRes = oechem.OEAtomGetResidue(atom) if not oechem.OESameResidue(prevRes, thisRes): resCt += 1 if thisRes.IsHetAtom(): hetCt += 1 prevRes = thisRes print("Molecule: %s" % mol.GetTitle()) print("Residues: %d (%d hets)" % (resCt, hetCt))
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 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 main(args): if len(args) != 3: oechem.OEThrow.Usage("%s <protein> <surface>" % args[0]) ifs = oechem.oemolistream() if not ifs.open(args[1]): oechem.OEThrow.Fatal("Unable to open %s for reading" % args[1]) mol = oechem.OEGraphMol() oechem.OEReadMolecule(ifs, mol) oechem.OEPerceiveResidues(mol) oechem.OEAssignBondiVdWRadii(mol) # Generate the molecular surface surf = oespicoli.OESurface() oespicoli.OEMakeMolecularSurface(surf, mol, 0.5) # Mark all the vertices associated with hydrophobic atoms for i in range(surf.GetNumVertices()): atom = mol.GetAtom(oechem.OEHasAtomIdx(surf.GetAtomsElement(i))) if (AtomInHydrophobicResidue(atom)): surf.SetVertexCliqueElement(i, 1) # Crop to only those triangles oespicoli.OESurfaceCropToClique(surf, 1) # nlqs is the number of different connected components nclqs = oespicoli.OEMakeConnectedSurfaceCliques(surf) # Find the largest component maxclq = 0 maxarea = 0.0 for i in range(nclqs): area = oespicoli.OESurfaceCliqueArea(surf, i+1) print("clique: %d area: %f" % (i+1, area)) if (area > maxarea): maxclq = i+1 maxarea = area # Crop to it oespicoli.OESurfaceCropToClique(surf, maxclq) oespicoli.OEWriteSurface(args[2], surf) return 0
def _featurize(self, system: ProteinLigandComplex) -> ProteinLigandComplex: """ Perform hybrid docking with the OpenEye toolkit and thoughtful defaults. Parameters ---------- system: ProteinLigandComplex A system object holding protein and ligand information. Returns ------- protein_ligand_complex: ProteinLigandComplex The same system but with docked ligand. """ from openeye import oechem from ..docking.OEDocking import create_hybrid_receptor, hybrid_docking logging.debug("Interpreting system ...") ligand, protein, electron_density = self._interpret_system(system) logging.debug("Preparing protein ligand complex ...") design_unit = self._get_design_unit(protein, system.protein.name, electron_density) logging.debug("Extracting components ...") prepared_protein, prepared_solvent, prepared_ligand = self._get_components( design_unit) # TODO: rename prepared_ligand logging.debug("Creating hybrid receptor ...") hybrid_receptor = create_hybrid_receptor( prepared_protein, prepared_ligand ) # TODO: takes quite long, should save this somehow logging.debug("Performing docking ...") docking_pose = hybrid_docking(hybrid_receptor, [ligand])[0] oechem.OEPerceiveResidues( docking_pose, oechem.OEPreserveResInfo_None) # generate residue information logging.debug("Retrieving Featurizer results ...") protein_ligand_complex = self._get_featurizer_results( system, prepared_protein, prepared_solvent, docking_pose) return protein_ligand_complex
def PrintLocations(mol, hideAtoms): """list alternate location codes and atom info (unless hideAtoms is True)""" if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) alf = oechem.OEAltLocationFactory(mol) print("%s" % mol.GetTitle()) print("grp-cnt=%d" % alf.GetGroupCount(), end=" ") if alf.GetGroupCount() > 0: print("{") else: print() for grp in alf.GetGroups(): print(" grp=%d loc-cnt=%d grp-codes='%s'" % (grp.GetGroupID(), grp.GetLocationCount(), alf.GetLocationCodes(grp))) for loc in grp.GetLocations(): print(" grp=%d loc=%d loc-codes='%s'" % (loc.GetGroupID(), loc.GetLocationID(), alf.GetLocationCodes(loc)), end=" ") if not hideAtoms: print("[", end=" ") num_atoms = 0 for atom in alf.GetAltAtoms(loc): num_atoms += 1 if not hideAtoms: res = oechem.OEAtomGetResidue(atom) print("%s:%c:%s%d%c:c%cm%d;" % (atom.GetName(), res.GetAlternateLocation(), res.GetName(), res.GetResidueNumber(), res.GetInsertCode(), res.GetChainID(), res.GetModelNumber()), end=" ") if not hideAtoms: print("]", end=" ") print(num_atoms) if alf.GetGroupCount() > 0: print("}")
def Rename(ims, oms): for mol in ims.GetOEGraphMols(): # @ <SNIPPET-PERCEIVE-RES> if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) # @ </SNIPPET-PERCEIVE-RES> # @ <SNIPPET-MSE-TO-MET-CORE> for atom in mol.GetAtoms(): thisRes = oechem.OEAtomGetResidue(atom) if oechem.OEGetResidueIndex(thisRes) == oechem.OEResidueIndex_MSE: thisRes.SetName("MET") # modify res properties thisRes.SetHetAtom(False) oechem.OEAtomSetResidue(atom, thisRes) # store updated residue if atom.GetAtomicNum() == oechem.OEElemNo_Se: atom.SetAtomicNum( oechem.OEElemNo_S) # fix atom type & name atom.SetName(" SD ") # @ </SNIPPET-MSE-TO-MET-CORE> oechem.OEWriteMolecule(oms, mol)
def SubSetRes(ifs, ofs, chainid, resname, resnum): adjustHCount = True mol = oechem.OEGraphMol() while oechem.OEReadMolecule(ifs, mol): if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) hv = oechem.OEHierView(mol) res = hv.GetResidue(chainid, resname, resnum) if res.GetOEResidue().GetName() is None: oechem.OEThrow.Fatal("Failed to find residue") atomiter = res.GetAtoms() member = oechem.OEIsAtomMember(atomiter) resmol = oechem.OEGraphMol() oechem.OESubsetMol(resmol, mol, member, adjustHCount) if chainid == " ": resmol.SetTitle("%s %d" % (resname, resnum)) else: resmol.SetTitle("%s %s %d" % (resname, chainid, resnum)) oechem.OEWriteMolecule(ofs, resmol)
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()
def PrintStates(mol): """list alternate location state information""" if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) alf = oechem.OEAltLocationFactory(mol) print("%s\t%d groups" % (mol.GetTitle(), alf.GetGroupCount()), end=" ") tot = 1 totexp = 0.0 for grp in alf.GetGroups(): tot *= grp.GetLocationCount() totexp += math.log10(grp.GetLocationCount()) if totexp > 7.0: print("\tover 10^%.0f states" % totexp) print("too many states to enumerate") else: print("\t%d states" % tot) locs = [grp.GetLocations() for grp in alf.GetGroups()] EnumerateStates(alf, locs, 0, len(locs))
def ShowPhiPsi(ifs): nrmol = 0 mol = oechem.OEGraphMol() while oechem.OEReadMolecule(ifs, mol): nrmol += 1 print("================================================") print("Molecule: %d Title: %s" % (nrmol, mol.GetTitle())) if not oechem.OEHasResidues(mol): oechem.OEPerceiveResidues(mol, oechem.OEPreserveResInfo_All) hv = oechem.OEHierView(mol) for res in hv.GetResidues(): if not oechem.OEIsStandardProteinResidue(res): continue phi = oechem.OEGetPhi(res) psi = oechem.OEGetPsi(res) oeres = res.GetOEResidue() print(" %s %s %d (PHI=%.2f, PSI=%.2f)" % (oeres.GetName(), oeres.GetChainID(), oeres.GetResidueNumber(), phi, psi))
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 mutate_structure(target_structure: oechem.OEGraphMol, template_sequence: str) -> oechem.OEGraphMol: """ Mutate a protein structure according to an amino acid sequence. Parameters ---------- target_structure: oechem.OEGraphMol An OpenEye molecule holding a protein structure to mutate. template_sequence: str A template one letter amino acid sequence, which defines the sequence the target structure should be mutated to. Protein residues not matching a template sequence will be either mutated or deleted. Returns ------- mutated_structure: oechem.OEGraphMol An OpenEye molecule holding the mutated protein structure. """ from Bio import pairwise2 # the hierarchy view is more stable if reinitialized after each change # https://docs.eyesopen.com/toolkits/python/oechemtk/biopolymers.html#a-hierarchy-view finished = False while not finished: altered = False # align template and target sequences target_sequence = get_sequence(target_structure) template_sequence_aligned, target_sequence_aligned = pairwise2.align.globalxs( template_sequence, target_sequence, -10, 0)[0][:2] logging.debug(f"Template sequence:\n{template_sequence}") logging.debug(f"Target sequence:\n{target_sequence}") hierview = oechem.OEHierView(target_structure) structure_residues = hierview.GetResidues() # adjust target structure to match template sequence for template_sequence_residue, target_sequence_residue in zip( template_sequence_aligned, target_sequence_aligned): if template_sequence_residue == "-": # delete any non protein residue from target structure structure_residue = structure_residues.next() if target_sequence_residue != "X": # delete for atom in structure_residue.GetAtoms(): target_structure.DeleteAtom(atom) # break loop and reinitialize altered = True break else: # compare amino acids if target_sequence_residue != "-": structure_residue = structure_residues.next() if target_sequence_residue not in [ "X", template_sequence_residue ]: # mutate structure_residue = structure_residue.GetOEResidue() three_letter_code = oechem.OEGetResidueName( oechem.OEGetResidueIndexFromCode( template_sequence_residue)) oespruce.OEMutateResidue(target_structure, structure_residue, three_letter_code) # break loop and reinitialize altered = True break # leave while loop if no changes were introduced if not altered: finished = True # OEMutateResidue doesn't build sidechains and doesn't add hydrogens automatically oespruce.OEBuildSidechains(target_structure) oechem.OEPlaceHydrogens(target_structure) # update residue information oechem.OEPerceiveResidues(target_structure, oechem.OEPreserveResInfo_All) return target_structure