Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NVlookup.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 core/scoring/nv/NVlookup.cc
11 /// @brief Neighbor Vector algorithm lookup table processing class
12 /// @detailed The neighbor vector algorithm relies on a table of knowledge based potentials based on statistical analysis of the PDB
13 /// This class loads the lookup table and provides an interface for accessing it. In the future this should and will probably be implemented as a spline rather than a table
14 /// @author Sam DeLuca (samuel.l.deluca@vanderbilt.edu)
15 
17 
18 #include <numeric/interpolation/spline/SplineGenerator.hh>
19 
20 #include <utility/vector1.hh>
21 #include <utility/io/izstream.hh>
22 #include <utility/json_spirit/json_spirit_reader.h>
23 
24 #include <basic/Tracer.hh>
25 
26 #include <algorithm>
27 #include <fstream>
28 #include <sstream>
29 #include <vector>
30 
31 using namespace std;
32 
33 static basic::Tracer TR("core.scoring.NV");
34 
35 namespace core {
36 namespace scoring {
37 namespace nv {
38 
39 /// @details Auto-generated virtual destructor
40 NVlookup::~NVlookup() {}
41 
42 using namespace numeric::interpolation::spline;
43 
44 void NVlookup::set_up_spline_from_data(core::chemical::AA const & aa_type, utility::vector1<core::Real> const & bin_centers, utility::vector1<core::Real> const & data)
45 {
46 
47  assert(bin_centers.size() == data.size()); //You need to have the same number of bin centers and spline points
48 
49  Real lower_bound_x = 0;
50  Real upper_bound_x = 1.1;
51 
52  core::Real lower_bound_y = *std::min_element(data.begin(),data.end());
53  core::Real upper_bound_y = *std::max_element(data.begin(),data.end());
54 
55  lower_bound_y -= 0.1; //Bounds are exclusive, so we pad out the min and max a bit
56  upper_bound_y += 0.1;
57 
58  SplineGenerator spline(lower_bound_x,lower_bound_y,0,upper_bound_x,upper_bound_y,0);
59 
60  for(Size potential_index = 1; potential_index <= data.size(); ++potential_index)
61  {
62  Real x_value = bin_centers[potential_index];
63  Real y_value = data[potential_index];
64  spline.add_known_value(x_value,y_value);
65  }
66 
67  //InterpolatorOP interpolator = spline.get_interpolator();
68 
69  lookup_table_[aa_type] = spline.get_interpolator();
70 
71 
72 }
73 
74 NVlookup::NVlookup(std::string filename) : lookup_table_(core::chemical::num_canonical_aas,0)
75 {
76  //Look at rosetta_database/scoring/score_function/NV/neighbor_vector_score.histogram to see what formatting should look like
77  utility::io::izstream infile;
78  infile.open(filename.c_str(),ifstream::in);
79  utility::json_spirit::mValue histogram_object;
80  utility::json_spirit::read(infile,histogram_object);
81 
82  //The bin centers are in an array with the key "bin_centers"
83  utility::json_spirit::mArray const & bin_array_data = histogram_object.get_obj()["bin_centers"].get_array();
84  utility::vector1<core::Real> bin_centers;
85 
86  //the rest of the code expects a vector of reals, so we convert the array to one
87  for(core::Size i =0; i < bin_array_data.size();++i)
88  {
89  bin_centers.push_back(bin_array_data[i].get_real());
90  }
91 
92  //the score information is a dictionary, key is amino acid type, data is an array of reals
93  utility::json_spirit::mObject const & spline_objects = histogram_object.get_obj()["scores"].get_obj();
94 
95  utility::json_spirit::mObject::const_iterator spline_object_iterator = spline_objects.begin();
96  for(; spline_object_iterator != spline_objects.end();++spline_object_iterator)
97  {
98  std::string aa_name_string = spline_object_iterator->first;
99  assert(aa_name_string.size() == 1); //The key should be a single letter amino acid
100  char aa_name = aa_name_string[0];
101 
103 
104  utility::json_spirit::mArray const & spline_array_data = spline_object_iterator->second.get_array();
105  utility::vector1<core::Real> spline_values;
106  for(core::Size i = 0; i < spline_array_data.size(); ++i)
107  {
108  spline_values.push_back(spline_array_data[i].get_real());
109  }
110  set_up_spline_from_data(aa_type,bin_centers,spline_values);
111 
112  }
113 
114  infile.close();
115 
116 }
117 //Given a neighbor vector score and a single letter AA abbrev, get the potential from the lookup table
119 {
120 
121  if(aa_type <= core::chemical::num_canonical_aas)
122  {
123  InterpolatorOP row(lookup_table_[aa_type]);
124  Real potential_energy;
125  Real delta_potential_energy;
126 
127  row->interpolate(score,potential_energy,delta_potential_energy);
128 
129  return potential_energy;
130  }
131 
132  return 0;
133 
134 
135 }
136 
137 } //NVscore
138 } //scoring
139 } //core