def measure_phi_psi_omega(residue, include_OXT=False): """ Returns phi, psi, omega for a residue, replacing out-of-bounds angles with GLOBAL_PAD_CHAR. """ try: phi = pr.calcPhi(residue, radian=True, dist=None) except ValueError: phi = GLOBAL_PAD_CHAR try: psi = pr.calcPsi(residue, radian=True, dist=None) except ValueError: # For the last residue, we can measure a "psi" angle that is actually # the placement of the terminal oxygen. Currently, this is not utilized # in the building of structures, but it is included in case the need # arises in the future. Otherwise, this would simply become a pad # character. if include_OXT: try: psi = compute_single_dihedral(residue.select("name N CA C OXT")) except ValueError: psi = GLOBAL_PAD_CHAR except IndexError: psi = GLOBAL_PAD_CHAR else: psi = GLOBAL_PAD_CHAR try: omega = pr.calcOmega(residue, radian=True, dist=None) except ValueError: omega = GLOBAL_PAD_CHAR return [phi, psi, omega]
def get_sec_struct_phipsi(self, parsed_pdb): phipsi = [] for resn in self.sele.getResnums()[self._ind]: try: phi = pr.calcPhi(parsed_pdb.prody_pdb[self.chid, resn]) except: phi = None try: psi = pr.calcPsi(parsed_pdb.prody_pdb[self.chid, resn]) except: psi = None if phi is not None and psi is not None: phipsi.append('(' + '{0:.2f}'.format(phi) + ' ' + '{0:.2f}'.format(psi) + ')') if resn == self.resnum: self.sec_struct_phi_psi = '{0:.2f}'.format( phi) + ' ' + '{0:.2f}'.format(psi) elif phi is None and psi is not None: phipsi.append('(' + 'None' + ' ' + '{0:.2f}'.format(psi) + ')') if resn == self.resnum: self.sec_struct_phi_psi = 'None ' + '{0:.2f}'.format(psi) elif phi is not None and psi is None: phipsi.append('(' + '{0:.2f}'.format(phi) + ' ' + 'None' + ')') if resn == self.resnum: self.sec_struct_phi_psi = '{0:.2f}'.format(phi) + ' None' self.sec_struct_phi_psi_frag = ' '.join(phipsi)
def read_residues(chain): ignored_restypes = dict() residues = [] for res in chain.iterResidues(): restype = res.getResname() if restype in nonstandard_restype_conversion: restype = nonstandard_restype_conversion[restype] if restype not in one_letter_aa: ignored_restypes[restype] = ignored_restypes.get(restype,0) + 1 continue # let's hope it is HOH or something try: phi = prody.calcPhi(res)*deg except ValueError: phi = np.nan try: psi = prody.calcPsi(res)*deg except ValueError: psi = np.nan try: omega = prody.calcOmega(res)*deg except ValueError: omega = np.nan adict = dict((a.getName(),a.getCoords()) for a in res.iterAtoms()) cg_list = [v for k,v in adict.items() if re.match("[^H]G1?$",k)] cd_list = [v for k,v in adict.items() if re.match("[^H]D1?$",k)] if len(cg_list) not in (0,1): raise RuntimeError('Residue %i CG-list %s has too many items'%(res.getResindex(), [k for k,v in adict.items() if re.match("[^H]G1?$",k)],)) if len(cd_list) not in (0,1): raise RuntimeError('Resdiue %i CD-list %s has too many items'%(res.getResindex(), [k for k,v in adict.items() if re.match("[^H]D1?$",k)],)) # note that you need to check the residue *before* to see if a proline is cis r = Residue( res.getResnum(), res.getChain(), restype if not (restype=='PRO' and residues and np.abs(residues[-1].omega)<90.*deg) else 'CPR', phi,psi,omega, adict.get('N', np.nan*np.ones(3)), adict.get('CA', np.nan*np.ones(3)), adict.get('C', np.nan*np.ones(3)), adict.get('CB', np.nan*np.ones(3)), cg_list[0] if cg_list else np.nan*np.ones(3), cd_list[0] if cd_list else np.nan*np.ones(3), np.nan, np.nan) r = r._replace(chi1=dihedral(r.N,r.CA,r.CB,r.CG), chi2=dihedral(r.CA,r.CB,r.CG,r.CD)) residues.append(r) return residues, ignored_restypes
def set_rois_phipsi(self): """returns a list of the phi,psi tuples of each residue of interest""" for resnum, chid in self.bs_residues: try: phi = pr.calcPhi(self.poi[chid, resnum]) except: phi = None try: psi = pr.calcPsi(self.poi[chid, resnum]) except: psi = None self.rois_phipsi[(resnum, chid)] = (phi, psi)
def get_rois_phi_psi(poi, resn_chid_pairs): phi_psi = [] for resn, chid in resn_chid_pairs: try: phi = pr.calcPhi(poi[chid, resn]) except: phi = None # traceback.print_exc() try: psi = pr.calcPsi(poi[chid, resn]) except: psi = None phi_psi.append((phi, psi)) return phi_psi
def measure_phi_psi_omega(residue, include_OXT=False, last_res=False): """Measures a residue's primary backbone torsional angles (phi, psi, omega). Args: residue: ProDy residue object. include_OXT: Boolean describing whether or not to measure an angle to place the terminal oxygen. last_res: Boolean describing if this residue is the last residue in a chain. If so, instead of measuring a psi angle, we measure the related torsional angle of (N, Ca, C, O). Returns: Python list of phi, psi, and omega angles for residue. """ try: phi = pr.calcPhi(residue, radian=True) except ValueError: phi = GLOBAL_PAD_CHAR try: if last_res: psi = compute_single_dihedral( [residue.select("name " + an) for an in "N CA C O".split()]) else: psi = pr.calcPsi(residue, radian=True) except (ValueError, IndexError): # For the last residue, we can measure a "psi" angle that is actually # the placement of the terminal oxygen. Currently, this is not utilized # in the building of structures, but it is included in case the need # arises in the future. Otherwise, this would simply become a pad # character. if include_OXT: try: psi = compute_single_dihedral([ residue.select("name " + an) for an in "N CA C OXT".split() ]) except ValueError: psi = GLOBAL_PAD_CHAR except IndexError: psi = GLOBAL_PAD_CHAR else: psi = GLOBAL_PAD_CHAR try: omega = pr.calcOmega(residue, radian=True) except ValueError: omega = GLOBAL_PAD_CHAR return [phi, psi, omega]
structure.setACSIndex(index) return structure #Pairs phi/psi lists by residue for a given frame def phi_psi_pair(phis, psis): return 1 #Generates lists of phi and psi angles for all frames with mp.Pool() as pool: frame_list = pool.map(lambda x: int(x), frame_list) structure_list = pool.map(lambda x: get_str(x), frame_list) hier_list = pool.map(lambda x: prd.HierView(x), structure_list) res_list = map(lambda x, y: x.getResidue('A', y), hier_list, core_res) phi_list = pool.map(lambda x: prd.calcPhi(x), res_list) res_list = map(lambda x, y: x.getResidue('A', y), hier_list, core_res) psi_list = pool.map(lambda x: prd.calcPsi(x), res_list) phi_list = list(phi_list) psi_list = list(psi_list) #Generates the columns and rows for a dataframe to store all angles clmns = [] rows = {} for i in range(len(init_core_res)): clmns.append('phi' f'{i+1}') clmns.append('psi' f'{i+1}') #Generates a dataframe and stores all angle values angles = pd.DataFrame.from_dict(rows, orient='index', columns=clmns)
def checkHBonds(appf,no_d, ox_a, ssindex): #1 Dist(don, acc) < 3.5 da_dist = pr.calcDistance( no_d , ox_a ) if( da_dist >= DONOR_ACCEPTOR_MAXDISTANCE ): return h_don = getHforAtom(appf,no_d) if(h_don == None): return #2 Dist(h_don, acc) < 3.5 ha_dist = pr.calcDistance(h_don, ox_a) if( ha_dist >= HYDROGEN_ACCEPTOR_MAXDISTANCE): return #3 Angle(don, h_don, acc) > 90 dha_ang = pr.calcAngle( no_d, h_don, ox_a ) if( dha_ang < DHA_ANGLE ): return #4 Angle(don, acc, acc_ante) > 90 #daa_ang = pr.calcAngle( no_d, ox_a, acc_ante) #if( daa_ang < DAB_ANGLE ): # return acc_ante = getAntecedent(appf, ox_a) #Get acc_ante if(acc_ante == None): return #5 Angle(h_don, acc, acc_ante) > 90 haa_ang = pr.calcAngle( h_don, ox_a, acc_ante ) if( haa_ang < HAB_ANGLE ): return #We have a valid H-Bond with no_d, ox_a, h_don #print 'HBond elements', h_don.getName(), no_d.getName(), ox_a.getName() #print 'DA dist', da_dist #print 'HA dist', ha_dist #print 'DHA ang', dha_ang #print 'DAA ang', daa_ang #print 'HAA ang', haa_ang beta_ang = getBetaAngle (appf,acc_ante,ox_a,h_don) gamm_ang = getGammaAngle(appf,acc_ante,ox_a,h_don) resNum = h_don.getResnum() if(resNum <= 0): return chain = appf.iterChains().next() phi = pr.calcPhi(chain.getResidue(resNum)) psi = pr.calcPsi(chain.getResidue(resNum)) #print phi, psi #PUT DATA INTO COLUMN DATA STRUCTURES # print ssindex #towrite = ",".join([str(h_don.getResnum()),str(h_don.getCoords())]) #fp.write(towrite+"\r\n") NUM_H_BONDS[ssindex] += 1 COLUMN_D_ON [ssindex].append(da_dist) COLUMN_D_OH [ssindex].append(ha_dist) COLUMN_A_NHO [ssindex].append(dha_ang) COLUMN_A_HOC [ssindex].append(haa_ang) COLUMN_BETA [ssindex].append(beta_ang) COLUMN_GAMMA [ssindex].append(gamm_ang) COLUMN_PHI [ssindex].append(phi) COLUMN_PSI [ssindex].append(psi) return
line = line.replace('ASP', aa123[sys.argv[1]]) if fileinput.filelineno() > 4: line = line.replace('PHE', aa123[sys.argv[2]]) print(line.rstrip('\n')) startpep = pd.read_table("Start_peptide2 - Copy.pdb", delim_whitespace=True, header=None) # print(getAngle(p0=np.array(startpep.iloc[1, 6:9]), # p1=np.array(startpep.iloc[2, 6:9]), # p2=np.array(startpep.iloc[3, 6:9]))) startpepPDB = prody.parsePDB("Start_peptide.pdb") Phi2 = prody.calcPhi(startpepPDB[2, ]) Psi1 = prody.calcPsi(startpepPDB[1, ]) N1 = Point3D(-51.511, -14.232, 13.641) CA1 = Point3D(-51.613, -15.247, 14.686) C1 = Point3D(-50.286, -15.951, 14.907) print(startpep) # Extract relevant info from pdb file starter for p in range(1, 50): PhiPsi_All = np.zeros((len(sys.argv) - 1, 2)) shutil.copyfile('Start_peptide2.pdb', 'Start_peptide2 - Copy.pdb') for i in range(1, 10): if startpep.iloc[-1, 5] == 8: break print(PhiPsi_All)
def paste_bulge(path_to_loop, path_to_pdb, query_selection_N, query_selection_C, query_length_N=4, query_length_C=4): loop = pr.parsePDB(path_to_loop) loop.setSegnames('A') keep = list() psi_prev = 0 for i, res in enumerate(loop.iterResidues()): if i > 0: try: phi = pr.calcPhi(res) except: phi = 0 try: psi = pr.calcPsi(res) if psi > -32 and (phi + psi_prev <= -125): resnum = set(res.getResnums()).pop() keep.append(resnum + 4) psi_prev = psi except: pass if len(keep) > 0: loop_bb = loop.select('backbone or resnum ' + ' '.join([str(i) for i in keep])) loop.select('not resnum ' + ' '.join([str(i) for i in keep])).setResnames('GLY') else: loop_bb = loop.select('backbone') loop.setResnames('GLY') pdb = pr.parsePDB(path_to_pdb) query_N_bb = pdb.select(query_selection_N + ' and name N C CA') query_C_bb = pdb.select(query_selection_C + ' and name N C CA') first_resnum_loop = loop_bb.getResnums()[0] last_resnum_loop = loop_bb.getResnums()[-1] n_last = first_resnum_loop + query_length_N - 1 c_first = last_resnum_loop - query_length_C + 1 if len(keep) > 0: if any([k <= n_last for k in keep]): n_last = min(keep) - 1 if any([k >= c_first for k in keep]): c_first = max(keep) + 1 if n_last <= first_resnum_loop: n_last = first_resnum_loop + 1 if c_first >= last_resnum_loop: c_first = last_resnum_loop - 1 loop_N_bb = loop_bb.select('name N C CA and resnum `' + str(first_resnum_loop) + 'to' + str(n_last) + '`') loop_C_bb = loop_bb.select('name N C CA and resnum `' + str(c_first) + 'to' + str(last_resnum_loop) + '`') len_loop_N = n_last - first_resnum_loop + 1 len_loop_C = last_resnum_loop - c_first + 1 print('len loop N bb=', len_loop_N) print('len loop C bb=', len_loop_C) try: coords_diff_N = loop_N_bb.getCoords() - query_N_bb.getCoords( )[:len_loop_N * 3 + 1] coords_diff_C = loop_C_bb.getCoords() - query_C_bb.getCoords( )[-len_loop_C * 3:] except ValueError: print('Loop failure') ind_match_N = np.argmin([np.linalg.norm(i) for i in coords_diff_N]) ind_match_C = np.argmin([np.linalg.norm(i) for i in coords_diff_C]) loop_N_bb_index = loop_N_bb.getIndices()[ind_match_N] loop_C_bb_index = loop_C_bb.getIndices()[ind_match_C] query_N_bb_index = query_N_bb.getIndices()[ind_match_N] query_C_bb_index = query_C_bb.getIndices()[ind_match_C] first_index_pdb = pdb.select('backbone').getIndices()[0] last_index_pdb = pdb.select('backbone').getIndices()[-1] loop_slice = loop_bb.select('index ' + str(loop_N_bb_index) + 'to' + str(loop_C_bb_index)) pdb_N = pdb.select('backbone and index ' + str(first_index_pdb) + 'to' + str(query_N_bb_index - 1)) pdb_C = pdb.select('backbone and index ' + str(query_C_bb_index + 1) + 'to' + str(last_index_pdb)) return pdb_N, loop_slice, pdb_C