Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LoopMover_QuickCCD.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 protocols/loops/loop_mover/perturb/LoopMover_Perturb_QuickCCD.cc
11 /// @brief kinematic loop closure main protocols
12 /// @author Mike Tyka
13 /// @author James Thompson
14 
15 //// Unit Headers
16 #include <protocols/loops/util.hh>
20 #include <protocols/loops/Loop.hh>
21 #include <protocols/loops/Loops.hh>
24 //// Rosetta Headers
26 
28 #include <core/id/TorsionID.hh>
33 #include <basic/options/option.hh>
34 #include <core/pose/Pose.hh>
35 #include <core/scoring/Energies.hh>
37 #include <core/fragment/FragSet.hh>
39 
41 // AUTO-REMOVED #include <core/conformation/symmetry/util.hh>
42 
44 
47 
48 #include <basic/Tracer.hh> // tracer output
50 
51 //Utility Headers
52 #include <numeric/random/random.hh>
53 
54 // C++ Headers
55 #include <iostream>
56 #include <map>
57 #include <string>
58 #if defined(WIN32) || defined(__CYGWIN__)
59  #include <ctime>
60 #endif
61 
62 // option key includes
63 
64 #include <basic/options/keys/loops.OptionKeys.gen.hh>
65 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
66 
67 #include <core/pose/util.hh>
68 #include <utility/vector1.hh>
69 
70 //Auto Headers
71 
72 
73 namespace protocols {
74 namespace loops {
75 namespace loop_mover {
76 namespace perturb {
77 
78 static basic::Tracer TR("protocols.loops.loop_mover.perturb.LoopMover_Perturb_QuickCCD");
79 
80 ///////////////////////////////////////////////////////////////////////////////
81 using namespace core;
82 
83 static numeric::random::RandomGenerator RG(42863);
84 
85 //constructors
86 
89 {
91 
92  protocols::moves::Mover::type("LoopMover_Perturb_QuickCCD");
94 }
95 
98 ) : IndependentLoopMover( loops_in )
99 {
101 
102  protocols::moves::Mover::type("LoopMover_Perturb_QuickCCD");
104 }
105 
106 
107 
109  protocols::loops::LoopsOP loops_in,
111 ) : IndependentLoopMover( loops_in )
112 {
113  if ( scorefxn ) {
114  set_scorefxn( scorefxn );
115  } else {
117  }
118 
119  protocols::moves::Mover::type("LoopMover_Perturb_QuickCCD");
121 }
122 
124  protocols::loops::LoopsOP loops_in,
127 ) : IndependentLoopMover( loops_in )
128 {
129  if ( scorefxn ) {
130  set_scorefxn( scorefxn );
131  } else {
133  }
134 
135  protocols::moves::Mover::type("LoopMover_Perturb_QuickCCD");
137  add_fragments( fragset );
138 }
139 
140 //destructors
142 
145  return "LoopMover_Perturb_QuickCCD";
146 }
147 
148 //clone
150  return new LoopMover_Perturb_QuickCCD( *this );
151 }
152 
154  core::pose::Pose & pose,
155  protocols::loops::Loop const & loop
156 ) {
157  using namespace kinematics;
158  using namespace scoring;
159  using namespace optimization;
160  using namespace protocols::simple_moves;
161  using namespace basic::options;
162  using namespace basic::options::OptionKeys;
163  using namespace numeric::random;
164 
165  tr().Info << "***** CCD CLOSURE *****" << std::endl;
167 
168  core::Size const nres = pose.total_residue();
169 
170  // store starting fold tree and cut pose
171  kinematics::FoldTree f_orig=pose.fold_tree();
172  set_single_loop_fold_tree( pose, loop );
173 
174  // generate movemap after fold_tree is set
175  kinematics::MoveMapOP mm_one_loop = new kinematics::MoveMap(), mm_one_loop_symm = new kinematics::MoveMap();
176  set_move_map_for_centroid_loop( loop, *mm_one_loop );
177  set_move_map_for_centroid_loop( loop, *mm_one_loop_symm );
178  if ( core::pose::symmetry::is_symmetric( pose ) ) {
179  core::pose::symmetry::make_symmetric_movemap( pose, *mm_one_loop_symm );
180  }
181 
182  int const loop_size( loop.stop() - loop.start() + 1 );
183  int cycles2 = 2;
184  // Minimum of 15 cycles
185  // Maximum of 5*15 cycles;
186  int base_cycles( std::max( 15, static_cast<int>( 5*std::min(loop_size,15) )));
187  int cycles3 = base_cycles;
188  tr().Info << "Number of cycles: cycles2 and cycles3 "
189  << cycles2 << " " << cycles3
190  << std::endl;
191 
192  //bool chainbreak_present = ( loop.start() != 1 && loop.stop() != nres );
193  // special case ... vrt res at last position
194  //chainbreak_present &= (loop.stop() != nres-1 || pose.residue( nres ).aa() != core::chemical::aa_vrt );
195  bool chainbreak_present = ( loop.start() != 1 && loop.stop() != nres &&
196  !pose.residue( loop.start() ).is_lower_terminus() &&
197  !pose.residue( loop.stop() ).is_upper_terminus() );
198 
199  // set loop.cut() variant residue for chainbreak score if chanbreak is present
200  if ( chainbreak_present ) {
202  pose, chemical::CUTPOINT_LOWER, loop.cut()
203  );
205  pose, chemical::CUTPOINT_UPPER, loop.cut()+1
206  );
207  }
208 
209 
210  ( *scorefxn() )(pose);
211  core::pose::Pose start_pose = pose;
212 
213  // either extend or at least idealize the loop (just in case).
214  if ( loop.is_extended() ) set_extended_torsions( pose, loop );
215  else idealize_loop( pose, loop );
216 
217  // omega needs to be moveable for FragmentMovers, so use a separate movemap
218  kinematics::MoveMapOP frag_mover_movemap = new kinematics::MoveMap();
219  frag_mover_movemap->set_bb_true_range( loop.start(), loop.stop() );
220  //fpd need to leave movemap for fragment insertion nonsymmetric
221  // (so that insertions will happen when scoring subunit is not 1st)
222 
225  it = frag_libs().begin(), it_end = frag_libs().end();
226  it != it_end; it++ ) {
227  ClassicFragmentMoverOP cfm = new ClassicFragmentMover( *it, frag_mover_movemap );
228  cfm->set_check_ss( false );
229  cfm->enable_end_bias_check( false );
230  fragmover.push_back( cfm );
231  }
232 
233  core::Real m_Temperature_ = 2.0;
234  moves::MonteCarloOP mc_ = new moves::MonteCarlo( pose, *scorefxn(), m_Temperature_ );
235 
236  if ( randomize_loop_ ) {
237  // insert random fragment as many times as the loop is long (not quite
238  // the exact same as the old code)
239  for ( Size i = loop.start(); i <= loop.stop(); ++i ) {
241  it = fragmover.begin(),it_end = fragmover.end(); it != it_end; it++
242  ) {
243  (*it)->apply( pose );
244  }
245  }
246  }
247 
248  // Set up Minimizer object
250  float const dummy_tol( 0.001 ); // linmin sets tol internally
251  bool const use_nblist( true ), deriv_check( false ); // true ); // false );
252  MinimizerOptions options( "linmin", dummy_tol, use_nblist, deriv_check);
253  if ( core::pose::symmetry::is_symmetric( pose ) ) {
255  } else {
257  }
258 
259 
260  // Set up MonteCarlo Object
261  core::Real const init_temp = 2.0;
262  core::Real temperature = init_temp;
263  mc_->reset( pose );
264  mc_->set_temperature( temperature );
265 
266  int starttime = time(NULL);
267  int frag_count = 0;
268  scorefxn()->show_line_headers( tr().Info );
269  tr().Info << std::endl;
270 
271  core::Real const final_temp( 1.0 );
272  core::Real const gamma = std::pow(
273  (final_temp/init_temp), (1.0/(cycles2*cycles3))
274  );
275 
276  bool has_constraints = pose.constraint_set()->has_constraints();
277  float final_constraint_weight = option[ basic::options::OptionKeys::constraints::cst_weight ](); // this is really stupid.
278 
279  if ( chainbreak_present ) scorefxn()->set_weight( chainbreak, 1.0 );
280 
281  // for symmetric case, upweight the chainbreak by # of monomers
282  if ( core::pose::symmetry::is_symmetric( pose ) ) {
284  dynamic_cast<core::conformation::symmetry::SymmetricConformation const & > ( pose.conformation()) );
286  scorefxn()->set_weight( chainbreak, symm_info->subunits() );
287  }
288 
289  for( int c2 = 1; c2 <= cycles2; ++c2 ) {
290  mc_->recover_low( pose );
291 
292  // ramp up constraints
293  if ( has_constraints ) {
294  if( c2 != cycles2 ) {
295  scorefxn()->set_weight( core::scoring::atom_pair_constraint, final_constraint_weight*float(c2)/float( cycles2 ) );
296  } else {
297  scorefxn()->set_weight( core::scoring::atom_pair_constraint, final_constraint_weight * 0.2 );
298  }
299  }
300 
301  ( *scorefxn() )(pose);
302  if ( tr().visible() ) { scorefxn()->show_line( tr().Info , pose ); }
303  tr().Info << std::endl;
304  mc_->score_function( *scorefxn() );
305 
306  for ( int c3 = 1; c3 <= cycles3; ++c3 ) {
307  temperature *= gamma;
308  mc_->set_temperature( temperature );
310  it = fragmover.begin(),it_end = fragmover.end();
311  it != it_end; it++
312  ) {
313  (*it)->apply( pose );
314  if ( chainbreak_present ) {
315  fast_ccd_close_loops( pose, loop, *mm_one_loop );
316  }
317 
318  mzr->run( pose, *mm_one_loop_symm, *scorefxn(), options );
319  mc_->boltzmann( pose, "QuickCCD" );
320  frag_count++;
321  }
322 
323  if ( debug ) {
324  ( *scorefxn() )(pose);
325  scorefxn()->show_line( tr().Info , pose );
326  tr().Info << std::endl;
327  }
328  } // for c3 in cycles3
329  } // for c2 in cycles2
330 
331  int looptime = time(NULL) - starttime;
332  tr() << "FragCount: " << frag_count << std::endl;
333  tr() << "Looptime " << looptime << std::endl;
334 
335  pose = mc_->lowest_score_pose();
336  scorefxn()->show( tr().Info , pose );
337  tr().Info << "-------------------------" << std::endl;
338  mc_->show_counters();
339 
340  // restore original CB wt if symmetric
341  if ( core::pose::symmetry::is_symmetric( pose ) ) {
342  scorefxn()->set_weight( chainbreak, 1.0 );
343  }
344 
345  // Check chain break !
346  if ( chainbreak_present ) {
347  using namespace core::scoring;
348  ( *scorefxn() )( pose );
349  core::Real chain_break_score = std::max(
350  static_cast<float> (pose.energies().total_energies()[ chainbreak ]),
351  static_cast<float> (pose.energies().total_energies()[ linear_chainbreak ])
352  );
353 
354  core::Real chain_break_tol
355  = option[ basic::options::OptionKeys::loops::chain_break_tol ]();
356  tr().Info << "Chainbreak: " << chain_break_score << " Max: "
357  << chain_break_tol << std::endl;
358 
359  //remove cutpoints before all return statements because the code is now determining loop failure without cutpoints.
361  pose.fold_tree( f_orig );
362 
363  if ( chain_break_score > (chain_break_tol*10) ) return ExtendFailure; // if we have a really bad chain break, extend loop definitions
364  if ( chain_break_score > chain_break_tol ) return Failure; // if we only have a slight chainbreak problem, try again
365  } // if ( chainbreak_present )
366 
367  // return to original fold tree
369  pose.fold_tree( f_orig );
370  return Success;
371 }
372 
373 basic::Tracer & LoopMover_Perturb_QuickCCD::tr() const
374 {
375  return TR;
376 }
377 
379 
381  return new LoopMover_Perturb_QuickCCD();
382 }
383 
385  return "LoopMover_Perturb_QuickCCD";
386 }
387 
388 
389 //////////////////////////////////////////////////////////////////////////////////
390 /// @details CCD close the loop [loop_begin,loop_end]. Wraps
391 /// protocols::loops::fast_ccd_loop_closure, sets reasonable weights for the
392 /// protocol.
394  core::pose::Pose & pose,
395  Loop const & loop,
397 )
398 {
399  // param for ccd_closure
400  int const ccd_cycles = { 100 }; // num of cycles of ccd_moves
401  Real const ccd_tol = { 0.01 }; // criterion for a closed loop
402  bool const rama_check = { false };
403  Real const max_rama_score_increase = { 2.0 }; // dummy number when rama_check is false
404  Real const max_total_delta_helix = { 10.0 }; // max overall angle changes for a helical residue
405  Real const max_total_delta_strand = { 50.0 }; // ... for a residue in strand
406  Real const max_total_delta_loop = { 75.0 }; // ... for a residue in loop
407  // output for ccd_closure
408  Real forward_deviation, backward_deviation; // actually loop closure msd, both dirs
409  Real torsion_delta, rama_delta; // actually torsion and rama score changes, averaged by loop_size
411  pose, mm, loop.start() , loop.stop(), loop.cut(), ccd_cycles,
412  ccd_tol, rama_check, max_rama_score_increase, max_total_delta_helix,
413  max_total_delta_strand, max_total_delta_loop, forward_deviation,
414  backward_deviation, torsion_delta, rama_delta
415  );
416 
417  // fix secondary structure??
418  for (core::Size i=loop.start(); i<=loop.stop(); ++i) {
419  char ss_i = pose.conformation().secstruct( i );
420  if ( ss_i != 'L' && ss_i != 'H' && ss_i != 'E')
421  pose.set_secstruct( i , 'L' );
422  }
423 }
424 
425 } // namespace perturb
426 } // namespace loop_mover
427 } // namespace loops
428 } // namespace protocols