IMP  2.0.1
The Integrative Modeling Platform
kernel/declare_Particle.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/declare_Particle.h
3  * \brief Classes to handle individual model particles.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_DECLARE_PARTICLE_H
10 #define IMPKERNEL_DECLARE_PARTICLE_H
11 
12 #include <IMP/kernel/kernel_config.h>
13 #include "base_types.h"
14 #include <IMP/base/Object.h>
15 #include <IMP/base/utility.h>
16 #include "Key.h"
17 #include "internal/AttributeTable.h"
18 #include "DerivativeAccumulator.h"
19 #include <IMP/base/Pointer.h>
20 #include "ModelObject.h"
21 #include "particle_index.h"
22 #include <utility>
23 
24 
25 #define IMP_PARTICLE_ATTRIBUTE_TYPE_DECL(UCName, lcname, Value) \
26  void add_attribute(UCName##Key name, Value initial_value); \
27  void remove_attribute(UCName##Key name); \
28  bool has_attribute(UCName##Key name) const; \
29  Value get_value(UCName##Key name) const; \
30  void set_value(UCName##Key name, Value value); \
31  void add_cache_attribute(UCName##Key name, Value value); \
32  UCName##Keys get_##lcname##_keys() const
33 
34 
35 #define IMP_PARTICLE_ATTRIBUTE_TYPE_DEF(UCName, lcname, Value) \
36  inline void Particle::add_attribute(UCName##Key name, Value initial_value){ \
37  IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
38  get_model()->add_attribute(name, id_, initial_value); \
39  } \
40  inline void Particle::remove_attribute(UCName##Key name) { \
41  IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
42  get_model()->remove_attribute(name, id_); \
43  } \
44  inline bool Particle::has_attribute(UCName##Key name) const{ \
45  IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
46  return get_model()->get_has_attribute(name, id_); \
47  } \
48  inline Value Particle::get_value(UCName##Key name) const { \
49  IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
50  return get_model()->get_attribute(name, id_); \
51  } \
52  inline void Particle::set_value(UCName##Key name, Value value) { \
53  IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
54  get_model()->set_attribute(name, id_, value); \
55  } \
56  inline UCName##Keys Particle::get_##lcname##_keys() const { \
57  IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
58  return get_model()->internal::UCName##AttributeTable \
59  ::get_attribute_keys(id_); \
60  } \
61  inline void Particle::add_cache_attribute(UCName##Key name, \
62  Value value) { \
63  IMP_USAGE_CHECK(get_is_active(), "Inactive particle used."); \
64  return get_model()->add_cache_attribute(name, id_, value); \
65  }
66 
67 
68 
69 IMPKERNEL_BEGIN_NAMESPACE
70 
71 class Model;
72 class Changed;
73 class SaveOptimizeds;
74 
75 //! Class to handle individual model particles.
76 /** At this point a Particle should only be considered as a placeholder for the
77  ParticleIndex, accessed through the get_index() method.
78 */
79 class IMPKERNELEXPORT Particle : public ModelObject
80 {
81  private:
82  // doxygen produces funny docs for these things
83 #ifndef IMP_DOXYGEN
84  friend class Model;
85 #endif
86  ParticleIndex id_;
88  public:
89 
90  //! Construct a particle and add it to the Model
91  Particle(Model *m, std::string name);
92 
93  //! Construct a particle and add it to the Model
94  Particle(Model *m);
95 
96 #ifndef IMP_DOXYGEN
97  IMP_PARTICLE_ATTRIBUTE_TYPE_DECL(Float, float, Float);
98  IMP_PARTICLE_ATTRIBUTE_TYPE_DECL(Int, int, Int);
99  IMP_PARTICLE_ATTRIBUTE_TYPE_DECL(String, string, String);
100  IMP_PARTICLE_ATTRIBUTE_TYPE_DECL(Object, object, Object*);
101  IMP_PARTICLE_ATTRIBUTE_TYPE_DECL(WeakObject, weak_object, Object*);
102 
103 
104  /** @name Float Attributes
105  Float attributes can be optimized, meaning the optimizer is
106  allowed to change their value in order to improve the score.
107  As a result, there are a number of extra methods to manipulate
108  them.
109 
110  All distances are assumed to be in angstroms
111  and derivatives in kcal/mol angstrom. This is not enforced.
112  */
113  /*@{*/
114  void add_attribute(FloatKey name, const Float initial_value, bool optimized);
115 
116  void add_to_derivative(FloatKey key, Float value,
117  const DerivativeAccumulator &da);
118 
119  void set_is_optimized(FloatKey k, bool tf);
120 
121  bool get_is_optimized(FloatKey k) const;
122 
123  Float get_derivative(FloatKey name) const ;
124  /** @} */
125 
126  /** \name Particle attributes
127  @{
128  */
129  void add_attribute(ParticleIndexKey k, Particle *v);
130  bool has_attribute(ParticleIndexKey k);
131  void set_value(ParticleIndexKey k, Particle *v);
132  Particle *get_value(ParticleIndexKey k) const;
133  void remove_attribute(ParticleIndexKey k);
134  ParticleIndexKeys get_particle_keys() const;
135  /** @} */
136 
137  //! Get whether the particle is active.
138  /** Restraints referencing the particle are only evaluated for 'active'
139  particles.
140  \return true it the particle is active.
141  */
142  bool get_is_active() const;
143 #endif
144 
145 #if 0
146 #if !defined(IMP_DOXYGEN)&& !defined(SWIG)
147  void *operator new(std::size_t sz, void*p);
148  void operator delete(void *p);
149  void *operator new(std::size_t sz);
150 #endif
151 #endif
152 
153  ParticleIndex get_index() const;
154 
155 #if !defined(IMP_DOXYGEN)
156  void clear_caches();
157 #endif
158  protected:
159  virtual ModelObjectsTemp do_get_inputs() const IMP_OVERRIDE IMP_FINAL {
160  return ModelObjectsTemp();
161  }
162  virtual ModelObjectsTemp do_get_outputs() const IMP_OVERRIDE IMP_FINAL {
163  return ModelObjectsTemp();
164  }
165  virtual void do_update_dependencies() IMP_OVERRIDE IMP_FINAL {}
166 };
167 
168 IMPKERNEL_END_NAMESPACE
169 
170 #endif /* IMPKERNEL_DECLARE_PARTICLE_H */