24 #include <utility/tag/Tag.hh>
25 #include <basic/Tracer.hh>
38 #include <numeric/random/random.hh>
41 #include <boost/foreach.hpp>
43 #include <utility/vector0.hh>
44 #include <utility/excn/Exceptions.hh>
45 #include <utility/vector1.hh>
47 #define foreach BOOST_FOREACH
50 static basic::Tracer
TR(
"protocols.filters.Filter");
51 static numeric::random::RandomGenerator
RG( 140789 );
67 :
Filter(
"Stochastic" ), confidence_( confidence )
77 TR<<
"stochastic filter returning false"<<std::endl;
80 TR<<
"stochastic filter returning true"<<std::endl;
106 TR<<
"stochastic filter with confidence "<<
confidence_<<std::endl;
113 Filter(
"CompoundStatement" ),
119 Filter(
"CompoundStatement" ),
120 compound_statement_( compound_statement ),
127 bool const value(
compute( pose ) );
129 TR<<
"Compound logical statement is "<<value<<
"."<<std::endl;
150 bool confidence(
false );
151 CompoundStatement::const_iterator non_stochastic_filter;
153 if( it->first->get_type() ==
"Stochastic" ) confidence =
true;
154 else non_stochastic_filter = it;
156 if( confidence ) non_stochastic_filter->first->report( out, pose );
158 bool const value(
compute( pose ) );
160 out<<
"Compound filter returns: "<<value<<
'\n';
168 bool confidence(
false );
169 CompoundStatement::const_iterator non_stochastic_filter;
171 if( it->first->get_type() ==
"Stochastic" ) confidence =
true;
172 else non_stochastic_filter = it;
174 if( confidence )
return( non_stochastic_filter->first->report_sm( pose ) );
176 bool const value(
compute( pose ) );
189 value = it->first->apply( pose );
190 if (it->second ==
NOT) value = !value;
191 if (it->second ==
ORNOT) {
192 TR <<
"WARNING: CompoundFilter treating operator ORNOT as NOT" << std::endl;
195 if (it->second ==
ANDNOT) {
196 TR <<
"WARNING: CompoundFilter treating operator ANDNOT as NOT" << std::endl;
200 switch( it->second ) {
201 case (
AND ) : value = value && it->first->apply( pose );
break;
202 case (
OR ) : value = value || it->first->apply( pose );
break;
203 case (
XOR ) : value = value ^ it->first->apply( pose );
break;
204 case (
ORNOT ) : value = value || !it->first->apply( pose );
break;
205 case (
ANDNOT ) : value = value && !it->first->apply( pose );
break;
206 case (
NOR ) : value = !( value || it->first->apply( pose ) );
break;
207 case (
NAND ) : value = !( value && it->first->apply( pose ) );
break;
209 TR <<
"WARNING: CompoundFilter treating operator NOT as ANDNOT" << std::endl;
210 value = value && !it->first->apply( pose );
270 TR<<
"CompoundStatement"<<std::endl;
271 invert_ = tag->getOption<
bool>(
"invert", false );
273 foreach(
TagPtr cmp_tag_ptr, tag->getTags() ){
274 std::string const operation( cmp_tag_ptr->getName() );
275 std::pair< FilterOP, boolean_operations > filter_pair;
276 if( operation ==
"AND" ) filter_pair.second =
AND;
277 else if( operation ==
"OR" ) filter_pair.second =
OR;
278 else if( operation ==
"XOR" ) filter_pair.second =
XOR;
279 else if( operation ==
"NOR" ) filter_pair.second =
NOR;
280 else if( operation ==
"NAND" ) filter_pair.second =
NAND;
281 else if( operation ==
"ORNOT" ) filter_pair.second =
ORNOT;
282 else if( operation ==
"ANDNOT" ) filter_pair.second =
ANDNOT;
283 else if( operation ==
"NOT" ) filter_pair.second =
NOT;
285 throw utility::excn::EXCN_RosettaScriptsOption(
"Error: Boolean operation in tag is undefined." );
289 Filters_map::const_iterator find_filter( filters.find( filter_name ));
290 bool const filter_found( find_filter!=filters.end() );
292 filter_pair.first = find_filter->second->clone();
294 TR<<
"***WARNING WARNING! Filter defined for CompoundStatement not found in filter_list!!!! Defaulting to truefilter***"<<std::endl;
297 runtime_assert( filter_found );
312 TR<<
"CombinedFilter value is "<<value<<
", threshold is "<<
threshold_ <<
"."<<std::endl;
333 out<<
"Combined filter returns: "<<value<<
'\n';
348 value += fw_pair.second * fw_pair.first->report_sm( pose );
363 foreach(
TagPtr tag_ptr, sub_tags){
365 if (tag_ptr->hasOption(
"factor") ) {
366 weight = tag_ptr->getOption<
core::Real>(
"factor" );
367 }
else if (tag_ptr->hasOption(
"temp") ) {
368 weight = 1.0 / tag_ptr->getOption<
core::Real>(
"temp" );
373 Filters_map::const_iterator find_filter( filters.find( filter_name ));
374 bool const filter_found( find_filter!=filters.end() );
376 filter = find_filter->second->clone();
379 TR.Warning<<
"***WARNING WARNING! Filter " << filter_name <<
" defined for CombinedValue not found in filter_list!!!! ***"<<std::endl;
380 throw utility::excn::EXCN_RosettaScriptsOption(
"Filter "+filter_name+
" not found in filter list.");
438 if ( tag->hasOption(
"mover") ) mover_name = tag->getOption<
std::string >(
"mover" );
439 if ( tag->hasOption(
"mover_name") ) mover_name = tag->getOption<
std::string >(
"mover_name" );
440 if ( tag->hasOption(
"filter") ) filter_name = tag->getOption<
std::string >(
"filter" );
441 if ( tag->hasOption(
"filter_name") ) filter_name = tag->getOption<
std::string >(
"filter_name" );
443 moves::Movers_map::const_iterator find_mover ( movers.find( mover_name ));
444 Filters_map::const_iterator find_filter( filters.find( filter_name ));
446 if( find_mover == movers.end() ) {
447 TR.Error <<
"ERROR !! mover '"<<mover_name<<
"' not found in map: \n" << tag << std::endl;
448 runtime_assert( find_mover != movers.end() );
450 if( find_filter == filters.end() ) {
451 TR.Error <<
"ERROR !! filter '"<<filter_name<<
"' not found in map: \n" << tag << std::endl;
452 runtime_assert( find_filter != filters.end() );
457 TR <<
"Setting MoveBeforeFilter for mover '"<<mover_name<<
"' and filter '"<<filter_name<<
"'"<<std::endl;
498 TR<<
"IfThenFilter value is "<<value<<
", threshold is "<<
threshold_;
500 TR <<
" (lower limit)" << std::endl;
503 TR <<
" (upper limit)" << std::endl;
525 out<<
"IfThen filter returns: "<<value<<
'\n';
553 TR.Warning <<
"WARNING: No conditional filters specified for IfThenFilter. Using else values only." << std::endl;
573 if( tag->hasOption(
"lower_threshold" ) && ! tag->hasOption(
"threshold" ) ){
574 TR.Warning <<
"WARNING: In IfThenFilter, lower_threshold set without setting threshold." << std::endl;
575 TR.Warning <<
"WARNING: Note that lower_threshold is a true/false flag, not a real-valued setting." << std::endl;
578 foreach(
TagPtr tag_ptr, sub_tags){
581 if( tag_ptr->hasOption(
"valuefilter") ) {
587 if( tagname ==
"IF" || tagname ==
"ELIF" ){
588 if( ! tag_ptr->hasOption(
"testfilter") ) {
589 TR.Error <<
"In IfThenFilter, If and ELIF require a tesfilter option." << std::endl;
590 throw utility::excn::EXCN_RosettaScriptsOption(
"In IfThenFilter, If and ELIF require a tesfilter option.");
593 bool inverttest = tag_ptr->getOption<
bool >(
"inverttest", false );
594 add_condition( testfilter, valuefilter, value, inverttest, weight );
595 }
else if ( tagname ==
"ELSE" ) {
596 set_else( valuefilter, value, weight );
598 TR.Error <<
"Unknown subtag name in IfThenFilter: " << tagname << std::endl;
599 TR.Error <<
" Acceptable values are: IF ELIF ELSE" << std::endl;
600 throw utility::excn::EXCN_RosettaScriptsOption(
"Unknown subtag name in IfThenFilter: " + tagname );
603 TR <<
"IfThenFilter defined with " <<
iffilters_.size() <<
" conditions and "
604 << (
elsefilter_ ?
"an ":
"no " ) <<
" else filter and a "
605 << (
floor_ ?
"lower " :
"upper " ) <<
"threshold of " <<
threshold_ << std::endl;