34 #include <basic/Tracer.hh>
37 #include <numeric/random/random.hh>
40 #include <utility/vector1.hh>
50 static numeric::random::RandomGenerator
RG( 101381274 );
51 static basic::Tracer
TR(
"protocols.forge.build.SegmentInsert" );
80 bool const keep_known_bb_torsions_at_junctions,
83 Super( i, &insert.residue( 1 ).residue_type_set() ),
86 keep_known_bb_torsions_at_junctions_( keep_known_bb_torsions_at_junctions ),
87 insert_connection_scheme_( connection_scheme ),
88 insert_pose_( insert )
91 for (
Size i = 0, ie =
ss_.length(); i < ie; ++i ) {
101 TR.Warning <<
"keep_known_bb_torsions_at_junctions set to True, but performing pure insertion, so forcing the setting to False" << std::endl;
134 bool const keep_known_bb_torsions_at_junctions,
137 Super( i, &insert.residue( 1 ).residue_type_set() ),
141 keep_known_bb_torsions_at_junctions_( keep_known_bb_torsions_at_junctions ),
142 insert_connection_scheme_( connection_scheme ),
143 insert_pose_( insert )
148 runtime_assert(
ss_.length() == one_letter_aa.length() );
154 for (
Size i = 0, ie =
ss_.length(); i < ie; ++i ) {
156 aa_.push_back(
'A' );
165 TR.Warning <<
"keep_known_bb_torsions_at_junctions set to True, but performing pure insertion, so forcing the setting to False" << std::endl;
176 interval_( rval.interval_ ),
179 insert_connection_scheme_( rval.insert_connection_scheme_ ),
180 insert_pose_( rval.insert_pose_ ),
181 insert_pose_torsion_override_movemap_( rval.insert_pose_torsion_override_movemap_ )
191 if (
this != &rval ) {
396 for (
Size i = left_flank.
left + 1; i <= left_flank.
left; ++i ) {
401 for (
Size i = insertion.
left + 1, ie = insertion.
right - 1; i <= ie; ++i ) {
406 for (
Size i = right_flank.
left, ie = right_flank.
right - 1; i <= ie; ++i ) {
412 Size const ridx_offset = insertion.
left - 1;
416 mm.
set( i->first, i->second );
421 MoveMapTorsionID shifted_id = i->first;
422 shifted_id.first += ridx_offset;
423 assert( insertion.
left <= shifted_id.first && shifted_id.first <= insertion.
right );
424 mm.
set( shifted_id, i->second );
429 TorsionID shifted_id = i->first;
430 shifted_id.rsd() += ridx_offset;
431 assert( insertion.
left <= shifted_id.rsd() && shifted_id.rsd() <= insertion.
right );
432 mm.
set( shifted_id, i->second );
458 TR.Error <<
"ERROR: insert_pose_torsion_override_movemap() passed a MoveMap with an unhandled TorsionType setting" << std::endl;
459 runtime_assert(
false );
467 TR.Error <<
"ERROR: insert_pose_torsion_override_movemap() passed a MoveMap with an unhandled"
468 <<
" MoveMapTorsionID type at residue " << i->first.first << std::endl;
469 runtime_assert(
false );
473 TR.Error <<
"ERROR: insert_pose_torsion_override_movemap() passed a MoveMap with a MoveMapTorsionID"
474 <<
" setting greater than the total number of residues in the insert pose at residue "
475 << i->first.first << std::endl;
476 runtime_assert(
false );
484 TR.Error <<
"ERROR: insert_pose_torsion_override_movemap() passed a MoveMap with an unhandled"
485 <<
" TorsionID type at residue " << i->first.rsd() << std::endl;
486 runtime_assert(
false );
490 TR.Error <<
"ERROR: insert_pose_torsion_override_movemap() passed a MoveMap with a MoveMapTorsionID"
491 <<
" setting greater than the total number of residues in the insert pose at residue "
492 << i->first.rsd() << std::endl;
493 runtime_assert(
false );
622 bool performing_n_term_insertion =
false;
623 bool performing_c_term_insertion =
false;
629 assert( !( performing_n_term_insertion && performing_c_term_insertion ) );
632 bool left_has_lower_terminus =
false;
633 bool left_has_upper_terminus =
false;
634 bool right_has_lower_terminus =
false;
635 bool right_has_upper_terminus =
false;
637 if ( !performing_n_term_insertion ) {
644 left_has_lower_terminus =
true;
645 left_has_upper_terminus =
false;
648 if ( !performing_c_term_insertion ) {
655 right_has_lower_terminus =
false;
656 right_has_upper_terminus =
true;
663 runtime_assert( !( left_has_lower_terminus && right_has_upper_terminus ) );
666 Size n_cutpoints = 0;
697 Real left_endpoint_minus_one_omega = 999.0;
698 Real left_endpoint_phi = 999.0;
699 Real right_endpoint_psi = 999.0;
700 Real right_endpoint_omega = 999.0;
731 if ( !( performing_n_term_insertion || performing_c_term_insertion ) ) {
759 if ( n_cutpoints == 0 && !left_has_lower_terminus && !right_has_upper_terminus
760 && !left_has_upper_terminus && !right_has_lower_terminus
766 ft.jump_edge( new_jump_number ).start_atom() =
"N";
767 ft.jump_edge( new_jump_number ).stop_atom() =
"C";
769 }
else if ( n_cutpoints > 0 ) {
777 Edge jump_edge = ft.jump_edge( jump );
778 ft.delete_edge( jump_edge );
784 if ( static_cast< Size >( jump_edge.start() ) ==
interval_.
left ) {
785 jump_edge.start_atom() =
"N";
786 }
else if ( jump_edge.start_atom().empty() ) {
790 jump_edge.start_atom() = pose.
residue( jump_edge.start() ).atom_name(
795 if ( static_cast< Size >( jump_edge.stop() ) ==
interval_.
right ) {
796 jump_edge.stop_atom() =
"C";
797 }
else if ( jump_edge.stop_atom().empty() ) {
801 jump_edge.stop_atom() = pose.
residue( jump_edge.stop() ).atom_name(
806 ft.add_edge( jump_edge );
816 if ( performing_n_term_insertion ) {
819 }
else if ( performing_c_term_insertion ) {
828 Size before_insert_point = 0;
829 if ( !left_has_lower_terminus ) {
830 assert( !performing_n_term_insertion );
832 if ( !r_types_flanking_left.empty() ) {
837 r_types_flanking_left.begin(),
838 r_types_flanking_left.end()
846 Size after_insert_point = 0;
847 if ( !right_has_upper_terminus ) {
848 assert( !performing_c_term_insertion );
850 if ( !r_types_flanking_right.empty() ) {
855 r_types_flanking_right.rbegin(),
856 r_types_flanking_right.rend()
864 assert( !left_has_lower_terminus && !right_has_upper_terminus ? before_insert_point == after_insert_point - 1 :
true );
874 if ( left_has_lower_terminus ) {
875 insert_connection_scheme =
C;
876 }
else if ( right_has_upper_terminus ) {
877 insert_connection_scheme =
N;
881 if (
RG.uniform() < 0.5 ) {
882 insert_connection_scheme =
N;
884 insert_connection_scheme =
C;
900 switch ( insert_connection_scheme ) {
904 before_insert_point, insert_residues.begin(), insert_residues.end(),
908 if ( right_has_upper_terminus ) {
909 grow_right_rtype( pose, new_anchor, r_types_flanking_right.begin(), r_types_flanking_right.end() );
916 after_insert_point, insert_residues.rbegin(), insert_residues.rend(),
920 if ( left_has_lower_terminus ) {
921 grow_left_rtype( pose, new_anchor, r_types_flanking_left.rbegin(), r_types_flanking_left.rend() );
926 runtime_assert(
false );
930 if ( performing_n_term_insertion ) {
933 }
else if ( performing_c_term_insertion ) {
949 if ( !( performing_n_term_insertion || performing_c_term_insertion ) ) {
953 assert( cutpoint > 0 );
955 Size new_cutpoint = 0;
956 switch ( insert_connection_scheme ) {
979 runtime_assert(
false );
982 if ( new_cutpoint != cutpoint ) {
983 new_ft.slide_cutpoint( cutpoint, new_cutpoint );
994 bool ft_was_altered =
false;
996 if ( e->label() > 0 ) {
1000 bool start_changed =
false;
1001 if ( static_cast< Size >( tmp.start() ) ==
interval_.
left - 1 ) {
1002 tmp.start_atom() =
"N";
1003 start_changed =
true;
1006 bool stop_changed =
false;
1007 if ( static_cast< Size >( tmp.stop() ) ==
interval_.
right + 1 ) {
1008 tmp.stop_atom() =
"C";
1009 stop_changed =
true;
1016 if ( start_changed && !stop_changed && tmp.stop_atom().empty() ) {
1017 tmp.stop_atom() = pose.
residue( tmp.stop() ).atom_name(
1020 stop_changed =
true;
1023 if ( !start_changed && stop_changed && tmp.start_atom().empty() ) {
1024 tmp.start_atom() = pose.
residue( tmp.start() ).atom_name(
1027 start_changed =
true;
1031 if ( start_changed && stop_changed ) {
1032 ft.delete_edge( *e );
1034 ft_was_altered =
true;
1039 if ( ft_was_altered ) {
1047 Size omega_left_start = 0, omega_left_end = 0;
1048 Size omega_right_start = 0, omega_right_end = 0;
1060 assert( omega_left_start <= omega_left_end );
1072 assert( omega_right_start <= omega_right_end );
1078 switch ( insert_connection_scheme ) {
1083 assert( omega_left_end > 0 );
1091 assert( omega_right_start > 0 );
1102 assert( omega_left_end > 0 );
1111 assert( omega_right_start > 0 );
1118 runtime_assert(
false );
1123 if ( pre_psi <= 360.0 ) {
1127 if ( post_phi <= 360.0 ) {
1134 trans_omega( omega_left_start, omega_left_end, pose );
1138 trans_omega( omega_right_start, omega_right_end, pose );
1145 if ( left_endpoint_minus_one_omega <= 360.0 ) {
1149 if ( left_endpoint_phi <= 360.0 ) {
1153 if ( right_endpoint_psi <= 360.0 ) {
1157 if ( right_endpoint_omega <= 360.0 ) {
1166 for (
Size i = 0, ie = f_l_ss.length(); i < ie; ++i ) {
1172 for (
Size i = 0, ie = f_r_ss.length(); i < ie; ++i, ++r ) {