Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RNA_LoopCloser.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 relax_protocols
11 /// @brief protocols that are specific to RNA_LoopCloser
12 /// @detailed
13 /// @author Rhiju Das
14 
16 // AUTO-REMOVED #include <protocols/rna/RNA_Minimizer.hh>
17 // AUTO-REMOVED #include <protocols/rna/RNA_ProtocolUtil.hh>
20 #include <core/id/AtomID_Map.hh>
21 #include <core/id/AtomID.hh>
22 #include <core/id/DOF_ID.hh>
24 #include <core/pose/Pose.hh>
31 
32 
33 //Minimizer stuff
37 
38 // AUTO-REMOVED #include <basic/options/option.hh>
39 #include <basic/options/keys/OptionKeys.hh>
40 // AUTO-REMOVED #include <basic/options/util.hh>
41 
42 // ObjexxFCL Headers
43 #include <ObjexxFCL/FArray1D.hh>
44 
45 #include <core/types.hh>
46 #include <basic/Tracer.hh>
47 
48 //#include <numeric/random/random.hh>
49 
50 // External library headers
51 
52 
53 //C++ headers
54 #include <vector>
55 #include <string>
56 #include <sstream>
57 // AUTO-REMOVED #include <fstream>
58 // AUTO-REMOVED #include <ctime>
59 
60 //Auto Headers
65 #include <core/pose/util.hh>
66 #include <utility/vector1.hh>
67 #include <numeric/conversions.hh>
68 #include <ObjexxFCL/string.functions.hh>
69 
70 //Auto using namespaces
71 namespace ObjexxFCL { } using namespace ObjexxFCL; // AUTO USING NS
72 //Auto using namespaces end
73 
74 
75 using namespace core;
76 using basic::T;
77 
78 static basic::Tracer TR( "protocols.rna.rna_loop_closer" ) ;
79 
81 
82 namespace protocols {
83 namespace rna {
84 
85 RNA_LoopCloser::RNA_LoopCloser():
86  verbose_( false ),
87  NUM_ROUNDS_( 100 ),
88  check_tolerance_( false ),
89  ccd_tolerance_( 0.000001 ),
90  absolute_ccd_tolerance_( 0.01 ),
91  attempt_closure_cutoff_( 20.0 ),
92  gap_distance_cutoff_( 8.0 ),
93  fast_scan_( true )
94 {
95  Mover::type("RNA_LoopCloser");
96 }
97 
98 
99 
100 ////////////////////////////////////////////
101 ////////////////////////////////////////////
102 // HEY NEED TO DEFINE A CLONER?
103 ////////////////////////////////////////////
104 ////////////////////////////////////////////
105 
106 /// @details Apply the RNA full atom minimizer.
107 ///
108 void RNA_LoopCloser::apply( core::pose::Pose & pose, std::map< Size, Size> const & connections )
109 {
110  using namespace core::scoring;
111  using namespace core::kinematics;
112  using namespace core::optimization;
113  using namespace basic::options;
114  using namespace basic::options::OptionKeys;
115 
116  // Loop through all residues and look for potential chainbreaks to close --
117  // marked by CUTPOINT_LOWER and CUTPOINT_UPPER variants.
118  for (Size i = 1; i < pose.total_residue(); i++ ) {
119 
120  if ( !pose.residue( i ).has_variant_type( chemical::CUTPOINT_LOWER ) ) continue;
121  if ( !pose.residue( i+1 ).has_variant_type( chemical::CUTPOINT_UPPER ) ) continue;
122 
123  // do_fast_scan will check if this cutpoint has changed since the
124  // last movement, or is the chainbreak is already well closed,
125  // or if the chainbreak is too big to close.
126  if ( fast_scan_ && !passes_fast_scan( pose, i ) ) continue;
127 
128  //TR << "Trying to close chain near cutpoint " << i << "-" << i+1 << std::endl;
129 
130  apply( pose, connections, i );
131 
132  }
133 
134 }
135 
136 ///////////////////////////////////////////////////////////////////////
138 {
139  std::map< Size, Size > connections_dummy;
140  apply( pose, connections_dummy );
141 }
142 
145  return "RNA_LoopCloser";
146 }
147 
148 ///////////////////////////////////////////////////////////////////////////////////////////////
149 Real RNA_LoopCloser::apply( core::pose::Pose & pose, std::map< Size, Size > const & connections, Size const & cutpoint )
150 {
151 
152  if (verbose_) TR << "Closing loop at: " << cutpoint << std::endl;
153  // TR << "Closing loop at: " << cutpoint << std::endl;
154 
155  // In the future might have a separate option, e.g., for kinematic loop closure.
156  return rna_ccd_close( pose, connections, cutpoint );
157 }
158 
159 ///////////////////////////////////////////////////////////////////////////////////////////////
160 Real RNA_LoopCloser::apply( core::pose::Pose & pose, Size const & cutpoint )
161 {
162 
163  if (verbose_) TR << "Closing loop at: " << cutpoint << std::endl;
164  // TR << "Closing loop at: " << cutpoint << std::endl;
165 
166  std::map< Size, Size > connections; /* empty*/
167 
168  // In the future might have a separate option, e.g., for kinematic loop closure.
169  return rna_ccd_close( pose, connections, cutpoint );
170 }
171 
172 
173 ////////////////////////////////////////////////////////////////////
174 // returns false if failure.
175 bool
177 {
178  //Don't bother if there hasn't been any movement...
179  core::kinematics::DomainMap domain_map;
180  pose.conformation().update_domain_map( domain_map );
181  if ( domain_map( i ) == domain_map( i+1 ) ) {
182  if (verbose_) TR << "Skipping " << i << " due to domain map." << std::endl;
183  return false;
184  }
185 
186  Real const current_dist_err = get_dist_err( pose, i );
187  //Don't bother if chain is really bad...
188  if ( current_dist_err > attempt_closure_cutoff_ ) {
189  if (verbose_) TR << "Cutpoint " << i << " will be tough to close: " << current_dist_err << std::endl;
190  return false;
191  }
192 
193  Real const current_gap_distance = get_gap_distance( pose, i );
194  //Don't bother if chain is really bad...
195  if ( current_gap_distance > gap_distance_cutoff_ ) {
196  if (verbose_) TR << "Cutpoint " << i << " will be tough to close since gap is : " << current_gap_distance << std::endl;
197  return false;
198  }
199 
200  //Don't bother if chain already closed...
201  if ( current_dist_err < absolute_ccd_tolerance_ ) {
202  if (verbose_) TR << "Cutpoint " << i << " already pretty close to closed: " << current_dist_err << std::endl;
203  return false;
204  }
205 
206  return true;
207 }
208 
209 ////////////////////////////////////////////////////////////////////////////
210 bool
212 {
213 
214  if ( ccd_tolerance <= 0.0 ) ccd_tolerance = absolute_ccd_tolerance_;
215 
216  // Loop through all residues and look for potential chainbreaks to close --
217  // marked by CUTPOINT_LOWER and CUTPOINT_UPPER variants.
218  for (Size i = 1; i < pose.total_residue(); i++ ) {
219 
220  if ( !pose.residue( i ).has_variant_type( chemical::CUTPOINT_LOWER ) ) continue;
221  if ( !pose.residue( i+1 ).has_variant_type( chemical::CUTPOINT_UPPER ) ) continue;
222 
223  Real const current_dist_err = get_dist_err( pose, i );
224  if ( current_dist_err > ccd_tolerance ) return false;
225 
226  }
227 
228  return true;
229 }
230 
231 
232 ///////////////////////////////////////////////////////////////////////////////////////////////
233 Real
234 RNA_LoopCloser::rna_ccd_close( core::pose::Pose & input_pose, std::map< Size, Size > const & connections, Size const & cutpoint ) const
235 {
236  using namespace core::scoring::rna;
237  using namespace core::id;
238 
239  if ( !input_pose.residue( cutpoint ).is_RNA() ||
240  !input_pose.residue( cutpoint+1 ).is_RNA() ) {
241  utility_exit_with_message( "RNA CCD closure at "+string_of( cutpoint )+" but residues are not RNA?");
242  }
243 
244  if ( !input_pose.residue( cutpoint ).has_variant_type( chemical::CUTPOINT_LOWER ) ||
245  !input_pose.residue( cutpoint+1 ).has_variant_type( chemical::CUTPOINT_UPPER ) ) {
246  utility_exit_with_message( "RNA CCD closure at "+string_of( cutpoint )+" but CUTPOINT_LOWER or CUTPOINT_UPPER variants not properly set up." );
247  }
248 
249  /////////////////////////////////////////////////////////////////////
250  //Just to get all the atom tree connectivities right, make a little scratch pose
251  // to play with.
252  /////////////////////////////////////////////////////////////////////
253  // In the future (if refold could be faster?!), we won't need this
254  // scratch pose.
255 
256  pose::Pose pose;
257  pose.append_residue_by_bond( input_pose.residue( cutpoint) );
258  pose.append_residue_by_jump( input_pose.residue( cutpoint+1), 1 );
259 
260  // This is a nice extra option -- instead of just tweaking torsions in the residue right before and after the chainbreak,
261  // there are some situations in which it makes sense to tweak torsions in their base pairing partners.
262  bool close_two_base_pairs = false;
263  Size cutpoint_partner( 0 ), cutpoint_next_partner( 0 );
264 
265  if ( connections.find( cutpoint ) != connections.end() &&
266  connections.find( cutpoint+1 ) != connections.end() ) {
267 
268  cutpoint_partner = connections.find( cutpoint )->second;
269  cutpoint_next_partner = connections.find( cutpoint+1 )->second;
270 
271  if (cutpoint_partner == cutpoint_next_partner + 1 ) {
272  close_two_base_pairs = true;
273  }
274  }
275  if ( close_two_base_pairs ) {
276  TR << "Also including some torsions in partners in CCD: " << cutpoint_partner << " " << cutpoint_next_partner << std::endl;
277  }
278 
279  // This is totally hard-wired and hacky -- should be easy to fix though.
280  if (close_two_base_pairs ) {
281  pose.append_residue_by_jump( input_pose.residue( cutpoint_next_partner /* 9 */ ), 1 );
282  pose.append_residue_by_jump( input_pose.residue( cutpoint_partner /* 10 */ ), 1 );
283  }
284 
285  kinematics::FoldTree f( pose.total_residue() );
286  if ( close_two_base_pairs ) {
287  // This is totally hard-wired and hacky -- should be easy to fix though.
288  f.new_jump( 1, 4, 1 );
289  f.set_jump_atoms( 1,
290  core::scoring::rna::chi1_torsion_atom( pose.residue(1) ),
291  core::scoring::rna::chi1_torsion_atom( pose.residue(4) ) );
292  f.new_jump( 2, 3, 2 );
293  f.set_jump_atoms( 2,
294  core::scoring::rna::chi1_torsion_atom( pose.residue(2) ),
295  core::scoring::rna::chi1_torsion_atom( pose.residue(3) ) );
296 
297  } else {
298  f.new_jump( 1, 2, 1 );
299  f.set_jump_atoms( 1,
300  core::scoring::rna::chi1_torsion_atom( pose.residue(1) ),
301  core::scoring::rna::chi1_torsion_atom( pose.residue(2) ) );
302  }
303 
304  pose.fold_tree( f );
305 
306 // pose.dump_pdb( "scratch.pdb" );
307 
308  //Vectors of the three atoms upstream or downstream of the cutpoint that need to be matched.
309  utility::vector1 <Vector> upstream_xyzs, downstream_xyzs;
310  Real mean_dist_err( -1.0 ), mean_dist_err_prev( 9999.9999 );
311  mean_dist_err = get_chainbreak_xyz( pose, 1, upstream_xyzs, downstream_xyzs );
312  // This get_chainbreak_xyz will get called repeatedly after each torsion change.
313 
314  // What torsions are in play? Note that this could be expanded (or contracted) at will.
315  utility::vector1< TorsionID > tor_ids, input_tor_ids;
316 
317  // epsilon and zeta before the cutpoint.
318  for (Size j = 5; j <=6; ++ j){
319  tor_ids.push_back( TorsionID( 1 /*cutpoint*/, BB, j ) );
320  input_tor_ids.push_back( TorsionID( cutpoint, BB, j ) );
321  }
322 
323  // alpha, beta, gamma, delta after the cutpoint?
324  for (Size j = 1; j <=3; ++ j){
325  tor_ids.push_back( TorsionID( 2 /*cutpoint+1*/, BB, j ) );
326  input_tor_ids.push_back( TorsionID( cutpoint+1, BB, j ) );
327  }
328 
329  //Parin May 5, 2009
330  // Also include delta (sugar pucker!) from second residue if its a free floater (cutpoints before and after)
331 // if ( input_pose.residue( cutpoint+1 ).has_variant_type( chemical::CUTPOINT_LOWER ) ||
332 // input_pose.residue( cutpoint+1 ).has_variant_type( chemical::UPPER_TERMINUS ) ) {
333 // Size const j = 4;
334 // tor_ids.push_back( TorsionID( 2 /*cutpoint+1*/, BB, j ) );
335 // input_tor_ids.push_back( TorsionID( cutpoint+1, BB, j ) );
336 // }
337 
338  // Also include delta (sugar pucker!) from second residue if its a free floater (cutpoints before and after)
339  // if ( input_pose.residue( cutpoint+1 ).has_variant_type( chemical::CUTPOINT_LOWER ) ||
340  // input_pose.residue( cutpoint+1 ).has_variant_type( chemical::UPPER_TERMINUS ) ) {
341  // Size const j = 4;
342  // tor_ids.push_back( TorsionID( 2 /*cutpoint+1*/, BB, j ) );
343  // input_tor_ids.push_back( TorsionID( cutpoint+1, BB, j ) );
344  // }
345 
346 
347  //Need to make following user-settable.
348  Size nrounds( 0 );
349 
350  /////////////////////////////////////////////////////////////////////
351  /////////////////////////////////////////////////////////////////////
352 
353  while ( nrounds++ < NUM_ROUNDS_ ) {
354 
355  if (check_tolerance_ && ( (mean_dist_err_prev - mean_dist_err) < ccd_tolerance_ ) ) {
356  if (verbose_ ) TR << "Reached tolerance of " << ccd_tolerance_ << " after " << nrounds << " rounds. " << std::endl;
357  break;
358  }
359  mean_dist_err_prev = mean_dist_err;
360 
361  /////////////////////////////////////////////////////////////////////
362  // One round of chain closure.
363  // This doesn't have to be sequential ... allow random traversal,
364  // and also biased towards "moveable torsions" (i.e., not beta or epsilon)
365  // Also to do? -- check on beta/epsilon -- could perhaps make use of
366  // torsion potential as a simple and general screen.
367  for (Size n = 1; n <= tor_ids.size(); n++ )
368  {
369  TorsionID const & tor_id( tor_ids[ n ] );
370  AtomID id1,id2,id3,id4;
371  pose.conformation().get_torsion_angle_atom_ids( tor_id, id1, id2, id3, id4 );
372 
373  //Is this torsion before or after the chainbreak?
374  AtomID my_id;
375  Real dir( 0.0 );
376  if ( Size( tor_id.rsd() ) == 1 /*cutpoint*/ ){
377  my_id = id3;
378  dir = 1;
379  } else {
380  my_id = id2;
381  dir = -1;
382  }
383 
384  core::kinematics::tree::Atom const & current_atom ( pose.atom_tree().atom( my_id ) );
385 
386  kinematics::Stub const & stub_i( current_atom.get_stub() );
387  Matrix const & M_i( stub_i.M );
388  Vector const & x_i = M_i.col_x();
389 
390  Real weighted_sine( 0.0 ), weighted_cosine( 0.0 );
391  for (Size m = 1; m <= upstream_xyzs.size(); m++ ){
392  Vector const current_xyz( current_atom.xyz() );
393 
394  Vector const r1 = upstream_xyzs[m] - current_xyz;
395  Vector const rho1 = r1 - dot( r1, x_i) * x_i;
396 
397  Vector const r2 = downstream_xyzs[m] - current_xyz;
398  Vector const rho2 = r2 - dot( r2, x_i) * x_i;
399 
400  Real const current_sine = dir * dot( x_i, cross( rho1, rho2 ) );
401  Real const current_cosine = dot( rho1, rho2 );
402  // std::cout << "PREFERRED ANGLE: " << numeric::conversions::degrees( std::atan2( current_sine, current_cosine) ) << std::endl;
403 
404  weighted_sine += current_sine;
405  weighted_cosine += current_cosine;
406 
407  mean_dist_err = get_chainbreak_xyz( pose, 1 /*cutpoint*/, upstream_xyzs, downstream_xyzs );
408  }
409 
410  Real const twist_torsion = numeric::conversions::degrees( std::atan2( weighted_sine, weighted_cosine) );
411 
412  // std::cout << "CHECK: " << twist_torsion << std::endl;
413 
414  Real const current_val = pose.torsion( tor_id );
415  pose.set_torsion( tor_id, current_val + twist_torsion );
416 
417 
418  }
419 
420  if ( verbose_ ) std::cout << "Distance error: " << mean_dist_err << std::endl;
421 
422  }
423 
424  if (verbose_) pose.dump_pdb( "scratch_close.pdb" );
425 
426  /////////////////////////////////////////////////////////////////////
427  // OK, done with mini_pose ... copy torsions back into main pose.
428  for (Size n = 1; n <= tor_ids.size(); n++ ) {
429  input_pose.set_torsion( input_tor_ids[n], pose.torsion( tor_ids[n] ) );
430  }
431 
432  if (verbose_) input_pose.dump_pdb( "pose_close.pdb" );
433 
434  return mean_dist_err;
435 
436 }
437 
438 
439 
440 ///////////////////////////////////////////////////////////////
441 Real
443  Size const cutpoint
444  ) const
445 {
446  utility::vector1< Vector > upstream_xyzs;
447  utility::vector1< Vector > downstream_xyzs;
448  return get_chainbreak_xyz( pose, cutpoint, upstream_xyzs, downstream_xyzs );
449 }
450 
451 ///////////////////////////////////////////////////////////////
452 Real
454  Size const cutpoint,
455  utility::vector1< Vector > & upstream_xyzs,
456  utility::vector1< Vector > & downstream_xyzs
457  ) const
458 {
459  upstream_xyzs.clear();
460  downstream_xyzs.clear();
461 
462  upstream_xyzs.push_back( pose.residue( cutpoint ).xyz( " O3*" ) );
463  upstream_xyzs.push_back( pose.residue( cutpoint ).xyz( "OVL1" ) );
464  upstream_xyzs.push_back( pose.residue( cutpoint ).xyz( "OVL2" ) );
465 
466  downstream_xyzs.push_back( pose.residue( cutpoint+1 ).xyz( "OVU1" ) );
467  downstream_xyzs.push_back( pose.residue( cutpoint+1 ).xyz( " P " ) );
468  downstream_xyzs.push_back( pose.residue( cutpoint+1 ).xyz( " O5*" ) );
469 
470  Real mean_dist_err( 0.0 );
471  for (Size m = 1; m <= upstream_xyzs.size(); m++ ){
472  mean_dist_err += ( upstream_xyzs[m] - downstream_xyzs[m] ).length();
473  }
474  mean_dist_err /= upstream_xyzs.size();
475 
476  return mean_dist_err;
477 }
478 
479 ///////////////////////////////////////////////////////////////
480 Real
482  Size const cutpoint
483  ) const
484 {
485  return ( pose.residue(cutpoint).xyz( " O3*" ) - pose.residue(cutpoint).xyz(" C5*" ) ).length();
486 }
487 
488 ///////////////////////////////////////////////////////////////////////////
491 {
492 
493  using namespace core::kinematics;
494  using namespace core::scoring::constraints;
495 
496  FoldTree const & f( pose.fold_tree() );
497 
498  utility::vector1< Size > extra_cutpoints;
499 
500  for ( Size cutpos = 1; cutpos < pose.total_residue(); cutpos++ ){
501 
502  if ( ! f.is_cutpoint( cutpos ) ) continue;
503 
504  if ( !pose.residue( cutpos ).has_variant_type( chemical::CUTPOINT_LOWER ) ||
505  !pose.residue( cutpos+1 ).has_variant_type( chemical::CUTPOINT_UPPER ) ) {
506 
507  // go through pose constraints -- was there any constraint holding residue i's O3* to i+1's P?
508  bool cst_found( false );
509  ConstraintCOPs csts( pose.constraint_set()->get_all_constraints() );
510 
511  for ( Size n = 1; n <= csts.size(); n++ ) {
512 
513  ConstraintCOP const & cst( csts[n] );
514 
515  if ( cst->natoms() == 2 ) { // currently only defined for pairwise distance constraints.
516  Size const i = cst->atom( 1 ).rsd();
517  std::string const name1 = pose.residue( i ).atom_name( cst->atom( 1 ).atomno() );
518  Size const j = cst->atom( 2 ).rsd();
519  std::string const name2 = pose.residue( j ).atom_name( cst->atom( 2 ).atomno() );
520 
521  if ( i == cutpos && j == cutpos+1 && name1 == " O3*" && name2 == " P " ){
522  cst_found = true; break;
523  }
524  if ( j == cutpos && i == cutpos+1 && name2 == " O3*" && name1 == " P " ){
525  cst_found = true; break;
526  }
527 
528  }
529 
530  }
531 
532  if (!cst_found) continue;
533 
534  extra_cutpoints.push_back( cutpos );
535  }
536  }
537 
538  return extra_cutpoints;
539 }
540 
541 ////////////////////////////////////////////////////////////////////////////////////////
542 void
544 {
545  pose::Pose pose_copy( pose );
546 
547  for ( Size n = 1; n <= extra_cutpoints.size(); n++ ) {
548 
549  Size cutpos( extra_cutpoints[ n ] );
550  //std::cout << "ADDING CUTPOINT VARIANTS " << cutpos << std::endl;
551 
554 
555  for (Size i = cutpos; i <= cutpos + 1; i++ ){
556  for (Size j = 1; j <= scoring::rna::NUM_RNA_MAINCHAIN_TORSIONS; j++ ) {
557  id::TorsionID torsion_id( i, id::BB, j );
558  pose.set_torsion( torsion_id, pose_copy.torsion( torsion_id ) ) ;
559  } // j
560  } // i
561 
562  } // n
563 }
564 
565 
566 
567 ///////////////////////////////////////////////////////////////////////////////////////////////
568 void
570 {
571 
572  pose::Pose pose_copy( pose );
573 
574  for ( Size n = 1; n <= extra_cutpoints.size(); n++ ) {
575  Size cutpos( extra_cutpoints[ n ] );
578 
579  for (Size i = cutpos; i <= cutpos + 1; i++ ){
580  for (Size j = 1; j <= scoring::rna::NUM_RNA_MAINCHAIN_TORSIONS; j++ ) {
581  id::TorsionID torsion_id( i, id::BB, j );
582  pose.set_torsion( torsion_id, pose_copy.torsion( torsion_id ) ) ;
583  } // j
584  } // i
585 
586  } // n
587 
588 }
589 
590 ///////////////////////////////////////////////////////////////////////////////////////////////
591 // void
592 // RNA_LoopCloser::close_loops_carefully(
593 // core::pose::Pose & pose,
594 // core::scoring::ScoreFunctionOP const & scorefxn,
595 // Size close_loops_rounds )
596 // {
597 
598 // for (Size k = 1; k <= close_loops_rounds; k++ ) {
599 // std::cout << "ROUND " << k << " of " << close_loops_rounds << ": " << std::endl;
600 // scorefxn->show( std::cout, pose );
601 // close_loops_carefully_one_round( pose, scorefxn );
602 // }
603 
604 // }
605 
606 ///////////////////////////////////////////////////////////////////////////////////////////////
607 // void
608 // RNA_LoopCloser::close_loops_carefully(
609 // core::pose::Pose & pose,
610 // core::scoring::ScoreFunctionOP const & scorefxn )
611 // {
612 // close_loops_carefully( pose, scorefxn, 1 );
613 // }
614 
615 ///////////////////////////////////////////////////////////////////////////////////////////////
616 void
617 RNA_LoopCloser::close_loops_carefully( core::pose::Pose & pose, std::map< Size, Size > const & connections )
618 {
619  using namespace core::scoring;
620 
621  // ScoreFunctionOP scorefxn_local( scorefxn->clone() );
622 
623  // A quick minimization
624  //static protocols::rna::RNA_Minimizer rna_minimizer;
625  // rna_minimizer.set_score_function( scorefxn_local );
626  // rna_minimizer.apply( pose );
627  // pose.dump_pdb( "dump1.pdb" );
628 
629  // OK, close the loops...
630  // Look through constraints -- there may be some cutpoints to close that are not
631  // yet flagged... set up chainbreak variants there...
632  utility::vector1< Size > const extra_cutpoints = get_extra_cutpoints( pose );
633  setup_variants_at_extra_cutpoints( pose, extra_cutpoints );
634 
635  // Now locally minimize around chainbreaks -- ignore chainbreak atoms because they're
636  // probably in crazy places (wait until CCD).
637  //scorefxn_local->set_weight( linear_chainbreak, 0.0 );
638  // local_minimize_at_chainbreaks( pose, scorefxn_local );
639  // pose.dump_pdb( "dump2.pdb" );
640 
641  // CCD loop close.
642  // bool fast_scan_save( fast_scan_ );
643  // fast_scan_ = false;
644  apply( pose, connections );
645  // fast_scan_ = fast_scan_save;
646  // pose.dump_pdb( "dump3.pdb" );
647 
648 
649  // Now minimize with strong coordinate constraints.
650  tight_minimize( pose );
651 
652  // local_minimize_at_chainbreaks( pose, scorefxn_local );
653 
654  // Leave the pose sequence/variants as we received it.
655  remove_variants_at_extra_cutpoints( pose, extra_cutpoints );
656  // pose.dump_pdb( "dump4.pdb" );
657 
658  //In case the pose is about to be output ...
659  // pose.constraint_set( cst_set_save );
660  // (*scorefxn)( pose );
661 
662 }
663 
664 //////////////////////////////////////////////////////////////////////////////////
665 void
667 {
668  using namespace core::optimization;
669  using namespace core::kinematics;
670  using namespace core::scoring;
671 
672  core::scoring::constraints::ConstraintSetOP const & cst_set_save( pose.constraint_set()->clone() );
673  pose.constraint_set( 0 );
675 
676  static AtomTreeMinimizer minimizer;
677  float const dummy_tol( 0.0000025);
678  bool const use_nblist( true );
679  static MinimizerOptions options( "dfpmin", dummy_tol, use_nblist, false /*deriv_check_*/, false /*deriv_check_*/ );
681  lores_scorefxn->set_weight( linear_chainbreak, 5.0 );
682  lores_scorefxn->set_weight( coordinate_constraint, 2.0 );
683 
684  MoveMap mm;
685  mm.set_bb( true );
686  mm.set_jump ( false );
687  mm.set_chi( false );
688  minimizer.run( pose, mm, *lores_scorefxn, options );
689 
690  pose.constraint_set( cst_set_save );
691 }
692 
693 /////////////////////////////////////////////////////////////////////////////////
694 void
696  core::pose::Pose & pose,
697  core::scoring::ScoreFunctionOP & scorefxn_local ) const
698 {
699 
700  using namespace core::optimization;
701 
702  AtomTreeMinimizer minimizer;
703  float const dummy_tol( 0.0000025);
704  bool const use_nblist( true );
705  MinimizerOptions options( "dfpmin", dummy_tol, use_nblist, false /*deriv_check_*/, false /*deriv_check_*/ );
706 
708  mm.set_bb( false );
709  mm.set_chi( false );
710  mm.set_jump( false );
711 
712  scorefxn_local->set_weight( core::scoring::linear_chainbreak, 1.0 );
713 
714  kinematics::FoldTree const & f( pose.fold_tree() );
715 
716  for ( Size cutpos = 1; cutpos < pose.total_residue(); cutpos++ ){
717 
718  mm.set_bb( false );
719 
720  if ( ! f.is_cutpoint( cutpos ) ) continue;
721 
722  if ( !pose.residue( cutpos ).has_variant_type( chemical::CUTPOINT_LOWER ) ||
723  !pose.residue( cutpos+1 ).has_variant_type( chemical::CUTPOINT_UPPER ) ) continue;
724 
725  mm.set_bb( cutpos, true );
726  mm.set_bb( cutpos+1, true );
727  minimizer.run( pose, mm, *scorefxn_local, options );
728 
729  TR << "Trying to minimize chain near cutpoint " << cutpos << std::endl;
730  }
731 }
732 
733 
734 } // namespace rna
735 } // namespace protocols