IMP logo
IMP Reference Guide  2.20.1
The Integrative Modeling Platform
Copy.h
Go to the documentation of this file.
1 /**
2  * \file IMP/atom/Copy.h
3  * \brief A decorator for keeping track of copies of a molecule.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPATOM_COPY_H
10 #define IMPATOM_COPY_H
11 
12 #include <IMP/atom/atom_config.h>
13 #include <IMP/macros.h>
14 
15 #include "Molecule.h"
16 #include <IMP/Decorator.h>
17 #include <vector>
18 #include <limits>
19 
20 IMPATOM_BEGIN_NAMESPACE
21 
22 //! A decorator for keeping track of copies of a molecule.
23 /** This decorator is for differentiating and keeping track
24  of identity when there are multiple copies of a
25  molecule in the system. It should only be applied to
26  Molecule particles.
27  */
28 class IMPATOMEXPORT Copy : public Molecule {
29  static void do_setup_particle(Model *m, ParticleIndex pi,
30  int number) {
31  m->add_attribute(get_copy_index_key(), pi, number);
32  if (!Molecule::get_is_setup(m, pi)) {
34  }
35  }
36 
37  public:
38  static IntKey get_copy_index_key();
39 
41  //! Create a decorator for the numberth copy.
43 
44  static bool get_is_setup(Model *m, ParticleIndex pi) {
45  return m->get_has_attribute(get_copy_index_key(), pi);
46  }
47 
48  int get_copy_index() const {
49  return get_particle()->get_value(get_copy_index_key());
50  }
51 };
52 
53 IMP_DECORATORS(Copy, Copies, ParticlesTemp);
54 
55 //! Walk up the hierarchy to find the current copy index.
56 /** \return the copy index, or -1 if there is none.
57  */
58 IMPATOMEXPORT int get_copy_index(Hierarchy h);
59 
60 IMPATOM_END_NAMESPACE
61 
62 #endif /* IMPATOM_COPY_H */
The base class for decorators.
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
Various general useful macros for IMP.
A decorator for Molecules.
static Molecule setup_particle(Model *m, ParticleIndex pi)
Definition: Molecule.h:37
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
A decorator for keeping track of copies of a molecule.
Definition: Copy.h:28
void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
add particle attribute with the specified key and initial value
Particle * get_particle() const
Returns the particle decorated by this decorator.
Definition: Decorator.h:194
#define IMP_DECORATOR_METHODS(Name, Parent)
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
int Int
Basic integer value.
Definition: types.h:34
int get_copy_index(Hierarchy h)
Walk up the hierarchy to find the current copy index.
bool get_has_attribute(TypeKey attribute_key, ParticleIndex particle) const
return true if particle has attribute with the specified key
A decorator for a molecule.
Definition: Molecule.h:24