IMP logo
IMP Reference Guide  2.20.1
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 =
103  "HarmonicSphereDistancePairScore%1%"),
106 
107 #ifndef IMP_DOXYGEN
108 inline double HarmonicUpperBoundSphereDiameterPairScore::evaluate_index(
109  Model *m, const ParticleIndexPair &p,
110  DerivativeAccumulator *da) const {
111  algebra::Vector3D delta =
112  m->get_sphere(p[0]).get_center() - m->get_sphere(p[1]).get_center();
113  static const double MIN_DISTANCE = .00001;
114  double distance = delta.get_magnitude();
115  double shifted_distance = distance - x0_ + m->get_sphere(p[0]).get_radius() +
116  m->get_sphere(p[1]).get_radius();
117  if (shifted_distance < 0) return 0;
118  double score = .5 * k_ * square(shifted_distance);
119  if (da && distance > MIN_DISTANCE) {
120  double deriv = k_ * shifted_distance;
121  algebra::Vector3D uv = delta / distance;
122  m->add_to_coordinate_derivatives(p[0], uv * deriv, *da);
123  m->add_to_coordinate_derivatives(p[1], -uv * deriv, *da);
124  }
125  return score;
126 }
127 #endif
128 
129 //! A score on the normalized distance between the surfaces of two spheres
130 /** The distance between the surfaces of the two spheres is divided by the
131  smaller radius to normalize it.
132  \see SphereDistancePairScore
133  \see XYZR
134  \see DistancePairScore
135  */
136 class IMPCOREEXPORT NormalizedSphereDistancePairScore : public PairScore {
138  FloatKey radius_;
139 
140  public:
142  FloatKey radius = FloatKey("radius"));
143  virtual double evaluate_index(Model *m,
144  const ParticleIndexPair &p,
145  DerivativeAccumulator *da) const override;
147  Model *m, const ParticleIndexes &pis) const override;
150  ;
151 };
152 
153 //! A score on a weighted distance between the surfaces of two spheres
154 /** The distance between the surfaces of the two spheres is multiplied by
155  the sum of a specific attribute
156  \see SphereDistancePairScore
157  \see XYZR
158  \see DistancePairScore
159  */
160 class IMPCOREEXPORT WeightedSphereDistancePairScore : public PairScore {
162  FloatKey radius_;
163  FloatKey weight_;
164 
165  public:
167  FloatKey radius = FloatKey("radius"));
168  virtual double evaluate_index(Model *m,
169  const ParticleIndexPair &p,
170  DerivativeAccumulator *da) const override;
172  Model *m, const ParticleIndexes &pis) const override;
175  ;
176 };
177 
180 
181 /** This class is equivalent to, but faster than a
182  SphereDistancePairScore with a HarmonicLowerBound.
183 */
185  (double k,
186  std::string name = "SoftSpherePairScore%1%"),
188 
189 IMPCORE_END_NAMESPACE
190 
191 #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
#define IMP_FUNCTOR_DISTANCE_PAIR_SCORE(Name, Functor, Args, PassArgs)
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:42
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_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
VectorD< 3 > Vector3D
Definition: VectorD.h:425
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.