Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ScoreTypeFilter.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/ScoreTypeFilter.cc
11 /// @brief
12 /// @author Sarel Fleishman (sarelf@u.washington.edu), Jacob Corn (jecorn@u.washington.edu)
13 
14 
15 //Unit Headers
18 
19 //Project Headers
20 #include <basic/Tracer.hh>
25 #include <core/scoring/Energies.hh>
26 #include <core/pose/Pose.hh>
27 #include <utility/tag/Tag.hh>
29 #include <utility/exit.hh>
30 #include <ObjexxFCL/FArray1D.hh>
31 #include <ObjexxFCL/FArray1D.fwd.hh>
32 #include <ObjexxFCL/format.hh>
36 //Auto Headers
38 #include <utility/excn/Exceptions.hh>
40 
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 score_type_filter_tracer( "protocols.simple_filters.ScoreTypeFilter" );
50 
53 
55 ScoreTypeFilterCreator::keyname() const { return "ScoreType"; }
56 
57 ScoreTypeFilter::ScoreTypeFilter( core::scoring::ScoreFunctionCOP scorefxn, core::scoring::ScoreType const score_type, core::Real const score_type_threshold ) : Filter( "ScoreType" ) {
58  score_type_ = score_type;
59  score_type_threshold_ = score_type_threshold;
60  scorefxn_ = scorefxn->clone();
61 }
62 
64 
65 void
67 {
68  using namespace core::scoring;
69 
70  std::string const scorefxn_name( tag->getOption<std::string>( "scorefxn", "score12" ) );
71  // scorefxn_ = new ScoreFunction( *(data.get< ScoreFunction * >( "scorefxns", scorefxn_name )) );
72  scorefxn_ = data.get< ScoreFunction * >( "scorefxns", scorefxn_name )->clone();
73 
74  score_type_ = core::scoring::score_type_from_name( tag->getOption<std::string>( "score_type", "total_score" ) );
75  if( ! tag->hasOption( "threshold" ) ) throw utility::excn::EXCN_RosettaScriptsOption("Must specify 'threshold' for ScoreTypeFilter.");
76  score_type_threshold_ = tag->getOption<core::Real>( "threshold" );
77 
78  score_type_filter_tracer<<"ScoreType filter for score_type "<<score_type_<<" with threshold "<<score_type_threshold_<<std::endl;
79 }
80 void ScoreTypeFilter::parse_def( utility::lua::LuaObject const & def,
81  utility::lua::LuaObject const & score_fxns,
82  utility::lua::LuaObject const & /*tasks*/ ) {
83  using namespace core::scoring;
84 
85  if( def["scorefxn"] ) {
86  scorefxn_ = protocols::elscripts::parse_scoredef( def["scorefxn"], score_fxns );
87  } else {
88  scorefxn_ = score_fxns["score12"].to<ScoreFunctionSP>()->clone();
89  }
90 
91  score_type_ = core::scoring::score_type_from_name( def["score_type"] ? def["score_type"].to<std::string>() : "total_score" );
92  if( ! def["threshold"] ) utility_exit_with_message("Must specify 'threshold' for ScoreTypeFilter.");
93  score_type_threshold_ = def["threshold"].to<core::Real>();
94 
95  score_type_filter_tracer<<"ScoreType filter for score_type "<<score_type_<<" with threshold "<<score_type_threshold_<<std::endl;
96 }
97 
98 bool
100  core::Real const score( compute( pose ) );
102  if( score <= score_type_threshold_ ) {
103  score_type_filter_tracer<<"passing." << std::endl;
104  return true;
105  }
106  else {
107  score_type_filter_tracer<<"failing."<<std::endl;
108  return false;
109  }
110 }
111 
112 void
113 ScoreTypeFilter::report( std::ostream & out, core::pose::Pose const & pose ) const {
114  out<<"Weighted score of "<<core::scoring::ScoreTypeManager::name_from_score_type( score_type_ )<<" "<<compute( pose )<<'\n';
115 }
116 
119  return( compute( pose ) );
120 }
121 
124  using namespace core::pose;
125  using namespace core::scoring;
126 
127  PoseOP in_pose = new Pose( pose );
128 
129  // make sure that scoring weights are compatible with pose's residue type set
130  // check centroid case
131  if( ( (*scorefxn_)[fa_rep] == 0.0 && (*scorefxn_)[fa_atr] == 0.0 ) // full atom terms are off
132  && ( (*scorefxn_)[interchain_vdw] > 0.0 || (*scorefxn_)[vdw] > 0.0) ) // a centroid term is on
133  {
134  if( in_pose->is_fullatom() ) { // but pose is full atom
136  }
137  }
138  else { // full atom case
139  if( in_pose->is_centroid() ) { // but pose is centroid
141  }
142  }
143 
144  (*scorefxn_)( *in_pose );
145  /// Now handled automatically. scorefxn_->accumulate_residue_total_energies( *in_pose );
146  core::Real const weight( (*scorefxn_)[ ScoreType( score_type_ ) ] );
147  core::Real const score( in_pose->energies().total_energies()[ ScoreType( score_type_ ) ]);
148  if( score_type_ == total_score ) return( score );
149  core::Real const weighted_score( weight * score );
150  return( weighted_score );
151 }
152 
153 }
154 }