IMP logo
IMP Reference Guide  2.15.0
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-2021 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, pi[1]));
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, distance - get_radius(m, pi[1]));
43  }
44  double get_maximum_range(Model *m,
45  const ParticleIndexPair &pi) const {
46  return P::get_maximum_range(m, pi) + get_radius(m, pi[1]);
47  }
48  bool get_is_trivially_zero(Model *m,
49  const ParticleIndexPair &pi,
50  double squared_distance) const {
51  return squared_distance >
52  algebra::get_squared(P::get_maximum_range(m, pi) +
53  get_radius(m, pi[1]));
54  }
55 };
56 
57 IMPSCOREFUNCTOR_END_NAMESPACE
58 
59 #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:72
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:23
Helper macros for throwing and handling exceptions.