IMP logo
IMP Reference Guide  develop.7400db2aee,2024/11/23
The Integrative Modeling Platform
quad_predicates.h
Go to the documentation of this file.
1 // Autogenerated by ../../../../tmp/nightly-build-484/imp-20241123.develop.7400db2aee/tools/build/make_containers.py
2 // from ../../../../tmp/nightly-build-484/imp-20241123.develop.7400db2aee/tools/build/container_templates/core/classname_predicates.h
3 // Do not edit - any changes will be lost!
4 
5 /**
6  * \file IMP/core/quad_predicates.h
7  * \brief Define some predicates.
8  *
9  * Copyright 2007-2023 IMP Inventors. All rights reserved.
10  */
11 
12 #ifndef IMPCORE_QUAD_PREDICATES_H
13 #define IMPCORE_QUAD_PREDICATES_H
14 
15 #include <IMP/core/core_config.h>
16 #include <IMP/core/Typed.h>
17 #include <IMP/QuadPredicate.h>
18 #include <IMP/quad_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 ConstantQuadPredicate : public QuadPredicate {
28  int v_;
29 
30  friend class cereal::access;
31  template<class Archive> void serialize(Archive &ar) {
32  ar(cereal::base_class<QuadPredicate>(this), v_);
33  }
35 
36  public:
38  std::string name = "ConstQuadPredicate%1%");
39 
41 
42  virtual int get_value_index(Model *, const ParticleIndexQuad&) 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 UnorderedTypeQuadPredicate
60  : public QuadPredicate {
61  friend class cereal::access;
62  template<class Archive> void serialize(Archive &ar) {
63  ar(cereal::base_class<QuadPredicate>(this));
64  }
66 
67  public:
68  UnorderedTypeQuadPredicate(std::string name =
69  "UnorderedTypeQuadPredicate%1%");
70  virtual int get_value_index(Model *m, const ParticleIndexQuad& 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 OrderedTypeQuadPredicate : public QuadPredicate {
90  private:
91  mutable int const* cached_particle_type_ids_table_;
92  mutable int cached_n_particle_types_;
93  public:
94  OrderedTypeQuadPredicate(std::string name =
95  "OrderedTypeQuadPredicate%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 ParticleIndexQuad& 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 ParticleIndexQuad& 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 AllSameQuadPredicate : public QuadPredicate {
138  friend class cereal::access;
139  template<class Archive> void serialize(Archive &ar) {
140  ar(cereal::base_class<QuadPredicate>(this));
141  }
143 
144  public:
145  AllSameQuadPredicate(std::string name = "AllSameQuadPredicate%1%");
146  virtual int get_value_index(Model *m, const ParticleIndexQuad& 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 CoinFlipQuadPredicate : public QuadPredicate {
160  double p_;
161  mutable boost::random::uniform_real_distribution<double> rng_;
162 
163  public:
164  CoinFlipQuadPredicate(double p, std::string name =
165  "CoinFlipQuadPredicate%1%");
166  virtual int get_value_index(Model *, const ParticleIndexQuad&) 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_QUAD_PREDICATES_H */
Define QuadPredicate.
Abstract predicate function.
Definition: QuadPredicate.h:31
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 int get_value_index(Model *m, const ParticleIndexQuad &pi) const override
Compute the predicate for types of specific pi.
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const override
Overload this method to specify the inputs.
virtual int get_value_index_in_batch(Model *m, const ParticleIndexQuad &pi) const override
Macros for various classes.
virtual int get_value_index(Model *m, const ParticleIndexQuad &pi) const override
Compute the predicate and the derivative if needed.
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
Return a unique predicate value for each unordered set of ParticleTypes.
A more IMP-like version of the std::vector.
Definition: Vector.h:50
virtual int get_value_index(Model *, const ParticleIndexQuad &) const override
Compute the predicate and the derivative if needed.
A particle with a user-defined type.
Return a unique predicate value for each ordered set of ParticleTypes.
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition: base_types.h:106
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
virtual int get_value_index(Model *, const ParticleIndexQuad &) const override
Compute the predicate and the derivative if needed.
#define IMP_UNUSED(variable)
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
Definition: object_macros.h:95
int get_value(const core::ParticleTypes &types)
Compute the predicate for specified types.
virtual int get_value_index(Model *m, const ParticleIndexQuad &pi) const override
Compute the predicate and the derivative if needed.
Always return a constant value.
Return true (1) with a fixed probability.
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
#define IMP_QUAD_PREDICATE_METHODS(Name)
Define extra the functions needed for a QuadPredicate.
Definition: quad_macros.h:78
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const override
Overload this method to specify the inputs.
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const override
Overload this method to specify the inputs.
virtual void setup_for_get_value_index_in_batch(Model *m) const override
RandomNumberGenerator random_number_generator
A shared non-GPU random number generator.