10 #ifndef IMPKERNEL_PARTICLE_H
11 #define IMPKERNEL_PARTICLE_H
13 #include <IMP/kernel_config.h>
20 #include "internal/AttributeTable.h"
26 #include <cereal/access.hpp>
27 #include <cereal/types/base_class.hpp>
29 IMPKERNEL_BEGIN_NAMESPACE
62 #define IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(UCName, lcname, Value) \
63 inline void add_attribute(UCName##Key name, Value initial_value); \
64 inline void remove_attribute(UCName##Key name); \
65 inline bool has_attribute(UCName##Key name) const; \
66 inline Value get_value(UCName##Key name) const; \
67 inline void set_value(UCName##Key name, Value value); \
68 inline void add_cache_attribute(UCName##Key name, Value value); \
69 inline UCName##Keys get_##lcname##_keys() const
71 IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(
Float,
float,
Float);
72 IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(
Floats, floats,
Floats);
73 IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(
Int,
int,
Int);
74 IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(
Ints, ints,
Ints);
75 IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(
String,
string,
String);
76 IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(
Object,
object,
Object *);
77 IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(WeakObject, weak_object,
Object *);
79 #define IMP_KERNEL_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DECL(UCName, lcname, Value) \
80 inline void add_attribute(UCName##Key name, Value initial_value); \
81 inline void remove_attribute(UCName##Key name); \
82 inline bool has_attribute(UCName##Key name) const; \
83 inline Value get_value(UCName##Key name) const; \
84 inline void set_value(UCName##Key name, Value value)
86 IMP_KERNEL_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DECL(SparseString,
string,
String);
87 IMP_KERNEL_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DECL(SparseInt,
int,
Int);
88 IMP_KERNEL_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DECL(SparseFloat,
float,
Float);
89 IMP_KERNEL_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DECL(SparseParticleIndex,
108 void add_attribute(
FloatKey name,
const Float initial_value,
bool optimized);
120 void set_is_optimized(
FloatKey k,
bool tf);
123 inline bool get_is_optimized(
FloatKey k)
const;
141 void show(std::ostream &out = std::cout)
const;
148 bool get_is_active()
const;
154 #if !defined(IMP_DOXYGEN)
166 friend class cereal::access;
167 template<
class Archive>
void serialize(Archive &ar) {
168 ar(cereal::base_class<ModelObject>(
this), id_);
192 : m_(p->get_model()), pi_(p->
get_index()) {}
194 : m_(p->get_model()), pi_(p->
get_index()) {}
196 : m_(p->get_model()), pi_(p->
get_index()) {}
198 Model *get_model()
const {
return m_; }
207 bool Particle::get_is_optimized(
FloatKey k)
const {
209 return get_model()->get_is_optimized(k, id_);
214 return get_model()->get_derivative(k, id_);
219 return get_model()->get_particle(get_model()->get_attribute(k, id_));
222 #define IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(UCName, lcname, Value) \
223 void Particle::add_attribute(UCName##Key name, Value initial_value) { \
224 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
225 get_model()->add_attribute(name, id_, initial_value); \
227 void Particle::remove_attribute(UCName##Key name) { \
228 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
229 get_model()->remove_attribute(name, id_); \
231 bool Particle::has_attribute(UCName##Key name) const { \
232 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
233 return get_model()->get_has_attribute(name, id_); \
235 Value Particle::get_value(UCName##Key name) const { \
236 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
237 return get_model()->get_attribute(name, id_); \
239 void Particle::set_value(UCName##Key name, Value value) { \
240 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
241 get_model()->set_attribute(name, id_, value); \
243 UCName##Keys Particle::get_##lcname##_keys() const { \
244 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
245 return get_model()->internal::UCName##AttributeTable::get_attribute_keys( \
248 void Particle::add_cache_attribute(UCName##Key name, Value value) { \
249 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
250 return get_model()->add_cache_attribute(name, id_, value); \
253 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(
Float,
float,
Float);
254 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(
Floats, floats,
Floats);
255 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(
Int,
int,
Int);
256 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(
Ints, ints,
Ints);
257 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(
String,
string,
String);
258 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(Object,
object, Object *);
259 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(WeakObject, weak_object, Object *);
261 #define IMP_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DEF(UCName, lcname, Value) \
262 void Particle::add_attribute(UCName##Key name, Value initial_value) { \
263 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
264 get_model()->add_attribute(name, id_, initial_value); \
266 void Particle::remove_attribute(UCName##Key name) { \
267 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
268 get_model()->remove_attribute(name, id_); \
270 bool Particle::has_attribute(UCName##Key name) const { \
271 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
272 return get_model()->get_has_attribute(name, id_); \
274 Value Particle::get_value(UCName##Key name) const { \
275 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
276 return get_model()->get_attribute(name, id_); \
278 void Particle::set_value(UCName##Key name, Value value) { \
279 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
280 get_model()->set_attribute(name, id_, value); \
283 IMP_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DEF(SparseString,
string,
String);
284 IMP_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DEF(SparseInt,
int,
Int);
285 IMP_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DEF(SparseFloat,
float,
Float);
286 IMP_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DEF(SparseParticleIndex, particle_index,
291 IMPKERNEL_END_NAMESPACE
virtual ModelObjectsTemp do_get_outputs() const overridefinal
Key< 0 > FloatKey
The type used to identify float attributes in the Particles.
Smart pointer to Object-derived classes that does not refcount.
Functions and adaptors for dealing with particle indexes.
IMP::Vector< Float > Floats
Standard way to pass a bunch of Float values.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Class for adding derivatives from restraints to the model.
Storage of a model, its restraints, constraints and particles.
Index< ParticleIndexTag > ParticleIndex
Keys to cache lookup of attribute strings.
virtual void clear_caches()
A smart pointer to a reference counted object.
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Class for storing model, its restraints, constraints, and particles.
Base class for objects in a Model that depend on other objects.
Key< 3 > ParticleIndexKey
The type used to identify a particle attribute in the Particles.
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
Common base class for heavy weight IMP objects.
A smart pointer to a ref-counted Object that is a class member.
Various general useful functions for IMP.
Base class for objects in a Model that depend on other objects.
Interface to specialized Particle types (e.g. atoms)
std::ostream & show(Hierarchy h, std::ostream &out=std::cout)
Print the hierarchy using a given decorator to display each node.
virtual ModelObjectsTemp do_get_inputs() const overridefinal
A nullptr-initialized pointer to an IMP Object.
Helper macros for throwing and handling exceptions.
A shared base class to help in debugging and things.
double Float
Basic floating-point value (could be float, double...)
Class to handle individual particles of a Model object.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
int Int
Basic integer value.
IMP::Vector< Int > Ints
Standard way to pass a bunch of Int values.
std::string String
Basic string value.
Class for adding derivatives from restraints to the model.
ParticleAdaptor(Particle *p)
convert p to itself