Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConstraintFragmentSampler.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 ConstraintFragmentSampler.cc
11 /// @brief ab-initio fragment assembly protocol for proteins
12 /// @detailed
13 /// Contains currently: Classic Abinitio
14 ///
15 /// @author Oliver Lange
16 /// @author James Thompson
17 /// @author Mike Tyka
18 /// @author Christopher Miles (cmiles@uw.edu)
19 
20 // Unit Headers
23 
24 // Project Headers
25 #include <core/pose/Pose.hh>
26 #include <core/types.hh>
27 #include <core/scoring/Energies.hh>
33 
34 // Utility headers
35 #include <utility/exit.hh>
36 #include <utility/vector1.fwd.hh>
37 #include <utility/pointer/ReferenceCount.hh>
38 #include <numeric/numeric.functions.hh>
39 #include <basic/prof.hh>
40 #include <basic/Tracer.hh>
41 #include <basic/options/option.hh>
42 #include <basic/options/keys/fold_cst.OptionKeys.gen.hh>
43 #include <basic/options/keys/jumps.OptionKeys.gen.hh>
44 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
45 
46 // C++ headers
47 #include <cstdlib>
48 #include <string>
49 
50 // Auto Headers
53 // AUTO-REMOVED #include <utility/io/mpistream.hh>
54 
55 #include <utility/vector1.hh>
56 
57 
58 static basic::Tracer tr("protocols.abinitio");
59 
60 using core::Real;
63 using std::string;
64 using namespace core;
65 using namespace basic;
66 using namespace basic::options;
67 using namespace basic::options::OptionKeys;
68 
69 /*!
70 @detail call this:
71 ConstraintFragmentSampler::register_options() before devel::init().
72 Derived classes that overload this function should also call Parent::register_options()
73 */
74 
75 Size seq_sep_stage( core::Size total_res, Real factor ) {
76  return static_cast< Size >( std::min( factor, 1.0 ) * total_res );
77 }
78 
81  using namespace basic::options;
82  using namespace basic::options::OptionKeys;
83  option.add_relevant( constraints::cst_weight );
84  option.add_relevant( fold_cst::no_minimize );
85  option.add_relevant( fold_cst::force_minimize );
86  option.add_relevant( fold_cst::seq_sep_stages );
87  option.add_relevant( fold_cst::skip_on_noviolation_in_stage1 );
88  option.add_relevant( fold_cst::stage1_ramp_cst_cycle_factor );
89  option.add_relevant( fold_cst::ignore_sequence_seperation );
90  option.add_relevant( fold_cst::no_recover_low_at_constraint_switch );
91  option.add_relevant( fold_cst::ramp_coord_cst );
92 }
93 
94 namespace protocols {
95 namespace abinitio {
96 
97 /// @detail large (stage1/stage2)
98 /// small(stage2/stage3/stage4)
99 /// smooth_small ( stage3/stage4)
100 ConstraintFragmentSampler::ConstraintFragmentSampler(topology_broker::TopologyBrokerOP broker)
101  : Parent(broker) {
102  BaseClass::type( "ConstraintFragmentSampler" );
103  set_defaults();
104 }
105 
106 /// @brief ConstraintFragmentSampler has virtual functions... use this to obtain a new instance
108  return new ConstraintFragmentSampler( *this );
109 }
110 
111 //@detail read cmd_line options and set default versions for many protocol members: trials/moves, score-functions, Monte-Carlo
114  using namespace basic::options;
115  using namespace basic::options::OptionKeys;
116  set_constraint_weight( option[ OptionKeys::constraints::cst_weight ] );
117  show_viol_level_ = option[OptionKeys::constraints::viol_level];
118  max_seq_sep_fudge_ = 1.0; //models rosetta++ behaviour.
119 
120  if ( option[ OptionKeys::fold_cst::seq_sep_stages ].user() ) {
121  if ( option[ OptionKeys::fold_cst::seq_sep_stages ]().size() != 3 ) {
122  utility_exit_with_message("option seq_sep_stages requires exact 3 values!!!");
123  }
124  seq_sep_stage1_ = option[ OptionKeys::fold_cst::seq_sep_stages ]()[ 1 ]; //default 15
125  seq_sep_stage3_ = option[ OptionKeys::fold_cst::seq_sep_stages ]()[ 2 ]; //default 15
126  seq_sep_stage4_ = option[ OptionKeys::fold_cst::seq_sep_stages ]()[ 3 ]; //default 15
127  } else {
128  seq_sep_stage1_ = 0.15;
129  seq_sep_stage3_ = 1.0; //have basically all but the furthest chainbreaks active at end of stage3.
130  seq_sep_stage4_ = 1.2; //make sure that all chainbreaks are switched on in the end
131  }
132 
133  bSkipOnNoViolation_ = option[ fold_cst::skip_on_noviolation_in_stage1 ];
134 
135  bNoRecoverLowAtSwitch_ = option[ fold_cst::no_recover_low_at_constraint_switch ];
136 
137  bRampChainbreaks_ = option[ jumps::ramp_chainbreaks ]; //default is true
138  bRampCoordConstraints_ = option[ fold_cst::ramp_coord_cst ]; //default is false
140  Real chainbreak_score_1 = option[ jumps::chainbreak_weight_stage1 ]();
141  Real chainbreak_score_2 = option[ jumps::chainbreak_weight_stage2 ]();
142  Real chainbreak_score_3 = option[ jumps::chainbreak_weight_stage3 ]();
143  Real chainbreak_score_4 = option[ jumps::chainbreak_weight_stage4 ]();
144  if ( !bRampChainbreaks_ ) {
145  set_score_weight( scoring::linear_chainbreak, chainbreak_score_1, STAGE_1 );
146  set_score_weight( scoring::linear_chainbreak, chainbreak_score_2, STAGE_2 );
147  set_score_weight( scoring::linear_chainbreak, chainbreak_score_3, STAGE_3a );
148  set_score_weight( scoring::linear_chainbreak, chainbreak_score_3, STAGE_3b );
149  set_score_weight( scoring::linear_chainbreak, chainbreak_score_4, STAGE_4 );
150  }
151 }
152 
154  StageID stage,
155  Real intra_stage_progress ) {
156  Parent::replace_scorefxn( pose, stage, intra_stage_progress );
157 
158  if ( bRampChainbreaks_ ) { //should this live in replace_scorefxn ???
159  Real setting( 0.0 );
160 
161  if ( stage == STAGE_2 ) {
162  setting = 0.25 / 3;
163  } else if ( stage == STAGE_3a ) {
164  setting = 2.5 * intra_stage_progress * 1.0/3;
165  } else if ( stage == STAGE_3b ) {
166  setting = 0.5 * intra_stage_progress * 1.0/3;
167  } else if ( stage == STAGE_4 ) {
168  setting = (1.5*intra_stage_progress+2.5 ) * ( 1.0/3);
169  }
170  set_current_weight( scoring::linear_chainbreak, setting * option[ jumps::increase_chainbreak ] ); //default 1.0
171  if ( bRampCoordConstraints_ ) {
172  set_current_weight( scoring::coordinate_constraint, setting * option[ jumps::increase_chainbreak ] );
173  }
174 
175  if ( bOverlapChainbreaks_ && stage == STAGE_4 ) {
176  set_score_weight( scoring::overlap_chainbreak, intra_stage_progress * option[ jumps::increase_chainbreak ] , STAGE_4 );
177  set_current_weight( scoring::overlap_chainbreak, intra_stage_progress * option[ jumps::increase_chainbreak ] );
178  }
179  }
180  Real sep_fact( seq_sep_stage1_ );
181  if ( stage == STAGE_1 ) {
182  sep_fact = std::min( 3.0/total_res( pose ), seq_sep_stage1_ );
183  } else if ( stage == STAGE_2 ) {
184  sep_fact = seq_sep_stage1_;
185  } else if ( stage == STAGE_3a || stage == STAGE_3b ) {
186  sep_fact = seq_sep_stage1_ + ( seq_sep_stage3_ - seq_sep_stage1_) * 1.0*intra_stage_progress;
187  } else if ( stage == STAGE_4 ) {
188  sep_fact = seq_sep_stage3_ + ( seq_sep_stage4_ - seq_sep_stage3_ ) * 1.0*intra_stage_progress;
189  }
190  tr.Debug << "replace_scorefxn... sep_fact: " << sep_fact << " STAGE " << stage << std::endl;
191  tr.Debug << "total number of residues: " << pose.total_residue() << " max. separation in fold-tree " << total_res(pose) << std::endl;
192  set_max_seq_sep( pose, seq_sep_stage( total_res( pose ), sep_fact ) );
193 }
194 
195 //otherwise stage2 cycles remain as in the classic protocol
197  return static_cast< Size >(
198  std::min( 1.0*pose.total_residue(), constraints_->largest_possible_sequence_sep( pose ) * max_seq_sep_fudge_ )
199  );
200 }
201 
203  using namespace basic::options;
204  using core::pose::Pose;
206 
207  bool const bHaveConstraints( pose.constraint_set()->has_residue_pair_constraints() );
208  bool const bHaveChainbreaks( topology_broker().has_chainbreaks_to_close() );
209 
210  if (bHaveConstraints)
211  runtime_assert( constraints_ );
212 
213  if ( bHaveConstraints || bHaveChainbreaks ) {
214  if ( bHaveConstraints) {
215  // pass along the updated sequence separation parameter to the constraints
216  constraints_->set_max_seq_sep( setting );
217  }
218  tr.Info << "max_seq_sep: " << setting << std::endl;
219 
220  // we really have constraints... let's get to work
221  if (!bNoRecoverLowAtSwitch_) {
222  // Recover the low energy pose, otherwise we will lose it at the next reset()
223  if (tr.Trace.visible())
224  current_scorefxn().show(tr.Trace, pose);
225 
226  tr.Trace << "================ RECOVER LOW (max_seq_sep) ==============" << std::endl;
227  mc().recover_low(pose);
228 
229  if (bHaveConstraints)
231 
232  if (bHaveChainbreaks) {
233  // Take note of our existing energy method options
234  const EnergyMethodOptions& current_options =
236 
237  // Update the maximum sequence separation setting, retaining the values
238  // of all other energy method options
239  EnergyMethodOptions updated_options(current_options);
240  updated_options.cst_max_seq_sep(setting);
241 
242  // Replace the score function
243  ScoreFunction new_scorefxn(current_scorefxn());
244  new_scorefxn.set_energy_method_options(updated_options);
245  current_scorefxn(new_scorefxn);
246  }
247 
248  mc().reset(pose);
249  if (tr.Trace.visible())
250  current_scorefxn().show(tr.Trace, pose);
251  tr.Trace << std::endl;
252  } else {
253  Pose low_pose;
254  mc().recover_low(low_pose);
255 
256  if (bHaveConstraints)
257  low_pose.constraint_set(constraints_);
258 
259  if (bHaveChainbreaks) {
260  // Take note of our existing energy method options
261  const EnergyMethodOptions& current_options =
263 
264  // Update the maximum sequence separation setting, retaining the values
265  // of all other energy method options
266  EnergyMethodOptions updated_options(current_options);
267  updated_options.cst_max_seq_sep(setting);
268 
269  // Replace the score function
270  ScoreFunction new_scorefxn(current_scorefxn());
271  new_scorefxn.set_energy_method_options(updated_options);
272  current_scorefxn(new_scorefxn);
273  }
274 
275  mc().reset(low_pose);
276 
277  if (bHaveConstraints)
279 
280  if (bHaveChainbreaks) {
281  // Take note of our existing energy method options
282  const EnergyMethodOptions& current_options =
284 
285  // Update the maximum sequence separation setting, retaining the values
286  // of all other energy method options
287  EnergyMethodOptions updated_options(current_options);
288  updated_options.cst_max_seq_sep(setting);
289 
290  // Replace the score function
291  ScoreFunction new_scorefxn(current_scorefxn());
292  new_scorefxn.set_energy_method_options(updated_options);
293  current_scorefxn(new_scorefxn);
294  }
295 
296  mc().boltzmann(pose, "add_constraints");
297  }
298  }
299 }
300 
302  Real old_constraint_score = evaluate_constraint_energy ( pose, mc().score_function() );
303 
304  moves::MoverOP trial( new moves::TrialMover( mover( pose, STAGE_1, current_scorefxn() ), mc_ptr() ) );
305 
306  if ( tr.visible() ) pose.constraint_set()->show_violations( tr, pose, show_viol_level_ );
307 
308  //first run a normal set of fragment insertions until extended chain is lost
309  Parent::do_stage1_cycles( pose );
310 
311  if ( tr.visible() ) pose.constraint_set()->show_violations( tr, pose, show_viol_level_ );
312 
313  if ( pose.constraint_set()->has_residue_pair_constraints() ) {
314  // Now ramp up the seq_sep of the constraints... still on score0
315  for ( Size jk = 3; jk <= seq_sep_stage( total_res( pose ), seq_sep_stage1_); jk += 2 ) {
316  set_max_seq_sep( pose, jk);
317  if ( tr.visible() ) pose.constraint_set()->show_violations( tr, pose, show_viol_level_ );
318  if ( std::abs( old_constraint_score - evaluate_constraint_energy ( pose, mc().score_function() ) ) < 0.01 ) continue;
319  for ( Size j = 1; j <= stage1_cycles(); ++j ) {
320  if ( numeric::mod( j, (Size) 10 ) == 0 && bSkipOnNoViolation_ && pose.constraint_set()->show_violations( tr, pose, 0 ) == 0 ) break;
321  trial->apply( pose );
322  }
323  old_constraint_score = evaluate_constraint_energy ( pose, mc().score_function() );
324  }
325  }
326 }
327 
328 void
330  //we set score term in here: we minimize in this one... need to set all score terms before that
331  Parent::prepare_stage1( pose );
332 }
333 
334 void
336  // set_max_seq_sep( pose, seq_sep_stage( total_res( pose ), seq_sep_stage1_ ) );
337  Parent::prepare_stage2( pose );
338  if ( tr.visible() ) pose.constraint_set()->show_violations( tr, pose, show_viol_level_ );
339 }
340 
341 void
343  Parent::prepare_loop_in_stage3( pose, loop_iteration, total_iterations );
344  if ( tr.Info.visible() ) pose.constraint_set()->show_violations( tr, pose, show_viol_level_ );
345 }
346 
347 void
349  Parent::prepare_loop_in_stage4( pose, loop_iteration, total_iterations );
350  if ( tr.Info.visible() ) pose.constraint_set()->show_violations( tr, pose, show_viol_level_ );
351 }
352 
355  tr.Info << "ConstraintFragment Sampler: " << get_current_tag() << std::endl;
356 
357  // take note of the current constraints, as we are responsible for restoring them
358  ConstraintSetOP orig_constraints(NULL);
359  tr.Debug << "introduce MaxSeqSep Filter for constraints" << std::endl;
360  orig_constraints = pose.constraint_set()->clone();
361 
362  // initialize a MaxSeqSepConstraintSet with the current set of constraints
364  constraints_->set_max_seq_sep(pose.total_residue()); // so it is prepared for stage4.
365 
366  // replace <pose>'s ConstraintSet with our newly initialized MaxSeqSepConstraintSet
368 
369  mc().clear_poses();
370  mc().reset(pose);
371 
372  // *** Parent::apply() ***
373  Parent::apply(pose);
374 
375  // restore the original set of constraints
376  if (orig_constraints)
377  pose.constraint_set(orig_constraints);
378 }
379 
381  return "ConstraintFragmentSampler";
382 }
383 
385  ScoreFunction const & scfxn) const {
386  scfxn( pose ); //accumulate energies
387  return
392 }
393 
394 } //abinitio
395 } //protocols