IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
singleton_predicates.h
Go to the documentation of this file.
1// Autogenerated by tools/build/make_containers.py
2// from tools/build/container_templates/core/classname_predicates.h
3// Do not edit - any changes will be lost!
4
5/**
6 * \file IMP/core/singleton_predicates.h
7 * \brief Define some predicates.
8 *
9 * Copyright 2007-2023 IMP Inventors. All rights reserved.
10 */
11
12#ifndef IMPCORE_SINGLETON_PREDICATES_H
13#define IMPCORE_SINGLETON_PREDICATES_H
14
15#include <IMP/core/core_config.h>
16#include <IMP/core/Typed.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
24IMPCORE_BEGIN_NAMESPACE
25
26//! Always return a constant value.
27class IMPCOREEXPORT ConstantSingletonPredicate : public SingletonPredicate {
28 int v_;
29
30 friend class cereal::access;
31 template<class Archive> void serialize(Archive &ar) {
32 ar(cereal::base_class<SingletonPredicate>(this), v_);
33 }
34 IMP_OBJECT_SERIALIZE_DECL(ConstantSingletonPredicate);
35
36 public:
37 ConstantSingletonPredicate(int v,
38 std::string name = "ConstSingletonPredicate%1%");
39
40 ConstantSingletonPredicate() {}
41
42 virtual int get_value_index(Model *, ParticleIndex) const
43 override {
44 return v_;
45 }
47 Model *, const ParticleIndexes &) const override {
48 return ModelObjectsTemp();
49 }
51 IMP_OBJECT_METHODS(ConstantSingletonPredicate);
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 */
59class IMPCOREEXPORT UnorderedTypeSingletonPredicate
60 : public SingletonPredicate {
61 friend class cereal::access;
62 template<class Archive> void serialize(Archive &ar) {
63 ar(cereal::base_class<SingletonPredicate>(this));
64 }
65 IMP_OBJECT_SERIALIZE_DECL(UnorderedTypeSingletonPredicate);
66
67 public:
68 UnorderedTypeSingletonPredicate(std::string name =
69 "UnorderedTypeSingletonPredicate%1%");
70 virtual int get_value_index(Model *m, ParticleIndex pi) const
71 override {
72 return internal::get_type_hash(m, pi);
73 }
75 Model *m, const ParticleIndexes &pis) const override {
77 ret += IMP::get_particles(m, pis);
78 return ret;
79 }
81 IMP_OBJECT_METHODS(UnorderedTypeSingletonPredicate);
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 */
89class IMPCOREEXPORT OrderedTypeSingletonPredicate : public SingletonPredicate {
90 private:
91 mutable int const* cached_particle_type_ids_table_;
92 mutable int cached_n_particle_types_;
93 public:
94 OrderedTypeSingletonPredicate(std::string name =
95 "OrderedTypeSingletonPredicate%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, ParticleIndex 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.
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 {
129 ret += IMP::get_particles(m, pis);
130 return ret;
131 }
133 IMP_OBJECT_METHODS(OrderedTypeSingletonPredicate);
134};
135
136//! Return true (1) if all members of the tuple are the same.
137class IMPCOREEXPORT AllSameSingletonPredicate : public SingletonPredicate {
138 friend class cereal::access;
139 template<class Archive> void serialize(Archive &ar) {
140 ar(cereal::base_class<SingletonPredicate>(this));
141 }
142 IMP_OBJECT_SERIALIZE_DECL(AllSameSingletonPredicate);
143
144 public:
145 AllSameSingletonPredicate(std::string name = "AllSameSingletonPredicate%1%");
146 virtual int get_value_index(Model *m, ParticleIndex pi) const
147 override {
148 return internal::get_all_same(m, pi);
149 }
151 Model *, const ParticleIndexes &) const override {
152 return ModelObjectsTemp();
153 }
155 IMP_OBJECT_METHODS(AllSameSingletonPredicate);
156};
157
158//! Return true (1) with a fixed probability.
159class IMPCOREEXPORT CoinFlipSingletonPredicate : public SingletonPredicate {
160 double p_;
161 mutable boost::random::uniform_real_distribution<double> rng_;
162
163 public:
164 CoinFlipSingletonPredicate(double p, std::string name =
165 "CoinFlipSingletonPredicate%1%");
166 virtual int get_value_index(Model *, ParticleIndex) 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 }
178 IMP_OBJECT_METHODS(CoinFlipSingletonPredicate);
179};
180
181IMPCORE_END_NAMESPACE
182
183#endif /* IMPCORE_SINGLETON_PREDICATES_H */
Define SingletonPredicate.
A particle with a user-defined type.
static unsigned int get_number_unique()
Definition Key.h:258
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Return true (1) if all members of the tuple are the same.
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const override
Overload this method to specify the inputs.
virtual int get_value_index(Model *m, ParticleIndex pi) const override
Compute the predicate and the derivative if needed.
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 *, ParticleIndex) const override
Compute the predicate and the derivative if needed.
Always return a constant value.
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const override
Overload this method to specify the inputs.
virtual int get_value_index(Model *, ParticleIndex) const override
Compute the predicate and the derivative if needed.
Return a unique predicate value for each ordered set of ParticleTypes.
int get_value(const core::ParticleTypes &types)
Compute the predicate for specified types.
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
virtual void setup_for_get_value_index_in_batch(Model *m) const override
virtual int get_value_index(Model *m, ParticleIndex pi) const override
Compute the predicate for types of specific pi.
virtual int get_value_index_in_batch(Model *m, ParticleIndex pi) const override
Return a unique predicate value for each unordered set of ParticleTypes.
virtual int get_value_index(Model *m, ParticleIndex pi) const override
Compute the predicate and the derivative if needed.
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
IMP::Vector< ParticleType > ParticleTypes
Definition Typed.h:29
Index< ParticleIndexTag > ParticleIndex
Definition base_types.h:196
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Definition base_types.h:199
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition base_types.h:122
RandomNumberGenerator random_number_generator
A shared non-GPU random number generator.
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Macros for various classes.
#define IMP_SINGLETON_PREDICATE_METHODS(Name)
Define extra the functions needed for a SingletonPredicate.
#define IMP_UNUSED(variable)