Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FadeInterval.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/hbonds/FadeInterval.cc
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 // Unit Headers
17 
18 // Project Headers
19 #include <core/types.hh>
20 
21 // C++ Headers
22 #include <ostream>
23 #include <string>
24 
25 namespace core {
26 namespace scoring {
27 namespace hbonds {
28 
29 /// @details Auto-generated virtual destructor
31 
32 using std::string;
33 using std::ostream;
34 
35 // For the default construction always return weight=0, deriv=0
36 // Proof: In the functions 'value_deriv' and 'value'
37 // if x < 0 then x < fmax_ and x <= min0_ so value and deriv both equal 0
38 // otherwise if x >= 0 then x >= max0_ so value and deriv both equal 0
40  name_("fade_zero"),
41  min0_(0.0),
42  fmin_(0.0),
43  fmax_(0.0),
44  max0_(0.0),
45  dfade_min_(0.0),
46  dfade_max_(0.0),
47  smooth_(false)
48 {}
49 
51  Real const min0,
52  Real const fmin,
53  Real const fmax,
54  Real const max0,
55  bool const smooth) :
56  name_("UNKNOWN"),
57  min0_(min0),
58  fmin_(fmin),
59  fmax_(fmax),
60  max0_(max0),
61  dfade_min_(1.0/static_cast<double>(fmin-min0)),
62  dfade_max_(1.0/static_cast<double>(max0-fmax)),
63  smooth_(smooth)
64 {
65  assert(min0 <= fmin && fmin <= fmax && fmax <= max0);
66 }
67 
69  string const & name,
70  Real const min0,
71  Real const fmin,
72  Real const fmax,
73  Real const max0,
74  bool const smooth) :
75  name_(name),
76  min0_(min0),
77  fmin_(fmin),
78  fmax_(fmax),
79  max0_(max0),
80  dfade_min_(1.0/static_cast<double>(fmin-min0)),
81  dfade_max_(1.0/static_cast<double>(max0-fmax)),
82  smooth_(smooth)
83 {
84  assert(min0 <= fmin && fmin <= fmax && fmax <= max0);
85 }
86 
87 void
89  Real const x,
90  double &val,
91  double &deriv) const
92 {
93  //JSS 5 intervals --a-b---c-d--
94  if (x <= fmax_) {
95  if (x <= min0_) { val = deriv = 0.0; return; } // in (-\infty, min0]
96  if (x >= fmin_) { val = 1.0; deriv = 0.0; return; } // in [fmin, fmax]
97  if (smooth_){
98  double const z((x - min0_)* dfade_min_);
99  val = z*z*(3-2*z);
100  deriv = -6*z*(z-1)*dfade_min_;
101  } else {
102  deriv = dfade_min_; val = (x - min0_) * dfade_min_; // in (min0,fmin)
103  }
104  } else {
105  if (x >= max0_) { val = deriv = 0.0; return; } // in [max0, \infty)
106  if (smooth_){
107  double const z((x - fmax_) * dfade_max_);
108  val = z*z*(2*z-3) + 1;
109  deriv = 6*z*(z-1)*dfade_max_;
110  } else {
111  deriv = -dfade_max_; val = (max0_ - x) * dfade_max_; // in (fmax,max0)
112  }
113  }
114 }
115 
116 double
118  Real const x) const
119 {
120  //JSS 5 intervals --a-b---c-d--
121  if (x <= fmax_) {
122  if (x <= min0_) return 0.0; // in (-\infty, min0]
123  if (x >= fmin_) return 1.0; // in [fmin, fmax]
124  if (smooth_){
125  double const z((x - min0_)* dfade_min_);
126  return z*z*(3.0-2.0*z);
127  } else {
128  return (x - min0_) * dfade_min_; // in (min0,fmin)
129  }
130  } else {
131  if (x >= max0_) return 0.0; // in [max0, \infty)
132  if (smooth_){
133  double const z((x - fmax_) * dfade_max_);
134  return z*z*(2.0*z-3.0) + 1.0;
135  } else {
136  return (max0_ - x) * dfade_max_; // in (fmax,max0)
137  }
138  }
139 }
140 
141 string
143 {
144  return name_;
145 }
146 
147 Real
149 {
150  return min0_;
151 }
152 
153 Real
155 {
156  return fmin_;
157 }
158 
159 Real
161 {
162  return fmax_;
163 }
164 
165 Real
167 {
168  return max0_;
169 }
170 
171 bool
173 {
174  return smooth_;
175 }
176 
177 bool
179  FadeInterval const & a,
180  FadeInterval const & b)
181 {
182  return
183  a.min0_ == b.min0_ &&
184  a.fmin_ == b.fmin_ &&
185  a.fmax_ == b.fmax_ &&
186  a.max0_ == b.max0_ &&
187  a.smooth_ == b.smooth_;
188 }
189 
190 bool
192  FadeInterval const & a,
193  FadeInterval const & b)
194 {
195  return !(a == b);
196 }
197 
198 ostream &
200  ostream & out,
201  FadeInterval const & fade_interval)
202 {
203  fade_interval.show( out );
204  return out;
205 }
206 
207 void
209  ostream & out ) const
210 {
211  out << "(" << name_ << "; " << min0_ << ", " << fmin_ << ", " << fmax_ << ", " << max0_ << ")" << (smooth_ ? " smoothed" : "");
212 }
213 
214 } // hbonds
215 } // scoring
216 } // core