IMP logo
DistancePairScore.h
Go to the documentation of this file.
1 /**
2  * \file DistancePairScore.h
3  * \brief A Score on the distance between a pair of particles.
4  *
5  * Copyright 2007-2012 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPCORE_DISTANCE_PAIR_SCORE_H
9 #define IMPCORE_DISTANCE_PAIR_SCORE_H
10 
11 #include "core_config.h"
12 #include "XYZ.h"
13 #include <IMP/generic.h>
14 #include <IMP/PairScore.h>
15 #include <IMP/UnaryFunction.h>
16 #include <IMP/Pointer.h>
17 
18 IMPCORE_BEGIN_NAMESPACE
19 
20 //! Apply a function to the distance between two particles.
21 /** \see SphereDistancePairScore
22  \see HarmonicDistancePairScore
23 */
24 class IMPCOREEXPORT DistancePairScore : public PairScore
25 {
27 public:
29  std::string name="DistancePairScore %1%");
30  UnaryFunction *get_unary_function() const {return f_;}
32 };
33 
34 IMP_OBJECTS(DistancePairScore, DistancePairScores);
35 
36 /** This class is significantly faster than using a DistancePairScore
37  with a Harmonic.
38 */
39 class IMPCOREEXPORT HarmonicDistancePairScore: public PairScore
40 {
41  const double x0_, k_;
42 public:
43  HarmonicDistancePairScore(double x0, double k,
44  std::string name="HarmonicDistancePairScore %1%");
45  double get_rest_length() const {
46  return x0_;
47  }
48  double get_stiffness() const {
49  return k_;
50  }
52 };
53 
54 IMP_OBJECTS(HarmonicDistancePairScore, HarmonicDistancePairScores);
55 
56 
57 #ifndef IMP_DOXYGEN
58 inline double HarmonicDistancePairScore
59 ::evaluate_index(Model *m,
60  const ParticleIndexPair &p,
61  DerivativeAccumulator *da) const {
63  IMP_LOG(VERBOSE, "Evaluating distance between "
64  << m->get_particle(p[0])->get_name()
65  << " and " << m->get_particle(p[1])->get_name()
66  << " at " << m->get_sphere(p[0])
67  << " and " << m->get_sphere(p[1]) << std::endl);
68  algebra::Vector3D delta=m->get_sphere(p[0]).get_center()
69  - m->get_sphere(p[1]).get_center();
70  static const double MIN_DISTANCE = .00001;
71  double distance2= delta.get_squared_magnitude();
72  double distance=std::sqrt(distance2);
73  double shifted_distance = distance- x0_;
74  double score= .5*k_*square(shifted_distance);
75  if (da && distance > MIN_DISTANCE) {
76  double deriv= k_*shifted_distance;
77  algebra::Vector3D uv= delta/distance;
78  m->add_to_coordinate_derivatives(p[0], uv*deriv, *da);
79  m->add_to_coordinate_derivatives(p[1], -uv*deriv, *da);
80  }
81 
82  return score;
83 }
84 #endif
85 
86 IMPCORE_END_NAMESPACE
87 
88 #endif /* IMPCORE_DISTANCE_PAIR_SCORE_H */

Generated on Tue May 22 2012 23:33:13 for IMP by doxygen 1.8.1