50 #include <basic/Tracer.hh>
62 #include <ObjexxFCL/FArray1D.hh>
65 #include <ObjexxFCL/string.functions.hh>
66 #include <ObjexxFCL/FArray2D.hh>
69 #include <utility/exit.hh>
76 #include <utility/vector1.hh>
90 static basic::Tracer
TR(
"protocols.swa.stepwise_pose_setup" ) ;
105 moving_res_list_( moving_res_list ),
106 desired_sequence_( desired_sequence ),
108 input_streams_with_residue_info_( input_streams_with_residue_info ),
109 cutpoint_open_( cutpoint_open ),
110 cutpoint_closed_( cutpoint_closed ),
111 is_cutpoint_( desired_sequence_.
size(), false ),
114 virtualize_5prime_phosphates_( true ),
115 add_peptide_plane_variants_( false ),
116 remove_nterminus_variant_( false ),
117 remove_cterminus_variant_( false ),
120 ready_to_align_( false ),
145 return "StepWisePoseSetup";
153 using namespace core::pose;
154 using namespace core::kinematics;
155 using namespace core::chemical;
235 std::map< core::Size, core::Size > full_to_sub;
241 ObjexxFCL::FArray1D< Size > is_working_res( nres );
242 ObjexxFCL::FArray1D< Size > is_moving_res( nres );
249 for (
Size n = 1; n <= input_res_vector.size(); n++ ) {
250 is_working_res( input_res_vector[ n ] ) = i;
266 Size start_chain( 0 );
270 for (
Size pos = 1; pos <= nres; pos++ ) {
272 if ( !is_working_res( pos ) )
continue;
275 if ( n == 1 ) start_chain = pos;
278 ( pos > end_chain + 1 ||
281 chain_boundaries.push_back( std::make_pair( start_chain, end_chain ) );
292 assert( start_chain > 0 );
293 chain_boundaries.push_back( std::make_pair( start_chain, end_chain ) );
303 working_sequence=
"";
308 if ( is_working_res( i ) ) {
311 full_to_sub[ i ] = count;
312 working_res_list.push_back( i );
317 std::cout <<
"working_sequence= " << working_sequence << std::endl;
321 if ( is_working_res( i ) && is_moving_res( i ) ){
322 working_moving_res_list.push_back(full_to_sub[ i ]);
329 job_parameters_->set_working_moving_res_list( working_moving_res_list );
348 std::map< core::Size, core::Size > & full_to_sub(
job_parameters_->full_to_sub() );
349 ObjexxFCL::FArray1D< Size >
const & is_working_res =
job_parameters_->is_working_res();
351 Size const num_chains( chain_boundaries.size() );
361 for (
Size n = 1; n <= working_jump_res.size() /2; n++ ){
362 Size const i = working_jump_res[ 2*(n-1) + 1 ];
363 Size const j = working_jump_res[ 2*(n-1) + 2 ];
364 potential_jump_partners.push_back( std::make_pair( i, j) );
370 for (
Size n = 1 ; n <= num_chains; n++ ) {
372 Size const i = chain_boundaries[n].second;
373 Size const j = n < num_chains ? chain_boundaries[n+1].first : chain_boundaries[1].first;
378 std::cout <<
"CHAIN " << n <<
". Considering jump: " << i <<
" to " << j <<
". WORKING_RES: " << is_working_res(i) <<
" " << is_working_res(j) << std::endl;
379 if ( is_working_res( i ) == 1 &&
380 is_working_res( j ) == 2 )
continue;
381 if ( is_working_res( j ) == 1 &&
382 is_working_res( i ) == 2 )
continue;
383 if ( is_working_res( i ) ==
BRIDGE_RES_ )
continue;
384 if ( is_working_res( j ) ==
BRIDGE_RES_ )
continue;
386 std::cout <<
"Adding potential jump! " << std::endl;
388 std::pair< Size, Size > jump_pair = std::make_pair( full_to_sub[ i ], full_to_sub[ j ] );
390 potential_jump_partners.push_back( jump_pair );
392 potential_jump_partners_low_priority.push_back( jump_pair );
397 for (
Size n = 1; n <= potential_jump_partners_low_priority.size(); n++ ) {
398 potential_jump_partners.push_back( potential_jump_partners_low_priority[ n ] );
403 for (
Size n = 1; n <= potential_jump_partners.size(); n++ ) {
404 potential_chain_partners.push_back( std::make_pair(
which_chain( potential_jump_partners[n].first ),
405 which_chain( potential_jump_partners[n].second ) ) );
406 std::cout <<
"POTENTIAL JUMPS: " << potential_jump_partners[n].first <<
" "
407 << potential_jump_partners[n].second <<
" chain: "
408 <<
which_chain( potential_jump_partners[n].first ) <<
' '
409 <<
which_chain( potential_jump_partners[n].second ) << std::endl;
420 while ( chain_partners.size() < (num_chains-1) && ntries++ < 10000 ){
421 for (
Size n = 1; n <= potential_jump_partners.size(); n++ ){
422 std::cout <<
"Going to test jump: " << potential_jump_partners[ n ].first <<
" "
423 << potential_jump_partners[ n ].second <<
"? " <<
already_connected( potential_chain_partners[ n ], chain_partners ) << std::endl;
425 if (
already_connected( potential_chain_partners[ n ], chain_partners ) )
continue;
426 chain_partners.push_back( potential_chain_partners[ n ] );
428 std::cout <<
"ADDING JUMP: " << potential_jump_partners[n].first <<
' ' << potential_jump_partners[n].second << std::endl;
433 if ( chain_partners.size() != (num_chains-1) ) utility_exit_with_message(
"Problem setting up jump partners!" );
442 std::map< core::Size, core::Size > & full_to_sub(
job_parameters_->full_to_sub() );
444 for (
Size n = 1; n <= chain_boundaries.size(); n++ ){
445 if ( full_to_sub[ chain_boundaries[n].first ] <= i &&
446 full_to_sub[ chain_boundaries[n].second ] >= i )
return n;
454 utility::vector1< std::pair< Size, Size > >
const & chain_partners )
const {
457 return already_connected( potential_chain_partner.first, potential_chain_partner.second, chain_partners, already_checked );
463 Size const stop_chain,
467 bool made_the_connection(
false );
468 for (
Size n = 1; n <= chain_partners.size(); n++ ) {
470 if ( already_checked[ n ] )
continue;
472 Size other_chain( 0 );
473 if ( chain_partners[n].first == start_chain ){
474 other_chain = chain_partners[ n ].second;
476 if ( chain_partners[n].second == start_chain ){
477 other_chain = chain_partners[ n ].first;
479 if ( other_chain < 1 )
continue;
481 if ( other_chain == stop_chain ){
482 made_the_connection =
true;
485 already_checked_new[ n ] =
true;
486 made_the_connection =
already_connected( other_chain, stop_chain, chain_partners, already_checked_new );
489 if ( made_the_connection )
return true;
504 std::map< core::Size, core::Size > & full_to_sub(
job_parameters_->full_to_sub() );
505 Size const num_chains = chain_boundaries.size();
507 for (
Size n = 1; n < num_chains; n++ ) {
508 cuts_.push_back( full_to_sub[ chain_boundaries[n].second ] );
530 using namespace core::conformation;
531 using namespace core::scoring::constraints;
547 ObjexxFCL::FArray1D< Size >
const & is_working_res =
job_parameters_->is_working_res();
549 for (
Size n = 1; n <= pose.
total_residue(); n++ )
if ( is_working_res( n ) ) working_res_list.push_back( n );
558 ObjexxFCL::FArray2D< int > jump_point( 2, num_cuts, 0 );
559 ObjexxFCL::FArray1D< int > cuts( num_cuts, 0 );
561 for (
Size i = 1; i <= num_cuts; i++ ) {
563 std::cout <<
" Downstream jump_point= " <<
jump_partners_[i].second;
564 std::cout <<
" cut_point= " <<
cuts_[ i ] << std::endl;
568 cuts( i ) =
cuts_[ i ];
575 f.tree_from_jumps_and_cuts( nres, num_cuts, jump_point, cuts );
577 for (
Size i = 1; i <= num_cuts; i++ ) {
578 Size const k = f.upstream_jump_residue( i );
579 Size const m = f.downstream_jump_residue( i );
584 bool const KeepStubInResidue(
true );
589 f.reassign_atoms_for_intra_residue_stubs();
610 std::map< core::Size, core::Size > & full_to_sub(
job_parameters_->full_to_sub() );
611 ObjexxFCL::FArray1D< Size >
const & is_working_res =
job_parameters_->is_working_res();
615 for (
Size n = 1; n <= disulf_bonds.size(); n++ ){
617 if ( is_working_res( disulf_bonds[n].first )>0 &&
618 is_working_res( disulf_bonds[n].second )>0 ){
620 std::cout <<
"FOUND PAIR: " << disulf_bonds[n].first <<
"--" << disulf_bonds[n].second <<
"[in subpose: " << full_to_sub[ disulf_bonds[n].first ] <<
"--" << full_to_sub[ disulf_bonds[n].second ] <<
"]" << std::endl;
622 working_disulf_bonds.push_back( std::make_pair( full_to_sub[ disulf_bonds[n].first ], full_to_sub[ disulf_bonds[n].second ] ) );
628 std::cout << std::endl;
640 if (rsd.
is_RNA() )
return " C4*";
644 utility_exit_with_message(
"Cannot deal with pose that is not RNA or protein yet." );
652 using namespace core::scoring::constraints;
669 full_pose.constraint_set(
cst_set_ );
670 (*scorefxn)( full_pose );
687 for (
Size n = 1; n <= nres; n++ ) {
706 assert( slice_res.size() == input_res.size() );
707 std::map< core::Size, core::Size > & full_to_sub(
job_parameters_->full_to_sub() );
709 for (
Size n = 1; n <= input_res.size(); n++ ) {
740 std::map< core::Size, core::Size > & full_to_sub(
job_parameters_->full_to_sub() );
742 for (
Size n = 1; n <= input_res.size(); n++ ) {
743 if (!import_pose.
residue( slice_res[ n ] ).
is_RNA())
continue;
744 pose.
set_chi( 1, full_to_sub[ input_res[ n ] ], import_pose.
chi( 1, slice_res[n] ) );
754 using namespace core::chemical;
763 bool align_pose_to_import_pose(
true );
768 if ( i > 1) align_pose_to_import_pose =
false;
774 stream->copy_next_pose_segment( pose, import_pose,
true , align_pose_to_import_pose );
777 copy_rna_chi( pose, import_pose, stream->input_res(), stream->slice_res() );
779 if (
dump_) pose.
dump_pdb(
"after_copy_dofs"+ObjexxFCL::string_of(i)+
".pdb" );
780 if (
dump_) import_pose.dump_pdb(
"import"+ObjexxFCL::string_of(i)+
".pdb" );
792 ObjexxFCL::FArray1D_bool partition_definition( pose.
total_residue(), false );
799 if ( moving_res_list.size() > 0 ){
801 Size partition_res( 0 );
802 if ( (moving_suite_list.size() > 0 &&
803 moving_suite_list[ 1 ] == (moving_res_list[ 1 ]-1) ) ||
804 ( moving_res_list[1] > 1 &&
805 moving_res_list[ moving_res_list.size() ] == pose.
total_residue() ) ){
806 partition_res = moving_res_list[ 1 ] - 1;
808 partition_res = moving_res_list[ moving_res_list.size() ];
810 std::cout <<
"PARTITION_RES ==> " << partition_res << std::endl;
814 std::cout <<
"PARTITION_DEFINITION ==> ";
815 for (
Size i = 1; i <= pose.
total_residue(); i++ ) std::cout << partition_definition( i );
816 std::cout << std::endl;
817 std::cout <<
"FOLD_TREE " << pose.
fold_tree() << std::endl;
822 if ( moving_res_list.size() == 0 )
return;
824 bool const start_partition = partition_definition( moving_res_list[ 1 ] );
831 ObjexxFCL::FArray1D< Size >
const & is_moving_res(
job_parameters_->is_moving_res() );
832 std::map< core::Size, core::Size > & sub_to_full(
job_parameters_->sub_to_full() );
834 if ( is_moving_res( sub_to_full[ i ] ) )
continue;
835 if ( partition_definition( i ) == start_partition ){
852 if ( moving_res_list.size() < 1 )
return;
854 ObjexxFCL::FArray1D< bool >
const & partition_definition =
job_parameters_->partition_definition();
858 Size num_partition_0( 0 ), num_partition_1( 0 );
859 Size possible_new_root_residue_in_partition_0( 0 ), possible_new_root_residue_in_partition_1( 0 ), root_res( 0 );
861 for (
Size n = 1; n <= nres; n++ ) {
862 if( partition_definition( n ) ) {
863 num_partition_1 += 1;
866 num_partition_0 += 1;
874 for(
Size i=1; i<=working_fixed_res.size(); i++){
875 Size const seq_num = working_fixed_res[i];
877 possible_new_root_residue_in_partition_1= seq_num;
882 for(
Size i=1; i<=working_fixed_res.size(); i++){
883 Size const seq_num = working_fixed_res[i];
885 possible_new_root_residue_in_partition_0= seq_num;
894 Size const moving_res( moving_res_list[1] );
897 if ( num_partition_1 >= num_partition_0 ){
899 if ( partition_definition( 1 ) && partition_definition( nres ) ) {
902 root_res = possible_new_root_residue_in_partition_1;
905 if ( !partition_definition( 1 ) && !partition_definition( nres )) {
908 root_res = possible_new_root_residue_in_partition_0;
914 if ( partition_definition( moving_res ) ){
915 root_res = possible_new_root_residue_in_partition_0;
918 root_res = possible_new_root_residue_in_partition_1;
923 if ( root_res == 0 ) root_res = 1;
925 std::cout <<
"Num. res in partition 0: " << num_partition_0 <<
". Num. res in partition 1: " << num_partition_1 <<
926 ". Moving_res is in partition " << partition_definition( moving_res ) <<
927 ". New root residue " << root_res << std::endl;
929 assert( root_res > 0 );
931 bool reorder_went_OK = f.
reorder( root_res );
932 runtime_assert( reorder_went_OK );
938 bool const root_partition = partition_definition( pose.
fold_tree().
root() );
940 if ( partition_definition( seq_num ) != root_partition ) moving_positions.push_back( seq_num );
950 if ( working_moving_suite_list.size() < 1 )
return;
951 Size const first_moving_suite = working_moving_suite_list[ 1 ];
954 if ( partition_definition( first_moving_suite ) == partition_definition( root_res ) ){
961 bool const should_be_prepend = ( partition_definition( first_moving_suite ) != partition_definition( root_res ) );
965 ObjexxFCL::FArray1D< Size >
const & is_working_res(
job_parameters_->is_working_res() );
966 ObjexxFCL::FArray1D< Size >
const & is_moving_res(
job_parameters_->is_moving_res() );
969 if ( is_working_res( i ) && !is_moving_res( i ) ) {
975 std::cout <<
" Is_prepend: " <<
job_parameters_->Is_prepend() << std::endl;
976 std::cout <<
" should_be_prepend: " << should_be_prepend << std::endl;
977 std::cout <<
" first_moving_suite: " << first_moving_suite <<
" partition: " << partition_definition( first_moving_suite ) << std::endl;
978 std::cout <<
" root_res: " << root_res <<
" partition: " << partition_definition( root_res ) << std::endl;
979 utility_exit_with_message(
"Possible problem with prepend/append assignment!!" );
1001 ObjexxFCL::FArray1D< bool >
const & partition_definition =
job_parameters_->partition_definition();
1002 ObjexxFCL::FArray1D< Size >
const & is_working_res =
job_parameters_->is_working_res();
1005 std::map< core::Size, core::Size > & full_to_sub(
job_parameters_->full_to_sub() );
1006 Size found_moving_gap( 0 );
1007 Size const num_chains = chain_boundaries.size();
1008 for (
Size n = 1; n < num_chains; n++ ) {
1009 Size chain_end = chain_boundaries[ n ].second;
1010 Size next_chain_start = chain_boundaries[ n+1 ].first;
1012 std::cout <<
"CHECK_CHAIN --> " << chain_end <<
' ' << partition_definition( full_to_sub[ chain_end ] ) <<
' ' << next_chain_start <<
' ' << partition_definition( full_to_sub[ next_chain_start ] ) << std::endl;
1014 if ( partition_definition( full_to_sub[ chain_end ] ) !=
1015 partition_definition( full_to_sub[ next_chain_start ] ) ||
1017 ( is_working_res( next_chain_start ) ==
BRIDGE_RES_ ) ){
1019 bool found_cutpoint_open(
false );
1022 found_cutpoint_open =
true;
1026 if ( found_cutpoint_open )
continue;
1028 std::cout <<
"CUTPOINT CLOSED --> " << chain_end <<
' ' << next_chain_start << std::endl;
1030 job_parameters_->set_first_chain_break_res( full_to_sub[ chain_end ] );
1036 if ( found_moving_gap > 1 ){
1037 std::cout <<
"WARNING: Had trouble figure out which gap might be the one to close! Try to renumber input poses sequentially." << std::endl;
1046 using namespace core::id;
1050 pose_copy.fold_tree( f_simple );
1052 std::map< core::Size, core::Size > & full_to_sub(
job_parameters_->full_to_sub() );
1058 if ( full_to_sub.find( cutpoint ) != full_to_sub.end() &&
1059 full_to_sub.find( cutpoint+1 ) != full_to_sub.end() ) {
1061 Size const cutpos = full_to_sub[ cutpoint ];
1070 std::cout <<
"Applied cutpoint variants to " << cutpoint << std::endl;
1072 for (
Size i = cutpos; i <= cutpos + 1; i++ ){
1074 for (
Size j = 1; j <= mainchain_torsions.size(); j++ ) {
1077 pose.
set_torsion( torsion_id, mainchain_torsions[ j ] );
1092 using namespace core::conformation;
1093 using namespace core::pose;
1095 ObjexxFCL::FArray1D< Size >
const & is_working_res(
job_parameters_->is_working_res() );
1096 std::map< core::Size, core::Size > & full_to_sub(
job_parameters_->full_to_sub() );
1099 if ( !is_working_res(
bulge_res_[ n ] ) )
continue;
1111 using namespace core::conformation;
1112 using namespace core::pose;
1129 utility_exit_with_message(
"mismatch --> gap_size = 0, but no cutpoint variants defined?" );
1144 ObjexxFCL::FArray1D< bool >
const & partition_definition =
job_parameters_->partition_definition();
1146 bool const root_partition = partition_definition( pose.
fold_tree().
root() );
1148 for (
Size i = 1; i <= working_superimpose_res.size(); i++ ) {
1149 if ( !
Contain_seq_num( working_superimpose_res[ i ], working_fixed_res ) ){
1150 std::cout <<
"working superimpose_res " << working_superimpose_res[ i] <<
" not in fixed_res? " << std::endl;
1151 utility_exit_with_message(
"You will get weird results if superimpose_res residues are allowed to move!" );
1153 if ( !partition_definition( working_superimpose_res[ i ] ) == root_partition ) {
1154 std::cout <<
"working_superimpose_res " << working_superimpose_res[ i ] << std::endl;
1155 utility_exit_with_message(
"Superimpose_res residues need to end up in root paritition and stay fixed!" );
1165 using namespace core::pose;
1166 using namespace core::conformation;
1168 working_pose =
Pose();
1170 ObjexxFCL::FArray1D< Size >
const & is_working_res(
job_parameters_->is_working_res() );
1173 Pose full_pose_copy = pose;
1176 for (
Size i = 1; i <= full_pose_copy.total_residue(); i++ ) {
1177 if ( !is_working_res( i ) )
continue;
1179 ResidueOP residue_to_add = full_pose_copy.residue( i ).clone() ;
1181 if ( i > 1 && residue_to_add->is_lower_terminus() ) {
1202 using namespace core::conformation;
1203 using namespace core::pose;
1204 using namespace protocols::rna;
1208 std::cout <<
"NATIVE sequence: " <<
get_native_pose()->annotated_sequence(
true ) << std::endl;
1221 Pose full_align_pose;
1227 std::cout <<
"PoseSetup: Align to file: " <<
align_file_ << std::endl;
1234 std::cout <<
"PoseSetup: Align to NATIVE" << std::endl;
1238 std::cout <<
"PoseSetup: Do not do any alignment." << std::endl;
1251 if ( superimpose_res.size() == 0 ){
1252 for (
Size i = 1; i <= pose.
total_residue(); i++ ) superimpose_res.push_back( i );
1278 utility_exit_with_message(
"Called align pose, but PoseSetup wasn't ready to do it..." );
1298 if ( working_moving_res_list.size() < 1 )
return;
1300 Size const first_working_moving_res = working_moving_res_list[ 1 ];
1301 Size const last_working_moving_res = working_moving_res_list[ working_moving_res_list.size() ];
1306 bool moving_res_attached_at_start =
true;
1307 bool moving_res_attached_at_end =
true;
1310 if ( first_working_moving_res == 1 ||
1312 moving_res_attached_at_start =
false;
1317 moving_res_attached_at_end =
false;
1327 bool const Is_internal = ( moving_res_attached_at_end && moving_res_attached_at_start );
1331 if ( moving_res_attached_at_start && !Is_internal ){
1332 working_moving_suite_list.push_back( first_working_moving_res - 1 );
1335 for (
Size n = 1; n < working_moving_res_list.size(); n++ ){
1336 working_moving_suite_list.push_back( working_moving_res_list[ n ] );
1339 if ( moving_res_attached_at_end ){
1340 working_moving_suite_list.push_back( last_working_moving_res );
1357 job_parameters_->set_Is_internal( moving_res_attached_at_end && moving_res_attached_at_start );
1360 job_parameters_->set_working_moving_suite_list( working_moving_suite_list );
1386 std::map< core::Size, core::Size > & full_to_sub(
job_parameters_->full_to_sub() );
1388 Size const num_chains = chain_boundaries.size();
1390 for (
Size n = 1; n <= num_chains; n++ ) {
1391 Size const chain_start = chain_boundaries[ n ].first;
1392 Size const potential_five_prime_res = full_to_sub[ chain_start ];
1396 if ( !pose.
residue( potential_five_prime_res ).
is_RNA() )
continue;
1399 utility_exit_with_message(
"Should not be trying to virtualize phosphate on close cutpoint residue!" );
1446 std::map< core::Size, core::Size > & full_to_sub(
job_parameters_->full_to_sub() );
1448 Size const num_chains = chain_boundaries.size();
1450 for (
Size n = 1; n <= num_chains; n++ ) {
1452 Size const chain_start = chain_boundaries[ n ].first;
1453 Size const potential_Nterm_res = full_to_sub[ chain_start ];
1460 Size const chain_end = chain_boundaries[ n ].second;
1461 Size const potential_Cterm_res = full_to_sub[ chain_end ];
1480 using namespace core::id;
1484 std::map< core::Size, core::Size > & full_to_sub(
job_parameters_->full_to_sub() );
1488 if (full_to_sub.find( seq_num ) != full_to_sub.end() ) {
1498 using namespace core::conformation;
1499 using namespace core::id;
1500 using namespace core::scoring::constraints;
1501 using namespace core::scoring::rna;
1511 ObjexxFCL::FArray1D<bool> is_moving_res( nres,
false );
1512 ObjexxFCL::FArray1D<bool> is_fixed_res( nres,
false );
1514 ObjexxFCL::FArray1D< bool >
const & partition_definition =
job_parameters_->partition_definition();
1515 bool const root_partition = partition_definition( pose.
fold_tree().
root() );
1517 for (
Size seq_num=1; seq_num <= nres; seq_num++){
1518 if ( partition_definition( seq_num ) == root_partition ) {
1519 is_fixed_res( seq_num ) =
true;
1521 is_moving_res( seq_num ) =
true;
1528 FuncOP const repulsion_func(
new FadeFunc( -2.0 , DIST_CUTOFF , 1.0 , 100.0 ) );
1530 for (
Size i = 1; i <= working_terminal_res.size(); i++ ) {
1532 Size const k = working_terminal_res[ i ];
1534 for (
Size m = 1; m <= nres; m++ ) {
1543 if ( ( ( is_moving_res( k ) && is_moving_res( m ) ) ||
1544 ( is_fixed_res( k ) && is_fixed_res( m ) ) ) &&
1545 ( pose.
xyz( atom_id1 ) - pose.
xyz( atom_id2 ) ).length() < DIST_CUTOFF ) {
1551 cst_set->add_constraint(
new AtomPairConstraint( atom_id1, atom_id2, repulsion_func ) );
1572 ObjexxFCL::FArray1D< Size >
const & is_working_res(
job_parameters_->is_working_res() );
1576 if (
secstruct_.size() !=
desired_sequence_.size() ) utility_exit_with_message(
"Input secstruct does not have same size as full length sequence" );
1580 if( !is_working_res[ n ] )
continue;