Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InterfaceDeltaEnergeticsCalculator.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 core/pose/metrics/simple_metrics/InterfaceDeltaEnergeticsCalculator.cc
11 /// @brief InterfaceDeltaEnergeticsCalculator class
12 /// @author John Karanicolas
13 /// @author Roland A Pache
14 
15 
16 // Unit headers
19 #include <core/pose/Pose.hh>
21 #include <core/scoring/Energies.hh>
25 #include <core/scoring/methods/Methods.hh> //for long range energies
26 #include <core/scoring/LREnergyContainer.hh> //long range energies
27 
28 // Utility headers
29 #include <basic/MetricValue.hh>
30 #include <basic/Tracer.hh>
31 #include <utility/exit.hh>
32 #include <utility/string_util.hh>
33 
34 #include <cassert>
35 
36 #include <utility/vector1.hh>
37 
38 
39 using namespace core;
40 using namespace core::pose;
41 using namespace core::pose::metrics;
42 using namespace utility;
43 
44 namespace core{
45 namespace pose {
46 namespace metrics {
47 namespace simple_calculators {
48 
49 
50 // preferred constructor - use an existing InterfaceNeighborDefinitionCalculator
51 InterfaceDeltaEnergeticsCalculator::InterfaceDeltaEnergeticsCalculator( std::string const & NameOfInterfaceNeighborDefinitionCalculator ) :
53  name_of_InterfaceNeighborDefinitionCalculator_(NameOfInterfaceNeighborDefinitionCalculator)
54 {
56  basic::Error() << "Tried to tie InterfaceDeltaEnergeticsCalculator to InterfaceNeighborDefinitionCalculator " <<
57  name_of_InterfaceNeighborDefinitionCalculator_ << " but this calculator does not exist." << std::endl;
58  utility_exit();
59  }
60 }
61 
62 // preferred alternative constructor - use an existing InterfaceNeighborDefinitionCalculator and define a set of score types to ignore
63  InterfaceDeltaEnergeticsCalculator::InterfaceDeltaEnergeticsCalculator( std::string const & NameOfInterfaceNeighborDefinitionCalculator, utility::vector1<core::scoring::ScoreType> const & score_types_to_ignore ) :
65  name_of_InterfaceNeighborDefinitionCalculator_(NameOfInterfaceNeighborDefinitionCalculator)
66 {
67  score_types_to_ignore_=score_types_to_ignore;
69  basic::Error() << "Tried to tie InterfaceDeltaEnergeticsCalculator to InterfaceNeighborDefinitionCalculator " <<
70  name_of_InterfaceNeighborDefinitionCalculator_ << " but this calculator does not exist." << std::endl;
71  utility_exit();
72  }
73 }
74 
75 
76 // less preferred constructor - creates a new InterfaceNeighborDefinitionCalculator
79 {
80  name_of_InterfaceNeighborDefinitionCalculator_ = "IEC_private_IDC_" + to_string(chain1_number) + "_" + to_string(chain2_number);
82  basic::Error() << "InterfaceDeltaEnergeticsCalculator cannot create a new InterfaceNeighborDefinitionCalculator named " <<
84  utility_exit();
85  }
89 }
90 
91 
92 // less preferred constructor - creates a new InterfaceNeighborDefinitionCalculator
93 InterfaceDeltaEnergeticsCalculator::InterfaceDeltaEnergeticsCalculator( char const chain1_letter, char const chain2_letter ) :
95 {
96  name_of_InterfaceNeighborDefinitionCalculator_ = "IEC_private_IDC_" + to_string(chain1_letter) + "_" + to_string(chain2_letter);
98  basic::Error() << "InterfaceDeltaEnergeticsCalculator cannot create a new InterfaceNeighborDefinitionCalculator named " <<
100  utility_exit();
101  }
105 }
106 
107 
108 void InterfaceDeltaEnergeticsCalculator::lookup( std::string const & key, basic::MetricValueBase * valptr ) const {
109 
110  if ( key == "weighted_total" ) {
111  basic::check_cast( valptr, &weighted_total_, "weighted_total expects to return a Real" );
112  (static_cast<basic::MetricValue<Real> *>(valptr))->set( weighted_total_ );
113 
114  } else {
116  Real scoreval = delta_energies_unweighted_[ requested_scoretype ] * weights_[ requested_scoretype ];
117  basic::check_cast( valptr, &scoreval, "Interface "+key+" expects to return a Real" );
118  (static_cast<basic::MetricValue<Real> *>(valptr))->set( scoreval );
119  }
120 
121 }
122 
123 
125 
126  if ( key == "weighted_total" ) {
127  return utility::to_string( weighted_total_ );
128  } else {
130  Real scoreval = delta_energies_unweighted_[ requested_scoretype ] * weights_[ requested_scoretype ];
131  return utility::to_string( scoreval );
132  }
133 
134  basic::Error() << "This Calculator cannot compute metric " << key << std::endl;
135  utility_exit();
136  return "";
137 
138 }
139 
140 
142 
143  // JK MAKE SURE THAT THE GRAPH STATE HERE IS "GOOD"
144 
145  // Get the first and last resnum of each chain, using name_of_InterfaceNeighborDefinitionCalculator_
146  basic::MetricValue<Size> mv_size;
147  this_pose.metric(name_of_InterfaceNeighborDefinitionCalculator_,"first_chain_first_resnum",mv_size);
148  Size ch1_begin_num = mv_size.value();
149  this_pose.metric(name_of_InterfaceNeighborDefinitionCalculator_,"first_chain_last_resnum",mv_size);
150  Size ch1_end_num = mv_size.value();
151  this_pose.metric(name_of_InterfaceNeighborDefinitionCalculator_,"second_chain_first_resnum",mv_size);
152  Size ch2_begin_num = mv_size.value();
153  this_pose.metric(name_of_InterfaceNeighborDefinitionCalculator_,"second_chain_last_resnum",mv_size);
154  Size ch2_end_num = mv_size.value();
155 
156  // Clear the energy-holders, get the (unweighted) energies from the pose
158  scoring::EnergyGraph const & energy_graph( this_pose.energies().energy_graph() );
159 
160  // Loop over interactions across the interface
161  for ( Size i = ch1_begin_num; i <= ch1_end_num; ++i ) {
163  iru = energy_graph.get_node(i)->const_upper_edge_list_begin(),
164  irue = energy_graph.get_node(i)->const_upper_edge_list_end();
165  iru != irue; ++iru ) {
166  const scoring::EnergyEdge * edge( static_cast< const scoring::EnergyEdge *> (*iru) );
167  Size const j( edge->get_second_node_ind() );
168  if ( ( j >= ch2_begin_num ) && ( j <= ch2_end_num ) ) {
170  }
171  }
172  }
173 
174  // Graph is asymmetric, so switch i/j and redo
175  for ( Size i = ch2_begin_num; i <= ch2_end_num; ++i ) {
177  iru = energy_graph.get_node(i)->const_upper_edge_list_begin(),
178  irue = energy_graph.get_node(i)->const_upper_edge_list_end();
179  iru != irue; ++iru ) {
180  const scoring::EnergyEdge * edge( static_cast< const scoring::EnergyEdge *> (*iru) );
181  Size const j( edge->get_second_node_ind() );
182  if ( ( j >= ch1_begin_num ) && ( j <= ch1_end_num ) ) {
184  }
185  }
186  }
187 
188  //let's not forget the long range energies
189  for( Size lr = 1; lr <= scoring::methods::n_long_range_types; lr++){
191  scoring::LREnergyContainerCOP lrec = this_pose.energies().long_range_container( lr_type );
192  //runtime_assert( lrec );
193  if( !lrec ) continue;
194  if( lrec->empty() ) continue;
195 
196  for( Size i = ch1_begin_num; i <= ch1_end_num; ++i ){
198  rni = lrec->const_upper_neighbor_iterator_begin( i );
199  *rni != *( lrec->const_upper_neighbor_iterator_end( i ) );
200  ++(*rni) ) {
201  Size j = rni->upper_neighbor_id();
202  if( ( j >= ch2_begin_num ) && ( j <= ch2_end_num ) ) {
203  scoring::EnergyMap emap;
204  rni->retrieve_energy( emap );
206  }
207  }
208  } //loop over chain 1 residues
209 
210  for( Size i = ch2_begin_num; i <= ch2_end_num; ++i ){
212  rni = lrec->const_upper_neighbor_iterator_begin( i );
213  *rni != *( lrec->const_upper_neighbor_iterator_end( i ) );
214  ++(*rni) ) {
215  Size j = rni->upper_neighbor_id();
216  if( ( j >= ch1_begin_num ) && ( j <= ch1_end_num ) ) {
217  scoring::EnergyMap emap;
218  rni->retrieve_energy( emap );
220  }
221  }
222  } //loop over chain 2 residues
223 
224  } //loop over long range energy types
225 
226  // Save the most recently used weights
227  weights_ = this_pose.energies().weights();
228  //set weights of score types to ignore to 0
230  weights_[*cit]=0.0;
231  }
232  //Save the total (weighted) delta score
234 
235  //debug stuff
236  //std::cerr << "intef Delta E calc has following non-zero values: ";
237  //for( Size ii = 1; ii <= scoring::n_score_types; ii++ ){
238  // scoring::ScoreType scotype = scoring::ScoreType( ii );
239  // if( weights_[scotype] != 0 ){
240  // std::cerr << scoring::name_from_score_type( scotype ) << " " << delta_energies_unweighted_[ scotype ] * weights_[ scotype ] << "; ";
241  // }
242  //}
243  //std::cerr << " you happy?" << std::endl;
244  //debug stuff over
245 }
246 
247 } // simple_calculators
248 } // metrics
249 } // pose
250 } // core