IMP logo
IMP Reference Guide  2.18.0
The Integrative Modeling Platform
particle_index.h
Go to the documentation of this file.
1 /**
2  * \file IMP/particle_index.h
3  * \brief Functions and adaptors for dealing with particle indexes.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_PARTICLE_INDEX_H
10 #define IMPKERNEL_PARTICLE_INDEX_H
11 
12 #include <IMP/kernel_config.h>
13 #include "base_types.h"
14 #include <boost/shared_ptr.hpp>
15 
16 IMPKERNEL_BEGIN_NAMESPACE
17 
18 class Particle;
19 class Decorator;
20 
21 //! Get the indexes from a list of particles.
22 IMPKERNELEXPORT ParticleIndexes get_indexes(const ParticlesTemp &ps);
23 
24 //! Get the particles from a list of indexes.
25 IMPKERNELEXPORT ParticlesTemp
26  get_particles(Model *m, const ParticleIndexes &ps);
27 
28 //! Get the indexes from a list of particle pairs.
29 IMPKERNELEXPORT ParticleIndexPairs get_indexes(const ParticlePairsTemp &ps);
30 
31 //! Take Decorator, Particle or ParticleIndex.
32 class IMPKERNELEXPORT ParticleIndexAdaptor
33 #ifndef SWIG
34  // suppress swig warning that doesn't make sense and I can't make go away
35  : public ParticleIndex,
37 #endif
38  {
39  public:
43 #if !defined(SWIG) && !defined(IMP_DOXYGEN) && !defined(IMP_SWIG_WRAPPER)
46 #endif
47 };
48 
49 //! Take Decorator, Particle or ParticleIndex.
50 class IMPKERNELEXPORT ParticleIndexesAdaptor : public InputAdaptor {
51  boost::shared_ptr<ParticleIndexes> tmp_;
52  const ParticleIndexes *val_;
53 
54  public:
55 #if !defined(SWIG)
56  template <class PS>
57  ParticleIndexesAdaptor(const PS &ps)
58  : tmp_(new ParticleIndexes(ps.size())), val_(tmp_.get()) {
59  for (unsigned int i = 0; i < ps.size(); ++i) {
60  (*tmp_)[i] = ps[i].get_particle_index();
61  }
62  }
64 #endif
67  : tmp_(new ParticleIndexes(pi)), val_(tmp_.get()) {}
68  ParticleIndexesAdaptor() : tmp_(new ParticleIndexes()), val_(tmp_.get()) {}
69 #ifndef SWIG
70  typedef ParticleIndexes::value_type value_type;
71  typedef ParticleIndexes::const_reference reference;
72  typedef ParticleIndexes::const_pointer pointer;
73  typedef ParticleIndexes::size_type size_type;
74  typedef ParticleIndexes::const_reference const_reference;
75  typedef ParticleIndexes::const_pointer const_pointer;
76  operator const ParticleIndexes &() const { return *val_; }
77  ParticleIndex operator[](unsigned int i) const { return (*val_)[i]; }
78  unsigned int size() const { return val_->size(); }
79  typedef ParticleIndexes::const_iterator const_iterator;
80  typedef ParticleIndexes::const_iterator iterator;
81  const_iterator begin() const { return val_->begin(); }
82  const_iterator end() const { return val_->end(); }
83 #endif
84 };
85 
86 //! Take ParticlePairs or ParticleIndexPairs.
87 class IMPKERNELEXPORT ParticleIndexPairsAdaptor
88 #ifndef SWIG
89  // suppress swig warning that doesn't make sense and I can't make go away
90  : public ParticleIndexPairs,
92 #endif
93  {
94  public:
95 #if !defined(SWIG)
96  template <class PS>
97  ParticleIndexPairsAdaptor(const PS &ps) {
98  resize(ps.size());
99  for (unsigned int i = 0; i < ps.size(); ++i) {
100  operator[](i) = ParticleIndexPair(ps[i][0].get_particle_index(),
101  ps[i][1].get_particle_index());
102  }
103  }
104 #endif
107  : ParticleIndexPairs(pi) {}
109 };
110 
111 IMPKERNEL_END_NAMESPACE
112 
113 #endif /* IMPKERNEL_PARTICLE_INDEX_H */
Basic types used by IMP.
Smart pointer to Object-derived classes that does not refcount.
Definition: WeakPointer.h:76
IMP::Vector< ParticleIndexPair > ParticleIndexPairs
Definition: base_types.h:168
Take Decorator, Particle or ParticleIndex.
Index< ParticleIndexTag > ParticleIndex
Definition: base_types.h:161
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
A smart pointer to a reference counted object.
Definition: Pointer.h:87
Take Decorator, Particle or ParticleIndex.
ParticleIndexPairs get_indexes(const ParticlePairsTemp &ps)
Get the indexes from a list of particle pairs.
Interface to specialized Particle types (e.g. atoms)
Definition: Decorator.h:118
IMP::Vector< ParticlePair > ParticlePairsTemp
Definition: base_types.h:146
Take ParticlePairs or ParticleIndexPairs.
Class to handle individual particles of a Model object.
Definition: Particle.h:41
Convenience class to accept multiple input types.
Definition: InputAdaptor.h:25