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 *);
95 void add_attribute(
FloatKey name,
const Float initial_value,
bool optimized);
107 void set_is_optimized(
FloatKey k,
bool tf);
110 inline bool get_is_optimized(
FloatKey k)
const;
128 void show(std::ostream &out = std::cout)
const;
135 bool get_is_active()
const;
141 #if !defined(IMP_DOXYGEN)
153 friend class cereal::access;
154 template<
class Archive>
void serialize(Archive &ar) {
155 ar(cereal::base_class<ModelObject>(
this), id_);
179 : m_(p->get_model()), pi_(p->
get_index()) {}
181 : m_(p->get_model()), pi_(p->
get_index()) {}
183 : m_(p->get_model()), pi_(p->
get_index()) {}
185 Model *get_model()
const {
return m_; }
194 bool Particle::get_is_optimized(
FloatKey k)
const {
196 return get_model()->get_is_optimized(k, id_);
201 return get_model()->get_derivative(k, id_);
206 return get_model()->get_particle(get_model()->get_attribute(k, id_));
209 #define IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(UCName, lcname, Value) \
210 void Particle::add_attribute(UCName##Key name, Value initial_value) { \
211 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
212 get_model()->add_attribute(name, id_, initial_value); \
214 void Particle::remove_attribute(UCName##Key name) { \
215 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
216 get_model()->remove_attribute(name, id_); \
218 bool Particle::has_attribute(UCName##Key name) const { \
219 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
220 return get_model()->get_has_attribute(name, id_); \
222 Value Particle::get_value(UCName##Key name) const { \
223 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
224 return get_model()->get_attribute(name, id_); \
226 void Particle::set_value(UCName##Key name, Value value) { \
227 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
228 get_model()->set_attribute(name, id_, value); \
230 UCName##Keys Particle::get_##lcname##_keys() const { \
231 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
232 return get_model()->internal::UCName##AttributeTable::get_attribute_keys( \
235 void Particle::add_cache_attribute(UCName##Key name, Value value) { \
236 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
237 return get_model()->add_cache_attribute(name, id_, value); \
240 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(
Float,
float,
Float);
241 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(
Floats, floats,
Floats);
242 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(
Int,
int,
Int);
243 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(
Ints, ints,
Ints);
244 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(
String,
string,
String);
245 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(Object,
object, Object *);
246 IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(WeakObject, weak_object, Object *);
250 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.
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.
Various general useful functions for IMP.
std::string String
Basic string value.
Class for adding derivatives from restraints to the model.
ParticleAdaptor(Particle *p)
convert p to itself