Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LoopClosure.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
11 /// @brief
12 /// @detailed
13 /// @author Oliver Lange
14 ///
15 
16 
17 // Unit Headers
19 
20 // Package Headers
21 // AUTO-REMOVED #include <protocols/loops/Loops.hh>
24 
25 // Project Headers
26 #include <core/pose/Pose.hh>
27 // AUTO-REMOVED #include <core/pose/util.hh>
28 
30 // AUTO-REMOVED #include <core/kinematics/FoldTree.hh>
31 
33 
34 #include <core/fragment/Frame.hh>
36 #include <core/fragment/FragSet.hh>
37 
38 // AUTO-REMOVED
39 
43 
44 // ObjexxFCL Headers
45 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
46 
47 // Utility headers
48 #include <basic/Tracer.hh>
49 #include <numeric/random/random.hh>
50 // AUTO-REMOVED #include <core/scoring/rms_util.hh>
51 
52 //numeric headers
53 
54 //// C++ headers
55 #include <cstdlib>
56 #include <string>
57 
59 #include <utility/vector1.hh>
60 
61 //Auto Headers
62 
63 
64 
65 
66 namespace protocols {
67 namespace loops {
68 namespace loop_closure {
69 namespace ccd {
70 
71 using namespace core;
72 using namespace pose;
73 
74 static numeric::random::RandomGenerator RG(9781212); // <- Magic number, do not change it!
75 static basic::Tracer tr("protocols.loops.loop_closure.ccd.LoopClosure");
76 
78  fragment::FragSetCOP fragset,
79  scoring::ScoreFunctionOP scorefxn,
80  Loop loop_def,
82 ) : loop_ ( loop_def ),
83  scorefxn_( scorefxn ),
84  movemap_( movemap ),
85  frag_mover_( NULL ),
86  ccd_mover_( NULL ),
87  fragset_( fragset ),
88  bEnableCcdMoves_( loop_def.size() >= 10 ? true : false ),
89  bRampChainbreak_( false )
90 {
91  set_cycles( 1.0 );
92  temperature_ = 2.0;
93  init();
94 }
95 
97  scorefxn_( NULL ),
98  movemap_( NULL ),
99  frag_mover_( NULL ),
100  ccd_mover_( NULL ),
101  fragset_( NULL ),
102  bEnableCcdMoves_( false )
103 {
104  set_cycles( 1.0 );
105  temperature_ = 2.0;
106 }
107 
109 
111 
113 
115  runtime_assert( fragset_ );
116  runtime_assert( movemap_ );
117  runtime_assert( scorefxn_ );
118 
119  //make movemap that only allows bb moves within loop ( if master movemap allows the move, too ).
120  kinematics::MoveMapOP loop_movemap = new kinematics::MoveMap;
121  loop_movemap->set_bb( false );
122  for ( Size pos = loop_.start(); pos <= loop_.stop(); pos ++ ) {
123  if ( movemap_->get_bb( pos ) ) loop_movemap->set_bb( pos, true );
124  }
125  set_movemap( loop_movemap );
126 
129  ptr->enable_end_bias_check( false ); //uniform sampling
130  ptr->set_check_ss( false );
131  if ( bEnableCcdMoves_ ) {
132  ccd_mover_ = new CcdMover( loop_, movemap_ );//well this has to change
133  }
134  runtime_assert( loop_.size() > 0 );
135  init_mc();
136  // put a template frame at top of list -- will always catch the fragments according to closure_frames.front()
137  using namespace fragment;
138  closure_frame_ = new Frame( loop_.start(), new FragData( new BBTorsionSRFD, loop_.size() ) );
139 }
140 
142 
143 void LoopClosure::set_cycles( core::Real cycle_ratio ) {
144  nr_fragments_ = static_cast< int > (100*cycle_ratio);
145  cycles_ = static_cast< int > (20*std::max( (int) loop_.size(), 5 /*arbitrary choice*/ ) *cycle_ratio);
146 }
147 
150 }
151 
156 }
157 
158 
159 bool
160 LoopClosure::apply( pose::Pose const& pose_in ) {
161  pose::Pose pose( pose_in );
162 
164 
165  Real best_score( 10000000.0 );
166  //Real best_fdev( 100000.0 );
167  for ( Size c1 = 1; c1 <= nr_fragments_; ++c1 ) {
168 
169  // replace all torsions of loop once
170  for ( Size pos = loop_.start(); pos <= (Size) loop_.stop(); pos++ ) {
171  bool success ( frag_mover_->apply( pose, pos ) );
172  if ( !success ) tr.Warning << " could not make fragment move at loop position " << pos
173  << " seqpos: " << pos << std::endl;
174  }
175 
176  mc().reset( pose );
177 
178  // monte-carlo based minimization of score via the supplied mover ( usually fragment insertions / and evtl. ccd-moves )
179  tr.Trace <<" before frag_cycles " << cycles_ << std::endl;
180  do_frag_cycles( pose );
181  tr.Trace << "after frag_cycles" << std::endl;
182  mc().recover_low( pose );
183  Real score;
184  score = (*scorefxn_)( pose );
185  tr.Trace << "start ccd " << std::endl;
186  CcdLoopClosureMover fast_ccd( loop_, movemap() );
187  fast_ccd.apply( pose );
188  Real fdev = fast_ccd.forward_deviation();
189  // if ( tr.Trace.visible() ) scorefxn_->show( tr, pose );
190 
191  if ( fast_ccd.success() ) {
192  best_score = std::min( best_score,score);
193  catch_fragment( pose );
194  }
195  tr.Debug << "LoopClosure: fragment " << c1 << " best_score: " << best_score << " pre ccd score: " << score
196  << " fdev: " << fdev << " bdev: " << fast_ccd.backward_deviation() << " " << ( fast_ccd.success() ? "SUCCESS" : "FAIL" )
197  << std::endl;
198  }
199  return closure_frame_->nr_frags() >= 1;
200 }
201 
202 void
203 LoopClosure::ramp_chainbreak( Size iter, Size total ) const {
204  runtime_assert( total > 0 );
205  if ( iter < static_cast< Size >( total/2.0) ) {
206  core::Real const progress( iter/total * 2.0 );
208  scorefxn_->set_weight( scoring::overlap_chainbreak, 0.0 );
209  } else {
210  core::Real const progress( iter/total );
211  scorefxn_->set_weight( scoring::linear_chainbreak, 1.0 );
213  }
214  mc_->score_function( *scorefxn_ );
215 }
216 
217 void
219  moves::TrialMover frag_trial( frag_mover_, mc_ );
220 
221  moves::TrialMoverOP ccd_trial;
222  if ( ccd_mover_ ) ccd_trial = new moves::TrialMover( ccd_mover_, mc_ );
224  for ( Size i = 1; i <= cycles_; i++ ) {
225  frag_trial.apply( pose );
226  if ( bRampChainbreak_ && ( i % 20 == 0 ) ) ramp_chainbreak( i, cycles_ );
227  if ( i % 10 ==0 ) tr.Trace << "loop-frag-trials: iterations: " << i << std::endl;
228  if ( ccd_trial && i > cycles_/2 && ( RG.uniform() * cycles_ ) < i ) {
229  ccd_trial->apply( pose );
230  }
231  }
232 }
233 
234 void
236  bool success ( closure_frame_->steal( pose ) );
237  runtime_assert( success );
238 }
239 
240 void
243  init_mc();
244 }
245 
246 } // namespace ccd
247 } // namespace loop_closure
248 } // namespace loops
249 } // namespace protocols