IMP logo
IMP Reference Guide  2.20.0
The Integrative Modeling Platform
Shift.h
Go to the documentation of this file.
1 /**
2  * \file IMP/score_functor/Shift.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_SHIFT_H
9 #define IMPSCORE_FUNCTOR_SHIFT_H
10 
11 #include <IMP/score_functor/score_functor_config.h>
12 #include <IMP/algebra/utility.h>
13 #include <IMP/Model.h>
14 #include <IMP/particle_index.h>
15 #include <cereal/access.hpp>
16 #include <cereal/types/base_class.hpp>
17 
18 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
19 
20 /** A shift the distance by subtracting x0 and pass it to the base
21  class.*/
22 template <class BaseDistanceScore>
23 class Shift : public BaseDistanceScore {
24  typedef BaseDistanceScore P;
25  double x0_;
26 
27  friend class cereal::access;
28  template<class Archive> void serialize(Archive &ar) {
29  ar(cereal::base_class<BaseDistanceScore>(this), x0_);
30  }
31 
32  public:
33  Shift(double x0, BaseDistanceScore base) : P(base), x0_(x0) {}
34  Shift() {}
35  template <unsigned int D>
36  double get_score(Model *m,
37  const Array<D, ParticleIndex> &pi,
38  double distance) const {
39  return P::get_score(m, pi, distance - x0_);
40  }
41  template <unsigned int D>
42  DerivativePair get_score_and_derivative(
43  Model *m, const Array<D, ParticleIndex> &p,
44  double distance) const {
45  return P::get_score_and_derivative(m, p, distance - x0_);
46  }
47  template <unsigned int D>
48  double get_maximum_range(
49  Model *m, const Array<D, ParticleIndex> &pi) const {
50  return P::get_maximum_range(m, pi) - x0_;
51  }
52  bool get_is_trivially_zero(Model *m,
53  const ParticleIndexPair &pi,
54  double squared_distance) const {
55  return squared_distance >
56  algebra::get_squared(P::get_maximum_range(m, pi) + x0_);
57  }
58 };
59 
60 IMPSCOREFUNCTOR_END_NAMESPACE
61 
62 #endif /* IMPSCORE_FUNCTOR_SHIFT_H */
Functions and adaptors for dealing with particle indexes.
A class to store a fixed array of same-typed values.
Definition: Array.h:35
Storage of a model, its restraints, constraints and particles.
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