IMP logo
IMP Reference Guide  2.19.0
The Integrative Modeling Platform
pair_predicates.h
Go to the documentation of this file.
1 // Autogenerated by ../../../../tmp/nightly-build-32402/imp-2.19.0/tools/build/make_containers.py
2 // from ../../../../tmp/nightly-build-32402/imp-2.19.0/tools/build/container_templates/core/classname_predicates.h
3 // Do not edit - any changes will be lost!
4 
5 /**
6  * \file IMP/core/pair_predicates.h
7  * \brief Define some predicates.
8  *
9  * Copyright 2007-2023 IMP Inventors. All rights reserved.
10  */
11 
12 #ifndef IMPCORE_PAIR_PREDICATES_H
13 #define IMPCORE_PAIR_PREDICATES_H
14 
15 #include <IMP/core/core_config.h>
16 #include <IMP/core/Typed.h>
17 #include <IMP/PairPredicate.h>
18 #include <IMP/pair_macros.h>
19 #include <boost/random.hpp>
20 #include "internal/container_helpers.h"
21 #include <cereal/access.hpp>
22 #include <cereal/types/base_class.hpp>
23 
24 IMPCORE_BEGIN_NAMESPACE
25 
26 /** Always return a constant value.
27  */
28 class IMPCOREEXPORT ConstantPairPredicate : public PairPredicate {
29  int v_;
30 
31  friend class cereal::access;
32  template<class Archive> void serialize(Archive &ar) {
33  ar(cereal::base_class<PairPredicate>(this), v_);
34  }
36 
37  public:
39  std::string name = "ConstPairPredicate%1%");
40 
42 
43  virtual int get_value_index(Model *, const ParticleIndexPair&) const
44  override {
45  return v_;
46  }
48  Model *, const ParticleIndexes &) const override {
49  return ModelObjectsTemp();
50  }
53 };
54 
55 /** Return a unique predicate value for each unordered set of
56  ParticleTypes
57  (see Typed).
58 */
59 
60 class IMPCOREEXPORT UnorderedTypePairPredicate
61  : public PairPredicate {
62  friend class cereal::access;
63  template<class Archive> void serialize(Archive &ar) {
64  ar(cereal::base_class<PairPredicate>(this));
65  }
67 
68  public:
69  UnorderedTypePairPredicate(std::string name =
70  "UnorderedTypePairPredicate%1%");
71  virtual int get_value_index(Model *m, const ParticleIndexPair& pi) const
72  override {
73  return internal::get_type_hash(m, pi);
74  }
76  Model *m, const ParticleIndexes &pis) const override {
77  ModelObjectsTemp ret;
78  ret += IMP::get_particles(m, pis);
79  return ret;
80  }
83 };
84 
85 /** Return a unique predicate value for each ordered pair of
86  ParticleTypes (see Typed).
87 */
88 class IMPCOREEXPORT OrderedTypePairPredicate : public PairPredicate {
89  private:
90  mutable int const* cached_particle_type_ids_table_;
91  mutable int cached_n_particle_types_;
92  public:
93  OrderedTypePairPredicate(std::string name =
94  "OrderedTypePairPredicate%1%");
95  //! Compute the predicate for specified types
96  int get_value(const core::ParticleTypes &types) {
97  return internal::get_ordered_type_hash(types);
98  }
99  //! Compute the predicate for types of specific pi
100  virtual int get_value_index(Model *m, const ParticleIndexPair& pi) const
101  override {
102  return internal::get_ordered_type_hash(m, pi);
103  }
104 
105  //! Setup for a batch of calls to get_value_index_in_batch()
106  //! (used for improving performance)
108  override{
109  cached_particle_type_ids_table_=
110  m->IMP::internal::IntAttributeTable::access_attribute_data(Typed::get_type_key());
111  cached_n_particle_types_= ParticleType::get_number_unique();
112  };
113 
114  //! Same as get_value_index, but with optimizations
115  //! for a batch of calls. Call setup_for_get_value_index_in_batch()
116  //! right before calling a batch of those, otherwise unexpected behavior.
117  virtual int get_value_index_in_batch(Model* m, const ParticleIndexPair& pi) const
118  override{
119  IMP_UNUSED(m);
120  return internal::get_ordered_type_hash( pi,
121  cached_particle_type_ids_table_,
122  cached_n_particle_types_);
123  }
124 
126  Model *m, const ParticleIndexes &pis) const override {
127  ModelObjectsTemp ret;
128  ret += IMP::get_particles(m, pis);
129  return ret;
130  }
133 };
134 
135 /** Return true if all members of the tuple are the same. */
136 class IMPCOREEXPORT AllSamePairPredicate : public PairPredicate {
137  friend class cereal::access;
138  template<class Archive> void serialize(Archive &ar) {
139  ar(cereal::base_class<PairPredicate>(this));
140  }
142 
143  public:
144  AllSamePairPredicate(std::string name = "AllSamePairPredicate%1%");
145  virtual int get_value_index(Model *m, const ParticleIndexPair& pi) const
146  override {
147  return internal::get_all_same(m, pi);
148  }
150  Model *, const ParticleIndexes &) const override {
151  return ModelObjectsTemp();
152  }
155 };
156 
157 /** Return true with a fixed probability. */
158 class IMPCOREEXPORT CoinFlipPairPredicate : public PairPredicate {
159  double p_;
160  mutable boost::uniform_real<double> rng_;
161 
162  public:
163  CoinFlipPairPredicate(double p, std::string name =
164  "CoinFlipPairPredicate%1%");
165  virtual int get_value_index(Model *, const ParticleIndexPair&) const
166  override {
167  if (rng_(random_number_generator) < p_)
168  return 1;
169  else
170  return 0;
171  }
173  Model *, const ParticleIndexes &) const override {
174  return ModelObjectsTemp();
175  }
178 };
179 
180 IMPCORE_END_NAMESPACE
181 
182 #endif /* IMPCORE_PAIR_PREDICATES_H */
virtual int get_value_index(Model *m, const ParticleIndexPair &pi) const override
Compute the predicate for types of specific pi.
Macros for various classes.
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const override
Overload this method to specify the inputs.
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
virtual int get_value_index(Model *m, const ParticleIndexPair &pi) const override
Compute the predicate and the derivative if needed.
A more IMP-like version of the std::vector.
Definition: Vector.h:42
A particle with a user-defined type.
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition: base_types.h:89
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
#define IMP_UNUSED(variable)
Define PairPredicate.
int get_value(const core::ParticleTypes &types)
Compute the predicate for specified types.
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
Definition: object_macros.h:95
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const override
Overload this method to specify the inputs.
virtual int get_value_index(Model *, const ParticleIndexPair &) const override
Compute the predicate and the derivative if needed.
virtual void setup_for_get_value_index_in_batch(Model *m) const override
Abstract predicate function.
Definition: PairPredicate.h:31
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const override
Overload this method to specify the inputs.
virtual int get_value_index(Model *, const ParticleIndexPair &) const override
Compute the predicate and the derivative if needed.
virtual int get_value_index_in_batch(Model *m, const ParticleIndexPair &pi) const override
virtual int get_value_index(Model *m, const ParticleIndexPair &pi) const override
Compute the predicate and the derivative if needed.
RandomNumberGenerator random_number_generator
A shared non-GPU random number generator.
#define IMP_PAIR_PREDICATE_METHODS(Name)
Define extra the functions needed for a PairPredicate.
Definition: pair_macros.h:78