46 #include <ObjexxFCL/FArray1D.hh>
47 #include <ObjexxFCL/FArray2D.hh>
48 #include <ObjexxFCL/format.hh>
50 #include <utility/io/izstream.hh>
51 #include <utility/exit.hh>
53 #include <numeric/random/random.hh>
56 #include <basic/Tracer.hh>
64 #include <utility/vector1.hh>
69 namespace ObjexxFCL { }
using namespace ObjexxFCL;
70 namespace ObjexxFCL {
namespace fmt { } }
using namespace ObjexxFCL::fmt;
77 static numeric::random::RandomGenerator
RG(144620);
79 static basic::Tracer
tr(
"protocols.rna.rna_structure_parameters" ) ;
83 RNA_StructureParameters::RNA_StructureParameters():
84 secstruct_defined_( false ),
85 assume_non_stem_is_loop( false ),
86 root_at_first_rigid_body_( false )
98 bool const ignore_secstruct )
124 std::cout <<
"OVER-RIDING SECONDARY STRUCTURE WITH: " <<
rna_secstruct_ << std::endl;
134 std::cout <<
"Current last residue is type: " << pose.
residue( pose.
total_residue() ).name3() << std::endl;
191 if ( rna_pairing.
edge1 ==
'W' &&
192 rna_pairing.
edge2 ==
'W' &&
202 std::cout <<
"Setting desired secondary structure to: " <<
rna_secstruct_ << std::endl;
211 std::list< Size > in_stem;
215 if ( rna_pairing.
edge1 ==
'W' &&
216 rna_pairing.
edge2 ==
'W' &&
220 in_stem.push_back( rna_pairing.
pos1 );
221 in_stem.push_back( rna_pairing.
pos2 );
273 std::istringstream & line_stream,
274 bool const obligate_pairing_set )
283 while ( !line_stream.fail() ) {
285 line_stream >> a >>
b ;
287 if ( line_stream.fail() ) {
288 std::cout <<
"Parse error!!!" << a <<
' ' << b << std::endl;
292 if ( line_stream.fail() || tag ==
"PAIR" ) {
298 line_stream >> e2 >> o;
299 if ( line_stream.fail() ) utility_exit_with_message(
"Problem with PAIR readin: "+tag );
313 utility_exit_with_message(
"Can't base pair a residue with itself: "+I(3,a)+
" "+I(3,b) );
325 if ( !line_stream.fail() && tag !=
"PAIR" ) utility_exit_with_message(
"Problem with PAIR readin: " + tag );
328 if ( obligate_pairing_set ) {
340 Size pos1( 0 ), pos2( 0 ), which_segment( 1 );
344 while ( !line_stream.fail() ) {
347 char checkchar(
' ' );
348 while ( checkchar ==
' ' && !line_stream.fail()) checkchar = line_stream.get();
350 if (line_stream.fail() )
break;
351 line_stream.putback( checkchar );
353 if ( checkchar ==
'S' ) {
356 if ( tag ==
"SEGMENT1" ) {
358 }
else if ( tag ==
"SEGMENT2" ) {
361 utility_exit_with_message(
"Looking for SEGMENT1 or SEGMENT2 in CHAIN_CONNECTION line, but got " + tag );
366 if (!line_stream.fail() ){
367 line_stream >> pos1 >> pos2;
368 runtime_assert( pos2 > pos1 );
369 for (
Size i = pos1; i <= pos2; i++ ){
370 if (which_segment == 1 ) res_list1.push_back( i );
371 if (which_segment == 2 ) res_list2.push_back( i );
377 if ( res_list1.size() == 0 || res_list2.size() == 0 ){
378 utility_exit_with_message(
"Did not specify SEGMENT1 or SEGMENT2 in CHAIN_CONNECTION line?" );
390 tr <<
"Reading RNA parameters file: " << filename << std::endl;
394 utility::io::izstream pairing_stream( filename );
395 if ( !pairing_stream ) {
396 pairing_stream.close();
397 utility_exit_with_message(
"Pairing file? " + filename );
403 while ( getline( pairing_stream, line ) ) {
405 std::istringstream line_stream( line );
408 if (line_stream.fail() )
continue;
410 if (tag ==
"OBLIGATE" ) {
413 if ( line_stream.fail() || tag !=
"PAIR" ) utility_exit_with_message(
"Problem with STEM readin: " + tag );
416 }
else if (tag ==
"STEM" || tag ==
"POSSIBLE" ) {
419 if ( line_stream.fail() || tag !=
"PAIR" ) utility_exit_with_message(
"Problem with STEM readin: " + tag );
422 }
else if (tag ==
"ALLOW_INSERT" ) {
425 while ( !line_stream.fail() ) {
426 line_stream >> pos1 >> pos2;
427 runtime_assert( pos2 >= pos1 );
432 }
else if (tag ==
"ALLOW_INSERT_RES" ) {
435 while ( !line_stream.fail() ) {
441 }
else if (tag ==
"VIRTUAL_ANCHOR" ) {
443 while ( !line_stream.fail() ) {
445 if (!line_stream.fail() ){
451 }
else if (tag ==
"CUTPOINT_CLOSED" ) {
452 while ( !line_stream.fail() ) {
454 if (!line_stream.fail() ){
459 }
else if (tag ==
"CUTPOINT_OPEN" ) {
460 while ( !line_stream.fail() ) {
462 if (!line_stream.fail() ){
467 }
else if (tag ==
"CHAIN_CONNECTION" ) {
471 }
else if (tag ==
"SECSTRUCT" ) {
475 }
else if ( tag[0] ==
'#' ) {
479 utility_exit_with_message(
"Unrecognized tag in pairing file: " + tag );
482 pairing_stream.close();
491 for (
Size n = 1; n <= res_list.size(); n++ ) {
492 if ( res_list[n] == pos )
return true;
503 for (
Size n = 1; n <= num_chain_connections ; n++ ){
507 if (
in_list( pos1, res_list1 ) &&
in_list( pos2, res_list2) )
return n;
508 if (
in_list( pos2, res_list1 ) &&
in_list( pos1, res_list2) )
return n;
519 Size const jump_pos )
const
521 using namespace core::kinematics::tree;
527 id::AtomID const parent_id( current_atom->parent()->id() );
528 std::string const & parent_name( pose.
residue(parent_id.rsd()).atom_name(parent_id.atomno()) );
530 if ( parent_name ==
" P " ) {
540 Size const & which_jump,
541 bool & success )
const
545 Size const jump_pos1( fold_tree.upstream_jump_residue( which_jump ) );
546 Size const jump_pos2( fold_tree.downstream_jump_residue( which_jump ) );
551 char e1(
'W') ,e2(
'W'), o(
'A');
552 bool found_pairing(
false );
556 if (pairing.
pos1 == jump_pos1 && pairing.
pos2 == jump_pos2 ){
560 found_pairing =
true;
564 if (pairing.
pos1 == jump_pos2 && pairing.
pos2 == jump_pos1 ){
568 found_pairing =
true;
576 if (!found_pairing) {
588 utility_exit_with_message(
"Trouble finding foldtree pairing in input pairing list? " + I(3,jump_pos1)+
' '+I(3,jump_pos2) );
601 atom_name1, atom_name2,
603 forward1, forward2 );
607 if (!success)
return;
609 fold_tree.set_jump_atoms( which_jump, atom_name1, atom_name2 );
614 pose.
set_jump( which_jump, new_jump );
625 Size const jump_pos1( fold_tree.upstream_jump_residue( which_jump ) );
626 Size const jump_pos2( fold_tree.downstream_jump_residue( which_jump ) );
631 if ( chain_connection_number < 1 )
return;
638 Size const MAX_TRIES( 1000 );
639 bool success(
false );
642 Size const num_jumps( fold_tree.num_jump() );
643 ObjexxFCL::FArray2D <int> jump_points( 2, num_jumps );
644 ObjexxFCL::FArray1D <int> cuts( num_jumps );
645 for (
Size n = 1; n <= num_jumps; n++ ){
646 jump_points( 1, n ) = fold_tree.jump_point( 1, n );
647 jump_points( 2, n ) = fold_tree.jump_point( 2, n );
648 cuts( n ) = fold_tree.cutpoint( n );
652 Size which_jump_in_list( 0 );
653 for ( which_jump_in_list = 1; which_jump_in_list <= num_jumps; which_jump_in_list++ ){
654 if (
Size( jump_points( 1, which_jump_in_list ) ) == jump_pos1 &&
655 Size( jump_points( 2, which_jump_in_list ) ) == jump_pos2 )
break;
656 if (
Size( jump_points( 1, which_jump_in_list ) ) == jump_pos2 &&
657 Size( jump_points( 2, which_jump_in_list ) ) == jump_pos1 )
break;
659 if (which_jump_in_list > num_jumps ) {
660 utility_exit_with_message(
"Problem with fold tree change --> Jump " + I(3, jump_pos1) +
" " + I(3, jump_pos2) );
663 while( !success && ntries++ < MAX_TRIES ){
664 Size const new1( static_cast<Size>(
RG.uniform() * res_list1.size() ) + 1 );
665 Size const new2( static_cast<Size>(
RG.uniform() * res_list2.size() ) + 1 );
666 jump_points( 1, which_jump_in_list ) = res_list1[ new1 ];
667 jump_points( 2, which_jump_in_list ) = res_list2[ new2 ];
668 success = fold_tree.tree_from_jumps_and_cuts( pose.
total_residue(), num_jumps,
669 jump_points, cuts, 1,
false );
676 if (success) pose.
fold_tree( fold_tree );
688 for (
Size i = 1; i <= num_jump; i++ ){
701 if (!success)
return;
735 Size const num_cuts_total ( num_cuts_closed + num_cuts_open );
741 runtime_assert( num_possible_pairing_sets + num_obligate_pairing_sets <= num_pairings );
746 Size const num_pairings_to_force = std::max( num_obligate_pairing_sets + num_chain_connections,
750 ObjexxFCL::FArray2D <int> jump_points( 2, num_pairings_to_force );
751 ObjexxFCL::FArray1D <int> cuts( num_pairings_to_force );
756 std::vector< int > obligate_cut_points;
758 for (
Size n = 1; n<= num_cuts_open ; n++ ) obligate_cut_points.push_back(
cutpoints_open_[n] );
764 FArray1D_float cut_bias( nres, 1.0 );
766 for (
Size i = 1; i < nres; i++ ) {
767 if ( rna_secstruct[i] ==
'H' && rna_secstruct[i+1] ==
'H' ) {
784 Size const MAX_TRIES( 1000 );
785 bool success(
false );
787 while (!success && ++ntries < MAX_TRIES ){
792 for (
Size n = 1; n <= num_obligate_pairing_sets ; n++ ){
804 for (
Size n = 1; n <= num_chain_connections ; n++ ){
807 Size const pairing_index_in_list1( static_cast<Size>(
RG.uniform() * res_list1.size() ) + 1 );
808 Size const pairing_index_in_list2( static_cast<Size>(
RG.uniform() * res_list2.size() ) + 1 );
810 jump_points(1, count) = res_list1[ pairing_index_in_list1 ];
811 jump_points(2, count) = res_list2[ pairing_index_in_list2 ];
820 FArray1D < bool > used_set( num_possible_pairing_sets,
false );
821 Size num_sets_left( num_possible_pairing_sets );
823 while ( count < num_pairings_to_force ) {
826 Size const set_index( static_cast<Size>(
RG.uniform() * num_sets_left ) + 1 );
827 Size m( 0 ), set_count( 0 );
828 for (m = 1; m <= num_possible_pairing_sets; m++ ){
829 if ( !used_set( m ) ) {
831 if (set_count == set_index )
break;
835 if (m > num_possible_pairing_sets ) {
836 utility_exit_with_message(
"Problem with pairing search "+I(3,num_possible_pairing_sets)+
" "+I(3,m) );
848 used_set( m ) =
true;
866 if (!success) utility_exit_with_message(
"Couldn't find a freaking tree!" );
879 runtime_assert( rigid_body_jumps.size() > 0 );
881 std::cout <<
"ROOTING AT RSD" << anchor_rsd << std::endl;
901 bool const random_jumps(
true );
907 utility_exit_with_message(
"Trouble inserting base pair jumps into pose -- check residues and edges." );
946 std::cout <<
"Adding chainbreak variants to " << cutpos << std::endl;
954 for (
Size i = cutpos; i <= cutpos + 1; i++ ){
1017 utility_exit_with_message(
"Do not specify cutpoint_open at last residue of model" );
1022 utility_exit_with_message(
"conflicting cutpoint_open & cutpoint_closed" );
1044 using namespace core::conformation;
1045 using namespace core::scoring::rna;
1046 using namespace core::id;
1050 if (num_jump == 0)
return false;
1053 Size const MAX_TRIES( 1000 );
1055 Size which_jump( 0 );
1057 while ( ntries++ < MAX_TRIES ){
1059 which_jump =
static_cast<Size>(
RG.uniform() * num_jump ) + 1 ;
1076 if (ntries >= MAX_TRIES )
return false;
1086 bool success(
false );
1097 using namespace scoring::rna;
1106 i = rna_pairing.
pos2;
1107 j = rna_pairing.
pos1;
1114 if ( !rna_low_resolution_potential.check_forming_base_pair(pose,i,j) ) {
1115 tr <<
"MISSING BASE PAIR " << i <<
" " << j << std::endl;
1123 if ( !rna_low_resolution_potential.check_clear_for_stacking( pose, i, +1 ))
return false;
1124 if ( !rna_low_resolution_potential.check_clear_for_stacking( pose, j, -1 ))
return false;
1128 if ( !rna_low_resolution_potential.check_clear_for_stacking( pose, i, -1 ))
return false;
1129 if ( !rna_low_resolution_potential.check_clear_for_stacking( pose, j, +1 ))
return false;
1146 using namespace core::id;
1155 Size const & i( rna_pairing.
pos1 );
1156 Size const & j( rna_pairing.
pos2 );
1159 if ( !( rna_pairing.
edge1 ==
'W' && rna_pairing.
edge2 ==
'W' && rna_pairing.
orientation ==
'A' ) ) {
1160 tr <<
"skipping constraints for non-canonical base pair: " << I(3,i) <<
" " << I(3,j) <<
" " << rna_pairing.
edge1 <<
" " << rna_pairing.
edge2 <<
" " << rna_pairing.
orientation << std::endl;
1170 pairings.push_back( std::make_pair( i, j ) ) ;
1178 std::map< Size, Size >
1182 std::map< Size, Size > connections_local;
1185 connections_local[ pairing.
pos1 ] = pairing.
pos2;
1186 connections_local[ pairing.
pos2 ] = pairing.
pos1;
1188 return connections_local;