Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DockingInitialPerturbation.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 DockingInitialPerturbation.cc
11 /// @brief initial position functions
12 /// @detailed
13 /// This contains the functions that create initial positions for docking
14 /// You can either randomize partner 1 or partner 2, spin partner 2, or
15 /// perform a simple perturbation.
16 /// Also contains docking mcm protocol
17 /// @author Monica Berrondo
18 
21 
22 // Rosetta Headers
23 #include <protocols/moves/Mover.hh>
25 #include <protocols/docking/RigidBodyInfo.hh> // zhe
26 #include <protocols/moves/DataMap.hh> // zhe
27 
28 #include <core/pose/Pose.hh>
29 #include <core/pose/Pose.fwd.hh>
30 #include <basic/options/option.hh>
31 #include <core/scoring/Energies.hh>
32 
35 
36 
37 // ObjexxFCL Headers
38 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
39 #include <ObjexxFCL/string.functions.hh>
40 
41 // C++ Headers
42 #include <string>
43 
44 //Utility Headers
45 // AUTO-REMOVED #include <numeric/conversions.hh>
46 
47 #include <numeric/trig.functions.hh>
48 #include <numeric/xyzMatrix.fwd.hh>
49 
50 #include <basic/Tracer.hh>
51 #include <utility/tools/make_vector1.hh>
52 #include <utility/tag/Tag.hh>
53 using basic::T;
54 
55 // option key includes
56 
57 #include <basic/options/keys/docking.OptionKeys.gen.hh>
58 
59 #include <utility/excn/Exceptions.hh>
60 #include <utility/vector1.hh>
61 
62 using basic::Error;
63 using basic::Warning;
64 
65 static basic::Tracer TR("protocols.docking.DockingInitialPerturbation");
66 static core::Size trans ( 1 ), rot ( 2 );
67 
68 using namespace core;
69 
70 namespace protocols {
71 namespace docking {
72 
73 
74 // Creator part for DockingInitialPerturbation, used in scripts
76 DockingInitialPerturbationCreator::keyname() const
77 {
78  return DockingInitialPerturbationCreator::mover_name();
79 }
80 
82 DockingInitialPerturbationCreator::create_mover() const
83 {
84  return new DockingInitialPerturbation;
85 }
86 
88 DockingInitialPerturbationCreator::mover_name()
89 {
90  return "DockingInitialPerturbation";
91 }
92 
93 
94 // initial perturbation on one of the partners
95 // the type of perturbation is defined in the options
96 // some of the options are randomize1 (randomizes the first partner)
97 // randomize2 (randomizes the second partner), dock_pert, and spin
98 //------------------------------------------------------------------------------
99 //
100 // there are several ways to perturb the structure before beginning
101 // the search; they are controlled through command-line flags
102 //
103 // at the end, partners are slid into contact and scored
104 //
105 
106 
107 //constructors
108 DockingInitialPerturbation::DockingInitialPerturbation()
109  :
110  Mover(),
111  slide_( true ),
112  rigid_body_info_( NULL )
113 {
114  Mover::type( "DockingInitialPerturbation" );
115  movable_jumps_ = utility::tools::make_vector1<core::Size>(1);
116  multiple_jumps_ = false;
117  init();
118 }
119 
121  core::Size const rb_jump,
122  bool const slide
123 ) :
124  Mover(),
125  slide_(slide),
126  rigid_body_info_( NULL )
127 {
128  Mover::type( "DockingInitialPerturbation" );
129  movable_jumps_ = utility::tools::make_vector1<core::Size>(rb_jump);
130  multiple_jumps_ = false;
131  init();
132 }
133 
135  DockJumps const movable_jumps,
136  bool const slide
137 ) :
138  Mover(),
139  slide_( slide ),
140  movable_jumps_( movable_jumps ),
141  rigid_body_info_( NULL )
142 {
143  Mover::type( "DockingInitialPerturbation" );
144  if ( movable_jumps_.size() > 1 ) multiple_jumps_ = true;
145  else multiple_jumps_ = false;
146  init();
147 }
148 
149 void
151 {
152  set_default();
153  init_from_options(); // put this into apply in case scripts is used, then this will not be needed.
154 }
155 
156 void
158 {
159  randomize1_ = false;
160  randomize2_ = false;
161  if_dock_pert_ = false;
162  if_uniform_trans_ = false;
163  spin_ = false;
164  center_at_interface_ = false;
165  // dock_pert_ = new utility::vector1< Real >(NULL);
166  // uniform_trans_ = NULL;
167 }
168 
171  return new DockingInitialPerturbation( *this );
172 }
173 
174 //destructor
176 
177 // ALERT!
178 // register_options() and init_from_options() are not called anywhere yet!!!!!
179 // !!!!!!!!!!!!!!!!!!!!!!!11
180 
181 void
183 {
184  using namespace basic::options;
185  TR << "Reading options..." << std::endl;
186 
187  if ( option[ OptionKeys::docking::randomize1 ].user() )
188  set_randomize1(option[ OptionKeys::docking::randomize1 ]());
189 
190  if ( option[ OptionKeys::docking::randomize2 ].user() )
191  set_randomize2(option[ OptionKeys::docking::randomize2 ]());
192 
193  if ( option[ OptionKeys::docking::dock_pert ].user() )
194  set_dock_pert(option[ OptionKeys::docking::dock_pert ]());
195 
196 
197  if ( option[ OptionKeys::docking::uniform_trans ].user() )
198  set_uniform_trans(option[ OptionKeys::docking::uniform_trans ]());
199 
200  if ( option[ OptionKeys::docking::spin ].user() )
201  set_spin(option[ OptionKeys::docking::spin ]());
202 
203  if ( option[ OptionKeys::docking::center_at_interface ].user() )
204  set_center(option[ OptionKeys::docking::center_at_interface ]());
205 }
206 
207 void
209 {
210  using namespace basic::options;
211 
212  option.add_relevant( OptionKeys::docking::randomize1 );
213  option.add_relevant( OptionKeys::docking::randomize2 );
214  option.add_relevant( OptionKeys::docking::dock_pert );
215  option.add_relevant( OptionKeys::docking::uniform_trans );
216  option.add_relevant( OptionKeys::docking::spin );
217  option.add_relevant( OptionKeys::docking::center_at_interface );
218 }
219 
220 
221 ////////////////////////////////////////////////////////////////////////////////
222 /// @begin initial_perturbation
223 ///
224 /// @brief Make starting perturbations for rigid body moves
225 ///
226 /// @detailed There are several ways to perturb the structure before beginning
227 /// the search; they are controlled through command-line flags
228 /// At the end, partners are slid into contact and scored (including
229 /// mc_reset).
230 /// Also, they are tested for passing the FAB filter.
231 ///
232 ///
233 /// @references see dock_structure or pose_docking from rosetta++
234 ///
235 /// @authors Monica Berrondo June 14 2007
236 ///
237 /// @last_modified October 17 2007
238 /////////////////////////////////////////////////////////////////////////////////
240 {
241  if ( rigid_body_info_ ) {
242  movable_jumps_ = rigid_body_info_->movable_jumps();
243  TR.Debug << "finished reading movable_jumps_ from RigidBodyInfo" << std::endl;
244  if ( movable_jumps_.empty() ) {
245  utility_exit_with_message( "DockSetupMover has to be applied before DockingInitialPerturbation !" );
246  }
247  }
248 
249 
250  runtime_assert( !movable_jumps_.empty() );
251 
252  for ( DockJumps::const_iterator it=movable_jumps_.begin(); it != movable_jumps_.end(); ++it){
253  apply_body( pose, *it );
254  TR.Debug <<"movable_jumps_ value in apply:" << *it << std::endl;
255  }
256 }
257 
258 void
260 {
261  using namespace moves;
262 
263  if ( randomize1_ ) {
264  TR << "randomize1: true" << std::endl;
265  rigid::RigidBodyRandomizeMover mover( pose, jump_number, rigid::partner_upstream );
266  mover.apply( pose );
267  }
268  if ( randomize2_ ) {
269  TR << "randomize2: true" << std::endl;
270  rigid::RigidBodyRandomizeMover mover( pose, jump_number, rigid::partner_downstream );
271  mover.apply( pose );
272  }
273  if ( if_dock_pert_ ) {
274  // DO NOT supply default values for this option -- reasonable values differ for protein and ligand protocols.
275  // Also, default values will cause a perturbation to *always* occur, even with no command line flags -- very surprising.
276  // Adding defaults WILL BREAK existing protocols in unexpected ways.
277  // Decided by Jeff, Monica, Ian, and Sid in March 2008.
278  //
279  // Jeff notes that eventually there should be 3 parameters, like Rosetta++:
280  // rotation, normal translation, and perpendicular translation.
281  TR << "dock_pert: true" << std::endl;
282  /// read in dock_pert options from commandline. the first value is the
283  /// rotation magnitude and the second value is the translational value
285  //TR << "option[ docking::rotational ]()" << rot << "\n";
286  //TR << "option[ docking::parallel ]()" << trans << "\n";
287  TR << "option[ docking::dock_pert ]()" << pert_mags[rot] << ' ' << pert_mags[trans] << std::endl;
289  if (center_at_interface_) mover = new rigid::RigidBodyPerturbMover( jump_number, pert_mags[rot], pert_mags[trans], rigid::partner_downstream, true );
290  else mover = new rigid::RigidBodyPerturbMover( jump_number, pert_mags[rot], pert_mags[trans] );
291  mover->apply( pose );
292  }
293 
294  if ( if_uniform_trans_ ) {
295  core::Real mag( uniform_trans_ );
296  TR << "uniform_trans: " << mag << std::endl;
297  rigid::UniformSphereTransMover mover( jump_number, mag );
298  mover.apply( pose );
299  }
300  if ( spin_ ) {
301  TR << "axis_spin: true" << std::endl;
302  rigid::RigidBodySpinMover mover( jump_number );
303  mover.apply( pose );
304  }
305  // DO NOT do this for e.g. ligand docking
306  if ( slide_ && !pose.is_fullatom() ) {
307  DockingSlideIntoContact slide( jump_number );
308  slide.apply( pose );
309  TR.Debug << "centroid mode, DockingSlideIntoContact applied" << std::endl;
310  } else if ( slide_ ) {
311  FaDockingSlideIntoContact slide( jump_number );
312  slide.apply( pose );
313  TR.Debug << "fa-standard mode, FaDockingSlideIntoContact applied" << std::endl;
314  }
315 
316 
317 }
320  return "DockingInitialPerturbation";
321 }
322 
323 void
325  utility::tag::TagPtr const tag,
326  protocols::moves::DataMap & data_map,
329  core::pose::Pose const &
330 ) {
331  if ( !data_map.has( "RigidBodyInfo", "docking_setup" ) ) {
332  TR << "RigidBodyInfo not found in DataMap" << std::endl;
334  data_map.add( "RigidBodyInfo", "docking_setup", rigid_body_info_ );
335  // throw utility::excn::EXCN_RosettaScriptsOption( "RigidBodyInfo not found in DataMap, DockingInitialPerturbation can not be done, so exit here!" );
336  } else {
337  rigid_body_info_ = data_map.get< protocols::docking::RigidBodyInfo* >( "RigidBodyInfo", "docking_setup" );
338  TR.Debug << "get RigidBodyInfo pointer from DataMap" << std::endl;
339  }
340 
341  if ( tag->hasOption( "randomize1" ) ) {
342  set_randomize1( tag->getOption<bool>( "randomize1" ) );
343  }
344 
345  if ( tag->hasOption( "randomize2" ) ) {
346  set_randomize2( tag->getOption<bool>( "randomize2" ) );
347  }
348 
349  if ( tag->hasOption( "dock_pert" ) && tag->getOption<bool>( "dock_pert" ) ) {
350  dock_pert_.push_back( tag->getOption<core::Real>("trans" ) );
351  dock_pert_.push_back( tag->getOption<core::Real>( "rot" ) );
353  }
354 
355  if ( tag->hasOption( "uniform_trans" ) ) {
356  set_uniform_trans( tag->getOption<core::Real>( "uniform_trans" ) );
357  }
358 
359  if ( tag->hasOption( "spin" ) ) {
360  set_spin( tag->getOption<bool>( "spin" ) );
361  }
362 
363  if ( tag->hasOption( "center_at_interface" ) ) {
364  set_center( tag->getOption<bool>( "center_at_interface" ) );
365  }
366 
367  slide_ = tag->getOption<bool>( "slide", true );
368 }
369 ////////////////////////////////////////// DockingSlideIntoContact ////////////////////////////////
370 
371 // default constructor
373 {
374  using namespace core::scoring;
375  Mover::type( "DockingSlideIntoContact" );
376  rb_jump_ = 1;
379 }
380 
381 //constructor
383  core::Size const rb_jump
384 ) : Mover(), rb_jump_(rb_jump)
385 {
386  using namespace core::scoring;
387  Mover::type( "DockingSlideIntoContact" );
390 }
391 
392 //destructor
394 
395 
397 {
398  using namespace moves;
399 
400  rigid::RigidBodyTransMover mover( pose, rb_jump_ );
401  ( *scorefxn_ )( pose );
402 
403  TR << "sliding into contact" << std::endl;
404  TR << "Moving away" << std::endl;
405  core::Size const counter_breakpoint( 500 );
406  core::Size counter( 0 );
407  // first try moving away from each other
408  while ( pose.energies().total_energies()[ scoring::interchain_vdw ] > 0.1 && counter <= counter_breakpoint ) {
409  mover.apply( pose );
410  ( *scorefxn_ )( pose );
411  ++counter;
412  }
413  if( counter > counter_breakpoint ){
414  TR<<"failed moving away with original vector. Aborting DockingSlideIntoContact."<<std::endl;
415  set_current_tag( "fail" );
416  return;
417  }
418  counter = 0;
419  // then try moving towards each other
420  TR << "Moving together" << std::endl;
421  mover.trans_axis().negate();
422  while ( counter <= counter_breakpoint && pose.energies().total_energies()[ scoring::interchain_vdw ] < 0.1 ) {
423  mover.apply( pose );
424  ( *scorefxn_ )( pose );
425  ++counter;
426  }
427  if( counter > counter_breakpoint ){
428  TR<<"moving together failed. Aborting DockingSlideIntoContact."<<std::endl;
429  set_current_tag( "fail" );
430  return;
431  }
432  // move away again until just touching
433  mover.trans_axis().negate();
434  mover.apply( pose );
435 }
436 
439  return "DockingSlideIntoContact";
440 }
441 
442 std::ostream &operator<< ( std::ostream &os, DockingSlideIntoContact const &mover )
443 {
444  moves::operator<<(os, mover);
445  os << "Jump number: " << mover.get_jump_num() << std::endl;
446  return os;
447 }
448 
449 ////////////////////////////////////////// FaDockingSlideIntoContact ////////////////////////////////
450 
451 // default constructor
453 {
454  Mover::type( "FaDockingSlideIntoContact" );
456  scorefxn_->set_weight( core::scoring::fa_rep, 1.0 );
457 }
458 
459 
460 //constructor
462  core::Size const rb_jump
463 ) : Mover(), rb_jump_(rb_jump), tolerance_(0.2)
464 {
465  Mover::type( "FaDockingSlideIntoContact" );
467  scorefxn_->set_weight( core::scoring::fa_rep, 1.0 );
468 }
469 
471  Mover(), rb_jumps_(rb_jumps),tolerance_(0.2){
472  Mover::type( "FaDockingSlideIntoContact" );
474  scorefxn_->set_weight( core::scoring::fa_rep, 1.0 );
475 }
476 
477 //destructor
479 
481 {
482  using namespace core::scoring;
483 
484  // A very hacky way of guessing whether the components are touching:
485  // if pushed together by 1A, does fa_rep change at all?
486  // (The docking rb_* score terms aren't implemented as of this writing.)
487  (*scorefxn_)( pose );
488  core::Real const initial_fa_rep = pose.energies().total_energies()[ fa_rep ];
489  bool are_touching = false;
490 
492 
493  if(rb_jumps_.size()<1){
494  trans_movers.push_back( rigid::RigidBodyTransMover(pose,rb_jump_));
495  }
496  else{
497  for(
499  end = rb_jumps_.end();
500  jump_idx != end;
501  jump_idx++
502  ){
503  trans_movers.push_back( rigid::RigidBodyTransMover(pose, *jump_idx));
504  }
505  }
506 
508 
509  //int i=1;
510  // Take 2A steps till clash, then back apart one step. Now you're within 2A of touching.
511  // Repeat with 1A steps, 0.5A steps, 0.25A steps, etc until you're as close are you want.
512  for( core::Real stepsize = 2.0; stepsize > tolerance_; stepsize /= 2.0 ) {
513  for(
514  utility::vector1< rigid::RigidBodyTransMover >::iterator trans_mover(trans_movers.begin());
515  trans_mover != end;
516  trans_mover++
517  ){
518  trans_mover->trans_axis( trans_mover->trans_axis().negate() ); // now move together
519  trans_mover->step_size(stepsize);
520  }
521  core::Size const counter_breakpoint( 500 );
522  core::Size counter( 0 );
523  do
524  {
525  for(
526  utility::vector1< rigid::RigidBodyTransMover >::iterator trans_mover(trans_movers.begin());
527  trans_mover != end;
528  trans_mover++
529  ){
530  trans_mover->apply( pose );
531  }
532  (*scorefxn_)( pose );
533  core::Real const push_together_fa_rep = pose.energies().total_energies()[ fa_rep ];
534  //std::cout << "fa_rep = " << push_together_fa_rep << std::endl;
535  are_touching = (std::abs(initial_fa_rep - push_together_fa_rep) > 1e-4);
536  //std::ostringstream s;
537  //s << "snapshot" << i << ".pdb";
538  //pose.dump_pdb(s.str());
539  //i += 1;
540  ++counter;
541  } while( counter <= counter_breakpoint && !are_touching );
542  if( counter > counter_breakpoint ){
543  TR<<"Failed Fadocking Slide Together. Aborting."<<std::endl;
544  set_current_tag( "fail" );
545  }
546  for(
547  utility::vector1< rigid::RigidBodyTransMover >::iterator trans_mover(trans_movers.begin());
548  trans_mover != end;
549  trans_mover++
550  ){
551  trans_mover->trans_axis( trans_mover->trans_axis().negate() ); // now move apart
552  trans_mover->apply( pose );
553  }
554  }
555 }
556 
559  return "FaDockingSlideTogether";
560 }
561 
562 std::ostream &operator<< ( std::ostream &os, FaDockingSlideIntoContact const &fadock )
563 {
564  moves::operator<<(os, fadock);
565  os << "Jump number: " << fadock.get_jump_num() << "\nTolerance: " << fadock.get_tolerance() << std::endl;
566  return os;
567 }
568 
569 } // namespace docking
570 } // namespace protocols