Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResidueIEFilter.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/simple_filters/ResidueIEFilter.cc
11 /// @brief
12 /// @author Sagar Khare (khares@u.washington.edu)
13 
16 
18 #include <basic/Tracer.hh>
19 #include <utility/tag/Tag.hh>
22 #include <core/scoring/Energies.hh>
24 #include <core/pose/Pose.hh>
26 #include <utility/vector1.hh>
27 #include <boost/foreach.hpp>
28 #include <core/pose/selection.hh>
30 #define foreach BOOST_FOREACH
31 
32 namespace protocols {
33 namespace simple_filters {
34 
35 static basic::Tracer tr( "protocols.simple_filters.ResidueIEFilter" );
36 
39 
41 ResidueIEFilterCreator::keyname() const { return "ResidueIE"; }
42 
44  utility::vector1< core::Size > const resnums,
45  std::string const restype,
47  core::scoring::ScoreType const score_type,
48  core::Real const threshold,
49  bool const whole_pose,
50  bool const whole_interface,
51  core::Size const rb_jump,
52  core::Real const interface_distance_cutoff,
53  core::Real max_penalty,
54  core::Real penalty_factor
55  ) :
56  filters::Filter( "ResidueIE" ),
57  resnums_( resnums ),
58  restype_ (restype),
59  score_type_( score_type ),
60  threshold_( threshold ),
61  whole_pose_ ( whole_pose ),
62  whole_interface_ ( whole_interface ),
63  rb_jump_ ( rb_jump ),
64  interface_distance_cutoff_ ( interface_distance_cutoff ),
65  max_penalty_ (max_penalty),
66  penalty_factor_ (penalty_factor)
67  {
68  using namespace core::scoring;
69 
70  if( scorefxn ) scorefxn_ = new core::scoring::ScoreFunction( *scorefxn );
71  if( score_type_ != total_score ) {
72  core::Real const old_weight( scorefxn_->get_weight( score_type_ ) );
73  scorefxn_->reset();
74  scorefxn_->set_weight( score_type_, old_weight );
75 
76  }
77  use_resE_ = false;
78  }
79 
81  Filter( init ), resnums_( init.resnums_ ),
82  restype_( init.restype_ ),
83  score_type_( init.score_type_ ),
84  threshold_( init.threshold_ ),
85  whole_pose_ (init.whole_pose_),
87  rb_jump_ (init.rb_jump_),
89  max_penalty_ ( init.max_penalty_),
91  use_resE_ ( init.use_resE_ )
92 {
93  using namespace core::scoring;
95 }
96 
99  return scorefxn_;
100 }
101 
102 void
105 }
106 
109  return score_type_;
110 }
111 
112 void
115 }
116 
119  return threshold_;
120 }
121 
122 void
124  threshold_ = th;
125 }
126 
129  return resnums_;
130 }
131 
132 void
134  resnums_ = rn;
135 }
136 
138 
139 void
141 {
142  using namespace core::scoring;
143  std::string const scorefxn_name( tag->getOption<std::string>( "scorefxn", "score12" ) );
144  scorefxn_ = data.get< ScoreFunction * >( "scorefxns", scorefxn_name )->clone();
145  score_type_ = core::scoring::score_type_from_name( tag->getOption<std::string>( "score_type", "total_score" ) );
146  threshold_ = tag->getOption<core::Real>( "energy_cutoff", 0.0 );
147  whole_pose_ = tag->getOption<bool>( "whole_pose" , 0 );
148  whole_interface_ = tag->getOption<bool>( "interface" , 0 );
149  rb_jump_ = tag->getOption<core::Size>( "jump_number", pose.num_jump() );
150  interface_distance_cutoff_ = tag->getOption<core::Real>( "interface_distance_cutoff" , 8.0 );
151  restype_ = tag->getOption<std::string>( "restype3", "TRP" );
152  penalty_factor_ = tag->getOption<core::Real>( "penalty_factor", 1.0 );
153  max_penalty_ = tag->getOption<core::Real>( "max_penalty", 1000.0 );
154 
155  if(tag->hasOption("residues")) {
156  tr << " the tag residues is seen by the program" << std::endl;
157  resnums_ = core::pose::get_resnum_list(tag, "residues", pose);
158 
159  if(resnums_.empty()){
160  whole_pose_=1;
162  tr<< "Failed to parse residues: " << tag->getOption<std::string> ("residues") << ". Using whole pose." << std::endl;
163  }
164  else
165  {
166  whole_pose_=0;
168  }
169  }
170 
171  runtime_assert(tag->hasOption("residues") || whole_pose_ || whole_interface_);
172 
173  use_resE_ = tag->getOption<bool>( "use_resE" , 0 );
174 }
175 
176 bool
178 {
179  core::Real const penalty( compute( pose ) );
180  if (penalty>max_penalty_) return false;
181  return true;
182 }
183 
184 
185 
186 void
187 ResidueIEFilter::report( std::ostream & out, core::pose::Pose const & pose ) const
188 {
189  core::Real const penalty( compute( pose ) );
190  out << "Total penalty for restype "<< restype_ << "is "<< penalty << std::endl;
191 }
192 
193 
196 {
197 
198  core::Real const penalty( compute( pose ) );
199  return( penalty );
200 }
201 
202 
203 
206 {
207  using namespace core::scoring;
208  using namespace core::graph;
209 
210 
211  if ( whole_interface_)
212  {
213  tr << "Detecting target resnums from interface." << std::endl;
214  resnums_.clear();
215 
216  if ( pose.conformation().num_chains() < 2 ) {
217  tr << "pose must contain at least two chains!" << std::endl;
218  return false;
219  }
220 
221  core::pose::Pose in_pose = pose;
222 
223  (*scorefxn_)(in_pose);
225 
226  in_pose.update_residue_neighbors();
227 
228  interface_obj.distance( interface_distance_cutoff_ );
229  interface_obj.calculate( in_pose );
230  for ( core::Size resnum = 1; resnum <= pose.total_residue(); ++resnum)
231  {
232  if ( in_pose.residue(resnum).is_protein() && interface_obj.is_interface( resnum ) && (in_pose.residue_type(resnum).name3() == restype_) )
233  {
234  resnums_.push_back( resnum );
235  }
236  }
237  }// whole_interface_
238 
239  else if ( whole_pose_ )
240  {
241  tr << "Detecting target resnums from whole pose." << std::endl;
242  resnums_.clear();
243 
244  core::pose::Pose in_pose = pose;
245  for ( core::Size resnum = 1; resnum <= in_pose.total_residue(); ++resnum)
246  {
247  if ( in_pose.residue(resnum).is_protein() && (in_pose.residue_type(resnum).name3() == restype_) ) resnums_.push_back( resnum );
248  }
249  }//whole_pose_
250 
251  std::unique( resnums_.begin(), resnums_.end() );
252  tr << "The following residues will be considered for interaction energy calculation:"<< std::endl;
253  foreach (core::Size const res, resnums_){
254  tr << pose.residue_type( res ).name3() << res <<" + ";
255  if (!(pose.residue_type( res ).name3() == restype_)) {
256  tr << "Residue " << res << " in pose is of type "<< pose.residue_type( res ).name3() << ". Requested restype3 is "<< restype_<<". Skipping!"<<std::endl;
257  return false;
258  }
259  }
260 
261  core::pose::Pose in_pose = pose;
262  (*scorefxn_)(in_pose);
263  core::Real penalty (0.0);
264  EnergyMap const curr_weights = in_pose.energies().weights();
265 
266  if (resnums_.size() == 0) {
267  tr << "No residues found. Skipping calculation."<< std::endl;
268 
269  return (0.0);
270  }
271 
272  foreach (core::Size const res, resnums_)
273  {
274 
275 
276  core::Real res_intE (0.0);
277 
278  if (use_resE_)
279  {
280  protocols::simple_filters::EnergyPerResidueFilter const eprf(res, scorefxn_, score_type_, 100000.0/*dummy threshold*/);
281  res_intE = eprf.compute( pose );
282  }
283  else
284  {
285  core::Real res_intE_samechain (0.0);
286  core::Real res_intE_differentchain (0.0);
287 
288  int res_chain = in_pose.chain(res);
289 
290  //Fill residue energies by traversing energy graph
291  for ( EdgeListConstIterator egraph_it = in_pose.energies().energy_graph().get_node( res )->const_edge_list_begin(); egraph_it != in_pose.energies().energy_graph().get_node( res )->const_edge_list_end(); ++egraph_it)
292  {
293  EnergyEdge const * Eedge = static_cast< EnergyEdge const * > (*egraph_it);
294  res_intE += Eedge->dot( curr_weights );
295 
296 
297 
298  if (in_pose.chain(Eedge->get_other_ind(res)) == res_chain)
299  {
300  res_intE_samechain += Eedge->dot( curr_weights );
301  }
302  else
303  {
304  res_intE_differentchain += Eedge->dot( curr_weights );
305  }
306  }//for each egraph_it
307  tr << "Residue "<< pose.residue_type( res ).name3()<<res<< " has a intra-chain interaction energy "<< res_intE_samechain << std::endl;
308  tr << "Residue "<< pose.residue_type( res ).name3()<<res<< " has a inter-chain interaction energy "<< res_intE_differentchain << std::endl;
309  }
310 
311  tr << "Residue "<< pose.residue_type( res ).name3()<<res<< " has an (interaction) energy "<< res_intE <<", threshold is "<< threshold_<<" and penalty is ";
312 
313  if (res_intE > threshold_)
314  {
315  penalty+= (res_intE - threshold_);
316  tr<< (res_intE - threshold_) << std::endl;
317  }
318  else
319  {
320  tr << " 0"<<std::endl;
321  }
322  } //foreach res
323 
324  return( penalty * penalty_factor_ );
325 }
326 
327 }
328 }