Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LoopsDatabaseDefiner.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/loops/loops_definers/LoopsDatabaseDefiner.cc
11 /// @brief A loops definer is creates a serialized loops list
12 /// @author Matthew O'Meara (mattjomear@gmail.com)
13 
14 // Unit Headers
16 
17 // Package Headers
18 #include <protocols/loops/Loop.hh>
19 
20 // Project Headers
21 #include <protocols/jd2/Job.hh>
23 #include <utility/tag/Tag.hh>
25 
26 // Utility Headers
27 #include <utility/sql_database/DatabaseSessionManager.hh>
28 
29 // Basic Headers
30 #include <basic/database/sql_utils.hh>
31 
32 // External Headers
33 #include <cppdb/frontend.h>
34 
35 // C++ Headers
36 #include <string>
37 #include <utility/excn/Exceptions.hh>
38 #include <sstream>
39 
40 
41 using std::string;
42 using std::endl;
43 using std::stringstream;
45 using core::pose::Pose;
47 using utility::sql_database::sessionOP;
49 using basic::database::parse_database_connection;
50 using cppdb::result;
51 
52 namespace protocols {
53 namespace loops {
54 namespace loops_definers {
55 
57  db_session_(),
58  database_table_()
59 {}
60 
62 
64  LoopsDatabaseDefiner const & src
65 ) :
66  db_session_(src.db_session_),
67  database_table_(src.database_table_)
68 {}
69 
70 
71 /// @brief Create another loops definer of the type matching the most-derived
72 /// version of the class.
75 ) const {
76  return new LoopsDatabaseDefiner(*this);
77 }
78 
79 /// @brief Used to parse an xml-like tag to load parameters and properties.
80 void
82  TagPtr const tag,
83  DataMap const &,
84  Pose const &
85 ) {
86 
87  db_session_ = parse_database_connection(tag);
88 
90  tag->getOption<string>("database_table", "loops");
91 
92  string const type(tag->getName());
93 
94  if(!tag->hasOption("name")){
95  throw utility::excn::EXCN_RosettaScriptsOption(
96  "Unable to create unnamed LoopsDefiner (type: " + type + ")" );
97  }
98  string const loops_name(tag->getOption<string>("name"));
99 
100 }
101 
104  Pose const &
105 ) {
106 
107  string pose_tag(JobDistributor::get_instance()->current_job()->input_tag());
108 
109  stringstream sql_stmt;
110  sql_stmt
111  << "SELECT start, stop, cut, skip_rate, extended FROM " << database_table_
112  << " WHERE tag='" << pose_tag << "';";
113  result res = (*db_session_) << sql_stmt.str();
114 
115  SerializedLoopList loop_list;
116  while(res.next()){
117  SerializedLoop loop;
118  int extended;
119  res >> loop.start >> loop.stop >> loop.cut >> loop.skip_rate >> extended;
120  loop.extended = extended;
121 
122  loop_list.push_back(loop);
123  }
124 
125  if(loop_list.size() == 0){
126  stringstream error_message;
127  error_message
128  << "Unable to locate loops for job distributor input tag '"
129  << pose_tag << "' in database." << endl;
130  utility_exit_with_message(error_message.str());
131  }
132 
133  return loop_list;
134 }
135 
136 } //namespace
137 } //namespace
138 } //namespace
139 
140 
141