23 #include <boost/uuid/uuid.hpp>
24 #include <boost/uuid/uuid_io.hpp>
34 #include <numeric/HomogeneousTransform.hh>
37 #include <utility/excn/Exceptions.hh>
38 #include <utility/vector1.hh>
39 #include <utility/sql_database/DatabaseSessionManager.hh>
40 #include <utility/tag/Tag.hh>
43 #include <basic/options/option.hh>
44 #include <basic/options/keys/inout.OptionKeys.gen.hh>
45 #include <basic/database/sql_utils.hh>
47 #include <basic/database/schema_generator/PrimaryKey.hh>
48 #include <basic/database/schema_generator/ForeignKey.hh>
49 #include <basic/database/schema_generator/Column.hh>
50 #include <basic/database/schema_generator/Schema.hh>
54 #include <cppdb/frontend.h>
57 #include <boost/foreach.hpp>
58 #define foreach BOOST_FOREACH
70 using std::stringstream;
74 using basic::database::safely_write_to_database;
75 using basic::database::safely_prepare_statement;
84 using numeric::HomogeneousTransform;
86 using utility::sql_database::sessionOP;
87 using utility::excn::EXCN_Msg_Exception;
90 using cppdb::statement;
117 using namespace basic::database::schema_generator;
119 Column struct_id(
"struct_id",
new DbUUID());
120 Column residue_begin(
"residue_begin",
new DbInteger());
121 Column turn_type(
"turn_type",
new DbText());
123 Columns primary_key_columns;
124 primary_key_columns.push_back(struct_id);
125 primary_key_columns.push_back(residue_begin);
126 PrimaryKey primary_key(primary_key_columns);
128 Columns foreign_key_columns;
129 foreign_key_columns.push_back(struct_id);
130 foreign_key_columns.push_back(residue_begin);
132 reference_columns.push_back(
"struct_id");
133 reference_columns.push_back(
"resNum");
134 ForeignKey foreign_key(foreign_key_columns,
"residues", reference_columns,
true);
136 Schema table(
"beta_turns", primary_key);
137 table.add_foreign_key(foreign_key);
138 table.add_column(turn_type);
140 table.write(db_session);
146 dependencies.push_back(
"ResidueFeatures");
157 boost::uuids::uuid struct_id,
160 string beta_turns_stmt_string =
"INSERT INTO beta_turns (struct_id, residue_begin, turn_type) VALUES (?,?,?);";
161 statement beta_turns_stmt(
162 safely_prepare_statement(beta_turns_stmt_string, db_session));
173 beta_turns_stmt.bind(1,struct_id);
174 beta_turns_stmt.bind(2,begin);
176 basic::database::safely_write_to_database( beta_turns_stmt );
185 static map< string, string > * conformation_to_turn_type = 0;
187 if ( conformation_to_turn_type == 0 )
189 conformation_to_turn_type =
new map< string, string >;
195 ( *conformation_to_turn_type )[
"AA" ] =
"TurnAA_I";
196 ( *conformation_to_turn_type )[
"AB" ] =
"TurnAB_VIII";
197 ( *conformation_to_turn_type )[
"AL" ] =
"TurnAL_IX";
198 ( *conformation_to_turn_type )[
"AE" ] =
"TurnAE";
200 ( *conformation_to_turn_type )[
"BA" ] =
"TurnBA";
201 ( *conformation_to_turn_type )[
"BB" ] =
"TurnBB";
202 ( *conformation_to_turn_type )[
"BL" ] =
"TurnBL_II";
203 ( *conformation_to_turn_type )[
"BE" ] =
"TurnBE";
205 ( *conformation_to_turn_type )[
"LA" ] =
"TurnLA_IXp";
206 ( *conformation_to_turn_type )[
"LB" ] =
"TurnLB";
207 ( *conformation_to_turn_type )[
"LL" ] =
"TurnLL_Ip";
208 ( *conformation_to_turn_type )[
"LE" ] =
"TurnLE_VIIIp";
210 ( *conformation_to_turn_type )[
"EA" ] =
"TurnEA_IIp";
211 ( *conformation_to_turn_type )[
"EB" ] =
"TurnEB";
212 ( *conformation_to_turn_type )[
"EL" ] =
"TurnEL";
213 ( *conformation_to_turn_type )[
"EE" ] =
"TurnEE";
216 ( *conformation_to_turn_type )[
"Ba" ] =
"TurnCis3_VIa";
217 ( *conformation_to_turn_type )[
"Bb" ] =
"TurnCis3_VIb";
220 ( *conformation_to_turn_type )[
"xX" ] =
"TurnCis2";
221 ( *conformation_to_turn_type )[
"xx" ] =
"TurnCis2Cis3";
222 ( *conformation_to_turn_type )[
"Xx" ] =
"TurnCis3other";
224 return *conformation_to_turn_type;
232 if ( valid_ramachandran_hashes == 0 )
237 ( *valid_ramachandran_hashes )[
A ] =
"A";
238 ( *valid_ramachandran_hashes )[
B ] =
"B";
239 ( *valid_ramachandran_hashes )[
L ] =
"L";
240 ( *valid_ramachandran_hashes )[
E ] =
"E";
243 return *valid_ramachandran_hashes;
249 for (
Size residue_number = first_residue + 1; residue_number <= first_residue +
beta_turn_length; ++residue_number )
261 for (
Size current_residue = range_begin; current_residue <= range_end; ++current_residue )
263 if ( current_residue > relevant_residues.size() || !relevant_residues[ current_residue ] )
273 for (
Size current_residue = range_begin; current_residue <= range_end; ++current_residue )
299 string rama_hash =
"";
300 for (
Size residue_number = first_residue + 1; residue_number < first_residue +
beta_turn_length; ++residue_number )
341 if ( psi > -100. && psi <= 50. )
352 if ( psi > -50. && psi <= 100. )
363 if ( omega > -90 && omega <= 90 )
365 transform( rama_hash.begin(), rama_hash.end(), rama_hash.begin(), ::tolower );
374 string cis_trans_hash =
"";
376 for ( string::const_iterator it = rama_hash.begin(); it != rama_hash.end(); ++it )
378 bool cis_peptide_bond = islower( * it );
379 string single_residue_rama_hash( 1, toupper( * it ) );
383 throw EXCN_Msg_Exception(
"The Ramachandran hash '" + rama_hash +
"' contains '" +
string( 1, * it ) +
",' which is not valid. " +
384 "Valid Ramachandran hashes are 'A', 'B', 'L' and 'E' for trans peptide bonds, and 'a', 'b', 'l' and 'e' for cis peptide bonds."
387 cis_trans_hash += cis_peptide_bond ?
"x" :
"X";
392 throw EXCN_Msg_Exception(
"The Ramachandran hash '" + rama_hash +
393 "' is not recognized as a valid beta-turn type. " +
394 "The attempt to create a generic hash based on the omega dihedral angle resulted in '" +
395 cis_trans_hash +
",' which is also not recognized as a valid beta-turn type."
399 rama_hash = cis_trans_hash;