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>
31IMPKERNEL_BEGIN_NAMESPACE
45class IMPKERNELEXPORT
Particle :
public ModelObject {
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);
132 void set_is_optimized(
FloatKey k,
bool tf);
137 inline bool get_is_optimized(
FloatKey k)
const;
163 void show(std::ostream &out = std::cout)
const;
170 bool get_is_active()
const;
176#if !defined(IMP_DOXYGEN)
188 friend class cereal::access;
189 template<
class Archive>
void serialize(Archive &ar) {
190 ar(cereal::base_class<ModelObject>(
this), id_);
202class IMPKERNELEXPORT ParticleAdaptor :
public InputAdaptor {
207 ParticleAdaptor() : m_(
nullptr), pi_() {}
214 : m_(p->get_model()), pi_(p->get_index()) {}
216 : m_(p->get_model()), pi_(p->get_index()) {}
218 : m_(p->get_model()), pi_(p->get_index()) {}
220 Model *get_model()
const {
return m_; }
229bool Particle::get_is_optimized(FloatKey k)
const {
231 return get_model()->get_is_optimized(k, id_);
234bool Particle::get_is_optimized(Vector3DDerivKey k)
const {
236 return get_model()->get_is_optimized(k, id_);
239bool Particle::get_is_optimized(Vector4DDerivKey k)
const {
241 return get_model()->get_is_optimized(k, id_);
244Float Particle::get_derivative(FloatKey k)
const {
246 return get_model()->get_derivative(k, id_);
249Vector3D Particle::get_derivative(Vector3DDerivKey k)
const {
251 return get_model()->get_derivative(k, id_);
254Vector4D Particle::get_derivative(Vector4DDerivKey k)
const {
256 return get_model()->get_derivative(k, id_);
259Particle *Particle::get_value(ParticleIndexKey k)
const {
261 return get_model()->get_particle(get_model()->get_attribute(k, id_));
264#define IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(UCName, lcname, Value) \
265 void Particle::add_attribute(UCName##Key name, Value initial_value) { \
266 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
267 get_model()->add_attribute(name, id_, initial_value); \
269 void Particle::remove_attribute(UCName##Key name) { \
270 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
271 get_model()->remove_attribute(name, id_); \
273 bool Particle::has_attribute(UCName##Key name) const { \
274 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
275 return get_model()->get_has_attribute(name, id_); \
277 Value Particle::get_value(UCName##Key name) const { \
278 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
279 return get_model()->get_attribute(name, id_); \
281 void Particle::set_value(UCName##Key name, Value value) { \
282 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
283 get_model()->set_attribute(name, id_, value); \
285 UCName##Keys Particle::get_##lcname##_keys() const { \
286 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
287 return get_model()->internal::UCName##AttributeTable::get_attribute_keys( \
290 void Particle::add_cache_attribute(UCName##Key name, Value value) { \
291 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
292 return get_model()->add_cache_attribute(name, id_, value); \
295IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(Float,
float, Float);
296IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(Floats, floats, Floats);
298IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(Vector3D, vector3d, Vector3D);
300IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(Int,
int, Int);
301IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(Ints, ints, Ints);
302IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(String,
string, String);
303IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(Object,
object, Object *);
304IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(WeakObject, weak_object, Object *);
306#define IMP_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DEF(UCName, lcname, Value) \
307 void Particle::add_attribute(UCName##Key name, Value initial_value) { \
308 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
309 get_model()->add_attribute(name, id_, initial_value); \
311 void Particle::remove_attribute(UCName##Key name) { \
312 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
313 get_model()->remove_attribute(name, id_); \
315 bool Particle::has_attribute(UCName##Key name) const { \
316 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
317 return get_model()->get_has_attribute(name, id_); \
319 Value Particle::get_value(UCName##Key name) const { \
320 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
321 return get_model()->get_attribute(name, id_); \
323 void Particle::set_value(UCName##Key name, Value value) { \
324 IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
325 get_model()->set_attribute(name, id_, value); \
328IMP_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DEF(SparseString,
string, String);
329IMP_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DEF(SparseInt,
int, Int);
330IMP_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DEF(SparseFloat,
float, Float);
331IMP_SPARSE_PARTICLE_ATTRIBUTE_TYPE_DEF(SparseParticleIndex, particle_index,
336IMPKERNEL_END_NAMESPACE
Classes to handle static sized arrays of things.
Class for adding derivatives from restraints to the model.
Keys to cache lookup of attribute strings.
Base class for objects in a Model that depend on other objects.
Storage of a model, its restraints, constraints and particles.
A shared base class to help in debugging and things.
A nullptr-initialized pointer to an IMP Object.
Helper macros for throwing and handling exceptions.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Interface to specialized Particle types (e.g. atoms).
Class for adding derivatives from restraints to the model.
Class for storing model, its restraints, constraints, and particles.
Common base class for heavy weight IMP objects.
virtual void clear_caches()
ParticleAdaptor(Particle *p)
convert p to itself
ParticleAdaptor(const Decorator &d)
convert d to the particle it decorates
Class to handle individual particles of a Model object.
Particle(Model *m, std::string name)
Construct a particle and add it to the Model.
virtual ModelObjectsTemp do_get_inputs() const override final
Particle(Model *m)
Construct a particle and add it to the Model.
ParticleIndex get_index() const
returns the particle index of this particle in its model
virtual ModelObjectsTemp do_get_outputs() const override final
Index< ParticleIndexTag > ParticleIndex
Key< 17 > Vector3DDerivKey
The type used to identify 3D vector attributes&derivatives in the Particles.
IMP::Vector< ParticleIndexKey > ParticleIndexKeys
double Float
Basic floating-point value (could be float, double...).
int Int
Basic integer value.
IMP::Vector< Int > Ints
Standard way to pass a bunch of Int values.
std::string String
Basic string value.
Key< 19 > Vector4DDerivKey
The type used to identify 4D vector attributes&derivatives in the Particles.
Key< 0 > FloatKey
The type used to identify float attributes in the Particles.
Key< 3 > ParticleIndexKey
The type used to identify a particle attribute in the Particles.
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
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.
Functions and adaptors for dealing with particle indexes.
A smart pointer to a ref-counted Object that is a class member.
A smart pointer to a reference counted object.
Smart pointer to Object-derived classes that does not refcount.
Various general useful functions for IMP.