10 #ifndef IMPKERNEL_PARTICLE_H
11 #define IMPKERNEL_PARTICLE_H
13 #include <IMP/kernel_config.h>
20 #include "internal/AttributeTable.h"
28 #include <cereal/access.hpp>
29 #include <cereal/types/base_class.hpp>
31 IMPKERNEL_BEGIN_NAMESPACE
64 #define IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(UCName, lcname, Value) \
65 inline void add_attribute(UCName##Key name, Value initial_value); \
66 inline void remove_attribute(UCName##Key name); \
67 inline bool has_attribute(UCName##Key name) const; \
68 inline Value get_value(UCName##Key name) const; \
69 inline void set_value(UCName##Key name, Value value); \
70 inline void add_cache_attribute(UCName##Key name, Value value); \
71 inline UCName##Keys get_##lcname##_keys() const
73 IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(
Float,
float,
Float);
74 IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(
Floats, floats,
Floats);
76 IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(
Vector3D, vector3d,
79 IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(
Int,
int,
Int);
80 IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(
Ints, ints,
Ints);
81 IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(
String,
string,
String);
82 IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(
Object,
object,
Object *);
83 IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(WeakObject, weak_object,
Object *);
85 #define IMP_KERNEL_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DECL(UCName, lcname, Value) \
86 inline void add_attribute(UCName##Key name, Value initial_value); \
87 inline void remove_attribute(UCName##Key name); \
88 inline bool has_attribute(UCName##Key name) const; \
89 inline Value get_value(UCName##Key name) const; \
90 inline void set_value(UCName##Key name, Value value)
92 IMP_KERNEL_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DECL(SparseString,
string,
String);
93 IMP_KERNEL_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DECL(SparseInt,
int,
Int);
94 IMP_KERNEL_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DECL(SparseFloat,
float,
Float);
95 IMP_KERNEL_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DECL(SparseParticleIndex,
114 void add_attribute(
FloatKey name,
const Float initial_value,
bool optimized);
126 void set_is_optimized(
FloatKey k,
bool tf);
129 inline bool get_is_optimized(
FloatKey k)
const;
147 void show(std::ostream &out = std::cout)
const;
154 bool get_is_active()
const;
160 #if !defined(IMP_DOXYGEN)
172 friend class cereal::access;
173 template<
class Archive>
void serialize(Archive &ar) {
174 ar(cereal::base_class<ModelObject>(
this), id_);
198 : m_(p->get_model()), pi_(p->
get_index()) {}
200 : m_(p->get_model()), pi_(p->
get_index()) {}
202 : m_(p->get_model()), pi_(p->
get_index()) {}
204 Model *get_model()
const {
return m_; }
213 bool Particle::get_is_optimized(
FloatKey k)
const {
215 return get_model()->get_is_optimized(k, id_);
220 return get_model()->get_derivative(k, id_);
225 return get_model()->get_particle(get_model()->get_attribute(k, id_));
228 #define IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(UCName, lcname, Value) \
229 void Particle::add_attribute(UCName##Key name, Value initial_value) { \
230 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
231 get_model()->add_attribute(name, id_, initial_value); \
233 void Particle::remove_attribute(UCName##Key name) { \
234 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
235 get_model()->remove_attribute(name, id_); \
237 bool Particle::has_attribute(UCName##Key name) const { \
238 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
239 return get_model()->get_has_attribute(name, id_); \
241 Value Particle::get_value(UCName##Key name) const { \
242 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
243 return get_model()->get_attribute(name, id_); \
245 void Particle::set_value(UCName##Key name, Value value) { \
246 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
247 get_model()->set_attribute(name, id_, value); \
249 UCName##Keys Particle::get_##lcname##_keys() const { \
250 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
251 return get_model()->internal::UCName##AttributeTable::get_attribute_keys( \
254 void Particle::add_cache_attribute(UCName##Key name, Value value) { \
255 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
256 return get_model()->add_cache_attribute(name, id_, value); \
259 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(
Float,
float,
Float);
260 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(
Floats, floats,
Floats);
264 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(
Int,
int,
Int);
265 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(
Ints, ints,
Ints);
266 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(
String,
string,
String);
267 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(Object,
object, Object *);
268 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(WeakObject, weak_object, Object *);
270 #define IMP_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DEF(UCName, lcname, Value) \
271 void Particle::add_attribute(UCName##Key name, Value initial_value) { \
272 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
273 get_model()->add_attribute(name, id_, initial_value); \
275 void Particle::remove_attribute(UCName##Key name) { \
276 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
277 get_model()->remove_attribute(name, id_); \
279 bool Particle::has_attribute(UCName##Key name) const { \
280 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
281 return get_model()->get_has_attribute(name, id_); \
283 Value Particle::get_value(UCName##Key name) const { \
284 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
285 return get_model()->get_attribute(name, id_); \
287 void Particle::set_value(UCName##Key name, Value value) { \
288 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
289 get_model()->set_attribute(name, id_, value); \
292 IMP_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DEF(SparseString,
string,
String);
293 IMP_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DEF(SparseInt,
int,
Int);
294 IMP_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DEF(SparseFloat,
float,
Float);
295 IMP_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DEF(SparseParticleIndex, particle_index,
300 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()
Classes to handle static sized arrays of things.
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