Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ChargeChargeFeatures.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 protocols/features/ChargeChargeFeatures.cc
11 /// @brief report geometric solvation energy for each polar site to a features database
12 /// @author Joseph S Harrison
13 
14 // Unit Headers
16 
17 // Platform Headers
18 #include <core/pose/Pose.hh>
19 #include <core/types.hh>
20 #include <core/chemical/AA.hh>
23 
24 //Basic Headers
25 #include <basic/database/sql_utils.hh>
26 #include <basic/database/schema_generator/PrimaryKey.hh>
27 #include <basic/database/schema_generator/ForeignKey.hh>
28 #include <basic/database/schema_generator/Column.hh>
29 #include <basic/database/schema_generator/Schema.hh>
30 
31 // Numeric Headers
32 #include <numeric/xyzVector.hh>
33 #include <numeric/xyz.functions.hh>
34 #include <numeric/sphericalVector.hh>
35 #include <core/kinematics/Stub.hh>
36 #include <numeric/constants.hh>
37 
38 // Utility Headers
39 #include <utility/sql_database/DatabaseSessionManager.hh>
40 #include <utility/vector1.hh>
41 
42 // External Headers
43 #include <cppdb/frontend.h>
44 
45 // Boost Headers
46 #include <boost/uuid/uuid_io.hpp>
47 
48 // C++ Headers
49 #include <string>
50 #include <sstream>
51 
52 namespace protocols{
53 namespace features{
54 
55 using std::string;
56 using std::stringstream;
57 using std::endl;
58 using core::Size;
59 using core::Real;
60 using core::Vector;
61 using core::Length;
62 using core::Angle;
63 using core::Distance;
72 using core::pose::Pose;
73 using numeric::dihedral_radians;
74 using numeric::sphericalVector;
75 using numeric::xyz_to_spherical;
76 using numeric::constants::r::pi;
77 using numeric::constants::r::pi_over_2;
78 using numeric::constants::r::pi_over_180;
79 using utility::vector1;
80 using utility::sql_database::sessionOP;
81 using cppdb::statement;
82 using cppdb::result;
83 using boost::uuids::uuid;
84 
87  distance_cutoff_(8)
88 {}
89 
91  Length distance_cutoff) :
93  distance_cutoff_(distance_cutoff)
94 {}
95 
97  ChargeChargeFeatures const & src ) :
99  distance_cutoff_(src.distance_cutoff_)
100 {}
101 
102 string
103 ChargeChargeFeatures::type_name() const { return "ChargeChargeFeatures"; }
104 
105 void
107  sessionOP db_session
108 ) const {
109 
110  using namespace basic::database::schema_generator;
111 
112  Column struct_id("struct_id", new DbUUID(), false);
113  Column q1_site_id("q1_site_id", new DbInteger(), false);
114  Column q2_site_id("q2_site_id", new DbInteger(), false);
115  Column q1_charge("q1_charge", new DbInteger(), false);
116  Column q2_charge("q2_charge", new DbInteger(), false);
117  Column B1q1q2_angle("B1q1q2_angle", new DbReal(), false);
118  Column B2q2q1_angle("B2q2q1_angle", new DbReal(), false);
119  Column q1q2_distance("q1q2_distance", new DbReal(), false);
120  Column B1q1_torsion("B1q1_torsion", new DbReal(), false);
121  Column B2q2_torsion("B2q2_torsion", new DbReal(), false);
122 
124  pkeys.push_back(struct_id);
125  pkeys.push_back(q1_site_id);
126  pkeys.push_back(q2_site_id);
127 
128 
129  utility::vector1<Column> fkey_site1_cols;
130  fkey_site1_cols.push_back(struct_id);
131  fkey_site1_cols.push_back(q1_site_id);
132 
133  utility::vector1<std::string> fkey_site1_reference_cols;
134  fkey_site1_reference_cols.push_back("struct_id");
135  fkey_site1_reference_cols.push_back("site_id");
136 
137  utility::vector1<Column> fkey_site2_cols;
138  fkey_site2_cols.push_back(struct_id);
139  fkey_site2_cols.push_back(q2_site_id);
140 
141  utility::vector1<std::string> fkey_site2_reference_cols;
142  fkey_site2_reference_cols.push_back("struct_id");
143  fkey_site2_reference_cols.push_back("site_id");
144 
145  Schema charge_charge_pairs("charge_charge_pairs", PrimaryKey(pkeys));
146  charge_charge_pairs.add_column(struct_id);
147  charge_charge_pairs.add_column(q1_site_id);
148  charge_charge_pairs.add_column(q2_site_id);
149  charge_charge_pairs.add_column(q1_charge);
150  charge_charge_pairs.add_column(q2_charge);
151  charge_charge_pairs.add_column(B1q1q2_angle);
152  charge_charge_pairs.add_column(B2q2q1_angle);
153  charge_charge_pairs.add_column(q1q2_distance);
154  charge_charge_pairs.add_column(B1q1_torsion);
155  charge_charge_pairs.add_column(B2q2_torsion);
156  charge_charge_pairs.add_foreign_key(
157  ForeignKey(fkey_site1_cols, "hbond_sites", fkey_site1_reference_cols, true));
158  charge_charge_pairs.add_foreign_key(
159  ForeignKey(fkey_site2_cols, "hbond_sites", fkey_site2_reference_cols, true));
160 
161  charge_charge_pairs.write(db_session);
162 }
163 
166  utility::vector1<std::string> dependencies;
167  dependencies.push_back("ResidueFeatures");
168  dependencies.push_back("HBondFeatures");
169  return dependencies;
170 }
171 
172 Size
174  Pose const &,
175  vector1< bool > const &,
176  uuid struct_id,
177  sessionOP db_session
178 ){
179 
180  // locate candidate polar sites from the hbond_sites table
181 
182  // Note: these are all pairs of potential salt bridge sites, not
183  // just the ones involved in hydrogen bonds
184  std::string hbond_string =
185  "SELECT\n"
186  " q1.site_id AS q1_id,\n"
187  " q2.site_id AS q2_id,\n"
188  " CASE q1.is_donor WHEN 1 THEN 1 ELSE -1 END AS q1_charge,\n"
189  " CASE q2.is_donor WHEN 1 THEN 1 ELSE -1 END AS q2_charge,\n"
190  " q1_xyz.atm_x AS q1_x, q1_xyz.atm_y AS q1_y, q1_xyz.atm_z AS q1_z,\n"
191  " q2_xyz.atm_x AS q2_x, q2_xyz.atm_y AS q2_y, q2_xyz.atm_z AS q2_z,\n"
192  " q1_xyz.base_x AS B1_x, q1_xyz.base_y AS B1_y, q1_xyz.base_z AS B1_z,\n"
193  " q2_xyz.base_x AS B2_x, q2_xyz.base_y AS B2_y, q2_xyz.base_z AS B2_z,\n"
194  " q1_xyz.bbase_x AS C1_x, q1_xyz.bbase_y AS C1_y, q1_xyz.bbase_z AS C1_z,\n"
195  " q2_xyz.bbase_x AS C2_x, q2_xyz.bbase_y AS C2_y, q2_xyz.bbase_z AS C2_z\n"
196  "FROM\n"
197  " hbond_sites AS q1,\n"
198  " hbond_sites AS q2,\n"
199  " hbond_site_atoms AS q1_xyz,\n"
200  " hbond_site_atoms AS q2_xyz\n"
201  "WHERE\n"
202  " q1.struct_id = ? AND q2.struct_id = ? AND\n"
203  " q1.resNum < q2.resNum AND\n"
204  " (q1.HBChemType = 'hbacc_CXL' OR\n"
205  " q1.HBChemType = 'hbacc_IMD' OR q1.HBChemType = 'hbacc_IME' OR q1.HBChemType = 'hbdon_IMD' OR q1.HBChemType = 'hbdon_IME' OR\n"
206  " q1.HBChemType = 'hbdon_AMO' OR\n"
207  " q1.HBChemType = 'hbdon_GDE' OR q1.HBChemType = 'hbdon_GDH' ) AND\n"
208  " (q2.HBChemType = 'hbacc_CXL' OR\n"
209  " q2.HBChemType = 'hbacc_IMD' OR q2.HBChemType = 'hbacc_IME' OR q2.HBChemType = 'hbdon_IMD' OR q2.HBChemType = 'hbdon_IME' OR\n"
210  " q2.HBChemType = 'hbdon_AMO' OR\n"
211  " q2.HBChemType = 'hbdon_GDE' OR q2.HBChemType = 'hbdon_GDH' ) AND\n"
212  " q1_xyz.struct_id = q1.struct_id AND\n"
213  " q2_xyz.struct_id = q2.struct_id AND\n"
214  " q1_xyz.site_id = q1.site_id AND\n"
215  " q2_xyz.site_id = q2.site_id;\n";
216 
217  statement hbond_stmt(basic::database::safely_prepare_statement(hbond_string,db_session));
218  hbond_stmt.bind(1,struct_id);
219  hbond_stmt.bind(2,struct_id);
220 
221  result res(basic::database::safely_read_from_database(hbond_stmt));
222  Size q1_site_id, q2_site_id;
223  int q1_charge;
224  int q2_charge;
225  Length q1_x, q1_y, q1_z;
226  Length q2_x, q2_y, q2_z;
227  Length B1_x, B1_y, B1_z;
228  Length B2_x, B2_y, B2_z;
229  Length C1_x, C1_y, C1_z;
230  Length C2_x, C2_y, C2_z;
231 
232  std::string charge_charge_string = "INSERT INTO charge_charge_pairs (struct_id, q1_site_id, q2_site_id, q1_charge, q2_charge, B1q1q2_angle, B2q2q1_angle, q1q2_distance, B1q1_torsion, B2q2_torsion) VALUES (?,?,?,?,?,?,?,?,?,?);";
233  statement charge_charge_statement(basic::database::safely_prepare_statement(charge_charge_string,db_session));
234 
235 
236  while(res.next()){
237  res >> q1_site_id >> q2_site_id;
238  res >> q1_charge >> q2_charge;
239  res >> q1_x >> q1_y >> q1_z;
240  res >> q2_x >> q2_y >> q2_z;
241  res >> B1_x >> B1_y >> B1_z;
242  res >> B2_x >> B2_y >> B2_z;
243  res >> C1_x >> C1_y >> C1_z;
244  res >> C2_x >> C2_y >> C2_z;
245 
246  PointPosition const q1(q1_x, q1_y, q1_z);
247  PointPosition const q2(q2_x, q2_y, q2_z);
248  PointPosition const B1(B1_x, B1_y, B1_z);
249  PointPosition const B2(B2_x, B2_y, B2_z);
250  PointPosition const C1(C1_x, C1_y, C1_z);
251  PointPosition const C2(C2_x, C2_y, C2_z);
252 
253  Angle const B1q1q2_angle(angle_of(B1, q1, q2));
254  Angle const B2q2q1_angle(angle_of(B2, q2, q1));
255  Distance const q1q2_distance = q1.distance(q2);
256  Angle const B1q1_torsion(dihedral_radians(C1, B1, q1, q2));
257  Angle const B2q2_torsion(dihedral_radians(C2, B2, q2, q1));
258 
259 
260  if(q1q2_distance > distance_cutoff_){
261  continue;
262  }
263 
264 
265 
266  charge_charge_statement.bind(1,struct_id);
267  charge_charge_statement.bind(2,q1_site_id);
268  charge_charge_statement.bind(3,q2_site_id);
269  charge_charge_statement.bind(4,q1_charge);
270  charge_charge_statement.bind(5,q2_charge);
271  charge_charge_statement.bind(6,B1q1q2_angle);
272  charge_charge_statement.bind(7,B2q2q1_angle);
273  charge_charge_statement.bind(8,q1q2_distance);
274  charge_charge_statement.bind(9,B1q1_torsion);
275  charge_charge_statement.bind(10,B2q2_torsion);
276  basic::database::safely_write_to_database(charge_charge_statement);
277 
278  }
279 
280  return 0;
281 }
282 
283 } //namesapce
284 } //namespace