Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LoopJumpFoldCst.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 KinematicTaskCenter
11 /// @brief this class will be handled to a SampleProtocol as a control instance
12 /// @detailed responsibilities:
13 /// know which chainbreaks to penalize and close
14 /// know which jumps to use during sampling, which (if any) to keep after loop-closing
15 /// supply a JumpMover if jumps should be moved
16 /// supply a MoveMap
17 /// supply a "StrictMoveMap": the protocol should not move anything that is dissallowed in strict_movemap(),
18 /// it should try to move just stuff in movemap()
19 /// should this class also know how to ramp score terms ?
20 /// handle the titration of constraints ?
21 /// @author Oliver Lange
22 
23 // Unit Headers
25 
26 // Package Headers
28 
29 // Project Headers
30 #include <core/pose/Pose.hh>
31 
32 #include <core/fragment/FragSet.hh>
33 // AUTO-REMOVED #include <core/kinematics/util.hh>
35 // AUTO-REMOVED #include <core/id/NamedAtomID.hh>
36 
37 // AUTO-REMOVED #include <core/conformation/ResidueFactory.hh>
38 
39 
40 #include <basic/options/option.hh>
41 
42 // AUTO-REMOVED #include <core/conformation/util.hh> //idealize
43 
44 #include <protocols/loops/util.hh>
45 #include <protocols/loops/Loop.hh>
47 
48 // ObjexxFCL Headers
49 #include <ObjexxFCL/FArray1D.hh>
50 #include <ObjexxFCL/FArray2D.hh>
51 // AUTO-REMOVED #include <ObjexxFCL/format.hh>
52 #include <ObjexxFCL/string.functions.hh>
53 
54 // Utility headers
55 #include <numeric/random/random.hh>
56 #include <utility/io/izstream.hh>
57 #include <utility/io/ozstream.hh>
58 #include <utility/io/util.hh>
59 #include <basic/Tracer.hh>
60 
61 
62 //// C++ headers
63 #include <fstream>
64 
65 
66 // option key includes
67 
68 #include <basic/options/keys/loops.OptionKeys.gen.hh>
69 
70 #include <utility/vector1.hh>
71 
72 
73 
74 static basic::Tracer tr("protocols.general_abinitio",basic::t_info);
75 static numeric::random::RandomGenerator RG(1871221234);
76 
77 namespace protocols {
78 namespace abinitio {
79 
80 using namespace core;
81 
83 
86  return "LoopJumpFoldCst";
87 }
88 
89 ///////////////////////////////////////////////////////////////////////
90 /// @brief Select loop set at random using skip rate
92  loops::Loops& loops_out
93 ) const
94 {
95  loops_out.clear();
96  int ntries = 0;
97  while (loops_out.size() == 0 && ntries++ < 50) {
98  for ( loops::Loops::const_iterator it = loops_.begin(), eit = loops_.end();
99  it != eit; ++it ) {
100  if ( RG.uniform() >= it->skip_rate() ) {
101  loops_out.push_back( *it );
102  }
103  }
104  }
105  if ( loops_out.size() == 0 ) {
106  loops_out = loops_;
107  }
108 } // void LoopRebuild::select_loops
109 
110 // helper to new_kinematics
112  // get flexible jumps ( beta-sheet stuff etc. )
113  jumping::JumpSample current_jumps;
114  if ( jump_def_ ) {
115  movemap->set_jump( true ); //careful that these don't get minimized!
116  // initialize jumping
117  Size attempts( 10 );
118  do {
119  current_jumps = jump_def_->create_jump_sample();
120  } while ( !current_jumps.is_valid() && attempts-- );
121 
122  if ( !current_jumps.is_valid() ) {
123  utility_exit_with_message( "not able to build valid fold-tree in JumpingFoldConstraints::setup_foldtree" );
124  }
125 
126  tr.Debug << "current_jumps " << current_jumps << std::endl;
127 
128  // get fragments to sample these jumps
129  core::fragment::FragSetOP jump_frags;
130 
131  if ( coordinate_constraint_weight_ > 0 ) { //don't allow jumps move in xyz-fixed area --- i.e., the stuff that should stay rather fixed
132  // movemap = new kinematics::MoveMap( *movemap ); seems redundant
133  // flexible_part.switch_movemap( *movemap, id::BB, true ); this line seems redundant here
134  }
135  jump_frags = jump_def_->generate_jump_frags( current_jumps, *movemap );
137  jump_mover->type( "JumpMoves" );
138  jump_mover->set_check_ss( false ); // this doesn't make sense with jump fragments
139  jump_mover->enable_end_bias_check( false ); //no sense for discontinuous fragments
140 
141 
142  current_kinematics->set_sampling_fold_tree( current_jumps.fold_tree() );
143  current_kinematics->set_jump_mover( jump_mover );
144  } else {
145  //take existing fold-tree
146  current_kinematics->set_sampling_fold_tree( current_kinematics->final_fold_tree() );
147  }
148 
149  return true;
150 }
151 
152 
153 
154 //@brief create a new fold-tree and movemap --- a KinematicControl object
155 // a basic generalized protocol:
156 // loops are determined: if loops present only loops move, otherwise everything moves
157 // get jumps from JumpDef ( as in JumpingFoldCst, for instance beta-sheet jumps )
158 // combine jumps with additional jumps that keep the rigid portions together ( looprlx-type )
159 // set movemap to allow only sampling of flexible parts. call sampling protocol
161  using namespace basic::options;
162  using namespace basic::options::OptionKeys;
163 
164  // select loops
165  loops::Loops loops;
166  if ( loops_.size() > 0 ) {
167  select_loops( loops );
168  }
169  tr.Debug << loops << std::endl;
170 
171  KinematicControlOP current_kinematics( NULL );
172  if ( loops.size() && coordinate_constraint_weight_ > 0.0 ) {
173  current_kinematics = new CoordinateConstraintKC( false /*ramp*/, coordinate_constraint_weight_ );
174  } else {
175  current_kinematics = new KinematicControl;
176  }
177 
178  loops::Loops mmloops;
179  if( option[ OptionKeys::loops::mm_loop_file ].user() ) {
180  mmloops = loops::Loops( option[ OptionKeys::loops::mm_loop_file ]() );
181  }else{
182  mmloops = loops;
183  }
184 
185  //figure out movemap!
187  movemap->set_jump( true );
188  if ( jump_def_ ) movemap->set_jump( true ); //careful that these don't get minimized!
189  if ( mmloops.size() && coordinate_constraint_weight_ == 0.0 ) {
190  mmloops.switch_movemap( *movemap, id::BB, true );
191  loops.switch_movemap( *movemap, id::BB, true );
192  } else {
193  movemap->set_bb( true );
194  }
195  loops::Loops rigid_core( loops.invert( pose.total_residue() ) );
196 
197  bool success( true );
198  current_kinematics->set_final_fold_tree( pose.fold_tree() );
199  success = parse_jump_def( current_kinematics, movemap );
200  current_kinematics->set_movemap( movemap );
201 
202  // change fold-tree such that only loop parts can move
203  if ( loops.size() ) {
204  // subsequently add sufficiently many jumps such that all numbers are the same.
205  success &= add_rigidity_jumps( rigid_core, current_kinematics );
206  if ( !success ) {
207  tr.Warning << "[WARNING] was not able to fix rigid regions with jumps...retry" << std::endl;
208  return NULL;
209  }
210  }
211  pose.fold_tree( current_kinematics->sampling_fold_tree() );
213  if ( rigid_core.size() ) {
214  success = add_coord_cst( rigid_core, pose );
215  }
216  return current_kinematics;
217 }
218 
219 bool
221  if ( coordinate_constraint_weight_ != 0.0 ) {
222  bool bWeightsIn = ( coordinate_constraint_weights_.size() >= pose.total_residue() );
223  loops::fix_with_coord_cst( rigid_core, pose, bCstAllAtom_, coordinate_constraint_weights_ );
224  if ( dump_weights_file_ != "NO_DUMP" ) {
225  utility::io::write_vector( dump_weights_file_, coordinate_constraint_weights_ );
226  dump_weights_file_ = "NO_DUMP"; //do it only once
227  }
228 
229  //add also constraints to the resolution switch...
230  loops::fix_with_coord_cst( rigid_core, res_switch().init_pose(), true, coordinate_constraint_weights_ );
231  if ( !bWeightsIn ) coordinate_constraint_weights_.clear(); //delete them again if they haven't been provided from the outside
232  }
233  return true;
234 }
235 
236 bool
238  ObjexxFCL::FArray1D_float const& cut_probability( ss_def_->loop_fraction() );
239  // add jumps to the fold-tree such that the rigid parts are all connected by jumps.
240  // first find out which rigid regions ( which are nothing else than inverted loops )
241  // are already connected by a jump.
242  // we make a "visited" field. It will contain number 0 for regions that have no connection to rigid regions
243  // and for each rigid-super-region it has a distinct number, e.g., 1 2 1 0 1 2 0, means region 1 3 with 5 and 2 with 6 are already connected
244  kinematics::FoldTree const f( current_kinematics->sampling_fold_tree() );
245 
246  // list of jumps that connect rigid regions ( these jump_dofs should not be moved )
247  jumping::JumpList rigid_jumps;
248  // list of jumps that connect flexible regions ( these jump_dofs should be moved )
249  jumping::JumpList flex_jumps;
250 
251  // go thru existing jumps and fill them into the rigid_jump/flex_jump lists. Moreover, figure out which rigid regions are already connected by jumps
252  utility::vector1< Size > visited( rigid.size(), 0 );
253  for ( Size jump_nr = 1; jump_nr <= f.num_jump(); jump_nr++ ) {
254  Size const up( f.upstream_jump_residue( jump_nr ) );
255  Size const down( f.downstream_jump_residue( jump_nr ));
256  Size up_loop;
257  Size down_loop;
258  if ( (up_loop = rigid.loop_index_of_residue( up )) && (down_loop = rigid.loop_index_of_residue( down ) )) {
259  if ( up_loop != down_loop
260  && ( !visited[ up_loop ] || !visited[ down_loop ] || ( visited[ up_loop ] != visited[ down_loop ] ) ) ) {
261  rigid_jumps.push_back( jumping::Interval( up, down ) ); //good jump --- keep it
262  // decide upon 3 cases: both nodes unvisited, 1 node visited, both nodes visited
263  // case0 : both new tag with new jump_nr
264  Size visit_nr = jump_nr;
265  // case1 : both visited--> replace all higher visit_nr by lower visit_nr
266  if ( visited[ up_loop ] && visited[ down_loop ] ) {
267  Size old_visit_nr = visited[ down_loop ]; //arbitrary choice
268  visit_nr = visited[ up_loop ];
269  for ( Size i=1; i<=visited.size(); i++ ) {
270  if ( visited[ i ] == old_visit_nr ) visited[ i ] = visit_nr;
271  }
272  } else if ( visited[ up_loop ] || visited[ down_loop ]) {
273  // case2: one already visited the other is still zero and thus neutral to addition
274  visit_nr = visited[ up_loop ] + visited[ down_loop ];
275  }
276  visited[ up_loop ] = visit_nr;
277  visited[ down_loop ] = visit_nr;
278  } // jump between different regions
279  } else {
280  flex_jumps.push_back( jumping::Interval( up, down ) ); // jump does not link rigid regions
281  }
282  } // for jump_nr
283 
284  //now we have a connection pattern based on the jumps already present.
285  //a visited region and make it the root-reg
286  Size root_reg = 0;
287  for ( Size region = 1; region <= visited.size(); region++ ) {
288  if ( visited[ region ] ) {
289  root_reg = region;
290  break;
291  }
292  }
293  // if no rigid regions are yet connected, define one arbitrarily as the root-reg
294  if ( root_reg == 0 ) {
295  root_reg = 1;
296  visited[ root_reg ] = 1;
297  }
298 
299  for ( jumping::JumpList::iterator it = rigid_jumps.begin(), eit = rigid_jumps.end(); it !=eit; ++it) {
300  tr.Debug << "Fix_jumps: " << it->start_<< " " << it->end_ << std::endl;
301  }
302  tr.Debug << "now add more fix-jumps " << std::endl;
303 
304  loops::Loops::LoopList rigid_loops = rigid.loops(); // loops in sequence that correspond to the regions
305  Size const anchor( static_cast< Size >( 0.5*(rigid_loops[ root_reg ].stop() - rigid_loops[ root_reg ].start()) ) + rigid_loops[ root_reg ].start() );
306  for ( Size region = 1; region <= visited.size(); region++ ) {
307  Size old_visited = visited[ region ];
308  if ( visited[ region ] != visited[ root_reg ] ) {
309  rigid_jumps.push_back ( jumping::Interval( anchor,
310  rigid_loops[ region ].start() + static_cast< Size >( 0.5*( rigid_loops[ region ].stop()-rigid_loops[ region ].start() ) ) ) );
311  visited[ region ] = visited[ root_reg ];
312  if ( old_visited ) { //if we connected a cluster make sure to update all its nodes
313  for ( Size i=1; i<=visited.size(); i++ ) {
314  if ( visited[ i ] == old_visited ) visited[ i ] = visited[ root_reg ];
315  }
316  }
317  }
318  } // for region
319 
320 
321  ObjexxFCL::FArray1D_float new_cut_prob( cut_probability );
322  for ( loops::Loops::const_iterator it = rigid.begin(), eit = rigid.end(); it != eit; ++it ) {
323  for ( Size pos = it->start(); pos <= it->stop(); pos++ ) {
324  new_cut_prob( pos ) = 0;
325  }
326  }
327 
328  Size total_njump( rigid_jumps.size() + flex_jumps.size() );
329  ObjexxFCL::FArray2D_int jumps( 2, total_njump );
330  Size ct = 1;
331  for ( jumping::JumpList::iterator it = rigid_jumps.begin(), eit = rigid_jumps.end(); it !=eit; ++it, ++ct ) {
332  jumps( 1, ct ) = it->start_;
333  jumps( 2, ct ) = it->end_;
334  tr.Debug << "Fix_jumps: " << it->start_<< " " << it->end_ << std::endl;
335  }
336  for ( jumping::JumpList::iterator it = flex_jumps.begin(), eit = flex_jumps.end(); it !=eit; ++it, ++ct ) {
337  jumps( 1, ct ) = it->start_;
338  jumps( 2, ct ) = it->end_;
339  tr.Debug << "Flex_jumps: " << it->start_<< " " << it->end_ << std::endl;
340  }
341  for ( Size i = 1; i<= current_kinematics->sampling_fold_tree().nres(); i++ ) {
342  tr.Trace << "cut_prob: " << i << " " << new_cut_prob( i ) << std::endl;
343  }
344  kinematics::FoldTree new_fold_tree;
345  bool success = new_fold_tree.random_tree_from_jump_points( current_kinematics->sampling_fold_tree().nres(), total_njump, jumps, new_cut_prob );
346 
347  if ( success ) {
348  if ( rigid_jumps.size() ) {
349  //this reordering is essential if we use coord cst. since they are relative to the origin (root of fold-tree)
350  // we want the root in the most "fixed" position, and then fix the coord-cst atoms to this root
351  success = new_fold_tree.reorder( rigid_jumps.begin()->start_ ); //or try multiple residues?
352  if ( !success ) {
353  tr.Warning << "[WARNING] failed to reorder fold-tree() ... retry"<<std::endl;
354  return success;
355  }
356  }
357  new_fold_tree.put_jump_stubs_intra_residue();
358  current_kinematics->set_sampling_fold_tree( new_fold_tree );
359  kinematics::MoveMapOP mm( new kinematics::MoveMap( current_kinematics->movemap() ) );
360  mm->set_jump( false );
361  //find flexible jump-nr in fold tree and update movemap accordingly
362  for ( jumping::JumpList::iterator it = flex_jumps.begin(), eit = flex_jumps.end(); it !=eit; ++it ) {
363  mm->set_jump( it->start_, it->end_, true );
364  }
365  current_kinematics->set_movemap( mm );
366  }
367 
368  return success;
369 }
370 
371 }
372 }