Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResidueTotalScoresFeatures.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/features/ResidueTotalScoresFeatures.cc
11 /// @brief report the total per residue score to a features database
12 /// @author Matthew O'Meara (mattjomeara@gmail.com)
13 
14 // Unit Headers
17 
18 // Project Headers
20 #include <core/pose/Pose.hh>
25 #include <core/scoring/Energies.hh>
27 #include <core/types.hh>
29 #include <basic/database/sql_utils.hh>
30 #include <basic/Tracer.hh>
31 #include <basic/database/schema_generator/PrimaryKey.hh>
32 #include <basic/database/schema_generator/ForeignKey.hh>
33 #include <basic/database/schema_generator/Column.hh>
34 #include <basic/database/schema_generator/Schema.hh>
35 
36 // Utility Headers
37 #include <numeric/xyzVector.hh>
38 #include <utility/tag/Tag.hh>
39 #include <utility/vector1.hh>
40 #include <utility/sql_database/DatabaseSessionManager.hh>
41 
42 // External Headers
43 #include <cppdb/frontend.h>
44 #include <boost/uuid/uuid_io.hpp>
45 
46 // C++ Headers
47 #include <cmath>
48 #include <utility/excn/Exceptions.hh>
49 #include <sstream>
50 
51 namespace protocols{
52 namespace features{
53 
54 using std::endl;
55 using std::string;
56 using std::stringstream;
57 using core::Size;
58 using core::Real;
59 using core::pose::Pose;
60 using core::pose::PoseOP;
71 using numeric::xyzVector;
73 using utility::vector1;
74 using basic::database::safely_write_to_database;
75 using utility::sql_database::sessionOP;
76 using cppdb::statement;
77 
78 static basic::Tracer TR( "protocols.features.ResidueTotalScoresFeatures" );
79 
81  scfxn_(getScoreFunction())
82 {}
83 
85  ScoreFunctionOP scfxn) :
86  scfxn_(scfxn)
87 {}
88 
91  scfxn_(src.scfxn_)
92 {}
93 
95 {}
96 
97 string
98 ResidueTotalScoresFeatures::type_name() const { return "ResidueTotalScoresFeatures"; }
99 
100 void
102  sessionOP db_session
103 ) const {
105 }
106 
107 void
109  sessionOP db_session
110 ) const {
111  using namespace basic::database::schema_generator;
112 
113  Column struct_id("struct_id", new DbUUID());
114  Column resNum("resNum", new DbInteger());
115  Column score_value("score_value", new DbReal());
116 
117  Columns primary_key_columns;
118  primary_key_columns.push_back(struct_id);
119  primary_key_columns.push_back(resNum);
120  PrimaryKey primary_key(primary_key_columns);
121 
122  Columns foreign_key_columns;
123  foreign_key_columns.push_back(struct_id);
124  foreign_key_columns.push_back(resNum);
125  vector1< string > reference_columns;
126  reference_columns.push_back("struct_id");
127  reference_columns.push_back("resNum");
128  ForeignKey foreign_key(foreign_key_columns, "residues", reference_columns, true);
129 
130  Schema table("residue_total_scores", primary_key);
131  table.add_foreign_key(foreign_key);
132  table.add_column(score_value);
133 
134  table.write(db_session);
135 }
136 
139  utility::vector1<string> dependencies;
140  dependencies.push_back("ResidueFeatures");
141  dependencies.push_back("ScoreTypeFeatures");
142  return dependencies;
143 }
144 
145 void
147  TagPtr const tag,
148  DataMap & data,
149  Filters_map const & /*filters*/,
150  Movers_map const & /*movers*/,
151  Pose const & /*pose*/
152 ) {
153  if(tag->hasOption("scorefxn")){
154  string const scorefxn_name(tag->getOption<string>("scorefxn"));
155  scfxn_ = data.get<ScoreFunction*>("scorefxns", scorefxn_name);
156  } else {
157  stringstream error_msg;
158  error_msg
159  << "The " << type_name() << " reporter requires a 'scorefxn' tag:" << endl
160  << endl
161  << " <feature name=" << type_name() <<" scorefxn=(name_of_score_function) />" << endl;
162  throw utility::excn::EXCN_RosettaScriptsOption(error_msg.str());
163  }
164 }
165 
166 Size
168  Pose const & pose,
169  vector1< bool > const & relevant_residues,
170  boost::uuids::uuid const struct_id,
171  sessionOP db_session
172 ){
173  insert_residue_total_scores_rows(pose, relevant_residues, struct_id, db_session );
174 
175  return 0;
176 }
177 
178 ///@details
179 void
181  Pose const & pose,
182  vector1< bool > const & relevant_residues,
183  boost::uuids::uuid const struct_id,
184  sessionOP db_session
185 ) const {
186  if(!scfxn_->energy_method_options().hbond_options().decompose_bb_hb_into_pair_energies()){
187  TR.Warning << "The backbone-backbone hydrogen bonds being stored in the per-residue scores. Please enable the decompose_bb_hb_into_pair_energies option if you want this behavior." << endl;
188  }
189 
190 
191  //calling setup for scoring on a temp copy of the pose, maybe
192  //there's a better way of doing this but we can't (and shouldn't)
193  //require that the pose be scored before calling this.
194  Pose temp_pose = pose;
195  (*scfxn_)(temp_pose);
196 
197  //Size const batch_id(get_batch_id(struct_id, db_session));
198 
199  string const stmt_string("INSERT INTO residue_total_scores (struct_id, resNum, score_value ) VALUES (?,?,?);");
200 
201  statement stmt(
202  basic::database::safely_prepare_statement(stmt_string, db_session));
203 
204  for(Size resNum=1; resNum <= temp_pose.total_residue(); ++resNum){
205  if(!relevant_residues[resNum]) continue;
206 
207  Real const score_value(temp_pose.energies().residue_total_energy(resNum));
208 
209  stmt.bind(1, struct_id);
210  stmt.bind(2, resNum);
211  stmt.bind(3, score_value);
212  safely_write_to_database(stmt);
213 
214  } // End rsd for loop
215 
216 
217 
218 } // End function body
219 
220 
221 } // namesapce
222 } // namespace