IMP logo
IMP Reference Guide  2.12.0
The Integrative Modeling Platform
Typed.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/Typed.h \brief A particle with a user-defined type.
3  *
4  * Copyright 2007-2019 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPCORE_TYPED_H
9 #define IMPCORE_TYPED_H
10 
11 #include <IMP/core/core_config.h>
12 #include <IMP/decorator_macros.h>
13 
14 #include <IMP/Decorator.h>
15 #include <IMP/algebra/Vector3D.h>
17 #include <vector>
18 #include <limits>
19 
20 IMPCORE_BEGIN_NAMESPACE
21 
22 // TODO: why this number? how can we tell it's unique?
23 #define IMP_PARTICLE_TYPE_INDEX 34897493
24 
25 //! An IMP::Key object for identifying types of particles by strings.
26 /** The ParticleType key is used to type particles within
27  the Typed decorator */
30 
31 //! A decorator for classifying particles in your system.
32 /** \see ParticleType
33  */
34 class IMPCOREEXPORT Typed : public Decorator {
35  static void do_setup_particle(Model *m, ParticleIndex pi,
36  ParticleType t) {
37  m->add_attribute(get_type_key(), pi, t.get_index());
38  }
39 
40  public:
41  inline static IntKey get_type_key();
42 
45 
46  static bool get_is_setup(Model *m, ParticleIndex pi) {
47  return m->get_has_attribute(get_type_key(), pi);
48  }
49 
50  ParticleType get_type() const {
51  return ParticleType(
52  get_model()->get_attribute(get_type_key(), get_particle_index()));
53  }
54 
55  void set_type(ParticleType pt) const {
56  get_model()->set_attribute(get_type_key(), get_particle_index(),
57  pt.get_index());
58  }
59 
60 };
61 
62 // in header for faster access
63 IntKey Typed::get_type_key() {
64  static IntKey k("particle type");
65  return k;
66 }
67 
68 
69 IMP_DECORATORS(Typed, Typeds, ParticlesTemp);
70 
71 IMPCORE_END_NAMESPACE
72 
73 #endif /* IMPCORE_TYPED_H */
The base class for decorators.
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition: Decorator.h:188
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
Model * get_model() const
Returns the Model containing the particle.
Definition: Decorator.h:191
Key< 34897493 > ParticleType
An IMP::Key object for identifying types of particles by strings.
Definition: Typed.h:28
A more IMP-like version of the std::vector.
Definition: Vector.h:39
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
add particle atribute with the specied key and initial value
Various general useful macros for IMP.
Key< 1 > IntKey
The type used to identify int attributes in the Particles.
Definition: base_types.h:36
void set_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
set the value of particle attribute with the specified key
A base class for Keys.
Definition: Key.h:44
Simple 3D transformation class.
Interface to specialized Particle types (e.g. atoms)
Definition: Decorator.h:118
#define IMP_DECORATOR_METHODS(Name, Parent)
Simple 3D vector class.
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
A decorator for classifying particles in your system.
Definition: Typed.h:34
bool get_has_attribute(TypeKey attribute_key, ParticleIndex particle) const
return true if particle has attribute with the specified key