Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FilterFactory.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/FilterFactory.cc
11 /// @brief
12 /// @author ashworth
13 
16 
17 // Package headers
19 #include <basic/Tracer.hh>
20 #include <utility/exit.hh> // runtime_assert, utility_exit_with_message
21 #include <utility/tag/Tag.hh>
22 
23 #include <utility/vector0.hh>
24 #include <utility/vector1.hh>
25 
26 
27 namespace protocols {
28 namespace filters {
29 
30 
31 static basic::Tracer TR( "protocols.filters.FilterFactory" );
32 
33 FilterFactory * FilterFactory::instance_( 0 );
34 
35 
37 {}
38 
40 
43  if ( ! instance_ ) {
44  FilterFactory * instance_local = new FilterFactory;
45  instance_ = instance_local;
46  }
47  return instance_;
48 }
49 
50 ///@brief add a Filter prototype, using its default type name as the map key
51 void
53 {
54  runtime_assert( creator );
55  std::string const filter_type( creator->keyname() );
56  if ( filter_type == "UNDEFINED NAME" ) {
57  utility_exit_with_message("Can't map derived Filter with undefined type name.");
58  }
59  if ( filter_creator_map_.find( filter_type ) != filter_creator_map_.end() ) {
60  utility_exit_with_message("FilterFactory::factory_register already has a filter creator with name \"" + filter_type + "\". Conflicting Filter names" );
61  }
62  filter_creator_map_[ filter_type ] = creator;
63 }
64 
65 
66 ///@brief return new Filter by key lookup in filter_prototype_map_ (new Filter parses Tag if provided)
68 FilterFactory::newFilter( std::string const & filter_type )
69 {
70  FilterMap::const_iterator iter( filter_creator_map_.find( filter_type ) );
71  if ( iter != filter_creator_map_.end() ) {
72  if ( ! iter->second ) {
73  utility_exit_with_message( "Error: FilterCreatorOP prototype for " + filter_type + " is NULL!" );
74  }
75  // use of cloning method would be faithful to pre-initialized prototypes
76  //return iter->second->clone();
77  // fresh_instance prevents propagation of pre-initialized prototypes, which may be safer(?)
78  return iter->second->create_filter();
79  } else {
80  TR<<"Available filters: ";
81  for( FilterMap::const_iterator filt_it = filter_creator_map_.begin(); filt_it != filter_creator_map_.end(); ++filt_it )
82  TR<<filt_it->first<<", ";
83  TR<<std::endl;
84  utility_exit_with_message( filter_type + " is not known to the FilterFactory. Was it registered via a FilterRegistrator in one of the init.cc files (devel/init.cc or protocols/init.cc)?" );
85  return NULL;
86  }
87 }
88 
89 ///@brief return new Filter by Tag parsing
90 /*FilterOP
91 FilterFactory::newFilter(
92  TagPtr const tag,
93  moves::DataMap & data,
94  Filters_map const & filters,
95  moves::Movers_map const & movers,
96  Pose const & pose )
97 {
98  FilterOP filter( newFilter( tag->getName() ) );
99  runtime_assert( filter );
100  filter->parse_my_tag( tag, data, filters, movers, pose );
101  return filter;
102  }*/
103 
104  ///@brief return new Filter by Tag parsing
105 FilterOP
107  TagPtr const tag,
108  moves::DataMap & data,
109  filters::Filters_map const & filters,
110  moves::Movers_map const & movers,
111  core::pose::Pose const & pose )
112 {
113  FilterOP filter( newFilter( tag->getName() ) );
114  runtime_assert( filter );
115  if ( ! tag->hasOption("name") )
116  utility_exit_with_message("Can't define unnamed Filter");
117  filter->set_user_defined_name( tag->getOption<std::string>("name") );
118  filter->parse_my_tag( tag, data, filters, movers, pose );
119  // if confidence specified, link to StochasticFilter and wrap inside CompoundFilter
120  core::Real const confidence( tag->getOption< core::Real >( "confidence", 1.0 ) );
121  if ( confidence < 0.999 ) { // fuzzy logic
122  CompoundFilter::CompoundStatement fuzzy_statement;
123  FilterCOP stochastic_filter( new StochasticFilter( confidence ) );
124  fuzzy_statement.push_back( std::make_pair( stochastic_filter->clone(), OR ) );
125  fuzzy_statement.push_back( std::make_pair( filter->clone(), OR ) );
126  FilterOP compound_filter( new CompoundFilter( fuzzy_statement ) );
127  compound_filter->set_user_defined_name( tag->getOption<std::string>("name") );
128  return compound_filter;
129  }
130  return filter;
131 }
132 
133 
134 } //namespace filters
135 } //namespace protocols