IMP logo
IMP Reference Guide  develop.cb6747d2d1,2024/03/28
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(std::get<0>(p)).get_center()
113  - m->get_sphere(std::get<1>(p)).get_center();
114  static const double MIN_DISTANCE = .00001;
115  double distance = delta.get_magnitude();
116  double shifted_distance
117  = distance - x0_ + m->get_sphere(std::get<0>(p)).get_radius() +
118  m->get_sphere(std::get<1>(p)).get_radius();
119  if (shifted_distance < 0) return 0;
120  double score = .5 * k_ * square(shifted_distance);
121  if (da && distance > MIN_DISTANCE) {
122  double deriv = k_ * shifted_distance;
123  algebra::Vector3D uv = delta / distance;
124  m->add_to_coordinate_derivatives(std::get<0>(p), uv * deriv, *da);
125  m->add_to_coordinate_derivatives(std::get<1>(p), -uv * deriv, *da);
126  }
127  return score;
128 }
129 #endif
130 
131 //! A score on the normalized distance between the surfaces of two spheres
132 /** The distance between the surfaces of the two spheres is divided by the
133  smaller radius to normalize it.
134  \see SphereDistancePairScore
135  \see XYZR
136  \see DistancePairScore
137  */
138 class IMPCOREEXPORT NormalizedSphereDistancePairScore : public PairScore {
140  FloatKey radius_;
141 
142  public:
144  FloatKey radius = FloatKey("radius"));
145  virtual double evaluate_index(Model *m,
146  const ParticleIndexPair &p,
147  DerivativeAccumulator *da) const override;
149  Model *m, const ParticleIndexes &pis) const override;
152  ;
153 };
154 
155 //! A score on a weighted distance between the surfaces of two spheres
156 /** The distance between the surfaces of the two spheres is multiplied by
157  the sum of a specific attribute
158  \see SphereDistancePairScore
159  \see XYZR
160  \see DistancePairScore
161  */
162 class IMPCOREEXPORT WeightedSphereDistancePairScore : public PairScore {
164  FloatKey radius_;
165  FloatKey weight_;
166 
167  public:
169  FloatKey radius = FloatKey("radius"));
170  virtual double evaluate_index(Model *m,
171  const ParticleIndexPair &p,
172  DerivativeAccumulator *da) const override;
174  Model *m, const ParticleIndexes &pis) const override;
177  ;
178 };
179 
182 
183 /** This class is equivalent to, but faster than a
184  SphereDistancePairScore with a HarmonicLowerBound.
185 */
187  (double k,
188  std::string name = "SoftSpherePairScore%1%"),
190 
191 IMPCORE_END_NAMESPACE
192 
193 #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: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_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.