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,
bool all_indexes_checked=
false)
const override;
60 virtual double evaluate_indexes_scores(
62 unsigned int lower_bound,
unsigned int upper_bound,
63 std::vector<double> &score,
64 bool all_indexes_checked=
false)
const override;
66 virtual double evaluate_indexes_delta(
68 const std::vector<unsigned> &indexes,
69 std::vector<double> &score,
70 bool all_indexes_checked=
false)
const override;
76 template <
class DistanceScore>
80 unsigned int upper_bound,
bool)
const {
82 ds_.check_cache_valid(m);
83 for (
unsigned int i = lower_bound; i < upper_bound; ++i) {
84 ret += evaluate_index_with_cache(m, p[i], da);
89 template <
class DistanceScore>
91 DistancePairScoreWithCache<DistanceScore>::evaluate_indexes_scores(
93 unsigned int lower_bound,
unsigned int upper_bound,
94 std::vector<double> &score,
bool)
const {
96 ds_.check_cache_valid(m);
97 for (
unsigned int i = lower_bound; i < upper_bound; ++i) {
98 double s = evaluate_index_with_cache(m, p[i], da);
105 template <
class DistanceScore>
107 DistancePairScoreWithCache<DistanceScore>::evaluate_indexes_delta(
109 const std::vector<unsigned> &indexes, std::vector<double> &score,
112 ds_.check_cache_valid(m);
113 for (
unsigned it : indexes) {
114 double s = evaluate_index_with_cache(m, p[it], da);
115 ret = ret - score[it] + s;
121 template <
class DistanceScore>
122 inline double DistancePairScoreWithCache<DistanceScore>::evaluate_index(
123 Model *m,
const ParticleIndexPair &p,
124 DerivativeAccumulator *da)
const {
125 ds_.check_cache_valid(m);
126 return evaluate_index_with_cache(m, p, da);
129 template <
class DistanceScore>
131 DistancePairScoreWithCache<DistanceScore>::evaluate_index_with_cache(
132 Model *m,
const ParticleIndexPair &p,
133 DerivativeAccumulator *da)
const {
135 m->get_sphere(std::get<0>(p)).get_center()
136 - m->get_sphere(std::get<1>(p)).get_center();
137 double sq = delta.get_squared_magnitude();
138 if (ds_.get_is_trivially_zero_with_cache(m, p, sq)) {
141 double dist = std::sqrt(sq);
143 std::pair<double, double> sp = ds_.get_score_and_derivative_with_cache(
145 static const double MIN_DISTANCE = .00001;
147 if (dist > MIN_DISTANCE) {
150 uv = algebra::get_zero_vector_d<3>();
152 m->add_to_coordinate_derivatives(std::get<0>(p), uv * sp.second, *da);
153 m->add_to_coordinate_derivatives(std::get<1>(p), -uv * sp.second, *da);
156 return ds_.get_score_with_cache(m, p, dist);
160 template <
class DistanceScore>
162 DistancePairScoreWithCache<DistanceScore>::do_get_inputs(
163 Model *m,
const ParticleIndexes &pis)
const {
165 ret += ds_.get_inputs(m, pis);
170 IMPSCOREFUNCTOR_END_NAMESPACE
IMP::Vector< ParticleIndexPair, std::allocator< ParticleIndexPair > > ParticleIndexPairs
Abstract class for scoring object(s) of type ParticleIndexPair.
Macros for various classes.
#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.