18 #include <boost/uuid/uuid.hpp>
19 #include <boost/uuid/uuid_io.hpp>
33 #include <basic/database/schema_generator/PrimaryKey.hh>
34 #include <basic/database/schema_generator/ForeignKey.hh>
35 #include <basic/database/schema_generator/Column.hh>
36 #include <basic/database/schema_generator/Schema.hh>
37 #include <basic/database/schema_generator/Constraint.hh>
39 #include <basic/database/insert_statement_generator/InsertGenerator.hh>
40 #include <basic/database/insert_statement_generator/RowData.hh>
43 #include <basic/options/option.hh>
44 #include <basic/options/keys/inout.OptionKeys.gen.hh>
45 #include <basic/database/sql_utils.hh>
46 #include <basic/Tracer.hh>
50 #include <numeric/xyzVector.hh>
51 #include <numeric/xyzMatrix.hh>
54 #include <utility/vector1.hh>
55 #include <utility/sql_database/DatabaseSessionManager.hh>
56 #include <utility/tools/make_vector.hh>
59 #include <boost/foreach.hpp>
60 #define foreach BOOST_FOREACH
63 #include <cppdb/frontend.h>
72 static basic::Tracer
TR(
"protocols.features.PoseConformationFeatures");
75 using std::stringstream;
98 using utility::sql_database::DatabaseSessionManager;
99 using utility::sql_database::sessionOP;
100 using cppdb::statement;
102 using basic::database::insert_statement_generator::InsertGenerator;
103 using basic::database::insert_statement_generator::RowDataBaseOP;
104 using basic::database::insert_statement_generator::RowData;
112 using namespace basic::database::schema_generator;
114 Column struct_id(
"struct_id",
new DbUUID(),
false ,
false );
117 Schema pose_conformations(
"pose_conformations");
118 pose_conformations.add_foreign_key(ForeignKey(struct_id,
"structures",
"struct_id",
true ));
120 pose_conformations.add_column( Column(
"annotated_sequence",
new DbText()) );
121 pose_conformations.add_column( Column(
"total_residue",
new DbInteger()) );
122 pose_conformations.add_column( Column(
"fullatom",
new DbInteger()) );
124 pose_conformations.write(db_session);
127 Schema fold_trees(
"fold_trees");
128 fold_trees.add_foreign_key(ForeignKey(struct_id,
"structures",
"struct_id",
true ));
130 fold_trees.add_column( Column(
"start_res",
new DbInteger()) );
131 fold_trees.add_column( Column(
"start_atom",
new DbText()) );
132 fold_trees.add_column( Column(
"stop_res",
new DbInteger()) );
133 fold_trees.add_column( Column(
"stop_atom",
new DbText()) );
134 fold_trees.add_column( Column(
"label",
new DbInteger()) );
135 fold_trees.add_column( Column(
"keep_stub_in_residue",
new DbInteger()) );
137 fold_trees.write(db_session);
140 Schema jumps(
"jumps");
141 jumps.add_foreign_key(ForeignKey(struct_id,
"structures",
"struct_id",
true ));
142 jumps.add_column( Column(
"jump_id",
new DbInteger()) );
143 jumps.add_column( Column(
"xx",
new DbDouble()) );
144 jumps.add_column( Column(
"xy",
new DbDouble()) );
145 jumps.add_column( Column(
"xz",
new DbDouble()) );
146 jumps.add_column( Column(
"yx",
new DbDouble()) );
147 jumps.add_column( Column(
"yy",
new DbDouble()) );
148 jumps.add_column( Column(
"yz",
new DbDouble()) );
149 jumps.add_column( Column(
"zx",
new DbDouble()) );
150 jumps.add_column( Column(
"zy",
new DbDouble()) );
151 jumps.add_column( Column(
"zz",
new DbDouble()) );
152 jumps.add_column( Column(
"x",
new DbDouble()) );
153 jumps.add_column( Column(
"y",
new DbDouble()) );
154 jumps.add_column( Column(
"z",
new DbDouble()) );
156 jumps.write(db_session);
159 Schema chain_endings(
"chain_endings");
160 chain_endings.add_foreign_key(ForeignKey(struct_id,
"structures",
"struct_id",
true ));
161 chain_endings.add_column( Column(
"end_pos",
new DbInteger()) );
163 chain_endings.write(db_session);
169 dependencies.push_back(
"StructureFeatures");
175 Pose const & pose_orig,
177 boost::uuids::uuid struct_id,
181 for(
Size i = 1; i <= relevant_residues.size(); ++i){
182 if(relevant_residues[i]) residue_indices.push_back(i);
185 if (residue_indices.size() == pose_orig.
n_residue()){
197 boost::uuids::uuid struct_id,
204 InsertGenerator fold_tree_insert(
"fold_trees");
205 fold_tree_insert.add_column(
"struct_id");
206 fold_tree_insert.add_column(
"start_res");
207 fold_tree_insert.add_column(
"start_atom");
208 fold_tree_insert.add_column(
"stop_res");
209 fold_tree_insert.add_column(
"stop_atom");
210 fold_tree_insert.add_column(
"label");
211 fold_tree_insert.add_column(
"keep_stub_in_residue");
213 RowDataBaseOP struct_id_data =
new RowData<boost::uuids::uuid>(
"struct_id",struct_id);
216 it = fold_tree.begin(), it_end = fold_tree.end(); it != it_end; ++it) {
218 int start_res(it->start()), stop_res(it->stop()), label(it->label());
219 string start_atom(it->start_atom()), stop_atom(it->stop_atom());
220 bool keep_stub_in_residue(it->keep_stub_in_residue());
223 RowDataBaseOP start_res_data =
new RowData<int>(
"start_res",start_res);
224 RowDataBaseOP start_atom_data =
new RowData<string>(
"start_atom",start_atom);
225 RowDataBaseOP stop_res_data =
new RowData<int>(
"stop_res",stop_res);
226 RowDataBaseOP stop_atom_data =
new RowData<string>(
"stop_atom",stop_atom);
227 RowDataBaseOP label_data =
new RowData<int>(
"label",label);
228 RowDataBaseOP keep_stub_data =
new RowData<bool>(
"keep_stub_in_residue",keep_stub_in_residue);
230 fold_tree_insert.add_row(
231 utility::tools::make_vector(struct_id_data,start_res_data,start_atom_data,stop_res_data,stop_atom_data,label_data,keep_stub_data));
234 fold_tree_insert.write_to_database(db_session);
236 InsertGenerator jump_insert(
"jumps");
237 jump_insert.add_column(
"struct_id");
238 jump_insert.add_column(
"jump_id");
239 jump_insert.add_column(
"xx");
240 jump_insert.add_column(
"xy");
241 jump_insert.add_column(
"xz");
242 jump_insert.add_column(
"yx");
243 jump_insert.add_column(
"yy");
244 jump_insert.add_column(
"yz");
245 jump_insert.add_column(
"zx");
246 jump_insert.add_column(
"zy");
247 jump_insert.add_column(
"zz");
248 jump_insert.add_column(
"x");
249 jump_insert.add_column(
"y");
250 jump_insert.add_column(
"z");
252 for (
Size nr = 1; nr <= fold_tree.num_jump(); nr++)
256 Real xx(r.xx()), xy(r.xy()), xz(r.xz());
257 Real yx(r.yx()), yy(r.yy()), yz(r.yz());
258 Real zx(r.zx()), zy(r.zy()), zz(r.zz());
259 Vector const &
t(jump.get_translation());
260 Real x(
t.x()), y(
t.y()), z(
t.z());
262 RowDataBaseOP jump_id_data =
new RowData<Size>(
"jump_id",nr);
263 RowDataBaseOP xx_data =
new RowData<Real>(
"xx",xx);
264 RowDataBaseOP xy_data =
new RowData<Real>(
"xy",xy);
265 RowDataBaseOP xz_data =
new RowData<Real>(
"xz",xz);
266 RowDataBaseOP yx_data =
new RowData<Real>(
"yx",yx);
267 RowDataBaseOP yy_data =
new RowData<Real>(
"yy",yy);
268 RowDataBaseOP yz_data =
new RowData<Real>(
"yz",yz);
269 RowDataBaseOP zx_data =
new RowData<Real>(
"zx",zx);
270 RowDataBaseOP zy_data =
new RowData<Real>(
"zy",zy);
271 RowDataBaseOP zz_data =
new RowData<Real>(
"zz",zz);
272 RowDataBaseOP x_data =
new RowData<Real>(
"x",x);
273 RowDataBaseOP y_data =
new RowData<Real>(
"y",y);
274 RowDataBaseOP z_data =
new RowData<Real>(
"z",z);
276 utility::tools::make_vector(struct_id_data,jump_id_data,xx_data,xy_data,xz_data,yx_data,yy_data,yz_data,zx_data,zy_data,zz_data,x_data,y_data,z_data));
278 jump_insert.write_to_database(db_session);
280 InsertGenerator chain_ending_insert(
"chain_endings");
281 chain_ending_insert.add_column(
"struct_id");
282 chain_ending_insert.add_column(
"end_pos");
285 RowDataBaseOP end_pos_data =
new RowData<Size>(
"end_pos",end_pos);
287 chain_ending_insert.add_row(
288 utility::tools::make_vector(struct_id_data,end_pos_data));
290 chain_ending_insert.write_to_database(db_session);
295 InsertGenerator pose_conformation_insert(
"pose_conformations");
296 pose_conformation_insert.add_column(
"struct_id");
297 pose_conformation_insert.add_column(
"annotated_sequence");
298 pose_conformation_insert.add_column(
"total_residue");
299 pose_conformation_insert.add_column(
"fullatom");
301 RowDataBaseOP annotated_sequence_data =
new RowData<string>(
"annotated_sequence",annotated_sequence);
302 RowDataBaseOP total_residue_data =
new RowData<Size>(
"total_residue",pose.
total_residue());
303 RowDataBaseOP fullatom_data =
new RowData<bool>(
"fullatom",pose.
is_fullatom());
305 pose_conformation_insert.add_row(
306 utility::tools::make_vector(struct_id_data,annotated_sequence_data,total_residue_data,fullatom_data));
308 pose_conformation_insert.write_to_database(db_session);
313 boost::uuids::uuid struct_id,
317 statement conf_stmt(basic::database::safely_prepare_statement(
"DELETE FROM pose_conformations WHERE struct_id = ?;\n",db_session));
318 conf_stmt.bind(1,struct_id);
319 basic::database::safely_write_to_database(conf_stmt);
321 statement fold_stmt(basic::database::safely_prepare_statement(
"DELETE FROM fold_trees WHERE struct_id = ?;\n",db_session));
322 fold_stmt.bind(1,struct_id);
323 basic::database::safely_write_to_database(fold_stmt);
325 statement jump_stmt(basic::database::safely_prepare_statement(
"DELETE FROM jumps WHERE struct_id = ?;\n",db_session));
326 jump_stmt.bind(1,struct_id);
327 basic::database::safely_write_to_database(jump_stmt);
329 statement chain_stmt(basic::database::safely_prepare_statement(
"DELETE FROM chain_endings WHERE struct_id = ?;",db_session));
330 chain_stmt.bind(1,struct_id);
331 basic::database::safely_write_to_database(chain_stmt);
336 sessionOP db_session,
337 boost::uuids::uuid struct_id,
348 sessionOP db_session,
349 boost::uuids::uuid struct_id,
353 if(!basic::database::table_exists(db_session,
"pose_conformations")){
354 TR <<
"WARNING: pose_conformations table does not exist and thus respective data will not be added to the pose!" << std::endl;
360 " annotated_sequence,\n"
364 " pose_conformations\n"
366 " pose_conformations.struct_id = ?;";
367 statement stmt(basic::database::safely_prepare_statement(statement_string,db_session));
368 stmt.bind(1,struct_id);
369 result res(basic::database::safely_read_from_database(stmt));
373 error_message <<
"Unable to locate structure with struct_id '" << to_string(struct_id) <<
"'";
374 utility_exit_with_message(error_message.str());
376 string annotated_sequence;
377 Size total_residue, fullatom;
379 res >> annotated_sequence >> total_residue >> fullatom;
390 sessionOP db_session,
391 boost::uuids::uuid struct_id,
395 if(!basic::database::table_exists(db_session,
"fold_trees")){
396 TR <<
"WARNING: fold_trees table does not exist and thus respective data will not be added to the pose!" << std::endl;
400 statement stmt = (*db_session) <<
407 " keep_stub_in_residue\n"
411 " fold_trees.struct_id=?;" << struct_id;
413 result res(basic::database::safely_read_from_database(stmt));
417 int start_res, stop_res, label;
418 string start_atom, stop_atom;
419 int keep_stub_in_residue;
420 res >> start_res >> start_atom >> stop_res >> stop_atom >> label >> keep_stub_in_residue;
421 if(label == -2 || label > 0){
423 start_res, stop_res, label, start_atom, stop_atom, keep_stub_in_residue));
425 t.
add_edge(
Edge(start_res, stop_res, label,
"",
"", keep_stub_in_residue));
431 TR.Debug <<
"Fold tree loaded" << std::endl;
436 sessionOP db_session,
437 boost::uuids::uuid struct_id,
440 if(!basic::database::table_exists(db_session,
"jumps")){
441 TR <<
"WARNING: jumps table does not exist and thus respective data will not be added to the pose!" << std::endl;
464 " jumps.struct_id=?;";
466 basic::database::safely_prepare_statement(statement_string,db_session));
468 stmt.bind(1,struct_id);
469 result res(basic::database::safely_read_from_database(stmt));
472 Real xx, xy, xz, yx, yy, yz, zx, zy, zz, x, y, z;
474 res >> xx >> xy >> xz >> yx >> yy >> yz >> zx >> zy >> zz >> x >> y >> z;
476 xx, xy, xz, yx, yy, yz, zx, zy, zz));
481 TR.Debug <<
"Jumps loaded" << std::endl;
486 sessionOP db_session,
487 boost::uuids::uuid struct_id,
491 if(!basic::database::table_exists(db_session,
"chain_endings")){
492 TR <<
"WARNING: chain_endings table does not exist and thus respective data will not be added to the pose!" << std::endl;
504 " chain_endings.struct_id=?;";
506 statement stmt(basic::database::safely_prepare_statement(statement_string,db_session));
507 stmt.bind(1,struct_id);
510 result res(basic::database::safely_read_from_database(stmt));
516 chain_endings.push_back(end_pos);
520 TR.Debug <<
"Chain endings loaded" << std::endl;