IMP logo
IMP Reference Guide  2.19.0
The Integrative Modeling Platform
triplet_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/triplet_predicates.h
7  * \brief Define some predicates.
8  *
9  * Copyright 2007-2023 IMP Inventors. All rights reserved.
10  */
11 
12 #ifndef IMPCORE_TRIPLET_PREDICATES_H
13 #define IMPCORE_TRIPLET_PREDICATES_H
14 
15 #include <IMP/core/core_config.h>
16 #include <IMP/core/Typed.h>
17 #include <IMP/TripletPredicate.h>
18 #include <IMP/triplet_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 ConstantTripletPredicate : public TripletPredicate {
29  int v_;
30 
31  friend class cereal::access;
32  template<class Archive> void serialize(Archive &ar) {
33  ar(cereal::base_class<TripletPredicate>(this), v_);
34  }
36 
37  public:
39  std::string name = "ConstTripletPredicate%1%");
40 
42 
43  virtual int get_value_index(Model *, const ParticleIndexTriplet&) 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 UnorderedTypeTripletPredicate
61  : public TripletPredicate {
62  friend class cereal::access;
63  template<class Archive> void serialize(Archive &ar) {
64  ar(cereal::base_class<TripletPredicate>(this));
65  }
67 
68  public:
69  UnorderedTypeTripletPredicate(std::string name =
70  "UnorderedTypeTripletPredicate%1%");
71  virtual int get_value_index(Model *m, const ParticleIndexTriplet& 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 triplet of
86  ParticleTypes (see Typed).
87 */
88 class IMPCOREEXPORT OrderedTypeTripletPredicate : public TripletPredicate {
89  private:
90  mutable int const* cached_particle_type_ids_table_;
91  mutable int cached_n_particle_types_;
92  public:
93  OrderedTypeTripletPredicate(std::string name =
94  "OrderedTypeTripletPredicate%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 ParticleIndexTriplet& 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 ParticleIndexTriplet& 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 AllSameTripletPredicate : public TripletPredicate {
137  friend class cereal::access;
138  template<class Archive> void serialize(Archive &ar) {
139  ar(cereal::base_class<TripletPredicate>(this));
140  }
142 
143  public:
144  AllSameTripletPredicate(std::string name = "AllSameTripletPredicate%1%");
145  virtual int get_value_index(Model *m, const ParticleIndexTriplet& 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 CoinFlipTripletPredicate : public TripletPredicate {
159  double p_;
160  mutable boost::uniform_real<double> rng_;
161 
162  public:
163  CoinFlipTripletPredicate(double p, std::string name =
164  "CoinFlipTripletPredicate%1%");
165  virtual int get_value_index(Model *, const ParticleIndexTriplet&) 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_TRIPLET_PREDICATES_H */
#define IMP_TRIPLET_PREDICATE_METHODS(Name)
Define extra the functions needed for a TripletPredicate.
virtual void setup_for_get_value_index_in_batch(Model *m) const override
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const override
Overload this method to specify the inputs.
A class to store a fixed array of same-typed values.
Definition: Array.h:35
Macros for various classes.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Define TripletPredicate.
virtual int get_value_index(Model *m, const ParticleIndexTriplet &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.
virtual int get_value_index(Model *m, const ParticleIndexTriplet &pi) const override
Compute the predicate for types of specific pi.
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
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
virtual int get_value_index_in_batch(Model *m, const ParticleIndexTriplet &pi) const override
Abstract predicate function.
int get_value(const core::ParticleTypes &types)
Compute the predicate for specified types.
virtual int get_value_index(Model *m, const ParticleIndexTriplet &pi) const override
Compute the predicate and the derivative if needed.
#define IMP_UNUSED(variable)
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
Definition: object_macros.h:95
virtual int get_value_index(Model *, const ParticleIndexTriplet &) const override
Compute the predicate and the derivative if needed.
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 int get_value_index(Model *, const ParticleIndexTriplet &) const override
Compute the predicate and the derivative if needed.
RandomNumberGenerator random_number_generator
A shared non-GPU random number generator.