Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PackstatCalculator.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 /// @file core/pose/metrics/PackstatCalculator.cc
11 /// @brief packstat calculator class
12 /// @author Florian Richter
13 
14 // Unit headers
17 
19 // AUTO-REMOVED #include <core/pose/metrics/CalculatorFactory.hh>
20 #include <core/pose/Pose.hh>
21 // AUTO-REMOVED #include <protocols/toolbox/PoseMetricCalculators/NumberHBondsCalculator.hh>
22 // AUTO-REMOVED #include <protocols/toolbox/PoseMetricCalculators/SasaCalculator.hh>
24 
25 
26 
27 // Utility headers
28 #include <basic/Tracer.hh>
29 #include <utility/exit.hh>
30 #include <utility/stream_util.hh>
31 #include <utility/string_util.hh>
32 #include <basic/MetricValue.hh>
33 
34 
35 #include <cassert>
36 
37 #include <utility/vector1.hh>
38 
39 
40 
41 using namespace core;
42 using namespace core::pose;
43 using namespace core::pose::metrics;
44 
45 static basic::Tracer TR("protocols/toolbox/PoseMetricCalculators/PackstatCalculator");
46 
47 namespace protocols{
48 namespace toolbox {
49 namespace pose_metric_calculators {
50 
51 
52 PackstatCalculator::PackstatCalculator(
53  core::Size oversample,
54  bool remove_nonprotein_res
55 ) : total_packstat_(0),
56  special_region_packstat_(0),
57  oversample_(oversample),
58  remove_nonprotein_res_(remove_nonprotein_res)
59 {
60  special_region_.clear();
61  residue_packstat_.clear();
62 }
63 
64 
66  std::set< core::Size > const & special_region,
67  core::Size oversample,
68  bool remove_nonprotein_res
69 ) : total_packstat_(0),
70  special_region_packstat_(0),
71  oversample_(oversample),
72  remove_nonprotein_res_(remove_nonprotein_res),
73  special_region_( special_region )
74 {
75  residue_packstat_.clear();
76 }
77 
78 
79 void
81  std::string const & key,
82  basic::MetricValueBase * valptr
83 ) const
84 {
85 
86  if ( key == "total_packstat" ) {
87  basic::check_cast( valptr, &total_packstat_, "total_packstat expects to return a real" );
88  (static_cast<basic::MetricValue<Real> *>(valptr))->set( total_packstat_ );
89 
90  } else if ( key == "special_region_packstat" ) {
91  basic::check_cast( valptr, &special_region_packstat_, "special_region_packstat expects to return a real" );
92  (static_cast<basic::MetricValue<Real> *>(valptr))->set( special_region_packstat_ );
93 
94  } else if ( key == "residue_packstat" ) {
95  basic::check_cast( valptr, &residue_packstat_, "residue_packstat expects to return a utility::vector1< Real >" );
96  (static_cast<basic::MetricValue<utility::vector1< Real > > *>(valptr))->set( residue_packstat_ );
97 
98  } else {
99  basic::Error() << "PackstatCalculator cannot compute the requested metric " << key << std::endl;
100  utility_exit();
101  }
102 
103 } //lookup
104 
105 
106 
109 {
110 
111  if ( key == "total_packstat" ) {
112  return utility::to_string( total_packstat_ );
113  } else if ( key == "special_region_packstat" ) {
114  return utility::to_string( special_region_packstat_ );
115  } else if ( key == "residue_packstat" ) {
116  return utility::to_string( residue_packstat_ );
117  }
118 
119  basic::Error() << "PackstatCalculator cannot compute metric " << key << std::endl;
120  utility_exit();
121  return "";
122 
123 } //print
124 
125 
126 /// @brief this function doesn't actually recompute anything by itself, but calls the
127 /// @brief stuff in the packstat code
128 void
130 {
131  using namespace core::scoring::packstat;
132 
134 
135  bool has_nonprot_res(false);
136 
137  for( core::Size i = 1; i <= this_pose.total_residue(); ++i){
138  if( ! this_pose.residue_type(i).is_protein() ){
139  has_nonprot_res = true;
140  break;
141  }
142  }
143 
144  if( has_nonprot_res ){
145 
146  PoseOP pureprotpose = new Pose( this_pose );
147 
149 
152  runtime_assert( pureprotpose->total_residue() == residue_packstat_.size() );
153  }
154  else{
157  runtime_assert( this_pose.total_residue() == residue_packstat_.size() );
158  }
159  }
160 
161  else{
164  runtime_assert( this_pose.total_residue() == residue_packstat_.size() );
165  }
166 
167 
168  core::Real respackstat_sum(0.0);
169  core::Real special_region_sum(0.0);
170  for( Size i = 1; i <= residue_packstat_.size(); ++i){
171 
172  respackstat_sum = respackstat_sum + residue_packstat_[i];
173  if( special_region_.find( i ) != special_region_.end() ) special_region_sum = special_region_sum + residue_packstat_[i];
174 
175  }
176 
177  //runtime_assert( total_packstat_ == ( respackstat_sum / residue_packstat_.size() ) );
178  //std::cerr << "total packstat is " << total_packstat_ << ", average residue packstat is " << respackstat_sum / residue_packstat_.size() << std::endl;
179 
180  special_region_packstat_ = ( special_region_sum / special_region_.size() );
181 
182 } //recompute
183 
184 
185 } //namespace pose_metric_calculators
186 } //namespace toolbox
187 } //namespace protocols