IMP  2.1.0
The Integrative Modeling Platform
LinearLowerBound.h
Go to the documentation of this file.
1 /**
2  * \file IMP/score_functor/LinearLowerBound.h
3  * \brief A Score on the distance between a pair of particles.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPSCORE_FUNCTOR_LINEAR_LOWER_BOUND_H
9 #define IMPSCORE_FUNCTOR_LINEAR_LOWER_BOUND_H
10 
11 #include <IMP/score_functor/score_functor_config.h>
12 #include "Score.h"
13 #include <IMP/algebra/utility.h>
14 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
15 
16 /** A DistanceScore that scores with a linear function on distances below 0.
17 
18  \note a positive k results in repulsion
19 */
20 class LinearLowerBound : public Score {
21  const double k_;
22 
23  public:
24  LinearLowerBound(double k) : k_(k) {}
25  // depend on get_is_trivially_zero
26  template <unsigned int D>
27  double get_score(kernel::Model *,
29  double distance) const {
30  if (distance >= 0) return 0;
31  return -k_ * distance;
32  }
33  template <unsigned int D>
34  DerivativePair get_score_and_derivative(
36  double distance) const {
37  if (distance >= 0) return DerivativePair(0, 0);
38  return DerivativePair(-k_ * distance, -k_);
39  }
40  template <unsigned int D>
41  double get_maximum_range(
43  return 0;
44  }
45  template <unsigned int D>
46  bool get_is_trivially_zero(kernel::Model *,
48  double squared_distance) const {
49  return squared_distance > 0;
50  }
51 };
52 
53 IMPSCOREFUNCTOR_END_NAMESPACE
54 
55 #endif /* IMPSCORE_FUNCTOR_LINEAR_LOWER_BOUND_H */
A class to store an fixed array of same-typed values.
Definition: base/Array.h:33
Functions to deal with very common math operations.
A Score on the distance between a pair of particles.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition: base/types.h:23
Class for storing model, its restraints, constraints, and particles.