Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResidueDecompositionCalculator.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 protocols/toolbox/PoseMetricCalculators/ResidueDecompositionCalculator.cc
11 /// @brief ResidueDecompositionCalculator class
12 /// @author Colin A. Smith
13 
14 // Unit headers
16 
17 #include <core/pose/Pose.hh>
18 #include <basic/MetricValue.hh>
19 
20 #include <utility/string_util.hh>
21 
22 #include <cassert>
23 
24 #include <utility/vector1.hh>
25 
26 
27 using namespace core;
28 using namespace core::pose;
29 using namespace core::pose::metrics;
30 
31 namespace protocols{
32 namespace toolbox {
33 namespace pose_metric_calculators {
34 
35 ResidueDecompositionCalculator::ResidueDecompositionCalculator():
37 {
38 }
39 
41  ResidueDecompositionCalculator const & calculator
42 ):
44  residue_decomposition_(calculator.residue_decomposition()),
45  residue_set_numbers_(calculator.residue_set_numbers())
46 {
47 }
48 
51  std::string const & key
52 ) const
53 {
54  if ( key == "num_sets" ) {
55  return utility::to_string( residue_decomposition_.size() );
56  } else if ( key == "residue_decomposition" ) {
57  std::ostringstream sstream;
58  sstream << "[";
59  for (core::Size i = 1; i <= residue_decomposition_.size(); ++i) {
60  if (i > 1) sstream << ", ";
61  sstream << "Set " << i << " (" << set_names_[i] << "): [";
62  for (std::set<core::Size>::const_iterator iter = residue_decomposition_[i].begin();
63  iter != residue_decomposition_[i].end(); ++iter) {
64  if (iter != residue_decomposition_[i].begin()) sstream << ", ";
65  sstream << *iter;
66  }
67  sstream << "]";
68  }
69  sstream << "]";
70  return sstream.str();
71  } else if ( key == "residue_set_numbers" ) {
72  std::ostringstream sstream;
73  sstream << "[";
74  for (core::Size i = 1; i <= residue_set_numbers_.size(); ++i) {
75  if (i > 1) sstream << ", ";
76  sstream << i << ": " << residue_set_numbers_[i];
77  }
78  sstream << "]";
79  return sstream.str();
80  } else if ( key == "set_names" ) {
81  std::ostringstream sstream;
82  sstream << "[";
83  for (core::Size i = 1; i <= set_names_.size(); ++i) {
84  if (i > 1) sstream << ", ";
85  sstream << set_names_[i];
86  }
87  sstream << "]";
88  return sstream.str();
89  }
90 
91  basic::Error() << "This Calculator cannot compute metric " << key << std::endl;
92  utility_exit();
93  return "";
94 }
95 
96 void
98  std::string const & key,
99  basic::MetricValueBase * valptr
100 ) const
101 {
102  if ( key == "num_sets" ) {
103  core::Size dummy_size(0);
104  basic::check_cast( valptr, &dummy_size, "num_sets expects to return a Size" );
105  (static_cast<basic::MetricValue<core::Size> *>(valptr))->set( residue_decomposition_.size() );
106 
107  } else if ( key == "residue_decomposition" ) {
108  basic::check_cast( valptr, &residue_decomposition_, "decomposition expects to return a utility::vector1<std::set<core::Size> >" );
109  (static_cast<basic::MetricValue<utility::vector1<std::set<core::Size> > > *>(valptr))->set( residue_decomposition_ );
110 
111  } else if ( key == "residue_set_numbers" ) {
112  basic::check_cast( valptr, &residue_set_numbers_, "set_numbers expects to return a utility::vector1< core::Size >" );
113  (static_cast<basic::MetricValue<utility::vector1<core::Size> > *>(valptr))->set( residue_set_numbers_ );
114 
115  } else if ( key == "set_names" ) {
116  basic::check_cast( valptr, &set_names_, "set_names expects to return a utility::vector1< std::string >" );
117  (static_cast<basic::MetricValue<utility::vector1<std::string> > *>(valptr))->set( set_names_ );
118 
119  } else {
120  basic::Error() << "ResidueDecompositionCalculator cannot compute the requested metric " << key << std::endl;
121  utility_exit();
122  }
123 }
124 
125 void
127  core::pose::Pose const & this_pose
128 )
129 {
130  // reset residue_set_numbers_ to zeros
131  residue_set_numbers_.assign(this_pose.total_residue(), 0);
132 
133  for (core::Size i = 1; i <= residue_decomposition_.size(); ++i) {
134  for (std::set<core::Size>::iterator iter = residue_decomposition_[i].begin(); iter != residue_decomposition_[i].end(); ++iter) {
135  if (*iter <= residue_set_numbers_.size()) residue_set_numbers_[*iter] = i;
136  }
137  }
138 }
139 
140 void
142 {
143  // reset residue_decomposition_ to the correct number of empty sets
144  core::Size max_set_number = 0;
145  for (core::Size i = 1; i <= residue_set_numbers_.size(); ++i) {
146  core::Size const residue_set_number(residue_set_numbers_[i]);
147  if (residue_set_number > max_set_number) max_set_number = residue_set_number;
148  }
149  residue_decomposition_.resize(max_set_number);
150  for (core::Size i = 1; i <= residue_decomposition_.size(); ++i) {
151  residue_decomposition_[i].clear();
152  }
153 
154  for (core::Size i = 1; i <= residue_set_numbers_.size(); ++i) {
155  core::Size const residue_set_number(residue_set_numbers_[i]);
156  if (residue_set_number > 0) residue_decomposition_[residue_set_number].insert(i);
157  }
158 }
159 
160 
161 } // PoseMetricCalculators
162 } // toolbox
163 } // protocols