Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JumpClaimer.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 TopologyBroker
11 /// @brief top-class (Organizer) of the TopologyBroker mechanism
12 /// @detailed responsibilities:
13 /// @author Oliver Lange
14 
15 // Unit Headers
17 
18 // Package Headers
20 
21 // Project Headers
22 #include <core/pose/Pose.hh>
24 #ifdef WIN32
25 #include <core/fragment/FragID.hh>
26 #endif
27 
28 #include <core/fragment/FragSet.hh>
31 // AUTO-REMOVED #include <core/fragment/FragmentIO.hh>
34 
35 
36 
37 // ObjexxFCL Headers
38 
39 // Utility headers
40 //#include <utility/io/izstream.hh>
41 //#include <utility/io/ozstream.hh>
42 #include <utility/excn/Exceptions.hh>
43 #include <basic/Tracer.hh>
44 //#include <basic/options/option.hh>
45 
46 //// C++ headers
47 // AUTO-REMOVED #include <fstream>
48 
49 #include <core/fragment/Frame.hh>
50 #include <utility/vector1.hh>
51 #include <typeinfo>
52 
53 // option key includes
54 
55 static basic::Tracer tr("protocols.topo_broker",basic::t_info);
56 //static numeric::random::RandomGenerator RG(18828234);
57 
58 namespace protocols {
59 namespace topology_broker {
60 
61 using namespace core;
62 
64  jump_def_( NULL ),
65  init_mover_( NULL ),
66  bKeepJumpsFromInputPose_( true )
67 {
68  set_bInitDofs( true ); //we want to initialize jumps
69 }
70 
72  FragmentClaimer( NULL, tag, weight ),
73  jump_def_ ( jump_def ),
74  init_mover_( NULL ),
75  bKeepJumpsFromInputPose_( true )
76 {
77  set_bInitDofs( true ); //we want to initialize jumps
78 }
79 
81  TopologyClaimer( src ),
82  Parent( src )
83 {
84  jump_def_ = src.jump_def_ ;
86  init_mover_ = src.init_mover_ ;
88 
89 }
90 
92 
94 {
95  return new JumpClaimer( *this );
96 }
97 
98 
100  discard_jumps_ = true;
101  input_pose_.clear();
102 }
103 
104 
106  new_decoy();
107  input_pose_ = pose;
108 }
109 
110 void JumpClaimer::initialize_dofs( core::pose::Pose& pose, DofClaims const& init_dofs, DofClaims& failed_to_init ) {
111  //need to copy coords and jumps --- if chunks were idealized no problem .... but non-idealized stuff ?
112  if ( init_mover_ ) {
115  FragmentClaimer::initialize_dofs( pose, init_dofs, failed_to_init );
116  set_mover( frag_mover );
117  init_mover_ = NULL;
118  } else {
119  FragmentClaimer::initialize_dofs( pose, init_dofs, failed_to_init );
120  }
121 }
122 
124  discard_jumps_ = false;
126  tr.Info << type()
127  << ": get jumps from input pose. use flag NO_USE_INPUT_POSE if you want to create new jumps "
128  << std::endl;
130  if ( current_jumps_.size() == 0 ) return;
131  std::set< Size > active_region;
132  get_sequence_region( active_region );
133  ObjexxFCL::FArray2D_int filtered_jumps( 2, current_jumps_.size() );
134  ObjexxFCL::FArray1D_int filtered_cuts( current_jumps_.size() );
135  Size ct( 0 );
136  for ( Size i = 1; i<=current_jumps_.size(); ++i ) {
137  Size jump1( current_jumps_.jumps()( 1, i ) );
138  Size jump2( current_jumps_.jumps()( 2, i ) );
139  if ( active_region.find( jump1 ) != active_region.end()
140  && active_region.find( jump2 ) != active_region.end() ) {
141  ++ct;
142  filtered_jumps( 1, ct ) = jump1 < jump2 ? jump1 : jump2 ;
143  filtered_jumps( 2, ct ) = jump1 < jump2 ? jump2 : jump1 ;
144  filtered_cuts( ct ) = current_jumps_.cuts()( i );
145  }
146  }
147  current_jumps_ = jumping::JumpSample( *active_region.rbegin() /*total_residue*/, ct, filtered_jumps, filtered_cuts );
148 
149  if ( jump_def_ ) current_jumps_ = jump_def_->clean_jumps( current_jumps_ );
150  tr.Debug << "current_jumps " << current_jumps_ << std::endl;
151  } else {
152  if ( !jump_def_ ) return;
153  runtime_assert( jump_def_ );
154  tr.Info << type() << ": create new random jumps" << std::endl;
155  Size attempts( 10 );
156  do {
157  current_jumps_ = jump_def_->create_jump_sample();
158  if ( tr.Debug.visible() && !current_jumps_.is_valid() ) {
159  tr.Debug << "was not able to make fold-tree for " << current_jumps_ << std::endl;
160  }
161  } while ( !current_jumps_.is_valid() && attempts-- );
162  }
163 
164  if ( !current_jumps_.is_valid() ) {
165  throw utility::excn::EXCN_BadInput("not able to build valid fold-tree from a "+jump_def_->type_name()+" in 10 attempts in JumpClaimer");
166  }
167  tr.Debug << "current_jumps " << current_jumps_ << std::endl;
168 
169  if ( input_pose_.total_residue() > 0 ) {
170  core::fragment::FrameList jump_frames;
172  mm.set_bb( true );
173  mm.set_jump( true );
174 
175  current_jumps_.generate_jump_frames( jump_frames,mm );
176 
177  for ( core::fragment::FrameList::iterator jump_frame = jump_frames.begin();
178  jump_frame != jump_frames.end(); ++jump_frame ) {
179  (*jump_frame)->steal( input_pose_ );
180  }
181 
183  jump_frags->add( jump_frames );
184 
186  init_mover_->type( mover_tag() );
187  init_mover_->set_check_ss( false ); // this doesn't make sense with jump fragments
188  init_mover_->enable_end_bias_check( false ); //no sense for discontinuous fragments
189  }
190  input_pose_.clear();
191 
192 }
193 
195  if ( discard_jumps_ ) init_jumps();
196  // get flexible jumps ( beta-sheet stuff etc. )
197  /// in future get rid of JumpSample class all-together.
198 
199  movemap_->set_jump( true ); //we switch them off on a as-need basis
200  movemap_->set_bb( true );
201 
202  fragment::FragSetOP jump_frags;
203  if ( jump_def_ ) {
204  jump_frags = jump_def_->generate_jump_frags( current_jumps_, *movemap_ );
205 
207  jump_mover->type( mover_tag() );
208  jump_mover->set_check_ss( false ); // this doesn't make sense with jump fragments
209  jump_mover->enable_end_bias_check( false ); //no sense for discontinuous fragments
210  set_mover( jump_mover );
211  } else {
212  jump_frags = new core::fragment::OrderedFragSet;
213  core::fragment::FrameList jump_frames;
215  jump_frags->add( jump_frames );
216  }
217 
218  Size nr_jumps = current_jumps_.size();
219  // runtime_assert( jump_frags->nr_frames() == nr_jumps );
220  for ( Size i = 1; i<=nr_jumps; ++i ) {
221  Size const up( current_jumps_.jumps()( 1, i ) );
222  Size const down( current_jumps_.jumps()( 2, i ) );
223  std::string up_atom( current_jumps_.jump_atoms()(1, i ) );
224  std::string down_atom( current_jumps_.jump_atoms()(2, i ) );
225  //now this assumes that we have the BB - Jump - BB frags...
226  // how about translating Fragments directly into Claims ???
227  fragment::FrameList frames;
228  jump_frags->frames( up, frames );
229  jump_frags->frames( down, frames );
230  kinematics::MoveMap jump_mm;
231  jump_mm.set_jump( up, down, true );
232  bool found_frame( false );
233  for ( fragment::FrameList::iterator it = frames.begin(); it!=frames.end(); ++it ) {
234  if ( 2 == (*it)->nr_res_affected( jump_mm ) ) {
235  //that is our jump-fragment
236  found_frame = true;
237  new_claims.push_back( new JumpClaim( this, up, down, up_atom, down_atom, DofClaim::INIT ) );
238  kinematics::MoveMap bb_mm; bb_mm.set_bb( false );
239  bb_mm.set_bb( up, true );
240  if ( 2 == (*it)->nr_res_affected( bb_mm ) ) new_claims.push_back( new BBClaim( this, up ) ); //up jump always counted
241  bb_mm.set_bb( down, true ); bb_mm.set_bb( up, false);
242  if ( 2 == (*it)->nr_res_affected( bb_mm ) ) new_claims.push_back( new BBClaim( this, down ) ); //up jump always counted
243  break;
244  }
245  }
246  runtime_assert( found_frame ); // there should be fragments for each jump!
247  } // for 1..nr_jumps
248 }
249 
250 bool JumpClaimer::read_tag( std::string tag, std::istream& is ) {
251  if ( tag == "NO_USE_INPUT_POSE" ) {
252  bKeepJumpsFromInputPose_ = false;
253  } else if ( tag == "USE_INPUT_POSE" ) {
255  } else return Parent::read_tag( tag, is );
256  return true;
257 }
258 
259 } //topology_broker
260 } //protocols