Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NonlocalContactsCalculator.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file protocols/toolbox/PoseMetricCalculator/NonlocalContactsCalculator.cc
11 /// @brief calculator to compute nonlocal/tertiary contacts in a given pose
12 /// @author Florian Richter
13 
14 // Unit headers
16 
17 //#include <core/pose/metrics/CalculatorFactory.hh>
19 #include <core/graph/Graph.hh>
20 #include <core/pose/Pose.hh>
21 #include <core/scoring/Energies.hh>
24 
25 // option key includes
26 #include <basic/options/keys/out.OptionKeys.gen.hh>
27 
28 // Utility headers
29 #include <basic/Tracer.hh>
30 #include <utility/exit.hh>
31 #include <utility/string_util.hh>
32 #include <basic/MetricValue.hh>
33 
34 
35 #include <cassert>
36 
37 #include <utility/vector1.hh>
38 
39 
40 
41 using namespace core;
42 using namespace core::pose;
43 using namespace core::pose::metrics;
44 
45 static basic::Tracer TR("protocols/toolbox/PoseMetricCalculators/NonlocalContactsCalculator");
46 
47 namespace protocols{
48 namespace toolbox {
49 namespace pose_metric_calculators {
50 
51 
52 NonlocalContactsCalculator::NonlocalContactsCalculator(
53  core::Size min_sequence_separation,
54  core::Real contact_cutoffE
55 ) : total_nlcontacts_(0),
56  special_region1_nlcontacts_(0),
57  special_region2_nlcontacts_(0),
58  special_region1_intra_nlcontacts_(0),
59  special_region1_to_other_nlcontacts_(0),
60  region1_region2_nlcontacts_(0),
61  nlcontacts_graph_( NULL ),
62  min_seq_separation_(min_sequence_separation),
63  cutoffE_(contact_cutoffE)
64 {
65  residue_nlcontacts_.clear();
66  residue_nlscore_.clear();
67  special_region1_.clear();
68  special_region2_.clear();
69 }
70 
71 
73  std::set< core::Size > const & special_region,
74  core::Size min_sequence_separation,
75  core::Real contact_cutoffE
76 ) : total_nlcontacts_(0),
77  special_region1_nlcontacts_(0),
78  special_region2_nlcontacts_(0),
79  special_region1_intra_nlcontacts_(0),
80  special_region1_to_other_nlcontacts_(0),
81  region1_region2_nlcontacts_(0),
82  nlcontacts_graph_( NULL ),
83  min_seq_separation_(min_sequence_separation),
84  cutoffE_(contact_cutoffE),
85  special_region1_(special_region)
86 {
87  residue_nlcontacts_.clear();
88  residue_nlscore_.clear();
89  special_region2_.clear();
90 }
91 
92 
94  std::set< core::Size > const & special_region1,
95  std::set< core::Size > const & special_region2,
96  core::Size min_sequence_separation,
97  core::Real contact_cutoffE
98 ) : total_nlcontacts_(0),
99  special_region1_nlcontacts_(0),
100  special_region2_nlcontacts_(0),
101  special_region1_intra_nlcontacts_(0),
102  special_region1_to_other_nlcontacts_(0),
103  region1_region2_nlcontacts_(0),
104  nlcontacts_graph_( NULL ),
105  min_seq_separation_(min_sequence_separation),
106  cutoffE_(contact_cutoffE),
107  special_region1_(special_region1),
108  special_region2_(special_region2)
109 {
110  residue_nlcontacts_.clear();
111  residue_nlscore_.clear();
112 }
113 
115 
116 
117 void
119  std::string const & key,
120  basic::MetricValueBase * valptr
121 ) const
122 {
123 
124  if ( key == "total_nlcontacts" ) {
125  basic::check_cast( valptr, &total_nlcontacts_, "total_nlcontacts expects to return a Size" );
126  (static_cast<basic::MetricValue<Size> *>(valptr))->set( total_nlcontacts_ );
127 
128  } else if ( (key == "special_region_nlcontacts") || (key == "special_region1_nlcontacts") ) {
129  basic::check_cast( valptr, &special_region1_nlcontacts_, "special_region_nlcontacts expects to return a Size" );
130  (static_cast<basic::MetricValue<Size> *>(valptr))->set( special_region1_nlcontacts_ );
131 
132  } else if ( key == "special_region2_nlcontacts_" ) {
133  basic::check_cast( valptr, &special_region2_nlcontacts_, "special_region2_nlcontacts expects to return a Size" );
134  (static_cast<basic::MetricValue<Size> *>(valptr))->set( special_region2_nlcontacts_ );
135 
136  } else if ( key == "special_region1_intra_nlcontacts_" ) {
137  basic::check_cast( valptr, &special_region1_intra_nlcontacts_, "special_region1_intra_nlcontacts expects to return a Size" );
138  (static_cast<basic::MetricValue<Size> *>(valptr))->set( special_region1_intra_nlcontacts_ );
139 
140  } else if ( key == "special_region1_to_other_nlcontacts_" ) {
141  basic::check_cast( valptr, &special_region1_to_other_nlcontacts_, "special_region1_to_other_nlcontacts expects to return a Size" );
142  (static_cast<basic::MetricValue<Size> *>(valptr))->set( special_region1_to_other_nlcontacts_ );
143 
144  } else if ( key == "region1_region2_nlcontacts_" ) {
145  basic::check_cast( valptr, &region1_region2_nlcontacts_, "regio1_region2_nlcontacts expects to return a Size" );
146  (static_cast<basic::MetricValue<Size> *>(valptr))->set( region1_region2_nlcontacts_ );
147 
148  } else if ( key == "residue_nlcontacts" ) {
149  basic::check_cast( valptr, &residue_nlcontacts_, "residue_nlcontacts expects to return a utility::vector1< Size >" );
150  (static_cast<basic::MetricValue<utility::vector1< Size > > *>(valptr))->set( residue_nlcontacts_ );
151 
152  } else if ( key == "residue_nlscore" ) {
153  basic::check_cast( valptr, &residue_nlscore_, "residue_nlscore expects to return a utility::vector1< Real >" );
154  (static_cast<basic::MetricValue<utility::vector1< Real > > *>(valptr))->set( residue_nlscore_ );
155 
156  } else if ( key == "nlcontacts_graph" ) {
157  basic::check_cast( valptr, &nlcontacts_graph_, "nlcontacts_graph expects to return a core::Graph::GraphOP" );
158  (static_cast<basic::MetricValue< core::graph::GraphOP > *>(valptr))->set( nlcontacts_graph_ );
159 
160  }
161 
162  else {
163  basic::Error() << "NonlocalContactsCalculator cannot compute the requested metric " << key << std::endl;
164  utility_exit();
165  }
166 
167 } //lookup
168 
169 
170 
173 {
174 
175 
176  basic::Error() << "NonlocalContactsCalculator cannot compute metric " << key << std::endl;
177  utility_exit();
178  return "";
179 
180 } //print
181 
182 
183 void
185 {
186  using namespace core::scoring;
187 
188  residue_nlcontacts_.clear();
189  residue_nlscore_.clear();
190  residue_nlcontacts_.resize( this_pose.total_residue(), 0 );
191  residue_nlscore_.resize( this_pose.total_residue(), 0.0 );
192  total_nlcontacts_ = 0;
197 
199 
200  EnergyMap cur_weights = this_pose.energies().weights();
201 
202  for( core::Size i = 1; i <= this_pose.total_residue(); ++i ){
203 
204  if( ! this_pose.residue_type( i ).is_protein() ) continue;
205  //get the node for this residue in the energy graph
207  egraph_it != this_pose.energies().energy_graph().get_node( i )->const_upper_edge_list_end(); ++egraph_it){
208 
209  core::Size other_res = (*egraph_it)->get_other_ind( i );
210 
211  if( ( ( other_res - i ) <= min_seq_separation_ ) || !this_pose.residue_type( other_res ).is_protein() ) continue;
212 
213  //TR << other_res << " - " << i << " is bigger than " << min_seq_separation_ << std::endl;
214  //downcast to energy edge
215  EnergyEdge const * Eedge = static_cast< EnergyEdge const * > (*egraph_it);
216 
217  //to do: get the long range energies
218 
219  core::Real resresE( Eedge->dot( cur_weights ) );
220  core::Real resresE_half( resresE / 2);
221 
222  residue_nlscore_[ i ] += resresE_half;
223  residue_nlscore_[ other_res ] += resresE_half;
224 
225  if( resresE <= cutoffE_ ){
226 
227  TR.Debug << "residues " << i << " and " << other_res << " make nonlocal contact, interactionE is " << resresE << std::endl;
228 
230  residue_nlcontacts_[i]++;
231  residue_nlcontacts_[other_res]++;
232  nlcontacts_graph_->add_edge( i, other_res );
233 
234  bool i_in_region1( special_region1_.find(i) != special_region1_.end() );
235  bool i_in_region2( special_region2_.find(i) != special_region2_.end() );
236 
237  bool other_in_region1( special_region1_.find( other_res ) != special_region1_.end() );
238  bool other_in_region2( special_region2_.find( other_res ) != special_region2_.end() );
239 
240  if( i_in_region1 || other_in_region1 ) special_region1_nlcontacts_++;
241 
242  if( i_in_region2 || other_in_region2 ) special_region2_nlcontacts_++;
243 
244  if( ( i_in_region1 && other_in_region2 ) || ( i_in_region2 && other_in_region1 ) ) region1_region2_nlcontacts_++;
245  else if( i_in_region1 && other_in_region1 ) special_region1_intra_nlcontacts_++;
246 
247 
248  } //if residues form nonlocal contact
249 
250  } //neighbors of this residue
251  } //loop over residues
252 
254 
255  //some optional debug output. done at the end to prevent tracer if evaluations in normal production runs
256  if( basic::options::option[basic::options::OptionKeys::out::level] >= basic::t_debug ){
257  for( core::Size i = 1; i <= this_pose.total_residue(); ++i) TR.Debug << "Residue " << i << " makes " << residue_nlcontacts_[i] << " nonlocal contacts and has a total nonlocal interaction energy of " << residue_nlscore_[i] << "." << std::endl;
258  }
259 } //recompute
260 
261 
262 } //namespace pose_metric_calculators
263 } //namespace toolbox
264 } //namespace protocols