IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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
18IMPSCOREFUNCTOR_BEGIN_NAMESPACE
19
20/** A shift the distance by subtracting x0 and pass it to the base
21 class.*/
22template <class BaseDistanceScore>
23class 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
36 double get_x0() const { return x0_; }
37
38 template <unsigned int D>
39 double get_score(Model *m,
41 double distance) const {
42 return P::get_score(m, pi, distance - x0_);
43 }
44 template <unsigned int D>
45 DerivativePair get_score_and_derivative(
46 Model *m, const Array<D, ParticleIndex> &p,
47 double distance) const {
48 return P::get_score_and_derivative(m, p, distance - x0_);
49 }
50 template <unsigned int D>
51 double get_maximum_range(
52 Model *m, const Array<D, ParticleIndex> &pi) const {
53 return P::get_maximum_range(m, pi) - x0_;
54 }
55 bool get_is_trivially_zero(Model *m,
56 const ParticleIndexPair &pi,
57 double squared_distance) const {
58 return squared_distance >
59 algebra::get_squared(P::get_maximum_range(m, pi) + x0_);
60 }
61};
62
63IMPSCOREFUNCTOR_END_NAMESPACE
64
65#endif /* IMPSCORE_FUNCTOR_SHIFT_H */
Storage of a model, its restraints, constraints and particles.
Functions to deal with very common math operations.
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:111
Array< 2, ParticleIndex > ParticleIndexPair
An ordered pair of particles, each identified by its ParticleIndex.
Definition base_types.h:202
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition types.h:22
Functions and adaptors for dealing with particle indexes.