Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PartitionAggregateFunction.hh
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 
14 #ifndef INCLUDED_protocols_multistate_design_PartitionAggregateFunction_hh
15 #define INCLUDED_protocols_multistate_design_PartitionAggregateFunction_hh
16 
17 
19 // AUTO-REMOVED #include <protocols/multistate_design/MultiStateFitnessFunction.hh>
20 
21 #include <core/types.hh>
22 // AUTO-REMOVED #include <basic/Tracer.hh>
23 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
24 
25 // Utility Headers
26 #include <utility/pointer/ReferenceCount.hh>
27 
29 #include <utility/vector1.hh>
30 
31 namespace protocols {
32 namespace multistate_design {
33 
34 class PartitionAggregateFunction : public MultiStateAggregateFunction {
35 
36 public:
39 
41  PartitionAggregateFunction(core::Real temp, core::Real anchor_offset, bool const compare_to_ground_state=false);
43 
44  /*
45  PartitionAggregateFunction() : MultiStateAggregateFunction<T>(), temp_(1), anchor_offset_(0), compare_all_to_ground_state_( false ) {}
46  PartitionAggregateFunction(core::Real const temp, core::Real const anchor_offset, bool const compare_to_ground_state = false ) :
47  MultiStateAggregateFunction<T>(), temp_(temp), anchor_offset_(anchor_offset), compare_all_to_ground_state_( compare_to_ground_state ) {}
48 */
49 
50  virtual core::Real temp() const;
51  virtual void set_temp( core::Real temp );
52 
53  virtual core::Real anchor_offset() const;
54  virtual void set_anchor_offset( core::Real offset );
55 
56  virtual
58  evaluate(
59  utility::vector1<core::Real> const & single_state_fitnesses,
60  MultiStateFitnessFunction & fitness_function
61  ) const;
62 
63 private:
66 
67  // if states are based on different starting structures, their ground states are different.
68  // in this case, the energies are taken as differences from the ground state.
69  bool const compare_all_to_ground_state_; // const to make sure that it doesn't change during a run
70 };
71 
72  /*
73 
74 /// SJF see https://wiki.rosettacommons.org/index.php/IDDocumentation#ProteinInterfaceMS
75 /// for explanations on the parameters
76 template <typename T>
77 core::Real
78 PartitionAggregateFunction<T>::evaluate(
79  utility::vector1<core::Real> const & single_state_fitnesses,
80  MultiStateFitnessFunction<T> & fitness_function
81 ) const
82 {
83  using namespace ObjexxFCL::fmt;
84 
85  utility::vector1<SingleStateCOP> single_states(fitness_function.const_states());
86  runtime_assert(single_state_fitnesses.size() == single_states.size());
87 
88 /// SJF the temperature plays the role of scaling the relative contributions of states' energies to
89 /// fitness. At low temperatures, even mild energy differences between positive and negative states will
90 /// translate to large fitness gains.
91 
92  core::Real const inv_temp( -1.0 / temp_ );
93  core::Real numer(0.), denom(0.);
94 
95  // 'normalize' is just a constant value to subtract from energies of large magnitude, in order to take exponents of
96  // smaller numbers (exact value used should not be important for the calculations)
97  core::Real const normalize( compare_all_to_ground_state_ ? 0 : single_state_fitnesses[ 1 ] );
98  for (core::Size i = 1; i <= single_state_fitnesses.size(); ++i) {
99 /// 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.
100  core::Real const ground_state_offset( compare_all_to_ground_state_ ? single_states[ i ]->best_score() : 0 );
101  TR(basic::t_trace) << "State fitness " << F(8,2,single_state_fitnesses[i]);
102  TR(basic::t_trace) << "State ground-state offset " << F(8,2,ground_state_offset);
103  core::Real const exp_term( std::exp( ( single_state_fitnesses[i] - ground_state_offset - normalize ) * inv_temp ) );
104  TR(basic::t_trace) << " exp. term " << F(6,2,exp_term);
105  denom += exp_term;
106  if ( single_states[i]->is_positive_state() ) {
107  TR(basic::t_trace) << " (POSITIVE STATE)";
108  numer += exp_term;
109 /// SJF The affinity anchor is not strictly part of the multi-state design framework. The idea
110 /// is to have some 'memory' of the energy of the best sequence for the target state. If you make large gains
111 /// in
112 /// specificity but the target state's energy is losing in a big way, the anchor_term will make the
113 /// fitness suffer. Intuitively, anchor_offset_ is a way to state what is an acceptable hit in stability,
114 /// beyond which fitness will suffer.
115 /// This is important of course in specificity designs, where large gains in specificity can come at
116 /// a cost to stability. In other scenarios, such as binding, an appropriate anchor_offset_ value might be
117 /// approximately the difference between the positive and negative states. This way, the energy of the
118 /// negative state will make decisive contributions to the fitness.
119  // also add 'affinity anchor(s)' to denominator for each positive state
120  core::Real const anchor_term( std::exp( ( single_states[i]->best_score() - ground_state_offset + anchor_offset_ - normalize ) * inv_temp ) );
121  TR(basic::t_trace) << " anchor exp. term " << F(6,2,anchor_term);
122  denom += anchor_term;
123  }//is positive state
124  TR(basic::t_trace) << std::endl;
125  }//for i
126  TR(basic::t_trace) << "numer " << F(5,2,numer) << " / denom " << F(5,2,denom) << std::endl;
127  // flip sign on the Boltzmann probability for proper ranking elsewhere (more negative is better)
128  core::Real const prob_target( numer/denom );
129  TR(basic::t_debug) << "Boltzmann prob. for target state(s) vs. competitor(s): "
130  << ObjexxFCL::fmt::F(5,2,prob_target) << std::endl;
131 
132  return -1.*prob_target; // in genetic algorithm, better fitnesses are more negative
133 }
134 
135 template <typename T>
136 basic::Tracer
137 PartitionAggregateFunction<T>::TR("protocols.multistate_design.PartitionAggregateFunction");
138 */
139 
140 } // namespace multistate_design
141 } // namespace protocols
142 
143 #endif