Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LoopRemodel.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 
11 /// @file protocols/protein_interface_design/movers/LoopRemodel.cc
12 /// @brief Parseable class to run loop perturbation or refinement between a given loop between start/end (inclusive). Intended to sample loop conformations at an interface.
13 /// @author Jacob Corn (jecorn@u.washington.edu)
14 
15 // Unit headers
18 
19 // Package headers
20 
21 // Project headers
26 // AUTO-REMOVED #include <protocols/loops/LoopMover_QuickCCD.hh>
29 #include <protocols/loops/loops_main.hh> // for various loop utility fxns
30 #include <protocols/loops/Loops.hh>
31 #include <utility/tag/Tag.hh>
35 #include <protocols/forge/methods/fragment_functions.hh> // smallmer_from_largemer
38 #include <core/pose/selection.hh>
39 
41 
42 
45 
46 #include <core/pose/Pose.hh>
47 
49 #include <core/scoring/dssp/Dssp.hh> // for getting secondary structure for fragments
50 
57 
59 
60 #include <basic/options/option.hh>
61 #include <basic/options/keys/packing.OptionKeys.gen.hh>
62 #include <basic/options/keys/loops.OptionKeys.gen.hh>
63 
66 #include <core/fragment/FragSet.hh>
67 #ifdef WIN32
68 #include <core/fragment/FragID.hh>
69 #endif
70 
71 #include <core/fragment/Frame.hh>
74 
78 #include <core/kinematics/Jump.hh>
81 #include <utility/vector0.hh>
82 #include <utility/vector1.hh>
83 #include <basic/Tracer.hh>
84 
85 //Auto Headers
87 
88 
89 
90 
91 namespace protocols {
92 namespace protein_interface_design {
93 namespace movers {
94 
95 using namespace protocols::moves;
96 
97 static basic::Tracer TR( "protocols.protein_interface_design.movers.LoopRemodel" );
98 
101 {
103 }
104 
107  return new LoopRemodel;
108 }
109 
112 {
113  return "LoopRemodel";
114 }
115 
117 
120  return( protocols::moves::MoverOP( new LoopRemodel( *this ) ) );
121 }
122 
124  simple_moves::DesignRepackMover( LoopRemodelCreator::mover_name() )
125 {}
126 
128  std::string const protocol,
129  core::Size const loop_start,
130  core::Size const loop_end,
131  core::Size const cycles,
132  bool const auto_loops,
133  //bool const design,
134  bool const perturb,
135  bool const refine,
136  bool const hurry,
137  core::scoring::ScoreFunctionOP hires_score,
138  core::scoring::ScoreFunctionOP lores_score,
143 ) :
144  simple_moves::DesignRepackMover( LoopRemodelCreator::mover_name() ),
145  protocol_( protocol ),
146  loop_start_( loop_start ),
147  loop_end_( loop_end ),
148  cycles_( cycles ),
149  auto_loops_(auto_loops),
150  //design_(design),
151  perturb_( perturb),
152  refine_( refine),
153  hurry_( hurry )
154 {
155  hires_score_ = hires_score;
156  lores_score_ = new core::scoring::ScoreFunction( *lores_score );
157  loops_ = new protocols::loops::Loops( *loops );
161 }
162 
163 void
165 {
166  using namespace protocols::loops;
167  core::pose::Pose native_pose = pose;
168 
169  LoopsOP loops = new protocols::loops::Loops( *loops_ ); // loops_ gets set in parse_my_tag
170  if( loops->size() == 0) {
171  TR << "No loops found!" << std::endl;
172  return; // bounce out if we didn't define any loops
173  }
174  else TR << *loops << std::endl;
175 
176  if( loops->size() > 0 ) {
177  // set up temporary fold tree for loop closure
178  TR.Debug << "Original FoldTree " << pose.fold_tree() << std::endl;
179  core::kinematics::FoldTree old_ft( pose.fold_tree() );
180  //core::kinematics::FoldTree new_ft;
182  //fold_tree_from_loops( pose, *loops, new_ft, false /*terminal_cutpoint*/ );
183  pose.fold_tree( new_ft );
184  add_cutpoint_variants( pose );
187  task_factory->push_back( new core::pack::task::operation::InitializeFromCommandline );
188  task_factory->push_back( new core::pack::task::operation::IncludeCurrent );
189  task_factory->push_back( new core::pack::task::operation::NoRepackDisulfides );
190  // perturbation and closure
191  if( hurry_ ) {
192  core::Real mc_kt( 1.0 );
193  if( basic::options::option[ basic::options::OptionKeys::loops::remodel_init_temp ].user() ) mc_kt = basic::options::option[ basic::options::OptionKeys::loops::remodel_init_temp ]();
194  core::Size const outer_cycles( cycles_ );
195  protocols::moves::MonteCarlo outer_mc( pose, *hires_score_, mc_kt );
196  outer_mc.set_autotemp( true, mc_kt );
197  for( core::Size i = 1; i <= outer_cycles; ++i ) {
198  TR.Debug << "outer_cycle " << i << " kt=" << outer_mc.temperature() << std::endl;
199  core::Size const inner_cycles( 20 );
200  protocols::moves::MonteCarlo inner_mc( pose, *hires_score_, mc_kt );
201  inner_mc.set_autotemp( true, mc_kt );
202  for( core::Size j = 1; j <= inner_cycles; ++j ) {
203  TR.Debug << "inner_cycle " << j << " kt=" << inner_mc.temperature() << std::endl;
204  for( Loops::iterator it = loops->v_begin(); it != loops->v_end(); ++it ) {
205  // make a temporary loop/loops set to use in this scope
206  Loop loop( *it );
207 
209  if( perturb_ ) kinmover->set_idealize_loop_first( true );
210  core::Size const cycles = 100;
211  kinmover->set_temperature( mc_kt );
212  kinmover->set_sfxn(hires_score_);
213  kinmover->set_vary_bondangles( true );
214  kinmover->set_sample_nonpivot_torsions( true );
215  kinmover->set_rama_check( true );
216 
217  protocols::loops::loop_closure::kinematic_closure::KinematicWrapper kinwrapper( kinmover, loop, cycles );
218  kinwrapper.apply( pose );
219  } // for all loops
220  inner_mc.boltzmann( pose );
221  } // for inner_cycles
222  inner_mc.show_counters();
223  if( basic::options::option[ basic::options::OptionKeys::loops::kic_recover_last ].value() ) {
224  pose = inner_mc.last_accepted_pose();
225  }
226  else inner_mc.recover_low( pose );
227 
228  //} // if perturb
229 
230  (*hires_score_)(pose); // score the pose (for safety & to get a good graph state)
231  // repack to relieve clashes
232 
233  if( prevent_repacking().size() ){
234  using namespace core::pack::task::operation;
235  OperateOnCertainResiduesOP prevent_repacking_on_certain_res = new OperateOnCertainResidues;
236  prevent_repacking_on_certain_res->residue_indices( prevent_repacking() );
237  prevent_repacking_on_certain_res->op( new PreventRepackingRLT );
238  task_factory->push_back( prevent_repacking_on_certain_res );
239  }
240 
241  if( basic::options::option[ basic::options::OptionKeys::packing::resfile ].user() ) {
242  task_factory->push_back( new core::pack::task::operation::ReadResfile );
243  }
244  if( !design() ) task_factory->push_back( new core::pack::task::operation::RestrictToRepacking );
245  core::pack::task::PackerTaskOP task = task_factory->create_task_and_apply_taskoperations( pose );
246 
247  if( design() ) {
248  for( Loops::iterator it = loops->v_begin(); it != loops->v_end(); ++it ) {
249  Loop loop( *it );
250  for( core::Size i = 1; i <= pose.total_residue(); ++i ) {
251  if( i >= loop.start() && i <= loop.stop() ) continue; // design
252  else task->nonconst_residue_task( i ).restrict_to_repacking(); // repack only
253  }
254  }
255  }
257  pack.apply( pose );
258 
259  if( refine_ ) {
260  loops_set_move_map( pose, *loops, refine_, *movemap ); // bb, except for omega and all sidechains
262  copy_score->set_weight( core::scoring::chainbreak, 10.0 ); // upweight chainbreak, to strongly disfavor breaks
263  copy_score->set_weight( core::scoring::omega, 0.5 ); // omega term to keep backbone healthy
264  protocols::simple_moves::MinMoverOP minmover( new protocols::simple_moves::MinMover( movemap, copy_score, "dfpmin", 1e-5, true) ); // DJM has reported better results with dfpmin
265  minmover->apply( pose );
266  } // if refine
267  outer_mc.boltzmann( pose );
268  } // for outer_cycles
269  outer_mc.recover_low( pose );
270  outer_mc.show_counters();
271  } // if hurry
272 
273  else { // !hurry
274  // pose will always start full atom
275  //protocols::moves::MonteCarlo mc( pose, *scorefxn_repack_, mc_kt );
276  SaveAndRetrieveSidechains retrieve_sc( pose );
277  retrieve_sc.allsc( true );
279  if( protocol_ == "kinematic" ) {
280  if( perturb_ ) {
281  for( Loops::iterator it = loops->v_begin(); it != loops->v_end(); ++it ) {
282  it->set_extended( true ); // set all loops to extended (needed for kinematic mover to really perturb)
283  }
285  perturb.set_native_pose( new core::pose::Pose ( native_pose ) );
286  perturb.apply( pose );
287  }
289  retrieve_sc.apply( pose ); // recover sidechains from pre-centroid pose
290  if( refine_ ) {
292  refine.set_redesign_loop( design() ); // design?
293  //if( task_factory() ) refine.set_task_factory( task_factory() ); // if we have a task factory set, then we should pass it to the loop mover
294  refine.set_native_pose( new core::pose::Pose ( native_pose ) );
296  refine.apply( pose );
297  }
298  } // protocol == kinematic
299  else if( protocol_ == "ccd" ) {
301  core::scoring::dssp::Dssp dssp( pose );
302  dssp.insert_ss_into_pose( pose );
303  std::string const full_ss = pose.secstruct();
304  std::string const full_sequence = pose.sequence();
305 
306  bool const pick_status = pick_loop_frags( loops, full_sequence, full_ss );
307  if( !pick_status ) {
309  return;
310  }
311  if( perturb_ ) {
312  //protocols::loops::LoopMover_Perturb_QuickCCD perturb(*loops, lores_score_ );
313  for( Loops::iterator it = loops->v_begin(); it != loops->v_end(); ++it ) {
314  it->set_extended( true ); // set all loops to extended (needed for CCD mover to really perturb)
315  }
317  perturb.add_fragments( frag1_ );
318  perturb.add_fragments( frag3_ );
319  perturb.add_fragments( frag9_ );
320  //perturb.randomize_loop( true );
321  perturb.set_strict_loops( true );
322  perturb.set_native_pose( new core::pose::Pose ( native_pose ) );
323  perturb.apply( pose );
324  }
326  retrieve_sc.apply( pose ); // recover sidechains from pre-centroid pose
327  if( refine_ ) {
329  refine.add_fragments( frag1_ );
330  refine.add_fragments( frag3_ );
331  refine.add_fragments( frag9_ );
332  refine.set_redesign_loop( design() );
333  //if( task_factory() ) refine.set_task_factory( task_factory() ); // if we have a task factory set, then we should pass it to the loop mover
334  refine.set_native_pose( new core::pose::Pose ( native_pose ) );
335  refine.apply( pose );
336  }
337  } // protocol == ccd
338  else if( protocol_ == "remodel" ) {
339  // remodel starts as fa
341  retrieve_sc.apply( pose ); // recover sidechains from pre-centroid pose
342 
343  core::scoring::dssp::Dssp dssp( pose );
344  dssp.insert_ss_into_pose( pose );
345  std::string const full_ss = pose.secstruct();
346  std::string const full_sequence = pose.sequence();
347  bool const pick_status = pick_loop_frags( loops, full_sequence, full_ss );
348  if( !pick_status ) {
350  return;
351  }
353  remodel.scorefunction( *hires_score_ );
354  remodel.add_fragments( frag1_ );
355  remodel.add_fragments( frag3_ );
356  remodel.add_fragments( frag9_ );
357  remodel.set_native_pose( new core::pose::Pose ( native_pose ) );
358  for( core::Size i = 1; i <= cycles_; ++i ) {
359  remodel.apply( pose );
361  }
362  }
363  }
364 
365  // revert to the original FT and take out cutpoints
366  remove_cutpoint_variants( pose, true );
367  pose.fold_tree( old_ft );
368  TR.Debug << "Reverted FoldTree " << pose.fold_tree() << std::endl;
369  }
370  else TR << "No loops found!" << std::endl;
371 }
372 
376 }
377 
378 // true if all fragments picked.
379 // false if something went wrong
380 bool
382 {
383  using namespace core;
384  using namespace core::fragment;
385  using namespace protocols::loops;
386 
387  LoopsCOP loops( new Loops( *loops_in ));
388  for( core::Size frag_length = 3; frag_length <= 9; frag_length+=6 ) { // frag3 and frag9
389  TR << "Finding " << frag_length <<"mer loop fragments..." << std::endl;
390  if( frag_length == 3 ) frag3_ = new ConstantLengthFragSet( frag_length );
391  else if( frag_length == 9 ) frag9_ = new ConstantLengthFragSet( frag_length );
392 
393  for( Loops::const_iterator it = loops->begin(); it != loops->end(); ++it ) {
394  // make a temporary loop/loops set to use in this scope
395  LoopCOP loop( new Loop(*it ));
396  if( loop->size() < frag_length ) continue; // fragment extends past loop
397 
398  for( core::Size i=loop->start(); i <= loop->stop() - frag_length; ++i ) {
399 
400  // figure out ss and sequence that we're currently working on
401  std::string ss = full_ss.substr( i - 1, frag_length); // subtract 1 to get string indexing -> pose indexing
402  if ( ss.length() < frag_length ) {
403  ss.append( frag_length - ss.length(), 'D' );
404  }
405  TR.Debug << "Window ss: " << ss << "\n";
406  std::string aa = full_sequence.substr( i - 1, frag_length);
407  if ( aa.length() < frag_length ) {
408  aa.append( frag_length - aa.length(), '.' );
409  }
410  TR.Debug << "Window aa: " << aa << std::endl;
411 
412  // pick fragments
413  FragDataList list;
414  if( design() ) list = picking_old::vall::pick_fragments_by_ss( ss, 4000, true /*add random noise*/ ); //magic number: 4000 fragments
415  else list = picking_old::vall::pick_fragments_by_ss_plus_aa( ss, aa, 4000, true );
416  for( FragDataList::const_iterator it = list.begin(); it != list.end(); ++it ) {
417  TR.Debug << (*it)->size() << " " << (*it)->sequence() << std::endl;
418  }
419 
420  // add frames to fragset
421  TR.Debug << "Adding frame: "<< i << "-" << i+frag_length << ": " << ss << " " << aa << std::endl;
422  core::fragment::FrameOP frame = new core::fragment::Frame( i, frag_length );
423  frame->add_fragment( list );
424  if( frag_length == 3 ) frag3_->add( frame );
425  else if( frag_length == 9 ) frag9_->add( frame );
426  } // for all residues in each loop
427  } // for all loops
428  } // frag3 and frag9
429  if( frag3_->size() ) {
430  frag1_ = new ConstantLengthFragSet( 1 );
432  }
433 
434  picking_old::FragmentLibraryManager::get_instance()->clear_Vall();
435  if( (frag1_->size() > 0) || (frag3_->size() > 0) || (frag9_->size() > 0) ) return true;
436  else return false;
437 }
438 
439 
440 void
442 {
443  protocol_ = tag->getOption<std::string>( "protocol", "ccd" );
444  perturb_ = tag->getOption<bool>( "perturb", 0 );
445  refine_ = tag->getOption<bool>( "refine", 1 );
446  std::string const hires_score( tag->getOption<std::string>( "refine_score", "score12" ) );
447  std::string const lores_score( tag->getOption<std::string>( "perturb_score", "score4L" ) );
448  hires_score_ = new core::scoring::ScoreFunction( *data.get< core::scoring::ScoreFunction * >( "scorefxns", hires_score ));
449  lores_score_ = new core::scoring::ScoreFunction( *data.get< core::scoring::ScoreFunction * >( "scorefxns", lores_score ));
450 
452 
453  auto_loops_ = tag->getOption<bool>( "auto_loops", 0 );
454  bool const des = tag->getOption<bool>( "design", 0 );
455  design( des ); // set baseclass design flag
456 
457  hurry_ = tag->getOption<bool>( "hurry", 0 );
458  cycles_ = tag->getOption<Size>( "cycles", 10 );
459  runtime_assert( cycles_ > 0 );
460 
461  loop_start_ = 0;
462  loop_end_ = 0;
463 
464  // populate loops
465  if( auto_loops_ ) {
466  if( !data.has( "loops", "found_loops" ) )
467  {
468  TR << "Loops not present in DataMap! Be sure to add LoopFinder before LoopRemodel!" << std::endl;
469  return;
470  }
471  loops_ = data.get< protocols::loops::Loops * >( "loops", "found_loops" ); // from LoopFinder
472  }
473  else {
474  loop_start_ = core::pose::get_resnum( tag, pose, "loop_start_" );
475  loop_end_ = core::pose::get_resnum( tag, pose, "loop_end_" );
476  core::Size const cutpt = (loop_start_+loop_end_)/2; // put cutpoint in the middle of the loop
479  loops_->add_loop( *loop );
480  }
481 
482  runtime_assert( auto_loops_ || (loop_start_ && loop_end_) );
483  if( (loop_start_ && loop_end_) && !auto_loops_ ) {
484  runtime_assert( loop_end_ > loop_start_ );
485  runtime_assert( (loop_end_ - loop_start_) >= 3 );
486  runtime_assert( loop_start_ > 1 );
487  runtime_assert( loop_end_ < pose.total_residue() );
488  }
489  TR << "LoopRemodel mover: auto_loops="<<auto_loops_<<" loop_start="<<loop_start_<<" loop_end="<<loop_end_<<" design="<<design()<<
490  " perturb="<<perturb_<<" refine="<<refine_<<" hurry=" <<hurry_<< " cycles=" << cycles_ <<" hires_score="<<hires_score << std::endl;
491 }
492 
493 } //movers
494 } //protein_interface_design
495 } //protocols