Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HBondDatabase.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 // This file is part of the Rosetta software suite and is made available under license.
5 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
6 // (C) 199x-2009 Rosetta Commons participating institutions and developers.
7 // For more information, see http://www.rosettacommons.org/.
8 
9 /// @file core/scoring/hbonds/HBondDatabase.cc
10 /// @brief Database containing params for HBondEnergy
11 /// @author John Karanicolas
12 /// @author Matthew O'Meara
13 
14 
15 // Unit Headers
17 
18 // Package Headers
25 
26 #include <basic/database/open.hh>
27 #include <basic/Tracer.hh>
28 #include <basic/database/sql_utils.hh>
29 #include <basic/database/schema_generator/PrimaryKey.hh>
30 #include <basic/database/schema_generator/ForeignKey.hh>
31 #include <basic/database/schema_generator/Column.hh>
32 #include <basic/database/schema_generator/Schema.hh>
33 
34 
35 // Utility Headers
36 #include <utility/io/izstream.hh>
37 #include <utility/exit.hh>
38 #include <utility/string_util.hh>
39 #include <utility/vector1.hh>
40 #include <utility/sql_database/DatabaseSessionManager.hh>
41 
42 // External Headers
43 #include <cppdb/frontend.h>
44 
45 // Boost Headers
46 #include <boost/foreach.hpp>
47 #define foreach BOOST_FOREACH
48 
49 // C++ headers
50 #include <cmath>
51 
52 #include <ObjexxFCL/FArray3D.hh>
53 
54 
55 
56 namespace core {
57 namespace scoring {
58 namespace hbonds {
59 
60  using std::endl;
61  using std::map;
62  using std::pair;
63  using std::string;
64  using std::stringstream;
65  using cppdb::result;
66  using cppdb::statement;
67  using basic::database::open;
68  using basic::Tracer;
69  using utility::io::izstream;
70  using utility::string_split;
71  using utility::vector1;
72  using utility::sql_database::sessionOP;
73 
74  static Tracer tr("core.scoring.hbonds.HBondDatabase");
75  // Initialize private static data
76  map< const string, HBondDatabaseCOP > HBondDatabase::initialized_databases_;
77 
78 
80  initialized_(false),
81  params_database_tag_(""),
82  HBFadeInterval_lookup_by_name_(),
83  HBFadeInterval_lookup_(),
84  AHdist_short_fade_lookup_(HB_EVAL_TYPE_COUNT, NULL),
85  AHdist_long_fade_lookup_(HB_EVAL_TYPE_COUNT, NULL),
86  cosBAH_fade_lookup_(HB_EVAL_TYPE_COUNT, NULL),
87  cosAHD_fade_lookup_(HB_EVAL_TYPE_COUNT, NULL),
88  HBPoly1D_lookup_by_name_(),
89  HBPoly1D_lookup_(),
90  AHdist_poly_lookup_(HB_EVAL_TYPE_COUNT, NULL),
91  cosBAH_short_poly_lookup_(HB_EVAL_TYPE_COUNT, NULL),
92  cosBAH_long_poly_lookup_(HB_EVAL_TYPE_COUNT, NULL),
93  cosAHD_short_poly_lookup_(HB_EVAL_TYPE_COUNT, NULL),
94  cosAHD_long_poly_lookup_(HB_EVAL_TYPE_COUNT, NULL),
95  chi_poly_lookup_(HB_EVAL_TYPE_COUNT, NULL),
96  don_strength_lookup_(hbdon_MAX, 1.0),
97  acc_strength_lookup_(hbacc_MAX, 1.0),
98  weight_type_lookup_(HB_EVAL_TYPE_COUNT, hbw_NONE)
99 {
100  HBondOptions hb_options; // default ctor reads options system, initializes default parameters tag from which this database will initialize itself.
102  initialize();
103 }
104 
106  //HBondOptionsCOP hb_options
107  std::string const & hbond_params_database_tag
108 ) :
109  initialized_(false),
110  //hb_options_( hb_options ),
111  params_database_tag_( hbond_params_database_tag ),
112  HBFadeInterval_lookup_by_name_(),
113  HBFadeInterval_lookup_(),
114  AHdist_short_fade_lookup_(HB_EVAL_TYPE_COUNT, NULL),
115  AHdist_long_fade_lookup_(HB_EVAL_TYPE_COUNT, NULL),
116  cosBAH_fade_lookup_(HB_EVAL_TYPE_COUNT, NULL),
117  cosAHD_fade_lookup_(HB_EVAL_TYPE_COUNT, NULL),
118  HBPoly1D_lookup_by_name_(),
119  HBPoly1D_lookup_(),
120  AHdist_poly_lookup_(HB_EVAL_TYPE_COUNT, NULL),
121  cosBAH_short_poly_lookup_(HB_EVAL_TYPE_COUNT, NULL),
122  cosBAH_long_poly_lookup_(HB_EVAL_TYPE_COUNT, NULL),
123  cosAHD_short_poly_lookup_(HB_EVAL_TYPE_COUNT, NULL),
124  cosAHD_long_poly_lookup_(HB_EVAL_TYPE_COUNT, NULL),
125  chi_poly_lookup_(HB_EVAL_TYPE_COUNT, NULL),
126  don_strength_lookup_(hbdon_MAX, 1.0),
127  acc_strength_lookup_(hbacc_MAX, 1.0),
128  weight_type_lookup_(HB_EVAL_TYPE_COUNT, hbw_NONE)
129 {
130  initialize();
131 }
132 
134  const HBondDatabase & src
135 ) :
136  ReferenceCount( src ),
137  initialized_(src.initialized_),
138  //hb_options_( src.hb_options_ ),
139  params_database_tag_( src.params_database_tag_ ),
140  HBFadeInterval_lookup_by_name_(src.HBFadeInterval_lookup_by_name_),
141  HBFadeInterval_lookup_(src.HBFadeInterval_lookup_),
142  AHdist_short_fade_lookup_(src.AHdist_short_fade_lookup_),
143  AHdist_long_fade_lookup_(src.AHdist_long_fade_lookup_),
144  cosBAH_fade_lookup_(src.cosBAH_fade_lookup_),
145  cosAHD_fade_lookup_(src.cosAHD_fade_lookup_),
146  HBPoly1D_lookup_by_name_(src.HBPoly1D_lookup_by_name_),
147  HBPoly1D_lookup_(src.HBPoly1D_lookup_),
148  AHdist_poly_lookup_(src.AHdist_poly_lookup_),
149  cosBAH_short_poly_lookup_(src.cosBAH_short_poly_lookup_),
150  cosBAH_long_poly_lookup_(src.cosBAH_long_poly_lookup_),
151  cosAHD_short_poly_lookup_(src.cosAHD_short_poly_lookup_),
152  cosAHD_long_poly_lookup_(src.cosAHD_long_poly_lookup_),
153  chi_poly_lookup_(src.chi_poly_lookup_),
154  don_strength_lookup_(hbdon_MAX, 1.0),
155  acc_strength_lookup_(hbacc_MAX, 1.0),
156  weight_type_lookup_(src.weight_type_lookup_)
157 {}
158 
161 
162  HBondOptions hb_options; // default ctor queries options system, initializes default hbond params
163 
164  map< string const, HBondDatabaseCOP >::const_iterator
165  param_db = initialized_databases_.find( hb_options.params_database_tag() );
166  if(param_db == initialized_databases_.end()){
167  return new HBondDatabase( hb_options.params_database_tag() );
168  }
169  return param_db->second();
170 }
171 
173 HBondDatabase::get_database( string const & tag ){
174 
175  map< string const, HBondDatabaseCOP >::const_iterator
176  param_db = initialized_databases_.find(tag);
177  if(param_db == initialized_databases_.end()){
178  return new HBondDatabase( tag );
179  }
180  return param_db->second();
181 }
182 
183 
184 
186 
187 
188 /// @details initialize hydrogen bond parameters
189 void
191 {
192  if(initialized_){
193  tr << "Re-intializing HBond Database when it has already been initialized!";
194  }
196 
200 
201  // Note if these aren't defined, then they are silently ignored
202  // Currently their use is experimental and are only defined in newer
203  // hbond parameter sets.
206 
207  initialized_ = true;
208 }
209 
210 /// @details has the database already been initialized?
211 bool
213 {
214  return initialized_;
215 }
216 
217 
218 void
220 {
221  string HBFadeInterval_fname = "scoring/score_functions/hbonds/" + params_database_tag_ + "/HBFadeIntervals.csv";
222 
223  izstream s;
224  if (!open(s, HBFadeInterval_fname)){
225  stringstream message;
226  message << "Unable to open hbond parameter file HBFadeInterval:" << endl;
227  message << "'" << HBFadeInterval_fname << "'";
228  utility_exit_with_message(message.str());
229  }
230 
231  Size line_no(0);
232  string line;
233  vector1<string> tokens;
234  Size id;
235  string fade_interval_name;
236  bool smoothed(false);
237  Real min0, fmin, fmax, max0;
238  while ( getline( s, line ) ) {
239  ++line_no;
240  tokens = string_split( line, ',');
241  Size ntokens = 8;
242  if (tokens.size() != ntokens){
243  stringstream message;
244  message << "FadeInterval definition line does not have the expected number of fields " << endl;
245  message << "Expected '" << ntokens << "' tokens but found '" << tokens.size() << "' tokens. " << endl;
246  message << line << endl;
247  utility_exit_with_message(message.str());
248  }
249 
250  Size i(1);
251  { stringstream buf;buf.precision(16); buf << tokens[i]; i++; buf >> id; }
252  { stringstream buf;buf.precision(16); buf << tokens[i]; i++; buf >> fade_interval_name; }
253  {
254  string junction_type;
255  stringstream buf; buf << tokens[i]; i++; buf >> junction_type;
256  if( junction_type == "smoothed" ){
257  smoothed = true;
258  } else if (junction_type == "piecewise_linear"){
259  smoothed = false;
260  } else {
261  stringstream message;
262  message
263  << "On line " << HBFadeInterval_fname << ":" << line_no << ": '" << line << "'"
264  << "the junction_type should be either 'smoothed' or 'piecewise_linear', "
265  << "however it the unrecognized string '" << junction_type << "'." << endl;
266  utility_exit_with_message(message.str());
267  }
268  }
269  { stringstream buf;buf.precision(16); buf << tokens[i]; i++; buf >> min0; }
270  { stringstream buf;buf.precision(16); buf << tokens[i]; i++; buf >> fmin; }
271  { stringstream buf;buf.precision(16); buf << tokens[i]; i++; buf >> fmax; }
272  { stringstream buf;buf.precision(16); buf << tokens[i]; i++; buf >> max0; }
273 
274  FadeIntervalOP fade_interval(
275  new FadeInterval(fade_interval_name, min0, fmin, fmax, max0, smoothed));
276 
277  if( HBFadeInterval_lookup_.size() + 1 != id ){
278  stringstream message;
279  message << "The id fields in the HBFadeInterval file '" << HBFadeInterval_fname << "'" << endl;
280  message << "are out of order or missing: Expected id: " << HBFadeInterval_lookup_.size() + 1 << " but instead found id: " << id << endl;
281  message << "on line: '" << line << "'" << endl;
282  utility_exit_with_message(message.str());
283  }
284  HBFadeInterval_lookup_.push_back(fade_interval);
285  HBFadeInterval_lookup_by_name_[fade_interval_name] = fade_interval;
286  }
287 }
288 
289  /// @details read one dimensional polynomial definition file
290  // File Format:
291  // -fields are space delimited
292  // -Columns are: polynomial_name, geometric_dimension, xmin, xmax, root1, root2, degree, c_a, c_b, ..., c_k
293 void
295 {
296 
297  string HBPoly1D_fname = "scoring/score_functions/hbonds/" + params_database_tag_ + "/HBPoly1D.csv";
298 
299  izstream s;
300  if (!open(s, HBPoly1D_fname)){
301  stringstream message;
302  message << "Unable to open hbond parameter file HBPoly1D:" << endl;
303  message << HBPoly1D_fname;
304  utility_exit_with_message(message.str());
305  }
306 
307  string line;
308  vector1<string> tokens;
309  Size id;
310  string polynomial_name;
311  string geo_dim_name;
312  HBGeoDimType geometric_dimension;
313  Real xmin, xmax, min_val, max_val, root1, root2;
314  Size degree;
315  vector1< Real > coefficients_;
316  while ( getline( s, line ) ) {
317  tokens = string_split( line, ',');
318  Size ntokens = 22;
319  if (tokens.size() != ntokens){
320  stringstream message;
321  message << "Polynomial definition line does not have enough fields" << endl;
322  message << "Expected " << ntokens << " tokens but found " << tokens.size() << " tokens. " << endl;
323  message << line << endl;
324  utility_exit_with_message(message.str());
325  }
326 
327  Size i(1);
328  { stringstream buf; buf << tokens[i]; i++; buf >> id;}
329  { stringstream buf; buf << tokens[i]; i++; buf >> polynomial_name;}
330  i++; // classic name field
331  { stringstream buf; buf << tokens[i]; i++; buf >> geo_dim_name;
332  geometric_dimension = HBondTypeManager::geo_dim_type_from_name( geo_dim_name ); }
333  { stringstream buf; buf << tokens[i]; i++; buf >> xmin;}
334  { stringstream buf; buf << tokens[i]; i++; buf >> xmax;}
335  { stringstream buf; buf << tokens[i]; i++; buf >> min_val;}
336  { stringstream buf; buf << tokens[i]; i++; buf >> max_val;}
337  { stringstream buf; buf << tokens[i]; i++; buf >> root1;}
338  { stringstream buf; buf << tokens[i]; i++; buf >> root2;}
339  { stringstream buf; buf << tokens[i]; i++; buf >> degree;}
340 
341  vector1< Real > coefficients_;
342  Real c;
343  while( i <= tokens.size()){
344  stringstream buf; buf << tokens[i]; i++; buf >> c;
345  coefficients_.push_back(c);
346  }
347 
349  polynomial_name,
350  geometric_dimension,
351  xmin, xmax, min_val, max_val, root1, root2,
352  degree,
353  coefficients_));
354 
355  if( HBPoly1D_lookup_.size() + 1 != id ){
356  stringstream message;
357  message << "The id fields in the HBPoly1D file '" << HBPoly1D_fname << "'" << endl;
358  message << "are out of order or missing: Expected id: " << HBPoly1D_lookup_.size() + 1 << " but instead found id: " << id << endl;
359  message << "on line: '" << line << "'" << endl;
360  utility_exit_with_message(message.str());
361  }
362  HBPoly1D_lookup_.push_back(p);
363  HBPoly1D_lookup_by_name_[polynomial_name] = p;
364 
365  }
366 }
367 
368  ///@details read one dimensional polynomial definition file
369  // File Format:
370  // -fields are space delimited
371  // -Columns are: HBDonChemType, HBAccChemType, HBSeqSep, AHdist_short_fade_name, AHdist_long_fade_name, cosBAH_fade_name, cosAHD_fade_name, AHDist_poly_name, cosBAH_poly_name, cosAHD_poly_name,
372 
373 void
375 {
376 
377  string HBEval_fname = "scoring/score_functions/hbonds/" + params_database_tag_ + "/HBEval.csv";
378 
379  izstream s;
380  open(s, HBEval_fname);
381  Size line_number(0);
382  vector1<string> tokens;
383  string line;
384  vector1<bool> initialized_hbe_types(hbe_MAX,false);
385  string AHdist_poly_name, cosBAH_short_poly_name, cosBAH_long_poly_name,
386  cosAHD_short_poly_name, cosAHD_long_poly_name, chi_poly_name,
387  don_chem_type_name, acc_chem_type_name, seq_sep_type_name,
388  AHdist_short_fade_name, AHdist_long_fade_name,
389  cosBAH_fade_name, cosAHD_fade_name;
390  HBDonChemType don_chem_type;
391  HBAccChemType acc_chem_type;
392  HBSeqSep seq_sep_type;
393  Polynomial_1dCOP AHdist_poly, cosBAH_short_poly, cosBAH_long_poly,
394  cosAHD_short_poly, cosAHD_long_poly, chi_poly;
395  FadeIntervalCOP AHdist_short_fade, AHdist_long_fade, cosBAH_fade, cosAHD_fade;
396  string weight_type_name;
397  HBondWeightType weight_type;
398 
399  while (getline(s, line)) {
400  ++line_number;
401  tokens = string_split( line, ',');
402  if (tokens.size() != 15){
403  stringstream message;
404  message << "HBond evaluation data line does not have enough fields" << endl;
405  message << "Expected '" << 15 << "' tokens but found '" << tokens.size() << "' tokens." << endl;
406  message << line << endl;
407  utility_exit_with_message(message.str());
408  }
409 
410  Size i(1);
411  {
412  stringstream buf;
413  buf << tokens[i]; i++;
414  buf >> don_chem_type_name;
415  don_chem_type = HBDonChemType(HBondTypeManager::don_chem_type_from_name(don_chem_type_name));
416  }
417  {
418  stringstream buf;
419  buf << tokens[i]; i++;
420  buf >> acc_chem_type_name;
421  acc_chem_type = HBAccChemType(HBondTypeManager::acc_chem_type_from_name(acc_chem_type_name));
422  }
423  {
424  stringstream buf;
425  buf << tokens[i]; i++;
426  buf >> seq_sep_type_name;
427  seq_sep_type = HBSeqSep(HBondTypeManager::seq_sep_type_from_name(seq_sep_type_name));
428  }
429 
430  HBEvalType hbe_type = HBEval_lookup(don_chem_type, acc_chem_type, seq_sep_type);
431  if( initialized_hbe_types[hbe_type]){
432  tr << "Duplicate parameter specification in HBEval.csv:" << endl;
433  tr << " hbe_type: " << hbe_type << " line :" << line_number << endl;
434  } else {
435  initialized_hbe_types[hbe_type] = true;
436  }
437 
438  if( hbe_type > static_cast<int>(HB_EVAL_TYPE_COUNT) ){
439  stringstream message;
440  message << "hb_eval_type created from" << endl;
441  message << "\tdon_chem_type:'"<< don_chem_type_name <<"'" << endl;
442  message << "\tacc_chem_type:'"<< acc_chem_type_name <<"'" << endl;
443  message << "\tseq_sep_type: '"<< seq_sep_type_name << "'" << endl;
444  message << "gives type" << hbe_type << ", which is out of the range valid range (0," << HB_EVAL_TYPE_COUNT << ")" << endl;
445  utility_exit_with_message(message.str());
446  }
447 
448  // NOTE: The rows in the HBEval table contain all combinations of
449  // donor chemical types, acceptor chemical types and sequence
450  // separation types, however the HBEvalType classification
451  // collapses these types for generic types. For example
452  // (hbdon_NONE, hbacc_NONE, seq_sep_other) and (hbdon_PBA,
453  // hbacc_NONE, seq_sep_other) both map to hbe_NONE. To make sure
454  // this collapsing does not cause problems, assert that the
455  // fade and plynomial functions for each hbe_type are not assigned
456  // two different values.
457 
458  {
459  stringstream buf;
460  buf << tokens[i]; i++;
461  buf >> AHdist_short_fade_name;
462  AHdist_short_fade = HBFadeInterval_from_name(AHdist_short_fade_name);
463  if(AHdist_short_fade_lookup_[hbe_type]){
464  assert(AHdist_short_fade_lookup_[hbe_type] == AHdist_short_fade);
465  } else {
466  AHdist_short_fade_lookup_[hbe_type] = AHdist_short_fade;
467  }
468  }
469  {
470  stringstream buf;
471  buf << tokens[i]; i++;
472  buf >> AHdist_long_fade_name;
473  AHdist_long_fade = HBFadeInterval_from_name(AHdist_long_fade_name);
474  if(AHdist_long_fade_lookup_[hbe_type]){
475  assert(AHdist_long_fade_lookup_[hbe_type] == AHdist_long_fade);
476  } else {
477  AHdist_long_fade_lookup_[hbe_type] = AHdist_long_fade;
478  }
479  }
480  {
481  stringstream buf;
482  buf << tokens[i]; i++;
483  buf >> cosBAH_fade_name;
484  cosBAH_fade = HBFadeInterval_from_name(cosBAH_fade_name);
485  if(cosBAH_fade_lookup_[hbe_type]){
486  assert(cosBAH_fade_lookup_[hbe_type] == cosBAH_fade);
487  } else {
488  cosBAH_fade_lookup_[hbe_type] = cosBAH_fade;
489  }
490  }
491  {
492  stringstream buf;
493  buf << tokens[i]; i++;
494  buf >> cosAHD_fade_name;
495  cosAHD_fade = HBFadeInterval_from_name(cosAHD_fade_name);
496  if(cosAHD_fade_lookup_[hbe_type]){
497  assert(cosAHD_fade_lookup_[hbe_type] == cosAHD_fade);
498  } else {
499  cosAHD_fade_lookup_[hbe_type] = cosAHD_fade;
500  }
501  }
502  ++i; // fade for chi dimension
503  {
504  stringstream buf;
505  buf << tokens[i]; i++;
506  buf >> AHdist_poly_name;
507  AHdist_poly = HBPoly1D_from_name(AHdist_poly_name);
508  /// Error handling: make sure we're given a distance polynomial
509  if ( AHdist_poly->geometric_dimension() != hbgd_AHdist ) {
510  utility_exit_with_message("When reading HBEval.csv parameters for " + don_chem_type_name + " and " + acc_chem_type_name + ", expected to read a distance polynomial (i.e. geometric_dimension == hbgd_AHdist), but instead, found " + AHdist_poly_name + " of geometric dimension " + utility::to_string(AHdist_poly->geometric_dimension()) );
511  }
512  if(AHdist_poly_lookup_[hbe_type]){
513  assert(AHdist_poly_lookup_[hbe_type] == AHdist_poly);
514  } else {
515  AHdist_poly_lookup_[hbe_type] = AHdist_poly;
516  }
517  }
518  {
519  stringstream buf;
520  buf << tokens[i]; i++;
521  buf >> cosBAH_short_poly_name;
522  cosBAH_short_poly = HBPoly1D_from_name(cosBAH_short_poly_name);
523  /// Error handling: make sure we're given a cosBAH polynomial
524  if ( cosBAH_short_poly->geometric_dimension() != hbgd_cosBAH ) {
525  utility_exit_with_message("When reading HBEval.csv parameters for " + don_chem_type_name + " and " + acc_chem_type_name + ", expected to read a short-range cosBAH polynomial (i.e. geometric_dimension == hbgd_cosBAH), but instead, found " + cosBAH_short_poly_name + " of geometric dimension " + utility::to_string(cosBAH_short_poly->geometric_dimension()) );
526  }
527  if(cosBAH_short_poly_lookup_[hbe_type]){
528  assert(cosBAH_short_poly_lookup_[hbe_type] == cosBAH_short_poly);
529  } else {
530  cosBAH_short_poly_lookup_[hbe_type] = cosBAH_short_poly;
531  }
532  }
533  {
534  stringstream buf;
535  buf << tokens[i]; i++;
536  buf >> cosBAH_long_poly_name;
537  cosBAH_long_poly = HBPoly1D_from_name(cosBAH_long_poly_name);
538  /// Error handling: make sure we're given a cosBAH polynomial
539  if ( cosBAH_long_poly->geometric_dimension() != hbgd_cosBAH ) {
540  utility_exit_with_message("When reading HBEval.csv parameters for " + don_chem_type_name + " and " + acc_chem_type_name + ", expected to read a long-range cosBAH polynomial (i.e. geometric_dimension == hbgd_cosBAH), but instead, found " + cosBAH_long_poly_name + " of geometric dimension " + utility::to_string(cosBAH_long_poly->geometric_dimension()) );
541  }
542  if(cosBAH_long_poly_lookup_[hbe_type]){
543  assert(cosBAH_long_poly_lookup_[hbe_type] == cosBAH_long_poly);
544  } else {
545  cosBAH_long_poly_lookup_[hbe_type] = cosBAH_long_poly;
546  }
547  }
548  {
549  stringstream buf;
550  buf << tokens[i]; i++;
551  buf >> cosAHD_short_poly_name;
552  cosAHD_short_poly = HBPoly1D_from_name(cosAHD_short_poly_name);
553  /// Error handling: make sure we're given either a cosAHD polynomial or an AHD polynomial
554  if ( cosAHD_short_poly->geometric_dimension() != hbgd_cosAHD && cosAHD_short_poly->geometric_dimension() != hbgd_AHD ) {
555  utility_exit_with_message("When reading HBEval.csv parameters for " + don_chem_type_name + " and " + acc_chem_type_name + ", expected to read a short-range cosAHD or AHD polynomial (i.e. geometric_dimension == hbgd_cosAHD or hbgd_AHD), but instead, found " + cosAHD_short_poly_name + " of geometric dimension " + utility::to_string(cosAHD_short_poly->geometric_dimension()) );
556  }
557  if(cosAHD_short_poly_lookup_[hbe_type]){
558  assert(cosAHD_short_poly_lookup_[hbe_type]);
559  } else {
560  cosAHD_short_poly_lookup_[hbe_type] = cosAHD_short_poly;
561  }
562  }
563  {
564  stringstream buf;
565  buf << tokens[i]; i++;
566  buf >> cosAHD_long_poly_name;
567  cosAHD_long_poly = HBPoly1D_from_name(cosAHD_long_poly_name);
568  /// Error handling: make sure we're given either a cosAHD polynomial or an AHD polynomial
569  if ( cosAHD_long_poly->geometric_dimension() != hbgd_cosAHD && cosAHD_long_poly->geometric_dimension() != hbgd_AHD ) {
570  utility_exit_with_message("When reading HBEval.csv parameters for " + don_chem_type_name + " and " + acc_chem_type_name + ", expected to read a long-range cosAHD or AHD polynomial (i.e. geometric_dimension == hbgd_cosAHD or hbgd_AHD), but instead, found " + cosAHD_long_poly_name + " of geometric dimension " + utility::to_string(cosAHD_long_poly->geometric_dimension()) );
571  }
572  /// Error handling: make sure the type of the long and short polynomials are consistent -- no mixing cosAHD and AHD polynomials!
573  if ( cosAHD_long_poly->geometric_dimension() != cosAHD_short_poly->geometric_dimension() ) {
574  utility_exit_with_message("When reading HBEval.csv parameters for " + don_chem_type_name + " and " + acc_chem_type_name + ", found that the short- and long-range polynomials for the AHD angle are of different geometric types: one of hbgd_cosAHD and the other of hbgd_AHD. These types cannot be mixed" );
575  }
576  if(cosAHD_long_poly_lookup_[hbe_type]){
577  assert(cosAHD_long_poly_lookup_[hbe_type] == cosAHD_long_poly);
578  } else {
579  cosAHD_long_poly_lookup_[hbe_type] = cosAHD_long_poly;
580  }
581  }
582 //if (tokens[i] != ""){ // chi dimension is not yet defined!
583 // stringstream buf;
584 // buf << tokens[i];
585 // buf >> chi_poly_name;
586 // chi_poly = HBPoly1D_from_name(chi_poly_name);
587 // if(chi_poly_lookup_[hbe_type]){
588 // assert(chi_poly_lookup_[hbe_type] == chi_poly);
589 // } else {
590 // chi_poly_lookup_[hbe_type] = chi_poly;
591 // }
592 //}
593 //i++;
594  {
595  stringstream buf;
596  buf << tokens[i]; i++;
597  buf >> weight_type_name;
598  weight_type = HBondWeightType(HBondTypeManager::weight_type_from_name(weight_type_name));
599  if(weight_type_lookup_[hbe_type] != hbw_NONE){
600  assert(weight_type_lookup_[hbe_type] == weight_type);
601  } else {
602  weight_type_lookup_[hbe_type] = weight_type;
603  }
604  }
605  }
606  for(Size i=1; i <= hbe_MAX; ++i){
607  if(!initialized_hbe_types[i]){
608  tr << "hbe_type: " << i << " is not initialized in HBEval.csv" << endl;
609  }
610  }
611 }
612 
613 void
615  string don_strength_fname =
616  "scoring/score_functions/hbonds/" + params_database_tag_ + "/DonStrength.csv";
617  izstream s;
618 
619  try{
620  open(s, don_strength_fname, false);
621  } catch (...){
622  // Currently these are experimental so don't complain if they
623  // aren't defined.
624  return;
625  }
626 
627 
628  Size line_number(0);
629  Size expected_n_tokens(2);
630  vector1<string> tokens;
631  string line;
632  string don_type_name;
633  Real site_strength;
634  HBDonChemType don_chem_type;
635  while(getline(s, line)){
636  ++line_number;
637  tokens = string_split(line, ',');
638  if(tokens.size() != expected_n_tokens){
639  stringstream message;
640  message
641  << "BondStrength.csv:" << line_number << " "
642  << "should have " << expected_n_tokens << ", "
643  << "however it has " << tokens.size() << endl;
644  message
645  << line << endl;
646  utility_exit_with_message(message.str());
647  }
648 
649  Size i(1);
650  {
651  stringstream buf;
652  buf << tokens[i]; i++;
653  buf >> don_type_name;
654  }
655  {
656  stringstream buf;
657  buf << tokens[i]; i++;
658  buf >> site_strength;
659  }
660 
661  don_chem_type = HBondTypeManager::don_chem_type_from_name(don_type_name);
662  don_strength_lookup_[don_chem_type] = site_strength;
663  }
664 }
665 
666 void
668  string acc_strength_fname =
669  "scoring/score_functions/hbonds/" + params_database_tag_ + "/AccStrength.csv";
670  izstream s;
671  try{
672  open(s, acc_strength_fname, false);
673  } catch (...){
674  // Currently these are experimental so don't complain if they
675  // aren't defined.
676  return;
677  }
678 
679  Size line_number(0);
680  Size expected_n_tokens(2);
681  vector1<string> tokens;
682  string line;
683  string acc_type_name;
684  Real site_strength;
685  HBAccChemType acc_chem_type;
686  while(getline(s, line)){
687  ++line_number;
688  tokens = string_split(line, ',');
689  if(tokens.size() != expected_n_tokens){
690  stringstream message;
691  message
692  << "BondStrength.csv:" << line_number << " "
693  << "should have " << expected_n_tokens << ", "
694  << "however it has " << tokens.size() << endl;
695  message
696  << line << endl;
697  utility_exit_with_message(message.str());
698  }
699 
700  Size i(1);
701  {
702  stringstream buf;
703  buf << tokens[i]; i++;
704  buf >> acc_type_name;
705  }
706  {
707  stringstream buf;
708  buf << tokens[i]; i++;
709  buf >> site_strength;
710  }
711 
712  acc_chem_type = HBondTypeManager::acc_chem_type_from_name(acc_type_name);
713  acc_strength_lookup_[acc_chem_type] = site_strength;
714  }
715 }
716 
719  string const name
720 ) const {
721  map< const string, FadeIntervalCOP >::const_iterator it(HBFadeInterval_lookup_by_name_.find(name));
722  if( it == HBFadeInterval_lookup_by_name_.end() ){
723  stringstream message;
724  message << "Fade Interval '" << name << "' has not been defined.";
725  utility_exit_with_message(message.str());
726  return NULL;
727  } else {
728  return it->second;
729  }
730 }
731 
732 
733 
734 ///@details use get_hbond_evaluation_type(...) or HBEval_lookup(...)
735 ///determine hb_eval_type.
738  Size const hb_eval_type
739 ) const {
740  if( hb_eval_type < 1 || hb_eval_type > HB_EVAL_TYPE_COUNT ){
741  stringstream message;
742  message << "HBond eval type '" << hb_eval_type <<
743  "' is out side of the valid range (1," << HB_EVAL_TYPE_COUNT << ")";
744  utility_exit_with_message(message.str());
745  }
746 
748 
749  if(!p) {
750  stringstream message;
751  message << "No short fade interval for AHdist has been defined for hb eval type '"
752  << hb_eval_type << "'" <<endl;
753  utility_exit_with_message(message.str());
754  }
755  return p;
756 }
757 
758 ///@details use get_hbond_evaluation_type(...) or HBEval_lookup(...)
759 ///determine hb_eval_type.
762  Size const hb_eval_type
763 ) const {
764  if( hb_eval_type < 1 || hb_eval_type > HB_EVAL_TYPE_COUNT ){
765  stringstream message;
766  message << "HBond eval type '" << hb_eval_type
767  << "' is out side of the valid range (1," << HB_EVAL_TYPE_COUNT << ")";
768  utility_exit_with_message(message.str());
769  }
770  FadeIntervalCOP p(AHdist_long_fade_lookup_[hb_eval_type]);
771 
772  if(!p) {
773  stringstream message;
774  message << "No long fade interval for AHdist has been defined for hb eval type '"
775  << hb_eval_type << "'" <<endl;
776  utility_exit_with_message(message.str());
777  }
778  return p;
779 }
780 
781 ///@details use get_hbond_evaluation_type(...) or HBEval_lookup(...)
782 ///determine hb_eval_type.
785  Size const hb_eval_type
786 ) const {
787  if( hb_eval_type < 1 || hb_eval_type > HB_EVAL_TYPE_COUNT ){
788  stringstream message;
789  message << "HBond eval type '" << hb_eval_type
790  << "' is out side of the valid range (1," << HB_EVAL_TYPE_COUNT << ")";
791  utility_exit_with_message(message.str());
792  }
793  FadeIntervalCOP p(cosBAH_fade_lookup_[hb_eval_type]);
794 
795  if(!p) {
796  stringstream message;
797  message << "No fade interval for cosBAH has been defined for hb eval type '"
798  << hb_eval_type << "'" <<endl;
799  utility_exit_with_message(message.str());
800  }
801  return p;
802 }
803 
804 ///@details use get_hbond_evaluation_type(...) or HBEval_lookup(...)
805 ///determine hb_eval_type.
808  Size const hb_eval_type
809 ) const {
810  if( hb_eval_type < 1 || hb_eval_type > HB_EVAL_TYPE_COUNT ){
811  stringstream message;
812  message << "HBond eval type '" << hb_eval_type
813  << "' is out side of the valid range (1," << HB_EVAL_TYPE_COUNT << ")";
814  utility_exit_with_message(message.str());
815  }
816  FadeIntervalCOP p(cosAHD_fade_lookup_[hb_eval_type]);
817 
818  if(!p) {
819  stringstream message;
820  message << "No fade interval for cosAHD has been defined for hb eval type '"
821  << hb_eval_type << "'" <<endl;
822  utility_exit_with_message(message.str());
823  }
824  return p;
825 }
826 
829  string const name
830 ) const {
831  map< const string, Polynomial_1dCOP >::const_iterator it(HBPoly1D_lookup_by_name_.find(name));
832  if( it == HBPoly1D_lookup_by_name_.end() ){
833  stringstream message;
834  message << "1d Polynomial '" << name << "' has not been defined.";
835  utility_exit_with_message(message.str());
836  return NULL;
837  } else {
838  return it->second;
839  }
840 }
841 
842 ///@details use get_hbond_evaluation_type(...) or HBEval_lookup(...)
843 ///determine hb_eval_type.
846  Size const hb_eval_type
847 ) const {
848  if( hb_eval_type < 1 || hb_eval_type > HB_EVAL_TYPE_COUNT ){
849  stringstream message;
850  message << "HBond eval type '" << hb_eval_type
851  << "' is out side of the valid range (1," << HB_EVAL_TYPE_COUNT << ")";
852  utility_exit_with_message(message.str());
853  }
854  Polynomial_1dCOP p(AHdist_poly_lookup_[hb_eval_type]);
855 
856  if(!p) {
857  stringstream message;
858  message << "No AHdist polynomial has been defined for hb eval type '"
859  << hb_eval_type << "'" <<endl;
860  utility_exit_with_message(message.str());
861  }
862  return p;
863 }
864 
865 ///@details use get_hbond_evaluation_type(...) or HBEval_lookup(...)
866 ///determine hb_eval_type.
869  Size const hb_eval_type
870 ) const {
871  if( hb_eval_type < 1 || hb_eval_type > HB_EVAL_TYPE_COUNT ){
872  stringstream message;
873  message << "HBond eval type '" << hb_eval_type
874  << "' is out side of the valid range (1," << HB_EVAL_TYPE_COUNT << ")";
875  utility_exit_with_message(message.str());
876  }
878 
879  if(!p) {
880  stringstream message;
881  message << "No cosBAH_short polynomial has been defined for hb eval type '"
882  << hb_eval_type << "'" << endl;
883  utility_exit_with_message(message.str());
884  }
885  return p;
886 
887 }
888 
889 ///@details use get_hbond_evaluation_type(...) or HBEval_lookup(...)
890 ///determine hb_eval_type.
893  Size const hb_eval_type
894 ) const {
895  if( hb_eval_type < 1 || hb_eval_type > HB_EVAL_TYPE_COUNT ){
896  stringstream message;
897  message << "HBond eval type '" << hb_eval_type
898  << "' is out side of the valid range (1," << HB_EVAL_TYPE_COUNT << ")";
899  utility_exit_with_message(message.str());
900  }
902 
903  if(!p) {
904  stringstream message;
905  message << "No cosBAH_long polynomial has been defined for hb eval type '"
906  << hb_eval_type << "'" << endl;
907  utility_exit_with_message(message.str());
908  }
909  return p;
910 }
911 
912 ///@details use get_hbond_evaluation_type(...) or HBEval_lookup(...)
913 ///determine hb_eval_type.
916  Size const hb_eval_type
917 ) const {
918  if( hb_eval_type < 1 || hb_eval_type > HB_EVAL_TYPE_COUNT ){
919  stringstream message;
920  message << "HBond eval type '" << hb_eval_type
921  << "' is out side of the valid range (1," << HB_EVAL_TYPE_COUNT << ")";
922  utility_exit_with_message(message.str());
923  }
925 
926  if(!p) {
927  stringstream message;
928  message << "No cosAHD_short polynomial has been defined for hb eval type '"
929  << hb_eval_type << "'" << endl;
930  utility_exit_with_message(message.str());
931  }
932  return p;
933 }
934 
935 ///@details use get_hbond_evaluation_type(...) or HBEval_lookup(...)
936 ///determine hb_eval_type.
939  Size const hb_eval_type
940 ) const {
941  if( hb_eval_type < 1 || hb_eval_type > HB_EVAL_TYPE_COUNT ){
942  stringstream message;
943  message << "HBond eval type '" << hb_eval_type
944  << "' is out side of the valid range (1," << HB_EVAL_TYPE_COUNT << ")";
945  utility_exit_with_message(message.str());
946  }
948 
949  if(!p) {
950  stringstream message;
951  message << "No cosAHD_long polynomial has been defined for hb eval type '"
952  << hb_eval_type << "'" << endl;
953  utility_exit_with_message(message.str());
954  }
955  return p;
956 }
957 ///@details use get_hbond_evaluation_type(...) or HBEval_lookup(...)
958 ///determine hb_eval_type.
961  Size const hb_eval_type
962 ) const {
963  if( hb_eval_type < 1 || hb_eval_type > HB_EVAL_TYPE_COUNT ){
964  stringstream message;
965  message << "HBond eval type '" << hb_eval_type
966  << "' is out side of the valid range (1," << HB_EVAL_TYPE_COUNT << ")";
967  utility_exit_with_message(message.str());
968  }
969  Polynomial_1dCOP p(chi_poly_lookup_[hb_eval_type]);
970 
971  if(!p) {
972  stringstream message;
973  message << "No chi polynomial has been defined for hb eval type '"
974  << hb_eval_type << "'" << endl;
975  utility_exit_with_message(message.str());
976  }
977  return p;
978 }
979 
980 
981 Real
983  HBDonChemType const don_chem_type
984 ) const {
985  assert(don_chem_type >= 1 && don_chem_type <= hbdon_MAX );
986 
987  return don_strength_lookup_[don_chem_type];
988 }
989 
990 Real
992  HBAccChemType const acc_chem_type
993 ) const {
994  assert(acc_chem_type >= 1 && acc_chem_type <= hbacc_MAX );
995 
996  return acc_strength_lookup_[acc_chem_type];
997 }
998 
999 ///@details use get_hbond_evaluation_type(...) or HBEval_lookup(...)
1000 ///determine hb_eval_type.
1003  Size const hb_eval_type
1004 ) const {
1005  if( hb_eval_type < 1 || hb_eval_type > HB_EVAL_TYPE_COUNT ){
1006  stringstream message;
1007  message << "HBond eval type '" << hb_eval_type
1008  << "' is out side of the valid range (1," << HB_EVAL_TYPE_COUNT << ")";
1009  utility_exit_with_message(message.str());
1010  }
1011  HBondWeightType p(weight_type_lookup_[hb_eval_type]);
1012 
1013  if(p == hbw_NONE) {
1014  stringstream message;
1015  message << "No weight type has been defined for hb eval type '"
1016  << hb_eval_type << "'" << endl;
1017  utility_exit_with_message(message.str());
1018  }
1019  return p;
1020 }
1021 
1022 void
1024  sessionOP db_session
1025 ) const {
1029 }
1030 
1031 void
1033  sessionOP db_session
1034 ) const {
1035  using namespace basic::database::schema_generator;
1036 
1037  Column database_tag("database_tag", new DbText());
1038  Column name("name", new DbText());
1039  Column junction_type("junction_type", new DbText());
1040  Column min0("min0", new DbReal());
1041  Column fmin("fmin", new DbReal());
1042  Column fmax("fmax", new DbReal());
1043  Column max0("max0", new DbReal());
1044 
1045 
1046  Columns primary_key_columns;
1047  primary_key_columns.push_back(database_tag);
1048  primary_key_columns.push_back(name);
1049  PrimaryKey primary_key(primary_key_columns);
1050 
1051  Schema table("hbond_fade_interval", primary_key);
1052  table.add_column(junction_type);
1053  table.add_column(min0);
1054  table.add_column(fmin);
1055  table.add_column(fmax);
1056  table.add_column(max0);
1057 
1058  table.write(db_session);
1059 }
1060 
1061 void
1063  sessionOP db_session
1064 ) const {
1065  using namespace basic::database::schema_generator;
1066 
1067  Column database_tag("database_tag", new DbText());
1068  Column name("name", new DbText());
1069  Column dimension("dimension", new DbText());
1070  Column xmin("xmin", new DbReal());
1071  Column xmax("xmax", new DbReal());
1072  Column min_val("min_val", new DbReal());
1073  Column max_val("max_val", new DbReal());
1074  Column root1("root1", new DbReal());
1075  Column root2("root2", new DbReal());
1076  Column degree("degree", new DbInteger());
1077  Column c_a("c_a", new DbReal());
1078  Column c_b("c_b", new DbReal());
1079  Column c_c("c_c", new DbReal());
1080  Column c_d("c_d", new DbReal());
1081  Column c_e("c_e", new DbReal());
1082  Column c_f("c_f", new DbReal());
1083  Column c_g("c_g", new DbReal());
1084  Column c_h("c_h", new DbReal());
1085  Column c_i("c_i", new DbReal());
1086  Column c_j("c_j", new DbReal());
1087  Column c_k("c_k", new DbReal());
1088 
1089 
1090  Columns primary_key_columns;
1091  primary_key_columns.push_back(database_tag);
1092  primary_key_columns.push_back(name);
1093  PrimaryKey primary_key(primary_key_columns);
1094 
1095  Schema table("hbond_polynomial_1d", primary_key);
1096  table.add_column(dimension);
1097  table.add_column(xmin);
1098  table.add_column(xmax);
1099  table.add_column(min_val);
1100  table.add_column(max_val);
1101  table.add_column(root1);
1102  table.add_column(root2);
1103  table.add_column(degree);
1104  table.add_column(c_a);
1105  table.add_column(c_b);
1106  table.add_column(c_c);
1107  table.add_column(c_d);
1108  table.add_column(c_e);
1109  table.add_column(c_f);
1110  table.add_column(c_g);
1111  table.add_column(c_h);
1112  table.add_column(c_i);
1113  table.add_column(c_j);
1114  table.add_column(c_k);
1115  table.write(db_session);
1116 
1117 }
1118 
1119 void
1121  sessionOP db_session
1122 ) const {
1123  using namespace basic::database::schema_generator;
1124 
1125  Column database_tag("database_tag", new DbText());
1126  Column don_chem_type("don_chem_type", new DbText());
1127  Column acc_chem_type("acc_chem_type", new DbText());
1128  Column separation("separation", new DbText());
1129  Column AHdist_short_fade("AHdist_short_fade", new DbText());
1130  Column AHdist_long_fade("AHdist_long_fade", new DbText());
1131  Column cosBAH_fade("cosBAH_fade", new DbText());
1132  Column cosAHD_fade("cosAHD_fade", new DbText());
1133  Column AHdist("AHdist", new DbText());
1134  Column cosBAH_short("cosBAH_short", new DbText());
1135  Column cosBAH_long("cosBAH_long", new DbText());
1136  Column cosAHD_short("cosAHD_short", new DbText());
1137  Column cosAHD_long("cosAHD_long", new DbText());
1138  Column weight_type("weight_type", new DbText());
1139 
1140  Columns primary_key_columns;
1141  primary_key_columns.push_back(database_tag);
1142  primary_key_columns.push_back(don_chem_type);
1143  primary_key_columns.push_back(acc_chem_type);
1144  primary_key_columns.push_back(separation);
1145  PrimaryKey primary_key(primary_key_columns);
1146 
1147  Columns foreign_key_columns_AHdist_short_fade;
1148  foreign_key_columns_AHdist_short_fade.push_back(database_tag);
1149  foreign_key_columns_AHdist_short_fade.push_back(AHdist_short_fade);
1150  vector1< std::string > reference_columns_AHdist_short_fade;
1151  reference_columns_AHdist_short_fade.push_back("database_tag");
1152  reference_columns_AHdist_short_fade.push_back("name");
1153  ForeignKey foreign_key_AHdist_short_fade(
1154  foreign_key_columns_AHdist_short_fade,
1155  "hbond_fade_interval",
1156  reference_columns_AHdist_short_fade,
1157  true);
1158 
1159  Columns foreign_key_columns_AHdist_long_fade;
1160  foreign_key_columns_AHdist_long_fade.push_back(database_tag);
1161  foreign_key_columns_AHdist_long_fade.push_back(AHdist_long_fade);
1162  vector1< std::string > reference_columns_AHdist_long_fade;
1163  reference_columns_AHdist_long_fade.push_back("database_tag");
1164  reference_columns_AHdist_long_fade.push_back("name");
1165  ForeignKey foreign_key_AHdist_long_fade(
1166  foreign_key_columns_AHdist_long_fade,
1167  "hbond_fade_interval",
1168  reference_columns_AHdist_long_fade,
1169  true);
1170 
1171  Columns foreign_key_columns_cosBAH_fade;
1172  foreign_key_columns_cosBAH_fade.push_back(database_tag);
1173  foreign_key_columns_cosBAH_fade.push_back(cosBAH_fade);
1174  vector1< std::string > reference_columns_cosBAH_fade;
1175  reference_columns_cosBAH_fade.push_back("database_tag");
1176  reference_columns_cosBAH_fade.push_back("name");
1177  ForeignKey foreign_key_cosBAH_fade(
1178  foreign_key_columns_cosBAH_fade,
1179  "hbond_fade_interval",
1180  reference_columns_cosBAH_fade,
1181  true);
1182 
1183  Columns foreign_key_columns_cosAHD_fade;
1184  foreign_key_columns_cosAHD_fade.push_back(database_tag);
1185  foreign_key_columns_cosAHD_fade.push_back(cosAHD_fade);
1186  vector1< std::string > reference_columns_cosAHD_fade;
1187  reference_columns_cosAHD_fade.push_back("database_tag");
1188  reference_columns_cosAHD_fade.push_back("name");
1189  ForeignKey foreign_key_cosAHD_fade(
1190  foreign_key_columns_cosAHD_fade,
1191  "hbond_fade_interval",
1192  reference_columns_cosAHD_fade,
1193  true);
1194 
1195  Columns foreign_key_columns_AHdist;
1196  foreign_key_columns_AHdist.push_back(database_tag);
1197  foreign_key_columns_AHdist.push_back(AHdist);
1198  vector1< std::string > reference_columns_AHdist;
1199  reference_columns_AHdist.push_back("database_tag");
1200  reference_columns_AHdist.push_back("name");
1201  ForeignKey foreign_key_AHdist(
1202  foreign_key_columns_AHdist,
1203  "hbond_polynomial_1d",
1204  reference_columns_AHdist,
1205  true);
1206 
1207  Columns foreign_key_columns_cosBAH_short;
1208  foreign_key_columns_cosBAH_short.push_back(database_tag);
1209  foreign_key_columns_cosBAH_short.push_back(cosBAH_short);
1210  vector1< std::string > reference_columns_cosBAH_short;
1211  reference_columns_cosBAH_short.push_back("database_tag");
1212  reference_columns_cosBAH_short.push_back("name");
1213  ForeignKey foreign_key_cosBAH_short(
1214  foreign_key_columns_cosBAH_short,
1215  "hbond_polynomial_1d",
1216  reference_columns_cosBAH_short,
1217  true);
1218 
1219  Columns foreign_key_columns_cosBAH_long;
1220  foreign_key_columns_cosBAH_long.push_back(database_tag);
1221  foreign_key_columns_cosBAH_long.push_back(cosBAH_long);
1222  vector1< std::string > reference_columns_cosBAH_long;
1223  reference_columns_cosBAH_long.push_back("database_tag");
1224  reference_columns_cosBAH_long.push_back("name");
1225  ForeignKey foreign_key_cosBAH_long(
1226  foreign_key_columns_cosBAH_long,
1227  "hbond_polynomial_1d",
1228  reference_columns_cosBAH_long,
1229  true);
1230 
1231  Columns foreign_key_columns_cosAHD_short;
1232  foreign_key_columns_cosAHD_short.push_back(database_tag);
1233  foreign_key_columns_cosAHD_short.push_back(cosAHD_short);
1234  vector1< std::string > reference_columns_cosAHD_short;
1235  reference_columns_cosAHD_short.push_back("database_tag");
1236  reference_columns_cosAHD_short.push_back("name");
1237  ForeignKey foreign_key_cosAHD_short(
1238  foreign_key_columns_cosAHD_short,
1239  "hbond_polynomial_1d",
1240  reference_columns_cosAHD_short,
1241  true);
1242 
1243  Columns foreign_key_columns_cosAHD_long;
1244  foreign_key_columns_cosAHD_long.push_back(database_tag);
1245  foreign_key_columns_cosAHD_long.push_back(cosAHD_long);
1246  vector1< std::string > reference_columns_cosAHD_long;
1247  reference_columns_cosAHD_long.push_back("database_tag");
1248  reference_columns_cosAHD_long.push_back("name");
1249  ForeignKey foreign_key_cosAHD_long(
1250  foreign_key_columns_cosAHD_long,
1251  "hbond_polynomial_1d",
1252  reference_columns_cosAHD_long,
1253  true);
1254 
1255  Schema table("hbond_evaluation_types", primary_key);
1256  table.add_foreign_key(foreign_key_AHdist_short_fade);
1257  table.add_foreign_key(foreign_key_AHdist_long_fade);
1258  table.add_foreign_key(foreign_key_cosBAH_fade);
1259  table.add_foreign_key(foreign_key_cosAHD_fade);
1260  table.add_foreign_key(foreign_key_AHdist);
1261  table.add_foreign_key(foreign_key_cosBAH_short);
1262  table.add_foreign_key(foreign_key_cosBAH_long);
1263  table.add_foreign_key(foreign_key_cosAHD_short);
1264  table.add_foreign_key(foreign_key_cosAHD_long);
1265  table.add_column(AHdist_short_fade);
1266  table.add_column(AHdist_long_fade);
1267  table.add_column(cosBAH_fade);
1268  table.add_column(cosAHD_fade);
1269  table.add_column(AHdist);
1270  table.add_column(cosBAH_short);
1271  table.add_column(cosBAH_long);
1272  table.add_column(cosAHD_short);
1273  table.add_column(cosAHD_long);
1274  table.add_column(weight_type);
1275 
1276  table.write(db_session);
1277 }
1278 
1279 Size
1281  sessionOP db_session
1282 ) const {
1283 
1284  string const & database_tag(params_database_tag_ );
1285 
1286  std::string select_string = "SELECT * FROM hbond_evaluation_types WHERE database_tag = ?;";
1287  statement select_statement(basic::database::safely_prepare_statement(select_string,db_session));
1288  select_statement.bind(1,database_tag);
1289  result res(basic::database::safely_read_from_database(select_statement));
1290  if(res.next()) return 0;
1291 
1292 
1293  pair<string, FadeIntervalCOP> fade_name_interval;
1294  std::string hbond_interval_string = "INSERT INTO hbond_fade_interval (database_tag, name, junction_type, min0, fmin, fmax, max0) VALUES (?,?,?,?,?,?,?);";
1295  statement hbond_interval_statement(basic::database::safely_prepare_statement(hbond_interval_string,db_session));
1296  foreach(fade_name_interval, HBFadeInterval_lookup_by_name_){
1297  hbond_interval_statement.bind(1,database_tag);
1298  hbond_interval_statement.bind(2,fade_name_interval.first);
1299  hbond_interval_statement.bind(3,(fade_name_interval.second->get_smooth() ? "smooth" : "piecewise_linear"));
1300  hbond_interval_statement.bind(4,fade_name_interval.second->get_min0());
1301  hbond_interval_statement.bind(5,fade_name_interval.second->get_fmin());
1302  hbond_interval_statement.bind(6,fade_name_interval.second->get_fmax());
1303  hbond_interval_statement.bind(7,fade_name_interval.second->get_max0());
1304  basic::database::safely_write_to_database(hbond_interval_statement);
1305 
1306  }
1307 
1308  pair<string, Polynomial_1dCOP> poly_name_fn;
1309  std::string hbond_polynomial_string = "INSERT INTO hbond_polynomial_1d (database_tag, name, dimension, xmin, xmax, min_val, max_val, root1, root2, degree, c_a, c_b, c_c, c_d, c_e, c_f, c_g, c_h, c_i, c_j, c_k) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
1310  statement hbond_polynomial_statement(basic::database::safely_prepare_statement(hbond_polynomial_string,db_session));
1311  foreach(poly_name_fn, HBPoly1D_lookup_by_name_){
1312  hbond_polynomial_statement.bind(1,database_tag);
1313  hbond_polynomial_statement.bind(2,poly_name_fn.first);
1314  hbond_polynomial_statement.bind(3,HBondTypeManager::name_from_geo_dim_type(poly_name_fn.second->geometric_dimension()));
1315  hbond_polynomial_statement.bind(4,poly_name_fn.second->xmin());
1316  hbond_polynomial_statement.bind(5,poly_name_fn.second->xmax());
1317  hbond_polynomial_statement.bind(6,poly_name_fn.second->min_val());
1318  hbond_polynomial_statement.bind(7,poly_name_fn.second->max_val());
1319  hbond_polynomial_statement.bind(8,poly_name_fn.second->root1());
1320  hbond_polynomial_statement.bind(9,poly_name_fn.second->root2());
1321  hbond_polynomial_statement.bind(10,poly_name_fn.second->degree());
1322  Size index = 10;
1323  for(Size i = 1; i <= poly_name_fn.second->degree(); ++i){
1324  index++;
1325  hbond_polynomial_statement.bind(index,poly_name_fn.second->coefficients()[i]);
1326  }
1327  for(Size i = 1; i <= 11-poly_name_fn.second->degree(); ++i){
1328  index++;
1329  hbond_polynomial_statement.bind_null(index);
1330  }
1331  basic::database::safely_write_to_database(hbond_polynomial_statement);
1332  }
1333 
1334  std::string hbond_evaluation_string = "INSERT INTO hbond_evaluation_types (database_tag, don_chem_type, acc_chem_type, separation, AHdist_short_fade, AHdist_long_fade, cosBAH_fade, cosAHD_fade, AHdist, cosBAH_short, cosBAH_long, cosAHD_short, cosAHD_long, weight_type) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
1335  statement hbond_evaluation_statement(basic::database::safely_prepare_statement(hbond_evaluation_string,db_session));
1336  for (Size hbdon=1; hbdon <= hbdon_MAX; ++hbdon){
1337  string const & don_chem_type(HBondTypeManager::name_from_don_chem_type(HBDonChemType(hbdon)));
1338  for (Size hbacc=1; hbacc <= hbacc_MAX; ++hbacc){
1339  string const & acc_chem_type(HBondTypeManager::name_from_acc_chem_type(HBAccChemType(hbacc)));
1340  for (Size hbseq_sep=1; hbseq_sep <= seq_sep_MAX; ++hbseq_sep){
1341  string const & separation(HBondTypeManager::name_from_seq_sep_type(HBSeqSep(hbseq_sep)));
1342 
1343  HBEvalType const hbe(HBEval_lookup(hbdon, hbacc, hbseq_sep));
1344  if(!hbe) continue;
1345 
1346  hbond_evaluation_statement.bind(1,database_tag);
1347  hbond_evaluation_statement.bind(2,don_chem_type);
1348  hbond_evaluation_statement.bind(3,acc_chem_type);
1349  hbond_evaluation_statement.bind(4,separation);
1350  hbond_evaluation_statement.bind(5,AHdist_short_fade_lookup(hbe)->get_name());
1351  hbond_evaluation_statement.bind(6,AHdist_long_fade_lookup(hbe)->get_name());
1352  hbond_evaluation_statement.bind(7,cosBAH_fade_lookup(hbe)->get_name());
1353  hbond_evaluation_statement.bind(8,cosAHD_fade_lookup(hbe)->get_name());
1354  hbond_evaluation_statement.bind(9,AHdist_poly_lookup(hbe)->name());
1355  hbond_evaluation_statement.bind(10,cosBAH_short_poly_lookup(hbe)->name());
1356  hbond_evaluation_statement.bind(11,cosBAH_long_poly_lookup(hbe)->name());
1357  hbond_evaluation_statement.bind(12,cosAHD_short_poly_lookup(hbe)->name());
1358  hbond_evaluation_statement.bind(13,cosAHD_long_poly_lookup(hbe)->name());
1359  hbond_evaluation_statement.bind(14,HBondTypeManager::name_from_weight_type(weight_type_lookup(hbe)));
1360  basic::database::safely_write_to_database(hbond_evaluation_statement);
1361 
1362  }
1363  }
1364  }
1365  return 0;
1366 }
1367 
1368 } // geometric_solvation
1369 } // namespace scoring
1370 } // namespace core
1371