Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MetropolisHastingsMover.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/canonical_sampling/MetropolisHastingsMover.cc
11 /// @brief MetropolisHastingsMover methods implemented
12 /// @author
13 
14 
15 // Unit Headers
18 
19 
20 // protocols headers
24 #include <protocols/jd2/Job.hh>
25 #include <protocols/jd2/util.hh>
28 #include <protocols/loops/Loop.hh>
30 #include <protocols/moves/Mover.hh>
41 
43 
44 // core headers
46 #include <basic/options/keys/in.OptionKeys.gen.hh>
47 #include <basic/options/keys/packing.OptionKeys.gen.hh>
51 #include <core/types.hh>
52 #include <core/pose/util.hh>
56 #include <basic/Tracer.hh>
57 
58 // numeric headers
59 #include <numeric/random/random.hh>
60 
61 // utility headers
62 #include <utility/file/file_sys_util.hh>
63 #include <utility/io/ozstream.hh>
64 #include <utility/io/izstream.hh>
65 #include <utility/pointer/owning_ptr.hh>
66 #include <utility/tag/Tag.hh>
67 
69 #include <utility/vector0.hh>
70 #include <utility/vector1.hh>
71 
72 #include <ObjexxFCL/format.hh>
73 
74 //Auto Headers
75 #include <utility/excn/Exceptions.hh>
76 #include <basic/options/option.hh>
77 #include <basic/options/keys/run.OptionKeys.gen.hh>
78 
79 // C++ Headers
80 #include <vector>
81 
82 using basic::T;
83 using basic::Error;
84 using basic::Warning;
85 
86 static THREAD_LOCAL basic::Tracer tr( "protocols.canonical_sampling.MetropolisHastingsMover" );
87 
88 namespace protocols {
89 namespace canonical_sampling {
90 
94 }
95 
99 }
100 
103  return "MetropolisHastings";
104 }
105 
107  monte_carlo_(/*0*/),
108  ntrials_(1000),
109  checkpoint_count_(0)
110 {
111  using namespace basic::options;
112  using namespace basic::options::OptionKeys;
113  if ( option[ run::checkpoint_interval ].user() ) {
114  protocols::checkpoint::checkpoint_with_interval( option[ run::checkpoint_interval ] );
115  job_outputter_ = jd2::SilentFileJobOutputterOP( new jd2::SilentFileJobOutputter() ); // only required when writing out checkpoints
116  }
117 }
118 
120  MetropolisHastingsMover const & metropolis_hastings_mover
121 ) :
122  //utility::pointer::ReferenceCount(),
123  Mover(metropolis_hastings_mover),
124  monte_carlo_( metropolis_hastings_mover.monte_carlo_->clone() ),
125  ntrials_(metropolis_hastings_mover.ntrials_),
126  output_name_(metropolis_hastings_mover.output_name_),
127  weighted_sampler_(metropolis_hastings_mover.weighted_sampler_),
128  job_outputter_(metropolis_hastings_mover.job_outputter_),
129  checkpoint_count_(metropolis_hastings_mover.checkpoint_count_)
130 {
131  for ( core::Size i = 1; i <= metropolis_hastings_mover.movers_.size(); ++i ) {
132  movers_.push_back(utility::pointer::dynamic_pointer_cast<ThermodynamicMover>(metropolis_hastings_mover.movers_[i]));
133  }
134 
135  for ( core::Size i = 1; i <= metropolis_hastings_mover.observers_.size(); ++i ) {
136  observers_.push_back(utility::pointer::dynamic_pointer_cast<ThermodynamicObserver>(metropolis_hastings_mover.observers_[i]));
137  }
138 
139  if ( metropolis_hastings_mover.tempering_ ) {
140  tempering_ = utility::pointer::dynamic_pointer_cast<TemperatureController>(metropolis_hastings_mover.tempering_);
141  if ( monte_carlo_ ) tempering_->set_monte_carlo(monte_carlo_);
142  }
143 
144 }
145 
147 
148 /// @details The return value indicates the number of cycles that have already
149 /// been run, if the simulation is not being started or restarted. I'm not
150 /// totally sure what this means though, and I couldn't see any way for this
151 /// function to return anything other than 0. The necessary logic might be
152 /// commented out right now.
155  if ( output_name() == "" ) {
157  tr.Info << " obtained output name from JobDistributor " << std::endl;
159  } else {
160  tr.Info << " running with preset output name: " << output_name() << std::endl;
161  }
162 
163  if ( !tempering_ ) {
164  //get this done before "initialize_simulation" is called no movers and observers
165  tr.Info << "no temperature controller in MetropolisHastings defined... generating FixedTemperatureController" << std::endl;
167  tempering_->set_monte_carlo( monte_carlo_ ); // MonteCarlo required for tempering_->observe_after_metropolis();
168  }
169  using namespace core;
170  bool restart = false;
171  core::Size cycle_number = 0;
172  Size temp_level = 0;
173  Real temperature = -1.0;
174  // for (core::Size i = 1; i <= observers_.size() && !restart; ++i) {
175  // tr.Info<< "Attempting restart using " << observers_[i]->get_name() << std::endl;
176  // restart = observers_[i]->restart_simulation(pose, *this, cycle_number, temp_level, temperature );
177  // if ( restart ) tr.Info<< "Restarted using " << observers_[i]->get_name() << std::endl;
178  // }
179 
180  if ( get_checkpoints() ) {
181  for ( core::Size i = 1; i <= observers_.size() && !restart; ++i ) {
182  if ( utility::pointer::dynamic_pointer_cast< TrajectoryRecorder >( observers_[i] ) ) { // first get the silent struct and cycle info
183  tr.Info<< "Attempting restart using " << observers_[i]->get_name() << std::endl;
184  restart = observers_[i]->restart_simulation(pose, *this, cycle_number, temp_level, temperature );
185  if ( restart ) tr.Info<< "Restarted using " << observers_[i]->get_name() << " cycle_number " << cycle_number << " temp_level " << temp_level << std::endl;
186  }
187  }
188 
189  for ( core::Size i = 1; i <= observers_.size() && restart; ++i ) { // if restart-able from silent trajectory file, collect BiasEnergy info
190  BiasEnergyOP bias_energy( utility::pointer::dynamic_pointer_cast< BiasEnergy >( observers_[i] ));
191  if ( bias_energy ) {
192  tr.Debug << "bias energy used " << std::endl;
193  restart = bias_energy->restart_simulation( pose, *this, cycle_number, temp_level, temperature );
194  if ( restart ) {
195  tr.Info << "grid info collected, restart now!" << std::endl;
196  } else {
197  tr.Info << "failed collecting grid info, restart failed!" << std::endl;
198  }
199  }
200  }
201  }
202 
203  if ( !restart ) {
204  cycle_number = 0; //make sure this is zero if we don't have a restart.
205  tempering_->initialize_simulation(pose, *this, cycle_number );
206  } else {
207  tempering_->initialize_simulation(pose, *this, temp_level, temperature, cycle_number );
208  }
209 
210  for ( core::Size i = 1; i <= movers_.size(); ++i ) {
211  tr.Info << "Initializing " << movers_[i]->get_name() << std::endl;
212  movers_[i]->set_metropolis_hastings_mover(
213  MetropolisHastingsMoverAP( utility::pointer::static_pointer_cast< MetropolisHastingsMover >( get_self_ptr() ) )
214  );
215  movers_[i]->initialize_simulation(pose, *this, cycle_number);
216  }
217 
218  runtime_assert( monte_carlo_ != 0 );
219  monte_carlo_->reset(pose);
220  monte_carlo_->reset_counters();
221 
222  for ( core::Size i = 1; i <= observers_.size(); ++i ) {
223  tr.Info << "Initializing " << observers_[i]->get_name() << std::endl;
224  observers_[i]->initialize_simulation(pose, *this, cycle_number);
225  }
226 
227  tr.Info << "Initial Score:\n";
228  monte_carlo_->score_function().show(tr, pose);
229 
230  tr.Info << "Running " << ntrials_-cycle_number << " trials..." << std::endl;
231  return cycle_number;
232 }
233 
234 void
237 
238  Size start_cycle = prepare_simulation( pose );
239 
240  for ( current_trial_ = start_cycle+1; !tempering_->finished_simulation( current_trial_, ntrials() ); ++current_trial_ ) {
241  write_checkpoint( pose );
243  mover->apply(pose);
244  bool accepted = monte_carlo_->boltzmann(
245  pose,
246  mover->type(),
247  mover->last_proposal_density_ratio(),
248  mover->last_inner_score_delta_over_temperature()
249  );
250  set_last_move( mover );
251  set_last_accepted( accepted );
252  tempering_->temperature_move( pose );
253  mover->observe_after_metropolis(*this);
254  tr.Trace << "current move accepted " << accepted <<std::endl;
255  for ( core::Size i = 1; i <= observers_.size(); ++i ) {
256  observers_[i]->observe_after_metropolis(*this);
257  }
258  //currently used to write tempering stats every so often...
259  tempering_->observe_after_metropolis(*this);
260  }
261  wind_down_simulation( pose );
262 }
263 
264 void
266  using namespace ObjexxFCL;
267  using namespace protocols::checkpoint;
268 
269  if ( !Timer::is_on() ) return;
270  if ( !Timer::time_to_checkpoint() ) return;
271 
273 
274  std::ostringstream checkpoint_id;
275  // checkpoint_id << jd2::current_output_filename(); // decoys.out
277  checkpoint_id << jd2_filename.base(); // decoys
278  checkpoint_id << "_" << jd2::current_output_name(); // protAB_0001
279  checkpoint_id << "_" << jd2::current_replica(); // rep
280  checkpoint_id << "_" << checkpoint_count_;
281 
282  checkpoint_ids_.push_back( checkpoint_id.str() ); // decoys_protAB_0001_1_n
283  utility::io::ozstream out( checkpoint_id.str()+".out");
284  // std::string const & checkpoint_id( jd2::current_output_name() + "_" + string_of( jd2::current_replica() ) + "_" + string_of( checkpoint_count_ ) ); // protAB_0001_3_N
285  // utility::file::FileName jd2_filename( jd2::current_output_filename() );
286  // checkpoint_ids_.push_back( jd2_filename.base()+"_"+checkpoint_id );
287  // tr.Debug << "checkpoint_id: " << checkpoint_id << std::endl; // "decoys_protAB_0001_3_n"
288  // core::pose::Pose tmp_pose( pose );
289 
291  std::ostringstream tag;
292  tag << jd2::current_output_name();
293  tag << "_" << std::setfill('0') << std::setw(3) << jd2::current_replica();
294  tag << "_" << std::setfill('0') << std::setw(8) << current_trial_;
295 
296  pss->fill_struct( pose, tag.str() );
297 
298  BiasedMonteCarloOP biased_mc = utility::pointer::dynamic_pointer_cast< protocols::canonical_sampling::BiasedMonteCarlo > ( monte_carlo_ );
299  if ( biased_mc ) { // if BiasedMonteCarlo, write out bias grid info
300  std::string str="";
301  biased_mc->bias_energy()->write_to_string( str );
302  // core::pose::Pose tmp_pose( pose );
303  // core::pose::add_comment( tmp_pose, "BIASENERGY", str );
304  pss->add_comment("BIASENERGY", str);
305  }
306  // write out snapshots for the replica, with joboutputter, the comment in pose will be not outputted
307  // job_outputter_->other_pose( jd2::get_current_job(), tmp_pose, checkpoint_id, current_trial_, false );
308 
310  pss->print_header( out );
311  pss->print_scores( out );
312  pss->print_conformation( out );
313 
314  Timer::reset();
315  // tr.Debug << "have done writing checkpoint " << checkpoint_ids_.back() << std::endl;
316 
317  /// maintain 5 snapshots for each replica, delete the rest
318  if ( checkpoint_ids_.size() > 5 ) { ///keep 5 snapshots for each replica
319  // tr.Debug << "deleting old checkpoints, only keep the last 5... " << std::endl;
320  utility::file::file_delete( checkpoint_ids_.front()+".out" );
321  checkpoint_ids_.erase( checkpoint_ids_.begin() ); ///each time delete one
322  }
323 }
324 
325 bool
327  using namespace utility::file;
328 
330  std::string filename_base( jd2_filename.base()+"_"+jd2::current_output_name() );
331  std::string filename_pattern( filename_base+"_"+ObjexxFCL::string_of( jd2::current_replica()) +"_"); // current_replica()=0 for FixedTemp
332 
333  utility::vector1< std::string > names;
334  std::vector< int > checkpoint_indics;
335  utility::file::list_dir( ".", names );
336  for ( core::Size i=1; i<=names.size(); ++i ) {
337  if ( names[i].find( filename_pattern ) != std::string::npos ) {
338  FileName found_name( names[i] );
339  core::Size ind = found_name.base().find_last_of('_');
340  checkpoint_indics.push_back( utility::string2int( found_name.base().substr(ind+1) ) );
341  }
342  }
343  tr.Debug << "found " << checkpoint_indics.size() << " checkpoints" << std::endl;
344  if ( checkpoint_indics.size()==0 ) return false; // no checkpoint found
345  std::sort( checkpoint_indics.begin(), checkpoint_indics.end() ); // sort by checkpoint index
346 
347  // starting from the last checkpoint, if all temp_levels are collected, then return
348  std::vector< int >::reverse_iterator rit = checkpoint_indics.rbegin();
349  for ( ; rit != checkpoint_indics.rend(); ++rit ) {
350  tr.Debug << "checkpoint_indics: " << *rit << std::endl;
351 
352  if ( tempering_->n_temp_levels() == 1 ) { // FixedTemperatureController
353  core::io::silent::SilentFileData sfd( filename_base+"_"+ObjexxFCL::string_of( 0 )+"_"+ObjexxFCL::string_of( *rit )+".out");
354  if ( utility::file::file_exists( sfd.filename() ) && utility::file::file_size( sfd.filename() ) ) {
355  checkpoint_ids_.push_back( filename_pattern + ObjexxFCL::string_of( *rit ) );
356  checkpoint_count_ = *rit;
357 
358  // delete any checkpoint file before the successfully collected checkpoint
359  std::vector< int >::reverse_iterator d_rit = ++rit;
360  for ( ; d_rit != checkpoint_indics.rend(); ++d_rit ) utility::file::file_delete( filename_pattern+ObjexxFCL::string_of( *d_rit )+".out" );
361  tr.Debug << "checkpoint for restart: " << checkpoint_ids_.front() << std::endl;
362  return true;
363  } else continue;
364 
365  } else { // replica exchange
366 
367  utility::vector1< core::Size > found_levels;
368  // collect all the temp_levels from the file of this checkpoint
369  for ( core::Size replica=1; replica <= tempering_->n_temp_levels(); ++replica ) {
370  core::io::silent::SilentFileData sfd( filename_base+"_"+ObjexxFCL::string_of( replica )+"_"+ObjexxFCL::string_of( *rit )+".out");
371  if ( utility::file::file_exists( sfd.filename() ) ) {
372  sfd.read_file( sfd.filename() );
373  found_levels.push_back( sfd.begin()->get_energy( "temp_level" ));
374  } else break;
375  }
376  // check if any temp_level is missing, if not, then return.
377  for ( core::Size replica=1; replica <= tempering_->n_temp_levels(); ++replica ) {
378  if ( !found_levels.has_value( replica ) ) { // certain level missing
379  tr.Debug << "temp_level: " << replica << " is missing" << std::endl;
380  break;
381  }
382  if ( replica == tempering_->n_temp_levels() ) {
383  checkpoint_ids_.push_back( filename_pattern + ObjexxFCL::string_of( *rit ) );
384  checkpoint_count_ = *rit;
385  // delete any checkpoint file before the successfully collected checkpoint
386  std::vector< int >::reverse_iterator d_rit = ++rit;
387  for ( ; d_rit != checkpoint_indics.rend(); ++d_rit ) utility::file::file_delete( filename_pattern+ObjexxFCL::string_of( *d_rit )+".out" );
388  tr.Debug << "checkpoint for restart: " << checkpoint_ids_.front() << std::endl;
389  return true;
390  }
391  }
392  }
393  }
394  std::cout << "complete restart info not collected from checkpoint, start from the begining..." << std::endl;
395  return false; // if runs to here, then not found for sure;
396 }
397 
400  if ( checkpoint_ids_.size()==0 ) {
401  return "";
402  }
403  return checkpoint_ids_.back();
404 }
405 
406 void
408  for ( core::Size i = 1; i <= movers_.size(); ++i ) {
409  tr.Info << "Finalizing " << movers_[i]->get_name() << std::endl;
410  movers_[i]->finalize_simulation(pose, *this);
411  }
412 
413  for ( core::Size i = 1; i <= observers_.size(); ++i ) {
414  tr.Info << "Finalizing " << observers_[i]->get_name() << std::endl;
415  observers_[i]->finalize_simulation(pose, *this);
416  }
417 
418  tempering_->finalize_simulation(pose, *this);
419 
420  tr.Debug << "Final Score:" << std::endl;
421  monte_carlo_->score_function().show(tr.Debug, pose);
422  tr.Debug << std::endl;
423 
424  monte_carlo_->show_counters();
425 
427 }
428 
431 {
432  return "MetropolisHastingsMover";
433 }
434 
437 {
439 }
440 
443 {
445 }
446 
447 bool
449 
450 bool
452 
453 void
456  basic::datacache::DataMap & data,
457  protocols::filters::Filters_map const & filters,
458  protocols::moves::Movers_map const & movers,
459  core::pose::Pose const & pose
460 ) {
461  ///ntrials
462  ntrials_ = tag->getOption< core::Size >( "trials", ntrials_ );
463 
464  ///checkpoint interval
465  if ( tag->hasOption("checkpoint_interval") ) {
466  core::Size const checkpoint_interval( tag->getOption< core::Size >( "checkpoint_interval")); // every 6 minutes
469  }
470 
471  //monte-carlo
472  //read tag scorefxn
474  core::Real const temperature(tag->getOption< core::Real >( "temperature", 0.6 ) );
475 
476  bool wte_sampling( tag->getOption< bool >( "wte", false ) );
477  if ( wte_sampling ) {
478  BiasEnergyOP bias_energy( new WTEBiasEnergy() ); // stride, omega, gamma );
479  bias_energy->parse_my_tag( tag, data, filters, movers, pose );
480  add_observer( bias_energy );
481  monte_carlo_ = protocols::moves::MonteCarloOP( new BiasedMonteCarlo( *score_fxn, temperature, bias_energy ) );
482  } else {
484  }
485 
486  //add movers and observers
487  utility::vector0< utility::tag::TagCOP > const subtags( tag->getTags() );
488  for ( utility::vector0< utility::tag::TagCOP >::const_iterator subtag_it = subtags.begin(); subtag_it != subtags.end(); ++subtag_it ) {
489  TagCOP const subtag = *subtag_it;
491  if ( subtag->getName() == "Add" ) { //add existing mover
492  std::string mover_name = subtag->getOption<std::string>( "mover_name", "null" );
493  protocols::moves::Movers_map::const_iterator mover_iter( movers.find( mover_name ) );
494  if ( mover_iter == movers.end() ) {
495  tr.Error<< "Mover not found for XML tag:\n" << subtag << std::endl;
497  }
498  mover = mover_iter->second;
499  } else { //generate new mover
501  mover = mover_factory->newMover(subtag, data, filters, movers, pose);
502  }
503 
504  ThermodynamicMoverOP th_mover( utility::pointer::dynamic_pointer_cast< protocols::canonical_sampling::ThermodynamicMover > ( mover ) );
505  ThermodynamicObserverOP th_observer( utility::pointer::dynamic_pointer_cast< protocols::canonical_sampling::ThermodynamicObserver > ( mover ) );
506  TemperatureControllerOP temp_controller( utility::pointer::dynamic_pointer_cast< protocols::canonical_sampling::TemperatureController > ( mover ) );
507  //figure out if ThermodynamicMover or ThermodynamicObserver
508  if ( th_mover ) { //its a mover
509  core::Real const weight( subtag->getOption< core::Real >( "sampling_weight", 1 ) );
510  add_mover( th_mover, weight, subtag );
511  // add_mover( th_mover, weight );
512  } else if ( th_observer ) { //its an observer
513  //it might also be a tempering module...
514  if ( temp_controller ) { // it is a temperature controller
515  if ( tempering_ ) {
516  throw utility::excn::EXCN_RosettaScriptsOption( "cannot define two TemperatureControllers" );
517  }
518  set_tempering( temp_controller );
519  } else { //no just an plain old observer
520  add_observer( th_observer );
521  }
522  } else { //its something different
523  tr.Error<< "Mover is not a ThermodynamicMover or ThermodynamicObserver for XML tag:\n" << subtag << std::endl;
525  }
526  }
527 }
528 
531  return monte_carlo_;
532 }
533 
535  return *monte_carlo_;
536 }
537 
538 void
541 )
542 {
544  if ( tempering_ ) tempering_->set_monte_carlo( monte_carlo_ );
545 }
546 
547 void
550 ) {
552  if ( monte_carlo_ ) tempering_->set_monte_carlo( monte_carlo_ );
553 }
554 
557  return tempering_;
558 }
559 
560 void
563 ) {
564  ntrials_ = ntrials;
565 }
566 
567 std::string const &
569  return output_name_;
570 }
571 
572 void
574  std::string const & output_name
575 ) {
577 }
578 
581  std::string const & suffix,
582  bool cumulate_jobs, //= false
583  bool cumulate_replicas //= false
584 ) const {
585 
586  if ( cumulate_jobs || cumulate_replicas ) runtime_assert(utility::io::ozstream::MPI_reroute_rank() >= 0);
587 
588  std::ostringstream file_name_stream;
589 
590  if ( !cumulate_jobs ) {
591  file_name_stream << output_name_;
592  }
593 
594  core::Size const replica( protocols::jd2::current_replica() );
595  if ( !cumulate_replicas && replica ) {
596  if ( file_name_stream.str().length() ) file_name_stream << "_";
597  file_name_stream << std::setfill('0') << std::setw(3) << replica;
598  }
599 
600  if ( suffix.length() ) {
601  if ( file_name_stream.str().length() ) file_name_stream << "_";
602  file_name_stream << suffix;
603  }
604 
605  return file_name_stream.str();
606 }
607 
608 void
610  ThermodynamicMoverOP setting
611 ) {
612  last_move_ = setting;
613 }
614 
615 ThermodynamicMover const&
617  assert( last_move_ );
618  return *last_move_;
619 }
620 
621 /// @details You can control the probability of selecting a particular mover
622 /// via the weight argument to the @ref add_mover() method.
625  return movers_[weighted_sampler_.random_sample(numeric::random::rg())];
626 }
627 
628 /// @details Specify a weight to control how often this mover should be
629 /// invoked. The weight does not have to be in any particular range. The
630 /// probability of choosing any particular move will be the weight of that
631 /// sampler divided by the sum of the weights of all the moves.
632 void
634  ThermodynamicMoverOP mover,
635  core::Real weight
636 ) {
637  mover->set_preserve_detailed_balance(true);
638  movers_.push_back(mover);
639  weighted_sampler_.add_weight(weight);
640 }
641 
642 /// @details In principle, information about the mover could be extracted from
643 /// the given XML tag, but currently this function is a simple alias for @ref
644 /// add_mover().
645 void
647  ThermodynamicMoverOP mover,
648  core::Real weight,
649  utility::tag::TagCOP const&
650 ) {
651  add_mover( mover, weight );
652 }
653 
654 void
656  core::Real weight
657 )
658 {
659  if ( !weight ) return;
660 
662  backrub_mover->branchopt().read_database();
663 
664  add_mover(backrub_mover, weight);
665 }
666 
667 void
669  core::Real weight,
670  protocols::loops::Loop const & loop
671 )
672 {
673  if ( !weight ) return;
674 
676  kic_mover->set_loop(loop);
677 
678  add_mover(kic_mover, weight);
679 }
680 
681 void
683  core::Real weight
684 )
685 {
686  if ( !weight ) return;
687 
688  using namespace basic::options;
689  using namespace basic::options::OptionKeys;
690 
692  small_mover->nmoves(1);
694  if ( utility::file::file_exists(option[ in::file::movemap ]) ) {
695  movemap->init_from_file(option[ in::file::movemap ]);
696  } else {
697  movemap->set_bb(true);
698  }
699  small_mover->movemap(movemap);
700 
701  add_mover(small_mover, weight);
702 }
703 
704 void
706  core::Real weight
707 )
708 {
709  if ( !weight ) return;
710 
711  using namespace basic::options;
712  using namespace basic::options::OptionKeys;
713 
715  shear_mover->nmoves(1);
717  if ( utility::file::file_exists(option[ in::file::movemap ]) ) {
718  movemap->init_from_file(option[ in::file::movemap ]);
719  } else {
720  movemap->set_bb(true);
721  }
722  shear_mover->movemap(movemap);
723 
724  add_mover(shear_mover, weight);
725 }
726 
727 void
729  core::Real weight,
730  core::Real prob_uniform,
731  core::Real prob_withinrot,
732  bool preserve_cbeta
733 )
734 {
735  if ( !weight ) return;
736 
737  using namespace basic::options;
738  using namespace basic::options::OptionKeys;
740 
742  main_task_factory->push_back( TaskOperationCOP( new core::pack::task::operation::InitializeFromCommandline ) );
743  if ( option[ packing::resfile ].user() ) {
744  main_task_factory->push_back( TaskOperationCOP( new core::pack::task::operation::ReadResfile ) );
745  } else {
746  main_task_factory->push_back( TaskOperationCOP( new core::pack::task::operation::RestrictToRepacking ) );
747  }
748  if ( preserve_cbeta ) main_task_factory->push_back( TaskOperationCOP( new core::pack::task::operation::PreserveCBeta ) );
749 
751  sidechain_mover->set_task_factory(main_task_factory);
752  sidechain_mover->set_prob_uniform(prob_uniform);
753  sidechain_mover->set_prob_withinrot(prob_withinrot);
754 
755  add_mover(sidechain_mover, weight);
756 }
757 
758 void
760  core::Real weight,
761  core::Real prob_uniform,
762  core::Real prob_withinrot,
763  bool preserve_cbeta,
765 )
766 {
767  if ( !weight ) return;
768 
769  using namespace basic::options;
770  using namespace basic::options::OptionKeys;
772 
774  main_task_factory->push_back( TaskOperationCOP( new core::pack::task::operation::InitializeFromCommandline ) );
775  if ( option[ packing::resfile ].user() ) {
776  main_task_factory->push_back( TaskOperationCOP( new core::pack::task::operation::ReadResfile ) );
777  } else {
778  main_task_factory->push_back( TaskOperationCOP( new core::pack::task::operation::RestrictToRepacking ) );
779  }
780  if ( preserve_cbeta ) main_task_factory->push_back( TaskOperationCOP( new core::pack::task::operation::PreserveCBeta ) );
781 
783  sidechain_mc_mover->set_task_factory(main_task_factory);
784  sidechain_mc_mover->set_prob_uniform(prob_uniform);
785  sidechain_mc_mover->set_prob_withinrot(prob_withinrot);
786  sidechain_mc_mover->setup(monte_carlo_->score_function().clone());
787  sidechain_mc_mover->set_ntrials(ntrials);
788 
789  add_mover(sidechain_mc_mover, weight);
790 }
791 
792 void
794  ThermodynamicObserverOP observer
795 )
796 {
797  observers_.push_back(observer);
798 }
799 
800 } //moves
801 } //protocols
802 
TemperatureControllerCOP tempering() const
Return the TemperatureController being used by this simulation.
utility::pointer::shared_ptr< ScoreFunction > ScoreFunctionOP
utility::pointer::shared_ptr< MonteCarlo const > MonteCarloCOP
virtual std::string get_name() const
Return the name of this mover.
utility::tag::TagCOP TagCOP
Definition: Mover.hh:66
protocols::jd2::SilentFileJobOutputterOP job_outputter_
static THREAD_LOCAL basic::Tracer tr("protocols.canonical_sampling.MetropolisHastingsMover")
why this inheritance pathway? this makes no sense!
JobOP get_current_job()
Definition: util.cc:206
header file for ThreadingJob classes, part of August 2008 job distributor as planned at RosettaCon08...
Declarations and simple accessor/mutator definitions for SmallMover and ShearMover.
utility::vector1< ThermodynamicObserverOP > observers_
silent input file reader for mini
std::string current_output_name()
gets used output name of pose ask jd for current-job —> ask jobOutputter for name of this job ...
Definition: util.cc:139
void add_sidechain_mover(core::Real weight, core::Real prob_uniform, core::Real prob_withinrot, bool preserve_cbeta)
Convenience method to add a sidechain move to the simulation.
Declarations for the MoveMap class.
void set_last_move(ThermodynamicMoverOP setting)
Indicate what type of move was last attempted.
void wind_down_simulation(core::pose::Pose &pose)
Finalize all the movers and observers used in this simulation, and write some debrief statistics to t...
void set_last_accepted(bool setting)
Indicate whether or not the last attempted move was accepted.
core::Size prepare_simulation(core::pose::Pose &pose)
Initialize all the movers and observers to be used in this simulation.
This object is responsible for all of the major functions needed in a Monte Carlo simulation...
Definition: MonteCarlo.hh:71
utility::pointer::shared_ptr< ThermodynamicObserver > ThermodynamicObserverOP
utility::pointer::shared_ptr< SilentFileJobOutputter > SilentFileJobOutputterOP
A molecular system including residues, kinematics, and energies.
Definition: Pose.hh:151
class for non-discrete side chain sampling using Dunbrack rotamer probabilities/distributions ...
Score function class.
void add_kic_mover(core::Real weight, protocols::loops::Loop const &loop)
Convenience method to add a kinematic closure move to the simulation.
core::Size current_replica()
returns 0 if no replicas (i.e., multiple processes per job ) otherwise it returns the sub-rank of the...
Definition: util.cc:288
single loop definition
Definition: Loop.hh:59
A class specifying DOFs to be flexible or fixed.
Definition: MoveMap.hh:87
protocols::moves::MoverOP clone() const
Return a copy of this mover.
bool read_file(std::string const &filename)
Read in the SilentStruct objects contained in the given filename. this version will throw an exceptio...
Abstract base class for classes that read and write different types of silent-files. Silent-files can contain SilentStruct objects which are expected, to be uniquely identified by some sort of string-based tag inside the file.
static std::string mover_name()
Static alias for keyname(). Not sure why this is needed.
utility::pointer::shared_ptr< TaskOperation > TaskOperationCOP
utility::pointer::shared_ptr< MonteCarlo > MonteCarloOP
utility::pointer::weak_ptr< MetropolisHastingsMover > MetropolisHastingsMoverAP
utility::pointer::shared_ptr< SidechainMover > SidechainMoverOP
std::string str(T const &t)
Definition: FunGroupTK.cc:77
utility::pointer::shared_ptr< TemperatureController const > TemperatureControllerCOP
utility::pointer::shared_ptr< BalancedKicMover > BalancedKicMoverOP
Base class for moves that can obey detailed balance.
A mover that makes independent random perturbations of the phi and psi torsion angles of residue i...
void add_observer(ThermodynamicObserverOP observer)
Add the given observer to this simulation.
std::map< std::string const, FilterOP > Filters_map
Definition: Filter.fwd.hh:44
virtual std::string keyname() const
Return the tag name associated with this factory.
static MoverFactory * get_instance()
static function to get the instance of ( pointer to) this singleton class
Definition: MoverFactory.cc:57
August 2008 job distributor as planned at RosettaCon08 - Base class.
class for applying backrub moves to arbitrary protein segments
Definition: BackrubMover.hh:53
Method declarations and simple accessors/getters for ResidueType.
Task class to describe packer's behavior header.
platform::Size Size
Definition: types.hh:30
void add_sidechain_mc_mover(core::Real weight, core::Real prob_uniform, core::Real prob_withinrot, bool preserve_cbeta, core::Size ntrials)
Convenience method to add a Monte Carlo sidechain move to the simulation. This move uses an internal ...
utility::pointer::shared_ptr< ShearMover > ShearMoverOP
silent input file reader for mini
utility::pointer::shared_ptr< MoveMap > MoveMapOP
Definition: MoveMap.fwd.hh:25
utility::pointer::shared_ptr< TemperatureController > TemperatureControllerOP
virtual void apply(core::pose::Pose &pose)
Run the Metropolis-Hastings simulation.
void add_shear_mover(core::Real weight)
Convenience method to add a shear move to the simulation.
utility::pointer::shared_ptr< ThermodynamicMover > ThermodynamicMoverOP
void set_ntrials(core::Size ntrials)
Set the number of iterations to use for this simulation.
utility::pointer::shared_ptr< SidechainMCMover > SidechainMCMoverOP
rosetta project type declarations
void write_checkpoint(core::pose::Pose const &pose)
write checkpoint snapshots for restarting
virtual bool reinitialize_for_new_input() const
Return false. This mover does not need to be reinitialized for new input.
virtual moves::MoverOP create_mover() const
Return a new mover.
utility::pointer::shared_ptr< BiasEnergy > BiasEnergyOP
std::string output_file_name(std::string const &suffix, bool cumulate_jobs=false, bool cumulate_replicas=false) const
Return a file name that is consistent with the given options.
Implement replica exchange in the MetropolisHastingsMover Framework.
definition of SidechainMover class and functions
virtual void add_mover(ThermodynamicMoverOP mover, core::Real weight, utility::tag::TagCOP const &subtag)
Add the given mover to the simulation.
static JobDistributor * get_instance()
static function to get the instance of ( pointer to) this singleton class
MoverCOP get_self_ptr() const
Definition: Mover.hh:85
: A mover is an object that can apply a conformational change to a pose.
utility::tag::TagCOP TagCOP
Definition: BasicFilters.cc:54
protocols::moves::MonteCarloCOP monte_carlo() const
Return the MonteCarlo object being used by this simulation.
A mover that perturbs the phi of residue i and the psi of residue i-1 such that they create a 'sheari...
utility::pointer::shared_ptr< BiasedMonteCarlo > BiasedMonteCarloOP
platform::Real Real
Definition: types.hh:35
void checkpoint_with_interval(const int interval_in)
Definition: Checkpoint.cc:27
definition of SidechainMCMover class and functions
virtual bool reinitialize_for_each_job() const
Return false. This mover does not need to be reinitialized for each job.
protocols::moves::MonteCarlo & nonconst_monte_carlo()
Protected non-const access to the MonteCarlo object.
definition of BackrubMover class and functions
utility::pointer::shared_ptr< BackrubMover > BackrubMoverOP
ThermodynamicMover const & last_move() const
Return the most recently used ThermodynamicMover.
iterator begin()
Returns an iterator to the start of the members of this container.
Pose utilities.
Manage the main loop of a canonical Monte Carlo simulation.
utility::pointer::shared_ptr< Mover > MoverOP
Definition: Mover.fwd.hh:29
bool file_exists(std::string const &file_name)
Definition: util.cc:572
void add_backrub_mover(core::Real weight)
Convenience method to add a backrub move to the simulation.
utility::pointer::shared_ptr< TaskFactory > TaskFactoryOP
header file for SilentFileJobOutputter class, part of August 2008 job distributor as planned at Roset...
class for non-discrete side chain sampling using Dunbrack rotamer probabilities/distributions ...
An operation to perform on a packer task – usually, by a PackerTaskFactory right after the task's co...
void add_job_data_to_ss(core::io::silent::SilentStructOP ss, JobCOP job_op)
Definition: util.cc:227
virtual protocols::moves::MoverOP fresh_instance() const
Return a newly instantiated mover.
utility::pointer::shared_ptr< SilentStruct > SilentStructOP
Definition: silent.fwd.hh:50
virtual ThermodynamicMoverOP random_mover() const
Return true if the simulation has been completed.
std::string const & output_name() const
Return the file name used by some of the observers to output data.
Base class for controlling the temperature of a simulation.
void set_tempering(TemperatureControllerOP)
Provide a TemperatureController to use for this simulation.
Make a kinematic closure move that obeys detailed balance.
std::string const & filename() const
Gets the filename that this SilentFileData object will write to.
utility::pointer::shared_ptr< SmallMover > SmallMoverOP
void set_output_name(std::string const &output_name)
Set the file name used by some of the observers to output data.
std::map< std::string const, MoverOP > Movers_map
Definition: Mover.fwd.hh:35
static THREAD_LOCAL basic::Tracer tr("protocols.canonical_sampling.CanonicalSamplingMover")
MoverOP newMover(std::string const &)
Create a mover given its identifying string.
Factory class for the creation and initialization of PackerTask objects.
Definition: TaskFactory.hh:42
virtual void parse_my_tag(utility::tag::TagCOP tag, basic::datacache::DataMap &data, protocols::filters::Filters_map const &filters, protocols::moves::Movers_map const &movers, core::pose::Pose const &pose)
Use a RosettaScripts tag to configure this mover.
void set_monte_carlo(protocols::moves::MonteCarloOP monte_carlo)
Provide a MonteCarlo object to use for this simulation.
core::Size ntrials() const
Return the number of iterations used by this simulation.
void add_small_mover(core::Real weight)
Convenience method to add a small move to the simulation.
This class will create instances of Mover MetropolisHastingsMover for the MoverFactory.
core::scoring::ScoreFunctionOP parse_score_function(utility::tag::TagCOP tag, std::string const &option_name, basic::datacache::DataMap const &data, std::string const &dflt_key)
Look up the score function defined in the through the given option. Default to 'talaris20...
Definition: util.cc:200
std::string current_output_filename()
call the 'filename' accessor of the current job-distributor with the current job
Definition: util.cc:161