IMP logo
IMP Reference Guide  2.20.2
The Integrative Modeling Platform
WeightScore.h
Go to the documentation of this file.
1 /**
2  * \file IMP/score_functor/WeightScore.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_WEIGHT_SCORE_H
9 #define IMPSCORE_FUNCTOR_WEIGHT_SCORE_H
10 
11 #include <IMP/score_functor/score_functor_config.h>
12 #include <IMP/algebra/utility.h>
13 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
14 
15 /** A shift the distance by subtracting x0 and pass it to the base
16  class.*/
17 template <class BaseDistanceScore>
18 class WeightScore : public BaseDistanceScore {
19  typedef BaseDistanceScore P;
20  double w_;
21 
22  public:
23  WeightScore(double w, BaseDistanceScore base) : P(base), w_(w) {}
24  template <unsigned int D>
25  double get_score(Model *m,
26  const Array<D, ParticleIndex> &pi,
27  double distance) const {
28  return w_ * P::get_score(m, pi, distance);
29  }
30  template <unsigned int D>
31  DerivativePair get_score_and_derivative(
32  Model *m, const Array<D, ParticleIndex> &p,
33  double distance) const {
34  DerivativePair ret = P::get_score_and_derivative(m, p, distance);
35  ret.first *= w_;
36  ret.second *= w_;
37  return ret;
38  }
39 };
40 
41 IMPSCOREFUNCTOR_END_NAMESPACE
42 
43 #endif /* IMPSCORE_FUNCTOR_WEIGHT_SCORE_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.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition: types.h:22