Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SidechainMetropolisHastingsMover.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/SidechainMetropolisHastingsMover.cc
11 /// @brief SidechainMetropolisHastingsMover methods implemented
12 /// @author
13 
14 
15 // Unit Headers
18 
20 
21 // protocols headers
24 
26 #include <protocols/jd2/util.hh>
27 #include <protocols/jd2/Job.hh>
28 
30 #include <protocols/moves/Mover.hh>
38 
39 // core headers
41 #include <basic/options/option_macros.hh>
42 #include <basic/options/keys/in.OptionKeys.gen.hh>
43 #include <basic/options/keys/packing.OptionKeys.gen.hh>
44 
45 #include <core/pose/Pose.hh>
49 
50 #include <core/types.hh>
51 #include <basic/Tracer.hh>
52 
53 
54 // numeric headers
55 #include <numeric/random/random.hh>
56 
57 // utility headers
58 #include <utility/file/file_sys_util.hh>
59 #include <utility/pointer/owning_ptr.hh>
60 #include <utility/tag/Tag.hh>
61 
62 // C++ Headers
63 
64 using basic::T;
65 using basic::Error;
66 using basic::Warning;
67 
68 static basic::Tracer tr( "protocols.canonical_sampling.SidechainSidechainMetropolisHastingsMover" );
69 static numeric::random::RandomGenerator RG(61257547);
70 
71 namespace protocols {
72 namespace canonical_sampling {
73 
74 using namespace core;
75 using namespace scoring;
76 
80 }
81 
85 }
86 
89  return "SidechainMetropolisHastings";
90 }
91 
93  stride_( 1000 )
94 {}
95 
97  stride_( stride )
98 {}
99 
102 ) :
103  protocols::canonical_sampling::MetropolisHastingsMover(other),
104  stride_( other.stride_ )
105 {}
106 
108 
109 bool
110 SidechainMetropolisHastingsMover::pass_metropolis(core::Real delta_energy, core::Real last_proposal_density_ratio ) const {
111  core::Real boltz_factor = delta_energy / monte_carlo()->temperature();
112  if ( tr.Trace.visible() ) {
113  tr.Trace << " temperature: " << monte_carlo()->temperature()
114  << " deltaE= " << delta_energy
115  << " boltzman=" << boltz_factor
116  << " lpd= " << last_proposal_density_ratio << std::endl;
117  }
118  core::Real probability = std::exp( std::min( 40.0, std::max( -40.0, boltz_factor ))) * last_proposal_density_ratio ;
119  if ( probability < 1 && RG.uniform() >= probability ) {
120  return false;
121  } else {
122  return true;
123  }
124 }
125 
126 void
128 {
129  prepare_simulation( pose );
130 
131  scoring::ScoreFunction const& sfxn = monte_carlo()->score_function();
133  ig = new pack::interaction_graph::SimpleInteractionGraph(); //commented out debug
134  ig->set_scorefunction( sfxn );
135 
136  utility::vector1< Real > new_chi;
137  Real current_energy = sfxn(pose);
138 
139  // std::string const traj_file_tag( jd2::current_output_name() );
140  // counters_.reset();
141 
142  jd2::JobOP job;
143  if ( jd2::jd2_used() ) {
144  job = jd2::get_current_job();
145  }
146 
147  //ek for fast sidechain sampling and internal mc trials
149  // utility::vector1< conformation::ResidueOP > previous;
150  // utility::vector1< pack::dunbrack::ChiVector > chi_vectors;
151  // utility::vector1< pack::dunbrack::RotVector > rot_vectors;
152 
153 
154  current.resize(pose.total_residue());
155  // previous.resize(pose.total_residue());
156 
157  // rot_vectors.resize( pose.total_residue() );
158  // chi_vectors.resize( pose.total_residue() );
159 
160  for ( core::Size i = 1; i <= pose.total_residue(); i++ ){
161  current[ i ] = new core::conformation::Residue( pose.residue( i ) );
162  }
163 
164 
165  runtime_assert( ig );
166 
167  ig->initialize( pose );
168  Real last_accepted_prop_density( 1.0 );
169  Real last_accepted_dE( 0.0 );
170  for ( Size ct = 1; ct <= ntrials(); ct++) {
172  runtime_assert( move ); //fow now only Sidechain Movers...
173 
174  Size resid = move->suggest_residue_number( pose );
175  conformation::ResidueOP new_state( new conformation::Residue( pose.residue( resid ) ) );
176  new_state = move->make_move( new_state );
177  set_last_move( move );
178 
179  Real delta_energy = ig->consider_substitution( resid, new_state );
180  if ( pass_metropolis( delta_energy, move->last_proposal_density_ratio() ) ) { //ek
181  ig->commit_change( resid );
182  current_energy -= delta_energy;
183  current[ resid ] = new_state;
184  set_last_accepted( true );
185  last_accepted_prop_density = move->last_proposal_density_ratio();
186  last_accepted_dE = delta_energy;
187  } else { //rejected metropolis criterion
188  ig->reject_change( resid );
189  set_last_accepted( false );
190  }
191 
192  tempering()->temperature_move( current_energy );
193  move->observe_after_metropolis( *this );
194 
195  Size model_count( output_count( ct ) );
196  if ( model_count ) {
197  for( Size res_i = 1; res_i <= current.size(); res_i++ ){
198  pose.replace_residue( res_i, (*current[ res_i ]), true );
199  }
200  core::Real const score( sfxn( pose ) );
201  if ( std::abs( score-current_energy ) > 1 ) { //threshold 0.1 gives a couple warnings -- but it never drifts apart
202  tr.Warning << "Energy mismatch!!! score=" << score << " ig->energy " << current_energy << std::endl;
203  }
205  if ( job ) {
206  job->add_string_real_pair( "prop_density", move->last_proposal_density_ratio() );
207  job->add_string_real_pair( "prop_density_accept", last_accepted_prop_density );
208  job->add_string_real_pair( "move_dE", delta_energy );
209  job->add_string_real_pair( "move_dE_accept", last_accepted_dE );
210  job->add_string_string_pair( "move_type", move->type() );
211  }
212  }
213 
214  for (Size i = 1; i <= observers().size(); ++i) {
215  if ( observers()[ i ]->requires_pose() && !model_count ) continue;
216  observers()[i]->observe_after_metropolis(*this);
217  }
218 
219  } //for ntrials
220 
221  wind_down_simulation( pose );
222 }
223 
226  if ( ct % stride_ == 0 ) {
227  return ct / stride_;
228  } else return 0;
229 }
230 
233 {
234  return "SidechainMetropolisHastingsMover";
235 }
236 
239 {
241 }
242 
245 {
247 }
248 
249 void
251  utility::tag::TagPtr const tag,
253  protocols::filters::Filters_map const & filters,
254  protocols::moves::Movers_map const & movers,
255  pose::Pose const & pose
256 ) {
257  stride_ = tag->getOption< Size >( "stride", stride_ );
258  Parent::parse_my_tag( tag, data, filters, movers, pose );
259 }
260 
261 
262 } //moves
263 } //protocols
264