Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FeaturesReporter.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/FeaturesReporter.cc
11 /// @brief Base class to report geometry and scores to features Statistics Scientific Benchmark
12 /// @author Matthew O'Meara
13 
14 // Unit Headers
16 
17 //External
18 #include <boost/uuid/uuid.hpp>
19 #include <boost/uuid/uuid_io.hpp>
20 
21 // Project Headers
22 #include <basic/Tracer.hh>
23 #include <basic/database/sql_utils.hh>
24 #include <utility/sql_database/DatabaseSessionManager.hh>
25 #include <utility/string_util.hh>
26 #include <utility/tag/Tag.hh>
27 #include <utility/vector1.hh>
28 #include <protocols/jd2/Job.hh>
30 #include <basic/datacache/BasicDataCache.hh>
31 #include <basic/datacache/CacheableString.hh>
32 #include <core/pose/Pose.hh>
34 #include <core/pose/PDBInfo.hh>
35 #include <basic/database/sql_utils.hh>
36 
37 // Boost Headers
38 #include <boost/foreach.hpp>
39 #include <boost/tokenizer.hpp>
40 #define foreach BOOST_FOREACH
41 
42 // External Headers
43 #include <cppdb/frontend.h>
44 
45 // C++ Headers
46 #include <string>
47 #include <sstream>
48 #include <iostream>
49 
50 #include <utility/vector0.hh>
51 
52 
53 namespace protocols {
54 namespace features {
55 
56 /// @details Auto-generated virtual destructor
58 
59 using basic::Tracer;
60 using basic::datacache::CacheableString;
61 using boost::char_separator;
62 using boost::tokenizer;
63 using core::Size;
64 using core::pose::Pose;
65 using cppdb::statement;
66 using cppdb::cppdb_error;
71 using std::endl;
72 using std::string;
73 using std::stringstream;
75 using basic::database::safely_prepare_statement;
76 using basic::database::safely_write_to_database;
77 using utility::trim;
78 using utility::vector1;
79 using utility::sql_database::sessionOP;
80 
81 static Tracer TR("protocols.features.FeaturesReporter");
82 
83 void
85  sessionOP db_session
86 ) const {
87 
88  string schema_str(schema());
89  try{
90  basic::database::write_schema_to_database(schema_str,db_session);
91  } catch (cppdb::cppdb_error error){
92  stringstream err_msg;
93  err_msg
94  << "Failed to write database schema for '" << type_name() << "'" << endl
95  << "Error Message:" << endl << error.what() << endl
96  << "Schema:" << endl << schema_str << endl;
97  utility_exit_with_message(err_msg.str());
98  }
99 }
100 
101 ///@details Extract all features from the pose to the database. The
102 ///input parent_id can be used to connect the features with the rest
103 ///of the database. Usually the parent_id will be struct_id which
104 ///uniquely identifies each structure in the database. The feature
105 ///reporter can return a parent_id.
106 Size
108  Pose const & pose,
109  boost::uuids::uuid parent_id,
110  sessionOP db_session
111 ){
112  vector1<bool> relevant_residues(true, pose.total_residue());
113  return report_features(pose, relevant_residues, parent_id, db_session);
114 }
115 
116 ///@details Extract all features from the pose to the database. The
117 ///input parent_id can be used to connect the features with the rest
118 ///of the database. Usually the parent_id will be struct_id which
119 ///uniquely identifies each structure in the database. The feature
120 ///reporter can return a parent_id.
121 Size
123  Pose const & /*pose*/,
124  vector1< bool > const & /*relevant_residues*/,
125  boost::uuids::uuid /*parent uuid*/,
126  sessionOP /*db_session*/
127 ){
128  Size dummy_parent_id(0);
129  return dummy_parent_id;
130 }
131 
132 
133 void
135  TagPtr const tag,
136  DataMap & /*data*/,
137  Filters_map const & /*filters*/,
138  Movers_map const & /*movers*/,
139  Pose const & /*pose*/
140 ) {
141  runtime_assert(tag->getName() == "feature");
142 }
143 
144 
145 string
147  Pose const & pose
148 ) const {
149  //silent files and pdbs set the name of the pose differently
150  string name = "";
151  if (pose.pdb_info()){
152  name = pose.pdb_info()->name();
153  }
154  if (name == ""){
156  name = static_cast< basic::datacache::CacheableString const & >
158  } else {
160  }
161  }
162  return name;
163 }
164 
165 void
167  string const & table_name,
168  boost::uuids::uuid struct_id,
169  sessionOP db_session){
170  stringstream sql;
171  sql << "DELETE FROM " << table_name << " WHERE struct_id = ?;";
172  statement stmt(safely_prepare_statement(sql.str(), db_session));
173  stmt.bind(1,struct_id);
174  safely_write_to_database(stmt);
175 }
176 
177 } // namespace
178 } // namespace
179