Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FadeInterval.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 //
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/hbonds/FadeInterval.hh
11 /// @brief FadeInterval class, used a simplified cross term for the hbond score term
12 /// @author Jack Snoeyink
13 /// @author Matthew O'Meara
14 
15 #ifndef INCLUDED_core_scoring_hbonds_FadeInterval_hh
16 #define INCLUDED_core_scoring_hbonds_FadeInterval_hh
17 
18 // Unit headers
20 
21 // Project headers
22 #include <core/types.hh>
23 
24 // Utility headers
25 #include <utility/pointer/ReferenceCount.hh>
26 
27 // C++ headers
28 #include <string>
29 
30 namespace core {
31 namespace scoring {
32 namespace hbonds {
33 
34 /////////////////////////////
35 /// Classic FadeInterval
36 /////////////////////////////
37 /// stores an "fading interval" [a b c d] with a <= b <= c <= d
38 /// and computes the fraction of containment for x, which is defined to be
39 /// 0 if x is outside of (a,d), 1 if x is inside of [b,c],
40 /// and a linear ramp otherwise.
41 /// ___/-----\___
42 /// i.e. (x-a)/(b-a) for x in (a,b), and (d-x)/(d-c) for x in (c,d)
43 /// This is used to ensure that hbond scoring as a sum Er + ExH + ExD goes to zero at the edges.
44 ///
45 /// Notes about discontinuities:
46 /// if x equals a, b, c, or d then deriv = 0
47 /// if x == a == b then value = 0
48 /// if x == c == d and a < c then value = 1
49 /// if x == c == d and a == c then value = 0
50 /// In particular if a == b == c == d then for all x, value == deriv == 0
51 ///
52 //////////////////////////////
53 /// Smooth FadeInteval
54 //////////////////////////////
55 /// Rather than using a piecewise linear fading function,
56 /// use a piecewise sigmoid function to have a continuous derivative.
57 ///
58 /// Look for a canonical sigmoid function f(x) such that,
59 /// f(0) = 1 f(1) = 0 // goes through the the knots
60 /// f'(0) = 0 f'(1) = 0 // is horizontal at the knots
61 /// a continuous differative
62 /// f(x-.5)-.5 is odd // symmetric
63 ///
64 /// I claim, f(x) = 2x^3 - 3x^2 + 1, satisfies these constraints:
65 /// f(0) = 2(0)^3 - 3(x)^2 + 1 = 1
66 /// f(1) = 2(1)^3 - 3(1)^2 + 1 = 2 - 3 + 1 = 0
67 ///
68 /// f'(x) = 6x^2 - 6x = 6x(x-1)
69 /// f'(0) = 6(0)(0-1) = 0
70 /// f'(1) = 6(1)(1-1) = 0
71 ///
72 /// a function g(x) is odd if g(-x) = -g(x)
73 /// f((-x)-.5)-.5 = 2(-x-.5)^3 - 3(-x-.5)^2 + 1 - .5
74 /// = -2x^3 - 6x^2 - 4.5x - .5
75 /// -(f(x-.5)-.5) = -2(x-.5)^3 + 3(x-.5)^2 - 1 + .5
76 /// = -2x^3 - 6x^2 - 4.5x - .5
77 ///
78 /// Given the knots --a-b---c-d-- transform f(x) to fill a-b and c-d
79 /// to connect the linear regions.
80 ///
81 ///
82 /// a-b region:
83 /// let z(x) = (x-a)/(b-a) and z'(x) = 1/(b-a)
84 /// use g(x) = 1-f(-z(x)) = -2z^3 + 3z^2
85 /// and g'(x) = -6z(z-1)*z'(x)
86 /// c-d region:
87 /// let z(x) = (x-c)/(d-c) and z'(x) = 1/(d-c)
88 /// use g(x) = f(z) = 2z^3 - 3z^2 + 1
89 /// and g'(x) = 6z(z-1)*z'(x)
90 ///
91 ////////////////////////////
93 
94 public:
95  ///@brief Automatically generated virtual destructor for class deriving directly from ReferenceCount
96  virtual ~FadeInterval();
97  /// Constructor
98 
99  FadeInterval();
100 
101  FadeInterval(
102  Real const min0,
103  Real const fmin,
104  Real const fmax,
105  Real const max0,
106  bool const smooth = false);
107 
108  FadeInterval(
109  std::string const & name,
110  Real const min0,
111  Real const fmin,
112  Real const fmax,
113  Real const max0,
114  bool const smooth = false);
115 
116  void
117  value_deriv(
118  Real const x,
119  double &val,
120  double &deriv
121  ) const;
122 
123  double
124  value(
125  Real const x
126  ) const;
127 
129  get_name() const;
130 
131  Real
132  get_min0() const;
133 
134  Real
135  get_fmin() const;
136 
137  Real
138  get_fmax() const;
139 
140  Real
141  get_max0() const;
142 
143  bool
144  get_smooth() const;
145 
146  friend
147  bool
148  operator==(FadeInterval const & a, FadeInterval const & b);
149 
150  friend
151  bool
152  operator!=(FadeInterval const & a, FadeInterval const & b);
153 
154  friend
155  std::ostream &
156  operator<< (std::ostream & out, FadeInterval const & fade_interval);
157 
158  void
159  show( std::ostream & out ) const;
160 
161 private:
163  Real const min0_;
164  Real const fmin_;
165  Real const fmax_;
166  Real const max0_;
167  double const dfade_min_;
168  double const dfade_max_;
169  bool const smooth_;
170 
171 };
172 
173 } // hbonds
174 } // scoring
175 } // core
176 
177 #endif