Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
append_data.py
Go to the documentation of this file.
1 # Appends data to end of PDB output file
2 # Emily Koo
3 
4 # Import python modules
5 import os
6 import math
7 import sys
8 
9 # Import Rosetta modules
10 from rosetta import *
11 
12 #========================= Data ========================================
13 def append_scores(file, pose, scorefxn):
14  # Appends energy scores to end of PDB
15  prot_start = pose.num_jump() + 1
16  prot_end = pose.total_residue()
17 
18  pose_file = open(file,'a')
19 
20  res = 1 - prot_start
21 
22  # Full atom scores
23  if pose.is_fullatom():
24  list = [fa_atr,fa_rep,fa_sol,fa_intra_rep,fa_pair,fa_dun, hbond_sr_bb,\
25  hbond_lr_bb,hbond_bb_sc,hbond_sc,fa_elec,p_aa_pp,ref, pro_close,\
26  atom_pair_constraint, dihedral_constraint]
27  else:
28  # Centroid scores
29  list = [vdw, pair, env, cbeta]
30 
31  # Write total energy
32  pose_file.write("\nTotal score: \n" )
33  stream = rosetta.utility.OStringStream()
34  scorefxn(pose)
35  scorefxn.show(stream, pose)
36  pose_file.write(stream.str())
37 
38  # Write all energy scores for each residue in protein
39  pose_file.write("\nEnergies by residue: ")
40  for i in range(prot_start, prot_end+1):
41  # Print res as actual protein residue (for adsorbed) without surface res
42  res += i
43  pose_file.write("\nResidue no.: "+str(res)+"\nResidue type: "+\
44  str(pose.residue(i).name()))
45 
46  for energy in list:
47  score = '{0:.3f}'.format(pose.energies().residue_total_energies(i)[energy])
48  pose_file.write('{0:20}'.format("\n"+str(energy)) + "\t"+str(score).rjust(10))
49 
50  res -= i
51 
52  pose_file.write("\n")
53  pose_file.close()
54 
55 def append_hbonds(file, pose, scorefxn):
56 # Appends hbond scores to end of PDB
57 
58  hbond_set = rosetta.core.scoring.hbonds.HBondSet()
59  pose.update_residue_neighbors()
60  rosetta.core.scoring.hbonds.fill_hbond_set(pose, False, hbond_set)
61  stream = rosetta.utility.OStringStream()
62  hbond_set.show(pose, True, stream)
63 
64  pose_file = open(file, 'a')
65  pose_file.write("\nbegin protein intra-molecular hydrogen bonds")
66  pose_file.write("\ndonor atom acceptor atom energy\n")
67  pose_file.write(stream.str())
68  pose_file.write("end protein intra-molecular hydrogen bonds\n")
69  pose_file.close()
70 
71 def append_constraints(file, pose, cst, scorefxn):
72  if cst:
73 
74  # Appends constraint data to end of PDB
75  prot_start = pose.num_jump() + 1
76  prot_end = pose.total_residue()
77 
78  pose_file = open(file,'a')
79  scorefxn(pose)
80 
81  print "Constraints energy:"
82  scorefxn.show(pose)
83 
84  pose_file.write("\nConstraint Energies")
85  pose_file.write("\nAtom pair energy: " + str(pose.energies().total_energies()[atom_pair_constraint]))
86  pose_file.write("\nDihedral energy: " + str(pose.energies().total_energies()[dihedral_constraint]))
87 
88  """
89  # Booleans for headers
90  m = 0
91  n = 0
92  lowest_dist = []
93  prev_res1 = 0
94  amb = 0
95 
96  # {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
97  for cst_file in cst:
98  for line in open(cst_file.strip(), 'r'):
99  # if line is not empty
100  if line.strip() is not "":
101  data = line.split()
102  # Dihedrals ==============================================================================================
103  if data[0] == 'Dihedral':
104  if m == 0:
105  pose_file.write("\nType\t\t\tRes\tActual\tConstr\tError\t\tScore")
106  m = 1
107 
108  res1 = int(data[4])
109  # Normalize the value such that it is the actual protein res number
110  res1 += - prot_start + 1
111 
112  # Phi/Psi
113  if data[1] == 'C':
114  type = "Phi"
115  angle = '{0:.3f}'.format(math.radians(pose.phi(int(data[4]))))
116  else:
117  type = "Psi"
118  angle = '{0:.3f}'.format(math.radians(pose.psi(int(data[4]))))
119 
120  score = '{0:.3f}'.format(pose.energies().residue_total_energies(res1)[dihedral_constraint])
121  constr = '{0:.3f}'.format(float(data[10]) + float(data[12]))
122  error = data[12]
123  pose_file.write("\n"+str(data[0])+"\t"+type+"\t"+str(res1)+\
124  "\t"+str(angle)+ "\t"+str(constr)+"\t"+str(error)+"\t\t"+\
125  str(score))
126 
127  # Atom pair ================================================================================================
128  elif data[0] == 'AtomPair' or data[1] == 'AtomPair':
129  if n == 0:
130  pose_file.write("\nType\t\t\tAtom1\tRes1\tAtom2\tRes2\tActual\tConstr\tError\tScore")
131  n = 1
132 
133  if data[1] == 'AtomPair':
134  data = data[1:]
135  amb = 1
136  type = "AmbiConstr"
137 
138  else:
139  amb = 0
140  type = "AtomPair"
141 
142  res1 = int(data[2])
143  res2 = int(data[4])
144  # Normalize the value such that it is the actual protein res number
145  res1 += - prot_start + 1
146  if type == "AtomPair" or res2 > prot_start -1:
147  res2 += - prot_start + 1
148 
149  if type == "AmbiConstr" and prev_res1 == 0:
150  prev_res1 = res1
151 
152  # Calculate distance between the two atoms
153  start = pose.residue(res1).xyz(str(data[1]))
154  end = pose.residue(res2).xyz(str(data[3]))
155  dist = '{0:.3f}'.format((end - start).norm)
156  score = '{0:.3f}'.format(pose.energies().residue_total_energies(res1)[atom_pair_constraint])
157  constr = '{0:.3f}'.format(float(data[6]) + float(data[8]))
158  error = '{0:.3f}'.format(float(data[8]))
159 
160  # For ambiguous constraints
161  if amb == 1:
162  # Only output pair with lowest distance
163  # Keep going if res in curr line is same as res in prev line (investigating same ambiguous constr)
164  if res1 is prev_res1:
165  lowest_dist.append([dist, str(data[1]), str(res1), str(data[3]), str(res2), str(constr), str(error), str(score)])
166 
167  else:
168 
169  low = min(lowest_dist)
170  pose_file.write("\n"+str(type)+"\t\t"+low[1]+"\t\t"+low[2]\
171  +"\t\t"+low[3]+"\t\t"+low[4]+"\t\t"+low[0]+"\t"+low[5]\
172  +"\t"+low[6]+"\t"+low[7])
173  # clear list
174  lowest_dist = []
175 
176  prev_res1 = res1
177 
178  else:
179  pose_file.write("\n"+str(type)+"\t\t"+str(data[1])+"\t\t"+str(res1)\
180  +"\t\t"+str(data[3])+"\t\t"+str(res2)+"\t\t"+str(dist)+"\t"+str(constr)\
181  +"\t"+str(error)+"\t"+str(score))
182 
183  # }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
184 
185  # Append last amb constraint (no more change in res so it doesn't go into else statement)
186  low = min(lowest_dist)
187  pose_file.write("\n"+str(type)+"\t\t"+low[1]+"\t\t"+low[2]\
188  +"\t\t"+low[3]+"\t\t"+low[4]+"\t\t"+low[0]+"\t"+low[5]\
189  +"\t"+low[6]+"\t"+low[7])
190 
191  """
192  pose_file.close()
193 
194 def append_rmsd(file, pose, native):
195  pose_file = open(file, 'r')
196 
197  for line in pose_file:
198  if line[:22] == " Total weighted score:":
199  score = line.split()[3]
200  break
201  pose_file = open(file, 'a')
202 
203  if file.startswith("Ads"):
204  rmsd = 0
205  else:
206  rmsd = CA_rmsd(native, pose)
207 
208  pose_file.write("\nRMSD and Total Weighted Score: \n"+str(rmsd)+"\t" + str(score))
209  pose_file.close()
210 
static T min(T x, T y)
Definition: Svm.cc:16
xyzVector< Real > xyz(Real const &r1, Real const &omega1, Real const &t, Real const &dz1, Real const &delta_omega1, Real const &delta_z1)
Returns the x-, y-, and z-coordinates of a point on a helix given r1, omega1, and t...
Definition: HelixParams.cc:67
tuple scorefxn
Definition: PyMOL_demo.py:63
bool open(utility::io::izstream &db_stream, std::string const &db_file, bool warn)
Open a database file on a provided stream.
Definition: open.cc:55
rule< Scanner, string_closure::context_t > name
Definition: Tag.cc:376
Fstring rjust(Fstring const &s)
Right-Justified Copy.
Definition: Fstring.hh:2413