IMP logo
IMP Reference Guide  develop.2f2f70d8d2,2026/03/10
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 harmonic score on the positive directed distance between
4  * a pair of particles. The score equals zero for
5  * non-positive directed distances.
6  *
7  * Copyright 2007-2022 IMP Inventors. All rights reserved.
8  */
9 
10 #ifndef IMPSCORE_FUNCTOR_HARMONIC_UPPER_BOUND_H
11 #define IMPSCORE_FUNCTOR_HARMONIC_UPPER_BOUND_H
12 
13 #include <IMP/score_functor/score_functor_config.h>
14 #include "Score.h"
15 #include <IMP/algebra/utility.h>
16 #include <cereal/access.hpp>
17 
18 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
19 
20 /** A harmonic score on the positive directed distance between
21  a pair of particles. The score equals zero for
22  non-positive directed distances.
23 */
24 class HarmonicUpperBound : public Score {
25  double k_;
26 
27  friend class cereal::access;
28  template<class Archive> void serialize(Archive &ar) {
29  ar(k_);
30  }
31  public:
32  HarmonicUpperBound(double k) : k_(k) {}
34 
35  double get_k() const { return k_; }
36 
37  template <unsigned int D>
38  double get_score(Model *,
40  double distance) const {
41  if (distance < 0)
42  return 0;
43  else
44  return .5 * k_ * algebra::get_squared(distance);
45  }
46  template <unsigned int D>
47  DerivativePair get_score_and_derivative(
48  Model *m, const Array<D, ParticleIndex> &p,
49  double distance) const {
50  if (distance < 0)
51  return DerivativePair(0, 0);
52  else
53  return DerivativePair(get_score(m, p, distance), k_ * (distance));
54  }
55 };
56 
57 IMPSCOREFUNCTOR_END_NAMESPACE
58 
59 #endif /* IMPSCORE_FUNCTOR_HARMONIC_UPPER_BOUND_H */
A class to store a fixed array of same-typed values.
Definition: Array.h:40
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