Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MoverFactory.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/moves/MoverFactory.cc
11 /// @brief
12 /// @author ashworth
13 
15 #include <protocols/moves/Mover.hh>
16 
17 // required for passing to Mover::parse_my_tag
18 // AUTO-REMOVED #include <protocols/moves/DataMap.hh>
19 // AUTO-REMOVED #include <protocols/filters/Filter.hh>
20 
21 #include <utility/exit.hh> // runtime_assert, throw utility::excn::EXCN_RosettaScriptsOption
22 #include <utility/tag/Tag.hh>
23 
24 #include <utility/vector0.hh>
25 #include <utility/vector1.hh>
26 #include <utility/excn/Exceptions.hh>
27 #include <basic/Tracer.hh>
28 
29 namespace protocols {
30 namespace moves {
31 
32 
33 static basic::Tracer TR( "protocols.moves.MoverFactory" );
34 
35 MoverFactory * MoverFactory::instance_( 0 );
36 
37 
39 {
40  forbidden_names_.clear();
41  //the following 5 names are used in the original
42  //LoopMoverFactory
43  forbidden_names_.insert("quick_ccd");
44  forbidden_names_.insert("sdwindow");
45  forbidden_names_.insert("quick_ccd_moves");
46  forbidden_names_.insert("perturb_ccd");
47  forbidden_names_.insert("perturb_kic");
48  //original loop mover names over
49 }
50 
52 
55  if ( ! instance_ ) {
56  MoverFactory * instance_local = new MoverFactory;
57  instance_ = instance_local;
58  }
59  return instance_;
60 }
61 
62 ///@brief add a Mover prototype, using its default type name as the map key
63 void
65 {
66  runtime_assert( creator );
67  std::string const mover_type( creator->keyname() );
68  if ( mover_type == "UNDEFINED NAME" ) {
69  throw utility::excn::EXCN_RosettaScriptsOption("Can't map derived Mover with undefined type name.");
70  }
71  if( forbidden_names_.find( mover_type ) != forbidden_names_.end() ){
72  throw utility::excn::EXCN_RosettaScriptsOption("Name "+mover_type+" is not an allowed mover name, probably because it has historical meaning.");
73  }
74  if ( mover_creator_map_.find( mover_type ) != mover_creator_map_.end() ) {
75  throw utility::excn::EXCN_RosettaScriptsOption("MoverFactory::factory_register already has a mover creator with name \"" + mover_type + "\". Conflicting Mover names" );
76  }
77  mover_creator_map_[ mover_type ] = creator;
78 }
79 
80 
81 ///@brief return new Mover by key lookup in mover_prototype_map_ (new Mover parses Tag if provided)
82 MoverOP
83 MoverFactory::newMover( std::string const & mover_type )
84 {
85  MoverMap::const_iterator iter( mover_creator_map_.find( mover_type ) );
86  if ( iter != mover_creator_map_.end() ) {
87  if ( ! iter->second ) {
88  throw utility::excn::EXCN_RosettaScriptsOption( "Error: MoverCreatorOP prototype for " + mover_type + " is NULL!" );
89  }
90  // use of cloning method would be faithful to pre-initialized prototypes
91  //return iter->second->clone();
92  // fresh_instance prevents propagation of pre-initialized prototypes, which may be safer(?)
93  return iter->second->create_mover();
94  }
95  else {
96  TR<<"Available movers: ";
97  for( MoverMap::const_iterator mover_it = mover_creator_map_.begin(); mover_it != mover_creator_map_.end(); ++mover_it )
98  TR<<mover_it->first<<", ";
99  TR<<std::endl;
100  throw utility::excn::EXCN_RosettaScriptsOption( mover_type + " is not known to the MoverFactory. Was it registered via a MoverRegistrator in one of the init.cc files (devel/init.cc or protocols/init.cc)?" );
101  return NULL;
102  }
103 }
104 
105 ///@brief return new Mover by Tag parsing
106 MoverOP
108  TagPtr const tag,
109  moves::DataMap & data,
110  protocols::filters::Filters_map const & filters,
111  moves::Movers_map const & movers,
112  Pose const & pose )
113 {
114  MoverOP mover( newMover( tag->getName() ) );
115  runtime_assert( mover );
116  mover->parse_my_tag( tag, data, filters, movers, pose );
117  return mover;
118 }
119 
120 } //namespace moves
121 } //namespace protocols