44 #include <basic/options/option.hh>
45 #include <basic/options/keys/in.OptionKeys.gen.hh>
60 #include <ObjexxFCL/FArray1D.hh>
61 #include <ObjexxFCL/FArray2D.hh>
64 #include <basic/Tracer.hh>
75 #include <utility/vector0.hh>
76 #include <utility/vector1.hh>
79 namespace ObjexxFCL { }
using namespace ObjexxFCL;
81 static basic::Tracer
tr(
"protocols.topo_broker", basic::t_info);
84 namespace topology_broker {
86 using namespace utility::excn;
89 TopologyBroker::TopologyBroker() :
92 final_fold_tree_( NULL ),
93 repack_scorefxn_( NULL ),
94 bUseJobPose_( false ),
102 claimers_( tp.claimers_ )
115 if (
this != &src ) {
131 cl->set_broker(
this );
135 for ( TopologyClaimers::iterator top =
claimers_.begin();
137 (*top)->generate_sequence_claims( all_claims );
139 tr.Trace <<
"All sequence claims: \n" << all_claims << std::endl;
143 for ( TopologyClaimers::const_iterator top =
claimers_.begin();
145 if ( msg.
matches( (*top)->label() ) ) {
146 (*top)->receive_message( msg );
152 for ( TopologyClaimers::iterator top =
claimers_.begin();
154 tr.Trace <<
"generate claim for " << (*top)->type() << std::endl;
155 (*top)->generate_claims( all_claims );
157 tr.Trace <<
"All round1 claims: \n" << all_claims << std::endl;
161 for ( TopologyClaimers::iterator top =
claimers_.begin();
163 (*top)->finalize_claims( all_claims );
165 tr.Trace <<
"all final claims: \n " << all_claims << std::endl;
170 for ( TopologyClaimers::const_iterator top =
claimers_.begin();
173 runtime_assert( !(new_frags && frags ) );
174 if ( new_frags ) frags = new_frags;
176 runtime_assert( frags );
177 runtime_assert( !frags->empty() );
183 for ( TopologyClaimers::const_iterator top =
claimers_.begin();
185 (*top)->add_constraints( pose );
187 if (
tr.Trace.visible() ) {
188 tr.Trace <<
"all constraints\n " << std::endl;
190 tr.Trace << std::endl;
200 for ( TopologyClaimers::const_iterator top =
claimers_.begin();
202 (*top)->
add_mover( *random_mover, pose, stage_id, scorefxn, progress );
206 if ( !random_mover->size() ) {
207 tr.Warning <<
"[ WARNING ] no mover returned in stage " << stage_id
208 <<
" progress " << progress << std::endl;
211 runtime_assert( random_mover->size() );
218 tr.Debug <<
"apply filter: \n";
219 for ( TopologyClaimers::const_iterator top =
claimers_.begin();
221 std::ostringstream report;
222 if ( !(*top)->passes_filter( pose, stage_id, progress, report ) ) {
226 if ( report.str().size() )
tr.Debug <<
"CLAIMER " << (*top)->type() <<
":" << (*top)->label() <<
" FILTER REPORT: \n"
233 for ( DofClaims::iterator claim=claims.begin(); claim != claims.end(); ++claim ) {
234 (*claim)->owner()->claim_accepted( *claim );
240 tr.Debug <<
"broking claims..." << std::endl;
242 for ( DofClaims::const_iterator claim = all_claims.begin();
243 claim != all_claims.end() && !fatal; ++claim ) {
245 for ( TopologyClaimers::iterator top =
claimers_.begin();
246 top !=
claimers_.end() && allow; ++top ) {
247 allow = (*top)->allow_claim( **claim );
250 tr.Trace <<
"declined: " << **claim << std::endl;
251 fatal = !(*claim)->owner()->accept_declined_claim( **claim );
253 tr.Trace <<
"accepted: " << **claim << std::endl;
254 pre_accepted.push_back( *claim );
265 for ( DofClaims::iterator claim = seq_claims.begin(); claim != seq_claims.end(); ++claim ) {
266 nres += (*claim)->pos( 2 );
276 std::vector< int > obligate_cut_points;
279 bool excl_root_set(
false );
281 tr.Debug <<
"build fold tree ... " << std::endl;
282 for ( DofClaims::iterator claim=claims.begin(); claim != claims.end(); ++claim ) {
284 if ( (*claim)->exclusive() ) {
285 exclusive_jumps.push_back( *claim );
287 negotiable_jumps.push_back( *claim );
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 ) );
295 if ( ( root && !excl_root_set && (*claim)->exclusive() ) || !root || root == (*claim)->pos( 1 ) ) {
296 root = (*claim)->pos( 1 );
297 excl_root_set = (*claim)->exclusive();
304 if ( !root ) root = 1;
307 for ( TopologyClaimers::iterator top =
claimers_.begin();
309 (*top)->manipulate_cut_bias( cut_bias );
311 ObjexxFCL::FArray1D_float cut_bias_farray( nres );
312 for (
Size i=1; i<=nres; i++ ) cut_bias_farray( i ) = cut_bias[ i ];
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() );
320 Size n_non_removed( 0 );
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 );
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() ) {
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 );
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 );
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 );
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;
358 std::vector< int > obligate_sampling_cut_points( obligate_cut_points );
361 while ( try_again && !bValidTree ) {
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 );
371 std::ostringstream msg;
372 for (
Size i = 1; i<=nexcl+nnegot; ++i ) {
373 msg << jumps(1, i ) <<
" " << jumps(2, i ) << std::endl;
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 ) );
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;
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 ) {
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) );
403 std::set< std::string > labels;
406 for ( DofClaims::iterator claim=claims.begin(); claim != claims.end(); ++claim ) {
409 if ( seq_claim->pos( 1 ) ) {
416 for ( DofClaims::iterator claim=claims.begin(); claim != claims.end(); ++claim ) {
419 if ( seq_claim->pos( 1 ) == 0 ) {
427 (*seq_claim_it)->set_offset( nres + 1 );
428 nres += (*seq_claim_it)->pos( 2 );
429 if ( (*seq_claim_it)->pos( 2 ) ) {
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() );
435 throw EXCN_Input(
"found duplicate sequence label "+(*seq_claim_it)->label() );
441 (*claim)->owner()->initialize_residues( new_pose, *claim, failures );
444 runtime_assert( failures.size() == 0 );
452 if ( (*claim)->label() == label ) {
453 runtime_assert( !found );
457 if ( !found )
throw EXCN_Unknown(
"requested SequenceLabel " + label +
" not found " );
468 for ( DofClaims::iterator claim = claims.begin(); claim != claims.end(); ++claim ) {
472 Size pos = bb_claim->pos( 1 );
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;
482 runtime_assert( jump_nr );
484 if ( !already || already->right() < jump->right() ) {
485 jumps[ jump_nr ] = jump;
490 if (
tr.Trace.visible() )
tr.Trace <<
"init-bb-dofs\n " << bb_claims <<
" init-jump-dofs\n" << jumps << std::endl;
493 std::ostringstream dof_msg;
496 for ( DofClaims::const_iterator it = bb_claims.begin(); it != bb_claims.end(); ++it, ++pos ) {
500 dof_msg <<
"BBTorsion at pos " << pos <<
"unitialized...unclaimed" << std::endl;
505 for ( DofClaims::const_iterator it = jumps.begin(); it != jumps.end(); ++it ) {
508 dof_msg <<
"Jump unitialized... " << *it << std::endl;
509 bool bUnitializedJump =
true;
510 runtime_assert( !bUnitializedJump );
513 if ( bad )
throw(
EXCN_Input( dof_msg.str() ) );
516 std::copy( bb_claims.begin(), bb_claims.end(), back_inserter( cumulated ) );
517 std::copy( jumps.begin(), jumps.end(), back_inserter( cumulated ) );
520 for ( TopologyClaimers::iterator top =
claimers_.begin();
522 (*top)->initialize_dofs( pose, cumulated, failures );
525 if ( failures.size() ) {
526 std::ostringstream dof_msg;
527 dof_msg <<
"failed to initialize dofs for these claims: .... " << failures << std::endl;
530 runtime_assert( failures.size() == 0 );
537 for ( DofClaims::iterator claim = claims.begin(); claim != claims.end(); ++claim ) {
544 runtime_assert( cut_nr );
545 cuts[ cut_nr ] = cut;
554 for (
Size cut_nr = 1; cut_nr<=cuts.size(); ++cut_nr ) {
555 if ( !cuts[ cut_nr ] ) {
576 for ( TopologyClaimers::iterator top =
claimers_.begin();
579 (*top)->new_decoy( pose );
598 tr.Debug <<
"Initialize Sequence" << std::endl;
603 if ( ok ) ok =
broking( fresh_claims, pre_accepted );
607 tr.Debug <<
"Start Round1-Broking..." << std::endl;
610 if ( ok ) ok =
broking( round1_claims, pre_accepted );
612 tr.Debug <<
"Start FinalRound-Broking..." << std::endl;
615 if ( ok ) ok =
broking( final_claims, pre_accepted );
617 tr.Debug <<
"Broking finished" << std::endl;
622 tr.Debug <<
"build fold-tree..." << std::endl;
628 tr.Debug <<
"set cuts..." << std::endl;
631 tr.Debug <<
"initialize dofs..." << std::endl;
644 if ( basic::options::option[ basic::options::OptionKeys::in::fix_disulf ].user() ) {
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;
676 tr.Debug <<
"add chainbreak variant to residues " << *it <<
" and " << *it+1 << std::endl;
686 bool success (
true );
689 tr.Debug <<
"consider cut between res " << *it <<
" and " << *it+1 << std::endl;
695 tr.Debug <<
"found chainbreak variant at residues " << *it <<
" and " << *it+1 << std::endl;
697 tr.Warning <<
"[WARNING] no chainbreak variant found at residues " << *it <<
" and " << *it+1 << std::endl;
709 for ( TopologyClaimers::const_iterator top =
claimers_.begin();
711 (*top)->adjust_relax_movemap( mm );
719 tr.Debug <<
"switch_to_fullatom... " << std::endl;
725 tr.Debug <<
"switched to fullatom... " << std::endl;
728 for ( TopologyClaimers::const_iterator top =
claimers_.begin();
730 (*top)->switch_to_fullatom( pose, needToRepack );
732 tr.Debug <<
"broker switch to fullatom... " << std::endl;
734 if ( basic::options::option[ basic::options::OptionKeys::in::detect_disulf ]() ) {
740 if ( basic::options::option[ basic::options::OptionKeys::in::fix_disulf ].user() ) {
749 tr.Debug <<
"detect bonds... " << std::endl;
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;
760 taskstd->restrict_to_repacking();
761 taskstd->or_include_current(
true);
762 taskstd->restrict_to_residues( needToRepack );
787 tr.Debug <<
"minimized.. " << std::endl;