Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Mover.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 Mover.cc
11 /// @brief Method code and full headers for Mover--
12 /// keeps heavily-included Mover.hh small and concise to maximize compiling
13 /// efficiency and to make the class definitions easier to read.
14 /// @author
15 
16 // Unit Headers
17 #include <protocols/moves/Mover.hh>
18 
19 // Package headers
20 // AUTO-REMOVED #include <protocols/moves/MonteCarlo.hh>
21 // AUTO-REMOVED #include <protocols/moves/MoverStatistics.hh>
22 
23 // Project headers
24 #include <core/pose/Pose.hh>
25 // AUTO-REMOVED #include <core/scoring/ScoreFunction.hh>
26 // AUTO-REMOVED #include <utility/tag/Tag.hh> // REQUIRED FOR WINDOWS
27 // AUTO-REMOVED #include <protocols/moves/DataMap.hh>
29 #include <utility/string_util.hh>
30 
31 // tracer
32 #include <basic/Tracer.hh>
33 
35 #include <utility/exit.hh>
36 #include <utility/vector0.hh>
37 #include <utility/vector1.hh>
38 
39 
40 // C++ Headers
41 
42 // ObjexxFCL Headers
43 
44 namespace protocols {
45 namespace moves {
46 
47 
48 #ifdef USELUA
49 void lregister_Mover( lua_State * lstate ) {
50  luabind::module(lstate, "protocols")
51  [
52  luabind::namespace_( "moves" )
53  [
54  luabind::class_<Mover>("Mover")
55  .def("apply", ( void (Mover::*)( core::io::serialization::PipeMap & )) &Mover::apply)
56  .def("apply", ( void (Mover::*)( core::pose::Pose & )) &Mover::apply)
57  .def("parse_state", &Mover::parse_state)
58  .def("save_state", &Mover::save_state)
59  ]
60  ];
61 }
62 
63 void lregister_SerializableState( lua_State * lstate ){
64  luabind::module(lstate, "protocols")
65  [
66  luabind::namespace_( "moves" )
67  [
68  luabind::class_<SerializableState>("SerializableState")
69  .def("set", ( void (*) ( SerializableStateSP, std::string, std::string )) &SerializableState_set )
70  .def("set", ( void (*) ( SerializableStateSP, std::string, core::Real )) &SerializableState_set )
71  .def("get", &SerializableState_get )
72  ]
73  ];
74 }
75 #endif
76 
77 using namespace core;
78  using namespace pose;
79 
80 using basic::T;
81 using basic::Error;
82 using basic::Warning;
83 static basic::Tracer TR("protocols.moves.Mover");
84 
86 :
87  utility::pointer::ReferenceCount(),
88  type_( "MoverBase" ),
89  current_tag_( "NoTag" ),
90  input_pose_(0),
91  native_pose_(0),
92  last_status_( MS_SUCCESS )
93 {}
94 
96 
97 Mover::Mover( std::string const & type_name ) :
98  utility::pointer::ReferenceCount(),
99  type_( type_name ),
100  current_tag_( "NoTag" ),
101  input_pose_(0),
102  native_pose_(0),
103  last_status_( MS_SUCCESS )
104 {}
105 
106 Mover::Mover( Mover const & other ) :
107  utility::pointer::ReferenceCount(),
108  type_( other.type_ ),
109  current_tag_( other.current_tag_ ),
110  input_pose_(other.input_pose_),
111  native_pose_(other.native_pose_),
112  last_status_( other.last_status_ ),
113  current_job_( other.current_job_ )
114 {}
115 
116 
117 ///@brief assignment operator
118 Mover& Mover::operator=( Mover const & rhs ) {
119  //abort self-assignment
120  if (this == &rhs) return *this;
121  type_ = rhs.type_;
123  input_pose_ = rhs.input_pose_;
127  return *this;
128 }
129 
130 PoseCOP
132 
133 void
135 
136 PoseCOP
138 
139 void
141 
142 // Factory<Mover> functions
144  MoverOP a = fresh_instance();
145  MoverSP tmpsp (a.get());
146  a.relinquish_ownership();
147  return tmpsp;
148 }
149 // elscripts functions
151  for( core::io::serialization::Pipe::iterator itr = pmap["input"]->begin(); itr != pmap["input"]->end(); itr++ ) {
152  apply( **itr );
153  }
154 }
155 
156 // called right before mover is used , allowing mover to set settings based on state
157 void Mover::parse_state( SerializableState const & /*state*/ ) {
158  utility_exit_with_message("This Mover has not implemented parse_state()");
159 }
160 // state is not an argument because it doesn't exist at this point
161 void Mover::parse_def( utility::lua::LuaObject const & /*def*/,
162  utility::lua::LuaObject const & /*score_fxns*/,
163  utility::lua::LuaObject const & /*tasks*/,
164  MoverCacheSP /*cache*/ ) {
165  utility_exit_with_message("This Mover has not implemented parse_def()");
166 }
167 
169  utility_exit_with_message("This Mover has not implemented save_state()");
170 }
171 
172 // end mpr support
173 ///@details Some movers need not be parsed, so we shouldn't stop executions. This, however, calls attention to the lack of this method, which could be due to something as silly as a wrong parameters definition.
175  TagPtr const,
176  DataMap &,
177  Filters_map const &,
178  Movers_map const &,
179  Pose const &
180 )
181 {
182  TR << "***WARNING!!!! WARNING!!!*** parse_my_tag has been invoked for this mover but it hasn't been defined. Are you sure this is appropriate?" << std::endl;
183 }
184 
185 void
187 {
188  current_job_ = job;
189 }
190 
191 
194  return current_job_;
195 }
196 
197 
198 ///@details Mechanism by which a mover may return multiple output poses from a single input pose. After apply is called, calling this function will return subsequent output poses. NULL is returned if the mover has no more output poses remaining. The base class implementation returns NULL always; multi-output movers must override this. RosettaScripts uses this interface to produce a 'branched' protocol.
201  return NULL;
202 }
203 
204 //////////////////////////start Job Distributor interface//////////////////////////////////
205 ///@details used by job distributor to get status
207 
208 ///@details The job distributor (august 08 vintage) uses this to ensure non-accumulation of status across apply()s.
210 
211 ///@details use this function for implementing filtering in your protocol - failed jobs should set the status to something other than "SUCCESS".
213 
214 ///@details Movers default to not regenerating
215 bool Mover::reinitialize_for_each_job() const { return false; }
216 
217 ///@details Movers default to not regenerating
218 bool Mover::reinitialize_for_new_input() const { return false; }
219 
220 ///@details fresh_instance is meant to return a new object of this class, created with the default constructor. This really should be a pure virtual in the base class, but adding pure virtuals to Mover would massively disrupt the code. This default implementation crashes at runtime instead of compiletime if you try to call it. If this code is causing you problems, your Mover needs to override this function. This is used by the August 08 job distributor.
222 {
223  utility_exit_with_message("fresh_instance has been called on a Mover which has not overridden the base class implementation. Probably you tried to pass a Mover to the job distributor which does not have fresh_instance implemented. Implement the function and try again.\n");
224  return MoverOP(NULL);
225  //return MoverOP( new Mover ); //this is what your Mover should return - it's illegal here because Mover does not define the pure virtual function apply().
226 }
227 
228 ///@details clone is meant to return an OP'ed deep copy of this object. This really should be a pure virtual in the base class, but adding pure virtuals to Mover would massively disrupt the code. This default implementation crashes at runtime instead of compiletime if you try to call it. If this code is causing you problems, your Mover needs to override this function.
230  utility_exit_with_message( "clone has been called on a Mover which has not overridden the base class implementation. Probably you tried to pass a Mover to the job distributor or parser which does not have clone implemented. Implement the function and try again.\n");
231  return MoverOP(NULL);
232 }
233 
234 std::ostream & operator << ( std::ostream & os, Mover const & mover)
235 {
236  os << "Mover name: " << mover.get_name() << ", Mover type: " << mover.get_type() << ", Mover current tag:" << mover.get_current_tag() << std::endl;
237  return os;
238 }
239 
240 /// serializable set helper functions
242  (*state)[key] = val;
243 }
244 
246  (*state)[key] = utility::to_string(val);
247 }
249  if( state->find( key ) != state->end() ) {
250  return (*state)[key];
251  } else {
252  return "";
253  }
254 }
255 
256 
257 } // moves
258 } // protocols