Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ClassicAbinitio.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 ClassicAbinitio.cc
11 /// @brief ab-initio fragment assembly protocol for proteins
12 /// @detailed
13 /// Contains currently: Classic Abinitio
14 ///
15 ///
16 /// @author Oliver Lange
17 /// @author James Thompson
18 /// @author Mike Tyka
19 
20 // Unit Headers
23 
24 // Package Headers
26 
27 // Project Headers
28 #include <core/pose/Pose.hh>
30 #include <core/types.hh>
34 #include <core/scoring/rms_util.hh>
35 // AUTO-REMOVED #include <core/pack/task/PackerTask.fwd.hh>
38 
39 #include <protocols/moves/Mover.hh>
46 //#include <protocols/simple_moves/BackboneMover.hh>
47 
48 // AUTO-REMOVED #include <protocols/checkpoint/Checkpoint.hh>
49 
50 // ObjexxFCL Headers
51 #include <ObjexxFCL/string.functions.hh>
52 
53 // Utility headers
54 #include <utility/exit.hh>
55 #include <utility/vector1.fwd.hh>
56 #include <utility/pointer/ReferenceCount.hh>
57 // AUTO-REMOVED #include <utility/file/file_sys_util.hh>
58 // AUTO-REMOVED #include <utility/io/izstream.hh>
59 #include <utility/io/ozstream.hh>
60 #include <numeric/numeric.functions.hh>
61 #include <basic/prof.hh>
62 #include <basic/Tracer.hh>
63 #include <basic/options/option.hh>
64 #include <basic/options/keys/abinitio.OptionKeys.gen.hh>
65 #include <basic/options/keys/run.OptionKeys.gen.hh>
66 #include <basic/options/keys/templates.OptionKeys.gen.hh>
67 
68 //// C++ headers
69 #include <cstdlib>
70 #include <string>
71 #ifdef WIN32
72 #include <ctime>
73 #endif
74 
75 //debug
76 // AUTO-REMOVED #include <core/fragment/FragmentIO.hh>
77 
79 #include <utility/vector0.hh>
80 #include <utility/vector1.hh>
81 
82 
83 static basic::Tracer tr("protocols.abinitio");
84 
85 using core::Real;
86 using namespace core;
87 using namespace basic;
88 using namespace basic::options;
89 using namespace basic::options::OptionKeys;
90 
91 /*!
92 @detail call this:
93 ClassicAbinitio::register_options() before devel::init().
94 Derived classes that overload this function should also call Parent::register_options()
95 */
96 
97 // This method of adding options with macros is a pain in the ass for people
98 // trying to nest ClassicAbinitio as part of other protocols. If you don't call
99 // ClassicAbinitio::register_options() in your main function, you get a really
100 // unintuitive segfault as the options system doesn't know about the options
101 // listed below. The solution is to call register_options() in your main method
102 // before devel::init(), which is really ugly as the main method shouldn't need
103 // to know what protocols are called, and it's prone to error because it's an
104 // easy thing to forget.
105 // This should get some more thought before it becomes the standard way to add options.
106 
109  using namespace basic::options;
110  using namespace basic::options::OptionKeys;
111  option.add_relevant( OptionKeys::abinitio::increase_cycles );
112  option.add_relevant( OptionKeys::abinitio::smooth_cycles_only );
113  option.add_relevant( OptionKeys::abinitio::debug );
114  option.add_relevant( OptionKeys::abinitio::skip_convergence_check );
115  option.add_relevant( OptionKeys::abinitio::log_frags );
116  option.add_relevant( OptionKeys::abinitio::only_stage1 );
117  option.add_relevant( OptionKeys::abinitio::end_bias );
118  option.add_relevant( OptionKeys::abinitio::symmetry_residue );
119  option.add_relevant( OptionKeys::abinitio::vdw_weight_stage1 );
120  option.add_relevant( OptionKeys::abinitio::override_vdw_all_stages );
121  option.add_relevant( OptionKeys::abinitio::recover_low_in_stages );
122  option.add_relevant( OptionKeys::abinitio::close_chbrk );
123 }
124 
125 
126 namespace protocols {
127 namespace abinitio {
128 
129 //little helper function
131  return find( vec.begin(), vec.end(), query) != vec.end();
132 }
133 
134 /// @detail large (stage1/stage2)
135 /// small(stage2/stage3/stage4)
136 /// smooth_small ( stage3/stage4)
137 ClassicAbinitio::ClassicAbinitio(
138  simple_moves::FragmentMoverOP brute_move_small,
139  simple_moves::FragmentMoverOP brute_move_large,
140  simple_moves::FragmentMoverOP smooth_move_small,
141  int /*dummy otherwise the two constructors are ambiguous */
142 ) :
143  brute_move_small_( brute_move_small ),
144  brute_move_large_( brute_move_large ),
145  smooth_move_small_( smooth_move_small )
146 {
147  BaseClass::type( "ClassicAbinitio" );
148  get_checkpoints().set_type("ClassicAbinitio");
149  // std::cerr << "ClassicAbinitio::constructor has stubbed out...(fatal) see code file";
150  // runtime_assert( 0 ); //---> needs more implementation to use this constructor: e.g. read out movemap from FragmentMover...
151  movemap_ = brute_move_large->movemap();
152  // set_defaults( pose ); in constructor virtual functions are not called
153  bSkipStage1_ = false;
154  bSkipStage2_ = false;
155 
156  close_chbrk_ = false;
157 }
158 
160  core::fragment::FragSetCOP fragset_small,
161  core::fragment::FragSetCOP fragset_large,
163 ) :
164  movemap_( movemap )
165 {
166  BaseClass::type( "ClassicAbinitio" );
167  get_checkpoints().set_type("ClassicAbinitio");
168  using namespace basic::options;
175  if ( option[ OptionKeys::abinitio::log_frags ].user() ) {
176  if ( !option[ OptionKeys::abinitio::debug ] ) utility_exit_with_message( "apply option abinitio::log_frags always together with abinitio::debug!!!");
177  bms = new simple_moves::LoggedFragmentMover( fragset_small, movemap );
178  bml = new simple_moves::LoggedFragmentMover( fragset_large, movemap );
179  sms = new SmoothFragmentMover( fragset_small, movemap, new GunnCost );
180  } else if ( option[ OptionKeys::abinitio::symmetry_residue ].user() ) {
181  Size const sr ( option[ OptionKeys::abinitio::symmetry_residue ] );
182  bms = new SymmetricFragmentMover( fragset_small, movemap, sr );
183  bml = new SymmetricFragmentMover( fragset_large, movemap, sr );
184  sms = new SmoothSymmetricFragmentMover( fragset_small, movemap, new GunnCost, sr );
185  } else {
186  bms = new ClassicFragmentMover( fragset_small, movemap );
187  bml = new ClassicFragmentMover( fragset_large, movemap );
188  sms = new SmoothFragmentMover ( fragset_small, movemap, new GunnCost );
189  }
190 
191  bms->set_end_bias( option[ OptionKeys::abinitio::end_bias ] ); //default is 30.0
192  bml->set_end_bias( option[ OptionKeys::abinitio::end_bias ] );
193  sms->set_end_bias( option[ OptionKeys::abinitio::end_bias ] );
194 
195  brute_move_small_ = bms;
196  brute_move_large_ = bml;
197  smooth_move_small_ = sms;
198 
199  bSkipStage1_ = false;
200  bSkipStage2_ = false;
201 
202  close_chbrk_ = false;
203 }
204 
205 /// @details Call parent's copy constructor and perform a shallow
206 /// copy of all the data. NOTE: Shallow copy is only to preserve
207 /// behavior pre 9/7/2009 when the compiler-provided copy constructor
208 /// was being invoked.
210  //utility::pointer::ReferenceCount(),
211  Parent( src )
212 {
227  bQuickTest_ = src.bQuickTest_;
230  movemap_ = src.movemap_;
231  mc_ = src.mc_;
245 }
246 
247 /// @brief Explicit destructor is needed to destroy all the OPs
248 /// The compiler does all the work, but it requires that we place
249 /// the destructor in the .cc file.
251 {}
252 
253 /// @brief setup moves, mc-object, scores
254 /// @details can't call this from constructor; virtual functions don't operate until construction has completed.
255 
256 void
258  // Parent::init( pose );
259  set_defaults( pose );
260  // bInitialized_ = true;
261 }
262 
263 /// @brief ClassicAbinitio has virtual functions... use this to obtain a new instance
266 {
267  return new ClassicAbinitio( *this );
268 }
269 
271  using namespace moves;
272  using namespace scoring;
273  using namespace scoring::constraints;
274 
275  Parent::apply( pose );
276  if ( option[ OptionKeys::run::dry_run ]() ) return;
277 
278  //basic::prof_reset();
279 
280 
281  bool success( true );
282  total_trials_ = 0;
283 
284  if ( !bSkipStage1_ ) {
285  PROF_START( basic::STAGE1 );
286  clock_t starttime = clock();
287 
288  if ( !prepare_stage1( pose ) ) {
290  return;
291  }
292  // part 1 ----------------------------------------
293  tr.Info << "\n===================================================================\n";
294  tr.Info << " Stage 1 \n";
295  tr.Info << " Folding with score0 for max of " << stage1_cycles() << std::endl;
296 
297  if ( option[ basic::options::OptionKeys::run::profile ] ) prof_show();
299  output_debug_structure( pose, "stage0" );
300  }
301  if (!get_checkpoints().recover_checkpoint( pose, get_current_tag(), "stage_1", false /* fullatom*/, true /*fold tree */ )) {
302  ConstraintSetOP orig_constraints(NULL);
303  orig_constraints = pose.constraint_set()->clone();
304  success = do_stage1_cycles( pose );
305 
306  if ( tr.Info.visible() ) current_scorefxn().show( tr, pose );
307  recover_low( pose, STAGE_1 );
308  mc().show_counters();
310  mc().reset_counters();
311 
312  pose.constraint_set( orig_constraints ); // restore constraints - this is critical for checkpointing to work
313  get_checkpoints().checkpoint( pose, get_current_tag(), "stage_1", true /*fold tree */ );
314  } //recover checkpoint
315  get_checkpoints().debug( get_current_tag(), "stage_1", current_scorefxn()( pose ) );
316 
317  clock_t endtime = clock();
318  PROF_STOP( basic::STAGE1 );
319  if ( option[ basic::options::OptionKeys::run::profile ] ) prof_show();
321  tr.Info << "Timeperstep: " << (double(endtime) - starttime )/(CLOCKS_PER_SEC ) << std::endl;
322  output_debug_structure( pose, "stage1" );
323  }
324  } //skipStage1
325  if ( !success ) {
327  return;
328  }
329 
330 
331  if ( !bSkipStage2_ ) {
332 
333  //
334  //
335  // part 2 ----------------------------------------
336  tr.Info << "\n===================================================================\n";
337  tr.Info << " Stage 2 \n";
338  tr.Info << " Folding with score1 for " << stage2_cycles() << std::endl;
339 
340  PROF_START( basic::STAGE2 );
341  clock_t starttime = clock();
342 
343 
344  if ( close_chbrk_ ){
345  Real const setting( 0.25 );
347  tr.Info << " Chain_break score assigned " << std::endl;
348  }
349 
350 
351  if ( !prepare_stage2( pose ) ) {
353  return;
354  }
355 
356  if (!get_checkpoints().recover_checkpoint( pose, get_current_tag(), "stage_2", false /* fullatom */, true /*fold tree */ )) {
357  ConstraintSetOP orig_constraints(NULL);
358  orig_constraints = pose.constraint_set()->clone();
359 
360  success = do_stage2_cycles( pose );
361  recover_low( pose, STAGE_2 ); //default OFF: seems to be a bad choice after score0
362 
363  if ( tr.visible() ) current_scorefxn().show( tr, pose );
364  mc().show_counters();
366  mc().reset_counters();
367 
368  pose.constraint_set( orig_constraints ); // restore constraints - this is critical for checkpointing to work
369  get_checkpoints().checkpoint( pose, get_current_tag(), "stage_2", true /*fold tree */ );
370  }
371  get_checkpoints().debug( get_current_tag(), "stage_2", current_scorefxn()( pose ) );
372 
373  clock_t endtime = clock();
374  PROF_STOP( basic::STAGE2 );
375  if ( option[ basic::options::OptionKeys::run::profile ] ) prof_show();
377  output_debug_structure( pose, "stage2" );
378  tr << "Timeperstep: " << (double(endtime) - starttime )/(CLOCKS_PER_SEC ) << std::endl;
379  }
380  } //bSkipStage2
381 
382  if ( !success ) {
384  return;
385  }
386 
387  if ( !bSkipStage3_ ) {
388  // moved checkpointing into do_stage3_cycles because of structure store
389 
390  // part 3 ----------------------------------------
391  tr.Info << "\n===================================================================\n";
392  tr.Info << " Stage 3 \n";
393  tr.Info << " Folding with score2 and score5 for " << stage3_cycles() <<std::endl;
394 
395  PROF_START( basic::STAGE3 );
396  clock_t starttime = clock();
397 
398  if ( !prepare_stage3( pose ) ) {
400  return;
401  }
402  // this is not the final score-function.. only known after prepare_loop_in_stage3
403  // because this is confusing rather not show.if ( tr.Info.visible() ) current_scorefxn().show( tr, pose );
404 
405  success = do_stage3_cycles( pose );
406  recover_low( pose, STAGE_3b );
407 
408  if ( tr.Info.visible() ) current_scorefxn().show( tr, pose );
409  mc().show_counters();
411  mc().reset_counters();
412 
413  clock_t endtime = clock();
414  PROF_STOP( basic::STAGE3);
415  if ( option[ basic::options::OptionKeys::run::profile ] ) prof_show();
417  output_debug_structure( pose, "stage3" );
418  tr << "Timeperstep: " << (double(endtime) - starttime )/( CLOCKS_PER_SEC) << std::endl;
419  }
420 
421  // pose.dump_pdb("stage3.pdb");
422 
423  }
424 
425  if ( !success ) {
427  return;
428  }
429  if ( !bSkipStage4_ ) {
430 
431  // part 4 ------------------------------------------
432  tr.Info << "\n===================================================================\n";
433  tr.Info << " Stage 4 \n";
434  tr.Info << " Folding with score3 for " << stage4_cycles() <<std::endl;
435 
436  PROF_START( basic::STAGE4 );
437  clock_t starttime = clock();
438 
439  if ( !prepare_stage4( pose ) ) {
441  return;
442  }
443 
444  //score-fxn may be changed in do_stage4_cycles...
445  // confusing if shown here already... if ( tr.Info.visible() ) current_scorefxn().show( tr, pose);
446  success = do_stage4_cycles( pose );
447  recover_low( pose, STAGE_4 );
448 
449  if ( tr.Info.visible() ) current_scorefxn().show( tr, pose);
450  mc().show_counters();
452  mc().reset_counters();
453 
454  clock_t endtime = clock();
455  PROF_STOP( basic::STAGE4 );
456  if ( option[ basic::options::OptionKeys::run::profile ] ) prof_show();
458  output_debug_structure( pose, "stage4" );
459  tr << "Timeperstep: " << (double(endtime) - starttime )/( CLOCKS_PER_SEC ) << std::endl;
460  }
461 
462  tr.Info << "\n===================================================================\n";
463  tr.Info << " Finished Abinitio \n";
464  tr.Info << std::endl;
465  // pose.dump_pdb("stage4.pdb");
466  }
467 
468  if ( !bSkipStage5_ ) {
469 
470  // part 5 ------------------------------------------
471  tr.Info << "\n===================================================================\n";
472  tr.Info << " Stage 5 \n";
473  tr.Info << " Folding with score3 for " << stage5_cycles() <<std::endl;
474 
475  PROF_START( basic::STAGE5 );
476  clock_t starttime = clock();
477 
478  if ( !prepare_stage5( pose ) ) {
480  return;
481  }
482 
483  success = do_stage5_cycles( pose );
484  recover_low( pose, STAGE_5 );
485 
486  if ( tr.Info.visible() ) current_scorefxn().show( tr, pose);
487  // current_scorefxn().show(tr, pose);
488  mc().show_counters();
490  mc().reset_counters();
491 
492  clock_t endtime = clock();
493  PROF_STOP( basic::STAGE5 );
494  if ( option[ basic::options::OptionKeys::run::profile ] ) prof_show();
496  output_debug_structure( pose, "stage5" );
497  tr << "Timeperstep: " << (double(endtime) - starttime )/( CLOCKS_PER_SEC ) << std::endl;
498  }
499 
500  tr.Info << "\n===================================================================\n";
501  tr.Info << " Now really finished Abinitio \n";
502  tr.Info << std::endl;
503  // pose.dump_pdb("stage5.pdb");
504 
505  }
506 
507 
509 
510  if ( !success ) set_last_move_status( moves::FAIL_RETRY );
511 
512  //basic::prof_show();
513 
514  return;
515 }// ClassicAbinitio::apply( pose::Pose & pose )
516 
517 
520  return "ClassicAbinitio";
521 }
522 
523 //@brief return FramgentMover for smooth_small fragment insertions (i.e., stage4 moves)
526  return smooth_move_small_;
527 }
528 
529 //@brief return FragmentMover for small fragment insertions ( i.e., stage3/4 moves )
532  return brute_move_small_;
533 }
534 
535 //@brief return FragmentMover for large fragment insertions (i.e., stage1/2 moves )
538  return brute_move_large_;
539 }
540 
541 //@brief change the movemap ( is propagated to mover-objects )
542 //@detail overload if your extension stores additional moves as member variables
543 void
545 {
546  movemap_ = mm;
547  if ( smooth_move_small_ ) smooth_move_small_->set_movemap( mm );
548  if ( brute_move_small_ ) brute_move_small_ ->set_movemap( mm );
549  if ( brute_move_large_ ) brute_move_large_ ->set_movemap( mm );
550 }
551 
552 //@brief set new instances of FragmentMovers
553 void
558 )
559 {
563  update_moves();
564 }
565 
566 //@brief returns current movemap
569  return movemap_;
570 }
571 
572 //@detail read cmd_line options and set default versions for many protocol members: trials/moves, score-functions, Monte-Carlo
574  temperature_ = 2.0;
575  bSkipStage1_ = false;
576  bSkipStage2_ = false;
577  bSkipStage3_ = false;
578  bSkipStage4_ = false;
579  bSkipStage5_ = true; //vats is turned off by default
582  set_default_mc( pose, *score_stage1_ );
583  update_moves();
584 }
585 
586 //@detail called to notify about changes in Movers: new movemap or Moverclass
588  /* set apply_large_frags_ and
589  short_insert_region_
590  */
591  /* what about move-map ? It can be set manually for all Fragment_Moves .. */
592  // set_move_map();
593  set_trials();
594 }
595 
596 //@detail create instances of TrialMover for our FragmentMover objects
598  // setup loop1
599  runtime_assert( brute_move_large_ );
601  //trial_large_->set_keep_stats( true );
602  trial_large_->keep_stats_type( moves::accept_reject );
603 
604  runtime_assert( brute_move_small_ );
606  //trial_small_->set_keep_stats( true );
607  trial_small_->keep_stats_type( moves::accept_reject );
608 
609  runtime_assert( smooth_move_small_ );
611  //smooth_trial_small_->set_keep_stats( true );
612  smooth_trial_small_->keep_stats_type( moves::accept_reject );
613 }
614 
615 //@detail sets Monto-Carlo object to default
617  pose::Pose const & pose,
618  scoring::ScoreFunction const & scorefxn
619 ) {
620  set_mc( new moves::MonteCarlo( pose, scorefxn, temperature_ ) );
621 }
622 
623 //@detail sets Monto-Carlo object
625  mc_ = mc_in;
626  if ( trial_large_ ) trial_large_->set_mc( mc_ );
627  if ( trial_small_ ) trial_small_->set_mc( mc_ );
628  if ( smooth_trial_small_ ) smooth_trial_small_->set_mc( mc_ );
629 }
630 
631 //@detail override cmd-line setting for "increase_cycling"
632 void ClassicAbinitio::set_cycles( Real increase_cycles ) {
633  stage1_cycles_ = static_cast< int > (2000 * increase_cycles);
634  stage2_cycles_ = static_cast< int > (2000 * increase_cycles);
635  stage3_cycles_ = static_cast< int > (2000 * increase_cycles);
636  stage4_cycles_ = static_cast< int > (4000 * increase_cycles);
637  stage5_cycles_ = static_cast< int > (50000* increase_cycles);//vats
638 
639  using namespace basic::options;
640  if ( option[ OptionKeys::abinitio::only_stage1 ]() ) {
641  stage2_cycles_ = 0;
642  stage3_cycles_ = 0;
643  stage4_cycles_ = 0;
644  bSkipStage2_ = bSkipStage3_ = /*bSkipStage3_ =*/ true; // Was bSkipStage4_ meant? ~Labonte
645  }
646 }
647 
649  using namespace scoring;
650  using namespace basic::options;
651  using namespace basic::options::OptionKeys;
652 
653  tr.Debug << "creating standard scoring functions" << std::endl;
654 
655  if ( option[ OptionKeys::abinitio::stage1_patch ].user() ) {
656  score_stage1_ = ScoreFunctionFactory::create_score_function( "score0", option[ OptionKeys::abinitio::stage1_patch ]() );
657  } else {
659  }
660 
661  if ( option[ OptionKeys::abinitio::stage2_patch ].user() ) {
662  score_stage2_ = ScoreFunctionFactory::create_score_function( "score1", option[ OptionKeys::abinitio::stage2_patch ]() );
663  } else {
665  }
666 
667  if ( option[ OptionKeys::abinitio::stage3a_patch ].user() ) {
668  score_stage3a_ = ScoreFunctionFactory::create_score_function( "score2", option[ OptionKeys::abinitio::stage3a_patch ]() );
669  } else {
671  }
672 
673  if ( option[ OptionKeys::abinitio::stage3b_patch ].user() ) {
674  score_stage3b_ = ScoreFunctionFactory::create_score_function( "score5", option[ OptionKeys::abinitio::stage3b_patch ]() );
675  } else {
677  }
678 
679  if ( option[ OptionKeys::abinitio::stage4_patch ].user() ) {
680  score_stage4_ = ScoreFunctionFactory::create_score_function( "score3", option[ OptionKeys::abinitio::stage4_patch ]() );
681  } else {
683  }
684 
685  if ( option[ OptionKeys::abinitio::stage5_patch ].user() ) { //vats
686  score_stage5_ = ScoreFunctionFactory::create_score_function( "score3", option[ OptionKeys::abinitio::stage5_patch ]() );
687  } else {
689  }
690 
691 
692  if ( option[ OptionKeys::abinitio::override_vdw_all_stages ] ) {
693  set_score_weight( scoring::vdw, option[ OptionKeys::abinitio::vdw_weight_stage1 ], ALL_STAGES );
694  }
695 }
696 
697 
698 /// @brief sets a score weight for all stages of abinitio
700  tr.Debug << "set score weights for ";
701  if ( stage == ALL_STAGES ) tr.Debug << "all stages ";
702  else tr.Debug << "stage " << (stage <= STAGE_3a ? stage : ( stage-1 ) ) << ( stage == STAGE_3b ? "b " : " " );
703  tr.Debug << scoring::name_from_score_type(type) << " " << setting << std::endl;
704  if (score_stage1_ && ( stage == STAGE_1 || stage == ALL_STAGES )) score_stage1_ ->set_weight(type, setting);
705  if (score_stage2_ && ( stage == STAGE_2 || stage == ALL_STAGES )) score_stage2_ ->set_weight(type, setting);
706  if (score_stage3a_ && ( stage == STAGE_3a || stage == ALL_STAGES )) score_stage3a_->set_weight(type, setting);
707  if (score_stage3b_ && ( stage == STAGE_3b || stage == ALL_STAGES )) score_stage3b_->set_weight(type, setting);
708  if (score_stage4_ && ( stage == STAGE_4 || stage == ALL_STAGES )) score_stage4_ ->set_weight(type, setting);
709  if (score_stage5_ && ( stage == STAGE_5 || stage == ALL_STAGES )) score_stage5_ ->set_weight(type, setting);//vats
710 }
711 
712 //@brief currently used score function ( depends on stage )
714  return mc().score_function();
715 }
716 
717 //@brief set current scorefunction
719  mc().score_function( scorefxn );
720 }
721 
722 //@brief set individual weight of current scorefunction --- does not change the predefined scores: score_stageX_
724  scoring::ScoreFunction scorefxn ( mc().score_function() );
725  scorefxn.set_weight( type, setting );
726  mc().score_function( scorefxn ); //trigger rescore
727 }
728 
731  bSkipStage5_ = true; //vats turned off by default
732  using namespace basic::options;
733  just_smooth_cycles_ = option[ OptionKeys::abinitio::smooth_cycles_only ]; // defaults to false
734  bQuickTest_ = basic::options::option[ basic::options::OptionKeys::run::test_cycles ]();
735 
736  if ( bQuickTest() ) {
737  set_cycles( 0.001 );
738  } else {
739  set_cycles( option[ OptionKeys::abinitio::increase_cycles ] ); // defaults to factor of 1.0
740  }
741 
742  if ( just_smooth_cycles_ ) {
744  }
745  if ( option[ OptionKeys::abinitio::only_stage1 ] ) {
747  }
748 
749  if ( option[ OptionKeys::abinitio::include_stage5 ] ) {
750  bSkipStage5_ = false;
751  }
752 
753  apply_large_frags_ = true; // apply large frags in phase 2!
754 
755  // in rosetta++ switched on in fold_abinitio if contig_size < 30 in pose_abinitio never
756  short_insert_region_ = false; // apply small fragments in phase 2!
757 
758  if ( option[ OptionKeys::abinitio::recover_low_in_stages ].user() ) {
759  for ( IntegerVectorOption::const_iterator it = option[ OptionKeys::abinitio::recover_low_in_stages ]().begin(),
760  eit = option[ OptionKeys::abinitio::recover_low_in_stages ]().end(); it!=eit; ++it ) {
761  if ( *it == 1 ) recover_low_stages_.push_back( STAGE_1 );
762  else if ( *it == 2 ) recover_low_stages_.push_back( STAGE_2 );
763  else if ( *it == 3 ) {
764  recover_low_stages_.push_back( STAGE_3a );
765  recover_low_stages_.push_back( STAGE_3b );
766  }
767  else if ( *it == 4 ) recover_low_stages_.push_back( STAGE_4 );
768  }
769  } else {
770  recover_low_stages_.clear();
771  recover_low_stages_.push_back( STAGE_1 );
772  recover_low_stages_.push_back( STAGE_2 );
773  recover_low_stages_.push_back( STAGE_3a );
774  recover_low_stages_.push_back( STAGE_3b );
775  recover_low_stages_.push_back( STAGE_4 );
776  recover_low_stages_.push_back( STAGE_5 );
777  }
778 
779  close_chbrk_ = option[ OptionKeys::abinitio::close_chbrk ];
780 
781 }
782 
783 
784 /// @brief (helper) functor class which keeps track of old pose for the
785 /// convergence check in stage3 cycles
786 /// @detail
787 /// calls of operator ( pose ) compare the
790 
792 public:
793  hConvergenceCheck() : bInit_( false ), ct_( 0 ) {}
794  void reset() { ct_ = 0; bInit_ = false; }
796  trials_ = trin;
797  runtime_assert( trials_->keep_stats_type() < moves::no_stats );
798  last_move_ = 0;
799  }
800  virtual bool operator() ( const core::pose::Pose & pose );
801 private:
803  bool bInit_;
807 };
808 
809 // keep going --> return true
811  if ( !bInit_ ) {
812  bInit_ = true;
813  very_old_pose_ = pose;
814  return true;
815  }
816  runtime_assert( trials_ );
817  tr.Trace << "TrialCounter in hConvergenceCheck: " << trials_->num_accepts() << std::endl;
818  if ( numeric::mod(trials_->num_accepts(),100) != 0 ) return true;
819  if ( (Size) trials_->num_accepts() <= last_move_ ) return true;
820  last_move_ = trials_->num_accepts();
821  // change this later to this: (after we compared with rosetta++ and are happy)
822  // if ( numeric::mod(++ct_, 1000) != 0 ) return false; //assumes an approx acceptance rate of 0.1
823 
824  // still here? do the check:
825 
826  core::Real converge_rms = core::scoring::CA_rmsd( very_old_pose_, pose );
827  very_old_pose_ = pose;
828  if ( converge_rms >= 3.0 ) {
829  return true;
830  }
831  // if we get here thing is converged stop the While-Loop
832  tr.Info << " stop cycles in stage3 due to convergence " << std::endl;
833  return false;
834 }
835 
836 
838  AllResiduesChanged done( pose, brute_move_large()->insert_map(), *movemap() );
839  moves::MoverOP trial( stage1_mover( pose, trial_large() ) );
840 
841  // FragmentMoverOP frag_mover = brute_move_large_;
842  // fragment::FragmentIO().write("stage1_frags_classic.dat",*frag_mover->fragments());
843 
844  Size j;
845  for ( j = 1; j <= stage1_cycles(); ++j ) {
846  trial->apply( pose ); // apply a large fragment insertion, accept with MC boltzmann probability
847  if ( done(pose) ) {
848  tr.Info << "Replaced extended chain after " << j << " cycles." << std::endl;
849  mc().reset( pose ); // make sure that we keep the final structure
850  return true;
851  }
852  }
853  tr.Warning << "Warning: extended chain may still remain after " << stage1_cycles() << " cycles!" << std::endl;
854  done.show_unmoved( pose, tr.Warning );
855  mc().reset( pose ); // make sure that we keep the final structure
856  return true;
857 }
858 
860 
861  //setup cycle
863  if ( apply_large_frags_ ) cycle->add_mover( trial_large_->mover() );
864  if ( short_insert_region_ ) cycle->add_mover( trial_small_->mover() );
865 
866  Size nr_cycles = stage2_cycles() / ( short_insert_region_ ? 2 : 1 );
867  moves::TrialMoverOP trials = new moves::TrialMover( cycle, mc_ptr() );
868  moves::RepeatMover( stage2_mover( pose, trials ), nr_cycles ).apply(pose);
869 
870  //is there a better way to find out how many steps ? for instance how many calls to scoring?
871  return true; // as best guess
872 }
873 
874 /*! @detail stage3 cycles:
875  nloop1 : outer iterations
876  nloop2 : inner iterations
877  stage3_cycle : trials per inner iteration
878  every inner iteration we switch between score_stage3a ( default: score2 ) and score_stage3b ( default: score 5 )
879 
880  prepare_loop_in_stage3() is called before the stage3_cycles() of trials are started.
881 
882  first outer loop-iteration is done with TrialMover trial_large()
883  all following iterations with trial_small()
884 
885  start each iteration with the lowest_score_pose. ( mc->recover_low() -- called in prepare_loop_in_stage3() )
886 
887 */
889  using namespace ObjexxFCL;
890 
891  // interlaced score2 / score 5 loops
892  // nloops1 and nloops2 could become member-variables and thus changeable from the outside
893  int nloop1 = 1;
894  int nloop2 = 10; //careful: if you change these the number of structures in the structure store changes.. problem with checkpointing
895  // individual checkpoints for each stage3 iteration would be a remedy. ...
896 
897  if ( short_insert_region_ ) {
898  nloop1 = 2;
899  nloop2 = 5;
900  }
901 
902  hConvergenceCheckOP convergence_checker ( NULL );
903  if ( !option[ basic::options::OptionKeys::abinitio::skip_convergence_check ] ) {
904  convergence_checker = new hConvergenceCheck;
905  }
906 
907  moves::TrialMoverOP trials = trial_large();
908  int iteration = 1;
909  for ( int lct1 = 1; lct1 <= nloop1; lct1++) {
910  if ( lct1 > 1 ) trials = trial_small(); //only with short_insert_region!
911  for ( int lct2 = 1; lct2 <= nloop2; lct2++, iteration++ ) {
912  tr.Debug << "Loop: " << lct1 << " " << lct2 << std::endl;
913 
914  if ( !prepare_loop_in_stage3( pose, iteration, nloop1*nloop2 ) ) return false;
915 
916  if ( !get_checkpoints().recover_checkpoint( pose, get_current_tag(), "stage_3_iter"+string_of( lct1)+"_"+string_of(lct2),
917  false /*fullatom */, true /*fold tree */ )) {
918 
919 
920  tr.Debug << " Score stage3 loop iteration " << lct1 << " " << lct2 << std::endl;
921  if ( convergence_checker ) {
922  moves::TrialMoverOP stage3_trials = stage3_mover( pose, lct1, lct2, trials );
923  convergence_checker->set_trials( stage3_trials ); //can be removed late
924  moves::WhileMover( stage3_trials, stage3_cycles(), convergence_checker ).apply( pose );
925  } else { //no convergence check -> no WhileMover
926  moves::RepeatMover( stage3_mover( pose, lct1, lct2, trials ), stage3_cycles() ).apply( pose );
927  }
928 
929  if ( numeric::mod( (int)iteration, 2 ) == 0 || iteration > 7 ) recover_low( pose, STAGE_3a );
930  recover_low( pose, STAGE_3b );
931 
932  get_checkpoints().checkpoint( pose, get_current_tag(), "stage_3_iter"+string_of( lct1)+"_"+string_of(lct2), true /*fold tree */ );
933  }//recover_checkpoint
934  get_checkpoints().debug( get_current_tag(), "stage_3_iter"+string_of( lct1)+"_"+string_of(lct2), current_scorefxn()( pose ) );
935 
936  // structure_store().push_back( mc_->lowest_score_pose() );
937  } // loop 2
938  } // loop 1
939  return true;
940 }
941 
942 
943  // interlaced score2 / score 5 loops
944 /*! @detail stage4 cycles:
945  nloop_stage4: iterations
946  stage4_cycle : trials per iteration
947 
948  first iteration: use trial_small()
949  following iterations: use trial_smooth()
950  only trial_smooth() if just_smooth_cycles==true
951 
952  prepare_loop_in_stage4() is called each time before the stage4_cycles_ of trials are started.
953 
954  start each iteration with the lowest_score_pose. ( mc->recover_low() in prepare_loop_in_stage4() )
955 
956 */
958  Size nloop_stage4 = 3;
959 
960  for ( Size kk = 1; kk <= nloop_stage4; ++kk ) {
961  tr.Debug << "prepare ..." << std::endl ;
962  if ( !prepare_loop_in_stage4( pose, kk, nloop_stage4 ) ) return false;
963 
964  if (!get_checkpoints().recover_checkpoint( pose, get_current_tag(), "stage4_kk_" + ObjexxFCL::string_of(kk), false /* fullatom */, true /* fold_tree */ )) {
965  moves::TrialMoverOP trials;
966  if ( kk == 1 && !just_smooth_cycles_ ) {
967  trials = trial_small();
968  } else {
969  tr.Debug << "switch to smooth moves" << std::endl;
970  trials = trial_smooth();
971  }
972 
973  tr.Debug << "start " << stage4_cycles() << " cycles" << std::endl;
974  moves::RepeatMover( stage4_mover( pose, kk, trials ), stage4_cycles() ).apply(pose);
975  tr.Debug << "finished" << std::endl;
976  recover_low( pose, STAGE_4 );
977 
978  get_checkpoints().checkpoint( pose, get_current_tag(), "stage4_kk_" + ObjexxFCL::string_of(kk), true /*fold tree */ );
979  }
980  get_checkpoints().debug( get_current_tag(), "stage4_kk_" + ObjexxFCL::string_of(kk), current_scorefxn()( pose ) );
981 
982 
983  //don't store last structure since it will be exactly the same as the final structure delivered back via apply
984  // if( kk < nloop_stage4 ) // <-- this line was missing although the comment above was existant.
985  // structure_store().push_back( mc_->lowest_score_pose() );
986  } // loop kk
987  return true;
988 }
989 
991 
992  Size nmoves = 1;
994  simple_moves::SmallMoverOP small_mover( new simple_moves::SmallMover( mm_temp, temperature_, nmoves) );
995  small_mover->angle_max( 'H', 2.0 );
996  small_mover->angle_max( 'E', 2.0 );
997  small_mover->angle_max( 'L', 5.0 );
998 
999  moves::TrialMoverOP trials = new moves::TrialMover( small_mover, mc_ptr() );
1000  moves::RepeatMover( stage5_mover( pose, trials ), stage5_cycles() ).apply( pose );
1001 
1002  // moves::MoverOP trial( stage5_mover( pose, small_mover ) );
1003  // Size j;
1004  // for( j = 1; j <= stage5_cycles(); ++j ) {
1005  // trial->apply( pose );
1006  // }
1007  mc().reset( pose );
1008  return true;
1009 
1010 }
1011 
1012 
1015  return trials;
1016 }
1017 
1018 
1021  return trials;
1022 }
1023 
1024 
1027  return trials;
1028 }
1029 
1032  return trials;
1033 }
1034 
1035 moves::TrialMoverOP //vats
1037  return trials;
1038 }
1039 
1040 
1041 
1043  if ( contains_stageid( recover_low_stages_, stage ) ) {
1044  mc_->recover_low( pose );
1045  }
1046 }
1047 
1048 // anything you want to have done before the stages ?
1049 void ClassicAbinitio::replace_scorefxn( core::pose::Pose& pose, StageID stage, core::Real /*intra_stage_progress */ ) {
1050  // must assume that the current pose is the one to be accepted into the next stage! (this change was necessary for
1051  // checkpointing to work correctly.
1052 
1053  //intra_stage_progress = intra_stage_progress;
1054  if (score_stage1_ && ( stage == STAGE_1 )) current_scorefxn( *score_stage1_ );
1055  if (score_stage2_ && ( stage == STAGE_2 )) current_scorefxn( *score_stage2_ );
1056  if (score_stage3a_ && ( stage == STAGE_3a)) current_scorefxn( *score_stage3a_ );
1057  if (score_stage3b_ && ( stage == STAGE_3b)) current_scorefxn( *score_stage3b_ );
1058  if (score_stage4_ && ( stage == STAGE_4 )) current_scorefxn( *score_stage4_ );
1059  if (score_stage5_ && ( stage == STAGE_5 )) current_scorefxn( *score_stage5_ );//vats
1060  Real temperature( temperature_ );
1061  if ( stage == STAGE_5 ) temperature = 0.5;
1062  mc_->set_autotemp( true, temperature );
1063  mc_->set_temperature( temperature ); // temperature might have changed due to autotemp..
1064  mc_->reset( pose );
1065 }
1066 
1067 
1070 }
1071 
1073  return trial_small_;
1074 }
1075 
1077  return smooth_trial_small_;
1078 }
1079 
1080 
1081 // prepare stage1 sampling
1083  replace_scorefxn( pose, STAGE_1, 0.5 );
1084  mc_->set_autotemp( false, temperature_ );
1085  // mc_->set_temperature( temperature_ ); already done in replace_scorefxn
1086  // mc_->reset( pose );
1087  (*score_stage1_)( pose );
1088  /// Now handled automatically. score_stage1_->accumulate_residue_total_energies( pose ); // fix this
1089  return true;
1090 }
1091 
1093  replace_scorefxn( pose, STAGE_2, 0.5 );
1094 
1095  (*score_stage2_)(pose);
1096  /// Now handled automatically. score_stage2_->accumulate_residue_total_energies( pose );
1097  return true;
1098 }
1099 
1100 
1102  replace_scorefxn( pose, STAGE_3a, 0 );
1103  //score for this stage is changed in the do_stage3_cycles explicitly
1104  if ( option[ templates::change_movemap ].user() && option[ templates::change_movemap ] == 3 ) {
1106  new_mm->set_bb( true );
1107  set_movemap( new_mm ); // --> store it in movemap_ --> original will be reinstated at end of apply()
1108  }
1109  return true;
1110 }
1111 
1112 
1114  replace_scorefxn( pose, STAGE_4, 0 );
1115  (*score_stage4_)( pose );
1116  /// Now handled automatically. score_stage4_->accumulate_residue_total_energies( pose ); // fix this
1117 
1118  if ( option[ templates::change_movemap ].user() && option[ templates::change_movemap ] == 4 ) {
1120  new_mm->set_bb( true );
1121  tr.Debug << "option: templates::change_movemap ACTIVE: set_movemap" << std::endl;
1122  set_movemap( new_mm ); // --> store it in movemap_ --> original will be reinstated at end of apply()
1123  }
1124  return true;
1125 }
1126 
1127 
1129  // temperature_ = 0.5; //this has to be reset to original temperature!!!
1130  // no special if-statement in replace_scorefxn...OL
1131  replace_scorefxn( pose, STAGE_5, 0 );
1132  (*score_stage5_)( pose );
1133  return true;
1134 }
1135 
1136 
1137 bool ClassicAbinitio::prepare_loop_in_stage3( core::pose::Pose &pose/*pose*/, Size iteration, Size total ){
1138  // interlace score2/score5
1139 
1140  Real chbrk_weight_stage_3a = 0;
1141  Real chbrk_weight_stage_3b = 0;
1142 
1143  if ( numeric::mod( (int)iteration, 2 ) == 0 || iteration > 7 ) {
1144  Real progress( iteration );
1145  chbrk_weight_stage_3a = 0.25 * progress;
1146  tr.Debug << "select score_stage3a..." << std::endl;
1147  recover_low( pose, STAGE_3a );
1148  replace_scorefxn( pose, STAGE_3a, 1.0* iteration/total );
1149  } else {
1150  Real progress( iteration );
1151  chbrk_weight_stage_3b = 0.05 * progress;
1152  tr.Debug << "select score_stage3b..." << std::endl;
1153  recover_low( pose, STAGE_3b );
1154  replace_scorefxn( pose, STAGE_3b, 1.0* iteration/total );
1155  }
1156 
1157  if ( close_chbrk_ ){
1158 
1159  set_score_weight( scoring::linear_chainbreak, chbrk_weight_stage_3a , STAGE_3a );
1160  set_score_weight( scoring::linear_chainbreak, chbrk_weight_stage_3b , STAGE_3b );
1161 
1162  }
1163 
1164 
1165  return true;
1166 }
1167 
1169  replace_scorefxn( pose, STAGE_4, 1.0* iteration/total );
1170  Real chbrk_weight_stage_4 (iteration*0.5+2.5);
1171 
1172  if ( close_chbrk_ ){
1173  set_current_weight( scoring::linear_chainbreak, chbrk_weight_stage_4 );
1174  }
1175 
1176  return true;
1177 }
1178 
1179 //@brief obtain currently used monte-carlo object --> use to obtain current score-func: mc().score_function()
1182  return mc_;
1183 }
1184 
1185 
1187  using namespace core::io::silent;
1188 
1189  mc().score_function()( pose );
1190  Parent::output_debug_structure( pose, prefix );
1191 
1192  if ( option[ basic::options::OptionKeys::abinitio::explicit_pdb_debug ]() ) {
1193  pose.dump_pdb( prefix + get_current_tag() + ".pdb" );
1194  }
1195 
1196  if ( option[ basic::options::OptionKeys::abinitio::log_frags ].user() ) {
1197  std::string filename = prefix + "_" + get_current_tag() + "_" + std::string( option[ basic::options::OptionKeys::abinitio::log_frags ]() );
1198  utility::io::ozstream output( filename );
1199  simple_moves::LoggedFragmentMover& log_frag = dynamic_cast< simple_moves::LoggedFragmentMover& > (*brute_move_large_);
1200  log_frag.show( output );
1201  log_frag.clear();
1202  }
1203 
1204 } // ClassicAbinitio::output_debug_structure( core::pose::Pose & pose, std::string prefix )
1205 
1206 } //abinitio
1207 } //protocols