31 #include <basic/options/option.hh>
32 #include <basic/options/keys/packing.OptionKeys.gen.hh>
36 #include <basic/Tracer.hh>
40 #include <platform/types.hh>
45 #include <utility/string_util.hh>
49 #include <ObjexxFCL/format.hh>
50 #include <ObjexxFCL/FArray4D.hh>
57 #include <utility/vector1.hh>
62 namespace rotamer_set {
64 using namespace ObjexxFCL;
66 basic::Tracer
TR(
"protocols.flexpack.rotamer_set.FlexbbRotamerSets" );
78 {
return rotamers_[ molten_resid ][ bbconf ]; }
131 if(
task_->pack_residue( ii ) ){
142 for(
core::Size frame_count = 1; frame_count <= num_frames; ++frame_count ){
144 core::Size cur_frame_start( frames[ frame_count ]->
start() ), cur_frame_end( frames[ frame_count]->
end() );
146 flexsegment_span_[ frame_count ] = std::pair< core::Size, core::Size>( cur_frame_start, cur_frame_end ) ;
148 nbbconfs_ += nbbconfs_for_flexseg_[ frame_count ];
150 for(
core::Size frameres_count = cur_frame_start; frameres_count <= cur_frame_end; ++frameres_count){
157 for(
core::Size frag_count = 1; frag_count <= frames[ frame_count ]->nr_frags(); ++frag_count ){
161 for(
core::Size rescount = cur_frame_start; rescount <= cur_frame_end; ++rescount ){
228 core::Distance sq_dist = cur_xyz.distance_squared( (*res_it)->xyz( (*res_it)->nbr_atom() ) );
230 if( sq_dist > max_sq_dist ) max_sq_dist = sq_dist;
233 return sqrt( max_sq_dist);
255 rotset->set_owner(
this );
256 rotset->set_resid( cur_resid );
257 rotset->set_existing_residue( *res_it );
259 rotset->build_rotamers(pose, sfxn, *
task_, &flexpack_neighbor_graph );
275 if( basic::options::option[basic::options::OptionKeys::packing::dump_rotamer_sets].user() ){
293 using ObjexxFCL::fmt::I;
295 std::string fix_filename = filename_base +
"_fixbb.pdb";
298 std::ofstream base_out( fix_filename.c_str() );
301 Size model(0), atom_counter(0);
303 base_out <<
"MODEL" << I(9,model) <<
'\n';
305 if (
task_->pack_residue(i) )
continue;
308 base_out <<
"ENDMDL\n";
312 bool found_a_rotamer(
false );
318 if ( rotset->num_rotamers() >= model ) {
319 if ( !found_a_rotamer ) {
320 found_a_rotamer =
true;
321 base_out <<
"MODEL" << I(9,model) <<
'\n';
326 if ( found_a_rotamer ) {
327 base_out <<
"ENDMDL\n";
337 bool all_confs_covered(
false);
339 while( ! all_confs_covered ){
341 std::string cur_filename = filename_base +
"_flexconf" + utility::to_string( curconf - 1 ) +
".pdb";
342 std::ofstream cur_out( cur_filename.c_str() );
344 all_confs_covered =
true;
351 bool found_a_rotamer(
false );
359 all_confs_covered =
false;
362 if( rotset->num_rotamers() >= model ){
363 if( !found_a_rotamer ){
364 found_a_rotamer =
true;
365 cur_out <<
"MODEL" << I(9,model) <<
'\n';
372 if( found_a_rotamer ) cur_out <<
"ENDMDL\n";
436 return rotamers_[ moltenres ][ bb ]->rotamer( rotid_on_bb );
445 return rotamers_[ moltenres_id ][ bb ]->rotamer( rotid_on_bb );
460 utility_exit_with_message(
"UNIMPLEMENTED");
469 utility_exit_with_message(
"UNIMPLEMENTED");
482 if( frame->apply( frag_num, pose ) != frame->length() ) utility_exit_with_message(
"unknown error when trying to apply a fragment to a pose in setting up FlexbbRotamerSets.");
484 for(
core::Size rescount = frame->start(); rescount <= frame->end(); ++rescount ){
591 using namespace interaction_graph;
594 if ( dynamic_cast< OTFFlexbbInteractionGraph * > ( &flexbb_ig ) ) {
595 OTFFlexbbInteractionGraph & otfig =
596 static_cast< OTFFlexbbInteractionGraph &
> ( flexbb_ig );
600 assert( dynamic_cast< PrecomputedFlexbbInteractionGraph * > ( &flexbb_ig ) );
601 PrecomputedFlexbbInteractionGraph & precomp_ig =
602 static_cast< PrecomputedFlexbbInteractionGraph &
> ( flexbb_ig );
616 std::cout <<
"Yo Mama so fat!" << std::endl;
629 using namespace utility;
630 using namespace core::chemical;
631 using namespace core::scoring;
632 using namespace core::scoring::methods;
653 regular_representatives[ ii ].resize( iinbb );
654 proline_representatives[ ii ].resize( iinbb );
655 glycine_representatives[ ii ].resize( iinbb );
656 std::fill( regular_representatives[ ii ].begin(), regular_representatives[ ii ].
end(), 0 );
657 std::fill( proline_representatives[ ii ].begin(), proline_representatives[ ii ].
end(), 0 );
658 std::fill( glycine_representatives[ ii ].begin(), glycine_representatives[ ii ].
end(), 0 );
659 for (
Size jj = 1; jj <= iinbb; ++jj ) {
661 Size jjntypes = jjrotset->get_n_residue_groups();
662 bool jjregfound(
false ), jjprofound(
false ), jjglyfound(
false );
663 for (
Size kk = 1; kk <= jjntypes; ++kk ) {
664 Size kkrep = jjrotset->get_residue_type_begin( kk );
665 AA kkaa = jjrotset->rotamer( kkrep )->aa();
666 if ( ! jjprofound && kkaa ==
aa_pro ) {
667 proline_representatives[ ii ][ jj ] = kkrep;
669 }
else if ( ! jjglyfound && kkaa ==
aa_gly ) {
670 glycine_representatives[ ii ][ jj ] = kkrep;
672 }
else if ( ! jjregfound && kkaa !=
aa_gly && kkaa !=
aa_pro ) {
673 regular_representatives[ ii ][ jj ] = kkrep;
676 if ( jjprofound && jjglyfound && jjregfound )
break;
684 li = flexpack_neighbor_graph->get_node( ii_resid )->const_upper_edge_list_begin(),
685 liend = flexpack_neighbor_graph->get_node( ii_resid )->const_upper_edge_list_end();
686 li != liend; ++li ) {
687 Size const jj_resid = (*li)->get_second_node_ind();
690 if( jj == 0 )
continue;
694 regular_representatives,
695 proline_representatives,
696 glycine_representatives,
697 pose, sfxn, flexbb_ig );
707 lr_iter != lr_end; ++lr_iter ) {
709 if ( !lrec || lrec->empty() )
continue;
713 using namespace platform;
720 rni = lrec->const_upper_neighbor_iterator_begin( ii_resid ),
721 rniend = lrec->const_upper_neighbor_iterator_end( ii_resid );
722 (*rni) != (*rniend); ++(*rni) ) {
723 Size const jj_resid = rni->upper_neighbor_id();
726 if ( ii > jj )
continue;
760 bool sought_pair =
false;
762 flexbb_ig.
add_edge( lowermoltenres, uppermoltenres );
779 Size const BBREG = 1;
780 Size const BBPRO = 2;
781 Size const BBGLY = 3;
782 Size const NBBCLASSES = 3;
785 FArray4D< PackerEnergy > bbbb_energies( NBBCLASSES, NBBCLASSES, lnbb, unbb, 0.0 );
789 for (
Size ii = 1; ii <= lnbb; ++ii ) {
792 lower_bbrepresentatives[ BBREG ] = lregrep[ ii ];
793 lower_bbrepresentatives[ BBPRO ] = lprorep[ ii ];
794 lower_bbrepresentatives[ BBGLY ] = lglyrep[ ii ];
795 for (
Size jj = 1; jj <= unbb; ++jj ) {
798 upper_bbrepresentatives[ BBREG ] = uregrep[ jj ];
799 upper_bbrepresentatives[ BBPRO ] = uprorep[ jj ];
800 upper_bbrepresentatives[ BBGLY ] = uglyrep[ jj ];
802 for (
Size kk = 1; kk <= NBBCLASSES; ++kk ) {
803 if ( lower_bbrepresentatives[ kk ] == 0 )
continue;
805 for (
Size ll = 1; ll <= NBBCLASSES; ++ll ) {
806 if ( upper_bbrepresentatives[ ll ] == 0 )
continue;
808 bbbb_energies( kk, ll, ii, jj ) =
811 std::cout <<
"bbbbE: " << ii <<
" " << jj <<
" " << kk <<
" " << ll <<
" " << bbbb_energies( kk, ll, ii, jj ) << std::endl;
819 for (
Size ii = 1; ii <= lnbb; ++ii ) {
822 for (
Size jj = 1; jj <= unbb; ++jj ) {
825 for (
Size kk = 1; kk <= iirotset->get_n_residue_types(); ++kk ) {
826 Size kkrep = iirotset->get_residue_type_begin( kk );
828 for (
Size ll = 1; ll <= jjrotset->get_n_residue_types(); ++ll ) {
829 Size llrep = jjrotset->get_residue_type_begin( ll );
832 std::cout <<
"BBBB: " << ii <<
" " << jj <<
" " <<
833 kkrot.
aa() <<
" " << llrot.aa() <<
" e: " <<
844 for (
Size ii = 1; ii <= lnrots; ++ii ) {
849 for (
Size jj = 1, jje = (sameflexseg ? 1 : unbb); jj <= jje; ++jj ) {
850 Size jjbb = sameflexseg ? iibb : jj;
852 upper_bbrepresentatives[ BBREG ] = uregrep[ jjbb ];
853 upper_bbrepresentatives[ BBPRO ] = uprorep[ jjbb ];
854 upper_bbrepresentatives[ BBGLY ] = uglyrep[ jjbb ];
855 std::fill( scbb_energies_lower.begin(), scbb_energies_lower.end(), 0.0f );
856 for (
Size kk = 1; kk <= NBBCLASSES; ++kk ) {
857 if ( upper_bbrepresentatives[ kk ] == 0 )
continue;
859 scbb_energies_lower[ kk ] =
862 std::cout <<
"lower bbscE: " << ii <<
" " << jj <<
" " << kk <<
" " << scbb_energies_lower[ kk ] << std::endl;
866 if ( upper_bbrepresentatives[ BBREG ] != 0 &&
867 upper_bbrepresentatives[ BBPRO ] == 0 &&
868 upper_bbrepresentatives[ BBGLY ] == 0 ) {
872 lowermoltenres, ii, jjbb,
873 bbbb_energies( iibbclass, BBREG, iibb, jjbb ), 0.0,
874 scbb_energies_lower[ BBREG ], 0.0 );
876 if ( upper_bbrepresentatives[ BBPRO ] != 0 ) {
878 lowermoltenres, ii, jjbb,
879 bbbb_energies( iibbclass, BBREG, iibb, jjbb ), bbbb_energies( iibbclass, BBPRO, iibb, jjbb ),
880 scbb_energies_lower[ BBREG ], scbb_energies_lower[ BBPRO ] );
883 if ( upper_bbrepresentatives[ BBGLY ] != 0 ) {
885 lowermoltenres, ii, jjbb,
886 bbbb_energies( iibbclass, BBREG, iibb, jjbb ), bbbb_energies( iibbclass, BBGLY, iibb, jjbb ),
887 scbb_energies_lower[ BBREG ], scbb_energies_lower[ BBGLY ] );
896 for (
Size ii = 1; ii <= unrots; ++ii ) {
901 for (
Size jj = 1, jje = sameflexseg ? 1 : lnbb; jj <= jje; ++jj ) {
902 Size jjbb = sameflexseg ? iibb : jj;
904 lower_bbrepresentatives[ BBREG ] = lregrep[ jjbb ];
905 lower_bbrepresentatives[ BBPRO ] = lprorep[ jjbb ];
906 lower_bbrepresentatives[ BBGLY ] = lglyrep[ jjbb ];
907 std::fill( scbb_energies_upper.begin(), scbb_energies_upper.end(), 0.0 );
909 for (
Size kk = 1; kk <= NBBCLASSES; ++kk ) {
910 if ( lower_bbrepresentatives[ kk ] == 0 )
continue;
912 scbb_energies_upper[ kk ] =
915 std::cout <<
"upper bbscE: " << ii <<
" " << jj <<
" " << kk <<
" " << scbb_energies_upper[ kk ] <<
916 " aa " << iirot.
aa() <<
922 if ( lower_bbrepresentatives[ BBREG ] != 0 &&
923 lower_bbrepresentatives[ BBPRO ] == 0 &&
924 lower_bbrepresentatives[ BBGLY ] == 0 ) {
928 uppermoltenres, ii, jjbb,
929 bbbb_energies( BBREG, iibbclass, jjbb, iibb ), 0.0,
930 scbb_energies_upper[ BBREG ], 0.0 );
932 if ( lower_bbrepresentatives[ BBPRO ] != 0 ) {
934 uppermoltenres, ii, jjbb,
935 bbbb_energies( BBREG, iibbclass, jjbb, iibb ), bbbb_energies( BBPRO, iibbclass, jjbb, iibb ),
936 scbb_energies_upper[ BBREG ], scbb_energies_upper[ BBPRO ] );
939 if ( lower_bbrepresentatives[ BBGLY ] != 0 ) {
941 uppermoltenres, ii, jjbb,
942 bbbb_energies( BBREG, iibbclass, jjbb, iibb ), bbbb_energies( BBGLY, iibbclass, jjbb, iibb ),
943 scbb_energies_upper[ BBREG ], scbb_energies_upper[ BBGLY ] );
973 Size const iinrots = iirotset->num_rotamers();
975 iirotset->compute_one_body_energies(
976 pose, sfxn, *
task_, flexpack_neighbor_graph, ii_one_body_energies );
978 for (
Size jj = 1; jj <= iinrots; ++jj ) {
981 all_one_body_energies[ jj + ii_offset ] = ii_one_body_energies[ jj ];