21 #include <basic/Tracer.hh>
22 #include <utility/exit.hh>
23 #include <utility/stream_util.hh>
24 #include <utility/string_util.hh>
25 #include <basic/MetricValue.hh>
40 #include <utility/vector1.hh>
47 using namespace core::pose;
48 using namespace core::pose::metrics;
54 namespace pose_metric_calculators {
58 NumberHBondsCalculator::lookup(
60 basic::MetricValueBase * valptr
64 if ( key ==
"all_Hbonds" ) {
65 basic::check_cast( valptr, &all_Hbonds_,
"all_Hbonds expects to return a Size" );
66 (
static_cast<basic::MetricValue<Size> *
>(valptr))->set( all_Hbonds_ );
68 }
else if ( key ==
"special_region_Hbonds" ) {
69 basic::check_cast( valptr, &special_region_Hbonds_,
"special_region_Hbonds expects to return a Size" );
70 (
static_cast<basic::MetricValue<Size> *
>(valptr))->set( special_region_Hbonds_ );
72 }
else if ( key ==
"atom_Hbonds" ) {
73 basic::check_cast( valptr, &atom_Hbonds_,
"atom_Hbonds expects to return a id::AtomID_Map< Size >" );
74 (
static_cast<basic::MetricValue<id::AtomID_Map< Size >
> *>(valptr))->set( atom_Hbonds_ );
76 }
else if ( key ==
"residue_Hbonds" ) {
77 basic::check_cast( valptr, &residue_Hbonds_,
"residue_Hbonds expects to return a utility::vector1< Size >" );
78 (
static_cast<basic::MetricValue<utility::vector1< Size >
> *>(valptr))->set( residue_Hbonds_ );
81 basic::Error() <<
"NumberHbondsCalculator cannot compute the requested metric " << key << std::endl;
90 NumberHBondsCalculator::print(
std::string const & key )
const
93 if ( key ==
"all_Hbonds" ) {
94 return utility::to_string( all_Hbonds_ );
95 }
else if ( key ==
"special_region_Hbonds" ) {
96 return utility::to_string( special_region_Hbonds_ );
97 }
else if ( key ==
"atom_Hbonds" ) {
98 basic::Error() <<
"id::AtomID_Map< Size > has no output operator, for metric " << key << std::endl;
100 }
else if ( key ==
"residue_Hbonds" ) {
101 return utility::to_string( residue_Hbonds_ );
104 basic::Error() <<
"NumberHbondsCalculator cannot compute metric " << key << std::endl;
113 NumberHBondsCalculator::recompute(
Pose const & this_pose )
116 using namespace core::scoring;
125 determine_res_to_recompute( this_pose, res_to_recompute );
126 runtime_assert( residue_Hbonds_.size() == res_to_recompute.size() );
129 for(
Size i = 1; i <= res_to_recompute.size(); ++i){
131 if( res_to_recompute[ i ] ) residue_Hbonds_[ i ] = 0;
135 for(
Size i = 1; i <= res_to_recompute.size(); ++i){
137 compute_Hbonds_for_residue( this_pose, i, res_to_recompute, hb_set );
147 for(
Size i = 1; i <= res_to_recompute.size(); ++i){
149 if( !res_to_recompute[i] )
continue;
157 if( residue_Hbonds_[i] == 0 ){
158 atom_Hbonds_.set( atid, 0 );
163 Size hbonds_this_donor(0);
166 hbonds_this_donor = hbonds_this_donor + hb_set.atom_hbonds(
core::id::AtomID (hcount, i ) ).size();
170 hbonds_this_donor = hbonds_this_donor + hb_set.atom_hbonds( atid ).size();;
171 atom_Hbonds_.set( atid, hbonds_this_donor );
177 atom_Hbonds_.set( atid, hb_set.atom_hbonds( atid ).size() );
181 Size hbonds_this_donor(0);
185 hbonds_this_donor = hbonds_this_donor + hb_set.atom_hbonds(
core::id::AtomID (hcount, i ) ).size();
189 atom_Hbonds_.set( atid, hbonds_this_donor );
191 else atom_Hbonds_.set( atid, 0 );
199 resh_it != residue_Hbonds_.end(); ++resh_it){
200 all_Hbonds_ = all_Hbonds_ + *resh_it;
202 all_Hbonds_ = all_Hbonds_ / 2;
213 NumberHBondsCalculator::determine_res_to_recompute(
217 using namespace core::scoring;
221 if( ref_residue_total_energies_.size() != pose.
total_residue() ){
222 atom_Hbonds_.clear();
227 res_to_recompute[ i ] =
true;
241 res_to_recompute[ i ] =
true;
245 if( special_region_.find( i ) != special_region_.end() ) res_to_recompute[ i ] =
true;
252 NumberHBondsCalculator::compute_Hbonds_for_residue(
258 using namespace core::scoring;
270 Size other_node = (*egraph_it)->get_other_ind( i );
272 if( (!res_to_recompute[i]) && !(res_to_recompute[other_node] ) )
continue;
287 false,
false,
false,
false, hb_set);
290 false,
false,
false,
false, hb_set);
293 Size num_hb_these_two_res = hb_set.
nhbonds() - prev_no_hb;
295 if( res_to_recompute[i] ) residue_Hbonds_[ i ] += num_hb_these_two_res;
296 if( res_to_recompute[ other_node ] ) residue_Hbonds_[ other_node ] += num_hb_these_two_res;
298 if( special_region_.find( i ) != special_region_.end() ) special_region_Hbonds_ += num_hb_these_two_res;
299 else if( special_region_.find( other_node ) != special_region_.end() ) special_region_Hbonds_ += num_hb_these_two_res;
313 NumberHBondsCalculator::sum_Hbond_terms(
317 using namespace core::scoring;