Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResidueSetChainEnergyFilter.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/ResidueSetChainEnergyFilter.cc
11 /// @brief
12 /// @author Chris King (chrisk1@uw.edu)
13 
14 
15 //Unit Headers
18 
19 //Project Headers
20 #include <basic/Tracer.hh>
25 #include <core/scoring/Energies.hh>
27 #include <core/pose/Pose.hh>
28 #include <utility/tag/Tag.hh>
30 #include <utility/exit.hh>
31 #include <ObjexxFCL/FArray1D.hh>
32 #include <ObjexxFCL/FArray1D.fwd.hh>
33 #include <ObjexxFCL/format.hh>
39 #include <utility/excn/Exceptions.hh>
40 #include <core/pose/selection.hh>
41 
42 namespace protocols{
43 namespace simple_filters {
44 
45 using namespace core;
46 using namespace core::scoring;
47 using namespace ObjexxFCL::fmt;
48 
49 static basic::Tracer TR( "protocols.simple_filters.ResidueSetChainEnergyFilter" );
50 
53 
55 ResidueSetChainEnergyFilterCreator::keyname() const { return "ResidueSetChainEnergy"; }
56 
57 //default ctor
59 protocols::filters::Filter( "ResidueSetChainEnergy" )
60 {}
61 
62 //full ctor, default ctor defined in header file
65  core::scoring::ScoreType const score_type,
66  core::Real const score_type_threshold,
67  std::string const string_resnums,
68  core::Size const chain
69 ) :
70 protocols::filters::Filter( "ResidueSetChainEnergy" )
71 {
72  score_type_ = score_type;
73  score_type_threshold_ = score_type_threshold;
74  scorefxn_ = scorefxn->clone();
75  string_resnums_ = string_resnums;
76  chain_ = chain;
77 }
78 
80 
81 void
83 {
84  using namespace core::scoring;
85 
86  std::string const scorefxn_name( tag->getOption<std::string>( "scorefxn", "score12" ) );
87  // scorefxn_ = new ScoreFunction( *(data.get< ScoreFunction * >( "scorefxns", scorefxn_name )) );
88  scorefxn_ = data.get< ScoreFunction * >( "scorefxns", scorefxn_name )->clone();
89 
90  score_type_ = core::scoring::score_type_from_name( tag->getOption<std::string>( "score_type", "total_score" ) );
91  if( ! tag->hasOption( "threshold" ) ) throw utility::excn::EXCN_RosettaScriptsOption("Must specify 'threshold' for ResidueSetChainEnergyFilter.");
92  score_type_threshold_ = tag->getOption< core::Real >( "threshold" );
93 
94  TR<< "filter for score_type "<< score_type_ <<" with threshold "<< score_type_threshold_ << std::endl;
95 
96  string_resnums_ = tag->getOption< std::string >( "resnums" );// these are kept in memory until the pose is available (at apply time)
97  chain_ = tag->getOption< core::Size >( "chain", 0 );
98 }
99 
100 bool
102  core::Real const score( compute( pose ) );
103  TR << "score " << core::scoring::ScoreTypeManager::name_from_score_type( score_type_ ) << " is " << score << ". ";
104  if( score <= score_type_threshold_ ) {
105  TR<<"passing." << std::endl;
106  return true;
107  }
108  else {
109  TR<<"failing."<<std::endl;
110  return false;
111  }
112 }
113 
114 void
115 ResidueSetChainEnergyFilter::report( std::ostream & out, core::pose::Pose const & pose ) const {
116  out<<"Weighted score of "<<core::scoring::ScoreTypeManager::name_from_score_type( score_type_ )<<" "<<compute( pose )<<'\n';
117 }
118 
121  return( compute( pose ) );
122 }
123 
126  core::pose::Pose const & pose
127 ) const {
128 
129  using namespace core::pose;
130  using namespace core::scoring;
131 
132  //copy the pose so we can set a possibly new scorefxn in it (input to apply is const!)
133  Pose in_pose( pose );
134 
135  // make sure that scoring weights are compatible with pose's residue type set
136  // check centroid case
137  //TODO: this is a hacky and not robust way of checking for centroid!
138  if( ( ( *scorefxn_ )[ fa_rep ] == 0.0 && ( *scorefxn_ )[ fa_atr ] == 0.0 ) // full atom terms are off
139  && ( ( *scorefxn_ )[ interchain_vdw ] > 0.0 || ( *scorefxn_ )[ vdw ] > 0.0 ) ) // a centroid term is on
140  {
141  if( in_pose.is_fullatom() ) { // but pose is full atom
143  }
144  }
145  else { // full atom case
146  if( in_pose.is_centroid() ) { // but pose is centroid
148  }
149  }
150 
151  scorefxn_->score( in_pose );
152 
154 // core::Size chain_seqpos_begin( in_pose.conformation().chain_begin( chain_ ) );
155 // core::Size chain_seqpos_end( in_pose.conformation().chain_end( chain_ ) );
156  // the neighbor/energy links
157  EnergyGraph & energy_graph( in_pose.energies().energy_graph() );
158  core::Real score( 0. );
159  for( core::Size i_res_vec = 1; i_res_vec <= res_set_vec.size(); ++i_res_vec ){
160  Size iseq1( res_set_vec[ i_res_vec ] );
161  assert( iseq1 <= in_pose.total_residue() );
162  //TR<< "Summing energies: seqpos: " << iseq1 << std::endl;
163  //search over energy edges
164  for( graph::Graph::EdgeListIter el_iter = energy_graph.get_node( iseq1 )->edge_list_begin();
165  el_iter != energy_graph.get_node( iseq1 )->edge_list_end(); ++el_iter ){
166  EnergyEdge * edge( static_cast< EnergyEdge *> ( *el_iter ) );
167  //the other seqpos connected to this edge
168  core::Size iseq2( edge->get_first_node_ind() );
169  if( iseq2 == iseq1 ) iseq2 = edge->get_second_node_ind();
170  //TR<< "set seqpos: " << iseq1 << " chain: " << in_pose.chain( iseq1 ) << " :: chain seqpos: " << iseq2 << " chain: " << in_pose.chain( iseq2 ) << std::endl;
171  //skip if iseq2 is not in the chain we care about
172  if( static_cast< core::Size >( in_pose.chain( iseq2 ) ) != chain_ ) continue;
173 
174  // the pair energies cached in the link
175  EnergyMap const & emap( edge->fill_energy_map() );
176  if( score_type_ == total_score ) score += emap.dot( scorefxn_->weights() );
177  else score += emap[ ScoreType( score_type_ ) ];
178  }
179  }
180 
181  //get wt for unweighted score
182  core::Real weight;
183  if( score_type_ == total_score ) weight = 1;
184  else weight = scorefxn_->get_weight( ScoreType( score_type_ ) );
185  core::Real const weighted_score( weight * score );
186  return( weighted_score );
187 }
188 
189 }
190 }