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(
58 unsigned int upper_bound)
const override;
60 virtual double evaluate_indexes_scores(
62 unsigned int lower_bound,
unsigned int upper_bound,
63 std::vector<double> &score)
const override;
65 virtual double evaluate_indexes_delta(
67 const std::vector<unsigned> &indexes,
68 std::vector<double> &score)
const override;
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 (
unsigned it : indexes) {
111 double s = evaluate_index_with_cache(m, p[it], da);
112 ret = ret - score[it] + s;
118 template <
class DistanceScore>
119 inline double DistancePairScoreWithCache<DistanceScore>::evaluate_index(
120 Model *m,
const ParticleIndexPair &p,
121 DerivativeAccumulator *da)
const {
122 ds_.check_cache_valid(m);
123 return evaluate_index_with_cache(m, p, da);
126 template <
class DistanceScore>
128 DistancePairScoreWithCache<DistanceScore>::evaluate_index_with_cache(
129 Model *m,
const ParticleIndexPair &p,
130 DerivativeAccumulator *da)
const {
132 m->get_sphere(p[0]).get_center() - m->get_sphere(p[1]).get_center();
133 double sq = delta.get_squared_magnitude();
134 if (ds_.get_is_trivially_zero_with_cache(m, p, sq)) {
137 double dist = std::sqrt(sq);
139 std::pair<double, double> sp = ds_.get_score_and_derivative_with_cache(
141 static const double MIN_DISTANCE = .00001;
143 if (dist > MIN_DISTANCE) {
146 uv = algebra::get_zero_vector_d<3>();
148 m->add_to_coordinate_derivatives(p[0], uv * sp.second, *da);
149 m->add_to_coordinate_derivatives(p[1], -uv * sp.second, *da);
152 return ds_.get_score_with_cache(m, p, dist);
156 template <
class DistanceScore>
158 DistancePairScoreWithCache<DistanceScore>::do_get_inputs(
159 Model *m,
const ParticleIndexes &pis)
const {
161 ret += ds_.get_inputs(m, pis);
166 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()
Class for adding derivatives from restraints to the model.