Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FlexPepDockingAbInitio.cc
Go to the documentation of this file.
1 // (c) Copyright Rosetta Commons Member Institutions.
2 // (c) This file is part of the Rosetta software suite and is made available under license.
3 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
4 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
5 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
6 
7 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
8 // vi: set ts=2 noet;
9 //
10 // (C) 199x-2008 Hebrew University, Jerusalem
11 //
12 /// @file FlexPepDockingAbInitio.hh
13 ///
14 /// @brief low-resolution part of docking protocol
15 /// @date August 5, 2008
16 /// @author Barak Raveh
17 
18 
21 
22 #include <core/types.hh>
27 // AUTO-REMOVED #include <core/conformation/util.hh>
28 #include <core/fragment/FragSet.hh>
30 // AUTO-REMOVED #include <core/fragment/FragmentIO.hh>
31 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
33 #include <basic/options/option.hh>
34 #include <basic/options/keys/OptionKeys.hh>
35 #include <basic/options/keys/loops.OptionKeys.gen.hh>
36 #include <basic/options/keys/in.OptionKeys.gen.hh>
37 #include <basic/options/keys/flexPepDocking.OptionKeys.gen.hh>
38 #include <core/pose/util.hh>
40 #include <basic/Tracer.hh>
47 #include <protocols/moves/Mover.hh>
53 #include <utility/exit.hh>
54 #include <string>
55 // AUTO-REMOVED #include <cstdio>
56 #include <math.h>
57 
58 #include <utility/vector0.hh>
59 #include <utility/vector1.hh>
60 
61 
62 using namespace protocols::flexpep_docking;
63 
64 static basic::Tracer TR("protocols.flexPepDockingAbInitio");
65 
66 
67 //////////////////////////////////////////////
68 /// @brief
69 /// constructor for low resolution flexpible peptide docking
70 //
71 // @param[in] scorefxn_in
72 // The scoring function used for optimization
73 // @param[in] rb_jump
74 // The FoldTree rigid body jump over
75 // which rigid-body pertrubations are made
79  core::kinematics::MoveMapOP movemap_in,
80  Size const rb_jump_in )
81  : flags_(flags_in),
82  movemap_(movemap_in),
83  rb_jump_(rb_jump_in),
84  fragset3mer_(NULL),
85  fragset9mer_(NULL),
86  fragset5mer_(NULL)
87 {
88  using namespace basic::options;
89 
90  // TODO: create a set_defaults() function
91  scorefxn_ = new core::scoring::ScoreFunction( *scorefxn_in );
92 
93  // Loop modeling options
94  // NOTE: most LoopRelax options are initiated automatically from cmd-line
95  // TODO: LoopRelaxMover is a wrapper, perhaps user the LoopModel class explicitly
96  loop_relax_mover_ = new protocols::comparative_modeling::LoopRelaxMover();
97  // loop_relax_mover_->centroid_scorefxn(scorefxn_); // TODO: we need a chain brteak score here, so let's leave it for modeller default?
98  loop_relax_mover_->refine("no"); // centroid modeling only
99  loop_relax_mover_->relax("no"); // centroid modeling only
100  if( option[ OptionKeys::loops::frag_files ].user() )
101  {
102  // these protocols optionally take a fragment set .. only load if
103  // specified
106  loop_relax_mover_->frag_libs( frag_libs );
107  }
108  // TODO: choose frag files through FlexPepDockingFlags
109  // 3mer fragments
110  if( option[ basic::options::OptionKeys::in::file::frag3].user() )
111  {
112  fragset3mer_ = new core::fragment::ConstantLengthFragSet( 3 );
113  fragset3mer_->read_fragment_file
114  ( option[ basic::options::OptionKeys::in::file::frag3].value() );
115  }
116  // 9mer fragments
117  if( option[ basic::options::OptionKeys::in::file::frag9].user() )
118  {
119  fragset9mer_ = new core::fragment::ConstantLengthFragSet( 9 );
120  fragset9mer_->read_fragment_file
121  ( option[ basic::options::OptionKeys::in::file::frag9].value() );
122  }
123  //5mer fragments
124  if( option[ basic::options::OptionKeys::flexPepDocking::frag5].user() )
125  {
126  fragset5mer_ = new core::fragment::ConstantLengthFragSet( 5 );
127  fragset5mer_->read_fragment_file
128  ( option[ basic::options::OptionKeys::flexPepDocking::frag5].value() );
129  }
130 
131 }
132 
133 
134 // empty destructor - for good inclusion of OP clasesses
136 {}
137 
138 
139 ///////////////////////////////////////////////
140 /// @brief initial setup for apply
141 void
143 {
144  double temperature = 0.8;
145  mc_ = new moves::MonteCarlo( pose, *scorefxn_, temperature );
146  // setup minimizer
147  std::string min_type = "dfpmin_atol"; // armijo_nonmonotone? different tolerance?
148  double min_func_tol = 0.1;
150  movemap_, scorefxn_, min_type, min_func_tol, true /*nb_list accel.*/ );
151 }
152 
153 
154 ///////////////////////////////////////////////
155 // switch pose to centroid mode, if not already there
156 void
158 ( core::pose::Pose & pose ) const
159 {
160  if(!pose.is_fullatom())
161  return;
162  TR.Debug << "Switching to centroid" << std::endl;
164  to_centroid_mover( core::chemical::CENTROID );
165  to_centroid_mover.apply(pose);
166 }
167 
168 
169 //////////////////////////////////////////////
170 // switch pose to full-atom mode, if not already
171 // using side-chains of referencePose
172 void
174 ( core::pose::Pose & pose, core::pose::Pose& referencePose ) const
175 {
176  runtime_assert(referencePose.is_fullatom());
177  // protocols::simple_moves::SwitchResidueTypeSetMover
178  //to_all_atom_mover( core::chemical::FA_STANDARD );
180  recover_sidechains( referencePose );
181  recover_sidechains.apply( pose );
182 }
183 
184 
185 ////////////////////////////////////////////
186 void
189  const int cycles,
190  double& acceptance_rate )
191 {
192  using namespace protocols::moves;
193  using namespace protocols::simple_moves;
194 
195  // setup sub-moves
196  simple_moves::SmallMoverOP small_mover =
197  new protocols::simple_moves::SmallMover( movemap_, mc_->temperature() /*temp*/, 5 /*nmoves ???*/ );
198  small_mover->angle_max('L',180 /*angle - TODO: parametrize and slowly ramp down */);
199  small_mover->angle_max('H',180 /*angle - TODO: parametrize and slowly ramp down */);
200  small_mover->angle_max('E',180 /*angle - TODO: parametrize and slowly ramp down */);
202  new protocols::simple_moves::ShearMover( movemap_, mc_->temperature() /*temp*/, 5 /*nmoves ???*/ );
203  shear_mover->angle_max('L',180 /*angle - TODO: parametrize, slowly ramp down */);
204  shear_mover->angle_max('H',180 /*angle - TODO: parametrize, slowly ramp down */);
205  shear_mover->angle_max('E',180 /*angle - TODO: parametrize, slowly ramp down */);
207  frag3_mover = NULL,
208  frag9_mover = NULL,
209  frag5_mover = NULL;
210  if(fragset3mer_){ //if we have fragments
211  frag3_mover = new ClassicFragmentMover(fragset3mer_, movemap_);
212  frag3_mover->enable_end_bias_check(false);
213  }
214  if(fragset9mer_){ //if we have fragments
215  frag9_mover = new ClassicFragmentMover(fragset9mer_, movemap_);
216  frag9_mover->enable_end_bias_check(false);
217  }
218  if(fragset5mer_){ //if we have fragments
219  frag5_mover = new ClassicFragmentMover(fragset5mer_, movemap_);
220  frag5_mover->enable_end_bias_check(false);
221  }
222 
223  // setup cycle of sub-moves
224  RandomMoverOP random_mover( new protocols::moves::RandomMover() );
225  random_mover->add_mover(small_mover,1.0 /*weight*/);
226  if(frag3_mover){
227  random_mover->add_mover(frag3_mover,flags_.frag3_weight /*weight*/);
228  }
229  if(frag9_mover){
230  random_mover->add_mover(frag9_mover,flags_.frag9_weight /*weight*/);
231  }
232  if(frag5_mover){
233  random_mover->add_mover(frag5_mover, flags_.frag5_weight /*weight*/);
234  }
235  random_mover->add_mover(shear_mover, 1.0);
236 
237  // wrap with monte-carlo trial mover
238  TrialMoverOP mc_trial = new TrialMover( random_mover, mc_ );
239  mc_trial->keep_stats_type( accept_reject ); // track stats (for acceptance rate)
240 
241  // Do initial forced perturbation // TODO: do we want to keep this part?
242  // if(frag9_mover){
243  // frag9_mover->apply(pose);
244  //}
245  // small_mover->apply(pose);
246  // shear_mover->apply(pose);
247  // run Monte-Carlo
248  // TR << "start MC " <<std::endl;
249  for( int i=1; i<=cycles; ++i ) {
250  mc_trial->apply( pose );
251  }
252  // TR << "finsihed MC " <<std::endl;
253  // extract best pose and return statistics
254  pose = mc_->lowest_score_pose();
255  mc_->reset( pose );
256  acceptance_rate = mc_trial->acceptance_rate();
257 }
258 
259 
260 ///////////////////////////////////////////
261 void
264 {
265  using namespace protocols::moves;
266 
267  if(flags_.peptide_nres() < 5) // TODO: 3 is minimum for KIC loop closure, and flanks should be excluded
268  return;
269  // set up and model a random loop
270  Size first_res = flags_.peptide_first_res() + 1;
271  Size last_res = flags_.peptide_last_res() - 1;
273  loops->add_loop(first_res, last_res); // TODO: cut defaults to zero, is this a random cut?
274  for(Size i = first_res; i <= last_res ; i++)
275  runtime_assert( movemap_->get_bb(i) ); // verify loop is movable, this should have been always true for the peptide
276  loop_relax_mover_->loops( loops );
277  loop_relax_mover_->apply( pose );
278 
279 }
280 
281 
282 
283 ///////////////////////////////////////////
284 // returns the acceptance rate from the RB monte-carlo
285 void
288  const int cycles,
289  const float trans_magnitude,
290  const float rot_magnitude,
291  double& acceptance_rate
292 )
293 {
294  using namespace protocols::moves;
295 
296  // set up monte-carlo trial moves
299  rb_jump_, rot_magnitude, trans_magnitude );
300  TrialMoverOP mc_trial = new TrialMover( rb_mover, mc_ );
301  mc_trial->keep_stats_type( accept_reject ); // track stats (for acceptance rate)
302 
303  // run monte-carlo
304  for(int i = 1; i <= cycles ; i++)
305  {
306  mc_trial->apply(pose);
307  }
308 
309  // extract best pose and return statistics
310  pose = mc_->lowest_score_pose();
311  mc_->reset( pose );
312  acceptance_rate = mc_trial->acceptance_rate();
313 }
314 
315 
316 ///////////////////////////////////////////////
317 void
319 {
320  using namespace core;
321  // variable declarations: //
322  pose::Pose startPose = pose;
323  int outer_cycles=10; // TODO: runtime param?
324  int inner_cycles_rb = 50; // TODO: runtime param?
325  int inner_cycles_torsions = 50; // TODO: runtime param?
326  double trans_mag = 1; // Angstrom // TODO: runtime param?
327  double rot_mag = 10; // Degrees // TODO: runtime param?
328  double rb_acceptance, torsions_acceptance; // MC acceptance rates
329  // MC temperature params
330  double init_MC_temp = 2;
331  double final_MC_temp = 0.6;
332  double gamma = pow( (final_MC_temp / init_MC_temp) , 1.0 / (outer_cycles - 1.0) );
333  std::cout << "gamma = " << gamma << std::endl;
334  double MC_temp = init_MC_temp;
335  // real stuff: //
336  std::set<int> pSer_positions;
337  if(flags_.pSer2Asp_centroid)
338  convertPSERtoASP(pose, pSer_positions); // for low-res
339  else if(flags_.pSer2Glu_centroid)
340  convertPSERtoGLU(pose, pSer_positions); // for low-res
341  to_centroid(pose);
342  setup_for_apply(pose);
343  TR.flush();
344  TR.flush();
345  for ( int i=1; i<=outer_cycles; ++i) {
346  mc_->set_temperature( MC_temp);
347  std::cout << "temperature = " << mc_->temperature() << std::endl;
348  if(flags_.rbMCM && ! flags_.pep_fold_only) {
349  rigidbody_monte_carlo
350  ( pose , inner_cycles_rb, trans_mag, rot_mag, rb_acceptance);
351  minimizer_->apply(pose);
352  }
353  if(flags_.torsionsMCM) {
354  torsions_monte_carlo
355  ( pose , inner_cycles_torsions, torsions_acceptance);
356  minimizer_->apply(pose);
357  }
358  if(flags_.peptide_loop_model){
359  loopclosure_monte_carlo( pose );
360  minimizer_->apply(pose);
361  }
362  MC_temp *= gamma;
363  }
364  TR.flush();
365  if(flags_.pSer2Asp_centroid || flags_.pSer2Glu_centroid)
366  restorePSER(pose, pSer_positions); // restore pSers before hi-res
367  to_allatom(pose, startPose /*reference pose*/);
368 }
369 
372  return "FlexPepDockingAbInitio";
373 }
374 
375 // convert all pSer residues to Asp for low-res part, and save list of pSers to pSer_positions
376 void
377 FlexPepDockingAbInitio::convertPSERtoASP(core::pose::Pose& pose, std::set<int>& pSer_positions)
378 {
379  using namespace core::chemical;
380  using namespace core::conformation;
381  ResidueTypeSetCAP rsd_set( ChemicalManager::get_instance()->residue_type_set( FA_STANDARD ) );
382  for(int resid = 1; resid <= (int)pose.total_residue(); resid++)
383  {
385  pose.residue_type(resid).name3() == "SER")
386  {
387  pSer_positions.insert(resid);
388  ResidueOP asp( ResidueFactory::create_residue( rsd_set->name_map("ASP") ));
389  pose.replace_residue( resid, *asp, true );
390  TR << "Replaced pSer residue " << resid << " to ASP for ab-initio centroid mode" << std::endl;
391  }
392  }
393 }
394 
395 
396 // convert all pSer residues to Glu for low-res part, and save list of pSers to pSer_positions
397 void
398 FlexPepDockingAbInitio::convertPSERtoGLU(core::pose::Pose& pose, std::set<int>& pSer_positions)
399 {
400  using namespace core::chemical;
401  using namespace core::conformation;
402  ResidueTypeSetCAP rsd_set( ChemicalManager::get_instance()->residue_type_set( FA_STANDARD ) );
403  for(int resid = 1; resid <= (int)pose.total_residue(); resid++)
404  {
406  pose.residue_type(resid).name3() == "SER")
407  {
408  pSer_positions.insert(resid);
409  ResidueOP glu( ResidueFactory::create_residue( rsd_set->name_map("GLU") ));
410  pose.replace_residue( resid, *glu, true );
411  TR << "Replaced pSer residue " << resid << " to GLU for ab-initio centroid mode" << std::endl;
412  }
413  }
414 }
415 
416 // convert all Asp residues to pSer, if they were originally pSer positions (based on pSer_positions)
417 void
418 FlexPepDockingAbInitio::restorePSER(core::pose::Pose& pose, std::set<int> const& pSer_positions)
419 {
420  using namespace core::chemical;
421  using namespace core::conformation;
422  ResidueTypeSetCAP centroid_set( ChemicalManager::get_instance()->residue_type_set( CENTROID ) );
423  std::set<int>::const_iterator iter;
424  for(iter = pSer_positions.begin();
425  iter != pSer_positions.end(); iter++)
426  {
427  int resid = *iter;
428  // Residue const & asp( pose.residue( resid ) ); // Unused variable causes warning.
429  ResidueOP pSer( ResidueFactory::create_residue( centroid_set->name_map("SER") ) );
430  pose.replace_residue( resid, *pSer, true );
432  }
433 }