Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RotamerRecovery.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 //////////////////////////////////////////////////////////////////////
10 /// @begin RotamerRecovery
11 ///
12 /// @brief
13 /// Compare the rotamer recovery between a native protein and a list of other proteins
14 ///
15 /// @detailed
16 /// This is an implementation taken from James Thompson. I am not even sure he knows I stole it
17 /// from him. The main function that is called is the get_rotamer_recovery() function. You can
18 /// pass this function a native pdb and a list of altered pdbs, or just 1 native and 1
19 /// alterd pdb. The rotamer recovery will be output to the screen. Output looks like:
20 /// # total = 1
21 /// resi_idx nat_bb_bin pct_bb nat_rot1 pct_rot1 nat_rot2 pct_rot2 nat_rot3 pct_rot3 nat_rot4 pct_rot4
22 /// 1 E 1.0000 1 1.0000 2 1.0000 1 1.0000 999 0.0000
23 /// 2 B 1.0000 2 1.0000 1 1.0000 999 0.0000 999 0.0000
24 /// Where the # total is how many proteins compared.
25 /// resi_idx = residue index
26 /// nat_bb_bin = dssp naming for bb
27 /// pct_bb = how many match the bb bins?
28 /// nat_rot1 = chi 1
29 /// pct_rot1 = how many are correct
30 /// If 999 appears, that means that the amino acid does not have that chi angle
31 ///
32 ///
33 ///
34 /// @authors
35 /// @author James Thompson (original author)
36 /// @author Steven Combs (moved it to protocols for general use)
37 ///
38 /// @last_modified October 20 2010
39 /////////////////////////////////////////////////////////////////////////
40 
41 #include <core/types.hh>
43 #include <core/pose/Pose.hh>
44 
45 // AUTO-REMOVED #include <basic/options/option.hh>
46 // AUTO-REMOVED #include <basic/database/open.hh>
47 //#include <devel/init.hh>
48 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
49 
50 // AUTO-REMOVED #include <core/chemical/util.hh>
52 
55 
56 // AUTO-REMOVED #include <core/import_pose/pose_stream/MetaPoseInputStream.hh>
57 // AUTO-REMOVED #include <core/import_pose/pose_stream/util.hh>
58 
59 // XRW-REMOVE #include <protocols/jumping/util.hh>
61 
62 #include <utility/vector1.hh>
63 
64 // C++ headers
65 #include <string>
66 #include <ObjexxFCL/format.hh>
67 #include <ObjexxFCL/string.functions.hh>
69 
70 // option key includes
71 
72 
73 
74 
75 namespace protocols{
76 namespace toolbox{
77 namespace pose_metric_calculators{
78 
79 
80 
82  float const phi,
83  float const psi,
84  float const omega
85 ) {
86  if ( std::abs( omega ) < 90 ) {
87  return 'O'; // cis-omega
88  } else if ( phi >= 0.0 ) {
89  if ( -100 < psi && psi <= 100 ) {
90  return 'G'; // alpha-L
91  } else {
92  return 'E'; // E
93  }
94  } else {
95  if ( -125 < psi && psi <= 50 ) {
96  return 'A'; // helical
97  } else {
98  return 'B'; // extended
99  }
100  }
101  return 'X';
102 }
103 
105  core::scoring::dssp::Dssp dssp(pose);
106  dssp.insert_ss_into_pose(pose);
107 
108  utility::vector1< char > ss( pose.total_residue(), 'L' );
109  for ( core::Size ii = 1; ii <= pose.total_residue(); ++ii ) {
110  ss[ii] = pose.secstruct(ii);
111  }
112 
113  return ss;
114 }
117  std::ostream & out
118 ) {
119  using core::Size;
120  for ( Size ii = 1; ii <= rot_vec.size(); ++ii ) {
121  out << rot_vec[ii];
122  if ( ii != rot_vec.size() ) {
123  out << ",";
124  }
125  }
126 }
127 
129  core::pose::Pose const & pose
130 ) {
131  utility::vector1< char > bb_bins;
132  for ( core::Size ii = 1; ii <= pose.total_residue(); ++ii ) {
133  bb_bins.push_back(
135  pose.residue(ii).mainchain_torsion(1),
136  pose.residue(ii).mainchain_torsion(2),
137  pose.residue(ii).mainchain_torsion(3)
138  )
139  );
140  }
141  return bb_bins;
142 }
143 
146  core::pose::Pose const & pose
147 ) {
148 
149 
151  for ( core::Size ii = 1; ii <= pose.total_residue(); ++ii ) {
154  rots.push_back( rot );
155  }
156  return rots;
157 }
158 
161  core::pose::Pose const & pose
162 ) {
163 
164 
166  for ( core::Size ii = 1; ii <= pose.total_residue(); ++ii ) {
168  for ( core::Size jj = 1; jj <= pose.residue(ii).nchi(); ++jj ) {
169  chi_vec.push_back( pose.chi(jj,ii) );
170  }
171  chis.push_back( chi_vec );
172  }
173  return chis;
174 }
175 
176 
177 //overflowed function so that you can give this only one pose
180  poses.push_back(compared_pose);
181  get_rotamer_recovery(native, poses);
182 }
183 
184 //main body. this is where the magic happens
186  utility::vector1< char > nat_bb_bins( bb_bins_from_pose(native) );
188 
189  utility::vector1< core::Size > bb_bins_correct( native.total_residue(), 0 );
192  );
193 
194 
195 
198  );
199 
200 
201  core::Size total(0);
202  utility::vector1< core::pose::Pose >::iterator other_poses_itr( compared_poses.begin() ), other_poses_last( compared_poses.end() );
203  while( (other_poses_itr != other_poses_last ) ) {
204  core::pose::Pose pose( *other_poses_itr );
205 
206  utility::vector1< char > pose_bb_bins( bb_bins_from_pose(pose) );
209 
210  runtime_assert( pose_bb_bins.size() == nat_bb_bins.size() );
211  runtime_assert( pose_rots.size() == pose_rots.size() );
212  for ( core::Size ii = 1; ii <= pose.total_residue(); ++ii ) {
213  if ( pose_bb_bins[ii] == nat_bb_bins[ii] ) {
214  bb_bins_correct[ii]++;
215  }
216  for ( core::Size jj = 1; jj <= pose_rots[ii].size(); ++jj ) {
217  //std::cout << "rot(" << ii << "," << jj << ")" << std::endl;
218  if ( pose_rots[ii][jj] == nat_rots[ii][jj] ) {
219  rots_correct[ii][jj]++;
220  }
221  }
222  }
223  ++total;
224  other_poses_itr++;
225  }
226 
227 
228  // print out stats on bb_bins_correct and rots_correct
229  std::ostream & output( std::cout );
230  core::Size const width(12);
231  core::Size const prec(4);
232 
233  output << "# total = " << ObjexxFCL::string_of(total) << std::endl;
234  output
235  << ObjexxFCL::fmt::A( width, "resi_idx" )
236  << ObjexxFCL::fmt::A( width, "nat_bb_bin" )
237  << ObjexxFCL::fmt::A( width, "pct_bb" )
238  << ObjexxFCL::fmt::A( width, "nat_rot1" )
239  << ObjexxFCL::fmt::A( width, "pct_rot1" )
240  << ObjexxFCL::fmt::A( width, "nat_rot2" )
241  << ObjexxFCL::fmt::A( width, "pct_rot2" )
242  << ObjexxFCL::fmt::A( width, "nat_rot3" )
243  << ObjexxFCL::fmt::A( width, "pct_rot3" )
244  << ObjexxFCL::fmt::A( width, "nat_rot4" )
245  << ObjexxFCL::fmt::A( width, "pct_rot4" )
246  << std::endl;
247 
248  for ( core::Size ii = 1; ii <= native.total_residue(); ++ii ) {
249  core::Real pct_bb(0.0);
250  if ( bb_bins_correct[ii] > 0 ) {
251  pct_bb = (
252  static_cast< core::Real > ( bb_bins_correct[ii] ) /
253  static_cast< core::Real > ( total )
254  );
255  }
256  utility::vector1< core::Real > pct_natrots;
257  utility::vector1< core::Size > out_nat_rots;
258  for ( core::Size jj = 1; jj <= 4; ++jj ) {
259  if ( jj <= nat_rots[ii].size() ) {
260  core::Real pct_natrots_correct(0.0);
261  if ( rots_correct[ii][jj] > 0 ) {
262  pct_natrots_correct = (
263  static_cast< core::Real > ( rots_correct[ii][jj] ) /
264  static_cast< core::Real > ( total )
265  );
266  }
267  pct_natrots.push_back( pct_natrots_correct );
268  out_nat_rots.push_back( nat_rots[ii][jj] );
269  } else {
270  //std::cout << "no rot " << jj << std::endl;
271  pct_natrots.push_back( 0.0 );
272  out_nat_rots.push_back( 999 );
273  }
274  }
275 
276  //std::cout << "nat_rots[" << ii << "][1] = "
277  // << nat_rots[ii][1] << std::endl;
278  //std::cout << "nat_rots[" << ii << "].size() = "
279  // << nat_rots[ii].size() << std::endl;
280 
281  output
282  << ObjexxFCL::fmt::A( width, ObjexxFCL::string_of(ii) )
283  << ObjexxFCL::fmt::A( width, nat_bb_bins[ii] )
284  << ObjexxFCL::fmt::F( width, prec, pct_bb )
285  << ObjexxFCL::fmt::A( width, ObjexxFCL::string_of(out_nat_rots[1]) )
286  << ObjexxFCL::fmt::F( width, prec, pct_natrots[1] )
287  << ObjexxFCL::fmt::A( width, ObjexxFCL::string_of(out_nat_rots[2]) )
288  << ObjexxFCL::fmt::F( width, prec, pct_natrots[2] )
289  << ObjexxFCL::fmt::A( width, ObjexxFCL::string_of(out_nat_rots[3]) )
290  << ObjexxFCL::fmt::F( width, prec, pct_natrots[3] )
291  << ObjexxFCL::fmt::A( width, ObjexxFCL::string_of(out_nat_rots[4]) )
292  << ObjexxFCL::fmt::F( width, prec, pct_natrots[4] )
293  << std::endl;
294  }
295 
296 
297 
298 }
299 
300 
301 
302 
303 /*
304 int
305 main( int argc, char* argv [] ) {
306  // options, random initialization
307  devel::init( argc, argv );
308 
309  using namespace basic::options;
310  using namespace basic::options::OptionKeys;
311  using namespace core::scoring::constraints;
312  using namespace ObjexxFCL::fmt;
313  using namespace core::import_pose::pose_stream;
314  using namespace core::chemical;
315  using namespace core::pack::dunbrack;
316 
317  using core::Size;
318  using core::Real;
319  using std::string;
320  using utility::vector1;
321  using ObjexxFCL::string_of;
322  using core::pose::Pose;
323 
324  core::import_pose::pose_stream::MetaPoseInputStream input
325  = core::import_pose::pose_stream::streams_from_cmd_line();
326  ResidueTypeSetCAP rsd_set = rsd_set_from_cmd_line();
327 
328  Pose native;
329  core::io::pdb::pose_from_pdb(
330  native, option[ in::file::native ]()
331  );
332 
333  vector1< char > nat_bb_bins( bb_bins_from_pose(native) );
334  vector1< RotVector > nat_rots( rots_from_pose(native) );
335 
336  vector1< Size > bb_bins_correct( native.total_residue(), 0 );
337  vector1< vector1< Size > > rots_correct(
338  native.total_residue(), vector1< Size >( native.total_residue(), 0 )
339  );
340 
341 
342  vector1< vector1< Size > > chis_correct(
343  native.total_residue(), vector1< Size >( native.total_residue(), 0 )
344  );
345 
346 
347 
348 
349  Size total(0);
350  while( input.has_another_pose() ) {
351  Pose pose;
352  input.fill_pose( pose, *rsd_set );
353 
354  vector1< char > pose_bb_bins( bb_bins_from_pose(pose) );
355  vector1< RotVector > pose_rots( rots_from_pose(pose) );
356  vector1< vector1< Real > > pose_chis( chis_from_pose(pose) );
357 
358  runtime_assert( pose_bb_bins.size() == nat_bb_bins.size() );
359  runtime_assert( pose_rots.size() == pose_rots.size() );
360  for ( Size ii = 1; ii <= pose.total_residue(); ++ii ) {
361  if ( pose_bb_bins[ii] == nat_bb_bins[ii] ) {
362  bb_bins_correct[ii]++;
363  }
364  for ( Size jj = 1; jj <= pose_rots[ii].size(); ++jj ) {
365  //std::cout << "rot(" << ii << "," << jj << ")" << std::endl;
366  if ( pose_rots[ii][jj] == nat_rots[ii][jj] ) {
367  rots_correct[ii][jj]++;
368  }
369  }
370  }
371  ++total;
372  }
373 
374 
375 
376  //////
377  /////
378  /////
379 
380  // print out stats on bb_bins_correct and rots_correct
381  std::ostream & output( std::cout );
382  Size const width(12);
383  Size const prec(4);
384 
385  output << "# total = " << string_of(total) << std::endl;
386  output
387  << A( width, "resi_idx" )
388  << A( width, "nat_bb_bin" )
389  << A( width, "pct_bb" )
390  << A( width, "nat_rot1" )
391  << A( width, "pct_rot1" )
392  << A( width, "nat_rot2" )
393  << A( width, "pct_rot2" )
394  << A( width, "nat_rot3" )
395  << A( width, "pct_rot3" )
396  << A( width, "nat_rot4" )
397  << A( width, "pct_rot4" )
398  << std::endl;
399 
400  for ( Size ii = 1; ii <= native.total_residue(); ++ii ) {
401  Real pct_bb(0.0);
402  if ( bb_bins_correct[ii] > 0 ) {
403  pct_bb = (
404  static_cast< Real > ( bb_bins_correct[ii] ) /
405  static_cast< Real > ( total )
406  );
407  }
408  vector1< Real > pct_natrots;
409  vector1< Size > out_nat_rots;
410  for ( Size jj = 1; jj <= 4; ++jj ) {
411  if ( jj <= nat_rots[ii].size() ) {
412  Real pct_natrots_correct(0.0);
413  if ( rots_correct[ii][jj] > 0 ) {
414  pct_natrots_correct = (
415  static_cast< Real > ( rots_correct[ii][jj] ) /
416  static_cast< Real > ( total )
417  );
418  }
419  pct_natrots.push_back( pct_natrots_correct );
420  out_nat_rots.push_back( nat_rots[ii][jj] );
421  } else {
422  //std::cout << "no rot " << jj << std::endl;
423  pct_natrots.push_back( 0.0 );
424  out_nat_rots.push_back( 999 );
425  }
426  }
427 
428  //std::cout << "nat_rots[" << ii << "][1] = "
429  // << nat_rots[ii][1] << std::endl;
430  //std::cout << "nat_rots[" << ii << "].size() = "
431  // << nat_rots[ii].size() << std::endl;
432 
433  output
434  << A( width, string_of(ii) )
435  << A( width, nat_bb_bins[ii] )
436  << F( width, prec, pct_bb )
437  << A( width, string_of(out_nat_rots[1]) )
438  << F( width, prec, pct_natrots[1] )
439  << A( width, string_of(out_nat_rots[2]) )
440  << F( width, prec, pct_natrots[2] )
441  << A( width, string_of(out_nat_rots[3]) )
442  << F( width, prec, pct_natrots[3] )
443  << A( width, string_of(out_nat_rots[4]) )
444  << F( width, prec, pct_natrots[4] )
445  << std::endl;
446  }
447  return 0;
448 } // int main( int argc, char * argv [] )
449 */
450 
451 
452 
453 }
454 }
455 }