Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BoltzmannFilter.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 sw=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 /// @author Sarel Fleishman (sarelf@uw.edu)
13 #include <utility/string_util.hh>
14 // AUTO-REMOVED #include <core/pose/Pose.hh>
15 #include <utility/tag/Tag.hh>
17 // AUTO-REMOVED #include <protocols/moves/DataMap.hh>
18 #include <basic/Tracer.hh>
20 #include <boost/foreach.hpp>
21 #define foreach BOOST_FOREACH
22 #include <math.h>
23 
24 #include <utility/vector0.hh>
25 #include <utility/vector1.hh>
26 
27 #include <ObjexxFCL/format.hh>
28 using ObjexxFCL::fmt::F;
29 
30 
31 namespace protocols {
32 namespace protein_interface_design{
33 namespace filters {
34 
35 static basic::Tracer TR( "protocols.protein_interface_design.filters.BoltzmannFilter" );
36 
37 ///@brief default ctor
39  temperature_( 0.6 ),
40  fitness_threshold_( 0.0 ),
41  triage_threshold_( -9999 ),
42  norm_neg_( false )
43 {
44  positive_filters_.clear();
45  negative_filters_.clear();
46  anchors_.clear();
47 }
48 
49 
52  return fitness_threshold_;
53 }
54 
55 void
58 }
59 
62  return temperature_;
63 }
64 
65 void
67  temperature_ = t;
68 }
69 
72  return triage_threshold_;
73 }
74 
75 void
78 }
79 
80 void
81 BoltzmannFilter::norm_neg( bool const n ){
82  norm_neg_ = n;
83 }
84 
85 bool
87  return norm_neg_;
88 }
89 
90 
93  return positive_filters_;
94 }
95 
98  return negative_filters_;
99 }
100 
101 void
103  positive_filters_.push_back( f );
104 }
105 
106 void
108  negative_filters_.push_back( f );
109 }
110 
111 void
113  anchors_ = anchors;
114 }
115 
118  return anchors_;
119 }
120 
121 bool
123 {
124  core::Real const fitness( compute( pose ) );
125  return( fitness <= fitness_threshold() );
126 }
127 
128 /// NOTICE that this returns -Fitness [-1:0] for use in optimization
129 /// F = Sum_{+}( -E/T ) / [ Sum_{-}( -E/T ) + Sum_{+} ( -E/T ) + Sum_{+}(( E - anchor )/T) ]
130 /// This is the standard fitness function, except for anchor. Anchor can be (but doesn't have to be)
131 /// defined for each positive state and sets a threshold above which energy increases in the positive
132 /// state substantially reduce fitness, irrespective of what happened to all negative states.
133 /// Can be used to ensure that the stability of a target state is not compromised during design.
134 /// Set this to a very large number (99999) to eliminate the effects of the anchor, or specify no anchors at all
138 
139  core::Real positive_sum( 0.0 ), negative_sum( 0.0 );
140  core::Size negative_counter( 0 );
141  std::string s = "BOLTZ: ";
142  for( core::Size index = 1; index <= get_positive_filters().size(); ++index ){
143  core::Real const filter_val( get_positive_filters()[ index ]->report_sm( pose ));
144  s += F(7,3,filter_val)+" ";
145  positive_sum += exp( -filter_val / temperature() );
146  if( anchors_.size() >= index ) {
147  negative_sum += exp( ( filter_val - anchors_[ index ] ) / temperature() );
148  }
149  }
150 
151  foreach( FilterCOP filter, get_negative_filters() ) {
152  core::Real filter_val = filter->report_sm( pose );
153  s += F(7,3,filter_val)+" ";
154  if ( filter_val >= triage_threshold() ){
155  negative_sum += exp( -filter_val / temperature() );
156  negative_counter += 1;
157  TR<<"Taken filter: "<<filter->get_user_defined_name()<<" filter val: "<< filter_val<<std::endl;
158  }
159  }
160  TR << s << -positive_sum/(positive_sum+negative_sum) <<std::endl;
161  if ( norm_neg() ){
162  TR<<"Negative counter: "<< negative_counter <<std::endl;
163  // if there are no negative states then set a value that will definitely return fail in compute
164  if( !negative_counter ){
165  TR<<"Normalized fitness: 9999 "<<std::endl;
166  return 9999;
167  }
168  TR<<"Normalized fitness: " << (( -(core::Real)positive_sum / ( positive_sum + negative_sum )) / ((core::Real) get_positive_filters().size()/(get_positive_filters().size()+negative_counter)))<<std::endl;
169  TR<<"Number of positive states: " << get_positive_filters().size() << std::endl;
170  return ( ( -(core::Real)positive_sum / ( positive_sum + negative_sum )) / ((core::Real) get_positive_filters().size()/(get_positive_filters().size()+negative_counter) ) );
171  }
172  TR<<"Fitness: " << ( -(core::Real)positive_sum / ( positive_sum + negative_sum )) << std::endl;
173  return( -(core::Real)positive_sum / ( positive_sum + negative_sum ));
174 }
175 
178 {
179  return( compute( pose ) );
180 }
181 
182 void
183 BoltzmannFilter::report( std::ostream &, core::pose::Pose const & ) const
184 {
185 }
186 
187 void
190  protocols::filters::Filters_map const & filters,
192  core::pose::Pose const & )
193 {
194  TR << "BoltzmannFilter"<<std::endl;
195  runtime_assert( tag->hasOption( "anchors" ) || tag->hasOption( "negative_filters" ) );
196  fitness_threshold( tag->getOption< core::Real >( "fitness_threshold", 0 ) );
197  temperature( tag->getOption< core::Real >( "temperature", 0.6 ) );
198  triage_threshold( tag->getOption< core::Real >( "triage_threshold", -9999 ) );
199  norm_neg( tag->getOption< bool >( "norm_neg", false ) );
200  utility::vector1< std::string > const positive_filter_names( utility::string_split( tag->getOption< std::string >( "positive_filters" ), ',' ) );
201  utility::vector1< std::string > negative_filter_names, anchors_string;
202  negative_filter_names.clear(); anchors_string.clear();
203  if( tag->hasOption( "negative_filters" ) )
204  negative_filter_names = utility::string_split( tag->getOption< std::string >( "negative_filters" ), ',' );
205  if( tag->hasOption( "anchors" ) )
206  anchors_string = utility::string_split( tag->getOption< std::string >( "anchors"), ',' );
207  foreach( std::string const positive_filter_name, positive_filter_names )
208  add_positive_filter( protocols::rosetta_scripts::parse_filter( positive_filter_name, filters ) );
209  foreach( std::string const negative_filter_name, negative_filter_names )
210  add_negative_filter( protocols::rosetta_scripts::parse_filter( negative_filter_name, filters ) );
211  foreach( std::string const anchor_str, anchors_string )
212  anchors_.push_back( (core::Real) utility::string2float( anchor_str ) );
213 
214  TR<<"with options temperature: "<<temperature()<<" triage_threshold "<<triage_threshold()<<" fitness_threshold "<<fitness_threshold()<<" "<<get_positive_filters().size()<<" positive and "<<get_negative_filters().size()<<" negative filters."<<std::endl;
215  if( anchors().size() > 0 ){
216  TR<<"defined "<<anchors().size()<<" anchors"<<std::endl;
217  runtime_assert( get_positive_filters().size() == anchors().size());
218  }
219 }
220 
223  return new BoltzmannFilter();
224 }
225 
227 
230  return new BoltzmannFilter( *this );
231 }
232 
235 
237 BoltzmannFilterCreator::keyname() const { return "Boltzmann"; }
238 
239 } // filters
240 } // protein_interface_design
241 } // protocols