Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SmotifFeatures.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 SmotifFeatures.cc
11 ///
12 /// @brief Calculate 4 geometric values used to classify smotifs. Reference (http://www.ncbi.nlm.nih.gov/pubmed/20421995)
13 /// @author Tim Jacobs
14 
15 // Unit Headers
17 
18 // Project Headers
19 #include <basic/Tracer.hh>
21 #include <core/pose/Pose.hh>
22 #include <core/types.hh>
24 
25 #ifdef WIN32
27 #endif
28 
29 //Basic Headers
30 #include <basic/database/sql_utils.hh>
31 #include <basic/database/schema_generator/PrimaryKey.hh>
32 #include <basic/database/schema_generator/ForeignKey.hh>
33 #include <basic/database/schema_generator/Column.hh>
34 #include <basic/database/schema_generator/Schema.hh>
35 #include <basic/database/schema_generator/Constraint.hh>
36 #include <basic/Tracer.hh>
37 
38 // Numeric Headers
39 #include <numeric/xyzMatrix.hh>
40 #include <numeric/xyzVector.hh>
41 #include <numeric/xyz.functions.hh>
42 #include <numeric/PCA.hh>
43 #include <numeric/xyzVector.io.hh>
44 
45 
46 // Utility Headers
47 #include <utility/sql_database/DatabaseSessionManager.hh>
48 #include <utility/vector1.hh>
49 
50 namespace protocols{
51 namespace features{
52 
53 static basic::Tracer TR("protocols.features.SmotifFeatures");
54 
55 
57 {}
58 
60 {
61 }
62 
64 {
65 }
66 
68 
69 ///@brief return string with class name
72 {
73  return "SmotifFeatures";
74 }
75 
76 ///@brief generate the table schemas and write them to the database
77 void
78 SmotifFeatures::write_schema_to_db(utility::sql_database::sessionOP db_session) const
79 {
80  using namespace basic::database::schema_generator;
81  using namespace utility;
82 
83  //******smotifs******//
84  Column struct_id("struct_id", new DbUUID(), false);
85  Column smotif_id("smotif_id", new DbInteger(), false);
86  Column ss1("secondary_struct_segment_id_1", new DbInteger(), false);
87  Column ss2("secondary_struct_segment_id_2", new DbInteger(), false);
88  Column loop("loop_segment_id", new DbInteger(), false);
89 
90  //Distance, in angstroms, between C-term of SS1 (P1) and N term of SS2 (P2)
91  Column distance("distance", new DbReal(), false);
92 
93  //Angle between L (vector between P1 and P2) and M1 (principal moment of inertia for SS1)
94  Column hoist("hoist", new DbReal(), false);
95 
96  //Angle between M1 and M2 (principal moment of inertia for SS1 and SS2)
97  Column packing("packing", new DbReal(), false);
98 
99  //Angle between M2 and Gamma (defined by M1 and normal to plane Pie, which is defined
100  Column meridian("meridian", new DbReal(), false);
101 
102  utility::vector1<Column> pkey_cols;
103  pkey_cols.push_back(struct_id);
104  pkey_cols.push_back(smotif_id);
105 
106  Columns foreign_key_columns1;
107  foreign_key_columns1.push_back(struct_id);
108  vector1< std::string > reference_columns1;
109  reference_columns1.push_back("struct_id");
110  ForeignKey foreign_key1(foreign_key_columns1, "structures", reference_columns1, true);
111 
112  Columns foreign_key_columns2;
113  foreign_key_columns2.push_back(struct_id);
114  foreign_key_columns2.push_back(ss1);
115  vector1< std::string > reference_columns2;
116  reference_columns2.push_back("struct_id");
117  reference_columns2.push_back("segment_id");
118  ForeignKey foreign_key2(foreign_key_columns2, "secondary_structure_segments", reference_columns2, true);
119 
120  Columns foreign_key_columns3;
121  foreign_key_columns3.push_back(struct_id);
122  foreign_key_columns3.push_back(ss2);
123  vector1< std::string > reference_columns3;
124  reference_columns3.push_back("struct_id");
125  reference_columns3.push_back("segment_id");
126  ForeignKey foreign_key3(foreign_key_columns3, "secondary_structure_segments", reference_columns3, true);
127 
128  Columns foreign_key_columns4;
129  foreign_key_columns4.push_back(struct_id);
130  foreign_key_columns4.push_back(loop);
131  vector1< std::string > reference_columns4;
132  reference_columns4.push_back("struct_id");
133  reference_columns4.push_back("segment_id");
134  ForeignKey foreign_key4(foreign_key_columns4, "secondary_structure_segments", reference_columns4, true);
135 
136  Schema smotifs("smotifs", PrimaryKey(pkey_cols));
137  smotifs.add_foreign_key(foreign_key1);
138  smotifs.add_foreign_key(foreign_key2);
139  smotifs.add_foreign_key(foreign_key3);
140  smotifs.add_foreign_key(foreign_key4);
141  smotifs.add_column(distance);
142  smotifs.add_column(hoist);
143  smotifs.add_column(packing);
144  smotifs.add_column(meridian);
145 
146  smotifs.write(db_session);
147 }
148 
149 ///@brief return the set of features reporters that are required to
150 ///also already be extracted by the time this one is used.
153 {
154  utility::vector1<std::string> dependencies;
155  dependencies.push_back("SecondaryStructureSegmentFeatures");
156  return dependencies;
157 }
158 
159 void
161  utility::tag::TagPtr const /*tag*/,
162  protocols::moves::DataMap & /*data*/,
163  protocols::filters::Filters_map const & /*filters*/,
164  protocols::moves::Movers_map const & /*movers*/,
165  core::pose::Pose const & /*pose*/)
166 {
167 }
168 
169 ///@brief collect all the feature data for the pose
172  core::pose::Pose const & pose,
173  utility::vector1< bool > const & /*relevant_residues*/,
174  boost::uuids::uuid struct_id,
175  utility::sql_database::sessionOP db_session)
176 {
177  using core::Size;
178  using core::Real;
179  using namespace numeric;
180 
182  get_ss_segments(struct_id, db_session);
183 
184  std::string smotif_insert_string =
185  "INSERT INTO smotifs (struct_id, smotif_id, secondary_struct_segment_id_1,\n"
186  " secondary_struct_segment_id_2, loop_segment_id, distance, hoist, packing,\n"
187  " meridian) VALUES(?,?,?,?,?,?,?,?,?)";
188 
189  cppdb::statement smotif_insert_stmt =
190  basic::database::safely_prepare_statement(smotif_insert_string, db_session);
191 
192  core::Size smotif_counter=1;
193  if(ss_segments.size()>2)
194  {
195  for(Size i=1; i<=ss_segments.size()-2; ++i)
196  {
197  SecondaryStructureSegment ss1=ss_segments[i];
198  SecondaryStructureSegment loop=ss_segments[i+1];
199  SecondaryStructureSegment ss2=ss_segments[i+2];
200 
201  if( (ss1.dssp=="H" || ss1.dssp=="E") &&
202  (ss2.dssp=="H" || ss2.dssp=="E") &&
203  loop.dssp == "L")//make sure loop is loop
204  {
206  for(core::Size i=ss1.residue_begin; i<=ss1.residue_end; ++i){
207  ss1_coords.push_back(pose.residue(i).atom("CA").xyz());
208  }
209 
211  for(core::Size i=ss2.residue_begin; i<=ss2.residue_end; ++i){
212  ss2_coords.push_back(pose.residue(i).atom("CA").xyz());
213  }
214 
215  xyzVector<core::Real> ss1_com = center_of_mass(ss1_coords);
216  xyzVector<core::Real> ss1_first_principal_component =
217  first_principal_component(ss1_coords);
218 
219  //Draw principal component vector from COM instead of origin
220  xyzVector<core::Real> ss1_com_principal_component=
221  ss1_first_principal_component+=ss1_com;
222 
223  //p0 is point on principal component vector closest to N-term of SS1
225  closest_point_on_line(ss1_com, ss1_com_principal_component,
226  pose.residue(ss1.residue_begin).atom("CA").xyz());
227 
228  //p1 is point on principal component vector closest to C-term of SS1
230  closest_point_on_line(ss1_com, ss1_com_principal_component,
231  pose.residue(ss1.residue_end).atom("CA").xyz());
232 
233  //SS2
234  xyzVector<core::Real> ss2_com = center_of_mass(ss2_coords);
235  xyzVector<core::Real> ss2_first_principal_component =
236  first_principal_component(ss2_coords);
237 
238  xyzVector<core::Real> ss2_com_principal_component=
239  ss2_first_principal_component+=ss2_com;
240 
241  //p2 is point on principal component vector closest to N-term of SS2
243  closest_point_on_line(ss2_com, ss2_com_principal_component,
244  pose.residue(ss2.residue_begin).atom("CA").xyz());
245 
246  //p3 is point on principal component vector closest to C-term of SS2
248  closest_point_on_line(ss2_com, ss2_com_principal_component,
249  pose.residue(ss2.residue_end).atom("CA").xyz());
250 
251  core::Real distance = p1.distance(p2);
252  core::Real hoist_angle_degrees = angle_degrees(p0,p1,p2);
253  core::Real packing_angle_degrees = angle_degrees(p0,p1,p2,p3);
254 
255  core::Real meridian_angle_degrees = dihedral_degrees(p0,p1,p2,p3);
256 
257  smotif_insert_stmt.bind(1, struct_id);
258  smotif_insert_stmt.bind(2, smotif_counter);
259  smotif_insert_stmt.bind(3, ss1.segment_id);
260  smotif_insert_stmt.bind(4, ss2.segment_id);
261  smotif_insert_stmt.bind(5, loop.segment_id);
262  smotif_insert_stmt.bind(6, distance);
263  smotif_insert_stmt.bind(7, hoist_angle_degrees);
264  smotif_insert_stmt.bind(8, packing_angle_degrees);
265  smotif_insert_stmt.bind(9, meridian_angle_degrees);
266 
267  basic::database::safely_write_to_database(smotif_insert_stmt);
268  ++smotif_counter;
269  }
270  }
271  }
272  return 0; // Added to remove warning; should this be returning an ID of some sort? ~Labonte
273 }
274 
277  boost::uuids::uuid struct_id,
278  utility::sql_database::sessionOP db_session)
279 {
280 
281  using cppdb::statement;
282  using cppdb::result;
283  using core::Size;
284 
285  std::string ss_segment_select_string=
286  "SELECT\n"
287  " segment_id, residue_begin, residue_end, dssp\n"
288  "FROM\n"
289  " secondary_structure_segments\n"
290  "WHERE\n"
291  " struct_id = ?\n"
292  "ORDER BY segment_id";
293 
294  statement ss_segment_select_statement(
295  basic::database::safely_prepare_statement(ss_segment_select_string,db_session));
296  ss_segment_select_statement.bind(1,struct_id);
297  result res(basic::database::safely_read_from_database(ss_segment_select_statement));
298 
300  while(res.next()){
301 
302  Size segment_id, residue_begin, residue_end;
303  std::string dssp;
304  res >> segment_id >> residue_begin >> residue_end >> dssp;
305 
306  SecondaryStructureSegment ss_segment;
307  ss_segment.segment_id = segment_id;
308  ss_segment.residue_begin = residue_begin;
309  ss_segment.residue_end = residue_end;
310  ss_segment.dssp = dssp;
311 
312  ss_segments.push_back(ss_segment);
313  }
314  return ss_segments;
315 
316 }
317 
318 } // namespace
319 } // namespace