IMP  2.2.1
The Integrative Modeling Platform
kernel/Particle.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/Particle.h
3  * \brief Classes to handle individual model particles.
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_PARTICLE_H
10 #define IMPKERNEL_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 IMPKERNEL_BEGIN_NAMESPACE
25 
26 class Model;
27 class Changed;
28 class SaveOptimizeds;
29 
30 //! Class to handle individual model particles.
31 /** At this point a Particle should only be considered as a placeholder for the
32  ParticleIndex, accessed through the get_index() method.
33 */
34 class IMPKERNELEXPORT Particle : public ModelObject {
35  private:
36 // doxygen produces funny docs for these things
37 #ifndef IMP_DOXYGEN
38  friend class Model;
39 #endif
40  ParticleIndex id_;
42 
43  public:
44  //! Construct a particle and add it to the Model
45  Particle(kernel::Model *m, std::string name);
46 
47  //! Construct a particle and add it to the Model
49 
50 #ifndef IMP_DOXYGEN
51 
52 #define IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(UCName, lcname, Value) \
53  void add_attribute(UCName##Key name, Value initial_value); \
54  void remove_attribute(UCName##Key name); \
55  bool has_attribute(UCName##Key name) const; \
56  Value get_value(UCName##Key name) const; \
57  void set_value(UCName##Key name, Value value); \
58  void add_cache_attribute(UCName##Key name, Value value); \
59  UCName##Keys get_##lcname##_keys() const
60 
61  IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(Float, float, Float);
62  IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(Int, int, Int);
63  IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(String, string, String);
64  IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(Object, object, Object *);
65  IMP_KERNEL_PARTICLE_ATTRIBUTE_TYPE_DECL(WeakObject, weak_object, Object *);
66 
67  /** @name Float Attributes
68  Float attributes can be optimized, meaning the optimizer is
69  allowed to change their value in order to improve the score.
70  As a result, there are a number of extra methods to manipulate
71  them.
72 
73  All distances are assumed to be in angstroms
74  and derivatives in kcal/mol angstrom. This is not enforced.
75  */
76  /*@{*/
77  void add_attribute(FloatKey name, const Float initial_value, bool optimized);
78 
79  void add_to_derivative(FloatKey key, Float value,
80  const DerivativeAccumulator &da);
81 
82  void set_is_optimized(FloatKey k, bool tf);
83 
84  bool get_is_optimized(FloatKey k) const;
85 
86  Float get_derivative(FloatKey name) const;
87  /** @} */
88 
89  /** \name Particle attributes
90  @{
91  */
92  void add_attribute(ParticleIndexKey k, Particle *v);
93  bool has_attribute(ParticleIndexKey k);
94  void set_value(ParticleIndexKey k, Particle *v);
95  Particle *get_value(ParticleIndexKey k) const;
96  void remove_attribute(ParticleIndexKey k);
97  ParticleIndexKeys get_particle_keys() const;
98  /** @} */
99 
100  //! Print out all the attributes
101  void show(std::ostream &out = std::cout) const;
102 
103  //! Get whether the particle is active.
104  /** Restraints referencing the particle are only evaluated for 'active'
105  particles.
106  \return true it the particle is active.
107  */
108  bool get_is_active() const;
109 #endif
110 
111  ParticleIndex get_index() const;
112 
113 #if !defined(IMP_DOXYGEN)
114  void clear_caches();
115 #endif
116  protected:
117  virtual ModelObjectsTemp do_get_inputs() const IMP_OVERRIDE IMP_FINAL {
118  return ModelObjectsTemp();
119  }
120  virtual ModelObjectsTemp do_get_outputs() const IMP_OVERRIDE IMP_FINAL {
121  return ModelObjectsTemp();
122  }
123 };
124 
125 // for swig
126 class Decorator;
127 
128 /** Take Decorator or Particle. */
129 class IMPKERNELEXPORT ParticleAdaptor : public base::InputAdaptor {
130  Model *m_;
131  ParticleIndex pi_;
132 
133  public:
134  ParticleAdaptor() : m_(nullptr), pi_() {}
135  ParticleAdaptor(Particle *p) : m_(p->get_model()), pi_(p->get_index()) {}
136  ParticleAdaptor(const Decorator &d);
137 #ifndef SWIG
139  : m_(p->get_model()), pi_(p->get_index()) {}
141  : m_(p->get_model()), pi_(p->get_index()) {}
143  : m_(p->get_model()), pi_(p->get_index()) {}
144 #endif
145  Model *get_model() const { return m_; }
146  ParticleIndex get_particle_index() const { return pi_; }
147 };
148 
149 IMPKERNEL_END_NAMESPACE
150 
151 #endif /* IMPKERNEL_PARTICLE_H */
Various general useful functions for IMP.
Class for adding derivatives from restraints to the model.
Class for adding derivatives from restraints to the model.
Ints get_index(const kernel::ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
IMP::base::Vector< IMP::base::WeakPointer< kernel::ModelObject > > ModelObjectsTemp
A nullptr-initialized pointer to an IMP Object.
A smart pointer to a ref-counted Object that is a class memeber.
Definition: base/Pointer.h:147
Basic types used by IMP.
virtual ModelObjectsTemp do_get_outputs() const
A smart pointer to a reference counted object.
Definition: base/Pointer.h:87
virtual void clear_caches()
Definition: base/Object.h:227
virtual ModelObjectsTemp do_get_inputs() const
Single variable function.
IMP::kernel::Model Model
Various general useful functions for IMP.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Class to handle individual model particles.
void show(Hierarchy h, std::ostream &out=std::cout)
Print out a molecular hierarchy.
IMP::kernel::Particle Particle
double Float
Basic floating-point value (could be float, double...)
Definition: base/types.h:20
int Int
Basic integer value.
Definition: base/types.h:35
A shared base class to help in debugging and things.
Keys to cache lookup of attribute strings.
std::string String
Basic string value.
Definition: base/types.h:44
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:72