Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RBSegmentRelax.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
11 /// @brief RBSegmentRelax protocol
12 /// @detailed
13 ///
14 ///
15 ///
16 /// @author Srivatsan Raman
17 /// @author Frank DiMaio
18 
19 #include <core/pose/util.hh>
27 #include <protocols/loops/Loop.hh>
29 
30 // Protocol headers
31 #include <protocols/moves/Mover.hh>
36 
37 #include <core/fragment/FragSet.hh>
40 
41 //Core headers
42 #include <core/types.hh>
43 #include <core/pose/Pose.hh>
49 #include <core/kinematics/Edge.hh>
52 #include <basic/options/option.hh>
53 #include <basic/options/keys/RBSegmentRelax.OptionKeys.gen.hh>
54 #include <basic/options/keys/loops.OptionKeys.gen.hh>
55 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
56 #include <basic/options/keys/relax.OptionKeys.gen.hh>
57 
58 #include <basic/Tracer.hh>
59 
60 //Map
61 #include <map>
62 
65 #include <utility/vector0.hh>
66 #include <utility/vector1.hh>
67 
68 
69 namespace protocols {
70 namespace rbsegment_relax {
71 
72 basic::Tracer TS("protocols.moves.RBSegmentRelax");
73 using namespace core;
74 using basic::Error;
75 
78 
81  utility::vector1< RBSegment > const & rbsegs_input,
82  protocols::loops::Loops const & loops_input
83 ) :
84  Mover("RBSegmentRelax"),
85  scorefxn_( scorefxn ),
86  rbsegs_input_( rbsegs_input ),
87  loops_input_( loops_input )
88 {
89  using namespace basic::options;
90 
91  // Default parameter settings
92  init_temp = 2.0;
93  final_temp = 1.0;
94 
95  // take defaults from the command line
96  utility::vector1< core::Real > helix_def = option[ OptionKeys::RBSegmentRelax::helical_movement_params ]();
97  utility::vector1< core::Real > strand_def = option[ OptionKeys::RBSegmentRelax::strand_movement_params ]();
98  utility::vector1< core::Real > generic_def = option[ OptionKeys::RBSegmentRelax::default_movement_params ]();
99  cycles_ = option[ OptionKeys::RBSegmentRelax::nrbmoves ]();
100 
101  helical_sigR = helix_def[1]; helical_sigT = helix_def[2];
102  helical_sigOffAxisR = helix_def[3]; helical_sigOffAxisT = helix_def[4];
103 
104  strand_sigR = strand_def[1]; strand_sigT = strand_def[2];
105  strand_sigOffAxisR = strand_def[3]; strand_sigOffAxisT = strand_def[4];
106 
107  genericRB_sigR = generic_def[1]; genericRB_sigT = generic_def[2];
108 
109  cst_weight_ = option[ OptionKeys::constraints::cst_weight ]();
110  cst_width_ = option[ OptionKeys::relax::coord_cst_width ]();
111  cst_stdev_ = option[ OptionKeys::relax::coord_cst_stdev ]();
112  cst_seqwidth_ = option[ OptionKeys::RBSegmentRelax::cst_seqwidth ]();
113 
114  rand_ = 0;
115  bootstrap_ = no_lr_ = false;
116 }
117 
118 
119 //////////////////////////////////////////////////////////////////////////
120 ///@brief setup_RBSegmentRelax; initialize movesets to defaults
121 //////////////////////////////////////////////////////////////////////////
123 {
124  using namespace basic::options;
125 
126  // set up default movesets ( start and end positions are set in apply() )
127  if (! option[ OptionKeys::RBSegmentRelax::skip_seqshift_moves ]() ) {
128  HelixMoveSet_.push_back( new SequenceShiftMover( ) );
129  StrandMoveSet_.push_back( new SequenceShiftMover( ) );
130  }
131 
132  if (! option[ OptionKeys::RBSegmentRelax::skip_rb_moves ]() ) {
137  }
138 
139  // frags
140  frag_libs_ = frag_libs;
141  randomness_ = rnd;
142 }
143 
144 
145 ////////////////////////////
147  init_temp = start;
148  final_temp = final;
149 }
150 
151 ////////////////////////////
152 void RBSegmentRelax::set_helicalMoveStepsize( Real onAxisTrans, Real onAxisRot, Real offAxisTrans, Real offAxisRot ) {
153  helical_sigT = onAxisTrans;
154  helical_sigR = onAxisRot;
155  helical_sigOffAxisT = offAxisTrans;
156  helical_sigOffAxisR = offAxisRot;
157 }
158 
159 ////////////////////////////
163 }
164 
165 ////////////////////////////
166 void RBSegmentRelax::set_ncycles( int ncycles ) {
167  cycles_ = ncycles; // cycles PER rb-segment
168 }
169 
170 
171 ////////////////////////////
173  cst_weight_ = wt;
174 }
175 
176 ////////////////////////////
178  cst_width_ = width;
179 }
180 
181 
182 
183 //////////////////////////////////////////////////////////////////////////
184 ///@brief apply method
185 //////////////////////////////////////////////////////////////////////////
187  using namespace basic::options;
188 
189  protocols::moves::RandomMoverOP SegmentRandomizeMover( new protocols::moves::RandomMover() );
190 
191  // Remove loops from pose, connect with jumps
192  core::pose::Pose pose_noloops, pose_input = pose;
195  bool fullatom = pose.is_fullatom();
196 
197  // make loopless pose
198  setup_pose_from_rbsegs( rbsegs_input_ , pose , pose_noloops , resmap, mm, fix_ligands_ );
199  TS << "LOOPS-REMOVED fold tree " << pose_noloops.fold_tree() << std::endl;
200  TS << "LOOPS-REMOVED secstruct " << pose_noloops.secstruct() << std::endl;
201 protocols::viewer::add_conformation_viewer( pose_noloops.conformation() );
202 
203  // remap rbsegs
205 
206  // set up constraints
207  set_rb_constraints( pose_noloops, pose, rbsegs_input_ , resmap, cst_width_, cst_stdev_, cst_seqwidth_ ); // does the mapping internally
208  scorefxn_->set_weight( core::scoring::coordinate_constraint, cst_weight_ ); // add constraint term
209 
210  bool doFragInserts=false;
211  FragInsertAndAlignMoverOP frag_ins;
212  if ( option[ OptionKeys::loops::vall_file ].user() && !option[ OptionKeys::RBSegmentRelax::skip_fragment_moves ]() ) {
213  frag_ins = new
215  doFragInserts = true;
216 
217  if (bootstrap_) {
218  frag_ins->bootstrapCATrace( pose_noloops ); // Bootstrap a model from the Ca trace (idealizing in the process)
219 
220  // if fullatom do a repack now
222  task_fast->restrict_to_repacking(); task_fast->or_include_current(false);
224  if (fullatom)
225  pack_fast.apply( pose_noloops );
226  }
227  }
228 
229  // loop over segments, add a mover for each
230  int nmovers=0;
231  for ( RBIt it_seg = rbsegs_remap_.begin(), it_seg_end = rbsegs_remap_.end();
232  it_seg != it_seg_end; ++it_seg ) {
233  // hardcoded since it needs a few extra things
234  // initialize the frag-insert mover
235  if ( doFragInserts ) {
236  SegmentRandomizeMover->add_mover( frag_ins );
237  nmovers++;
238  }
239 
240  // add the whole structure movers
241  // add a copy for each RB segment
242  for ( std::vector< protocols::moves::MoverOP >::iterator it_mover = WholeStructureMoveSet_.begin(),
243  it_mover_end = WholeStructureMoveSet_.end();
244  it_mover != it_mover_end; ++it_mover ) {
245  SegmentRandomizeMover->add_mover( *it_mover );
246  nmovers++;
247  }
248 
249  //////////////////////
250  // HELIX SEGMENTS
251  if( it_seg->isHelix() ) {
252  // add each mover from the helix moveset
253  // resids refer to those in the loop-removed pose
254  for ( std::vector< RBSegmentMoverOP >::iterator it_mover = HelixMoveSet_.begin(),
255  it_mover_end = HelixMoveSet_.end(); it_mover != it_mover_end; ++it_mover ) {
256  RBSegmentMoverOP moverToAdd = dynamic_cast< RBSegmentMover * >((*it_mover)()->clone()()); // make a deep copy of the mover
257  moverToAdd->setResidueRange( *it_seg );
258  if ( it_seg->initialized() ) moverToAdd->set_movement(*it_seg); // override default movement params
259  SegmentRandomizeMover->add_mover( moverToAdd );
260  nmovers++;
261  }
262 
263  //////////////////////
264  // SHEET SEGMENTS
265  } else if ( it_seg->isSheet() ) {
266  // add each mover from the strand moveset
267  // resids refer to those in the loop-removed pose
268  for ( std::vector< RBSegmentMoverOP >::iterator it_mover = StrandMoveSet_.begin(),
269  it_mover_end = StrandMoveSet_.end(); it_mover != it_mover_end; ++it_mover ) {
270  RBSegmentMoverOP moverToAdd = dynamic_cast< RBSegmentMover * >((*it_mover)()->clone()()); // make a deep copy of the mover
271  if ( it_seg->initialized() ) moverToAdd->set_movement(*it_seg); // override default movement params
272  moverToAdd->setResidueRange( *it_seg );
273  SegmentRandomizeMover->add_mover( moverToAdd );
274  nmovers++;
275  }
276 
277  //////////////////////
278  // GENERIC RB SEGMENTS
279  } else if ( it_seg->isGenericRB() ) {
280  // Neither helix nor strand, we can include more logic here to be more specific
281  // add each genericRB mover
282  // resids refer to those in the loop-removed pose
283  for ( std::vector< RBSegmentMoverOP >::iterator it_mover = GenericRBMoveSet_.begin(),
284  it_mover_end = GenericRBMoveSet_.end(); it_mover != it_mover_end; ++it_mover ) {
285  RBSegmentMoverOP moverToAdd = dynamic_cast< RBSegmentMover * >((*it_mover)()->clone()()); // make a deep copy of the mover
286  moverToAdd->setResidueRange( *it_seg );
287  if ( it_seg->initialized() ) moverToAdd->set_movement(*it_seg); // override default movement params
288  SegmentRandomizeMover->add_mover( moverToAdd );
289  nmovers++;
290  }
291 
292  //////////////////////
293  // COMPOUND SEGMENTS
294  } else if ( it_seg->isCompound() ) {
295  if (! it_seg->initialized() ) {
296  it_seg->set_movement( genericRB_sigT, genericRB_sigR );
297  }
298  // add each genericRB mover
299  // resids refer to those in the loop-removed pose
300  for ( std::vector< RBSegmentMoverOP >::iterator it_mover = CompositeSegmentMoveSet_.begin(),
301  it_mover_end = CompositeSegmentMoveSet_.end(); it_mover != it_mover_end; ++it_mover ) {
302  RBSegmentMoverOP moverToAdd = dynamic_cast< RBSegmentMover * >((*it_mover)()->clone()()); // make a deep copy of the mover
303  moverToAdd->setResidueRange( *it_seg );
304  if ( it_seg->initialized() ) moverToAdd->set_movement(*it_seg); // override default movement params
305  SegmentRandomizeMover->add_mover( moverToAdd );
306  nmovers++;
307  }
308 
309  /////////////////////
310  // error?
311  } else {
312  TS << "[ ERROR ] Unknown segment type\n";
313  exit(1);
314  }
315  }
316 
317  if (nmovers == 0) {
318  TS << "[ ERROR ] RBSegmentRelax::apply() caled with no segments or movers defined!\n";
319  return;
320  }
321 
322  // repacking task
323  // to do: use factory
325  taskstd->initialize_from_command_line();
326  taskstd->restrict_to_repacking();
327  taskstd->or_include_current(true);
329 
330  // rand
331  if (rand_>0) {
332  for (int i=1; i<=(int)rand_; ++i) {
333  SegmentRandomizeMover->apply( pose_noloops );
334  }
335 
336  // repack
337  pack.apply( pose_noloops );
338  }
339 
340  // set up move-minimization cycle
341 
342  // create MC object
343  // - Currently, this is not exposed in the interface, since the MC object needs
344  // the pose object _without_ loops, which is not created until apply is called
345  // - In the future, removal of loops should be separated from apply, which would
346  // allow the MC object to be exposed in the interface
347  // - A side effect of this is that the viewer -- that needs the MC object --
348  // can only be called here. Again, this should be fixed in the future
349  mc_ = new protocols::moves::MonteCarlo( pose_noloops , *scorefxn_ , init_temp );
350 
351  // wrap in a MC search for 'cycles' iteration
352  int total_cycles = cycles_;
353  core::Real temperature = init_temp;
354  core::Real gamma = std::pow( final_temp/init_temp, 1.0/total_cycles );
355  mc_->reset( pose_noloops );
356  mc_->set_temperature( temperature );
357 
358  //Minimizer object
360  optimization::MinimizerOptions options1( "linmin", 0.1, true, false );
361  core::optimization::MinimizerOptions options2( "dfpmin_armijo_nonmonotone", 1e-3, true, false );
362 
363  // set movemaps
364  if (fullatom) {
365  mm.set_bb( true );
366  mm.set_chi( true );
367 
368  // fix ligands
369  if ( fix_ligands_ ) {
370  for (int i=1; i<=(int)pose.total_residue(); ++i) {
371  if ( pose.residue(i).is_ligand() ) {
372  mm.set_bb( false );
373  mm.set_chi( false );
374  }
375  }
376  }
377  } else {
378  //mm.set_bb( true );
379  mm.set_bb( false ); // ? think about this
380  mm.set_chi( false );
381  }
382 
383  scorefxn_->show( TS.Debug , pose_noloops );
384  for (int i=0; i<total_cycles; ++i) {
385  temperature *= gamma;
386  mc_->set_temperature( temperature );
387 
388  // 1: random move
389  SegmentRandomizeMover->apply( pose_noloops );
390 
391  // 2: minimization
392  if (fullatom) {
393  // if fullatom mode
394  // repack + SC + RB minimize (as in docking)
395  // TO DO restrict packing to interface reses only
396  pack.apply( pose_noloops );
397  mzr.run( pose_noloops, mm, *scorefxn_, options2 );
398  } else {
399  // quick BB + RB linmin
400  mzr.run( pose_noloops, mm, *scorefxn_, options1 );
401  }
402 
403  // 3: MC
404  (*scorefxn_)(pose_noloops);
405  scorefxn_->show_line( TS.Debug , pose_noloops );
406  //scorefxn_->show( std::cout , pose_noloops );
407  if ( mc_->boltzmann( pose_noloops ) ) TS.Debug << " *";
408  TS.Debug << std::endl;
409 
410  mc_->boltzmann( pose_noloops );
411  }
412 
413  // recover low-energy pose
414  mc_->recover_low( pose_noloops );
415  mc_->show_counters();
416 
417  if (no_lr_ || loops_input_.size() == 0) {
418  pose = pose_noloops;
419  // rescore
420  (*scorefxn_)(pose);
421  } else {
422  //pose_noloops.dump_pdb("rb_noloops.pdb");
423  restore_pose_from_rbsegs( rbsegs_input_ , pose_noloops, pose );
424 
425  // cut loops & restore original loop conformation
426  // dilate loops
428  for ( loops::Loops::iterator it = loops->v_begin(), it_end = loops->v_end(); it != it_end; ++it ) {
429  if (!pose.fold_tree().is_cutpoint( it->start() - 1 ) )
430  it->set_start( it->start() - 1 );
431  if (!pose.fold_tree().is_cutpoint( it->stop() ) )
432  it->set_stop( it->stop() + 1 );
433  }
434 
435  core::kinematics::FoldTree f, f_in = pose.fold_tree();
436  loops->auto_choose_cutpoints( pose );
437  protocols::loops::fold_tree_from_loops( pose, *loops, f);
438 
439  //pose.dump_pdb("precopy.pdb");
440  //protocols::viewer::add_conformation_viewer( pose.conformation() ); // <<<< added in looprelax mover
441  pose.fold_tree( f );
442  for ( loops::Loops::const_iterator it = loops->begin(), it_end = loops->end(); it != it_end; ++it ) {
443  core::Size lstart = it->start(), lstop = it->stop();
444  idealize_loop( pose, *it );
445  for (core::Size k=lstart; k<lstop; ++k) {
446  pose.set_phi( k, pose_input.phi(k) );
447  pose.set_psi( k, pose_input.psi(k) );
448  pose.set_omega( k, pose_input.omega(k) );
449  }
450  }
451  pose.fold_tree( f_in );
452 
453  // get LR params
454  std::string remodel, intermedrelax, refine, relax;
455 
456  // defaults
457  remodel = "quick_ccd";
458  refine = "no";
459  intermedrelax = "no";
460  relax = "fastrelax";
461 
462  // override defaults is specified on the command line
463  if ( option[ OptionKeys::loops::remodel ].user() )
464  remodel = option[ OptionKeys::loops::remodel ]();
465  if ( option[ OptionKeys::loops::intermedrelax ].user() )
466  intermedrelax = option[ OptionKeys::loops::intermedrelax ]();
467  if ( option[ OptionKeys::loops::refine ].user() )
468  refine = option[ OptionKeys::loops::refine ]();
469  if ( option[ OptionKeys::loops::relax ].user() )
470  relax = option[ OptionKeys::loops::relax ]();
471 
472  // set up LR constraints (if provided in input pose)
473  set_constraints( pose, pose_input, cst_width_, cst_stdev_, cst_seqwidth_ );
474 
475  // setup scorefunction for loopbuilding
478 
479  // call looprelax
481  mover.fa_scorefxn( lr_fa_scorefxn );
482  mover.frag_libs( frag_libs_ );
483  mover.loops( loops );
484  mover.relax( relax );
485  mover.refine( refine );
486  mover.remodel( remodel );
487  mover.intermedrelax( intermedrelax );
488  mover.cmd_line_csts( false ); // csts come from this protocol, not the cmd line
489  // however, use wts from cmd line
490  mover.apply( pose );
491  //TS << "FINAL fold tree " << pose.fold_tree() << std::endl;
492  }
493 }
494 
495 
498  return "RBSegmentRelax";
499 }
500 
501 //////////////////////////////////////////////////////////////////////////
502 ///@brief
503 //////////////////////////////////////////////////////////////////////////
505  HelixMoveSet_.push_back( newMover );
506 }
507 
508 
509 //////////////////////////////////////////////////////////////////////////
510 ///@brief
511 //////////////////////////////////////////////////////////////////////////
513  StrandMoveSet_.push_back( newMover );
514 }
515 
516 
517 //////////////////////////////////////////////////////////////////////////
518 ///@brief
519 //////////////////////////////////////////////////////////////////////////
521  GenericRBMoveSet_.push_back( newMover );
522 }
523 
524 
525 //////////////////////////////////////////////////////////////////////////
526 ///@brief
527 //////////////////////////////////////////////////////////////////////////
529  CompositeSegmentMoveSet_.push_back( newMover );
530 }
531 
532 //////////////////////////////////////////////////////////////////////////
533 ///@brief
534 //////////////////////////////////////////////////////////////////////////
536  WholeStructureMoveSet_.push_back( newMover );
537 }
538 
539 
540 //////////////////////////////////////////////////////////////////////////
541 ///@brief
542 //////////////////////////////////////////////////////////////////////////
544  HelixMoveSet_.clear();
545  StrandMoveSet_.clear();
546  GenericRBMoveSet_.clear();
547  CompositeSegmentMoveSet_.clear();
548  WholeStructureMoveSet_.clear();
549 }
550 
551 }// moves
552 }//protocols