8 #ifndef IMPSCORE_FUNCTOR_DISTANCE_PAIR_SCORE_WITH_CACHE_H
9 #define IMPSCORE_FUNCTOR_DISTANCE_PAIR_SCORE_WITH_CACHE_H
11 #include <IMP/score_functor/score_functor_config.h>
15 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
25 template <
class DistanceScoreT>
29 double evaluate_index_with_cache(
Model *m,
34 typedef DistanceScoreT DistanceScore;
38 std::string name =
"FunctorDistancePairScoreWithCache %1%")
41 virtual double evaluate_index(
Model *m,
55 virtual double evaluate_indexes(
60 virtual double evaluate_indexes_scores(
62 unsigned int lower_bound,
unsigned int upper_bound,
65 virtual double evaluate_indexes_delta(
67 const std::vector<unsigned> &indexes,
74 template <
class DistanceScore>
78 unsigned int upper_bound)
const {
80 ds_.check_cache_valid(m);
81 for (
unsigned int i = lower_bound; i < upper_bound; ++i) {
82 ret += evaluate_index_with_cache(m, p[i], da);
87 template <
class DistanceScore>
89 DistancePairScoreWithCache<DistanceScore>::evaluate_indexes_scores(
91 unsigned int lower_bound,
unsigned int upper_bound,
92 std::vector<double> &score)
const {
94 ds_.check_cache_valid(m);
95 for (
unsigned int i = lower_bound; i < upper_bound; ++i) {
96 double s = evaluate_index_with_cache(m, p[i], da);
103 template <
class DistanceScore>
105 DistancePairScoreWithCache<DistanceScore>::evaluate_indexes_delta(
107 const std::vector<unsigned> &indexes, std::vector<double> &score)
const {
109 ds_.check_cache_valid(m);
110 for (std::vector<unsigned>::const_iterator it = indexes.begin();
111 it != indexes.end(); ++it) {
112 double s = evaluate_index_with_cache(m, p[*it], da);
113 ret = ret - score[*it] + s;
119 template <
class DistanceScore>
120 inline double DistancePairScoreWithCache<DistanceScore>::evaluate_index(
121 Model *m,
const ParticleIndexPair &p,
122 DerivativeAccumulator *da)
const {
123 ds_.check_cache_valid(m);
124 return evaluate_index_with_cache(m, p, da);
127 template <
class DistanceScore>
129 DistancePairScoreWithCache<DistanceScore>::evaluate_index_with_cache(
130 Model *m,
const ParticleIndexPair &p,
131 DerivativeAccumulator *da)
const {
133 m->get_sphere(p[0]).get_center() - m->get_sphere(p[1]).get_center();
134 double sq = delta.get_squared_magnitude();
135 if (ds_.get_is_trivially_zero_with_cache(m, p, sq)) {
138 double dist = std::sqrt(sq);
140 std::pair<double, double> sp = ds_.get_score_and_derivative_with_cache(
142 static const double MIN_DISTANCE = .00001;
144 if (dist > MIN_DISTANCE) {
147 uv = algebra::get_zero_vector_d<3>();
149 m->add_to_coordinate_derivatives(p[0], uv * sp.second, *da);
150 m->add_to_coordinate_derivatives(p[1], -uv * sp.second, *da);
153 return ds_.get_score_with_cache(m, p, dist);
157 template <
class DistanceScore>
159 DistancePairScoreWithCache<DistanceScore>::do_get_inputs(
160 Model *m,
const ParticleIndexes &pis)
const {
162 ret += ds_.get_inputs(m, pis);
167 IMPSCOREFUNCTOR_END_NAMESPACE
Abstract class for scoring object(s) of type ParticleIndexPair.
Macros for various classes.
IMP::Vector< ParticleIndexPair > ParticleIndexPairs
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Create efficient distance-based pair scores, with cache.
A more IMP-like version of the std::vector.
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Class for storing model, its restraints, constraints, and particles.
DistanceScoreT & get_score_functor()
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for adding derivatives from restraints to the model.