9 #ifndef IMPDOMINO_SUBSET_SCORES_H
10 #define IMPDOMINO_SUBSET_SCORES_H
23 #if IMP_DOMINO_HAS_RMF
24 #include <RMF/HDF5/Group.h>
28 IMPDOMINO_BEGIN_NAMESPACE
38 IMP_NAMED_TUPLE_2(Key,
Keys, WeakPointer<Restraint>, restraint,
41 OwnerPointer<ScoringFunction>,
42 scoring_function,
Subset, subset,
double, max,);
44 Slice, slice, WeakPointer<Restraint>, restraint,);
52 OwnerPointer<ParticleStatesTable> pst_;
55 typedef double result_type;
56 typedef Key argument_type;
57 template <
class Cache>
58 result_type operator()(
const argument_type&k,
const Cache &cache)
const {
59 RMap::const_iterator it= rmap_.find(k.get_restraint());
60 if (it != rmap_.end()) {
61 Subset s= rmap_.find(k.get_restraint())->second.get_subset();
66 e= it->second.get_scoring_function()->evaluate_if_below(
false,
67 it->second.get_max());
70 <<
" evaluated to " << e <<
" on " << k.get_assignment()
71 <<
" vs " << it->second.get_max() << std::endl);
73 if (e > it->second.get_max()) e= std::numeric_limits<double>::max();
76 SMap::const_iterator it= sets_.find(k.get_restraint());
78 "Restraint set " << Showable(k.get_restraint())
81 for (
unsigned int i=0; i< it->second.get_members().size(); ++i) {
83 .get_slice().get_sliced(k.get_assignment());
84 double score= cache.get(argument_type(it->second.get_members()[i]
85 .get_restraint(), cur));
86 total+=score*k.get_restraint()->get_weight();
87 if (total >= it->second.get_max()) {
92 <<
" evaluated to " << total <<
" on " << k.get_assignment()
93 <<
" with max " << it->second.get_max() << std::endl);
94 if (total>= it->second.get_max()) {
95 return std::numeric_limits<double>::max();
102 Slice slice,
double max) {
104 "don't pass restraint sets here as second arg");
105 sets_[rs].access_members().push_back(RestraintSetData(slice, r));
106 sets_[rs].set_max(max);
110 "don't pass restraint sets here");
111 if (rmap_.find(e) == rmap_.end()) {
115 "Subsets don't match on restraint update");
116 rmap_[e].set_max( std::min(rmap_[e].get_max(), max));
122 void show_restraint_information(std::ostream &out)
const;
124 struct ApproximatelyEqual {
125 bool operator()(
double a,
double b)
const {
126 return std::abs(a-b) < .1*(a+b)+.1;
130 void add_restraint_internal(
Restraint *r,
135 const DepMap &dependencies);
136 void add_restraint_set_child_internal(
Restraint *r,
145 const DepMap &dependencies);
147 const DepMap &dependencies)
const;
155 unsigned int next_index_;
158 unsigned int size=std::numeric_limits<unsigned int>::max());
172 double s= cache_.get(Key(r, a));
190 const Subsets&exclusions)
const;
194 #if IMP_DOMINO_HAS_RMF || defined(IMP_DOXYGEN)
203 void save_cache(
const ParticlesTemp &particle_ordering,
204 const RestraintsTemp &restraints,
205 RMF::HDF5::Group group,
206 unsigned int max_entries);
207 void load_cache(
const ParticlesTemp &ps,
208 RMF::HDF5::ConstGroup group);
216 return cache_.size();
220 void validate()
const;
223 void show_restraint_information(std::ostream &out=std::cout)
const;
224 double get_hit_rate()
const {
225 return cache_.get_hit_rate();
228 out <<
"size=" << cache_.size() << std::endl;,);
232 IMPDOMINO_END_NAMESPACE