Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
analysis.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 # (c) Copyright Rosetta Commons Member Institutions.
4 # (c) This file is part of the Rosetta software suite and is made available under license.
5 # (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
6 # (c) For more information, see http://www.rosettacommons.org. Questions about this can be
7 # (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
8 
9 ## @file /GUIs/pyrosetta_toolkit/modules/tools/analysis.py
10 ## @brief Functions for analysis in the toolkit
11 ## @author Jared Adolf-Bryfogle (jadolfbr@gmail.com)
12 
13 #Rosetta Imports
14 from rosetta import *
15 from rosetta.protocols.analysis import *
16 from rosetta.protocols.vip import *
17 
18 #Tkinter Imports
19 import tkMessageBox
20 import tkSimpleDialog
21 import tkFileDialog
22 
23 #Python Imports
24 import time
25 import math
26 import os.path
27 
28 #Toolkit Imports
29 
31 from app.pyrosetta_toolkit.window_main import global_variables
32 
34  tot=pose.total_residue()
35  print "Residue - Phi - Psi"
36  for i in range(1, tot+1):
37  print repr(pose.pdb_info().number(i))+" "+repr(pose.phi(i))+" "+repr(pose.psi(i))
38 
40  for i in range(0, pose.total_residue()):
41  pose.energies().show(i)
42 
43 def rmsd(native, p, loops_as_strings, ca_only = False, all_atom=False):
44  """
45  Prints + Returns RMSD for Full Protein, as well as any loops in loops_as_strings.
46  """
47  rms = ""
48  if ca_only:
49  rms = CA_rmsd(native, p)
50  print "C-Alpha:"
51  print "%.3f RMSD"%rms
52  elif all_atom:
53  rms = all_atom_rmsd(native, p)
54  print "All Atom:"
55  print "%.3f RMSD"%rms
56  else:
57  rms = bb_rmsd(native, p)
58  print "Backbone:"
59  print "%.3f RMSD"%rms
60 
61  #if start !=0 and end!=0:
62  # start = p.pdb_info().pdb2pose(chain, int(start)); end = p.pdb_info().pdb2pose(chain, int(end))
63  # cut = start+((end-start)/2); loo=Loop(start,end, cut)
64  # loops = Loops()
65  # loops.add_loop(loo)
66 
67  # lrms = loop_rmsd(p, native, loops, False)
68  # print "Loop RMSD:" + str(lrms)
69 
70  if all_atom:bb_only = False
71  else: bb_only=True
72  loop_rmsd_map = dict(); #[loop_string]:[lrms] and ['total']:[total average loop rms]
73  if loops_as_strings:
74  all_rosetta_loops = Loops()
75  for loop_string in loops_as_strings:
76  rosetta_loop = loop_tools.return_rosetta_Loop(p, loop_string)
77  single_loops = Loops()
78 
79  single_loops.add_loop(rosetta_loop)
80  all_rosetta_loops.add_loop(rosetta_loop)
81 
82  lrms = loop_rmsd(p, native, single_loops, ca_only, bb_only)
83  print "Region "+loop_string
84  print "%.3f RMSD"%lrms
85  loop_rmsd_map[loop_string]=lrms
86  lrms = loop_rmsd(p, native, all_rosetta_loops, ca_only, bb_only)
87  loop_rmsd_map["total"]=lrms
88  print "Regions Average: "
89  print "%.3f RMSD"%lrms
90 
91  return rms, loop_rmsd_map
92 
93 def readFASC(fileName):
94  File = open(fileName, 'r')
95  fascData = dict()
96  for line in File:
97  lineSplit = line.split()
98  if lineSplit[0]!="pdb":
99  x = 3
100  for i in range(3, (len(lineSplit)/2)+2):
101  if not fascData.has_key(lineSplit[1]):
102  fascData[lineSplit[1]]=dict()
103  fascData[lineSplit[1]][lineSplit[x-1]]=lineSplit[x]
104  x = x+2
105  return fascData
106 
107 #### Analyze Movers ####
108 
110  pack_mover = PackStatMover()
111  print "\nSee the paper on RosettaHoles to find out more about this statistic (Protein Sci. 2009 Jan;18(1):229-39.)"
112  pack_mover.apply(p)
113 
114 def analyze_interface(p, scorefxn, toolkit = None):
115  print "Analyzing Interface. "
116  print "\nNo references are directly associated with this protocol. It was used with Documentation for AnchoredDesign application (see that app's documentation) and CAPRI21 interface descrimination. (Steven Lewis)"
117  print "The Mover will seperate chains defined in the interface to calculate energy differences. Repacking is recommended."
118  chains = ""
119  if (p.conformation().num_chains()==2):
120  pass
121  else:
122  chains = tkSimpleDialog.askstring(title = "-fixedchains", prompt = "Please input chains to keep fixed - seperated by a space")
123  chains.upper()
124  if (chains):
125  chains = chains.split()
126  else:return
127 
128  pack_together = tkMessageBox.askyesno(message="rePack before separation")
129  pack_separated = tkMessageBox.askyesno(message="rePack after separation (Recommended)")
130 
131  if (p.conformation().num_chains()==2):
132  interface_mover = InterfaceAnalyzerMover(1, True, scorefxn, False, pack_together, pack_separated, False)
133  interface_mover.apply(p)
134 
135  else:
136  chain_ids = []
137  #Get ChainIDs
138  for chain in chains:
139  for i in range(1, p.total_residue()+1):
140  if (p.pdb_info().chain( i ) == chain):
141  chain_ids.append( p.chain(i))
142  break
143 
144  #Pass in the set.
145  print "Fixedchains: "+repr(chains)
146  interface_mover = InterfaceAnalyzerMover(rosetta.Set(chain_ids), True, scorefxn, False, pack_together, pack_separated, False )
147  interface_mover.use_tracer(True)
148  interface_mover.apply(p)
149  print "Interface Analyzer complete."
150 
151 def analyze_loops(p, loops_as_strings):
152  """
153  Uses AnalyzeLoopMover to print loop information.
154  To accurately use this, add cutpoint variants using the FullControl Window.
155  """
156 
157  if not loops_as_strings: return
158  loops_object = loop_tools.InitializeLoops(p, loops_as_strings)
159  loop_mover = LoopAnalyzerMover(loops_object, True)
160  loop_mover.apply(p)
161 
162 def analyze_vip(p, scorefxn):
163  """
164  Uses VIP mover to get Mutational information.
165  Should be threaded, which will be added soon.
166  """
167  vip_mover = VIP_Mover()
168  vip_mover.set_initial_pose(p)
169  old_energy = scorefxn(p)
170  print "\nThis is going to take some time...."
171  print "This code uses the RosettaHoles approach to identify problematic buried cavities, and suggests a set of mutations that are predicted to improve stability as determined by improvements to the RosettaHoles and Rosetta fullatom energy scores."
172  print "NOTE: For full options, please see the Rosetta application."
173  print "Please see Borgo, B., Havranek, J.J. (2012), 'Automated selection of stabilizing mutations in designed and natural proteins', Proc. Natl. Acad. Sci. USA, v.109(5) pp.1494-99."
174  time.sleep(6)
175  if (tkMessageBox.askyesno(message="Continue?")):
176  pass
177  else:
178  return
179  cycles = tkSimpleDialog.askinteger(title = "Cycles", prompt="Please enter max cycles", initialvalue=rosetta.basic.options.get_integer_option('cp:ncycles'))
180 
181  # Rewritten in python From VIP.cc so the same behavior is met. Just an interface through PyRosetta to the application code.
182  not_finished=True
183  improved = False
184  i=1
185  while (not_finished):
186 
187  vip_mover.apply()
188  out = vip_mover.get_final_pose()
189  print "Comparing new energy " + repr(scorefxn(out)) + " with old energy " + repr(old_energy)
190  if (old_energy>scorefxn(out)):
191  improved = True
192  else:
193  improved = False
194 
195  if(improved):
196  for j in range(1, p.total_residue()+1):
197  if( out.residue(j).name() != p.residue(j).name() ):
198  position = out.pdb_info().number(j)
199  pdb_chain = out.pdb_info().chain(j)
200  print "Accepting mutation at position "+repr(pdb_position)+" chain "+pdb_chain +" from " +p.residue(j).name() +" to " +out.residue(j).name()
201  old_energy = scorefxn(out)
202 
203 #### Rotamers ####
204  """
205  Used in full control window to get energy and probability of the rotamer.
206  """
207 
208 def return_energy(p, res, chain=0, type = fa_dun):
209  """
210  Returns the energy of the rotamer/scoretype by talaris2013.
211  """
212 
213  if chain !=0:
214  res = p.pdb_info().pdb2pose(chain, int(res))
215  score = create_score_function("talaris2013")
216  emap = core.scoring.EMapVector()
217  score.eval_ci_1b(p.residue(res), p, emap)
218  e = emap[type]
219  return e
220 
221 def return_probability(p, res, chain=0):
222  """
223  Returns probability of rotamer based on -ln(p)=E -> p = e^-E
224  """
225 
226  e = return_energy(p, res, chain)
227  p = math.exp(-e)
228  return p
229 
230 
231 
StringOptionKey const chain
tuple scorefxn
Definition: PyMOL_demo.py:63
Fstring::size_type len(Fstring const &s)
Length.
Definition: Fstring.hh:2207
void show(utility::vector1< T_ > vector)
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
def analyze_packing
Analyze Movers ####.
Definition: analysis.py:109