Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AbrelaxMover.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/abinitio/AbrelaxMover.cc
11 /// @author Oliver Lange
12 /// @author Christopher Miles (cmiles@uw.edu)
13 
14 #ifdef BOINC_GRAPHICS
15 #include <protocols/boinc/boinc.hh>
16 #endif
17 
18 // Unit Headers
20 
21 // Project Headers
22 #include <core/pose/Pose.hh>
32 #include <protocols/jd2/util.hh>
33 #include <protocols/jd2/Job.hh>
36 #include <protocols/loops/Loops.hh>
37 #include <protocols/loops/Loop.hh>
42 #include <protocols/relax/util.hh>
46 
48 
49 // Utility headers
50 #include <basic/options/option.hh>
51 #include <basic/datacache/BasicDataCache.hh>
52 #include <basic/datacache/CacheableData.hh>
53 #include <basic/options/keys/OptionKeys.hh>
54 #include <basic/options/keys/abinitio.OptionKeys.gen.hh>
55 #include <basic/options/keys/score.OptionKeys.gen.hh>
56 #include <basic/options/keys/loops.OptionKeys.gen.hh>
57 #include <basic/options/keys/out.OptionKeys.gen.hh>
58 // AUTO-REMOVED #include <basic/options/keys/broker.OptionKeys.gen.hh>
59 #include <basic/options/keys/run.OptionKeys.gen.hh>
60 #include <basic/options/keys/abrelax.OptionKeys.gen.hh>
61 #include <basic/Tracer.hh>
62 #include <basic/MemTracer.hh>
63 #include <numeric/random/random.hh>
64 
65 #include <utility/vector1.hh>
66 
67 
68 static basic::Tracer tr("protocols.general_abinitio", basic::t_info);
69 
70 static numeric::random::RandomGenerator RG(1981221134);
71 
72 namespace protocols {
73 namespace abinitio {
74 
75 using namespace core;
76 
78  topology_broker_( NULL ),
79  sampling_protocol_( NULL ),
80  loop_closure_protocol_( NULL ),
81  relax_protocol_( NULL ),
82  post_loop_closure_protocol_( NULL ),
83  b_return_unrelaxed_fullatom_( false )
84  {
85  basic::mem_tr << "AbrelaxMover CStor start" << std::endl;
86  set_defaults();
87  basic::mem_tr << "AbrelaxMover CStor end" << std::endl;
88  }
89 
91 
93  topology_broker_ = NULL;
94  sampling_protocol_ = NULL;
96  relax_protocol_ = NULL;
98 }
99 
101  using namespace basic::options;
107 
109 
112 
113  // add basic abinitio sampler
115  sampling_protocol( sampler );
116 
117  // Idealize the structure before relax
118  bool bIdeal( true );
119  if ( option[ OptionKeys::loops::idealize_before_loop_close ].user() ) {
120  IdealizeMoverOP idealizer(new IdealizeMover);
121  idealizer->fast( false );
122  pre_loop_closure_protocol( idealizer );
123  }
124 
125  // loop closing
126  if ( option[ OptionKeys::abinitio::close_loops ]() ) {
127  SlidingWindowLoopClosureOP closure_method = new SlidingWindowLoopClosure;
128 
129  if ( option[ OptionKeys::loops::alternative_closure_protocol ]() ) {
130  closure_method = new WidthFirstSlidingWindowLoopClosure;
131  }
132 
133  bIdeal = !option[ OptionKeys::loops::non_ideal_loop_closing ]();
134 
135  // set options here if you like
136  // closure_protocol-> ... and write the setters/accessors, too, if you have to
137  closure_method->scored_frag_cycle_ratio( option[ OptionKeys::loops::scored_frag_cycles ]() );
138  closure_method->short_frag_cycle_ratio( option[ OptionKeys::loops::short_frag_cycles ]() );
139  closure_method->set_bIdealLoopClosing( bIdeal );
140  closure_method->set_chainbreak_max( option[ OptionKeys::loops::chainbreak_max_accept ]() );
141 
142  //add closure protocol to abrelax
143  closure_protocol( closure_method );
144  }
145 
146  // Idealize the structure after relax
147  if ( option[ OptionKeys::loops::idealize_after_loop_close ].user() ) {
148  IdealizeMoverOP idealizer(new IdealizeMover);
149  idealizer->fast( false );
150  post_loop_closure_protocol( idealizer );
151  bIdeal = true;
152  }
153 
154  //yipee a bad hack using global variables
155  if ( !bIdeal ) option[ basic::options::OptionKeys::out::file::silent_struct_type ].def( "binary");
156 
157  //add relax protocol to abrelax
158  //cst_fa_weight and cst_weight are properly interpreted by this utility function
159  relax_protocol( relax::generate_relax_from_cmd( true /*null if no relax flag*/ ) );
160 
161  if ( relax_protocol() && option[ OptionKeys::run::test_cycles ] ) {
162  //in test_cycles we don't test relax...
163  //special relax integration test takes care of that...
164  // so make it fast here... dry_run means just an energy evaluation
165  relax_protocol()->set_dry_run( true );
166  }
167 }
168 
170  return sampling_protocol_;
171 }
172 
174  return relax_protocol_;
175 }
176 
178  return relax_protocol_;
179 }
180 
182  return loop_closure_protocol_;
183 }
184 
186  sampling_protocol_ = set;
187 }
188 
190  relax_protocol_ = set;
191 }
192 
195 }
196 
197 // idealize after loop-closing
200 }
201 
202 // idealize before loop-closing
205 }
206 
208  return topology_broker_;
209 }
210 
211 //@brief basic apply for the generalized protocol:
213  using namespace basic::options;
214 
215  runtime_assert( sampling_protocol() );
216  runtime_assert( topology_broker() );
217 
218  tr.Info << "AbrelaxMover: " << get_current_tag() << std::endl;
219  basic::mem_tr << "AbrelaxMover::apply" << std::endl;
220  basic::show_time( tr, "AbrelaxMover: start..."+jd2::current_batch()+" "+jd2::current_output_name() );
221 
222  // kidnap sampling_protocols's checkpointer - this could ultimately be a singleton i guess
223  checkpoint::CheckPointer &checkpoints = sampling_protocol()->get_checkpoints();
224 
225  // need to save RG states such that choices for constraints and fold-tree are the same.
226  if( ! checkpoints.recover_checkpoint( pose, get_current_tag(), "rg_state") ){
227  checkpoints.checkpoint( pose, get_current_tag(), "rg_state");
228  }
229 
230  checkpoints.debug( get_current_tag(), "rg_state", RG.uniform() );
231  if ( sampling_protocol() ) sampling_protocol()->set_current_tag( get_current_tag() );
232  if ( closure_protocol() ) closure_protocol()->set_current_tag( get_current_tag() );
233  if ( relax_protocol() ) relax_protocol()->set_current_tag( get_current_tag() );
234 
235  // setup -- e.g., sequence --> pose
236  //
237  topology_broker()->apply( pose ); //creates pose and a state in the topology_broker needed for the whole run
238 
239  // apply a mover which calculates only repulsive energy on designate residues
240  {
242  replonly.set_mutate_to_glycine( false );
243  replonly.apply( pose );
244  }
245 
246  protocols::viewer::add_conformation_viewer( pose.conformation(), "start_pose" ); //add viewer
247 
248 #ifdef BOINC_GRAPHICS
249  protocols::boinc::Boinc::attach_graphics_current_pose_observer( pose );
250 #endif
251 
252  // abinitio
253  //
254  sampling_protocol()->topology_broker( topology_broker() );
255 
256 #ifdef BOINC_GRAPHICS
257  protocols::boinc::Boinc::attach_graphics_current_pose_observer( pose );
258 #endif
259 
260  sampling_protocol()->apply( pose );
261 
262  //make sure all chainbreak variants are activated:
263  if ( !topology_broker()->check_chainbreak_variants( pose ) ) {
264  tr.Warning << "[WARNING] some chainbreaks in " << jd2::current_output_name()
265  << " were not penalized at end of " << sampling_protocol()->type()
266  << std::endl;
267  topology_broker()->add_chainbreak_variants( pose );
268  }
269 
270  // filters
271  //
272  bool loop_success = true;
273 
274 #ifdef BOINC_GRAPHICS
275  protocols::boinc::Boinc::attach_graphics_current_pose_observer( pose );
276 #endif
277 
278  scoring::ScoreFunctionCOP last_scorefxn ( sampling_protocol()->current_scorefxn() );
279 
280  // Make sure score columns always the same.
283 
285  tr.Info << "abrelax_stage: pre_loopclosing (i.e., idealize) for " << get_current_tag() << std::endl;
286  kinematics::FoldTree fold_tree( pose.fold_tree() );
287  pose.fold_tree( topology_broker()->final_fold_tree() );
288  pre_loop_closure_protocol_->apply( pose );
289  pose.fold_tree( fold_tree );
290  sampling_protocol()->current_scorefxn()( pose );
291  jd2::output_intermediate_pose( pose, "loops_closed_preprocessed" );
292  }
293 
294  // loop closing
295  //
296  if ( closure_protocol() ) {
297  // Did we already close the loops successfully ?
298  if ( checkpoints.recover_checkpoint( pose, get_current_tag(), "loops_S", false /*fullatom*/, true /*foldtree*/)) {
299  checkpoints.debug( get_current_tag(), "close_loops", (*last_scorefxn)(pose), (core::Real) true );
300  loop_success = true;
301  } else if ( checkpoints.recover_checkpoint( pose, get_current_tag(), "loops_C", false /*fullatom*/, true /*foldtree*/)) {
302  // No ? Have we already tried but failed ?
303  checkpoints.debug( get_current_tag(), "close_loops", (*last_scorefxn)(pose), (core::Real) false );
304  loop_success = false;
305  } else {
306  // No ? Then evidently we havn't even tried yet
307  tr << "AbrelaxMover: start loops" << std::endl;
309  closure_protocol()->scorefxn( new scoring::ScoreFunction( sampling_protocol()->current_scorefxn() ) );
310  closure_protocol()->fragments( topology_broker()->loop_frags( *movemap ) ); //get frags and movemap from broker
311  closure_protocol()->movemap( movemap ); //this is the movemap sanctioned by the broker ... see line above
312 
313  try {
315  pose,
316  sampling_protocol()->get_checkpoints(),
317  get_current_tag(),
318  topology_broker()->final_fold_tree());
319  } catch ( loops::EXCN_Loop_not_closed& excn ) {
320  set_current_tag( "C_"+get_current_tag().substr(std::min(2,(int)get_current_tag().size())) );
322  loop_success = false;
323  if ( option[ OptionKeys::abrelax::fail_unclosed ]() ) return;
324  }
325  sampling_protocol()->current_scorefxn()( pose );
326  jd2::output_intermediate_pose( pose, "loops_closed" );
327 
328  topology_broker()->apply_filter( pose, LOOP_CLOSURE, 1 );
329 
330  if ( post_loop_closure_protocol_ && loop_success ) {
331  tr.Info << "abrelax_stage: post_loopclosing (i.e., idealize) for " << get_current_tag() << std::endl;
332  post_loop_closure_protocol_->apply( pose );
333  sampling_protocol()->current_scorefxn()( pose );
334  jd2::output_intermediate_pose( pose, "loops_closed_postprocessed" );
335  }
336 
337  // to know this we'd have to catch the Exception EXCN_Loop_not_closed
338  if ( loop_success ) {
339  checkpoints.checkpoint( pose, get_current_tag(), "loops_S", true /*foldtree*/ );
340  } else {
341  checkpoints.checkpoint( pose, get_current_tag(), "loops_C", true /*foldtree*/ );
342  }
343 
344  checkpoints.debug( get_current_tag(), "loops", (*last_scorefxn)(pose), (core::Real) loop_success );
345  }
346  }
347 
348  // Fullatom switch
349  //
350  basic::mem_tr << "AbrelaxMover::apply fullatom switch" << std::endl;
352  tr << "AbrelaxMover: switch to fullatom" << std::endl;
353  jd2::get_current_job()->add_string_real_pair( "prefa_centroid_score", ((sampling_protocol()->current_scorefxn())( pose ) ) );
354  tr.Info << "prefa_centroid_score:\n ";
355  (sampling_protocol()->current_scorefxn()).show( tr.Info, pose );
356  tr.Info << std::endl;
358  clean_score3->set_weight( scoring::linear_chainbreak, 1.33 );
359  clean_score3->set_weight( scoring::overlap_chainbreak, 1.0 );
360  // clean_score3->set_weight( scoring::chainbreak, 1.0 );
361  jd2::get_current_job()->add_string_real_pair( "prefa_clean_score3", ((*clean_score3)(pose)) );
362  tr.Info << "prefa_clean_score3:\n ";
363  clean_score3->show( tr.Info, pose );
364  tr.Info << std::endl;
365  topology_broker()->switch_to_fullatom( pose );
366 
367  // we're now in fullatom mode - so upate the score function.
368  if (( (option[ OptionKeys::score::weights ]() == "score0") ||
369  (option[ OptionKeys::score::weights ]() == "score2") ||
370  (option[ OptionKeys::score::weights ]() == "score3") ||
371  (option[ OptionKeys::score::weights ]() == "score5") ) ) {
372  utility_exit_with_message("Cannot proceed - you chose a centroid score function for fullatom mode");
373  }
374 
376  core::scoring::ScoreFunctionCOP last_scorefxn_cop = relax_prot->get_scorefxn();
377  last_scorefxn = last_scorefxn_cop->clone();
378  } //switched to fullatom
379 
380 
381  {// apply a mover which calculates only repulsive energy on designate residues
383  replonly.set_mutate_to_glycine( false );
384  replonly.apply( pose );
385  }
386 
387  if( option[ basic::options::OptionKeys::abinitio::close_loops_by_idealizing ]() ){
388  close_with_idealization( pose );
389  }
390 
391  // Relax
392  //
393  basic::mem_tr << "AbrelaxMover::apply relax" << std::endl;
394  if ( ( loop_success || option[ OptionKeys::abinitio::relax_failures ]() ) && relax_protocol()) {
395  tr << "AbrelaxMover: relax " << std::endl;
396  if ( !checkpoints.recover_checkpoint( pose, get_current_tag(), "relax", true, true) ) {
397  topology_broker()->adjust_relax_movemap( *(relax_protocol()->get_movemap() ) );
398  relax_protocol()->apply( pose );
399  checkpoints.checkpoint( pose, get_current_tag(), "relax", true ); //since relax_protocol throws away its checkpoints right here
400  }
401  checkpoints.debug( get_current_tag(), "relax", (*last_scorefxn)( pose ) );
402  }
403 
404  topology_broker()->apply_filter( pose, RELAX, 1 );
405 
406  // Final clean relax
407  //
408  if ( ( loop_success || option[ OptionKeys::abinitio::relax_failures ]() ) && relax_protocol() && option[ OptionKeys::abinitio::final_clean_relax ]() ) {
409  tr << "AbrelaxMover: final relax " << std::endl;
410  pose.constraint_set( NULL );
411  if ( !checkpoints.recover_checkpoint( pose, get_current_tag(), "finalrelax", true, true) ) {
412  relax_protocol()->apply( pose );
413  checkpoints.checkpoint( pose, get_current_tag(), "finalrelax", true ); //since relax_protocol throws away its checkpoints right here
414  }
415  checkpoints.debug( get_current_tag(), "finalrelax", (*last_scorefxn)( pose ) );
416  }
417 
418  if ( option[ OptionKeys::abinitio::clear_pose_cache ]() ) {
419  tr.Debug << "\n******************************************************** \n"
420  << " CLEAR POSE CACHE \n"
421  << "*************************************************************"
422  << std::endl;
423  pose.data().clear();
424  }
425 
426  if ( sampling_protocol() ) sampling_protocol()->get_checkpoints().clear_checkpoints();
427  if ( !b_return_unrelaxed_fullatom_ ) (*last_scorefxn)( pose );
428 
429  basic::mem_tr << "AbrelaxMover::apply end" << std::endl;
430  basic::show_time( tr, "AbrelaxMover: finished ..."+jd2::current_batch()+" "+jd2::current_output_name() );
431 }
432 
434  return "AbrelaxMover";
435 }
436 
438  using namespace basic::options;
439  kinematics::FoldTree fold_tree( pose.fold_tree() );
440 
441  // record cutpoints
443  for ( Size ncut = 1; ncut <= (Size) pose.fold_tree().num_cutpoint(); ncut++ ) {
444  Size cutpoint = pose.fold_tree().cutpoint( ncut );
445  Size margin = option[ basic::options::OptionKeys::abinitio::optimize_cutpoints_margin ]();
446  protocols::loops::Loop newloop (std::max( (int) 1, int(cutpoint - margin) ),
447  std::min( (int) pose.total_residue(), int(cutpoint + margin) ),
448  0);
449  if( cloops->size() >= 2 )
450  if( newloop.start() <= ( *cloops )[cloops->size()-1].stop() ) newloop.set_start( ( *cloops )[cloops->size()-1].stop() +2 );
451  newloop.choose_cutpoint( pose );
452  cloops->add_loop( newloop );
453  }
454  cloops->auto_choose_cutpoints( pose );
455 
456  // remove cuts
457  pose.fold_tree( topology_broker()->final_fold_tree() );
458 
459  //idealize
461  idealizer.fast( false );
462  idealizer.apply( pose );
463 
464  // Relax, with none of the cutpoints
465  relax_protocol()->apply( pose );
466 
467  // now optimize around the old cut points.
468  if( option[ basic::options::OptionKeys::abinitio::optimize_cutpoints_using_kic ]() ){
469  protocols::loops::fold_tree_from_loops( pose, *cloops, fold_tree , true /* include terminal cutpoints */);
470  pose.fold_tree( fold_tree );
471 
473  core::scoring::ScoreFunctionOP refine_scorefxn = relax_prot->get_scorefxn()->clone();
474  protocols::loops::loop_mover::refine::LoopMover_Refine_KIC refine_kic( cloops, refine_scorefxn );
475  refine_kic.apply( pose );
476 
477  // Return fold tree to normal state
478  pose.fold_tree( topology_broker()->final_fold_tree() );
479  }
480 }
481 
482 }
483 }