IMP  2.2.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-2014 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 /** \see XYZR
30  \see SphereDistancePairScore
31  \see DistancePairScore
32  \see SoftSpherePairScore
33  */
34 IMP_FUNCTOR_DISTANCE_PAIR_SCORE(SphereDistancePairScore, SphereDistanceScore,
35  (UnaryFunction *uf,
36  std::string name =
37  "SphereDistancePairScore%1%"),
39 
42 
43 //!A harmonic upper bound on the distance between two spheres
44 /** \see XYZR
45  \see SpherePairScore
46  \see SoftSpherePairScore
47  */
50  HarmonicUpperBoundSphereDistanceScore,
51  (double x0, double k,
52  std::string name = "HarmonicUpperBoundSphereDistancePairScore%1%"),
55 
56 //!A harmonic upper bound on the diameter of the span of two spheres
57 /** This restraint restraints how far the furthest points of two spheres
58  are from one another.
59 
60  \see XYZR
61  \see SpherePairScore
62  \see SoftSpherePairScore
63  \see NormalizedSphereDistancePairScore
64  */
66  : public PairScore {
67  double x0_, k_;
68 
69  public:
70  HarmonicUpperBoundSphereDiameterPairScore(double d0, double k);
71  double get_rest_length() const { return x0_; }
72  double get_stiffness() const { return k_; }
74  DerivativeAccumulator *da) const IMP_OVERRIDE;
76  kernel::Model *m, const kernel::ParticleIndexes &pis) const;
79 };
80 
83 
86 
87 //!A harmonic score on the distance between two spheres
88 /** \see XYZR
89  \see SpherePairScore
90  \see SoftSpherePairScore
91  */
93  HarmonicSphereDistanceScore,
94  (double x0, double k,
95  std::string name =
96  "HarmonicSphereDistancePairScore%1%"),
99 
100 #ifndef IMP_DOXYGEN
101 inline double HarmonicUpperBoundSphereDiameterPairScore::evaluate_index(
103  DerivativeAccumulator *da) const {
104  algebra::Vector3D delta =
105  m->get_sphere(p[0]).get_center() - m->get_sphere(p[1]).get_center();
106  static const double MIN_DISTANCE = .00001;
107  double distance = delta.get_magnitude();
108  double shifted_distance = distance - x0_ + m->get_sphere(p[0]).get_radius() +
109  m->get_sphere(p[1]).get_radius();
110  if (shifted_distance < 0) return 0;
111  double score = .5 * k_ * square(shifted_distance);
112  if (da && distance > MIN_DISTANCE) {
113  double deriv = k_ * shifted_distance;
114  algebra::Vector3D uv = delta / distance;
115  m->add_to_coordinate_derivatives(p[0], uv * deriv, *da);
116  m->add_to_coordinate_derivatives(p[1], -uv * deriv, *da);
117  }
118  return score;
119 }
120 #endif
121 
122 //! A score on the normalized distance between the surfaces of two spheres
123 /** The distance between the surfaces of the two spheres is divided by the
124  smaller radius to normalize it.
125  \see SphereDistancePairScore
126  \see XYZR
127  \see DistancePairScore
128  */
129 class IMPCOREEXPORT NormalizedSphereDistancePairScore : public PairScore {
131  FloatKey radius_;
132 
133  public:
135  FloatKey radius = FloatKey("radius"));
136  virtual double evaluate_index(kernel::Model *m,
137  const kernel::ParticleIndexPair &p,
138  DerivativeAccumulator *da) const IMP_OVERRIDE;
140  kernel::Model *m, const kernel::ParticleIndexes &pis) const IMP_OVERRIDE;
143  ;
144 };
145 
146 //! A score on a weighted distance between the surfaces of two spheres
147 /** The distance between the surfaces of the two spheres is multiplied by
148  the sum of a specific attribute
149  \see SphereDistancePairScore
150  \see XYZR
151  \see DistancePairScore
152  */
153 class IMPCOREEXPORT WeightedSphereDistancePairScore : public PairScore {
155  FloatKey radius_;
156  FloatKey weight_;
157 
158  public:
160  FloatKey radius = FloatKey("radius"));
161  virtual double evaluate_index(kernel::Model *m,
162  const kernel::ParticleIndexPair &p,
163  DerivativeAccumulator *da) const IMP_OVERRIDE;
165  kernel::Model *m, const kernel::ParticleIndexes &pis) const IMP_OVERRIDE;
168  ;
169 };
170 
173 
174 /** This class is equivalent to, but faster than a
175  SphereDistancePairScore with a HarmonicLowerBound.
176 */
178  (double k,
179  std::string name = "SoftSpherePairScore%1%"),
181 
182 IMPCORE_END_NAMESPACE
183 
184 #endif /* IMPCORE_SPHERE_DISTANCE_PAIR_SCORE_H */
Various important macros for implementing decorators.
A harmonic upper bound on the distance between two spheres.
Class for adding derivatives from restraints to the model.
A Score on the distance between a pair of particles.
A smart pointer to a ref-counted Object that is a class memeber.
Definition: base/Pointer.h:147
IMP::kernel::UnaryFunction UnaryFunction
#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.
#define IMP_PAIR_SCORE_METHODS(Name)
A Score on the distance between a pair of particles.
virtual double evaluate_index(kernel::Model *m, const kernel::ParticleIndexPair &vt, DerivativeAccumulator *da) const
Compute the score and the derivative if needed.
Abstract single variable functor class for score functions.
A class to store an fixed array of same-typed values.
Definition: base/Array.h:33
A Score on the distance between a pair of particles.
Abstract score function.
virtual ModelObjectsTemp do_get_inputs(kernel::Model *m, const ParticleIndexes &pis) const
A Score on the distance between a pair of particles.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
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 sets of objects.
VectorD< 3 > Vector3D
Definition: VectorD.h:395
Decorator for a sphere-like particle.
A score on the normalized distance between the surfaces of two spheres.
Key< 0, true > FloatKey
The type used to identify float attributes in the Particles.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:72