IMP logo
IMP Reference Guide  develop.27926d84dc,2024/04/19
The Integrative Modeling Platform
PointToSphereDistance.h
Go to the documentation of this file.
1 /**
2  * \file IMP/score_functor/PointToSphereDistance.h
3  * \brief A Score on the distance between a point and a sphere.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPSCORE_FUNCTOR_POINT_TO_SPHERE_DISTANCE_H
9 #define IMPSCORE_FUNCTOR_POINT_TO_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 
16 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
17 
18 /** Transform the center distance to the sphere distance
19  where only the second particle is treated as a sphere
20  and pass it off to BaseDistanceScore.
21 
22  \note The second particle is assumed to be the sphere.
23 
24  \see SphereDistance
25  */
26 template <class BaseDistanceScore>
27 class PointToSphereDistance : public BaseDistanceScore {
28  typedef BaseDistanceScore P;
29  static double get_radius(Model *m, const ParticleIndex pi) {
30  return m->get_sphere(pi).get_radius();
31  }
32 
33  public:
34  PointToSphereDistance(BaseDistanceScore base) : P(base) {}
35  double get_score(Model *m, const ParticleIndexPair &pi,
36  double distance) const {
37  return P::get_score(m, pi, distance - get_radius(m, std::get<1>(pi)));
38  }
39  DerivativePair get_score_and_derivative(Model *m,
40  const ParticleIndexPair &pi,
41  double distance) const {
42  return P::get_score_and_derivative(m, pi,
43  distance - get_radius(m, std::get<1>(pi)));
44  }
45  double get_maximum_range(Model *m,
46  const ParticleIndexPair &pi) const {
47  return P::get_maximum_range(m, pi) + get_radius(m, std::get<1>(pi));
48  }
49  bool get_is_trivially_zero(Model *m,
50  const ParticleIndexPair &pi,
51  double squared_distance) const {
52  return squared_distance >
53  algebra::get_squared(P::get_maximum_range(m, pi) +
54  get_radius(m, std::get<1>(pi)));
55  }
56 };
57 
58 IMPSCOREFUNCTOR_END_NAMESPACE
59 
60 #endif /* IMPSCORE_FUNCTOR_POINT_TO_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.