IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2022 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>
13
14#include <IMP/Decorator.h>
17#include <vector>
18#include <limits>
19
20IMPCORE_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 */
34class 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
43 IMP_DECORATOR_METHODS(Typed, Decorator);
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
63IntKey Typed::get_type_key() {
64 static IntKey k("particle type");
65 return k;
66}
67
68
69IMP_DECORATORS(Typed, Typeds, ParticlesTemp);
70
71IMPCORE_END_NAMESPACE
72
73#endif /* IMPCORE_TYPED_H */
The base class for decorators.
Simple 3D transformation class.
Simple 3D vector class.
A base class for Keys.
Definition Key.h:45
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Helper macros for implementing Decorators.
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
#define IMP_DECORATOR_METHODS(Name, Parent)
Key< 34897493 > ParticleType
An IMP::Key object for identifying types of particles by strings.
Definition Typed.h:28
IMP::Vector< ParticleType > ParticleTypes
Definition Typed.h:29
Index< ParticleIndexTag > ParticleIndex
Definition base_types.h:196
Key< 1 > IntKey
The type used to identify int attributes in the Particles.
Definition base_types.h:36
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.