Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MultiStateFitnessFunction.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 MultiStateFitnessFunction.tmpl.hh
11 /// @brief
12 /// @author ashworth
13 
14 // Unit headers
16 
19 
20 // AUTO-REMOVED #include <protocols/viewer/viewers.hh>
21 
22 #include <core/pose/Pose.hh>
25 
27 #include <utility/vector1.hh>
28 
29 namespace protocols {
30 namespace multistate_design {
31 
33  : genetic_algorithm::FitnessFunction(),
34  aggregate_function_(NULL),
35  scorefxn_(0),
36  best_fitness_(0.)
37 {}
38 
40 
41 void
42 MultiStateFitnessFunction::add_state( core::pose::Pose const & pose, bool is_positive )
43 {
44  add_state( new SingleState( pose, is_positive ) );
45 }
46 
47 void
49 {
50  states_.push_back( state );
51  // for real-time pose tracking of best trait set vs. positive state pose(s) (graphics)
52  if ( state->is_positive_state() ) {
54  *pose = state->pose();
55 // ja this is annoying during iterative protocols because there is no way(?) to close old viewers
56 // protocols::viewer::add_conformation_viewer( pose->conformation(), "Best fitness" );
57  best_entity_positive_states_.push_back( pose );
58  }
59 }
60 
63 {
64  runtime_assert(aggregate_function_);
65 
66  if ( dynamic_cast< protocols::multistate_design::MultiStateEntity * >( &entity ) ) {
68  static_cast< protocols::multistate_design::MultiStateEntity & >( entity );
69  multi_state_entity.single_state_entity_data().resize(states().size());
70  }
71 
72  utility::vector1<core::Real> single_state_fitnesses(states_.size());
73  for (core::Size i = 1; i <= states_.size(); ++i) {
74  single_state_fitnesses[i] += evaluate(entity, i);
75  }
76 
77  core::Real fitness = aggregate_function_->evaluate(single_state_fitnesses, *this );
78  entity.set_fitness(fitness);
79 
80  if ( fitness < best_fitness_ ) {
81  best_fitness_ = fitness;
82  // real-time pose tracking of best traits vs. positive state pose(s) (graphics)
84  for ( SingleStateOPs::iterator s( states_.begin() ), end( states_.end() ); s != end; ++s ) {
85  if ( (*s)->is_positive_state() ) {
86  **pose = (*s)->pose();
87  ++pose;
88  }
89  }
90  }
91 
92  return fitness;
93 }
94 
97 {
98  core::Real fitness(0.);
99  for ( SingleStateOPs::iterator s( states_.begin() ), end( states_.end() ); s != end; ++s ) {
100  if ( !(*s)->is_positive_state() ) continue;
101  fitness += evaluate( entity, *s );
102  }
103  return fitness;
104 }
105 
106 void
108 {
110 }
111 
114 {
115  return aggregate_function_;
116 }
117 
118 void
120 
123 
124 ///@brief true const (read only) access to states
126 MultiStateFitnessFunction::const_states( bool positive_only /* = false */ ) const
127 {
129  for ( SingleStateOPs::const_iterator s( states_.begin() ), end( states_.end() );
130  s != end; ++s ) {
131  if ( positive_only && !(*s)->is_positive_state() ) continue;
132  const_states.push_back( *s );
133  }
134  return const_states;
135 }
136 
139 
142 {
143  core::Size n(0);
144  for ( SingleStateOPs::const_iterator s( states_.begin() ), end( states_.end() );
145  s != end; ++s ) {
146  if ( (*s)->is_positive_state() != pos_neg ) continue;
147  ++n;
148  }
149  return n;
150 }
151 
152 void
154  std::string const & name,
156 )
157 {
158  metric_value_getters_[name] = metric_value_getter;
159 }
160 
163 
164 std::map< std::string, protocols::toolbox::pose_metric_calculators::MetricValueGetter > const &
166 
167 } // namespace multistate_design
168 } // namespace protocols
169