Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MoverContainer.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 MoverContainer.cc
11 /// @brief apply functions for classes of type MoverContainer
12 /// @detailed
13 /// @author Monica Berrondo
14 
17 
18 // Rosetta Headers
19 #include <core/pose/Pose.hh>
20 #include <basic/Tracer.hh>
22 
23 // Random number generator
24 #include <numeric/random/random.hh>
25 
26 #include <utility/tag/Tag.hh>
28 #include <protocols/moves/Mover.hh>
29 #include <protocols/moves/util.hh>
30 
31 //
32 #include <string>
33 
34 #include <utility/vector0.hh>
35 #include <utility/vector1.hh>
36 #include <utility/string_util.hh>
37 
38 static basic::Tracer tr("protocols.moves.MoverContainer");
39 
40 
41 namespace protocols {
42 namespace moves {
43 
44 static numeric::random::RandomGenerator RG(114); // <- Mike's Magic number, do not change it (and dont try and use it anywhere else) !!! what a retarded system ... %-|
45 
46 using namespace core;
47 using basic::T;
48 using basic::Error;
49 using basic::Warning;
50 
51 /// @details Invoke clone() on each of the movers that are contained by this MoverContainer
52 /// to create deep copies.
53 MoverContainer::MoverContainer( MoverContainer const & source ) : protocols::moves::Mover()
54 {
55  //remember that movers_ is a vector0
56  movers_.resize( source.movers_.size() );
57  for ( Size ii = 0; ii < source.movers_.size(); ++ii ) {
58  movers_[ ii ] = source.movers_[ ii ]->clone();
59  }
60  weight_ = source.weight_;
61 }
62 
63 void MoverContainer::add_mover( MoverOP mover_in , Real weight_in ) // do we need weights?
64 {
65  movers_.push_back(mover_in);
66  weight_.push_back(weight_in);
67 }
68 
70  return movers_[index]->get_name();
71 }
72 
73 
74 // Sets the input pose for both the container and the contained movers
75 // overriding this method fixes an annoying bug (barak)
76  // TODO: does it make sense to cal this also from add_mover? I think not (barak)
78  this->Mover::set_input_pose( pose );
79  for ( Size i=0; i<movers_.size(); ++i ) {
80  movers_[i]->set_input_pose( pose );
81  }
82 }
83 
84 // Sets the native pose for both the container and the contained movers
85 // overriding this method fixes an annoying bug (barak)
86 // TODO: does it make sense to call this also from add_mover? I think not (barak)
88  this->Mover::set_native_pose( pose );
89  for ( Size i=0; i<movers_.size(); ++i ) {
90  movers_[i]->set_native_pose( pose );
91  }
92 }
93 
95  MoverContainer( source ),
96  use_mover_status_( source.use_mover_status_ )
97 {}
98 
99 MoverOP
101  return new SequenceMover( *this );
102 }
103 
105 {
106 
111 
112  type("");
113  if( use_mover_status_ ){
114 
115  Size i = 0;
116  while( i < movers_.size() ){
117 
118  core::pose::Pose storepose( pose );
119  movers_[i]->apply( pose );
120 
121  MoverStatus ms = movers_[i]->get_last_move_status();
122  set_last_move_status( ms );
123  if( ms == MS_SUCCESS ){
124  type( type()+movers_[i]->type() );
125  i++;
126  }else if( ms == FAIL_RETRY ){
127  tr << "Mover failed. Same mover is performed again. " << std::endl;
128  pose = storepose;
129  }else if( ms == FAIL_DO_NOT_RETRY || ms == FAIL_BAD_INPUT ){
130  tr << "Mover failed. Exit from SequenceMover." << std::endl;
131  break;
132  }
133  }
134 
135  }else{
136  // set the mover status from the last mover applied, but do not act on the mover status
137  for ( Size i=0; i<movers_.size(); ++i ) {
138  movers_[i]->apply( pose );
139  type( type()+movers_[i]->type() );
140  }
141  if ( movers_.size() > 0 ) {
142  set_last_move_status( movers_[movers_.size()-1]->get_last_move_status() );
143  }
144 
145  }
146 }
147 
150  return "SequenceMover";
151 }
152 
153 
154 
156  return "RandomMover";
157 }
158 
160  return mover_name();
161 }
162 
164  return new RandomMover();
165 }
166 
167 
169 {
170  Real weight_sum(0.0);
171  size_t m;
172  for(m=0;m< movers_.size(); m++){
173  weight_sum += weight_[m];
174  }
175  type("");
176  for(Size i=0;i< nmoves_; i++)
177  {
178  // choose a move
179  Real movechoice = RG.uniform()*weight_sum;
180  Real sum=0.0;
181  for(m=0;m< movers_.size(); m++){
182  if(movechoice < sum) break;
183  sum += weight_[m];
184  }
185  m--;
186  // tr.Trace << "choose move " << m+1 << " of " << nr_moves() << std::endl;
187  // apply the chosen move
188  movers_[m]->apply( pose );
189  type( type() + movers_[m]->type());
190  last_proposal_density_ratio_ = movers_[m]->last_proposal_density_ratio();//ek
191  }
192 
193 }
194 
196  MoverContainer( source ),
197  nmoves_( source.nmoves_ ),
198  last_proposal_density_ratio_( source.last_proposal_density_ratio_ )
199 {}
200 
201 MoverOP
203  return new RandomMover( *this );
204 }
205 
208  return "RandomMover";
209 }
210 
211 void
215  protocols::moves::Movers_map const &movers,
216  core::pose::Pose const & ) {
217  using namespace protocols::filters;
218 
219  utility::vector1<std::string> mover_names( utility::string_split( tag->getOption< std::string >("movers"), ',') );
220  utility::vector1<std::string> mover_weights;
221  if (tag->hasOption ("weights"))
222  mover_weights = utility::string_split( tag->getOption< std::string >( "weights" ), ',');
223 
224  // make sure # movers matches # weights
225  runtime_assert( mover_weights.size() == 0 || mover_weights.size() == mover_names.size() );
226 
227  nmoves_ = tag->getOption< core::Size >( "repeats",1 );
228 
229  for (core::Size i=1; i<=mover_names.size(); ++i) {
230  protocols::moves::MoverOP mover = find_mover_or_die(mover_names[i], tag, movers);
231  core::Real weight = (mover_weights.size() == 0)? 1.0 : std::atof( mover_weights[i].c_str() );
232  add_mover( mover, weight );
233  }
234 }
235 
236 
237 
238 //ek added this function must be called AFTER apply
241 }
242 
244  MoverContainer( source ),
245  next_move_( source.next_move_ )
246 {}
247 
248 MoverOP
250  return new CycleMover( *this );
251 }
252 
254 {
255  next_move_ %= movers_.size();
256  movers_[ next_move_ ]->apply(pose);
257  ++next_move_;
258 }
259 
260 
261 //JQX added this to reset the next_move_
263 {
264  next_move_ = 0;
265 }
266 
269  return "CycleMover";
270 }
271 
272 std::ostream &operator<< (std::ostream &os, MoverContainer const &mover)
273 {
274  //moves::operator<<(os, mover);
275  os << "Mover name: " << mover.get_name() << ", Mover type: " << mover.get_type() << ", Mover current tag: " << mover.get_current_tag() << std::endl;
276  os << mover.size() << " movers are contained in the following order:" << std::endl;
277  for ( Size i=0; i<mover.size(); ++i ) {
278  os << " Mover[" << i+1 << "]: " << mover.get_mover(i) << std::endl;
279  }
280 
281  return os;
282 }
283 
284 } // namespace moves
285 } // namespace protocols