Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TemperedDocking.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 TemperedDocking
11 /// @brief low resolution docking using parallel or simulated tempering
12 /// @detailed
13 /// @author Oliver Lange
14 
15 //Unit Headers
18 
19 //Package Headers
21 
22 //Project Headers
23 #include <basic/options/option.hh>
24 #include <basic/options/keys/OptionKeys.hh>
25 
27 
30 
31 #include <core/pose/Pose.hh>
32 
34 
44 
45 // Utility Headers
46 #include <utility/tag/Tag.hh>
47 #include <utility/tools/make_vector1.hh>
48 
49 // ObjexxFCL Headers
50 #include <ObjexxFCL/string.functions.hh>
51 #include <ObjexxFCL/format.hh>
52 
53 //#include <numeric/trig.functions.hh>
54 //#include <numeric/xyzMatrix.fwd.hh>
55 
56 // C++ Headers
57 #include <string>
58 
59 #include <basic/Tracer.hh>
60 
61 //Auto Headers
62 #include <basic/options/option_macros.hh>
63 #include <basic/options/keys/run.OptionKeys.gen.hh>
64 #include <basic/options/keys/rigid.OptionKeys.gen.hh>
65 #include <basic/options/keys/docking.OptionKeys.gen.hh>
66 #include <basic/options/keys/score.OptionKeys.gen.hh>
67 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
68 
70 
71 
72 // cmd-line options
73 
74 
76 
78  using namespace basic::options;
79  using namespace OptionKeys;
80  if ( options_registered_ ) return;
81  options_registered_ = true;
85  OPT( docking::partners );
86  OPT( score::patch );
87  OPT( constraints::cst_file );
88  OPT( run::n_cycles );
89  OPT( run::n_replica );
90  OPT( rigid::translation );
91  OPT( rigid::rotation );
92 }
93 
94 static basic::Tracer tr("protocols.docking.TemperedDocking");
95 
96 using namespace core;
97 
98 namespace protocols {
99 namespace docking {
100 
101 //// ----------------------------------- BEGIN CONSTRUCTORS --------------------------------------------------
102 // Constructors
104  init( utility::tools::make_vector1<core::SSize>(1), NULL, NULL);
105 }
106 
108  DockJumps const movable_jumps,
109  core::scoring::ScoreFunctionCOP docking_score_low,
110  core::scoring::ScoreFunctionCOP docking_score_high
111 ) {
112  Mover::type( "TemperedDocking" );
114  docking_scorefxn_low_ = docking_score_low;
115  docking_scorefxn_high_= docking_score_high;
116 
117  // setup all the booleans with default values
118  // they will get overwritten by the options and/or passed values
119  set_defaults();
121 
122  // set up objects based on the boolean values defined above
123  setup_objects();
124 }
125 
126 ///@brief clone operator, calls the copy constructor
129  return new TemperedDocking(*this);
130 }
131 
132 ///@brief copy ctor
134  Mover(rhs)
135 {
136  copy(*this, rhs);
137 }
138 
139 ///@brief assignment operator
141  //abort self-assignment
142  if (this == &rhs) return *this;
143  Mover::operator=(rhs);
144  copy(*this, rhs);
145  return *this;
146 }
147 
149 
150  lhs.autofoldtree_ = rhs.autofoldtree_;
153  lhs.sc_min_ = rhs.sc_min_;
154 
155  lhs.use_csts_ = rhs.use_csts_;
156 
157  lhs.fold_tree_ = rhs.fold_tree_;
158  lhs.partners_ = rhs.partners_;
160 
161  lhs.movable_jumps_ = rhs.movable_jumps_;
162  lhs.docking_scorefxn_low_ = rhs.docking_scorefxn_low_->clone();
164 
165  lhs.to_centroid_ = rhs.to_centroid_->clone();
166 
167  if( rhs.docking_constraint_ ) lhs.docking_constraint_ = rhs.docking_constraint_->clone();
168 }
169 
170 //// ----------------------------------- END CONSTRUCTORS --------------------------------------------------
171 
172 ///@brief setup steps when new pose comes in (this is not repeated for every reply, ... only when new sequence.. )
173 void
174 TemperedDocking::finalize_setup( pose::Pose & pose ) //setup objects requiring pose during apply
175 {
176  if( autofoldtree_ ) {
177  tr.Info << "Setting docking foldtree" << std::endl;
178  tr.Info << "old fold tree: " << pose.fold_tree() << std::endl;
180  tr.Info << "new fold tree: " << pose.fold_tree() << std::endl;
181  }
182  fold_tree_ = pose.fold_tree();
183 
184  rb_mover_->clear_jumps();
185  for ( Size i=1; i<=pose.num_jump(); ++i ) {
186  // should honor movemap or movable_jumps_ here...
187  rb_mover_->add_jump( i );
188  }
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// @begin Docking apply
193 ///
194 /// @brief main docking protocol
195 ///
196 /// @detailed
197 ///
198 void
200 {
201  /// -------------- any changes ? ------------------------------------------------------
204  }
205 
206  /// ---------------- do we have to call finalize_setup() again ? -------------------------////
207  if ( previous_sequence_.compare( pose.sequence() ) != 0 ){
209  previous_sequence_ = pose.sequence();
210  }
211 
213  finalize_setup( pose );
215  }
216 
217  pose.fold_tree( fold_tree_ );
218  show(tr.Info);
219 
220  /// go into centroid mode
221  to_centroid_->apply( pose );
222 
223  /// apply constraints
224  if ( docking_constraint_ ) {
225  tr.Info << "setting up the constraint set mover" << std::endl;
226  docking_constraint_->apply( pose );
227  }
228 
229  sampler_->apply( pose );
230 
231 
232 }
233 
234 //// --------------------------------- Setters -------------------------------------------------
235 
236 
238 {
239  docking_scorefxn_low_ = docking_scorefxn_low;
240 }
241 
243 {
244  set_highres_scorefxn( scfxn, scfxn, scfxn );
245 }
246 
250 {
251  set_highres_scorefxn( high, pack, high );
252 }
253 
255  core::scoring::ScoreFunctionCOP docking_scorefxn_high,
256  core::scoring::ScoreFunctionCOP docking_scorefxn_pack,
257  core::scoring::ScoreFunctionCOP docking_scorefxn_output )
258 {
259  docking_scorefxn_high_ = docking_scorefxn_high;
260  docking_scorefxn_pack_ = docking_scorefxn_pack;
261  docking_scorefxn_output_ = docking_scorefxn_output;
262 }
263 
265 
267 {
268  if ( use_csts_ != setting ) flags_and_objects_are_in_sync_ = false;
269  use_csts_ = setting;
270 }
271 
272 /// ----------------------------------------- Getters ------------------------------------------
273 
274 //getters for const access to movers and data of docking protocol
276  return to_centroid_;
277 }
278 
279 
280 
281 /// ---------------------------- diagnostic output ------------------------------------------
282 
283 /// @details Show the complete setup of the docking protocol
284 void
285 TemperedDocking::show( std::ostream & out ) {
288  }
289  out << *this;
290 }
291 
292 std::ostream & operator<<(std::ostream& out, const TemperedDocking & dp )
293 {
294  using namespace ObjexxFCL::fmt;
295 
296  // All output will be 80 characters - 80 is a nice number, don't you think?
297  std::string line_marker = "///";
298  out << "////////////////////////////////////////////////////////////////////////////////" << std::endl;
299  out << line_marker << A( 47, "Rosetta 3 Docking Protocol" ) << space( 27 ) << line_marker << std::endl;
300  out << line_marker << space( 74 ) << line_marker << std::endl;
301  // Display the movable jumps that will be used in docking
302  out << line_marker << " Dockable Jumps: ";
303 
304  core::Size spaces_so_far = 23;
305  bool first = true;
306  for ( DockJumps::const_iterator it = dp.movable_jumps_.begin() ; it != dp.movable_jumps_.end() ; ++it ){
307  if (!first) {
308  out << ", ";
309  spaces_so_far += 2;
310  }
311  else first = false;
312 
313  out << I( 1, *it );
314  spaces_so_far += 1;
315  }
316  core::Size remaining_spaces = 80 - spaces_so_far;
317  if ( remaining_spaces > 0 ) out << space( 80 - spaces_so_far );
318  out << line_marker << std::endl;
319 
320  // Close the box I have drawn
321  out << "////////////////////////////////////////////////////////////////////////////////" << std::endl;
322  return out;
323 }
324 
325 /// ------------------ initializing helpers ---------------------------------
326 
327 void
329 {
330  //using namespace basic::options;
331  using namespace core::scoring;
332  autofoldtree_ = true;
333 
334  sc_min_ = false;
335  partners_ = "_";
336  n_cycles_ = 10000;
337 
338 }
339 
341 {
342  // initialize constraint set mover
343  docking_constraint_ = NULL;
344 
345  // stores the sequence of the previous pose, so that the TemperedDocking can re setup the fold tree
346  previous_sequence_ = "";
347 
349 
350  // Residue movers
352 
353  // correctly set up the score functions from either passed in values or defaults
354 
357 
358  rb_mover_->rot_magnitude( rigid_rot_mag_ );
359  rb_mover_->trans_magnitude( rigid_trans_mag_ );
360 
362 
363  sampler_->set_monte_carlo( mc_object );
364  sampler_->set_ntrials( n_cycles_ );
365  tempering_->set_monte_carlo( mc_object );
366 
367  sampler_->add_mover( rb_mover_, 1.0 );
368  sampler_->set_tempering( tempering_ );
371 }
372 
374 {
375  // set up constraint set mover
376  if ( !use_csts_ ) {
377  docking_constraint_ = NULL;
378  } else {
379  if ( !docking_constraint_ ) {
381  }
382  }
383 
386 }
387 
388 void
390 {
391  using namespace basic::options;
392 
393  // check for n_cycle option
394  if ( option[ OptionKeys::run::n_cycles ].user() ) {
395  n_cycles_ = option[ OptionKeys::run::n_cycles ]();
396  }
397 
398  // check for movable jumps option
399  if( option[ OptionKeys::docking::multibody ].user() ) {
400  set_movable_jumps( option[ OptionKeys::docking::multibody ]() );
401  }
402 
403  // Sets the member directly so sync_objects_with_flags won't be triggered prematurely.
404  // A public setter exists for this member.
405  if( option[ OptionKeys::docking::sc_min ].user() ) {
406  sc_min_ = option[ OptionKeys::docking::sc_min ]();
407  }
408 
409  // This defaults to "_"
410  if( option[ OptionKeys::docking::partners ].user() ) {
411  set_partners(option[ OptionKeys::docking::partners ]());
412  }
413 
414  // Defaults to false
415  set_use_constraints( option[ OptionKeys::constraints::cst_file ].user() );
416 
417  if ( !docking_scorefxn_low_ ) {
418  //docking_scorefxn_low_ = core::scoring::ScoreFunctionFactory::create_score_function( "interchain_cen" );
420  option[ OptionKeys::score::patch ]()
421  );
422  }
423  if ( !docking_scorefxn_high_ ) {
427  }
428 
429  rigid_rot_mag_ = option[ OptionKeys::rigid::rotation ]();
430  rigid_trans_mag_ = option[ OptionKeys::rigid::translation ]();
431 
432  if ( option[ OptionKeys::run::n_replica ]() > 1 ) {
434  } else {
436  }
437 
438 }
439 
440 
441 void
443 {
444  using namespace core::scoring;
445 
446  if( tag->hasOption("docking_score_low" ) ){
447  std::string const score_low( tag->getOption<std::string>( "docking_score_low" ) );
448  ScoreFunctionOP scorelo = new ScoreFunction( *data.get< ScoreFunction * >( "scorefxns", score_low ) );
449  set_lowres_scorefxn(scorelo);
450  }
451  if( tag->hasOption("docking_score_high" ) ){
452  std::string const score_high( tag->getOption<std::string>( "docking_score_high" ) );
453  ScoreFunctionOP scorehi = new ScoreFunction( *data.get< ScoreFunction * >( "scorefxns", score_high ));
454  set_highres_scorefxn(scorehi);
455  }
456  //get through partners
457  if( tag->hasOption( "partners" ) ){
458  std::string const partners( tag->getOption<std::string>( "partners") );
459  set_partners(partners);
460  }
461 
462 }//end parse_my_tag
463 
464 
465 /// ------------------ End initializing helpers ---------------------------------
466 
469 {
471 }
472 
475  return new TemperedDocking();
476 }
477 
480 {
481  return "TemperedDocking";
482 }
483 } //docking
484 } //protocols