IMP logo
IMP Reference Guide  2.17.0
The Integrative Modeling Platform
score_functor/Harmonic.h
Go to the documentation of this file.
1 /**
2  * \file IMP/score_functor/Harmonic.h
3  * \brief A harmonic score on the directed distance between a pair of particles,
4  * centered at 0.
5  *
6  * Copyright 2007-2022 IMP Inventors. All rights reserved.
7  */
8 
9 #ifndef IMPSCORE_FUNCTOR_HARMONIC_H
10 #define IMPSCORE_FUNCTOR_HARMONIC_H
11 
12 #include <IMP/score_functor/score_functor_config.h>
13 #include "Score.h"
14 #include <IMP/algebra/utility.h>
15 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
16 
17 /** A harmonic score on the directed distance between a pair of particles,
18  centered at 0.
19 */
20 class Harmonic : public Score {
21  double k_;
22 
23  public:
24  Harmonic(double k) : k_(k) {}
25  template <unsigned int D>
26  double get_score(Model *,
28  double distance) const {
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  return DerivativePair(get_score(m, p, distance), k_ * (distance));
36  }
37  double get_k() { return k_; }
38  void set_k(double k) { k_ = k; }
39 };
40 
41 IMPSCOREFUNCTOR_END_NAMESPACE
42 
43 #endif /* IMPSCORE_FUNCTOR_HARMONIC_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:73
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