Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FoldConstraints.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 FoldConstraints.cc
11 /// @brief ab-initio fragment assembly protocol for proteins under the influence of contraints (e.g., NOE)
12 /// @detailed
13 /// @author Oliver Lange
14 ///
15 
16 
17 // Unit Headers
19 
20 // Package headers
21 // AUTO-REMOVED #include <protocols/simple_moves/GunnCost.hh>
22 // AUTO-REMOVED #include <protocols/simple_moves/ConstraintFragmentMover.hh>
23 
24 // Project Headers
25 #include <core/pose/Pose.hh>
26 #include <core/scoring/Energies.hh>
28 #include <core/types.hh>
30 // AUTO-REMOVED #include <core/kinematics/ShortestPathInFoldTree.hh>
31 
33 
34 // ObjexxFCL Headers
35 
36 // Utility headers
37 #include <utility/vector1.fwd.hh>
38 #include <utility/pointer/ReferenceCount.hh>
39 #include <numeric/numeric.functions.hh>
40 
41 // AUTO-REMOVED #include <basic/prof.hh>
42 #include <basic/Tracer.hh>
43 #include <basic/options/option.hh>
44 #include <basic/options/keys/fold_cst.OptionKeys.gen.hh>
45 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
46 
47 
48 //// C++ headers
49 #include <cstdlib>
50 #include <string>
51 // AUTO-REMOVED #include <fstream>
52 
53 
54 // option key includes
55 
56 
57 #include <core/fragment/FragSet.hh>
64 #include <utility/vector1.hh>
65 
66 
67 
68 static basic::Tracer tr("protocols.abinitio.foldconstraints",basic::t_info);
69 
73 
74 /// Why is this not being registered ? Probably not actually needed
75 
77  using namespace basic::options;
78  using namespace basic::options::OptionKeys;
80  option.add_relevant( constraints::cst_weight );
81  option.add_relevant( fold_cst::no_minimize );
82  option.add_relevant( fold_cst::force_minimize );
83  option.add_relevant( fold_cst::seq_sep_stages );
84  option.add_relevant( fold_cst::reramp_cst_cycles );
85  option.add_relevant( fold_cst::reramp_start_cstweight );
86  option.add_relevant( fold_cst::reramp_iterations );
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::stage2_constraint_threshold );
90  option.add_relevant( fold_cst::ignore_sequence_seperation );
91  option.add_relevant( fold_cst::no_recover_low_at_constraint_switch );
92 }
93 
94 namespace protocols {
95 namespace abinitio {
96 
97 using namespace core;
98 
99 ///@brief c'stor from Movers
104  int dummy /* otherwise the two constructors are ambigous */
105 ) : ClassicAbinitio( brute_move_small, brute_move_large, smooth_move_small, dummy ),
106  constraint_weight_( 1.0 ), run_( 0 )
107 {
108  BaseClass::type( "FoldConstraints" );
110 }
111 
112 ///@brief c'stor from FragSets --- ClassicFragmentMover and SmoothFragmentMover will be created
114  core::fragment::FragSetCOP fragset3mer,
115  core::fragment::FragSetCOP fragset9mer,
117 ) : ClassicAbinitio( fragset3mer, fragset9mer, movemap ),
118  constraint_weight_( 1.0 ), run_( 0 )
119 {
120  BaseClass::type( "FoldConstraints" );
122 }
123 
124 /// @details SHALLOW copy.
126  //utility::pointer::ReferenceCount(),
127  Parent( src )
128 {
129  min_move_ = src.min_move_;
132  bMinTrial_ = src.bMinTrial_;
134  run_ = src.run_;
145 }
146 
148 
149 
150 
153  return new FoldConstraints(*this);
154 }
155 
156 
159  using namespace basic::options;
160  using namespace basic::options::OptionKeys;
161  set_constraint_weight( option[ OptionKeys::constraints::cst_weight ] );
162  bMinTrial_ = !bQuickTest() && !option[ OptionKeys::fold_cst::no_minimize ];
163  bIgnoreSequenceSeparation_ = option[ OptionKeys::fold_cst::ignore_sequence_seperation ];
164  max_seq_sep_fudge_ = 1.0; //models roseta++ behaviour.
165  if ( option[ OptionKeys::fold_cst::seq_sep_stages ].user() ) {
166  if ( option[ OptionKeys::fold_cst::seq_sep_stages ]().size() != 3 ) {
167  utility_exit_with_message("option seq_sep_stages requires exact 3 values!!!");
168  }
169  seq_sep_stage1_ = option[ OptionKeys::fold_cst::seq_sep_stages ]()[ 1 ]; //default 15
170  seq_sep_stage3_ = option[ OptionKeys::fold_cst::seq_sep_stages ]()[ 2 ]; //default 15
171  seq_sep_stage4_ = option[ OptionKeys::fold_cst::seq_sep_stages ]()[ 3 ]; //default 15
172  } else {
173  seq_sep_stage1_ = 0.15;
174  seq_sep_stage3_ = 0.5;
175  seq_sep_stage4_ = 1.0;
176  }
177 
178  start_ramp_cstweight_ = option[ fold_cst::reramp_start_cstweight ];
179  ramp_cst_cycles_ = option[ fold_cst::reramp_cst_cycles ];
180  bSkipOnNoViolation_ = option[ fold_cst::skip_on_noviolation_in_stage1 ];
181  constraint_threshold_ = option[ fold_cst::stage2_constraint_threshold ];
182 }
183 
184 //otherwise stage2 cycles remain as in the classic protocol
186  return static_cast< Size >( std::min( 1.0*pose.total_residue(), constraints_->largest_possible_sequence_sep( pose ) * max_seq_sep_fudge_ ) );
187 }
188 
189 // what's an noe_stage?
191  return static_cast< Size >( std::min( factor, 1.0 ) * total_res );
192 }
193 
194 bool
196  Parent::prepare_stage1( pose );
197  tr.Debug << "active constraints \n";
198  return true;
199 }
200 
201 void
203  using namespace basic::options;
204  if ( pose.constraint_set()->has_residue_pair_constraints() ) {
205  tr.Info << "max_seq_sep: " << setting << std::endl;
206  // we really have constraints... lets' get to work
207  if ( !bIgnoreSequenceSeparation() ) {
208  if ( !option[ OptionKeys::fold_cst::no_recover_low_at_constraint_switch ]() ) {
209  mc().recover_low( pose ); //is this really what one should do at this point ?
210  }
211  constraints_->set_max_seq_sep( setting );
213  if ( !bMinTrial_ ) mc().reset( pose ); //is also done by min_trial... don't do it twice
214  }
215  } else if ( !option[ OptionKeys::fold_cst::force_minimize ] ) return; //jump out if no constraints and no force_minimize
216  if ( bMinTrial_ ) {
217  min_trial( pose );
218  }
219 }
220 
221 bool
223  set_max_seq_sep( pose, std::min(3, int(noe_stage( total_res( pose ), seq_sep_stage1_) ) ) );
224  //set_max_seq_sep( pose, 3 ); //yip this is the classic value
225  core::Real old_constraint_score = evaluate_constraint_energy ( pose, mc().score_function() );
226  using namespace basic::options;
227  using namespace basic::options::OptionKeys;
228  moves::MoverOP trial( stage1_mover( pose, trial_large() ) );
229  core::Real const cycle_factor( option[ fold_cst::stage1_ramp_cst_cycle_factor ] );
230  Size const cycles ( static_cast< Size > ( cycle_factor * stage1_cycles() ) );
231  int total_cycles = 0;
232  if ( tr.visible() ) pose.constraint_set()->show_violations( tr, pose, show_viol_level_ );
233  //first run a normal set of fragment insertions until extended chain is lost
234  total_cycles += Parent::do_stage1_cycles( pose );
235  if ( tr.visible() ) pose.constraint_set()->show_violations( tr, pose, show_viol_level_ );
236 
237  if ( pose.constraint_set()->has_residue_pair_constraints() ) {
238  // Now ramp up the seq_sep of the constraints... still on score0
239  for ( Size jk = 3; jk <= noe_stage( total_res( pose ), seq_sep_stage1_); jk += 2 ) {
240  // mc().recover_low( pose ); superfluous -- done in set_max_seq_sep if constraints are actually present
241  set_max_seq_sep( pose, jk);
242  if ( tr.visible() ) pose.constraint_set()->show_violations( tr, pose, show_viol_level_ );
243  if ( old_constraint_score == evaluate_constraint_energy ( pose, mc().score_function() ) ) continue;
244  for ( Size j = 1; j <= cycles; ++j, ++total_cycles ) {
245  // if ( evaluate_constraint_energy( pose, mc().score_function() ) < 10.0 ) break; this is unlikely to be triggered for cnc and always triggered for james-cst
246  if ( numeric::mod( j, (Size)10)==0 && bSkipOnNoViolation_ && pose.constraint_set()->show_violations( tr, pose, 0 ) == 0 ) break;
247  trial->apply( pose );
248  }
249  old_constraint_score = evaluate_constraint_energy ( pose, mc().score_function() );
250  }
251  }
252  return true;
253 }
254 
255 bool
257  set_max_seq_sep( pose, noe_stage( total_res( pose ), seq_sep_stage1_ ) );
258  Parent::prepare_stage2( pose );
259  if ( tr.visible() ) pose.constraint_set()->show_violations( tr, pose, show_viol_level_ );
260  // if ( bMinTrial_ ) min_trial( pose ); done in set_max_seq_sep now
261  return true;
262 }
263 
264 bool
266  set_max_seq_sep( pose, noe_stage( total_res( pose ), seq_sep_stage1_ ) );
267 
268  // first do normal stage2 sampling
269  bool success = Parent::do_stage2_cycles( pose );
270 
271  // if ramp_cycles drop atom_pair_constraint weight to low value and ramp up
272  if ( success && ramp_cst_cycles_ > 500 ) {
273  moves::MoverOP trial( stage2_mover( pose, trial_large() ) );
274  for ( Size loop = 1; loop <= ramp_iterations_; loop++ ) {
275  mc().recover_low( pose );
276  Real const final_weight( current_scorefxn().get_weight( scoring::atom_pair_constraint ) );
277  for ( Size j=1; j<=ramp_cst_cycles_; j++ ) {
278  if ( numeric::mod( j, (Size) 50 ) == 0 ) {
279  Real weight( (start_ramp_cstweight_ + (1.0-start_ramp_cstweight_)*j/ramp_cst_cycles_ )*final_weight );
281  }
282  trial->apply( pose );
283  }
284  }
285  }
286  return success;
287 }
288 
289 bool
290 FoldConstraints::prepare_loop_in_stage3( core::pose::Pose &pose, Size loop_iteration, Size total_iterations ) {
291  /* stage3 rosetta++
292  noe_stage = 15 + (total_residue/2-15)*kk/nloop;
293  classical_constraints::BOUNDARY::set_max_seqSep(noe_stage);
294  */
295  bool success = Parent::prepare_loop_in_stage3( pose, loop_iteration, total_iterations );
296 
297  if ( constraints_ ) {
298  // mc().recover_low( pose ); superfluous -- recover low in set_max_seq_sep if actually necessary
299  core::Real const noe_fact ( seq_sep_stage1_ + ( seq_sep_stage3_ - seq_sep_stage1_) * 1.0*loop_iteration/ total_iterations );
300  tr.Debug << "current noe_fact is " << noe_fact << std::endl;
301  set_max_seq_sep( pose, noe_stage( total_res( pose ), noe_fact) );
302  if ( tr.Info.visible() ) pose.constraint_set()->show_violations( tr, pose, show_viol_level_ );
303 
304  if ( constraint_threshold_ > 0 ) {
305  constraints_->set_max_seq_sep( pose.total_residue() );
307  scoring::ScoreFunction cst_score;
308  cst_score.set_weight( scoring::atom_pair_constraint, 1.0 );
309  core::Real total_cst = cst_score( pose );
310  if ( total_cst > constraint_threshold_ ) {
311  tr.Info << " Constraint threshold violated: " << total_cst << " (limit: " << constraint_threshold_ << " abandon decoy!" << std::endl;
312  return false;
313  }
314  }
315 
316  }
317  return success;
318 }
319 
320 bool
321 FoldConstraints::prepare_loop_in_stage4( core::pose::Pose &pose, Size loop_iteration, Size total_iterations ) {
322  /* stage3 rosetta++
323  noe_stage = 15 + (total_residue/2-15)*kk/nloop;
324  classical_constraints::BOUNDARY::set_max_seqSep(noe_stage);
325  */
326  bool success = Parent::prepare_loop_in_stage4( pose, loop_iteration, total_iterations );
327  // if ( bMinTrial_ ) min_trial( pose ); done in set_max_seq_sep now
328  if ( constraints_ ) {
329  Real const noe_fact ( seq_sep_stage3_ + ( seq_sep_stage4_ - seq_sep_stage3_ ) * 1.0*loop_iteration / total_iterations );
330  tr.Debug << "current noe_fact is " << noe_fact << std::endl;
331  set_max_seq_sep( pose, noe_stage( total_res( pose ), noe_fact ) );
332  }
333  if ( tr.Info.visible() ) pose.constraint_set()->show_violations( tr, pose, show_viol_level_ );
334  return success;
335 }
336 
337 bool
339  bool success = Parent::prepare_stage4( pose );
340  if ( tr.Info.visible() ) pose.constraint_set()->show_violations( tr, pose, show_viol_level_ );
341  return success;
342 }
343 /*
344 bool
345 FoldConstraints::do_stage2_cycles( core::pose::Pose& pose ) {
346 }*/
347 
348 void
350  using namespace scoring;
352  tr.Debug << "switch constraints on..." << std::endl;
354  // set_score_weight( angle_constraint, constraint_weight_ );
355 }
356 
357 
358 void
360  // setup constraints to allow for MaxSeqSep
361  core::scoring::constraints::ConstraintSetOP orig_constraints( NULL );
362  if ( !bIgnoreSequenceSeparation() ) {
363  tr.Debug << "introduce MaxSeqSep Filter for constraints \n";
364  orig_constraints = pose.constraint_set()->clone();
365  constraints_ = new constraints_additional::MaxSeqSepConstraintSet( *orig_constraints, pose.fold_tree() );
366  constraints_->set_max_seq_sep( pose.total_residue() ); // so it is prepared for stage4.
368  }
369 
370  mc().reset( pose );
371  ++run_;
372  // call apply of original protocol
373  Parent::apply( pose );
374 
375  // revert constraints to original form
376  if ( orig_constraints ) {
377  pose.constraint_set( orig_constraints );
378  }
379 }
380 
383  return "FoldConstraints";
384 }
385 
386 void
388  tr.Info << "setup basic minmove" << std::endl;
390  min_move_->movemap( movemap() );
391  min_move_->min_type( "dfpmin" );
392 }
393 
394 //@detail overload if your extension stores additional moves as member variables
396  Parent::set_movemap( mm );
397  if ( min_move_ ) min_move_->movemap( mm );
398 }
399 
400 
402  min_move_ = mm;
403 }
404 
405 void
408  tr.Debug << "start minimization... " << std::endl;
409  current_scorefxn().show( tr.Debug, pose );
410  //get currently used score_function...
411  min_move_->score_function( new core::scoring::ScoreFunction( current_scorefxn() ) );
412  min_move_->apply( pose );
413  mc().reset( pose );
414  tr.Debug << "done with minimization! " << std::endl;
415  if ( tr.Info.visible() ) {
416  tr.Info << "minimized: ";
417  pose.constraint_set()->show_violations( tr.Info, pose, show_viol_level_ );
418  tr.Info << std::endl;
419  }
420 }
421 
422 inline core::Real
424  core::pose::Pose & pose,
425  core::scoring::ScoreFunction const & scfxn
426 ) const {
427  scfxn( pose ); //accumulate energies
428 
429  return
434 
435 }
436 
437 } //abinitio
438 } //protocols
439 
440