IMP logo
IMP Reference Guide  develop.e004443c3b,2024/04/25
The Integrative Modeling Platform
SphereDistance.h
Go to the documentation of this file.
1 /**
2  * \file IMP/score_functor/SphereDistance.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_SPHERE_DISTANCE_H
9 #define IMPSCORE_FUNCTOR_SPHERE_DISTANCE_H
10 
11 #include <IMP/score_functor/score_functor_config.h>
12 #include <IMP/Model.h>
13 #include <IMP/algebra/utility.h>
14 #include <IMP/check_macros.h>
15 #include <cereal/access.hpp>
16 #include <cereal/types/base_class.hpp>
17 
18 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
19 
20 /** Transform the center distance to the sphere distance
21  and pass it off to BaseDistanceScore.*/
22 template <class BaseDistanceScore>
23 class SphereDistance : public BaseDistanceScore {
24  friend class cereal::access;
25  template<class Archive> void serialize(Archive &ar) {
26  ar(cereal::base_class<BaseDistanceScore>(this));
27  }
28 
29  /* Caching the rsum makes things 30% faster with a linear score, but
30  doesn't work in non-trivial cases (eg AddScores where get_maximum_range()
31  isn't necessarily called first). I don't see how to fix the nontrivial
32  cases and, since they are the point of this module, disabled it.*/
33  typedef BaseDistanceScore P;
34  static double get_rsum(Model *m,
35  const ParticleIndexPair &pi) {
36  return m->get_sphere(std::get<0>(pi)).get_radius() +
37  m->get_sphere(std::get<1>(pi)).get_radius();
38  }
39 
40  public:
41  SphereDistance(BaseDistanceScore base) : P(base) {}
42  SphereDistance() {}
43  double get_score(Model *m, const ParticleIndexPair &pi,
44  double distance) const {
45  return P::get_score(m, pi, distance - get_rsum(m, pi));
46  }
47  DerivativePair get_score_and_derivative(Model *m,
48  const ParticleIndexPair &pi,
49  double distance) const {
50  return P::get_score_and_derivative(m, pi, distance - get_rsum(m, pi));
51  }
52  double get_maximum_range(Model *m,
53  const ParticleIndexPair &pi) const {
54  return P::get_maximum_range(m, pi) + get_rsum(m, pi);
55  }
56  bool get_is_trivially_zero(Model *m,
57  const ParticleIndexPair &pi,
58  double squared_distance) const {
59  return squared_distance >
60  algebra::get_squared(P::get_maximum_range(m, pi) + get_rsum(m, pi));
61  }
62 };
63 
64 IMPSCOREFUNCTOR_END_NAMESPACE
65 
66 #endif /* IMPSCORE_FUNCTOR_SPHERE_DISTANCE_H */
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
Helper macros for throwing and handling exceptions.