37 #include <basic/basic.hh>
38 #include <basic/Tracer.hh>
41 #include <numeric/numeric.functions.hh>
42 #include <numeric/constants.hh>
43 #include <numeric/xyz.functions.hh>
46 #include <utility/vector1.functions.hh>
51 #include <utility/vector0.hh>
52 #include <utility/vector1.hh>
56 namespace simple_moves {
61 basic::Tracer
TR(
"protocols.simple_moves.GreenPacker");
64 residue_type_( res.type() ),
65 ideal_geometry_( false )
105 Size st2 = atom_icoor.stub_atom2().atomno();
106 Size st3 = atom_icoor.stub_atom2().atomno();
108 Real const ideal_d = atom_icoor.d();
109 if ( std::abs( res.
xyz( atom_id ).distance( res.
xyz( st1 ) ) - ideal_d ) > 1e-8 ) {
123 Real const ideal_theta = atom_icoor.theta();
124 Real const actual_theta = numeric::constants::d::pi - numeric::angle_radians(
128 if ( std::abs( actual_theta - ideal_theta ) > 1e-8 ) {
134 bool atom_is_last_for_some_chi =
false;
137 atom_is_last_for_some_chi =
true;
141 if ( ! atom_is_last_for_some_chi ) {
142 Real const ideal_phi = atom_icoor.phi();
143 Real const actual_phi = numeric::dihedral_radians(
149 if ( std::abs( basic::periodic_range( actual_phi - ideal_phi, numeric::constants::d::pi ) ) > 1e-8 ) {
164 for (
Size ii = 1; ii <=
chi_.size(); ++ii ) {
192 Size st2 = atom_icoor.stub_atom2().atomno();
193 Size st3 = atom_icoor.stub_atom2().atomno();
195 Real actual_d = res.
xyz( atom_id ).distance( res.
xyz( st1 ) );
200 Real const actual_theta = numeric::angle_radians(
206 Real const actual_phi = numeric::dihedral_radians(
212 internal_geometry_[ atom_id ][
phi ] = actual_phi;
219 assert( chi_atoms.size() == 4 );
220 Real const actual_chi = numeric::dihedral_degrees(
221 res.
xyz( chi_atoms[ 1 ] ),
222 res.
xyz( chi_atoms[ 2 ] ),
223 res.
xyz( chi_atoms[ 3 ] ),
224 res.
xyz( chi_atoms[ 4 ] )
226 if ( std::abs( basic::periodic_range( actual_chi - res.
chi( chi_index ), 180 ) ) > 1e-8 ) {
256 assert(
chi_.size() == other.
chi_.size() );
257 for (
Size ii = 1; ii <=
chi_.size(); ++ii ) {
258 if ( std::abs( basic::periodic_range(
chi_[ ii ] - other.
chi_[ ii ], 180 ) ) > 1e-8 ) {
283 if ( std::abs( basic::periodic_range(
285 numeric::constants::d::pi ) ) > 1e-8 ) {
357 clock_t starttime = clock();
362 clock_t stoptime = clock();
363 TR <<
"Green Packer took: " << ((double) stoptime-starttime) / CLOCKS_PER_SEC <<
" seconds." << std::endl;
368 return "GreenPacker";
398 for (
Size ii = 1; ii <= scoretypes.size(); ++ii ) {
399 sfxn.
set_weight( scoretypes[ ii ], weights[ scoretypes[ ii ] ] );
498 using namespace core::pack::rotamer_set;
522 for (
Size jj = 1; jj <= ii_nrots; ++jj ) {
535 using namespace core::pack::interaction_graph;
540 dynamic_cast< PrecomputedPairEnergiesInteractionGraph * > (
549 utility_exit_with_message(
"GreenPacker asked to use on-the-fly interaction graph. Why?" );
604 iru = packer_neighbor_graph->get_node(ii)->upper_edge_list_begin(),
605 irue = packer_neighbor_graph->get_node(ii)->upper_edge_list_end();
609 if ( ii_grp !=
group_ids_[ (*iru)->get_second_node_ind() ] ||
611 packer_neighbor_graph->delete_edge( *iru );
628 iru = packer_neighbor_graph->get_node(ii)->upper_edge_list_begin(),
629 irue = packer_neighbor_graph->get_node(ii)->upper_edge_list_end();
633 if ( ii_grp ==
group_ids_[ (*iru)->get_second_node_ind() ] &&
635 group_ids_[ (*iru)->get_second_node_ind() ] != 0 ) {
636 packer_neighbor_graph->delete_edge( *iru );
662 for (
Size jj = 1; jj <= ii_nrots; ++jj ) {
675 using namespace core::pack::rotamer_set;
682 Size correspondences_found( 0 );
686 if ( ii_moltenresid == 0 )
continue;
695 Size orig_id( 1 ), curr_id( 1 );
696 bool orig_prev_restype_match(
false );
697 Size ii_correspondences_found( 0 );
698 while ( orig_id <= ii_orig_nrots && curr_id <= ii_curr_nrots ) {
701 if ( orig_rot->same_residue_type( *curr_rot )) {
702 if ( orig_rot->same( *curr_rot ) ) {
708 ++ii_correspondences_found;
713 orig_prev_restype_match =
true;
715 if ( orig_prev_restype_match ) {
735 if ( orig_rot->aa() >= curr_rot->aa() ) {
741 orig_prev_restype_match =
false;
745 correspondences_found += ii_correspondences_found;
748 for (
Size jj = 1; jj <= ii_curr_nrots; ++jj ) {
757 TR <<
"Found correspondence for " << correspondences_found;
775 if ( ii_moltenresid != 0 ) {
789 using namespace core::pack::interaction_graph;
798 dynamic_cast< PrecomputedPairEnergiesInteractionGraph * > (
807 utility_exit_with_message(
"GreenPacker asked to use on-the-fly interaction graph. Why?" );
845 using namespace core::pack;
846 using namespace core::pack::interaction_graph;
851 if ( ii_moltenres_curr == 0 || ii_moltenres_orig == 0 )
continue;
853 for (
ci_rpes_->reset_edge_list_iterator_for_node( ii_moltenres_orig );
854 !
ci_rpes_->edge_list_iterator_at_end();
855 ci_rpes_->increment_edge_list_iterator() ) {
859 if ( jj_moltenres_orig < ii_moltenres_orig )
continue;
863 if ( jj_moltenres_curr == 0 )
continue;
865 assert( dynamic_cast< PrecomputedPairEnergiesEdge const * > ( & edge ) );
868 static_cast< PrecomputedPairEnergiesEdge const & > ( edge ) );
870 if ( !pig->get_edge_exists( ii_moltenres_curr, jj_moltenres_curr )) {
871 pig->add_edge( ii_moltenres_curr, jj_moltenres_curr );
881 Size ii_ncorr_rots = ii_corr_rots.size();
882 Size jj_ncorr_rots = jj_corr_rots.size();
884 if ( ii_ncorr_rots == 0 || jj_ncorr_rots == 0 )
continue;
886 for (
Size kk = 1; kk <= ii_ncorr_rots; ++kk ) {
887 Size const kk_curr_rot = ii_corr_rots[ kk ];
888 Size const kk_orig_rot = ii_curr_2_orig[ kk_curr_rot ];
890 for (
Size ll = 1; ll <= jj_corr_rots.size(); ++ll ) {
891 Size const ll_curr_rot = jj_corr_rots[ ll ];
892 Size const ll_orig_rot = jj_curr_2_orig[ ll_curr_rot ];
894 pig->add_to_two_body_energies_for_edge(
895 ii_moltenres_curr, jj_moltenres_curr,
896 kk_curr_rot, ll_curr_rot,
915 using namespace core::scoring;
920 if ( ii_moltenres_curr == 0 )
continue;
926 iru != irue; ++iru ) {
928 Size const jj = (*iru)->get_second_node_ind();
930 if ( jj_moltenres_curr == 0 )
continue;
934 if ( ii_nnew_rots == 0 && jj_nnew_rots == 0 )
continue;
936 if ( ! pig->get_edge_exists( ii_moltenres_curr, jj_moltenres_curr ) ) {
937 pig->add_edge( ii_moltenres_curr, jj_moltenres_curr );
947 lr_iter =
ci_sfxn_->long_range_energies_begin(),
948 lr_end =
ci_sfxn_->long_range_energies_end();
949 lr_iter != lr_end; ++lr_iter ) {
951 if ( !lrec || lrec->empty() )
continue;
956 if ( ii_moltenres_curr == 0 )
continue;
960 rni = lrec->const_upper_neighbor_iterator_begin( ii ),
961 rniend = lrec->const_upper_neighbor_iterator_end( ii );
962 (*rni) != (*rniend); ++(*rni) ) {
963 Size const jj = rni->upper_neighbor_id();
966 if ( jj_moltenres_curr == 0 )
continue;
969 if ( ii_nnew_rots == 0 && jj_nnew_rots == 0 )
continue;
971 if ( ! pig->get_edge_exists( ii_moltenres_curr, jj_moltenres_curr ) ) {
972 pig->add_edge( ii_moltenres_curr, jj_moltenres_curr );
990 using namespace core::conformation;
991 using namespace core::scoring;
994 assert( lower_res_moltenresid );
997 assert( upper_res_moltenresid );
1005 if ( lower_res_nnew_rots > 0 ) {
1006 for (
Size ii = 1; ii <= lower_res_nnew_rots; ++ii ) {
1009 for (
Size jj = 1; jj <= upper_res_nrots; ++jj ) {
1012 ci_sfxn_->eval_ci_2b( *ii_rot, *jj_rot, pose, emap );
1013 Real const weighted_energy =
ci_sfxn_->weights().dot( emap );
1014 pig->add_to_two_body_energies_for_edge(
1015 lower_res_moltenresid, upper_res_moltenresid,
1016 ii_rot_index, jj, weighted_energy );
1021 if ( upper_res_nnew_rots > 0 ) {
1022 for (
Size ii = 1; ii <= lower_res_nrots; ++ii ) {
1029 for (
Size jj = 1; jj <= upper_res_nnew_rots; ++jj ) {
1033 ci_sfxn_->eval_ci_2b( *ii_rot, *jj_rot, pose, emap );
1034 Real const weighted_energy =
ci_sfxn_->weights().dot( emap );
1035 pig->add_to_two_body_energies_for_edge(
1036 lower_res_moltenresid, upper_res_moltenresid,
1037 ii, jj_rot_index, weighted_energy );
1053 using namespace core::conformation;
1054 using namespace core::scoring;
1057 assert( lower_res_moltenresid );
1060 assert( upper_res_moltenresid );
1068 if ( lower_res_nnew_rots > 0 ) {
1069 for (
Size ii = 1; ii <= lower_res_nnew_rots; ++ii ) {
1072 for (
Size jj = 1; jj <= upper_res_nrots; ++jj ) {
1076 Real const weighted_energy =
ci_sfxn_->weights().dot( emap );
1077 pig->add_to_two_body_energies_for_edge(
1078 lower_res_moltenresid, upper_res_moltenresid,
1079 ii_rot_index, jj, weighted_energy );
1084 if ( upper_res_nnew_rots > 0 ) {
1085 for (
Size ii = 1; ii <= lower_res_nrots; ++ii ) {
1092 for (
Size jj = 1; jj <= upper_res_nnew_rots; ++jj ) {
1097 Real const weighted_energy =
ci_sfxn_->weights().dot( emap );
1098 pig->add_to_two_body_energies_for_edge(
1099 lower_res_moltenresid, upper_res_moltenresid,
1100 ii, jj_rot_index, weighted_energy );
1150 if ( std::abs( basic::periodic_range(
1153 std::cerr <<
"Critical Error in GreenPacker -- Backbone torsions have changed since original packing" << std::endl;
1154 std::cerr <<
"Residue " << ii <<
" torsion " << jj <<
" originally: " <<
orig_bb_tors_[ ii ][ jj ];
1156 utility_exit_with_message(
"Bad torsion in GreenPacker" );