Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PartitionAggregateFunction.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 PartitionAggregateFunction.hh
11 /// @brief
12 /// @author Colin A. Smith
13 
15 
16 // AUTO-REMOVED #include <protocols/multistate_design/MultiStateAggregateFunction.tmpl.hh>
17 
19 // AUTO-REMOVED #include <protocols/multistate_design/MultiStateFitnessFunction.hh>
20 // AUTO-REMOVED #include <protocols/multistate_design/MultiStateFitnessFunction.tmpl.hh>
21 #include <core/types.hh>
22 #include <basic/Tracer.hh>
23 #include <ObjexxFCL/format.hh>
24 
25 // Utility Headers
26 #include <utility/pointer/ReferenceCount.hh>
27 
30 #include <utility/exit.hh>
31 #include <utility/vector1.hh>
32 
33 namespace protocols {
34 namespace multistate_design {
35 
36 static basic::Tracer TR("protocols.multistate_design.PartitionAggregateFunction");
37 
40  temp_(1),
41  anchor_offset_(0),
42  compare_all_to_ground_state_( false )
43 {}
44 
46  core::Real temp,
47  core::Real anchor_offset,
48  bool const compare_to_ground_state
49 ) :
51  temp_(temp),
52  anchor_offset_(anchor_offset),
53  compare_all_to_ground_state_( compare_to_ground_state )
54 {}
55 
57 
60 
63 
64 
65 /// SJF see https://wiki.rosettacommons.org/index.php/IDDocumentation#ProteinInterfaceMS
66 /// for explanations on the parameters
69  utility::vector1<core::Real> const & single_state_fitnesses,
70  MultiStateFitnessFunction & fitness_function
71 ) const
72 {
73  using namespace ObjexxFCL::fmt;
74 
75  utility::vector1<SingleStateCOP> single_states(fitness_function.const_states());
76  runtime_assert(single_state_fitnesses.size() == single_states.size());
77 
78 /// SJF the temperature plays the role of scaling the relative contributions of states' energies to
79 /// fitness. At low temperatures, even mild energy differences between positive and negative states will
80 /// translate to large fitness gains.
81 
82  core::Real const inv_temp( -1.0 / temp_ );
83  core::Real numer(0.), denom(0.);
84 
85  // 'normalize' is just a constant value to subtract from energies of large magnitude, in order to take exponents of
86  // smaller numbers (exact value used should not be important for the calculations)
87  core::Real const normalize( compare_all_to_ground_state_ ? 0 : single_state_fitnesses[ 1 ] );
88  for (core::Size i = 1; i <= single_state_fitnesses.size(); ++i) {
89  /// SJF ground_state_offset changes the energy of each design as used by the fitness function by the value of the best-score energy of the single state. This means that designs will be judged by the differences in energy that they imply relative to the starting 'best-score' design. This is useful if you have multiple (e.g., homologous) pdb files of the starting structures, each with a different starting energy. ground_state_offset overrides normalize and has a different meaning from it.
90  core::Real const ground_state_offset( compare_all_to_ground_state_ ? single_states[ i ]->best_score() : 0 );
91  TR(basic::t_trace) << "State fitness " << F(8,2,single_state_fitnesses[i]);
92  TR(basic::t_trace) << "State ground-state offset " << F(8,2,ground_state_offset);
93  core::Real const exp_term( std::exp( ( single_state_fitnesses[i] - ground_state_offset - normalize ) * inv_temp ) );
94  TR(basic::t_trace) << " exp. term " << F(6,2,exp_term);
95  denom += exp_term;
96  if ( single_states[i]->is_positive_state() ) {
97  TR(basic::t_trace) << " (POSITIVE STATE)";
98  numer += exp_term;
99 /// SJF The affinity anchor is not strictly part of the multi-state design framework. The idea
100 /// is to have some 'memory' of the energy of the best sequence for the target state. If you make large gains
101 /// in
102 /// specificity but the target state's energy is losing in a big way, the anchor_term will make the
103 /// fitness suffer. Intuitively, anchor_offset_ is a way to state what is an acceptable hit in stability,
104 /// beyond which fitness will suffer.
105 /// This is important of course in specificity designs, where large gains in specificity can come at
106 /// a cost to stability. In other scenarios, such as binding, an appropriate anchor_offset_ value might be
107 /// approximately the difference between the positive and negative states. This way, the energy of the
108 /// negative state will make decisive contributions to the fitness.
109  // also add 'affinity anchor(s)' to denominator for each positive state
110  core::Real const anchor_term( std::exp( ( single_states[i]->best_score() - ground_state_offset + anchor_offset_ - normalize ) * inv_temp ) );
111  TR(basic::t_trace) << " anchor exp. term " << F(6,2,anchor_term);
112  denom += anchor_term;
113  }//is positive state
114  TR(basic::t_trace) << std::endl;
115  }//for i
116  TR(basic::t_trace) << "numer " << F(5,2,numer) << " / denom " << F(5,2,denom) << std::endl;
117  // flip sign on the Boltzmann probability for proper ranking elsewhere (more negative is better)
118  core::Real const prob_target( numer/denom );
119  TR(basic::t_debug) << "Boltzmann prob. for target state(s) vs. competitor(s): "
120  << ObjexxFCL::fmt::F(5,2,prob_target) << std::endl;
121 
122  return -1.*prob_target; // in genetic algorithm, better fitnesses are more negative
123 }
124 
125 
126  /*core::Real
127 PartitionAggregateFunction::evaluate(
128  utility::vector1<core::Real> const & single_state_fitnesses,
129  MultiStateFitnessFunction & fitness_function
130 ) const
131 {
132  using namespace ObjexxFCL::fmt;
133 
134  utility::vector1< SingleStateCOP > single_states(fitness_function.const_states());
135  runtime_assert(single_state_fitnesses.size() == single_states.size());
136 
137  core::Real const inv_temp( -1.0 / temp_ );
138  core::Real normalize(0.), numer(0.), denom(0.);
139 
140  for (core::Size i = 1; i <= single_state_fitnesses.size(); ++i) {
141 
142  TR(basic::t_trace) << "State fitness " << F(8,2,single_state_fitnesses[i]);
143  // 'normalize' is just a constant value to subtract from energies of large magnitude, in order to take exponents of
144  // smaller numbers (exact value used should not be important for the calculations)
145  if ( i == 1 ) normalize = single_state_fitnesses[i];
146  core::Real const exp_term( std::exp( ( single_state_fitnesses[i] - normalize ) * inv_temp ) );
147  TR(basic::t_trace) << " exp. term " << F(6,2,exp_term);
148  denom += exp_term;
149  if ( single_states[i]->is_positive_state() ) {
150  TR(basic::t_trace) << " (POSITIVE STATE)";
151  numer += exp_term;
152  // also add 'affinity anchor(s)' to denominator for each positive state
153  core::Real const anchor_term(
154  std::exp( ( single_states[i]->best_score() + anchor_offset_ - normalize ) * inv_temp )
155  );
156  TR(basic::t_trace) << " anchor exp. term " << F(6,2,anchor_term);
157  denom += anchor_term;
158  }
159  TR(basic::t_trace) << std::endl;
160  }
161  TR(basic::t_trace) << "numer " << F(5,2,numer) << " / denom " << F(5,2,denom) << std::endl;
162  // flip sign on the Boltzmann probability for proper ranking elsewhere (more negative is better)
163  core::Real const prob_target( numer/denom );
164  TR(basic::t_debug) << "Boltzmann prob. for target state(s) vs. competitor(s): "
165  << F(5,2,prob_target) << std::endl;
166 
167  return -1.*prob_target; // in genetic algorithm, better fitnesses are more negative
168 }*/
169 
170 } // namespace multistate_design
171 } // namespace protocols