IMP logo
IMP Reference Guide  2.10.0
The Integrative Modeling Platform
PredicatePairsRestraint.h
Go to the documentation of this file.
1 // Autogenerated by ../../../../tmp/nightly-build-36368/imp-2.10.0/tools/build/make_containers.py
2 // from ../../../../tmp/nightly-build-36368/imp-2.10.0/tools/build/container_templates/container/PredicateClassnamesRestraint.h
3 // Do not edit - any changes will be lost!
4 
5 /**
6  * \file IMP/container/PredicatePairsRestraint.h
7  * \brief Apply a PairScore to each Pair in a list.
8  *
9  * Copyright 2007-2018 IMP Inventors. All rights reserved.
10  *
11  */
12 
13 #ifndef IMPCONTAINER_PREDICATE_PAIRS_RESTRAINT_H
14 #define IMPCONTAINER_PREDICATE_PAIRS_RESTRAINT_H
15 
16 #include <IMP/container/container_config.h>
17 #include <IMP/PairPredicate.h>
18 #include "generic.h"
19 
20 
21 #if IMP_CONTAINER_HAS_ROBIN_MAP==1
22 #define IMP_CONTAINER_PREDICATE_USE_ROBIN_MAP
23 #include <tsl/robin_map.h>
24 #elif IMP_CONTAINER_HAS_GOOGLE_DENSE_HASH_MAP==1
25 #define IMP_CONTAINER_PREDICATE_USE_GOOGLE_DENSE_HASH_MAP
26 #include <google/dense_hash_map>
27 #else
28 #define IMP_CONTAINER_PREDICATE_USE_KERNEL_MAP
29 #include <IMP/set_map_macros.h>
30 //#include <boost/unordered_map.hpp>
31 #endif
32 
33 #include <iostream>
34 
35 
36 IMPCONTAINER_BEGIN_NAMESPACE
37 
38 //! Applies a PairScore to each Pair in a list based on a predicate
39 /** This restraint uses a passed predicate to choose which score to apply
40  to each tuple in the input container. The selections are cached, making it
41  substantially faster than using a core::TypedPairScore.
42 
43  \note The ordering of particles within a tuple may vary depending on the
44  input container used. You may need to call set_score() with several
45  different predicate values for different orderings.
46 */
47 class IMPCONTAINEREXPORT PredicatePairsRestraint : public Restraint {
50 #if IMP_CONTAINER_HAS_ROBIN_MAP==1
51  typedef tsl::robin_map<int, ParticleIndexPairs> t_lists_map;
52  typedef tsl::robin_map<int, PointerMember<PairScore> > t_score_map;
53 #elif IMP_CONTAINER_HAS_GOOGLE_DENSE_HASH_MAP==1
54  typedef google::dense_hash_map<int, ParticleIndexPairs> t_lists_map;
55  typedef google::dense_hash_map<int, PointerMember<PairScore> > t_score_map;
56 #else
57  typedef IMP_KERNEL_LARGE_UNORDERED_MAP<int, ParticleIndexPairs> t_lists_map;
58  typedef IMP_KERNEL_LARGE_UNORDERED_MAP<int, PointerMember<PairScore> > t_score_map;
59 #endif
60  mutable t_lists_map lists_;
61  t_score_map scores_;
62 
63  bool is_get_inputs_ignores_individual_scores_;
64  mutable std::size_t input_version_;
65  // bool is_unknown_score_set_;
66  bool error_on_unknown_;
67  PointerMember<PairScore> unknown_score_;
68  // void update_lists_with_item(ParticleIndexPair const &it) const;
69  void update_lists_if_necessary() const;
70 
71  public:
74  std::string name =
75  "PredicatePairsRestraint %1%");
76 
77  /** Apply the passed score to all pairs whose predicate values match
78  the passed value.*/
79  void set_score(int predicate_value, PairScore *score);
80 
81  /** Apply this score to any pair whose predicate value does not match
82  one passed to set_score().*/
83  void set_unknown_score(PairScore *score);
84 
85  /** By default, it is an error if the predicate returns a value that is
86  not known. If this is false, then they are silently skipped even
87  if set_unknown_score() was not called.
88  */
89  void set_is_complete(bool tf) { error_on_unknown_ = tf; }
90 
91  /** return the indexes of all particles for a given predicate value.*/
92  ParticleIndexPairs get_indexes(int predicate_value) const {
93  return lists_.find(predicate_value)->second;
94  }
95 
96  public:
100 
101 #ifndef SWIG
102  //! use at own risk - for efficiency in case e.g. all scores use same inputs
103  //! If true, do_get_inputs() includes all inputs in input container
104  //! but not individual inputs from individual scores
106  is_get_inputs_ignores_individual_scores_= is_ignore;
107  }
108 #endif
110 
111  private:
112  /**
113  Returns the score for specified predicate based on set_score()
114 
115  Unknown scores:
116  If predicate was not added with set_score(), return the default unknown score
117  set by set_unknown_score() if applicable. If not, then if set_is_complete(false)
118  was called, return nullptr. Otherwise, undefined behavior (will fail when checks
119  are on)
120  */
121  inline PairScore*
122  get_score_for_predicate(int predicate) const;
123 
124 
126 };
127 
128 
129 #ifndef SWIG
130 PairScore*
131 PredicatePairsRestraint::get_score_for_predicate
132 (int predicate) const
133 {
134  PairScore* score;
135  t_score_map::const_iterator it= scores_.find(predicate);
136  if(it!=scores_.end()){
137  score= it->second;
138  } else {
139  IMP_USAGE_CHECK(!error_on_unknown_, // is_unknown_score_set_,
140  "unknown interaction type cannot be scored when error_on_unknown is true");
141  score = unknown_score_;
142  }
143  return score;
144 }
145 #endif
146 
147 
148 IMPCONTAINER_END_NAMESPACE
149 
150 #endif /* IMPCONTAINER_PREDICATE_PAIRS_RESTRAINT_H */
Abstract class for scoring object(s) of type ParticleIndexPair.
Definition: PairScore.h:37
Various important functionality for implementing decorators.
void set_is_get_inputs_ignores_individual_scores(bool is_ignore)
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
virtual void do_add_score_and_derivatives(ScoreAccumulator sa) const
A restraint should override this to compute the score and derivatives.
Applies a PairScore to each Pair in a list based on a predicate.
Macros to choose the best set or map for different purposes.
virtual Restraints do_create_current_decomposition() const
Definition: Restraint.h:235
Define PairPredicate.
A smart pointer to a ref-counted Object that is a class member.
Definition: Pointer.h:146
Class for adding up scores during ScoringFunction evaluation.
Abstract predicate function.
Definition: PairPredicate.h:31
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
ParticleIndexPairs get_indexes(int predicate_value) const
virtual ModelObjectsTemp do_get_inputs() const =0
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
A restraint is a term in an IMP ScoringFunction.
Definition: Restraint.h:54