IMP  2.0.0
The Integrative Modeling Platform
score_functor/HarmonicLowerBound.h
Go to the documentation of this file.
1 /**
2  * \file IMP/score_functor/HarmonicLowerBound.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_HARMONIC_LOWER_BOUND_H
9 #define IMPSCORE_FUNCTOR_HARMONIC_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 harmonic on distances below 0.*/
17 class HarmonicLowerBound: public Score {
18  double k_;
19 public:
20  HarmonicLowerBound(double k): k_(k){}
21  template <unsigned int D>
22  double get_score(Model *, const base::Array<D, ParticleIndex>&,
23  double distance) const {
24  if (distance > 0) return 0;
25  return .5*k_*algebra::get_squared(distance);
26  }
27  template <unsigned int D>
28  DerivativePair get_score_and_derivative(Model *m,
30  double distance) const {
31  if (distance > 0) return DerivativePair(0,0);
32  return DerivativePair(get_score(m,p,distance),
33  k_*(distance));
34  }
35  template <unsigned int D>
36  double get_maximum_range(Model *,
37  const base::Array<D, ParticleIndex>& ) const {
38  return 0;
39  }
40  template <unsigned int D>
41  bool get_is_trivially_zero(Model *,
43  double squared_distance) const {
44  return squared_distance > 0;
45  }
46 };
47 
48 IMPSCOREFUNCTOR_END_NAMESPACE
49 
50 #endif /* IMPSCORE_FUNCTOR_HARMONIC_LOWER_BOUND_H */