Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DDPlookup.cc
Go to the documentation of this file.
1 // (c) Copyright Rosetta Commons Member Institutions.
2 // (c) This file is part of the Rosetta software suite and is made available under license.
3 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
4 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
5 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
6 
7 /// @file src/core/scoring/Interface/DDPlookup.cc
8 /// @author Hermann Zellner (hermann1.zellner@biologie.uni-regensburg.de)
10 
11 #include <basic/database/open.hh>
12 #include <basic/Tracer.hh>
13 #include <utility/io/izstream.hh>
14 
15 #include <utility/vector1.hh>
16 
17 
18 namespace core {
19 namespace scoring {
20 namespace interface {
21 
22 static basic::Tracer TR("core.scoring.Interface.DDPlookup");
23 
25 {
26  core::Size const n_bins ( 50 );
27  core::Real const n_max (20.);
28  core::Size const max_aa( 20 );
29 
30  std::string tag, line;
31  core::chemical::AA aa1, aa2;
32 
37 
38  for (core::Size i=1; i<=n_bins; i++)
39  {
40  myvec.push_back(0.);
41  }
42  for (core::Size i=1; i<=max_aa; i++)
43  {
44  myvec_2.push_back(0.);
45  }
46  for (core::Size i=1; i<=max_aa; i++)
47  {
48  left_.push_back(myvec_2);
49  right_.push_back(myvec_2);
50  mymyvec.push_back(myvec);
51  }
52  for (core::Size i=1; i<=max_aa; i++)
53  {
54  known_values.push_back(mymyvec);
55  }
56  utility::vector1< core::Real > distance_bin;
57 
58 
59  core::Real stepsize = n_max / (core::Real) n_bins;
60  core::Real e = 0 + stepsize/2;
61 
62  for (core::Size i=1; i<=n_bins; i++)
63  {
64  distance_bin.push_back(e);
65  e += stepsize;
66  }
67 
68  utility::io::izstream stream;
69  basic::database::open( stream, filename );
70  while ( getline( stream, line ) ) {
71  std::istringstream l(line);
72  l >> tag >> aa1 >> aa2;
73  for ( Size i=1; i<=n_bins; ++i ) {
74  l >> known_values[aa1][aa2][i];
75  }
76  if ( l.fail() || tag != "DDIPP:" )
77  {
78  TR << "bad format for interface_dd_score.txt" << std::endl;
79  TR << "fail: " << l.fail() << " tag: " << tag << std::endl;
80  exit(1);
81  }
82 
83  // #######################################
84  // Identify borders of the valey. Left border ist the smallest distance with score < 0. of a valey with an integral larger than .5
85  // The right border is either the smallest distance with score >= 0 or a maximum of the score (if you have 2 separated minima)
86  bool valey = false;
87  core::Size leftidx=1;
88  while( !valey && leftidx < n_bins )
89  {
90  core::Real auc=0;
91  for (core::Size i=leftidx; i<=n_bins; i++)
92  {
93  if ( known_values[aa1][aa2][i] < -1e-10 )
94  {
95  left_[aa1][aa2] = distance_bin[i-1];
96  leftidx = i;
97  break;
98  }
99  leftidx = n_bins;
100  }
101  bool up=false;
102 
103  for (core::Size i=leftidx; i<=n_bins; i++)
104  {
105  auc += known_values[aa1][aa2][i] * (n_max/n_bins);
106  if ( !up && i>1 && known_values[aa1][aa2][i-1] < known_values[aa1][aa2][i])
107  {
108  up=true;
109  }
110  if ( known_values[aa1][aa2][i] > -1e-10 )
111  {
112  right_[aa1][aa2] = distance_bin[i];
113  break;
114  }
115  if ( up && known_values[aa1][aa2][i-1] > known_values[aa1][aa2][i] )
116  {
117  right_[aa1][aa2] = distance_bin[i-3];
118  break;
119  }
120  right_[aa1][aa2] = distance_bin[1];
121  }
122  if ( auc < .5 )
123  {
124  valey=true;
125  }
126  else
127  {
128  left_[aa1][aa2] = distance_bin[n_bins];
129  right_[aa1][aa2] = distance_bin[1];
130  }
131  leftidx++; // to avoid an endless loop
132  }
133  }
134  stream.close();
135 
136  //generate spline for every pair of amino acid
137  lookup_table_ = new numeric::interpolation::spline::SplineGenerator**[max_aa+1];
138  for (core::Size i=1; i<=max_aa; i++)
139  {
140  lookup_table_[i] = new numeric::interpolation::spline::SplineGenerator*[max_aa+1];
141  for (core::Size j=1; j<=max_aa; j++)
142  {
143  utility::vector1<core::Real>::iterator lower_bound_y_iterator(std::min_element(known_values[i][j].begin(),known_values[i][j].end()));
144 
145  core::Real lower_bound_x = 0 - stepsize/2;
146  core::Real upper_bound_x = distance_bin[n_bins] + stepsize/2;
147  core::Real lower_bound_y = *lower_bound_y_iterator;
148  core::Real upper_bound_y = 0.;
149 
150  lower_bound_y -= 0.1; //Bounds are exclusive, so we pad out the min and max a bit
151  upper_bound_y += 0.1;
152 
153  lookup_table_[i][j] = new numeric::interpolation::spline::SplineGenerator(lower_bound_x, lower_bound_y, 0, upper_bound_x, upper_bound_y, 0);
154  for (core::Size energy_index = 1; energy_index <= n_bins; energy_index++)
155  {
156  if (distance_bin[energy_index] > left_[i][j] && distance_bin[energy_index] < right_[i][j])
157  {
158  lookup_table_[i][j]->add_known_value( distance_bin[energy_index], known_values[i][j][energy_index]);
159  }
160  else
161  {
162  lookup_table_[i][j]->add_known_value( distance_bin[energy_index], -1e-5);
163  }
164  }
165  }
166  }
167 }
168 
169 
170 
173 {
174  if ( aa1 < 1 || aa1 > 20 || aa2 < 1 || aa2 > 20 )
175  {
176  TR << "bad amino acid for DDPlookup" << std::endl;
177  exit(1);
178  }
179 
180  core::Real delta_potential_energy = 0;
181  core::Real potential_energy = 0;
182  core::Real result;
183 
184 
185  numeric::interpolation::spline::InterpolatorOP interpolator =
186  lookup_table_[aa1][aa2]->get_interpolator();
187  interpolator->interpolate(distance, potential_energy, delta_potential_energy);
188  if ( potential_energy > 0. || distance < 2. || distance < left_[aa1][aa2] || distance > right_[aa1][aa2] )
189  {
190  result = -1e-5;
191  }
192  else
193  {
194  result = potential_energy;
195  }
196 
197 
198  return result;
199 }
200 
201 } //NVscore
202 } //scoring
203 } //core