home
about
news
download
doc
source
systems
tests
bugs
contact
IMP Reference Guide
develop.8bf871cb5d,2024/11/14
The Integrative Modeling Platform
IMP Manual
Reference Guide
Tutorial Index
Modules
Classes
Examples
include
IMP
version 20241114.develop.8bf871cb5d
singleton_macros.h
Go to the documentation of this file.
1
// Autogenerated by ../../../../tmp/nightly-build-366/imp-20241114.develop.8bf871cb5d/tools/build/make_containers.py
2
// from ../../../../tmp/nightly-build-366/imp-20241114.develop.8bf871cb5d/tools/build/container_templates/kernel/classname_macros.h
3
// Do not edit - any changes will be lost!
4
5
/**
6
* \file IMP/singleton_macros.h
7
* \brief Macros for various classes.
8
*
9
* Copyright 2007-2022 IMP Inventors. All rights reserved.
10
*/
11
12
#ifndef IMPKERNEL_SINGLETON_MACROS_H
13
#define IMPKERNEL_SINGLETON_MACROS_H
14
15
#include "internal/TupleRestraint.h"
16
#include "internal/functors.h"
17
#include "
container_macros.h
"
18
#include <
IMP/object_macros.h
>
19
#include <algorithm>
20
21
/** Define
22
- IMP::SingletonScore::evaluate_indexes()
23
- IMP::SingletonScore::evaluate_if_good_indexes()
24
*/
25
#define IMP_SINGLETON_SCORE_METHODS(Name) \
26
double evaluate_indexes(Model *m, const ParticleIndexes &p, \
27
DerivativeAccumulator *da, unsigned int lower_bound, \
28
unsigned int upper_bound) \
29
const override final { \
30
double ret = 0; \
31
for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
32
ret += evaluate_index(m, p[i], da); \
33
} \
34
return ret; \
35
} \
36
double evaluate_indexes_scores( \
37
Model *m, const ParticleIndexes &p, \
38
DerivativeAccumulator *da, unsigned int lower_bound, \
39
unsigned int upper_bound, \
40
std::vector<double> &score) \
41
const override final { \
42
double ret = 0; \
43
for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
44
double s = evaluate_index(m, p[i], da); \
45
score[i] = s; \
46
ret += s; \
47
} \
48
return ret; \
49
} \
50
double evaluate_indexes_delta( \
51
Model *m, const ParticleIndexes &p, \
52
DerivativeAccumulator *da, \
53
const std::vector<unsigned> &indexes, \
54
std::vector<double> &score) \
55
const override final { \
56
double ret = 0; \
57
for (std::vector<unsigned>::const_iterator it = indexes.begin(); \
58
it != indexes.end(); ++it) { \
59
double s = evaluate_index(m, p[*it], da); \
60
ret = ret - score[*it] + s; \
61
score[*it] = s; \
62
} \
63
return ret; \
64
} \
65
double evaluate_if_good_indexes( \
66
Model *m, const ParticleIndexes &p, DerivativeAccumulator *da, \
67
double max, unsigned int lower_bound, \
68
unsigned int upper_bound) const override { \
69
double ret = 0; \
70
for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
71
ret += evaluate_if_good_index(m, p[i], da, max - ret); \
72
if (ret > max) return std::numeric_limits<double>::max(); \
73
} \
74
return ret; \
75
}
76
77
//! Define extra the functions needed for a SingletonPredicate
78
#define IMP_SINGLETON_PREDICATE_METHODS(Name) \
79
int get_value(Particle* a) const { \
80
return get_value_index(IMP::internal::get_model(a), \
81
IMP::internal::get_index(a)); \
82
} \
83
Ints get_value(const ParticlesTemp &o) const { \
84
Ints ret(o.size()); \
85
for (unsigned int i = 0; i < o.size(); ++i) { \
86
ret[i] += Name::get_value(o[i]); \
87
} \
88
return ret; \
89
} \
90
Ints get_value_index(Model *m, const ParticleIndexes &o) const override { \
91
Ints ret(o.size()); \
92
for (unsigned int i = 0; i < o.size(); ++i) { \
93
ret[i] += Name::get_value_index(m, o[i]); \
94
} \
95
return ret; \
96
} \
97
IMP_IMPLEMENT_INLINE_NO_SWIG( \
98
void remove_if_equal(Model *m, ParticleIndexes &ps, \
99
int value) const, \
100
{ \
101
ps.erase( \
102
std::remove_if(ps.begin(), ps.end(), \
103
IMP::internal::PredicateEquals<Name, true>( \
104
this, m, value)), \
105
ps.end()); \
106
}); \
107
IMP_IMPLEMENT_INLINE_NO_SWIG(void remove_if_not_equal(Model *m, \
108
ParticleIndexes &ps, \
109
int value) const, \
110
{ \
111
ps.erase( \
112
std::remove_if(ps.begin(), ps.end(), \
113
IMP::internal::PredicateEquals<Name, false>( \
114
this, m, value)), \
115
ps.end()); \
116
});
117
118
//! Use IMP_SINGLETON_MODIFIER() instead
119
#define IMP_SINGLETON_DERIVATIVE_MODIFIER(Name) IMP_SINGLETON_MODIFIER(Name)
120
121
/** Define
122
- IMP::SingletonModifier::apply_indexes()
123
*/
124
#define IMP_SINGLETON_MODIFIER_METHODS(Name) \
125
virtual void apply_indexes(Model *m, const ParticleIndexes &o, \
126
unsigned int lower_bound, \
127
unsigned int upper_bound) \
128
const override final { \
129
for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
130
apply_index(m, o[i]); \
131
} \
132
}
133
134
//! Use IMP_INDEX_SINGLETON_MODIFIER instead
135
#define IMP_INDEX_SINGLETON_DERIVATIVE_MODIFIER(Name) \
136
IMP_INDEX_SINGLETON_MODIFIER(Name)
137
138
#ifndef IMP_DOXYGEN
139
#define IMP_IMPLEMENT_SINGLETON_CONTAINER(Name) \
140
IMP_IMPLEMENT_INLINE(void do_apply(const SingletonModifier *sm) const, \
141
{ apply_generic(sm); }); \
142
IMP_IMPLEMENT_INLINE(void do_apply_moved(const SingletonModifier *sm, \
143
const ParticleIndexes &moved_pis, \
144
const ParticleIndexes &reset_pis) const, \
145
{ apply_generic_moved(sm, moved_pis, reset_pis); }); \
146
virtual ParticleIndexes get_all_possible_indexes() const override; \
147
IMP_OBJECT_METHODS(Name)
148
#endif
149
150
/** Use this to fill in container methods
151
IMP::SingletonContainer::do_apply()
152
IMP::SingletonContainer::do_apply_moved()
153
*/
154
#define IMP_SINGLETON_CONTAINER_METHODS(Name) \
155
void do_apply(const SingletonModifier *sm) const override { \
156
apply_generic(sm); } \
157
void do_apply_moved(const SingletonModifier *sm, \
158
const ParticleIndexes &moved_pis, \
159
const ParticleIndexes &reset_pis) const override { \
160
apply_generic_moved(sm, moved_pis, reset_pis); }
161
162
#endif
/* IMPKERNEL_SINGLETON_MACROS_H */
object_macros.h
Helper macros for implementing IMP Objects.
container_macros.h
Macros to define containers of objects.