Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ScoreCutoffFilter.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/filters/ScoreCutoffFilter.cc
11 /// @brief
12 /// @detailed
13 /// Contains currently:
14 ///
15 ///
16 /// @author Florian Richter
17 
18 // Unit Headers
21 
22 // Package Headers
23 
24 // Project Headers
26 #include <core/pose/Pose.hh>
27 #include <core/types.hh>
28 // AUTO-REMOVED #include <core/scoring/ScoreFunction.hh>
29 #include <core/scoring/Energies.hh>
32 #include <basic/Tracer.hh>
33 // AUTO-REMOVED #include <protocols/moves/DataMap.hh>
34 // ObjexxFCL Headers
35 #include <ObjexxFCL/format.hh>
36 
37 // Utility headers
38 #include <utility/tag/Tag.hh>
39 
40 #include <utility/vector0.hh>
41 #include <utility/vector1.hh>
42 
43 //Auto Headers
45 
46 
47 
48 //// C++ headers
49 static basic::Tracer tr("protocols.filters.ScoreCutoffFilter");
50 
51 namespace protocols {
52 namespace simple_filters {
53 
54 
56  parent("ScoreCutoffFilter"), cutoff_( 0.0 ), report_residue_pair_energies_( false ), total_score_( true ), unweighted_( false )
57 {
59  positions_.clear();
60 }
61 
63  parent("ScoreCutoffFilter"),cutoff_(cutoff_in), report_residue_pair_energies_( false ), total_score_( true ), unweighted_( false )
64 {
66  positions_.clear();
67 }
68 
69 
70 void
72 {
73  score_types_.clear();
74  add_score_type( scotype );
75 }
76 
77 void
79 {
80  using namespace core::scoring;
81 
82  if( scotype == total_score ){
83 
84  total_score_ = true;
85  if ( score_types_.size() != 0 ) {
86  if( (score_types_.size() > 1) || ( score_types_[1] != total_score ) ){
87 
88  score_types_.clear();
89  tr << "WARNING: setting score_type to total score even though other score types have previously been set. these will be erased." << std::endl;
90  }
91  }
92  }
93  else{
94 
95  if( total_score_ == true ){
96 
97  score_types_.clear();
98  total_score_ = false;
99  }
100  }
101 
102  score_types_.push_back( scotype );
103 }
104 
105 
106 bool
108 
109  core::Real cur_score = get_score( pose );
110 
111  if ( cur_score <= cutoff() ) return true;
112 
113  return false;
114 
115 } // apply_filter
116 
117 
120 
121  using namespace core::scoring;
122  EnergyMap emap;
123 
124  assert( score_types_.size() > 0 );
125 
126  if ( positions_.size() == 0 ) { //means we're interested in pose totals
127 
129  sco_it != score_types_.end(); ++sco_it ){
130 
131  emap[ *sco_it ] = pose.energies().total_energies()[ *sco_it ];
132  }
133  }
134 
135  else {
136  for ( utility::vector1< core::Size >::const_iterator pos_it = positions_.begin(); pos_it != positions_.end(); ++pos_it ) {
137 
139  sco_it != score_types_.end(); ++sco_it ){
140  emap[ *sco_it ] += pose.energies().residue_total_energies( *pos_it )[ *sco_it ];
141  }
142  }
143  } // else
144 
145  //now accumulate into score: total, unweighted, or weighted
146  if ( total_score_ ) return emap[ total_score ];
147  if ( unweighted_ ) return emap.sum();
148  return emap.dot( pose.energies().weights() );
149 
150 }
151 
152 void
154 {
155  if (tag->hasOption("report_residue_pair_energies")) {
156  if( tag->getOption<core::Size>("report_residue_pair_energies",0) == 1 ) report_residue_pair_energies_ = true;
157  }
158  if (tag->hasOption("cutoff")) {
159  cutoff_ = tag->getOption<core::Real>("cutoff", 10000.0 );
160  }
161 }
162 
163 void
164 ScoreCutoffFilter::report( std::ostream & ostr, core::pose::Pose const & pose ) const
165 {
167  else {
168  using namespace core::scoring;
170  sco_it != score_types_.end(); ++sco_it ) {
171  EnergyMap emap;
172  emap[ *sco_it ] = pose.energies().total_energies()[ *sco_it ];
173  ostr << " Scoretype: " << *sco_it << " score: " << emap.sum() << ", cutoff: " << cutoff_ << std::endl;
174  }
175  }
176 }
177 
178 void
179 ScoreCutoffFilter::output_residue_pair_energies( std::ostream & ostr, core::pose::Pose const & pose ) const
180 {
181  using namespace core::scoring;
182  core::Size field_width( 10 ), last_active_sr_st(0);
184  EnergyMap const & weights( pose.energies().weights() );
185  for( core::Size i = 1; i <= n_score_types; ++i ){
186  if( weights[ ScoreType(i)] != 0 ) active_st.push_back( ScoreType(i) );
187  if( i == n_shortranged_2b_score_types ) last_active_sr_st = active_st.size();
188  }
190  for( Size lr = 1; lr <= methods::n_long_range_types; lr++){
192  LREnergyContainerCOP lrec = pose.energies().long_range_container( lr_type );
193  if( !lrec ) continue;
194  if( !lrec->empty() ) active_lr_e.push_back( lrec );
195  }
196 
197  ostr << "\nResResE " << ObjexxFCL::fmt::A( field_width, "Res1" ) << " " << ObjexxFCL::fmt::A(field_width, "Res2") << " ";
198  for( core::Size i =1; i <= active_st.size(); ++i) ostr << ObjexxFCL::fmt::A( field_width , name_from_score_type( active_st[i] ) ) << " ";
199  ostr << ObjexxFCL::fmt::A( field_width , "total" )<< " \n";
200 
201  ostr << "ResResE " << ObjexxFCL::fmt::A( field_width, "nonzero" ) << " " << ObjexxFCL::fmt::A( field_width, "weights" ) << " ";
202  for( core::Size i =1; i <= active_st.size(); ++i) ostr << ObjexxFCL::fmt::F( field_width, 2, weights[ active_st[ i ] ] ) << " ";
203  ostr << ObjexxFCL::fmt::A( field_width , "NA" ) << "\n";
204 
205  EnergyGraph const & egraph( pose.energies().energy_graph() );
206 
207  for( core::Size res1 = 1; res1 <= pose.total_residue(); ++res1 ){
208  std::string res1name( pose.residue_type( res1 ).name1() + utility::to_string( res1 ) );
209  std::map< core::Size, EnergyMap > upper_interactions;
210 
211  //1st, get short range enegires
212  for( core::graph::EdgeListConstIterator egraph_it = egraph.get_energy_node( res1 )->const_upper_edge_list_begin();
213  egraph_it != egraph.get_energy_node( res1 )->const_upper_edge_list_end(); ++egraph_it){
214  core::Size other_ind( (*egraph_it)->get_other_ind( res1 ) );
215  upper_interactions.insert( std::pair< Size, EnergyMap >(other_ind, EnergyMap() ) );
216  EnergyMap & this_emap( upper_interactions.find( other_ind )->second );
217  EnergyEdge const * eedge( static_cast< EnergyEdge const * >(*egraph_it));
218 
219  for( core::Size i =1; i <= last_active_sr_st; ++i) this_emap[ active_st[i] ] = ((*eedge)[ active_st[i] ]);
220 
221  } //loop over all short range upper edges for res
222 
223  //2nd, get long range energies
224  for( Size lr = 1; lr <= active_lr_e.size(); lr++){
225  for ( ResidueNeighborConstIteratorOP rni( active_lr_e[lr]->const_upper_neighbor_iterator_begin( res1 ) );
226  *rni != *( active_lr_e[lr]->const_upper_neighbor_iterator_end( res1 ) ); ++(*rni) ) {
227  EnergyMap lr_emap;
228  core::Size other_ind( rni->upper_neighbor_id() );
229  rni->retrieve_energy( lr_emap );
230  std::map< core::Size, EnergyMap >::iterator map_it = upper_interactions.find( other_ind );
231  if( map_it == upper_interactions.end() ) upper_interactions.insert( std::pair<Size, EnergyMap >(other_ind, lr_emap ) );
232  else map_it->second += lr_emap;
233  } // loop over all lr interactions for this res
234  } //loop over all lr energies
235 
236  //3. finally output shit
237  for( std::map< core::Size, EnergyMap >::const_iterator map_it = upper_interactions.begin(); map_it != upper_interactions.end(); ++map_it){
238  core::Size res2 = map_it->first;
239  EnergyMap const & this_emap( map_it->second );
240  std::string res2name( pose.residue_type( res2 ).name1() + utility::to_string( res2 ) );
241  ostr << "ResResE " << ObjexxFCL::fmt::A( field_width, res1name ) << " " << ObjexxFCL::fmt::A( field_width, res2name ) << " ";
242  core::Real totscore(0.0);
243  for( core::Size i =1; i <= active_st.size(); ++i){
244  core::Real score( weights[ active_st[i] ] * this_emap[ active_st[i] ] );
245  totscore += score;
246  ostr << ObjexxFCL::fmt::F( field_width, 2, score) << " ";
247  }
248  ostr << ObjexxFCL::fmt::F( field_width, 2, totscore) << "\n";
249  }
250  } //loop over all residues
251 
252 }
253 
256 
258 ScoreCutoffFilterCreator::keyname() const { return "ScoreCutoffFilter"; }
259 
260 
261 
262 } // filters
263 } // protocols