IMP logo
IMP Reference Guide  2.20.2
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-2022 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  LinearLowerBound() : k_(0.0) {}
26  // depend on get_is_trivially_zero
27  template <unsigned int D>
28  double get_score(Model *,
30  double distance) const {
31  if (distance >= 0) return 0;
32  return -k_ * distance;
33  }
34  template <unsigned int D>
35  DerivativePair get_score_and_derivative(
36  Model *, const Array<D, ParticleIndex> &,
37  double distance) const {
38  if (distance >= 0) return DerivativePair(0, 0);
39  return DerivativePair(-k_ * distance, -k_);
40  }
41  template <unsigned int D>
42  double get_maximum_range(
43  Model *, const Array<D, ParticleIndex> &) const {
44  return 0;
45  }
46  template <unsigned int D>
47  bool get_is_trivially_zero(Model *,
49  double squared_distance) const {
50  return squared_distance > 0;
51  }
52 
53  float get_k() const{
54  return k_;
55  }
56 };
57 
58 IMPSCOREFUNCTOR_END_NAMESPACE
59 
60 #endif /* IMPSCORE_FUNCTOR_LINEAR_LOWER_BOUND_H */
A class to store a fixed array of same-typed values.
Definition: Array.h:35
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
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: types.h:22
A functor for computing a distance based score for D particles.
Definition: Score.h:20