Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
interpolation_util.hh
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 // :noTabs=false:tabSize=4:indentSize=4:
4 //
5 // (c) Copyright Rosetta Commons Member Institutions.
6 // (c) This file is part of the Rosetta software suite and is made available under license.
7 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
8 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
9 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
10 
11 /// @file core/interpolation/interpolation_util.hh
12 /// @brief Useful function for interpolation...
13 /// @author Rhiju Das
14 ///
15 
16 #ifndef INCLUDED_core_scoring_interpolation_util_hh
17 #define INCLUDED_core_scoring_interpolation_util_hh
18 
19 #include <core/types.hh>
20 #include <ObjexxFCL/FArray1D.hh>
21 
22 namespace core {
23 namespace scoring {
24 
25 /////////////////////////////////////////////////////////////////////////////////////////
26 // A generally useful function for interpolation.
27 // Its a little puzzling that this isn't in any of the utility::interpolation
28 // files, but I sure can't find it.
29 inline
30 void
32  ObjexxFCL::FArray1D <Real> const & potential,
33  Real const & bin_width,
34  Real const & r,
35  Real & value,
36  Real & deriv )
37 {
38 
39  Size const & NUM_BINS( potential.size() );
40 
41  Size r_bin_lo = Size( r/bin_width + 0.5 );
42  Size r_bin_hi = r_bin_lo + 1;
43 
44  value = 0.0;
45  deriv = 0.0;
46 
47  if (r_bin_lo > NUM_BINS ) return;
48 
49  if (r_bin_hi > NUM_BINS ){
50  value = potential( NUM_BINS );
51  } else if (r_bin_lo < 1 ) {
52  value = potential( 1 );
53  } else {
54  Real const fraction = (r/bin_width + 0.5) - r_bin_lo;
55  value = ( (1 - fraction ) * potential( r_bin_lo ) +
56  fraction * potential( r_bin_hi ) );
57  deriv = ( potential( r_bin_hi ) - potential( r_bin_lo ) ) / bin_width;
58  }
59 
60 }
61 
62 } // end namespace scoring
63 } // end namespace core
64 
65 #endif