23 #include <boost/uuid/uuid.hpp>
30 #include <utility/sql_database/DatabaseSessionManager.hh>
31 #include <utility/tag/Tag.hh>
32 #include <utility/LexicographicalIterator.hh>
47 #include <cppdb/frontend.h>
50 #include <basic/database/sql_utils.hh>
51 #include <basic/Tracer.hh>
52 #include <basic/options/util.hh>
53 #include <basic/options/keys/helixAssembly.OptionKeys.gen.hh>
54 #include <basic/database/schema_generator/PrimaryKey.hh>
55 #include <basic/database/schema_generator/ForeignKey.hh>
56 #include <basic/database/schema_generator/Column.hh>
57 #include <basic/database/schema_generator/Schema.hh>
58 #include <basic/database/schema_generator/Constraint.hh>
61 #include <numeric/PCA.hh>
62 #include <numeric/xyz.functions.hh>
63 #include <numeric/xyzVector.hh>
65 static basic::Tracer
TR(
"protocols.features.helixAssembly.HelixBundleFeatures");
69 namespace helixAssembly {
75 using utility::sql_database::sessionOP;
76 using cppdb::statement;
80 helix_cap_dist_cutoff_(12.0),
91 dependencies.push_back(
"ResidueFeatures");
92 dependencies.push_back(
"ProteinResidueConformationFeatures");
93 dependencies.push_back(
"ResidueSecondaryStructureFeatures");
94 dependencies.push_back(
"SecondaryStructureSegmentFeatures");
101 using namespace basic::database::schema_generator;
103 Column struct_id(
"struct_id",
new DbUUID(),
false ,
false );
106 Column bundle_id(
"bundle_id",
new DbInteger(),
false ,
false );
108 Column bundle_size(
"bundle_size",
new DbInteger(),
false,
false);
109 Column helix_size(
"helix_size",
new DbInteger(),
false,
false);
112 helix_bundle_pkey_cols.push_back(struct_id);
113 helix_bundle_pkey_cols.push_back(bundle_id);
115 Schema helix_bundles(
"helix_bundles", helix_bundle_pkey_cols);
116 helix_bundles.add_column(bundle_size);
117 helix_bundles.add_column(helix_size);
118 helix_bundles.add_foreign_key(ForeignKey(struct_id,
"structures",
"struct_id",
true ));
120 helix_bundles.write(db_session);
123 Column helix_id(
"helix_id",
new DbInteger(),
false ,
false );
125 Column flipped(
"flipped",
new DbInteger());
126 Column sasa(
"sasa",
new DbReal());
128 Column residue_begin(
"residue_begin",
new DbInteger());
129 Column residue_end(
"residue_end",
new DbInteger());
132 bundle_helix_pkey_cols.push_back(struct_id);
133 bundle_helix_pkey_cols.push_back(helix_id);
136 fkey_res_reference_cols.push_back(
"struct_id");
137 fkey_res_reference_cols.push_back(
"resNum");
140 fkey_cols_begin.push_back(struct_id);
141 fkey_cols_begin.push_back(residue_begin);
144 fkey_cols_end.push_back(struct_id);
145 fkey_cols_end.push_back(residue_end);
148 fkey_bundle_reference_cols.push_back(
"struct_id");
149 fkey_bundle_reference_cols.push_back(
"bundle_id");
152 fkey_bundle_cols.push_back(struct_id);
153 fkey_bundle_cols.push_back(bundle_id);
156 Schema bundle_helices(
"bundle_helices", bundle_helix_pkey_cols);
157 bundle_helices.add_foreign_key(ForeignKey(fkey_bundle_cols,
"helix_bundles", fkey_bundle_reference_cols,
true ));
158 bundle_helices.add_foreign_key(ForeignKey(fkey_cols_begin,
"residues", fkey_res_reference_cols,
true ));
159 bundle_helices.add_foreign_key(ForeignKey(fkey_cols_end,
"residues", fkey_res_reference_cols,
true ));
160 bundle_helices.add_column(struct_id);
161 bundle_helices.add_column(flipped);
162 bundle_helices.add_column(sasa);
164 bundle_helices.write(db_session);
167 Column pair_id(
"pair_id",
new DbInteger(),
false ,
false );
169 Column helix_id_1(
"helix_id_1",
new DbInteger(),
false,
false);
170 Column helix_id_2(
"helix_id_2",
new DbInteger(),
false,
false);
171 Column shared_fa_atr(
"shared_fa_atr",
new DbReal(),
false,
false);
172 Column interacting_fraction(
"interacting_fraction",
new DbReal(),
false,
false);
173 Column crossing_angle(
"crossing_angle",
new DbReal(),
false,
false);
174 Column end_1_distance(
"end_1_distance",
new DbReal(),
false,
false);
175 Column end_2_distance(
"end_2_distance",
new DbReal(),
false,
false);
178 helix_pair_pkey_cols.push_back(struct_id);
179 helix_pair_pkey_cols.push_back(pair_id);
182 fkey_ref_helix.push_back(
"struct_id");
183 fkey_ref_helix.push_back(
"helix_id");
186 fkey_cols_helix_1.push_back(struct_id);
187 fkey_cols_helix_1.push_back(helix_id_1);
190 fkey_cols_helix_2.push_back(struct_id);
191 fkey_cols_helix_2.push_back(helix_id_2);
193 Schema helix_pairs(
"helix_pairs", helix_pair_pkey_cols);
194 helix_pairs.add_column(helix_id_1);
195 helix_pairs.add_column(helix_id_2);
196 helix_pairs.add_column(shared_fa_atr);
197 helix_pairs.add_column(interacting_fraction);
198 helix_pairs.add_column(crossing_angle);
199 helix_pairs.add_column(end_1_distance);
200 helix_pairs.add_column(end_2_distance);
201 helix_pairs.add_foreign_key(ForeignKey(struct_id,
"structures",
"struct_id",
true ));
202 helix_pairs.add_foreign_key(ForeignKey(fkey_bundle_cols,
"helix_bundles", fkey_bundle_reference_cols,
true ));
203 helix_pairs.add_foreign_key(ForeignKey(fkey_cols_helix_1,
"bundle_helices", fkey_ref_helix,
true ));
204 helix_pairs.add_foreign_key(ForeignKey(fkey_cols_helix_2,
"bundle_helices", fkey_ref_helix,
true ));
206 helix_pairs.write(db_session);
217 " secondary_structure_segments\n"
219 " struct_id = ?\n AND "
221 "ORDER BY residue_begin;";
223 statement select_statement(basic::database::safely_prepare_statement(select_string,db_session));
224 select_statement.bind(1,struct_id);
225 result res(basic::database::safely_read_from_database(select_statement));
233 Size residue_begin, residue_end;
234 res >> residue_begin >> residue_end;
236 if(residue_begin - prev_residue_end == 2 && all_helices.size() > 0)
238 all_helices.pop_back();
239 all_helices.push_back(
new HelicalFragment(prev_residue_begin, residue_end));
240 TR <<
"combining helix segments: " << prev_residue_begin <<
"-" << prev_residue_end
241 <<
" and " << residue_begin <<
"-" << residue_end << std::endl;
245 all_helices.push_back(
new HelicalFragment(residue_begin, residue_end));
247 prev_residue_begin=residue_begin;
248 prev_residue_end=residue_end;
251 TR <<
"number of uninterrupted helix_segments: " << all_helices.size() << std::endl;
253 for(
core::Size i=1; i<=all_helices.size(); ++i)
269 all_helix_fragments.push_back(frag_1);
270 all_helix_fragments.push_back(frag_2);
275 return all_helix_fragments;
286 for(
core::Size i=1; i<=helix_fragments.size(); ++i)
288 for(
core::Size j=i+1; j<=helix_fragments.size(); ++j)
291 if((helix_fragments[i]->seq_start() >= helix_fragments[j]->seq_start() &&
292 helix_fragments[i]->seq_start() <= helix_fragments[j]->seq_end()) ||
294 (helix_fragments[i]->seq_end() >= helix_fragments[j]->seq_start() &&
295 helix_fragments[i]->seq_end() <= helix_fragments[j]->seq_end()))
300 FragmentPair helix_pair(helix_fragments[i], helix_fragments[j]);
317 if(end_1_dist_sq > dist_sq_cutoff || end_2_dist_sq > dist_sq_cutoff)
346 helix_pairs.push_back(helix_pair);
363 std::set<core::Size> interacting_residues;
364 for(
core::Size ii=frag_1->seq_start(); ii<=frag_1->seq_end(); ++ii)
373 iter != iter_end; ++iter )
376 if(jj >= frag_2->seq_start() && jj <= frag_2->seq_end())
383 interacting_residues.insert(ii);
384 interacting_residues.insert(jj);
449 closest_point_on_line(frag_1->com(), frag_1->principal_component(),
450 pose.
residue(frag_1->start()).atom(
"N").
xyz());
452 TR <<
"P0: " << p0.x() <<
"," << p0.y() <<
"," << p0.z() << endl;
455 closest_point_on_line(frag_1->com(), frag_1->principal_component(),
456 pose.
residue(frag_1->end()).atom(
"CA").
xyz());
458 TR <<
"P1: " << p1.x() <<
"," << p1.y() <<
"," << p1.z() << endl;
461 closest_point_on_line(frag_2->com(), frag_2->principal_component(),
462 pose.
residue(frag_2->end()).atom(
"CA").
xyz());
464 TR <<
"P2: " << p2.x() <<
"," << p2.y() <<
"," << p2.z() << endl;
467 closest_point_on_line(frag_2->com(), frag_2->principal_component(),
468 pose.
residue(frag_2->start()).atom(
"N").
xyz());
470 TR <<
"P3: " << p3.x() <<
"," << p3.y() <<
"," << p3.z() << endl;
473 numeric::dihedral_degrees(p0,p1,p2,p3);
486 std::set<HelicalFragmentOP>
const &
558 std::set<HelicalFragmentOP>
const & frag_set
565 for(std::set<HelicalFragmentOP>::const_iterator it_i=frag_set.begin();
566 it_i != frag_set.end(); ++it_i)
568 for(std::set<HelicalFragmentOP>::const_iterator it_j=it_i;
569 ++it_j != frag_set.end(); )
571 if(((*it_i)->seq_start() >= (*it_j)->seq_start() &&
572 (*it_i)->seq_start() <= (*it_j)->seq_end()) ||
574 ((*it_i)->seq_end() >= (*it_j)->seq_start() &&
575 (*it_i)->seq_end() <= (*it_j)->seq_end()))
593 for(
core::Size j=i+1; j<=frag_set.size(); ++j){
596 pose.
residue(frag_set[j]->start()).atom(
"CA").
xyz());
599 pose.
residue(frag_set[j]->end()).atom(
"CA").
xyz());
601 if(helix_start_dist_sq > dist_sq_cutoff || helix_end_dist_sq > dist_sq_cutoff){
609 for(
core::Size j=i+1; j<=frag_set.size(); ++j){
612 pose.
residue(frag_set[j]->start()).atom(
"CA").
xyz());
615 pose.
residue(frag_set[j]->end()).atom(
"CA").
xyz());
617 if(helix_start_dist_sq > dist_sq_cutoff || helix_end_dist_sq > dist_sq_cutoff){
632 for(
core::Size cur_res=fragment->seq_start(); cur_res<=fragment->seq_end(); ++cur_res)
635 fragment_coords.push_back(pose.
residue(cur_res).
atom(
"CA").
xyz());
642 fragment->principal_component(numeric::first_principal_component(fragment_coords) + com);
653 runtime_assert(tag->getOption<
string>(
"name") ==
type_name());
669 boost::uuids::uuid struct_id,
670 utility::sql_database::sessionOP db_session
675 TR <<
"Total helical fragments of size " <<
helix_size_ <<
": " << all_helix_fragments.size() << std::endl;
682 if(helix_pairs.size()==0)
685 TR <<
"Total valid fragment pairs: " << helix_pairs.size() << std::endl;
689 string bundle_insert =
691 "INSERT INTO helix_bundles (bundle_id, struct_id, bundle_size, helix_size) VALUES (?, ?, ?, ?);";
692 statement bundle_insert_stmt(basic::database::safely_prepare_statement(bundle_insert,db_session));
694 string helix_insert =
696 "INSERT INTO bundle_helices (helix_id, bundle_id, struct_id, residue_begin, residue_end, flipped, sasa) VALUES (?,?,?,?,?,?,?);";
697 statement helix_insert_stmt(basic::database::safely_prepare_statement(helix_insert,db_session));
702 "INSERT INTO helix_pairs (pair_id, struct_id, bundle_id, helix_id_1, helix_id_2, shared_fa_atr, interacting_fraction, crossing_angle, end_1_distance, end_2_distance)\n"
703 "VALUES (?,?,?,?,?,?,?,?,?,?)";
704 statement pair_insert_stmt(basic::database::safely_prepare_statement(pair_insert, db_session));
711 num_factorial=num_factorial*temp;
714 denom_factorial=denom_factorial*temp;
717 core::Size n_dims = num_factorial/(2*denom_factorial);
723 for ( utility::LexicographicalIterator lex( dim_sizes ); ! lex.at_end(); ++lex )
728 while(lex[i-1] >= lex[i])
734 lex.continue_at_dimension(i);
739 std::set<HelicalFragmentOP> cur_frag_set;
743 cur_frag_pairs.push_back(cur_frag_pair);
744 cur_frag_set.insert(cur_frag_pair.
fragment_1);
745 cur_frag_set.insert(cur_frag_pair.
fragment_2);
754 bundle_insert_stmt.bind(1,bundle_counter);
755 bundle_insert_stmt.bind(2,struct_id);
762 basic::database::safely_write_to_database(bundle_insert_stmt);
766 std::map<HelicalFragmentOP, core::Size> helix_ids;
767 for(std::set<HelicalFragmentOP>::const_iterator it=cur_frag_set.begin(); it != cur_frag_set.end();
771 helix_insert_stmt.bind(1,helix_counter);
772 helix_insert_stmt.bind(2,bundle_counter);
773 helix_insert_stmt.bind(3,struct_id);
774 helix_insert_stmt.bind(4,(*it)->seq_start());
775 helix_insert_stmt.bind(5,(*it)->seq_end());
776 helix_insert_stmt.bind(6,(*it)->reversed());
777 helix_insert_stmt.bind(7,(*it)->sasa());
785 basic::database::safely_write_to_database(helix_insert_stmt);
787 core::Size helix_id(bundle_insert_stmt.sequence_last(
"bundle_helices_helix_id_seq"));
788 helix_ids.insert(std::make_pair(*it, helix_id));
795 core::Size frag_1_id = helix_ids[it->fragment_1];
796 core::Size frag_2_id = helix_ids[it->fragment_2];
798 pair_insert_stmt.bind(1,pair_counter);
799 pair_insert_stmt.bind(2,struct_id);
800 pair_insert_stmt.bind(3,bundle_counter);
801 pair_insert_stmt.bind(4,frag_1_id);
802 pair_insert_stmt.bind(5,frag_2_id);
803 pair_insert_stmt.bind(6,it->fa_attr);
804 pair_insert_stmt.bind(7,it->fa_fraction);
805 pair_insert_stmt.bind(8,it->crossing_angle);
806 pair_insert_stmt.bind(9,it->end_1_distance);
807 pair_insert_stmt.bind(10,it->end_2_distance);
818 basic::database::safely_write_to_database(pair_insert_stmt);
822 TR <<
"Found " << bundle_counter <<
"total bundles";