def get_sequence(structure: oechem.OEGraphMol) -> str: """ Get the amino acid sequence with one letter characters of an OpenEye molecule holding a protein structure. All residues not perceived as amino acid will receive the character 'X'. Parameters ---------- structure: oechem.OEGraphMol An OpenEye molecule holding a protein structure. Returns ------- sequence: str The amino acid sequence of the protein with one letter characters. """ sequence = [] hv = oechem.OEHierView(structure) for residue in hv.GetResidues(): if oechem.OEIsStandardProteinResidue(residue): sequence.append( oechem.OEGetAminoAcidCode( oechem.OEGetResidueIndex(residue.GetResidueName()))) else: sequence.append("X") sequence = "".join(sequence) return sequence
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 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 strip_water_ions(in_system): """ This function remove waters and ions molecules from the input system Parameters: ---------- in_system : oechem.OEMol The bio-molecular system to clean opt: python dictionary The system option Output: ------- clean_system : oechem.OEMol The cleaned system """ # Copy the input system system = in_system.CreateCopy() # Create a bit vector mask bv = oechem.OEBitVector(system.GetMaxAtomIdx()) bv.NegateBits() # Create a Hierarchical View of the protein system hv = oechem.OEHierView( system, oechem.OEAssumption_BondedResidue + oechem.OEAssumption_ResPerceived) # Looping over the system residues for chain in hv.GetChains(): for frag in chain.GetFragments(): for hres in frag.GetResidues(): res = hres.GetOEResidue() # Check if a residue is a mono atomic ion natoms = 0 for at in hres.GetAtoms(): natoms += 1 # Set the atom bit mask off if oechem.OEGetResidueIndex( res) == oechem.OEResidueIndex_HOH or natoms == 1: # Set Bit mask atms = hres.GetAtoms() for at in atms: bv.SetBitOff(at.GetIdx()) # Extract the system without waters or ions pred = oechem.OEAtomIdxSelected(bv) clean_system = oechem.OEMol() oechem.OESubsetMol(clean_system, system, pred) return clean_system
def AtomInHydrophobicResidue(atom): residues = set([oechem.OEResidueIndex_ALA, oechem.OEResidueIndex_ILE, oechem.OEResidueIndex_LEU, oechem.OEResidueIndex_MET, oechem.OEResidueIndex_PHE, oechem.OEResidueIndex_PRO, oechem.OEResidueIndex_TRP, oechem.OEResidueIndex_VAL]) if oechem.OEGetResidueIndex(atom) in residues: return True else: return False
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 _OEFixConnectionNH(protein): """ Temporary fix, thanks to Jesper! """ for atom in protein.GetAtoms( oechem.OEAndAtom(oespruce.OEIsModeledAtom(), oechem.OEIsNitrogen())): if oechem.OEGetPDBAtomIndex(atom) == oechem.OEPDBAtomName_N: expected_h_count = 1 if oechem.OEGetResidueIndex(atom) == oechem.OEResidueIndex_PRO: expected_h_count = 0 if atom.GetTotalHCount() != expected_h_count: oechem.OESuppressHydrogens(atom) atom.SetImplicitHCount(1) oechem.OEAddExplicitHydrogens(protein, atom) for nbr in atom.GetAtoms(oechem.OEIsHydrogen()): oechem.OESet3DHydrogenGeom(protein, nbr)
def CalcResCounts(mol): hv = oechem.OEHierView(mol) chainCt = 0 fragCt = 0 resCt = 0 watCt = 0 for chain in hv.GetChains(): chainCt += 1 for frag in chain.GetFragments(): fragCt += 1 for hres in frag.GetResidues(): resCt += 1 if (oechem.OEGetResidueIndex( hres.GetOEResidue()) == oechem.OEResidueIndex_HOH): watCt += 1 print("Molecule : %s" % mol.GetTitle()) print("Chains : %d" % chainCt) print("Fragments: %d" % fragCt) print("Residues : %d (%d waters)" % (resCt, watCt))
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 DropLigandFromProtein(prot, lig): """delete atoms from the protein w/same coords as the ligand as well as any waters""" approximatelyTheSame = 0.05 nn = oechem.OENearestNbrs(prot, approximatelyTheSame) # mark ligand atoms for deletion bv = oechem.OEBitVector(prot.GetMaxAtomIdx()) for nbrs in nn.GetNbrs(lig): r1 = oechem.OEAtomGetResidue(nbrs.GetBgn()) r2 = oechem.OEAtomGetResidue(nbrs.GetEnd()) if r1.GetModelNumber() == r2.GetModelNumber(): bv.SetBitOn(nbrs.GetBgn().GetIdx()) # mark waters for deletion too for atom in prot.GetAtoms(): res = oechem.OEAtomGetResidue(atom) if oechem.OEGetResidueIndex(res) == oechem.OEResidueIndex_HOH: bv.SetBitOn(atom.GetIdx()) pred = oechem.OEAtomIdxSelected(bv) for atom in prot.GetAtoms(pred): prot.DeleteAtom(atom)