Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ScoreTypeFeatures.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/ScoreTypeFeatures.cc
11 /// @brief report protocol level features to features statistics scientific benchmark
12 /// @author Matthew O'Meara
13 
14 // Unit Headers
17 
18 //External
19 #include <boost/uuid/uuid.hpp>
20 
21 //Basic Headers
22 #include <basic/database/sql_utils.hh>
23 #include <basic/database/schema_generator/PrimaryKey.hh>
24 #include <basic/database/schema_generator/ForeignKey.hh>
25 #include <basic/database/schema_generator/Column.hh>
26 #include <basic/database/schema_generator/Schema.hh>
27 #include <basic/database/schema_generator/Constraint.hh>
28 
29 // Platform Headers
30 #include <basic/options/option.hh>
31 #include <basic/options/keys/inout.OptionKeys.gen.hh>
32 #include <core/graph/Graph.fwd.hh>
41 #include <utility/sql_database/DatabaseSessionManager.hh>
42 #include <utility/vector1.hh>
43 #include <basic/database/sql_utils.hh>
44 
45 // External Headers
46 #include <cppdb/frontend.h>
47 
48 // C++ Headers
49 #include <sstream>
50 #include <string>
51 
52 
53 namespace protocols{
54 namespace features{
55 
56 using std::string;
57 using std::stringstream;
58 using std::endl;
59 using core::pose::Pose;
60 using core::graph::Graph;
75 using core::Size;
76 using core::Real;
77 using utility::vector1;
78 using utility::sql_database::sessionOP;
79 using cppdb::statement;
80 using cppdb::result;
81 
83  scfxn_(getScoreFunction())
84 {}
85 
87  ScoreFunctionOP scfxn
88 ) :
89  scfxn_(scfxn)
90 {
91  if ( scfxn_ == 0 ) {
92  utility_exit_with_message( "ScoreTypeFeatures may not be constructed with a null-pointer ScoreFunctionOP" );
93  }
94 }
95 
97  ScoreTypeFeatures const & src
98 ) :
100  scfxn_(src.scfxn_)
101 {}
102 
104 
105 string
106 ScoreTypeFeatures::type_name() const { return "ScoreTypeFeatures"; }
107 
108 void
110  sessionOP db_session
111 ) const {
112 
113  using namespace basic::database::schema_generator;
114 
115  //******score_types******//
116  Column batch_id("batch_id", new DbInteger(), false);
117  Column score_type_id("score_type_id", new DbInteger(), false);
118  Column score_type_name("score_type_name", new DbText(), false);
119 
120  utility::vector1<Column> pkey_cols;
121  pkey_cols.push_back(batch_id);
122  pkey_cols.push_back(score_type_id);
123 
124  Schema score_types("score_types", PrimaryKey(pkey_cols));
125  score_types.add_column(batch_id);
126  score_types.add_column(score_type_id);
127  score_types.add_column(score_type_name);
128 
129  score_types.add_foreign_key(ForeignKey(batch_id, "batches", "batch_id", true));
130 
131  score_types.write(db_session);
132 }
133 
136  utility::vector1<std::string> dependencies;
137  dependencies.push_back("ProtocolFeatures");
138  return dependencies;
139 }
140 
141 Size
143  Pose const &,
144  vector1< bool > const &,
145  boost::uuids::uuid const struct_id,
146  sessionOP db_session
147 ){
148  Size const batch_id(get_batch_id(struct_id, db_session));
149 
150  insert_score_type_rows(batch_id, db_session);
151  return 0;
152 }
153 
154 
155 Size
157  Size const batch_id,
158  sessionOP db_session
159 ){
160  insert_score_type_rows(batch_id, db_session);
161  return 0;
162 }
163 
164 
165 
166 
168  boost::uuids::uuid,
169  utility::sql_database::sessionOP ){}
170 
171 void
173  Size protocol_id,
174  sessionOP db_session
175 ) {
176  std::string statement_string;
177 
178  switch(db_session->get_db_mode()){
179  case utility::sql_database::DatabaseMode::sqlite3:
180  statement_string = "INSERT OR IGNORE INTO score_types (batch_id, score_type_id, score_type_name) VALUES (?,?,?);";
181  break;
182  case utility::sql_database::DatabaseMode::mysql:
183  case utility::sql_database::DatabaseMode::postgres:
184  statement_string = "INSERT IGNORE INTO score_types (batch_id, score_type_id, score_type_name) VALUES (?,?,?);";
185  break;
186  default:
187  utility_exit_with_message(
188  "Unrecognized database mode: '" +
189  name_from_database_mode(db_session->get_db_mode()) + "'");
190  break;
191  }
192 
193  statement stmt(basic::database::safely_prepare_statement(statement_string,db_session));
194 
195  for(Size score_type_id=1; score_type_id <= n_score_types; ++score_type_id){
196  ScoreType type(static_cast<ScoreType>(score_type_id));
197 
198  string const score_type( ScoreTypeManager::name_from_score_type(type) );
199  stmt.bind(1,protocol_id);
200  stmt.bind(2,score_type_id);
201  stmt.bind(3,score_type);
202  basic::database::safely_write_to_database(stmt);
203 
204 
205  }
206  //transact_guard.commit();
207 }
208 
209 
210 } // namesapce
211 } // namespace