Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProteinBondGeometryFeatures.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/ProteinBondGeometryFeatures.cc
11 /// @brief report Backbone Torsional Angle features
12 /// @author Matthew O'Meara
13 
14 // Unit Headers
18 
19 // Project Headers
21 #include <utility/sql_database/DatabaseSessionManager.hh>
22 #include <utility/vector1.hh>
23 #include <basic/database/sql_utils.hh>
24 #include <basic/options/option.hh>
25 #include <basic/options/keys/score.OptionKeys.gen.hh>
26 #include <numeric/xyz.functions.hh>
30 #include <basic/basic.hh>
31 #include <basic/Tracer.hh>
32 #include <basic/database/schema_generator/PrimaryKey.hh>
33 #include <basic/database/schema_generator/ForeignKey.hh>
34 #include <basic/database/schema_generator/Column.hh>
35 #include <basic/database/schema_generator/Schema.hh>
36 
37 #include <core/pose/PDBInfo.hh>
38 
39 // Platform Headers
40 #include <core/pose/Pose.hh>
41 
42 // External Headers
43 #include <cppdb/frontend.h>
44 #include <boost/uuid/uuid.hpp>
45 #include <boost/lexical_cast.hpp>
46 #include <boost/uuid/uuid_io.hpp>
47 
48 namespace protocols{
49 namespace features{
50 
51 using std::string;
52 using cppdb::statement;
53 using core::Size;
54 using core::Real;
56 using core::pose::Pose;
57 using utility::vector1;
58 using utility::sql_database::sessionOP;
59 
60 static basic::Tracer TR("protocols.features.ProteinBondGeometry");
61 
63  // if flag _or_ energy method wants a linear potential, make the potential linear - ptc: just the flag here
65  basic::options::option[ basic::options::OptionKeys::score::linear_bonded_potential ]();
66 
67  // initialize databases
68  db_ = new core::scoring::methods::IdealParametersDatabase(-1.0,-1.0,-1.0,-1.0,-1.0);
69 }
70 
73 {
74 }
75 
77 
78 string
79 ProteinBondGeometryFeatures::type_name() const { return "ProteinBondGeometryFeatures"; }
80 
81 void
83  sessionOP db_session
84 ) const {
90 }
91 
92 void
94  sessionOP db_session
95 ) const {
96  using namespace basic::database::schema_generator;
97 
98  Column struct_id("struct_id", new DbUUID(), false);
99  Column resNum("resNum", new DbInteger(), false);
100  Column cenAtmNum("cenAtmNum", new DbInteger(), false);
101  Column outAtm1Num("outAtm1Num", new DbInteger(), false);
102  Column outAtm2Num("outAtm2Num", new DbInteger(), false);
103  Column cenAtmName("cenAtmName", new DbText(), false);
104  Column outAtm1Name("outAtm1Name", new DbText(), false);
105  Column outAtm2Name("outAtm2Name", new DbText(), false);
106  Column ideal("ideal", new DbReal());
107  Column observed("observed", new DbReal());
108  Column difference("difference", new DbReal());
109  Column energy("energy", new DbReal());
110 
111  Columns primary_key_columns;
112  primary_key_columns.push_back(struct_id);
113  primary_key_columns.push_back(resNum);
114  primary_key_columns.push_back(cenAtmNum);
115  primary_key_columns.push_back(outAtm1Num);
116  primary_key_columns.push_back(outAtm2Num);
117  PrimaryKey primary_key(primary_key_columns);
118 
119  Columns foreign_key_columns;
120  foreign_key_columns.push_back(struct_id);
121  foreign_key_columns.push_back(resNum);
122  vector1< std::string > reference_columns;
123  reference_columns.push_back("struct_id");
124  reference_columns.push_back("resNum");
125  ForeignKey foreign_key(foreign_key_columns, "residues", reference_columns, true);
126 
127  Schema table("bond_intrares_angles", primary_key);
128  table.add_foreign_key(foreign_key);
129  table.add_column(cenAtmName);
130  table.add_column(outAtm1Name);
131  table.add_column(outAtm2Name);
132  table.add_column(ideal);
133  table.add_column(observed);
134  table.add_column(difference);
135  table.add_column(energy);
136 
137  table.write(db_session);
138 }
139 
140 void
142  sessionOP db_session
143 ) const {
144  using namespace basic::database::schema_generator;
145 
146  Column struct_id("struct_id", new DbUUID(), false);
147  Column cenResNum("cenresNum", new DbInteger(), false);
148  Column connResNum("connResNum", new DbInteger(), false);
149  Column cenAtmNum("cenAtmNum", new DbInteger(), false);
150  Column outAtmCenNum("outAtmCenNum", new DbInteger(), false);
151  Column outAtmConnNum("outAtmConnNum", new DbInteger(), false);
152  Column cenAtmName("cenAtmName", new DbText(), false);
153  Column outAtmCenName("outAtmCenName", new DbText(), false);
154  Column outAtmConnName("outAtmConnName", new DbText(), false);
155  Column ideal("ideal", new DbReal());
156  Column observed("observed", new DbReal());
157  Column difference("difference", new DbReal());
158  Column energy("energy", new DbReal());
159 
160  Columns primary_key_columns;
161  primary_key_columns.push_back(struct_id);
162  primary_key_columns.push_back(cenResNum);
163  primary_key_columns.push_back(connResNum);
164  primary_key_columns.push_back(cenAtmNum);
165  primary_key_columns.push_back(outAtmCenNum);
166  primary_key_columns.push_back(outAtmConnNum);
167  PrimaryKey primary_key(primary_key_columns);
168 
169  Columns foreign_key_columns;
170  foreign_key_columns.push_back(struct_id);
171  foreign_key_columns.push_back(cenResNum);
172  vector1< std::string > reference_columns;
173  reference_columns.push_back("struct_id");
174  reference_columns.push_back("resNum");
175  ForeignKey foreign_key(foreign_key_columns, "residues", reference_columns, true);
176 
177  Schema table("bond_interres_angles", primary_key);
178  table.add_foreign_key(foreign_key);
179  table.add_column(cenAtmName);
180  table.add_column(outAtmCenName);
181  table.add_column(outAtmConnName);
182  table.add_column(ideal);
183  table.add_column(observed);
184  table.add_column(difference);
185  table.add_column(energy);
186 
187  table.write(db_session);
188 }
189 
190 void
192  sessionOP db_session
193 ) const {
194  using namespace basic::database::schema_generator;
195 
196  Column struct_id("struct_id", new DbUUID(), false);
197  Column resNum("resNum", new DbInteger(), false);
198  Column atm1Num("atm1Num", new DbInteger(), false);
199  Column atm2Num("atm2Num", new DbInteger(), false);
200  Column atm1Name("atm1Name", new DbText(), false);
201  Column atm2Name("atm2Name", new DbText(), false);
202  Column ideal("ideal", new DbReal());
203  Column observed("observed", new DbReal());
204  Column difference("difference", new DbReal());
205  Column energy("energy", new DbReal());
206 
207  Columns primary_key_columns;
208  primary_key_columns.push_back(struct_id);
209  primary_key_columns.push_back(resNum);
210  primary_key_columns.push_back(atm1Num);
211  primary_key_columns.push_back(atm2Num);
212  PrimaryKey primary_key(primary_key_columns);
213 
214  Columns foreign_key_columns;
215  foreign_key_columns.push_back(struct_id);
216  foreign_key_columns.push_back(resNum);
217  vector1< std::string > reference_columns;
218  reference_columns.push_back("struct_id");
219  reference_columns.push_back("resNum");
220  ForeignKey foreign_key(foreign_key_columns, "residues", reference_columns, true);
221 
222  Schema table("bond_intrares_lengths", primary_key);
223  table.add_foreign_key(foreign_key);
224  table.add_column(atm1Name);
225  table.add_column(atm2Name);
226  table.add_column(ideal);
227  table.add_column(observed);
228  table.add_column(difference);
229  table.add_column(energy);
230 
231  table.write(db_session);
232 }
233 
234 void
236  sessionOP db_session
237 ) const {
238  using namespace basic::database::schema_generator;
239 
240  Column struct_id("struct_id", new DbUUID(), false);
241  Column res1Num("res1Num", new DbInteger(), false);
242  Column res2Num("res2Num", new DbInteger(), false);
243  Column atm1Num("atm1Num", new DbInteger(), false);
244  Column atm2Num("atm2Num", new DbInteger(), false);
245  Column atm1Name("atm1Name", new DbText(), false);
246  Column atm2Name("atm2Name", new DbText(), false);
247  Column ideal("ideal", new DbReal());
248  Column observed("observed", new DbReal());
249  Column difference("difference", new DbReal());
250  Column energy("energy", new DbReal());
251 
252  Columns primary_key_columns;
253  primary_key_columns.push_back(struct_id);
254  primary_key_columns.push_back(res1Num);
255  primary_key_columns.push_back(res2Num);
256  primary_key_columns.push_back(atm1Num);
257  primary_key_columns.push_back(atm2Num);
258  PrimaryKey primary_key(primary_key_columns);
259 
260  Columns foreign_key_columns1;
261  foreign_key_columns1.push_back(struct_id);
262  foreign_key_columns1.push_back(res1Num);
263  vector1< std::string > reference_columns1;
264  reference_columns1.push_back("struct_id");
265  reference_columns1.push_back("resNum");
266  ForeignKey foreign_key1(foreign_key_columns1, "residues", reference_columns1, true);
267 
268  Columns foreign_key_columns2;
269  foreign_key_columns2.push_back(struct_id);
270  foreign_key_columns2.push_back(res2Num);
271  vector1< std::string > reference_columns2;
272  reference_columns2.push_back("struct_id");
273  reference_columns2.push_back("resNum");
274  ForeignKey foreign_key2(foreign_key_columns2, "residues", reference_columns2, true);
275 
276  Schema table("bond_interres_lengths", primary_key);
277  table.add_foreign_key(foreign_key1);
278  table.add_foreign_key(foreign_key2);
279  table.add_column(atm1Name);
280  table.add_column(atm2Name);
281  table.add_column(ideal);
282  table.add_column(observed);
283  table.add_column(difference);
284  table.add_column(energy);
285 
286  table.write(db_session);
287 }
288 
289 void
291  sessionOP db_session
292 ) const {
293  using namespace basic::database::schema_generator;
294 
295  Column struct_id("struct_id", new DbUUID(), false);
296  Column resNum("resNum", new DbInteger(), false);
297  Column atm1Num("atm1Num", new DbInteger(), false);
298  Column atm2Num("atm2Num", new DbInteger(), false);
299  Column atm3Num("atm3Num", new DbInteger(), false);
300  Column atm4Num("atm4Num", new DbInteger(), false);
301  Column atm1Name("atm1Name", new DbText(), false);
302  Column atm2Name("atm2Name", new DbText(), false);
303  Column atm3Name("atm3Name", new DbText(), false);
304  Column atm4Name("atm4Name", new DbText(), false);
305  Column ideal("ideal", new DbReal(), false);
306  Column observed("observed", new DbReal(), false);
307  Column difference("difference", new DbReal(), false);
308  Column energy("energy", new DbReal(), false);
309 
310  Columns primary_key_columns;
311  primary_key_columns.push_back(struct_id);
312  primary_key_columns.push_back(resNum);
313  primary_key_columns.push_back(atm1Num);
314  primary_key_columns.push_back(atm2Num);
315  primary_key_columns.push_back(atm3Num);
316  primary_key_columns.push_back(atm4Num);
317  PrimaryKey primary_key(primary_key_columns);
318 
319  Columns foreign_key_columns;
320  foreign_key_columns.push_back(struct_id);
321  foreign_key_columns.push_back(resNum);
322  vector1< std::string > reference_columns;
323  reference_columns.push_back("struct_id");
324  reference_columns.push_back("resNum");
325  ForeignKey foreign_key(foreign_key_columns, "residues", reference_columns, true);
326 
327  Schema table("bond_intrares_torsions", primary_key);
328  table.add_foreign_key(foreign_key);
329  table.add_column(atm1Name);
330  table.add_column(atm2Name);
331  table.add_column(atm3Name);
332  table.add_column(atm4Name);
333  table.add_column(ideal);
334  table.add_column(observed);
335  table.add_column(difference);
336  table.add_column(energy);
337 
338  table.write(db_session);
339 }
340 
343  utility::vector1<std::string> dependencies;
344  dependencies.push_back("ResidueFeatures");
345  return dependencies;
346 }
347 
348 Size
350  Pose const & pose,
351  vector1< bool > const & relevant_residues,
352  boost::uuids::uuid const struct_id,
353  sessionOP db_session
354 ){
355  report_intrares_angles( pose, relevant_residues, struct_id, db_session );
356  report_interres_angles( pose, relevant_residues, struct_id, db_session );
357  report_intrares_lengths( pose, relevant_residues, struct_id, db_session );
358  report_interres_lengths( pose, relevant_residues, struct_id, db_session );
359  report_intrares_torsions( pose, relevant_residues, struct_id, db_session );
360  return 0;
361 }
362 
363 void
365  Pose const & pose,
366  vector1< bool > const & relevant_residues,
367  boost::uuids::uuid const struct_id,
368  sessionOP db_session
369 ){
370  std::string statement_string ="INSERT INTO bond_intrares_angles (struct_id, resNum, cenAtmNum, outAtm1Num, outAtm2Num, cenAtmName, outAtm1Name, outAtm2Name, ideal, observed, difference, energy) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
371  statement stmt(basic::database::safely_prepare_statement(statement_string,db_session));
372 
373  Real energy_angle = 0;
374 
375  for (Size i = 1; i <= pose.total_residue(); ++i) {
376  if(!relevant_residues[i]) continue;
377 
378  Residue const & rsd = pose.residue(i);
379  if(!rsd.is_protein()) continue;
380 
381  //following code ripped off from core/scoring/methods/CartesianBondedEnergy.cc
382 
383  // get residue type
384  core::chemical::ResidueType const & rsd_type = rsd.type();
385 
386  // for each angle in the residue
387  for ( Size bondang = 1; bondang <= rsd_type.num_bondangles(); ++bondang ) {
388  // get ResidueType ints
389  Size rt1 = ( rsd_type.bondangle( bondang ) ).key1();
390  Size rt2 = ( rsd_type.bondangle( bondang ) ).key2();
391  Size rt3 = ( rsd_type.bondangle( bondang ) ).key3();
392 
393  // check for vrt
394  //if ( rsd_type.atom_type(rt1).is_virtual()
395  // || rsd_type.atom_type(rt2).is_virtual()
396  // || rsd_type.atom_type(rt3).is_virtual() )
397  if ( rsd_type.aa() == core::chemical::aa_vrt)
398  continue;
399 
400  // lookup Ktheta and theta0
401  Real Ktheta, theta0;
402  db_->lookup_angle_legacy( pose, rsd, rt1, rt2, rt3, Ktheta, theta0 );
403  if (Ktheta == 0.0) continue;
404 
405  // get angle
406  Real const angle = numeric::angle_radians(
407  rsd.atom( rt1 ).xyz(),
408  rsd.atom( rt2 ).xyz(),
409  rsd.atom( rt3 ).xyz() );
410 
411  if (linear_bonded_potential_ && std::fabs(angle - theta0)>1) {
412  energy_angle = 0.5*Ktheta*std::fabs(angle-theta0);
413  //TR << "intrares_angles - linear_bonded energy: " << energy_angle << std::endl;
414  } else {
415  energy_angle = 0.5*Ktheta*(angle-theta0) * (angle-theta0);
416  //TR << "intrares_angles - energy: " << energy_angle << std::endl;
417  /*TR.Debug << pose.pdb_info()->name() << " seqpos: " << rsd.seqpos() << " pdbpos: " << pose.pdb_info()->number(rsd.seqpos()) << " intrares angle: " <<
418  rsd_type.name() << " : " <<
419  rsd.atom_name( rt1 ) << " , " << rsd.atom_name( rt2 ) << " , " <<
420  rsd.atom_name( rt3 ) << " " << angle << " " << theta0 << " " <<
421  Ktheta << " " << 0.5*Ktheta*(angle-theta0) * (angle-theta0) << std::endl;*/
422  }
423 
424  const std::string tmp = boost::lexical_cast<std::string>(struct_id);
425 
426  //report results here
427  stmt.bind(1,struct_id);
428  stmt.bind(2,i);
429  stmt.bind(3,rt2);
430  stmt.bind(4,rt1);
431  stmt.bind(5,rt3);
432  stmt.bind(6,rsd.atom_type( rt2 ).name());
433  stmt.bind(7,rsd.atom_type( rt1 ).name());
434  stmt.bind(8,rsd.atom_type( rt3 ).name());
435  stmt.bind(9,theta0);
436  stmt.bind(10,angle);
437  stmt.bind(11,angle-theta0);
438  stmt.bind(12,energy_angle);
439  basic::database::safely_write_to_database(stmt);
440  }
441  }
442 }
443 
444 void
446  Pose const & pose,
447  vector1< bool > const & relevant_residues,
448  boost::uuids::uuid const struct_id,
449  sessionOP db_session
450 ){
451  std::string statement_string ="INSERT INTO bond_interres_angles (struct_id, cenresNum, connResNum, cenAtmNum, outAtmCenNum, outAtmConnNum, cenAtmName, outAtmCenName, outAtmConnName, ideal, observed, difference, energy) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
452  statement stmt(basic::database::safely_prepare_statement(statement_string,db_session));
453 
454  for (Size i = 1; i <= pose.total_residue(); ++i) {
455  if(!relevant_residues[i]) continue;
456  Residue const & rsd1 = pose.residue(i);
457  if(!rsd1.is_protein()) continue;
458 
459  for (Size j = i+1; j <= pose.total_residue(); ++j) {
460  if(!relevant_residues[j]) continue;
461  Residue const & rsd2 = pose.residue(j);
462  if(!rsd2.is_protein()) continue;
463 
464  //following code ripped off from core/scoring/methods/CartesianBondedEnergy.cc
465 
466  // bail out if the residues aren't bonded
467  if (!rsd1.is_bonded(rsd2)) continue;
468 
469  //fpd chainbreak variants also mess things up
470  //fpd check for chainbreaks
471  if ( pose.fold_tree().is_cutpoint( std::min( rsd1.seqpos(), rsd2.seqpos() ) ) ) continue;
472 
473  // get residue types
474  core::chemical::ResidueType const & rsd1_type = rsd1.type();
475  core::chemical::ResidueType const & rsd2_type = rsd2.type();
476 
477  utility::vector1< Size > const & r1_resconn_ids( rsd1.connections_to_residue( rsd2 ) );
478 
479  for ( Size ii = 1; ii <= r1_resconn_ids.size(); ++ii ) {
480 
481  Size const resconn_id1( r1_resconn_ids[ii] );
482  Size const resconn_id2( rsd1.residue_connection_conn_id( resconn_id1 ) );
483 
484  Size const resconn_atomno1( rsd1.residue_connection( resconn_id1 ).atomno() );
485  Size const resconn_atomno2( rsd2.residue_connection( resconn_id2 ).atomno() );
486 
487  /// compute the bond-angle energies from pairs of atoms within-1 bond on rsd1 with
488  /// the the connection atom on rsd2.
489  utility::vector1< core::chemical::two_atom_set > const & rsd1_atoms_wi1_bond_of_ii(
490  rsd1_type.atoms_within_one_bond_of_a_residue_connection( resconn_id1 ));
491  for ( Size jj = 1; jj <= rsd1_atoms_wi1_bond_of_ii.size(); ++jj ) {
492  assert( rsd1_atoms_wi1_bond_of_ii[ jj ].key1() == resconn_atomno1 );
493  Size const res1_lower_atomno = rsd1_atoms_wi1_bond_of_ii[ jj ].key2();
494 
495  Real const angle = numeric::angle_radians(
496  rsd1.atom( res1_lower_atomno ).xyz(),
497  rsd1.atom( resconn_atomno1 ).xyz(),
498  rsd2.atom( resconn_atomno2 ).xyz() );
499 
500  // lookup Ktheta and theta0
501  Real Ktheta, theta0;
502  db_->lookup_angle_legacy( pose, rsd1, res1_lower_atomno, resconn_atomno1, -resconn_id1, Ktheta, theta0 );
503 
504  if (Ktheta == 0.0) continue;
505 
506  // accumulate the energy
507  Real energy_angle = 0; //ptc - don't accumulate, report each angle on it's own
508  if (linear_bonded_potential_ && std::fabs(angle-theta0)>1) {
509  energy_angle += 0.5*Ktheta*std::fabs(angle-theta0);
510  } else {
511  energy_angle += 0.5*Ktheta*(angle-theta0) * (angle-theta0);
512  }
513 
514  //report results here
515  stmt.bind(1,struct_id);
516  stmt.bind(2,i);
517  stmt.bind(3,j);
518  stmt.bind(4,resconn_atomno1);
519  stmt.bind(5,res1_lower_atomno);
520  stmt.bind(6, resconn_atomno2);
521  stmt.bind(7, rsd1.atom_type( resconn_atomno1 ).name());
522  stmt.bind(8, rsd1.atom_type( res1_lower_atomno ).name());
523  stmt.bind(9, rsd2.atom_type( resconn_atomno2 ).name());
524  stmt.bind(10,theta0);
525  stmt.bind(11,angle);
526  stmt.bind(12,angle-theta0);
527  stmt.bind(13,energy_angle);
528  basic::database::safely_write_to_database(stmt);
529  }
530 
531  /// compute the bond-angle energies from pairs of atoms within-1 bond on rsd2 with
532  /// the the connection atom on rsd1.
533  utility::vector1< core::chemical::two_atom_set > const & rsd2_atoms_wi1_bond_of_ii(
534  rsd2_type.atoms_within_one_bond_of_a_residue_connection( resconn_id2 ));
535  for ( Size jj = 1; jj <= rsd2_atoms_wi1_bond_of_ii.size(); ++jj ) {
536  assert( rsd2_atoms_wi1_bond_of_ii[ jj ].key1() == resconn_atomno2 );
537  Size const res2_lower_atomno = rsd2_atoms_wi1_bond_of_ii[ jj ].key2();
538 
539  // lookup Ktheta and theta0
540  Real Ktheta, theta0;
541  db_->lookup_angle_legacy( pose, rsd2, res2_lower_atomno, resconn_atomno2, -resconn_id2, Ktheta, theta0 );
542 
543  if (Ktheta == 0.0) continue;
544  Real const angle = numeric::angle_radians(
545  rsd2.atom( res2_lower_atomno ).xyz(),
546  rsd2.atom( resconn_atomno2 ).xyz(),
547  rsd1.atom( resconn_atomno1 ).xyz() );
548 
549  // accumulate the energy
550  Real energy_angle = 0; //ptc - don't accumulate, report each angle on it's own
551  if (linear_bonded_potential_ && std::fabs(angle-theta0)>1) {
552  energy_angle += 0.5*Ktheta*std::fabs(angle-theta0);
553  } else {
554  energy_angle += 0.5*Ktheta*(angle-theta0) * (angle-theta0);
555  }
556 
557  //report results here
558  stmt.bind(1,struct_id);
559  stmt.bind(2,j);
560  stmt.bind(3,i);
561  stmt.bind(4,resconn_atomno2);
562  stmt.bind(5,res2_lower_atomno);
563  stmt.bind(6, resconn_atomno1);
564  stmt.bind(7, rsd2.atom_type( resconn_atomno2 ).name());
565  stmt.bind(8, rsd2.atom_type( res2_lower_atomno ).name());
566  stmt.bind(9, rsd1.atom_type( resconn_atomno1 ).name());
567  stmt.bind(10,theta0);
568  stmt.bind(11,angle);
569  stmt.bind(12,angle-theta0);
570  stmt.bind(13,energy_angle);
571  basic::database::safely_write_to_database(stmt);
572  }
573  }
574  }
575  }
576 }
577 
578 void
580  Pose const & pose,
581  vector1< bool > const & relevant_residues,
582  boost::uuids::uuid const struct_id,
583  sessionOP db_session
584 ){
585  std::string statement_string ="INSERT INTO bond_intrares_lengths (struct_id, resNum, atm1Num, atm2Num, atm1Name, atm2Name, ideal, observed, difference, energy) VALUES (?,?,?,?,?,?,?,?,?,?)";
586  statement stmt(basic::database::safely_prepare_statement(statement_string,db_session));
587 
588  for (Size i = 1; i <= pose.total_residue(); ++i) {
589  if(!relevant_residues[i]) continue;
590 
591  Residue const & rsd = pose.residue(i);
592  if(!rsd.is_protein()) continue;
593 
594  //following code ripped off from core/scoring/methods/CartesianBondedEnergy.cc
595 
596  core::chemical::ResidueType const & rsd_type = rsd.type();
597 
598  // for each bond in the residue
599  // for each bonded atom
600  for (Size atm_i=1; atm_i<=rsd_type.natoms(); ++atm_i) {
601  core::chemical::AtomIndices atm_nbrs = rsd_type.nbrs( atm_i );
602  for (Size j=1; j<=atm_nbrs.size(); ++j) {
603  Size atm_j = atm_nbrs[j];
604  if ( atm_i<atm_j ) { // only score each bond once -- use restype index to define ordering
605  // check for vrt
606  //if ( rsd_type.atom_type(atm_i).is_virtual() || rsd_type.atom_type(atm_j).is_virtual() )
607  if ( rsd_type.aa() == core::chemical::aa_vrt)
608  continue;
609 
610  // lookup Ktheta and theta0
611  Real Kd, d0;
612  db_->lookup_length_legacy( pose, rsd, atm_i, atm_j, Kd, d0 );
613  if (Kd == 0.0) continue;
614 
615  Real const d = ( rsd.atom( atm_i ).xyz()-rsd.atom( atm_j ).xyz() ).length();
616 
617  // accumulate the energy
618  Real energy_length = 0; //ptc - don't accumulate, report each length on it's own
619  if (linear_bonded_potential_ && std::fabs(d - d0)>1) {
620  energy_length += 0.5*Kd*std::fabs(d-d0);
621  } else {
622  energy_length += 0.5*Kd*(d-d0)*(d-d0);
623  }
624 
625  //report results here
626  stmt.bind(1,struct_id);
627  stmt.bind(2,i);
628  stmt.bind(3,atm_i);
629  stmt.bind(4,atm_j);
630  stmt.bind(5, rsd.atom_type( atm_i ).name());
631  stmt.bind(6, rsd.atom_type( atm_j ).name());
632  stmt.bind(7,d0);
633  stmt.bind(8,d);
634  stmt.bind(9,d-d0);
635  stmt.bind(10,energy_length);
636  basic::database::safely_write_to_database(stmt);
637  }
638  }
639  }
640  }
641 }
642 
643 void
645  Pose const & pose,
646  vector1< bool > const & relevant_residues,
647  boost::uuids::uuid const struct_id,
648  sessionOP db_session
649 ){
650  std::string statement_string ="INSERT INTO bond_interres_lengths (struct_id, res1Num, res2Num, atm1Num, atm2Num, atm1Name, atm2Name, ideal, observed, difference, energy) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
651  statement stmt(basic::database::safely_prepare_statement(statement_string,db_session));
652 
653 
654  for (Size i = 1; i <= pose.total_residue(); ++i) {
655  if(!relevant_residues[i]) continue;
656  Residue const & rsd1 = pose.residue(i);
657  if(!rsd1.is_protein()) continue;
658 
659  for (Size j = i+1; j <= pose.total_residue(); ++j) {
660  if(!relevant_residues[j]) continue;
661  Residue const & rsd2 = pose.residue(j);
662  if(!rsd2.is_protein()) continue;
663 
664  //following code ripped off from core/scoring/methods/CartesianBondedEnergy.cc
665 
666  // bail out if the residues aren't bonded
667  if (!rsd1.is_bonded(rsd2)) continue;
668 
669  //fpd chainbreak variants also mess things up
670  //fpd check for chainbreaks
671  if ( pose.fold_tree().is_cutpoint( std::min( rsd1.seqpos(), rsd2.seqpos() ) ) ) continue;
672 
673  utility::vector1< Size > const & r1_resconn_ids( rsd1.connections_to_residue( rsd2 ) );
674 
675  for ( Size ii = 1; ii <= r1_resconn_ids.size(); ++ii ) {
676 
677  Size const resconn_id1( r1_resconn_ids[ii] );
678  Size const resconn_id2( rsd1.residue_connection_conn_id( resconn_id1 ) );
679 
680  Size const resconn_atomno1( rsd1.residue_connection( resconn_id1 ).atomno() );
681  Size const resconn_atomno2( rsd2.residue_connection( resconn_id2 ).atomno() );
682 
683 
684  /// finally, compute the bondlength across the interface
685  Real length =
686  ( rsd2.atom( resconn_atomno2 ).xyz() - rsd1.atom( resconn_atomno1 ).xyz() ).length();
687 
688  // lookup Ktheta and theta0
689  Real Kd, d0;
690  db_->lookup_length_legacy( pose, rsd1, resconn_atomno1, -resconn_id1, Kd, d0 );
691 
692  // accumulate the energy
693  Real energy_length = 0; //ptc - dont accumulate energy, report each length on it's own.
694  if (linear_bonded_potential_ && std::fabs(length-d0)>1) {
695  energy_length += 0.5*Kd*std::fabs(length-d0);
696  } else {
697  energy_length += 0.5*Kd*(length-d0)*(length-d0);
698  }
699 
700  //report results here
701  stmt.bind(1,struct_id);
702  stmt.bind(2,i);
703  stmt.bind(3,j);
704  stmt.bind(4,resconn_atomno1);
705  stmt.bind(5,resconn_atomno2);
706  stmt.bind(6, rsd1.atom_type( resconn_atomno1 ).name());
707  stmt.bind(7, rsd2.atom_type( resconn_atomno2 ).name());
708  stmt.bind(8,d0);
709  stmt.bind(9,length);
710  stmt.bind(10,length-d0);
711  stmt.bind(11,energy_length);
712  basic::database::safely_write_to_database(stmt);
713  }
714  }
715  }
716 }
717 
718 void
720  Pose const & pose,
721  vector1< bool > const & relevant_residues,
722  boost::uuids::uuid const struct_id,
723  sessionOP db_session
724 ){
725  std::string statement_string ="INSERT INTO bond_intrares_torsions (struct_id, resNum, atm1Num, atm2Num, atm3Num, atm4Num, atm1Name, atm2Name, atm3Name, atm4Name, ideal, observed, difference, energy) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
726  statement stmt(basic::database::safely_prepare_statement(statement_string,db_session));
727 
728  for (Size i = 1; i <= pose.total_residue(); ++i) {
729  if(!relevant_residues[i]) continue;
730 
731  Residue const & rsd = pose.residue(i);
732  if(!rsd.is_protein()) continue;
733 
734  //following code ripped off from core/scoring/methods/CartesianBondedEnergy.cc
735 
736  core::chemical::ResidueType const & rsd_type = rsd.type();
737 
738  // for each torsion _that doesn't correspond to a DOF_ID in the pose_
739  for ( Size dihe = 1; dihe <= rsd_type.ndihe(); ++dihe ){
740  // get ResidueType ints
741  int rt1 = ( rsd_type.dihedral( dihe ) ).key1();
742  int rt2 = ( rsd_type.dihedral( dihe ) ).key2();
743  int rt3 = ( rsd_type.dihedral( dihe ) ).key3();
744  int rt4 = ( rsd_type.dihedral( dihe ) ).key4();
745 
746  // lookup Ktheta and theta0
747  Real Kphi, phi0, phi_step;
748  db_->lookup_torsion_legacy( rsd.type(), rt1, rt2, rt3, rt4, Kphi, phi0, phi_step );
749  if (Kphi == 0.0) continue;
750 
751  // get angle
752  Real angle = numeric::dihedral_radians
753  ( rsd.atom( rt1 ).xyz(), rsd.atom( rt2 ).xyz(),
754  rsd.atom( rt3 ).xyz(), rsd.atom( rt4 ).xyz() );
755 
756  // accumulate the energy
757  Real energy_torsion = 0; //ptc - dont accumulate energy, report each torsion on it's own
758  Real del_phi = basic::subtract_radian_angles(angle, phi0);
759  if (phi_step>0) del_phi = basic::periodic_range( del_phi, phi_step );
760 
761  if (linear_bonded_potential_ && std::fabs(del_phi)>1)
762  energy_torsion += 0.5*Kphi*std::fabs(del_phi);
763  else
764  energy_torsion += 0.5*Kphi*del_phi*del_phi;
765 
766  //report results here
767  stmt.bind(1,struct_id);
768  stmt.bind(2,i);
769  stmt.bind(3,rt1);
770  stmt.bind(4,rt2);
771  stmt.bind(5,rt3);
772  stmt.bind(6,rt4);
773  stmt.bind(7,rsd.atom_type( rt1 ).name() );
774  stmt.bind(8,rsd.atom_type( rt2 ).name() );
775  stmt.bind(9,rsd.atom_type( rt3 ).name() );
776  stmt.bind(10,rsd.atom_type( rt4 ).name() );
777  stmt.bind(11,phi0);
778  stmt.bind(12,angle);
779  stmt.bind(13,del_phi);
780  stmt.bind(14,energy_torsion);
781  basic::database::safely_write_to_database(stmt);
782  }
783  }
784 }
785 
786 } // namesapce
787 } // namespace