IMP logo
IMP Reference Guide  develop.e004443c3b,2024/04/25
The Integrative Modeling Platform
pair_predicates.h
Go to the documentation of this file.
1 // Autogenerated by ../../../../tmp/nightly-build-97066/imp-20240425.develop.e004443c3b/tools/build/make_containers.py
2 // from ../../../../tmp/nightly-build-97066/imp-20240425.develop.e004443c3b/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 class IMPCOREEXPORT ConstantPairPredicate : public PairPredicate {
28  int v_;
29 
30  friend class cereal::access;
31  template<class Archive> void serialize(Archive &ar) {
32  ar(cereal::base_class<PairPredicate>(this), v_);
33  }
35 
36  public:
38  std::string name = "ConstPairPredicate%1%");
39 
41 
42  virtual int get_value_index(Model *, const ParticleIndexPair&) const
43  override {
44  return v_;
45  }
47  Model *, const ParticleIndexes &) const override {
48  return ModelObjectsTemp();
49  }
52 };
53 
54 //! Return a unique predicate value for each unordered set of ParticleTypes
55 /** When applied to a set of particles that are decorated with the
56  Typed decorator, this returns a value that is a function of all of
57  the types. The order of the particles does not matter.
58  */
59 class IMPCOREEXPORT UnorderedTypePairPredicate
60  : public PairPredicate {
61  friend class cereal::access;
62  template<class Archive> void serialize(Archive &ar) {
63  ar(cereal::base_class<PairPredicate>(this));
64  }
66 
67  public:
68  UnorderedTypePairPredicate(std::string name =
69  "UnorderedTypePairPredicate%1%");
70  virtual int get_value_index(Model *m, const ParticleIndexPair& pi) const
71  override {
72  return internal::get_type_hash(m, pi);
73  }
75  Model *m, const ParticleIndexes &pis) const override {
76  ModelObjectsTemp ret;
77  ret += IMP::get_particles(m, pis);
78  return ret;
79  }
82 };
83 
84 //! Return a unique predicate value for each ordered set of ParticleTypes
85 /** When applied to a set of particles that are decorated with the
86  Typed decorator, this returns a value that is a function of all of
87  the types. The order of the particles matters.
88  */
89 class IMPCOREEXPORT OrderedTypePairPredicate : public PairPredicate {
90  private:
91  mutable int const* cached_particle_type_ids_table_;
92  mutable int cached_n_particle_types_;
93  public:
94  OrderedTypePairPredicate(std::string name =
95  "OrderedTypePairPredicate%1%");
96  //! Compute the predicate for specified types
97  int get_value(const core::ParticleTypes &types) {
98  return internal::get_ordered_type_hash(types);
99  }
100  //! Compute the predicate for types of specific pi
101  virtual int get_value_index(Model *m, const ParticleIndexPair& pi) const
102  override {
103  return internal::get_ordered_type_hash(m, pi);
104  }
105 
106  //! Setup for a batch of calls to get_value_index_in_batch()
107  //! (used for improving performance)
109  override{
110  cached_particle_type_ids_table_=
111  m->IMP::internal::IntAttributeTable::access_attribute_data(Typed::get_type_key());
112  cached_n_particle_types_= ParticleType::get_number_unique();
113  };
114 
115  //! Same as get_value_index, but with optimizations
116  //! for a batch of calls. Call setup_for_get_value_index_in_batch()
117  //! right before calling a batch of those, otherwise unexpected behavior.
118  virtual int get_value_index_in_batch(Model* m, const ParticleIndexPair& pi) const
119  override{
120  IMP_UNUSED(m);
121  return internal::get_ordered_type_hash( pi,
122  cached_particle_type_ids_table_,
123  cached_n_particle_types_);
124  }
125 
127  Model *m, const ParticleIndexes &pis) const override {
128  ModelObjectsTemp ret;
129  ret += IMP::get_particles(m, pis);
130  return ret;
131  }
134 };
135 
136 //! Return true (1) if all members of the tuple are the same.
137 class IMPCOREEXPORT AllSamePairPredicate : public PairPredicate {
138  friend class cereal::access;
139  template<class Archive> void serialize(Archive &ar) {
140  ar(cereal::base_class<PairPredicate>(this));
141  }
143 
144  public:
145  AllSamePairPredicate(std::string name = "AllSamePairPredicate%1%");
146  virtual int get_value_index(Model *m, const ParticleIndexPair& pi) const
147  override {
148  return internal::get_all_same(m, pi);
149  }
151  Model *, const ParticleIndexes &) const override {
152  return ModelObjectsTemp();
153  }
156 };
157 
158 //! Return true (1) with a fixed probability.
159 class IMPCOREEXPORT CoinFlipPairPredicate : public PairPredicate {
160  double p_;
161  mutable boost::uniform_real<double> rng_;
162 
163  public:
164  CoinFlipPairPredicate(double p, std::string name =
165  "CoinFlipPairPredicate%1%");
166  virtual int get_value_index(Model *, const ParticleIndexPair&) const
167  override {
168  if (rng_(random_number_generator) < p_)
169  return 1;
170  else
171  return 0;
172  }
174  Model *, const ParticleIndexes &) const override {
175  return ModelObjectsTemp();
176  }
179 };
180 
181 IMPCORE_END_NAMESPACE
182 
183 #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.
Return a unique predicate value for each ordered set of ParticleTypes.
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.
Return true (1) if all members of the tuple are the same.
#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:50
A particle with a user-defined type.
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition: base_types.h:106
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
Return true (1) with a fixed probability.
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.
Return a unique predicate value for each unordered set of ParticleTypes.
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
Always return a constant value.
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