IMP logo
IMP Reference Guide  2.20.1
The Integrative Modeling Platform
triplet_predicates.h
Go to the documentation of this file.
1 // Autogenerated by ../../../../tmp/nightly-build-8871/imp-2.20.1/tools/build/make_containers.py
2 // from ../../../../tmp/nightly-build-8871/imp-2.20.1/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 class IMPCOREEXPORT ConstantTripletPredicate : public TripletPredicate {
28  int v_;
29 
30  friend class cereal::access;
31  template<class Archive> void serialize(Archive &ar) {
32  ar(cereal::base_class<TripletPredicate>(this), v_);
33  }
35 
36  public:
38  std::string name = "ConstTripletPredicate%1%");
39 
41 
42  virtual int get_value_index(Model *, const ParticleIndexTriplet&) 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 UnorderedTypeTripletPredicate
60  : public TripletPredicate {
61  friend class cereal::access;
62  template<class Archive> void serialize(Archive &ar) {
63  ar(cereal::base_class<TripletPredicate>(this));
64  }
66 
67  public:
68  UnorderedTypeTripletPredicate(std::string name =
69  "UnorderedTypeTripletPredicate%1%");
70  virtual int get_value_index(Model *m, const ParticleIndexTriplet& 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 OrderedTypeTripletPredicate : public TripletPredicate {
90  private:
91  mutable int const* cached_particle_type_ids_table_;
92  mutable int cached_n_particle_types_;
93  public:
94  OrderedTypeTripletPredicate(std::string name =
95  "OrderedTypeTripletPredicate%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 ParticleIndexTriplet& 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 ParticleIndexTriplet& 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 AllSameTripletPredicate : public TripletPredicate {
138  friend class cereal::access;
139  template<class Archive> void serialize(Archive &ar) {
140  ar(cereal::base_class<TripletPredicate>(this));
141  }
143 
144  public:
145  AllSameTripletPredicate(std::string name = "AllSameTripletPredicate%1%");
146  virtual int get_value_index(Model *m, const ParticleIndexTriplet& 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 CoinFlipTripletPredicate : public TripletPredicate {
160  double p_;
161  mutable boost::uniform_real<double> rng_;
162 
163  public:
164  CoinFlipTripletPredicate(double p, std::string name =
165  "CoinFlipTripletPredicate%1%");
166  virtual int get_value_index(Model *, const ParticleIndexTriplet&) 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_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.
Always return a constant value.
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: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_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.
Return a unique predicate value for each ordered set of ParticleTypes.
#define IMP_UNUSED(variable)
Return true (1) if all members of the tuple are the same.
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.
Return true (1) with a fixed probability.
Return a unique predicate value for each unordered set of ParticleTypes.
RandomNumberGenerator random_number_generator
A shared non-GPU random number generator.