Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PoseMetricContainer.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/PoseMetricContainer.cc
11 /// @brief PoseMetricContainer class
12 /// @author John Karanicolas
13 
14 // Unit headers
18 
19 #include <core/pose/Pose.hh>
23 // AUTO-REMOVED #include <core/conformation/Conformation.hh>
24 
25 // Utility headers
26 #include <basic/Tracer.hh>
27 #include <basic/MetricValue.fwd.hh>
28 #include <utility/exit.hh>
29 
30 // C++ Headers
31 #include <map>
32 
33 #include <utility/vector0.hh>
34 #include <utility/vector1.hh>
35 
36 //Auto Headers
38 #include <core/kinematics/Jump.hh>
39 
40 
41 
42 namespace core {
43 namespace pose {
44 namespace metrics {
45 
46 
47 /// @brief default destructor
49  pose_ptr_( NULL ),
50  structure_is_outdated_( true ),
51  energies_are_outdated_( true )
52 {}
53 
54 
55 /// @brief copy constructor
56 /// @warning observation of subject Pose in src not duplicated
58  ReferenceCount(),
59  pose_ptr_( NULL ), // this is correct behavior
60  structure_is_outdated_( src.structure_is_outdated_ ),
61  energies_are_outdated_( src.energies_are_outdated_ )
62 {
64 }
65 
66 
67 /// @brief default destructor
69  detach_from();
70 }
71 
72 
73 /// @brief copy assignment
74 /// @warning container keeps observing whatever Pose it was originally observing
76  if ( this != &src ) {
77  // subject Pose in src is *not* copied, we retain whatever Pose we were originally
78  // observing
79  clear(); // flags reset here, we'll need an update after this
81  }
82  return *this;
83 }
84 
85 
86 /// @brief clear the list of metric calculators, reset flags
88  metric_calculators_.clear();
91 }
92 
93 
94 /// @brief get a value out of a PoseMetricCalculator
95 // TODO: should we really be passing a Pose pointer in...? Consider using the internal pose_ptr_;
96 void PoseMetricContainer::get( std::string const & calculator_name, std::string const & key, basic::MetricValueBase & val, Pose const & this_pose ) {
97  get_calculator(calculator_name)->get( key, val, this_pose );
98 }
99 
100 
101 /// @brief return a string with the results of a PoseMetricCalculator
102 std::string PoseMetricContainer::print( std::string const & calculator_name, std::string const & key, Pose const & this_pose ) {
103  return get_calculator(calculator_name)->get( key, this_pose );
104 }
105 
106 
107 /// @brief attach to a Pose
109  if ( pose_ptr_ ) {
110  detach_from();
111  }
112 
116  pose_ptr_ = &pose;
117 
118  // new pose, so assume we need a full update
119  structure_is_outdated_ = true;
120  energies_are_outdated_ = true;
121 }
122 
123 
124 /// @brief detach from Pose
126  if ( pose_ptr_ ) {
130  }
131 
132  pose_ptr_ = NULL;
133 }
134 
135 
136 /// @brief is observing a Pose?
137 /// @return the Pose if observing, otherwise NULL
139  return pose_ptr_;
140 }
141 
142 
143 /// @brief upon receiving a pose::signals::DestructionEvent, detaches
145  detach_from();
146 }
147 
148 
149 /// @brief upon receiving pose::signals::ConformationEvent, sets flag telling
150 /// calculators to refresh structure based calculations
152  structure_is_outdated_ = true;
153 }
154 
155 
156 /// @brief upon receiving a pose:signals::EnergyEvent, sets flag telling
157 /// calculators to refresh energy based calculations
159  energies_are_outdated_ = true;
160 }
161 
162 
163 /// @brief set PoseMetricCalculator structure changed flags
165  // notify all calculators that the structure is outdated
166  std::map< std::string, PoseMetricCalculatorOP >::iterator iter_calculators;
167  for ( iter_calculators = metric_calculators_.begin(); iter_calculators != metric_calculators_.end(); ++iter_calculators ) {
168  iter_calculators->second->notify_structure_change();
169  }
170 
171  // reset global flag
172  structure_is_outdated_ = false;
173 }
174 
175 
176 /// @brief set PoseMetricCalculator energy changed flags
178 
179  // notify all calculators that the energy is outdated
180  Name2Calculator::iterator iter_calculators;
181  for ( iter_calculators = metric_calculators_.begin(); iter_calculators != metric_calculators_.end(); ++iter_calculators ) {
182  iter_calculators->second->notify_energy_change();
183  }
184 
185  // reset global flag
186  energies_are_outdated_ = false;
187 }
188 
189 
190 /// @brief get a PoseMetricCalculator by name
192 
193  if ( !pose_ptr_ ) {
194  basic::Error() << "This PoseMetricContainer is not observing a Pose" << std::endl;
195  utility_exit();
196  }
197 
198  // propagate news of the outdated structure/sequence/energy to the metrics and calculators
199  if ( structure_is_outdated_ ) {
201  }
202 
203  // if ( sequence_is_outdated_ ) process_sequence_change();
204 
205  if ( energies_are_outdated_ ) {
207  }
208 
209  // call the "get" function for the appropriate metric
210  Name2Calculator::const_iterator calculator_iter;
211  calculator_iter = metric_calculators_.find( calculator_name );
212  if (calculator_iter == metric_calculators_.end() ) {
213  // this calculator has not yet been setup, add it
214  add_calculator( calculator_name );
215  calculator_iter = metric_calculators_.find( calculator_name );
216  if (calculator_iter == metric_calculators_.end() ) {
217  basic::Error() << "Could not lookup calculator " << calculator_name << " despite trying to add it" << std::endl;
218  utility_exit();
219  }
220  }
221 
222  return calculator_iter->second;
223 }
224 
225 
226 /// @brief add a PoseMetricCalculator by name
227 void PoseMetricContainer::add_calculator( std::string const & calculator_name ) {
228  PoseMetricCalculatorOP new_calculator = CalculatorFactory::Instance().retrieve_calculator( calculator_name );
229  metric_calculators_.insert( std::make_pair( calculator_name, new_calculator ) );
230 }
231 
232 
233 /// @brief clone calculators, primarily for copy
235  for ( Name2Calculator::const_iterator i = calcs.begin(), ie = calcs.end(); i != ie; ++i ) {
236  metric_calculators_.insert( std::make_pair( i->first, i->second->clone() ) );
237  }
238 }
239 
240 /*
241 void PoseMetricContainer::process_sequence_change() {
242  // notify all calculators that the sequence is outdated
243  Name2Calculator:iterator iter_calculators;
244  for ( iter_calculators = metric_calculators_.begin(); iter_calculators != metric_calculators_.end(); ++iter_calculators ) {
245  iter_calculators->second->notify_sequence_change();
246  }
247  // reset global flag
248  sequence_is_outdated_ = false;
249  return;
250 }
251 */
252 
253 
254 } // metrics
255 } // pose
256 } // core