IMP logo
IMP Reference Guide  develop.02fce3ae61,2026/01/08
The Integrative Modeling Platform
SphereDistancePairScore.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/SphereDistancePairScore.h
3  * \brief A score on the distance between the surfaces of two spheres.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPCORE_SPHERE_DISTANCE_PAIR_SCORE_H
9 #define IMPCORE_SPHERE_DISTANCE_PAIR_SCORE_H
10 
11 #include <IMP/core/core_config.h>
12 #include "XYZR.h"
20 
21 IMPCORE_BEGIN_NAMESPACE
22 
23 // needed to keep swig from getting confused or breaking line
24 // lengths
25 typedef score_functor::SphereDistance<score_functor::UnaryFunctionEvaluate>
26  SphereDistanceScore;
27 
28 //! A score on the distance between the surfaces of two spheres.
29 /** Scores based on the distance between the surfaces of two spheres,
30  implicitly assuming they are decorated as XYZR, using an arbitrary
31  unary function. Note the distance may be negative if the spheres overlap.
32 
33  \see XYZR
34  \see SphereDistancePairScore
35  \see DistancePairScore
36  \see SoftSpherePairScore
37  */
38 IMP_FUNCTOR_DISTANCE_PAIR_SCORE(SphereDistancePairScore, SphereDistanceScore,
39  (UnaryFunction *uf,
40  std::string name =
41  "SphereDistancePairScore%1%"),
43 
46 
47 //!A harmonic upper bound on the distance between two spheres
48 /** \see XYZR
49  \see SpherePairScore
50  \see SoftSpherePairScore
51  */
54  HarmonicUpperBoundSphereDistanceScore,
55  (double x0, double k,
56  std::string name = "HarmonicUpperBoundSphereDistancePairScore%1%"),
59 
60 //!A harmonic upper bound on the diameter of the span of two spheres
61 /** This restraint restraints how far the furthest points of two spheres
62  are from one another.
63 
64  \see XYZR
65  \see SpherePairScore
66  \see SoftSpherePairScore
67  \see NormalizedSphereDistancePairScore
68  */
70  : public PairScore {
71  double x0_, k_;
72 
73  public:
74  HarmonicUpperBoundSphereDiameterPairScore(double d0, double k);
75  double get_rest_length() const { return x0_; }
76  double get_stiffness() const { return k_; }
77  double evaluate_index(Model *m, const ParticleIndexPair &p,
78  DerivativeAccumulator *da) const override;
80  Model *m, const ParticleIndexes &pis) const override;
83 };
84 
87 
90 
91 //! A harmonic score on the distance between two spheres
92 /** A harmonic score on the distance between two spheres, implicitly
93  assuming they are decorated as XYZR.
94 
95  \see XYZR
96  \see SpherePairScore
97  \see SoftSpherePairScore
98  */
100  HarmonicSphereDistanceScore,
101  (double x0, double k,
102  std::string name = "HarmonicSphereDistancePairScore%1%"),
104  x0, score_functor::Harmonic(k))),
105  double get_x0() const { return get_score_functor().get_x0(); }
106  double get_k() const { return get_score_functor().get_k(); });
108 
109 #ifndef IMP_DOXYGEN
110 inline double HarmonicUpperBoundSphereDiameterPairScore::evaluate_index(
111  Model *m, const ParticleIndexPair &p,
112  DerivativeAccumulator *da) const {
113  algebra::Vector3D delta =
114  m->get_sphere(std::get<0>(p)).get_center()
115  - m->get_sphere(std::get<1>(p)).get_center();
116  static const double MIN_DISTANCE = .00001;
117  double distance = delta.get_magnitude();
118  double shifted_distance
119  = distance - x0_ + m->get_sphere(std::get<0>(p)).get_radius() +
120  m->get_sphere(std::get<1>(p)).get_radius();
121  if (shifted_distance < 0) return 0;
122  double score = .5 * k_ * square(shifted_distance);
123  if (da && distance > MIN_DISTANCE) {
124  double deriv = k_ * shifted_distance;
125  algebra::Vector3D uv = delta / distance;
126  m->add_to_coordinate_derivatives(std::get<0>(p), uv * deriv, *da);
127  m->add_to_coordinate_derivatives(std::get<1>(p), -uv * deriv, *da);
128  }
129  return score;
130 }
131 #endif
132 
133 //! A score on the normalized distance between the surfaces of two spheres
134 /** The distance between the surfaces of the two spheres is divided by the
135  smaller radius to normalize it.
136  \see SphereDistancePairScore
137  \see XYZR
138  \see DistancePairScore
139  */
140 class IMPCOREEXPORT NormalizedSphereDistancePairScore : public PairScore {
142  FloatKey radius_;
143 
144  public:
146  FloatKey radius = FloatKey("radius"));
147  virtual double evaluate_index(Model *m,
148  const ParticleIndexPair &p,
149  DerivativeAccumulator *da) const override;
151  Model *m, const ParticleIndexes &pis) const override;
154  ;
155 };
156 
157 //! A score on a weighted distance between the surfaces of two spheres
158 /** The distance between the surfaces of the two spheres is multiplied by
159  the sum of a specific attribute
160  \see SphereDistancePairScore
161  \see XYZR
162  \see DistancePairScore
163  */
164 class IMPCOREEXPORT WeightedSphereDistancePairScore : public PairScore {
166  FloatKey radius_;
167  FloatKey weight_;
168 
169  public:
171  FloatKey radius = FloatKey("radius"));
172  virtual double evaluate_index(Model *m,
173  const ParticleIndexPair &p,
174  DerivativeAccumulator *da) const override;
176  Model *m, const ParticleIndexes &pis) const override;
179  ;
180 };
181 
184 
185 /** This class is equivalent to, but faster than a
186  SphereDistancePairScore with a HarmonicLowerBound.
187 */
189  (double k,
190  std::string name = "SoftSpherePairScore%1%"),
192 
193 IMPCORE_END_NAMESPACE
194 
195 #endif /* IMPCORE_SPHERE_DISTANCE_PAIR_SCORE_H */
Various important macros for implementing decorators.
Abstract class for scoring object(s) of type ParticleIndexPair.
Definition: PairScore.h:44
A harmonic upper bound on the distance between two spheres.
Key< 0 > FloatKey
The type used to identify float attributes in the Particles.
Definition: base_types.h:32
A Score on the distance between a pair of particles.
#define IMP_PAIR_SCORE_METHODS(Name)
Definition: pair_macros.h:25
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
A Score on the distance between a pair of particles.
A harmonic score on the distance between two spheres.
A harmonic upper bound on the diameter of the span of two spheres.
A harmonic score on the positive directed distance between a pair of particles. The score equals zero...
A more IMP-like version of the std::vector.
Definition: Vector.h:50
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
A harmonic score on the directed distance between a pair of particles, centered at 0...
A smart pointer to a ref-counted Object that is a class member.
Definition: Pointer.h:143
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const =0
Overload this method to specify the inputs.
A harmonic score on the negative directed distance between a pair of particles. The score equals zero...
A score on a weighted distance between the surfaces of two spheres.
A Score on the distance between a pair of particles.
#define IMP_FUNCTOR_DISTANCE_PAIR_SCORE(Name, Functor, Args, PassArgs, Accessors)
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
VectorD< 3 > Vector3D
Definition: VectorD.h:408
Decorator for a sphere-like particle.
A score on the normalized distance between the surfaces of two spheres.
Abstract single variable functor class for score functions.
Definition: UnaryFunction.h:27
virtual double evaluate_index(Model *m, const ParticleIndexPair &vt, DerivativeAccumulator *da) const =0
Compute the score and the derivative if needed.
Class for adding derivatives from restraints to the model.