Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TopologyBroker.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 /// maintains list of ToplogyClaimers
14 /// maintains DofClaims -- exclusive or non-exclusively markedup dofs like BackboneClaim, IntraResClaim, JumpClaim
15 /// generates FoldTree, MoveMap, and collects samplers provided by TopologyClaimers
16 /// @author Oliver Lange
17 
18 // Unit Headers
20 
21 // Package Headers
25 
26 // Project Headers
27 #include <core/pose/Pose.hh>
28 #include <protocols/jd2/util.hh>
44 #include <basic/options/option.hh>
45 #include <basic/options/keys/in.OptionKeys.gen.hh>
49 #include <core/pose/util.hh>
50 // AUTO-REMOVED #include <core/scoring/dssp/StrandPairing.hh>
53 
54 // for symmetry
56 // AUTO-REMOVED #include <core/conformation/symmetry/util.hh>
58 
59 // ObjexxFCL Headers
60 #include <ObjexxFCL/FArray1D.hh>
61 #include <ObjexxFCL/FArray2D.hh>
62 
63 // Utility headers
64 #include <basic/Tracer.hh>
65 
66 // C++ headers
67 #ifdef WIN32
68 #include <algorithm>
69 #include <iterator>
70 #endif
71 
72 #include <sstream>
73 #include <vector>
74 
75 #include <utility/vector0.hh>
76 #include <utility/vector1.hh>
77 
78 
79 namespace ObjexxFCL { } using namespace ObjexxFCL;
80 
81 static basic::Tracer tr("protocols.topo_broker", basic::t_info);
82 
83 namespace protocols {
84 namespace topology_broker {
85 
86 using namespace utility::excn;
87 using namespace core;
88 
89 TopologyBroker::TopologyBroker() :
90  nres_( 0 ),
91  fold_tree_( NULL ),
92  final_fold_tree_( NULL ),
93  repack_scorefxn_( NULL ),
94  bUseJobPose_( false ),
95  current_pose_( NULL )
96 {}
97 
99 
101  ReferenceCount(),
102  claimers_( tp.claimers_ )
103 {
105  nres_ = tp.nres_;
106  fold_tree_ = tp.fold_tree_;
112 }
113 
115  if ( this != &src ) {
116  claimers_ = src.claimers_;
118  nres_ = src.nres_;
119  fold_tree_ = src.fold_tree_;
125  }
126  return *this;
127 }
128 
130  claimers_.push_back( cl );
131  cl->set_broker( this );
132 }
133 
135  for ( TopologyClaimers::iterator top = claimers_.begin();
136  top != claimers_.end(); ++top ) {
137  (*top)->generate_sequence_claims( all_claims );
138  }
139  tr.Trace << "All sequence claims: \n" << all_claims << std::endl;
140 }
141 
143  for ( TopologyClaimers::const_iterator top = claimers_.begin();
144  top != claimers_.end(); ++top ) {
145  if ( msg.matches( (*top)->label() ) ) {
146  (*top)->receive_message( msg );
147  }
148  }
149 }
150 
152  for ( TopologyClaimers::iterator top = claimers_.begin();
153  top != claimers_.end(); ++top ) {
154  tr.Trace << "generate claim for " << (*top)->type() << std::endl;
155  (*top)->generate_claims( all_claims );
156  }
157  tr.Trace << "All round1 claims: \n" << all_claims << std::endl;
158 }
159 
161  for ( TopologyClaimers::iterator top = claimers_.begin();
162  top != claimers_.end(); ++top ) {
163  (*top)->finalize_claims( all_claims );
164  }
165  tr.Trace << "all final claims: \n " << all_claims << std::endl;
166 }
167 
169  fragment::FragSetCOP frags( NULL );
170  for ( TopologyClaimers::const_iterator top = claimers_.begin();
171  top != claimers_.end(); ++top ) {
172  fragment::FragSetCOP new_frags = (*top)->loop_frags( movemap );
173  runtime_assert( !(new_frags && frags ) );
174  if ( new_frags ) frags = new_frags;
175  }
176  runtime_assert( frags );
177  runtime_assert( !frags->empty() );
178  return frags;
179 }
180 
182  pose.constraint_set( NULL );
183  for ( TopologyClaimers::const_iterator top = claimers_.begin();
184  top != claimers_.end(); ++top ) {
185  (*top)->add_constraints( pose );
186  }
187  if ( tr.Trace.visible() ) {
188  tr.Trace << "all constraints\n " << std::endl;
189  pose.constraint_set()->show_definition( tr.Trace, pose );
190  tr.Trace << std::endl;
191  }
192 }
193 
195  abinitio::StageID stage_id,
196  core::scoring::ScoreFunction const& scorefxn,
197  core::Real progress ) const {
198 
199  moves::RandomMoverOP random_mover = new moves::RandomMover;
200  for ( TopologyClaimers::const_iterator top = claimers_.begin();
201  top != claimers_.end(); ++top ) {
202  (*top)->add_mover( *random_mover, pose, stage_id, scorefxn, progress );
203  }
204 
205  //should this be an exception? --- it seems pretty pathological
206  if ( !random_mover->size() ) {
207  tr.Warning << "[ WARNING ] no mover returned in stage " << stage_id
208  << " progress " << progress << std::endl;
209  }
210 
211  runtime_assert( random_mover->size() ); //seg-fault down the line otherwise
212  return random_mover;
213 }
214 
216  abinitio::StageID stage_id,
217  core::Real progress ) const {
218  tr.Debug << "apply filter: \n";
219  for ( TopologyClaimers::const_iterator top = claimers_.begin();
220  top != claimers_.end(); ++top ) {
221  std::ostringstream report;
222  if ( !(*top)->passes_filter( pose, stage_id, progress, report ) ) {
223  tr.Debug.flush();
224  throw EXCN_FilterFailed( report.str() );
225  }
226  if ( report.str().size() ) tr.Debug << "CLAIMER " << (*top)->type() << ":" << (*top)->label() << " FILTER REPORT: \n"
227  << report.str();
228  }
229  tr.Debug.flush();
230 }
231 
233  for ( DofClaims::iterator claim=claims.begin(); claim != claims.end(); ++claim ) {
234  (*claim)->owner()->claim_accepted( *claim );
235  }
236 }
237 
238 bool TopologyBroker::broking( DofClaims const& all_claims, DofClaims& pre_accepted ) {
239  // DofClaims pre_accepted;
240  tr.Debug << "broking claims..." << std::endl;
241  bool fatal( false );
242  for ( DofClaims::const_iterator claim = all_claims.begin();
243  claim != all_claims.end() && !fatal; ++claim ) {
244  bool allow( true );
245  for ( TopologyClaimers::iterator top = claimers_.begin();
246  top != claimers_.end() && allow; ++top ) {
247  allow = (*top)->allow_claim( **claim );
248  }
249  if ( !allow ) {
250  tr.Trace << "declined: " << **claim << std::endl;
251  fatal = !(*claim)->owner()->accept_declined_claim( **claim );
252  } else {
253  tr.Trace << "accepted: " << **claim << std::endl;
254  pre_accepted.push_back( *claim );
255  }
256  }
257  return !fatal;
258 }
259 
261  DofClaims seq_claims;
262  generate_sequence_claims( seq_claims );
263 
264  core::Size nres( 0 );
265  for ( DofClaims::iterator claim = seq_claims.begin(); claim != seq_claims.end(); ++claim ) {
266  nres += (*claim)->pos( 2 );
267  }
268  return nres > 0;
269 }
270 
272  DofClaims exclusive_jumps;
273  DofClaims negotiable_jumps;
274  DofClaims must_cut;
275  DofClaims cut_biases;
276  std::vector< int > obligate_cut_points; //yes FoldTree.cc uses still these classes
277 
278  Size root( 0 );
279  bool excl_root_set( false );
280 
281  tr.Debug << "build fold tree ... " << std::endl;
282  for ( DofClaims::iterator claim=claims.begin(); claim != claims.end(); ++claim ) {
283  if ( (*claim)->type() == DofClaim::JUMP ) {
284  if ( (*claim)->exclusive() ) {
285  exclusive_jumps.push_back( *claim );
286  } else {
287  negotiable_jumps.push_back( *claim );
288  }
289  } else if ( (*claim)->type() == DofClaim::CUT ) {
290  must_cut.push_back( *claim );
291  tr.Trace << "obligate cut-point requested at " << (*claim)->pos( 1 ) << std::endl;
292  obligate_cut_points.push_back( (int) (*claim)->pos( 1 ) );
293  } else if ( (*claim)->type() == DofClaim::ROOT ) {
294  //we allow only a single non-exclusive setting of root --- this can be overwritten by a single exclusive clain
295  if ( ( root && !excl_root_set && (*claim)->exclusive() ) || !root || root == (*claim)->pos( 1 ) ) {
296  root = (*claim)->pos( 1 );
297  excl_root_set = (*claim)->exclusive();
298  } else {
299  throw( kinematics::EXCN_InvalidFoldTree( "Shouldn't have two exclusive roots --- ask oliver, throw an exception ?", *fold_tree_ ) );
300  }
301  }
302  }
303 
304  if ( !root ) root = 1;
305 
306  utility::vector1< core::Real > cut_bias( nres, 1.0 );
307  for ( TopologyClaimers::iterator top = claimers_.begin();
308  top != claimers_.end(); ++top ) {
309  (*top)->manipulate_cut_bias( cut_bias );
310  }
311  ObjexxFCL::FArray1D_float cut_bias_farray( nres );
312  for ( Size i=1; i<=nres; i++ ) cut_bias_farray( i ) = cut_bias[ i ];
313 
314  ObjexxFCL::FArray2D_int jumps( 2, exclusive_jumps.size() + negotiable_jumps.size() );
315  ObjexxFCL::FArray2D< std::string > jump_atoms( 2, exclusive_jumps.size() + negotiable_jumps.size() );
316  ObjexxFCL::FArray2D_int after_loops_jumps( 2, exclusive_jumps.size() + negotiable_jumps.size() );
317  ObjexxFCL::FArray2D< std::string > after_loops_jump_atoms( 2, exclusive_jumps.size() + negotiable_jumps.size() );
318 
319  Size nexcl( 0 );
320  Size n_non_removed( 0 );
321  // make list of all exclusive jumps from 1 .. nexecl
322  for ( DofClaims::iterator jump=exclusive_jumps.begin(); jump != exclusive_jumps.end(); ++jump ) {
323  runtime_assert( (*jump)->size() == 2 );
324  JumpClaimOP jump_ptr( dynamic_cast< JumpClaim* >( jump->get() ) );
325  runtime_assert( jump_ptr );
326  ++nexcl;
327  jumps( 1, nexcl) = (*jump)->pos( 1 );
328  jumps( 2, nexcl) = (*jump)->pos( 2 );
329  jump_atoms( 1, nexcl ) = jump_ptr->jump_atom( 1 );
330  jump_atoms( 2, nexcl ) = jump_ptr->jump_atom( 2 );
331  if ( !jump_ptr->remove() ) {
332  ++n_non_removed;
333  after_loops_jumps( 1, n_non_removed ) = jump_ptr->pos( 1 );
334  after_loops_jumps( 2, n_non_removed ) = jump_ptr->pos( 2 );
335  after_loops_jump_atoms( 1, n_non_removed ) = jump_ptr->jump_atom( 1 );
336  after_loops_jump_atoms( 2, n_non_removed ) = jump_ptr->jump_atom( 2 );
337  }
338  }
339  /// add all negotiable jumps to list ... 1..nexcl+nnegot
340  Size nnegot( 0 );
341  for ( DofClaims::iterator jump=negotiable_jumps.begin(); jump != negotiable_jumps.end(); ++jump ) {
342  runtime_assert( (*jump)->size() == 2 );
343  JumpClaimOP jump_ptr( dynamic_cast< JumpClaim* >( jump->get() ) );
344  runtime_assert( jump_ptr );
345  ++nnegot;
346  jumps( 1, nexcl+nnegot ) = (*jump)->pos( 1 );
347  jumps( 2, nexcl+nnegot ) = (*jump)->pos( 2 );
348  jump_atoms( 1, nexcl+nnegot ) = jump_ptr->jump_atom( 1 );
349  jump_atoms( 2, nexcl+nnegot ) = jump_ptr->jump_atom( 2 );
350  }
351  tr.Trace << "negotiable jumps: " << negotiable_jumps << std::endl;
352  tr.Trace << "exclusive jumps: " << exclusive_jumps << std::endl;
353  bool bValidTree = false;
354  bool try_again = true;
355 
356  //there might be cutpoints in the starting points these are added for sampling...
357  //but not for final fold-tree
358  std::vector< int > obligate_sampling_cut_points( obligate_cut_points );
359  std::copy( start_pose_cuts_.begin(), start_pose_cuts_.end(), std::back_inserter( obligate_sampling_cut_points ) );
360 
361  while ( try_again && !bValidTree ) {
363  Size attempts( 10 );
364  while ( !bValidTree && attempts-- > 0 ) {
365  bValidTree = fold_tree_->random_tree_from_jump_points( nres, nexcl+nnegot, jumps, obligate_sampling_cut_points, cut_bias_farray, root, true );
366  }
367  try_again = false;// for now. later we can think of ways to improve by switching negotiable_jumps on and off
368  }
369 
370  if ( !bValidTree ) {
371  std::ostringstream msg;
372  for ( Size i = 1; i<=nexcl+nnegot; ++i ) {
373  msg << jumps(1, i ) << " " << jumps(2, i ) << std::endl;
374  }
375  throw( kinematics::EXCN_InvalidFoldTree( "TopologyBroker failed to make a fold-tree in 10 attempts\n"+msg.str(), *fold_tree_ ) );
376  }
377 
378  for ( Size i = 1; i <= nexcl+nnegot; ++i ) {
379  fold_tree_->set_jump_atoms( i, jumps( 1, i), jump_atoms( 1, i ), jumps( 2, i), jump_atoms( 2, i ) );
380  }
381  fold_tree_->put_jump_stubs_intra_residue();
382 
383  //make final tree: cutbias will be 0 everywhere 1 where we had cuts before ... makes sense?
384  for ( Size i=1; i<=nres; i++ ) {
385  cut_bias_farray( i ) = 0.0;
386  if ( fold_tree_->is_cutpoint( i ) ) cut_bias_farray( i ) = 1.0;
387  }
389  bool bValidFinalTree =
390  final_fold_tree_->random_tree_from_jump_points( nres, n_non_removed, after_loops_jumps, obligate_cut_points, cut_bias_farray, root );
391  if ( !bValidFinalTree ) {
392  throw( kinematics::EXCN_InvalidFoldTree( "TopologyBroker failed to make a final_fold-tree in 1 attempts ", *final_fold_tree_ ) );
393  }
394  for ( Size i = 1; i <= n_non_removed; ++i ) {
395  final_fold_tree_->set_jump_atoms( i, after_loops_jumps( 1,i), after_loops_jump_atoms(1,i), after_loops_jumps( 2,i ), after_loops_jump_atoms(2,i) );
396  }
397  final_fold_tree_->put_jump_stubs_intra_residue();
398 }
399 
401  DofClaims failures;
402  sequence_claims_.clear();
403  std::set< std::string > labels; //for now sequence-claims define continuous patches. they are moveable if pos(1)==0.
404 
405  //first round add those with pos(1) != 0
406  for ( DofClaims::iterator claim=claims.begin(); claim != claims.end(); ++claim ) {
407  if ( (*claim)->type() == DofClaim::SEQUENCE ) {
408  SequenceClaimOP seq_claim = dynamic_cast< SequenceClaim* >( claim->get() );
409  if ( seq_claim->pos( 1 ) ) {
410  sequence_claims_.push_back( seq_claim );
411  }
412  }
413  }
414 
415  //first round add those with pos(1) == 0
416  for ( DofClaims::iterator claim=claims.begin(); claim != claims.end(); ++claim ) {
417  if ( (*claim)->type() == DofClaim::SEQUENCE ) {
418  SequenceClaimOP seq_claim = dynamic_cast< SequenceClaim* >( claim->get() );
419  if ( seq_claim->pos( 1 ) == 0 ) {
420  sequence_claims_.push_back( seq_claim );
421  }
422  }
423  }
424 
425  core::Size nres( 0 );
426  for ( SequenceClaims::iterator seq_claim_it =sequence_claims_.begin(); seq_claim_it != sequence_claims_.end(); ++seq_claim_it ) {
427  (*seq_claim_it)->set_offset( nres + 1 );
428  nres += (*seq_claim_it)->pos( 2 );
429  if ( (*seq_claim_it)->pos( 2 ) ) { //it actually provides sequence and is not a query
430  //check label is unique
431  tr.Debug << "found SequenceClaim labelled: " << (*seq_claim_it)->label() << std::endl;
432  if ( labels.find( (*seq_claim_it)->label() ) == labels.end() ) {
433  labels.insert( (*seq_claim_it)->label() );
434  } else {
435  throw EXCN_Input( "found duplicate sequence label "+(*seq_claim_it)->label() );
436  }
437  }
438  }
439 
440  for ( SequenceClaims::iterator claim = sequence_claims_.begin(); claim != sequence_claims_.end(); ++claim ) {
441  (*claim)->owner()->initialize_residues( new_pose, *claim, failures );
442  }
443 
444  runtime_assert( failures.size() == 0 );
445 }
446 
447 ///@brief get the sequence claim that is consistent with the label,
448 /// throws EXCN_Unknown_SequenceLabel if not found
450  SequenceClaimOP found(NULL);
451  for ( SequenceClaims::const_iterator claim = sequence_claims_.begin(); claim != sequence_claims_.end(); ++claim ) {
452  if ( (*claim)->label() == label ) {
453  runtime_assert( !found ); //don't allow duplicate labels -- input is checked when this list is made
454  found = *claim;
455  }
456  }
457  if ( !found ) throw EXCN_Unknown( "requested SequenceLabel " + label + " not found " );
458  return *found;
459 }
460 
462  return resolve_sequence_label( chain_label ).offset() + pos - 1;
463 }
464 
466  DofClaims bb_claims( pose.total_residue(), NULL ); //one claim per position
467  DofClaims jumps( pose.num_jump(), NULL );
468  for ( DofClaims::iterator claim = claims.begin(); claim != claims.end(); ++claim ) {
469  if ( (*claim)->type() == DofClaim::BB ) {
470  //BBClaimOP bb_claim = dynamic_cast< BBClaim* >( claim->get() );
471  DofClaimOP bb_claim = *claim;
472  Size pos = bb_claim->pos( 1 );
473  if ( pos > pose.total_residue() ) throw EXCN_BadInput( "attempt to initialize dof "+string_of( pos ) +
474  " in "+string_of( pose.total_residue() ) + " pose. ... fragments inconsistent with fasta ? " );
475  if ( !bb_claims[ pos ] || bb_claims[ pos ]->right() < bb_claim->right() ) {
476  bb_claims[ pos ] = bb_claim;
477  } else runtime_assert( bb_claim->right() < DofClaim::EXCLUSIVE );
478  } else if ( (*claim)->type() == DofClaim::JUMP ) {
479  //JumpClaimOP jump = dynamic_cast< JumpClaim* >( claim->get() );
480  DofClaimOP jump = *claim;
481  Size jump_nr ( pose.fold_tree().jump_nr( jump->pos( 1 ), jump->pos( 2 ) ) );
482  runtime_assert( jump_nr ); //XOR would be even better
483  DofClaimOP already ( jumps[ jump_nr ] ); //one of them is 0 -- neutral to addition
484  if ( !already || already->right() < jump->right() ) {
485  jumps[ jump_nr ] = jump;
486  } else runtime_assert( jump->right() < DofClaim::EXCLUSIVE );
487  }
488  }
489 
490  if ( tr.Trace.visible() ) tr.Trace << "init-bb-dofs\n " << bb_claims << " init-jump-dofs\n" << jumps << std::endl;
491 
492  //check for un-initialized dofs and throw exception with dof_msg if not fully covered
493  std::ostringstream dof_msg;
494  bool bad( false );
495  Size pos( 1 );
496  for ( DofClaims::const_iterator it = bb_claims.begin(); it != bb_claims.end(); ++it, ++pos ) {
497  if ( !*it ) {
498  //throw exception later, but first accumulate all errors in dof_msg
499  bad = true;
500  dof_msg << "BBTorsion at pos " << pos << "unitialized...unclaimed" << std::endl;
501  }
502  }
503 
504  //check for un-initialized dofs
505  for ( DofClaims::const_iterator it = jumps.begin(); it != jumps.end(); ++it ) {
506  if ( !*it ) {
507  bad = true;
508  dof_msg << "Jump unitialized... " << *it << std::endl;
509  bool bUnitializedJump = true;
510  runtime_assert( !bUnitializedJump );
511  }
512  }
513  if ( bad ) throw( EXCN_Input( dof_msg.str() ) );
514 
515  DofClaims cumulated;
516  std::copy( bb_claims.begin(), bb_claims.end(), back_inserter( cumulated ) );
517  std::copy( jumps.begin(), jumps.end(), back_inserter( cumulated ) );
518 
519  DofClaims failures;
520  for ( TopologyClaimers::iterator top = claimers_.begin();
521  top != claimers_.end(); ++top ) {
522  (*top)->initialize_dofs( pose, cumulated, failures );
523  }
524 
525  if ( failures.size() ) {
526  std::ostringstream dof_msg;
527  dof_msg << "failed to initialize dofs for these claims: .... " << failures << std::endl;
528  throw EXCN_Unknown( dof_msg.str() );
529  }
530  runtime_assert( failures.size() == 0 ); //should have thrown exception before -- Exception
531 }
532 
534  //cuts will contain NULL for automatic cutpoints
535  //and the fold-tree cut-point nr for those which we keep since they have been CUT-Claimed
536  DofClaims cuts( pose.num_jump(), NULL );
537  for ( DofClaims::iterator claim = claims.begin(); claim != claims.end(); ++claim ) {
538  if ( (*claim)->type() == DofClaim::CUT ) {
539  //DofClaimOP cut = dynamic_cast< JumpClaim* >( claim->get() );
540  DofClaimOP cut = *claim;
541  Size cut_nr ( pose.fold_tree().cutpoint_map( cut->pos( 1 ) ) );
542  // we allow cuts without claim -- random cuts due to jumping ...
543  // but if there was a CUT claim, there should be a cut
544  runtime_assert( cut_nr );
545  cuts[ cut_nr ] = cut;
546  //NOTE in principle we could support mutiple CUT claims at the same position... if they all just want a cut there.
547  // maybe need to allow keeping of multiple DofClaims per cutpoint in the list... if the list is actully ever needed.
548  // we assume a DofClaim::CUT will never be closed.. of course we could also change that... then however, the rights will play a role.
549  }
550  }
551 
552  //find the unclaimed -- automatic -- cutpoints
553  to_be_closed_cuts_.clear();
554  for ( Size cut_nr = 1; cut_nr<=cuts.size(); ++cut_nr ) {
555  if ( !cuts[ cut_nr ] ) { //automatic cut-point
556  to_be_closed_cuts_.push_back( pose.fold_tree().cutpoint( cut_nr ) );
557  tr.Debug << "close this cut: " << to_be_closed_cuts_.back() << std::endl;
558  // for now we assume that these always should get closed --- add cutpoint variants
559  // one could also have Jumpers issue floating CUT claims (without position number)
560  // then their pos will be assigned actual cutpoints at this stage
561 
562  // could also make a new TopologyClaimer --- CutCloser which will handle these extra cutpoints.
563  // but difficult to remove the CutCloser from the list of TopologyClaimers before the next decoy
564 
565  //in principle we want to maintain a list of chainbreaks that are to be closed
566  //Question: are CUT claims always coding for Cutpoints that shall not be closed ?
567  // so far I see it that way...
568  }
569  }
570 }
571 
573  DofClaims pre_accepted;
574  bool ok( true );
575 
576  for ( TopologyClaimers::iterator top = claimers_.begin();
577  top != claimers_.end(); ++top ) {
578  if ( bUseJobPose_ ) {
579  (*top)->new_decoy( pose );
580  } else {
581  (*top)->new_decoy();
582  }
583  }
584 
585  start_pose_cuts_.clear();
586  if ( bUseJobPose_ ) {
587  for ( Size i(1), cutpoints(pose.fold_tree().num_cutpoint()); i<=cutpoints; i++ ) {
588  start_pose_cuts_.push_back( pose.fold_tree().cutpoint( i ) );
589  }
590  }
591 
592  pose.clear(); //yay!
593 
594  if ( pose::symmetry::is_symmetric( pose ) ) {
596  }
597 
598  tr.Debug << "Initialize Sequence" << std::endl;
599  DofClaims fresh_claims;
600 
601  sequence_claims_.clear();
602  generate_sequence_claims( fresh_claims );
603  if ( ok ) ok = broking( fresh_claims, pre_accepted );
604  initialize_sequence( pre_accepted, pose );
605  current_pose_ = new core::pose::Pose( pose );
606 
607  tr.Debug << "Start Round1-Broking..." << std::endl;
608  DofClaims round1_claims;
609  generate_round1( round1_claims );
610  if ( ok ) ok = broking( round1_claims, pre_accepted );
611 
612  tr.Debug << "Start FinalRound-Broking..." << std::endl;
613  DofClaims final_claims;
614  generate_final_claims( final_claims );
615  if ( ok ) ok = broking( final_claims, pre_accepted );
616 
617  tr.Debug << "Broking finished" << std::endl;
618  // --> now we know nres
619  // if ( tr.Debug.visible() ) pose.dump_pdb( "init_seq.pdb" );
620  current_pose_ = new core::pose::Pose( pose );
621 
622  tr.Debug << "build fold-tree..." << std::endl;
623  build_fold_tree( pre_accepted, pose.total_residue() );
624  accept_claims( pre_accepted );
625  tr.Debug << *fold_tree_ << std::endl;
626  pose.fold_tree( *fold_tree_ );
627 
628  tr.Debug << "set cuts..." << std::endl;
629  initialize_cuts( pre_accepted, pose );
630 
631  tr.Debug << "initialize dofs..." << std::endl;
632  initialize_dofs( pre_accepted, pose );
633  // if ( tr.Debug.visible() ) pose.dump_pdb( "init_dofs.pdb" );
634  current_pose_ = new core::pose::Pose( pose );
635 
636  //we will need this one in switch_to_fullatom
638 
639  // initialize secondary structure from DSSP.
640  core::scoring::dssp::Dssp dssp_obj( pose );
641  dssp_obj.insert_ss_into_pose( pose );
642 
643  // Fix disulfides if a file is given
644  if ( basic::options::option[ basic::options::OptionKeys::in::fix_disulf ].user() ) {
645  io::raw_data::DisulfideFile ds_file( basic::options::option[ basic::options::OptionKeys::in::fix_disulf ]() );
647  ds_file.disulfides(disulfides, pose);
648  pose.conformation().fix_disulfides( disulfides );
649  }
650 
651  add_chainbreak_variants( pose, 0 /*ignored*/, NULL /*no sequence separation switch*/ );
652 
653  //add constraints
654  add_constraints( pose );
655 }
656 
658  return to_be_closed_cuts_.size();
659 }
660 
662  pose::Pose &pose,
663  Size max_dist,
665 ) const {
666  pose::Pose init_pose = pose;
668  it != to_be_closed_cuts_.end(); ++it ) {
669  tr.Debug << "consider cut between res " << *it << " and " << *it+1;
670  if ( sp ) tr.Debug << " distance is " << sp->dist( *it, *it+1 ) << " of max " << sp->max_dist();
671  tr.Debug << " (" << max_dist << ")"<< std::endl;
672  if ( sp && max_dist && sp->dist( *it, *it+1 ) > max_dist ) continue;
673  if ( !pose.fold_tree().is_cutpoint( *it ) ){
674  continue; //maybe we are in full-atom mode, or have some of chainbreaks already closed... ?
675  }
676  tr.Debug << "add chainbreak variant to residues " << *it << " and " << *it+1 << std::endl;
679  }
680  pose.constraint_set( init_pose.constraint_set()->remapped_clone( init_pose, pose ) );
681 }
682 
684  pose::Pose &pose
685 ) const {
686  bool success ( true );
688  it != to_be_closed_cuts_.end(); ++it ) {
689  tr.Debug << "consider cut between res " << *it << " and " << *it+1 << std::endl;
690  if ( !pose.fold_tree().is_cutpoint( *it ) ){
691  throw( kinematics::EXCN_InvalidFoldTree( "Foldtree missmatch", pose.fold_tree() ) );
692  }
694  && pose.residue( *it+1 ).has_variant_type( chemical::CUTPOINT_UPPER ) ) {
695  tr.Debug << "found chainbreak variant at residues " << *it << " and " << *it+1 << std::endl;
696  } else {
697  tr.Warning << "[WARNING] no chainbreak variant found at residues " << *it << " and " << *it+1 << std::endl;
698  tr.Warning << jd2::current_output_name() << std::endl;
699  tr.Warning << pose.fold_tree() << std::endl;
700  tr.Warning << pose.annotated_sequence() << std::endl;
701  success = false;
702  }
703  }
704  return success;
705 }
706 
707 ///@brief if some claimer wants to influence the movemap for relax he can do it here:
709  for ( TopologyClaimers::const_iterator top = claimers_.begin();
710  top != claimers_.end(); ++top ) {
711  (*top)->adjust_relax_movemap( mm );
712  }
713 
714 }
715 
717  pose::Pose init_pose = pose;
718  std::string sequence_old( pose.annotated_sequence() );
719  tr.Debug << "switch_to_fullatom... " << std::endl;
720 
721  if ( !pose.is_fullatom() ) {
723  }
724 
725  tr.Debug << "switched to fullatom... " << std::endl;
726 
727  utility::vector1< bool > needToRepack( pose.total_residue(), true );
728  for ( TopologyClaimers::const_iterator top = claimers_.begin();
729  top != claimers_.end(); ++top ) {
730  (*top)->switch_to_fullatom( pose, needToRepack );
731  } //this might copy residue-sidechains ... need to have 'disulf' stuff afterwards.
732  tr.Debug << "broker switch to fullatom... " << std::endl;
733 
734  if ( basic::options::option[ basic::options::OptionKeys::in::detect_disulf ]() ) {
735  //disulfide stuff .... do already on the centroid level ? --- that will triger the rebuild disulfides in swtich_to_residye_type_set
737  }
738 
739  // Fix disulfides if a file is given --- in a claimer? ... a util.cc function() ?
740  if ( basic::options::option[ basic::options::OptionKeys::in::fix_disulf ].user() ) {
741  io::raw_data::DisulfideFile ds_file( basic::options::option[ basic::options::OptionKeys::in::fix_disulf ]() );
743  ds_file.disulfides(disulfides, pose);
744  pose.conformation().fix_disulfides( disulfides );
745  }
746 
747  pose.conformation().detect_bonds();//apl fix this !
748 
749  tr.Debug << "detect bonds... " << std::endl;
750 
751  //sanity check
752  std::string sequence_new( pose.annotated_sequence() );
753  if ( sequence_old != sequence_new ) {
754  tr.Warning << "[WARNING] switch_to_fullatom changed sequence/variants:\n " <<
755  " before " << sequence_old << "\n after " << sequence_new << std::endl;
756  }
757 
758  // repack loop + missing-density residues
760  taskstd->restrict_to_repacking();
761  taskstd->or_include_current(true);
762  taskstd->restrict_to_residues( needToRepack );
763 
764  add_constraints( pose );
765 
766  // if ( tr.Debug.visible() ) pose.dump_pdb( "before_repack.pdb");
767  if ( tr.Debug.visible() ) pose.constraint_set()->show_numbers( tr.Debug );
768 
770  pack1.apply( pose );
771 
772  // quick SC minimization
774  core::optimization::MinimizerOptions options( "dfpmin_armijo_nonmonotone", 1e-5, true, false );
776  mm->set_bb( false );
777  mm->set_chi( true );
778 
779  if ( pose::symmetry::is_symmetric( pose ) ) {
782  smzr.run( pose, *mm, *repack_scorefxn_, options );
783  } else {
784  mzr.run( pose, *mm, *repack_scorefxn_, options );
785  }
786 
787  tr.Debug << "minimized.. " << std::endl;
788 }
789 
790 }
791 }