Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RangeFilter.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 protocols/filters/RangeFilter.cc
11 /// @brief
12 /// @detailed
13 /// @author Javier Castellanos (javiercv@uw.edu)
14 
15 // Unit Headers
18 
19 // Project Headers
20 // AUTO-REMOVED #include <basic/database/open.hh>
21 #include <core/types.hh>
22 #include <core/pose/Pose.hh>
23 
24 // Utility headers
25 #include <basic/Tracer.hh>
26 
27 // Parser headers
29 #include <utility/tag/Tag.hh>
30 
31 #include <utility/vector0.hh>
32 #include <utility/excn/Exceptions.hh>
33 #include <utility/vector1.hh>
34 
35 //// C++ headers
36 static basic::Tracer tr("protocols.filters.RangeFilter");
37 
38 namespace protocols {
39 namespace simple_filters {
40 
41 // @brief default constructor
42 RangeFilter::RangeFilter() : protocols::filters::Filter()
43 {}
44 
45 RangeFilter::RangeFilter(Real lower_bound, Real upper_bound, FilterOP const & filter ) : protocols::filters::Filter(),
46  filter_(filter),
47  lower_bound_( lower_bound ),
48  upper_bound_( upper_bound )
49 {}
50 
51 // @brief copy constructor
52 RangeFilter::RangeFilter( RangeFilter const & rval ) : protocols::filters::Filter(),
53  filter_( rval.filter_),
54  lower_bound_( rval.lower_bound_ ),
55  upper_bound_( rval.upper_bound_ )
56 {}
57 
58 
59 /// @brief
60 void
61 RangeFilter::report( std::ostream & out, Pose const & pose ) const
62 {
63  Real value = filter_->apply( pose );
64  out << value << " in range " << lower_bound_ << " - " << upper_bound_ << std::endl;
65 }
66 
67 
68 // @brief returns true if the given pose passes the filter, false otherwise.
69 bool RangeFilter::apply( Pose const & pose ) const
70 {
71  Real value = filter_->report_sm( pose );
72  if( value > lower_bound_ && value < upper_bound_ ){
73  tr << "Successfully filtered: " << value << " in range " << lower_bound_ << " - " << upper_bound_ << std::endl;
74  return true;
75  }else{
76  tr << "Filter failed: value = " << value << " range = "<< lower_bound_ << " - " << upper_bound_ << std::endl;
77  return false;
78  }
79 } // apply_filter
80 
81 /// @brief parse xml
82 void
84  TagPtr const tag,
85  DataMap &,
86  filters::Filters_map const &filters,
87  Movers_map const &,
88  Pose const & )
89 {
90  std::string const filter_name( tag->getOption< std::string >( "filter") );
91  filters::Filters_map::const_iterator filter_it( filters.find( filter_name ) );
92  if( filter_it == filters.end() )
93  throw utility::excn::EXCN_RosettaScriptsOption( "Filter "+filter_name+" not found" );
94  filter_ = filter_it->second;
95 
96  lower_bound_ = tag->getOption<Real>( "lower_bound");
97  upper_bound_ = tag->getOption<Real>( "upper_bound");
98  assert(lower_bound_ < upper_bound_);
99 }
100 
103 
105 RangeFilterCreator::keyname() const { return "Range"; }
106 
107 
108 } // filters
109 } // protocols