IMP logo
IMP Reference Guide  2.6.1
The Integrative Modeling Platform
score_functor/HarmonicUpperBound.h
Go to the documentation of this file.
1 /**
2  * \file IMP/score_functor/HarmonicUpperBound.h
3  * \brief A Score on the distance between a pair of particles.
4  *
5  * Copyright 2007-2016 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPSCORE_FUNCTOR_HARMONIC_UPPER_BOUND_H
9 #define IMPSCORE_FUNCTOR_HARMONIC_UPPER_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 harmonic on distances above 0.*/
17 class HarmonicUpperBound : public Score {
18  double k_;
19 
20  public:
21  HarmonicUpperBound(double k) : k_(k) {}
22  template <unsigned int D>
23  double get_score(Model *,
25  double distance) const {
26  if (distance < 0)
27  return 0;
28  else
29  return .5 * k_ * algebra::get_squared(distance);
30  }
31  template <unsigned int D>
32  DerivativePair get_score_and_derivative(
33  Model *m, const Array<D, ParticleIndex> &p,
34  double distance) const {
35  if (distance < 0)
36  return DerivativePair(0, 0);
37  else
38  return DerivativePair(get_score(m, p, distance), k_ * (distance));
39  }
40 };
41 
42 IMPSCOREFUNCTOR_END_NAMESPACE
43 
44 #endif /* IMPSCORE_FUNCTOR_HARMONIC_UPPER_BOUND_H */
A class to store an fixed array of same-typed values.
Definition: Array.h:33
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
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:23
A functor for computing a distance based score for two particles.
Definition: Score.h:20