Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CircularGeneral1D_Func.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 /// @file src/core/scoring/constraints/CircularGeneral1D_Func.cc
10 /// @brief A general 1D function that can be initialized by FArray or from text file. There's stuff like this all over Rosetta.
11 /// @author Rhiju Das
12 
14 #include <core/types.hh>
15 
16 #include <utility/io/izstream.hh>
17 #include <utility/vector1.hh>
18 
19 #include <ObjexxFCL/FArray1D.hh>
20 
21 #include <iostream>
22 
23 namespace core {
24 namespace scoring {
25 namespace constraints {
26 
27 //Constructor
29  ObjexxFCL::FArray1D< Real > const & data,
30  Real const & xmin,
31  Real const & xbin):
32  data_( data ),
33  xmin_( xmin ),
34  xbin_( xbin ),
35  num_bins_( data.size() )
36 {
37 }
38 
39 //Constructor
41 {
42  //Read in data file, and fill in private data.
43  utility::io::izstream stream;
44  stream.open( filename );
45 
46  std::string line;
47  Real x( 0.0 ), /*x_prev( 0.0 ),*/ val( 0.0 );
48  Size count( 0 );
49  utility::vector1< Real > all_vals;
50 
51  while( getline( stream, line ) ){
52 
53  std::istringstream l( line );
54  l >> x >> val;
55 
56  count++;
57  if ( count == 1 ) xmin_ = x;
58  if ( count == 2 ) xbin_ = x - xmin_;
59  //if ( count > 2 ) assert( (x - x_prev) == xbin_ );
60 
61  all_vals.push_back( val );
62 
63  //x_prev = x; // set but never used ~Labonte
64  }
65 
66  num_bins_ = all_vals.size();
67  data_.dimension( num_bins_ );
68 
69  for ( Size i = 1; i <= num_bins_; i++ ) data_( i ) = all_vals[ i ];
70  // std::cout << "READ: " << num_bins_ << " from " << filename << " --> " <<
71  // " " << xmin_ << " " << xbin_ << " " << all_vals[ num_bins_ ] << std::endl;
72 
73  stream.close();
74 }
75 
76 Real
78 
79  Real bin_real = ( x - xmin_ ) / xbin_;
80 
81  Real const bin_wrap_real = bin_real - num_bins_ * floor( bin_real / num_bins_ ) + 1;
82 
83  assert( bin_wrap_real >= 1 && bin_wrap_real < num_bins_ + 1 );
84 
85  Size const bin = static_cast< Size >( bin_wrap_real );
86  Real const leftover = bin_wrap_real - bin;
87 
88  Size next_bin = bin + 1;
89  if ( next_bin > num_bins_ ) next_bin = 1; //wrap around.
90 
91  return (data_( bin ) * ( 1 - leftover )) + (data_( next_bin ) * leftover) ;
92 
93 }
94 
95 Real
97 
98  Real bin_real = ( x - xmin_ ) / xbin_;
99 
100  Real const bin_wrap_real = bin_real - num_bins_ * floor( bin_real / num_bins_ ) + 1;
101  assert( bin_wrap_real >= 1 && bin_wrap_real < num_bins_ + 1 );
102 
103  Size const bin = static_cast< Size >( bin_wrap_real );
104  //Real const leftover = bin_wrap_real - bin;
105 
106  Size next_bin = bin + 1;
107  if ( next_bin > num_bins_ ) next_bin = 1; //wrap around.
108 
109  return ( data_( next_bin ) - data_( bin ) )/ xbin_;
110 
111 }
112 
113 } // namespace constraints
114 } // namespace scoring
115 } // namespace core