46 #include <basic/options/keys/in.OptionKeys.gen.hh>
47 #include <basic/options/keys/packing.OptionKeys.gen.hh>
56 #include <basic/Tracer.hh>
59 #include <numeric/random/random.hh>
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>
69 #include <utility/vector0.hh>
70 #include <utility/vector1.hh>
72 #include <ObjexxFCL/format.hh>
75 #include <utility/excn/Exceptions.hh>
76 #include <basic/options/option.hh>
77 #include <basic/options/keys/run.OptionKeys.gen.hh>
86 static THREAD_LOCAL basic::Tracer
tr(
"protocols.canonical_sampling.MetropolisHastingsMover" );
89 namespace canonical_sampling {
103 return "MetropolisHastings";
111 using namespace basic::options;
112 using namespace basic::options::OptionKeys;
113 if ( option[ run::checkpoint_interval ].user() ) {
123 Mover(metropolis_hastings_mover),
132 movers_.push_back(utility::pointer::dynamic_pointer_cast<ThermodynamicMover>(metropolis_hastings_mover.
movers_[i]));
136 observers_.push_back(utility::pointer::dynamic_pointer_cast<ThermodynamicObserver>(metropolis_hastings_mover.
observers_[i]));
157 tr.Info <<
" obtained output name from JobDistributor " << std::endl;
160 tr.Info <<
" running with preset output name: " <<
output_name() << std::endl;
165 tr.Info <<
"no temperature controller in MetropolisHastings defined... generating FixedTemperatureController" << std::endl;
169 using namespace core;
170 bool restart =
false;
173 Real temperature = -1.0;
182 if ( utility::pointer::dynamic_pointer_cast< TrajectoryRecorder >(
observers_[i] ) ) {
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;
192 tr.Debug <<
"bias energy used " << std::endl;
193 restart = bias_energy->restart_simulation( pose, *
this, cycle_number, temp_level, temperature );
195 tr.Info <<
"grid info collected, restart now!" << std::endl;
197 tr.Info <<
"failed collecting grid info, restart failed!" << std::endl;
205 tempering_->initialize_simulation(pose, *
this, cycle_number );
207 tempering_->initialize_simulation(pose, *
this, temp_level, temperature, cycle_number );
211 tr.Info <<
"Initializing " <<
movers_[i]->get_name() << std::endl;
212 movers_[i]->set_metropolis_hastings_mover(
215 movers_[i]->initialize_simulation(pose, *
this, cycle_number);
223 tr.Info <<
"Initializing " <<
observers_[i]->get_name() << std::endl;
224 observers_[i]->initialize_simulation(pose, *
this, cycle_number);
227 tr.Info <<
"Initial Score:\n";
230 tr.Info <<
"Running " <<
ntrials_-cycle_number <<
" trials..." << std::endl;
247 mover->last_proposal_density_ratio(),
248 mover->last_inner_score_delta_over_temperature()
253 mover->observe_after_metropolis(*
this);
254 tr.Trace <<
"current move accepted " << accepted <<std::endl;
256 observers_[i]->observe_after_metropolis(*
this);
266 using namespace ObjexxFCL;
267 using namespace protocols::checkpoint;
269 if ( !Timer::is_on() )
return;
270 if ( !Timer::time_to_checkpoint() )
return;
274 std::ostringstream checkpoint_id;
277 checkpoint_id << jd2_filename.base();
283 utility::io::ozstream out( checkpoint_id.str()+
".out");
291 std::ostringstream tag;
294 tag <<
"_" << std::setfill(
'0') << std::setw(8) <<
current_trial_;
296 pss->fill_struct( pose, tag.str() );
301 biased_mc->bias_energy()->write_to_string( str );
304 pss->add_comment(
"BIASENERGY", str);
310 pss->print_header( out );
311 pss->print_scores( out );
312 pss->print_conformation( out );
327 using namespace utility::file;
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 ) {
339 core::Size ind = found_name.base().find_last_of(
'_');
340 checkpoint_indics.push_back( utility::string2int( found_name.base().substr(ind+1) ) );
343 tr.Debug <<
"found " << checkpoint_indics.size() <<
" checkpoints" << std::endl;
344 if ( checkpoint_indics.size()==0 )
return false;
345 std::sort( checkpoint_indics.begin(), checkpoint_indics.end() );
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;
355 checkpoint_ids_.push_back( filename_pattern + ObjexxFCL::string_of( *rit ) );
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" );
367 utility::vector1< core::Size > found_levels;
373 found_levels.push_back( sfd.
begin()->get_energy(
"temp_level" ));
378 if ( !found_levels.has_value( replica ) ) {
379 tr.Debug <<
"temp_level: " << replica <<
" is missing" << std::endl;
382 if ( replica ==
tempering_->n_temp_levels() ) {
383 checkpoint_ids_.push_back( filename_pattern + ObjexxFCL::string_of( *rit ) );
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" );
394 std::cout <<
"complete restart info not collected from checkpoint, start from the begining..." << std::endl;
409 tr.Info <<
"Finalizing " <<
movers_[i]->get_name() << std::endl;
410 movers_[i]->finalize_simulation(pose, *
this);
414 tr.Info <<
"Finalizing " <<
observers_[i]->get_name() << std::endl;
415 observers_[i]->finalize_simulation(pose, *
this);
420 tr.Debug <<
"Final Score:" << std::endl;
422 tr.Debug << std::endl;
432 return "MetropolisHastingsMover";
456 basic::datacache::DataMap & data,
465 if ( tag->hasOption(
"checkpoint_interval") ) {
476 bool wte_sampling( tag->getOption<
bool >(
"wte",
false ) );
477 if ( wte_sampling ) {
479 bias_energy->parse_my_tag( tag, data, filters, movers, pose );
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" ) {
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;
498 mover = mover_iter->second;
501 mover = mover_factory->
newMover(subtag, data, filters, movers, pose);
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 ) );
512 }
else if ( th_observer ) {
514 if ( temp_controller ) {
523 tr.Error<<
"Mover is not a ThermodynamicMover or ThermodynamicObserver for XML tag:\n" << subtag << std::endl;
583 bool cumulate_replicas
586 if ( cumulate_jobs || cumulate_replicas ) runtime_assert(utility::io::ozstream::MPI_reroute_rank() >= 0);
588 std::ostringstream file_name_stream;
590 if ( !cumulate_jobs ) {
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;
600 if ( suffix.length() ) {
601 if ( file_name_stream.str().length() ) file_name_stream <<
"_";
602 file_name_stream << suffix;
605 return file_name_stream.str();
637 mover->set_preserve_detailed_balance(
true);
659 if ( !weight )
return;
662 backrub_mover->branchopt().read_database();
673 if ( !weight )
return;
676 kic_mover->set_loop(loop);
686 if ( !weight )
return;
688 using namespace basic::options;
689 using namespace basic::options::OptionKeys;
692 small_mover->nmoves(1);
695 movemap->init_from_file(option[ in::file::movemap ]);
697 movemap->set_bb(
true);
699 small_mover->movemap(movemap);
709 if ( !weight )
return;
711 using namespace basic::options;
712 using namespace basic::options::OptionKeys;
715 shear_mover->nmoves(1);
718 movemap->init_from_file(option[ in::file::movemap ]);
720 movemap->set_bb(
true);
722 shear_mover->movemap(movemap);
735 if ( !weight )
return;
737 using namespace basic::options;
738 using namespace basic::options::OptionKeys;
743 if ( option[ packing::resfile ].user() ) {
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);
767 if ( !weight )
return;
769 using namespace basic::options;
770 using namespace basic::options::OptionKeys;
775 if ( option[ packing::resfile ].user() ) {
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);
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
protocols::jd2::SilentFileJobOutputterOP job_outputter_
static THREAD_LOCAL basic::Tracer tr("protocols.canonical_sampling.MetropolisHastingsMover")
why this inheritance pathway? this makes no sense!
header file for ThreadingJob classes, part of August 2008 job distributor as planned at RosettaCon08...
bool output_name_from_job_distributor_
Declarations and simple accessor/mutator definitions for SmallMover and ShearMover.
utility::vector1< ThermodynamicObserverOP > observers_
silent input file reader for mini
protocols::moves::MonteCarloOP monte_carlo_
std::string current_output_name()
gets used output name of pose ask jd for current-job —> ask jobOutputter for name of this job ...
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.
ThermodynamicMoverOP last_move_
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...
utility::pointer::shared_ptr< ThermodynamicObserver > ThermodynamicObserverOP
utility::pointer::shared_ptr< SilentFileJobOutputter > SilentFileJobOutputterOP
A molecular system including residues, kinematics, and energies.
class for non-discrete side chain sampling using Dunbrack rotamer probabilities/distributions ...
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...
A class specifying DOFs to be flexible or fixed.
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)
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
virtual std::string keyname() const
Return the tag name associated with this factory.
utility::vector1< ThermodynamicMoverOP > movers_
static MoverFactory * get_instance()
static function to get the instance of ( pointer to) this singleton class
August 2008 job distributor as planned at RosettaCon08 - Base class.
class for applying backrub moves to arbitrary protein segments
Method declarations and simple accessors/getters for ResidueType.
Task class to describe packer's behavior header.
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
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
: A mover is an object that can apply a conformational change to a pose.
bool get_checkpoints()
get checkpoint_id for restarting
Maintain a constant temperature.
utility::tag::TagCOP TagCOP
protocols::moves::MonteCarloCOP monte_carlo() const
Return the MonteCarlo object being used by this simulation.
std::string get_last_checkpoint() const
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
void checkpoint_with_interval(const int interval_in)
definition of SidechainMCMover class and functions
utility::file::FileName FileName
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.
MetropolisHastingsMover()
Default constructor.
core::Size current_trial_
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.
Manage the main loop of a canonical Monte Carlo simulation.
numeric::random::WeightedSampler weighted_sampler_
utility::pointer::shared_ptr< Mover > MoverOP
bool file_exists(std::string const &file_name)
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...
virtual ~MetropolisHastingsMover()
Destructor.
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)
virtual protocols::moves::MoverOP fresh_instance() const
Return a newly instantiated mover.
utility::pointer::shared_ptr< SilentStruct > SilentStructOP
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
static THREAD_LOCAL basic::Tracer tr("protocols.canonical_sampling.CanonicalSamplingMover")
std::vector< std::string > checkpoint_ids_
MoverOP newMover(std::string const &)
Create a mover given its identifying string.
Factory class for the creation and initialization of PackerTask objects.
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.
core::Size checkpoint_count_
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...
std::string current_output_filename()
call the 'filename' accessor of the current job-distributor with the current job
TemperatureControllerOP tempering_