19 #include <boost/uuid/uuid.hpp>
31 #include <numeric/xyzVector.hh>
32 #include <utility/vector1.hh>
33 #include <utility/sql_database/DatabaseSessionManager.hh>
34 #include <utility/tools/make_vector.hh>
37 #include <basic/database/sql_utils.hh>
38 #include <basic/database/schema_generator/PrimaryKey.hh>
39 #include <basic/database/schema_generator/ForeignKey.hh>
40 #include <basic/database/schema_generator/Column.hh>
41 #include <basic/database/schema_generator/Schema.hh>
42 #include <basic/database/schema_generator/Constraint.hh>
43 #include <basic/options/option.hh>
44 #include <basic/options/keys/out.OptionKeys.gen.hh>
45 #include <basic/options/keys/inout.OptionKeys.gen.hh>
46 #include <basic/database/insert_statement_generator/InsertGenerator.hh>
47 #include <basic/database/insert_statement_generator/RowData.hh>
49 #include <cppdb/frontend.h>
50 #include <boost/uuid/uuid_io.hpp>
65 using basic::database::table_exists;
67 using utility::sql_database::sessionOP;
68 using cppdb::statement;
70 using basic::database::insert_statement_generator::InsertGenerator;
71 using basic::database::insert_statement_generator::RowDataBaseOP;
72 using basic::database::insert_statement_generator::RowData;
76 return "ResidueConformationFeatures";
81 using namespace basic::database::schema_generator;
84 Column struct_id(
"struct_id",
new DbUUID(),
false);
85 Column seqpos(
"seqpos",
new DbInteger(),
false);
86 Column
phi(
"phi",
new DbDouble(),
false);
87 Column
psi(
"psi",
new DbDouble(),
false);
88 Column
omega(
"omega",
new DbDouble(),
false);
91 non_prot_res_pkeys.push_back(struct_id);
92 non_prot_res_pkeys.push_back(seqpos);
97 fkey_cols.push_back(struct_id);
98 fkey_cols.push_back(seqpos);
101 fkey_reference_cols.push_back(
"struct_id");
102 fkey_reference_cols.push_back(
"resNum");
104 Schema nonprotein_residue_conformation(
"nonprotein_residue_conformation", PrimaryKey(non_prot_res_pkeys));
105 nonprotein_residue_conformation.add_column(struct_id);
106 nonprotein_residue_conformation.add_column(seqpos);
107 nonprotein_residue_conformation.add_column(phi);
108 nonprotein_residue_conformation.add_column(psi);
109 nonprotein_residue_conformation.add_column(omega);
110 nonprotein_residue_conformation.add_foreign_key(ForeignKey(fkey_cols,
"residues", fkey_reference_cols,
true));
112 nonprotein_residue_conformation.write(db_session);
115 Column chinum(
"chinum",
new DbInteger(),
false);
116 Column chiangle(
"chiangle",
new DbDouble(),
false);
119 non_prot_res_angle_keys.push_back(struct_id);
120 non_prot_res_angle_keys.push_back(seqpos);
121 non_prot_res_angle_keys.push_back(chinum);
123 Schema nonprotein_residue_angles(
"nonprotein_residue_angles", PrimaryKey(non_prot_res_angle_keys));
124 nonprotein_residue_angles.add_column(struct_id);
125 nonprotein_residue_angles.add_column(seqpos);
126 nonprotein_residue_angles.add_column(chinum);
127 nonprotein_residue_angles.add_column(chiangle);
128 nonprotein_residue_angles.add_foreign_key(ForeignKey(fkey_cols,
"residues", fkey_reference_cols,
true));
130 nonprotein_residue_angles.write(db_session);
133 Column atomno(
"atomno",
new DbInteger(),
false);
134 Column x(
"x",
new DbDouble(),
false);
135 Column y(
"y",
new DbDouble(),
false);
136 Column z(
"z",
new DbDouble(),
false);
139 res_atm_coords_pkeys.push_back(struct_id);
140 res_atm_coords_pkeys.push_back(seqpos);
141 res_atm_coords_pkeys.push_back(atomno);
143 Schema residue_atom_coords(
"residue_atom_coords", PrimaryKey(res_atm_coords_pkeys));
144 residue_atom_coords.add_column(struct_id);
145 residue_atom_coords.add_column(seqpos);
146 residue_atom_coords.add_column(atomno);
147 residue_atom_coords.add_column(x);
148 residue_atom_coords.add_column(y);
149 residue_atom_coords.add_column(z);
150 residue_atom_coords.add_foreign_key(ForeignKey(fkey_cols,
"residues", fkey_reference_cols,
true));
152 residue_atom_coords.write(db_session);
159 dependencies.push_back(
"ResidueFeatures");
167 boost::uuids::uuid struct_id,
173 if(!basic::options::option[basic::options::OptionKeys::out::file::force_nonideal_structure]())
177 if(!relevant_residues[resn])
continue;
189 InsertGenerator conformation_insert(
"nonprotein_residue_conformation");
190 conformation_insert.add_column(
"struct_id");
191 conformation_insert.add_column(
"seqpos");
192 conformation_insert.add_column(
"phi");
193 conformation_insert.add_column(
"psi");
194 conformation_insert.add_column(
"omega");
196 InsertGenerator angle_insert(
"nonprotein_residue_angles");
197 angle_insert.add_column(
"struct_id");
198 angle_insert.add_column(
"seqpos");
199 angle_insert.add_column(
"chinum");
200 angle_insert.add_column(
"chiangle");
202 InsertGenerator atom_insert(
"residue_atom_coords");
203 atom_insert.add_column(
"struct_id");
204 atom_insert.add_column(
"seqpos");
205 atom_insert.add_column(
"atomno");
206 atom_insert.add_column(
"x");
207 atom_insert.add_column(
"y");
208 atom_insert.add_column(
"z");
211 RowDataBaseOP struct_id_data =
new RowData<boost::uuids::uuid>(
"struct_id",struct_id);
213 if(!relevant_residues[i])
continue;
229 RowDataBaseOP seqpos_data =
new RowData<Size>(
"seqpos",i);
230 RowDataBaseOP phi_data =
new RowData<Real>(
"phi",
phi);
231 RowDataBaseOP psi_data =
new RowData<Real>(
"psi",
psi);
232 RowDataBaseOP omega_data =
new RowData<Real>(
"omega",
omega);
234 conformation_insert.add_row(
235 utility::tools::make_vector(struct_id_data,seqpos_data,phi_data,psi_data,omega_data));
242 RowDataBaseOP chinum_data =
new RowData<Size>(
"chinum",chi_num);
243 RowDataBaseOP chiangle_data =
new RowData<Real>(
"chiangle",chi_angle);
244 angle_insert.add_row(utility::tools::make_vector(
245 struct_id_data,seqpos_data,chinum_data,chiangle_data));
249 for(
Size atom = 1; atom <= resi.
natoms(); ++atom){
252 RowDataBaseOP atom_data =
new RowData<Size>(
"atomno",atom);
253 RowDataBaseOP x_data =
new RowData<Real>(
"x",coords.x());
254 RowDataBaseOP y_data =
new RowData<Real>(
"y",coords.y());
255 RowDataBaseOP z_data =
new RowData<Real>(
"z",coords.z());
257 atom_insert.add_row(utility::tools::make_vector(
258 struct_id_data,seqpos_data,atom_data,x_data,y_data,z_data));
265 conformation_insert.write_to_database(db_session);
266 angle_insert.write_to_database(db_session);
267 atom_insert.write_to_database(db_session);
274 boost::uuids::uuid struct_id,
278 statement conformation_stmt(basic::database::safely_prepare_statement(
"DELETE FROM nonprotein_residue_conformation WHERE struct_id = ?;\n",db_session));
279 conformation_stmt.bind(1,struct_id);
280 basic::database::safely_write_to_database(conformation_stmt);
281 statement angle_stmt(basic::database::safely_prepare_statement(
"DELETE FROM nonprotein_residue_angles WHERE struct_id = ?;\n",db_session));
282 angle_stmt.bind(1,struct_id);
283 basic::database::safely_write_to_database(angle_stmt);
284 statement coords_stmt(basic::database::safely_prepare_statement(
"DELETE FROM residue_atom_coords WHERE struct_id = ?;",db_session));
285 coords_stmt.bind(1,struct_id);
286 basic::database::safely_write_to_database(coords_stmt);
292 sessionOP db_session,
293 boost::uuids::uuid struct_id,
301 sessionOP db_session,
302 boost::uuids::uuid struct_id,
305 if(!table_exists(db_session,
"nonprotein_residue_conformation"))
return;
306 if(!table_exists(db_session,
"nonprotein_residue_angles"))
return;
317 " nonprotein_residue_conformation\n"
319 " nonprotein_residue_conformation.struct_id=?;";
321 statement protein_stmt(basic::database::safely_prepare_statement(protein_string,db_session));
322 protein_stmt.bind(1,struct_id);
330 " nonprotein_residue_angles\n"
332 " nonprotein_residue_angles.struct_id=?;";
334 statement conformation_stmt(basic::database::safely_prepare_statement(conformation_string,db_session));
335 conformation_stmt.bind(1,struct_id);
338 result protein_res(basic::database::safely_read_from_database(protein_stmt));
339 while(protein_res.next()){
342 protein_res >> seqpos >> phi >> psi >>
omega;
349 result res_conformation(basic::database::safely_read_from_database(conformation_stmt));
350 while(res_conformation.next()){
356 res_conformation >> seqpos >> chinum >> chiangle;
357 pose.
set_chi(chinum,seqpos,chiangle);
369 " nonprotein_residue_conformation\n"
371 " nonprotein_residue_conformation.struct_id=?;";
373 statement protein_stmt(basic::database::safely_prepare_statement(protein_string,db_session));
374 protein_stmt.bind(1,struct_id);
376 result protein_res(basic::database::safely_read_from_database(protein_stmt));
377 while(protein_res.next()){
380 protein_res >> seqpos >> phi >> psi >>
omega;
396 sessionOP db_session,
397 boost::uuids::uuid struct_id,
409 " residue_atom_coords\n"
411 "residue_atom_coords.struct_id=? AND residue_atom_coords.seqpos=?;";
413 statement stmt(basic::database::safely_prepare_statement(statement_string,db_session));
414 stmt.bind(1,struct_id);
417 result res(basic::database::safely_read_from_database(stmt));
421 res >> atomno >> x >> y >> z;