IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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 <memory>
15
16IMPKERNEL_BEGIN_NAMESPACE
17
18class Particle;
19class Decorator;
20
21//! Get the indexes from a list of particles.
22IMPKERNELEXPORT ParticleIndexes get_indexes(const ParticlesTemp &ps);
23
24//! Get the particles from a list of indexes.
25IMPKERNELEXPORT ParticlesTemp
27
28//! Get the indexes from a list of particle pairs.
30
31//! Take Decorator, Particle or ParticleIndex.
32class IMPKERNELEXPORT ParticleIndexAdaptor
33#ifndef SWIG
34 // suppress swig warning that doesn't make sense and I can't make go away
35 : public ParticleIndex,
36 InputAdaptor
37#endif
38 {
39 public:
40 ParticleIndexAdaptor(Particle *p);
41 ParticleIndexAdaptor(ParticleIndex pi) : ParticleIndex(pi) {}
42 ParticleIndexAdaptor(const Decorator &d);
43#if !defined(SWIG) && !defined(IMP_DOXYGEN) && !defined(IMP_SWIG_WRAPPER)
44 ParticleIndexAdaptor(WeakPointer<Particle> p);
45 ParticleIndexAdaptor(Pointer<Particle> p);
46#endif
47};
48
49//! Take Decorator, Particle or ParticleIndex.
50class IMPKERNELEXPORT ParticleIndexesAdaptor : public InputAdaptor {
51 std::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 }
63 ParticleIndexesAdaptor(const Particles &ps);
64#endif
65 ParticleIndexesAdaptor(const ParticlesTemp &ps);
66 ParticleIndexesAdaptor(const ParticleIndexes &pi)
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.
87class IMPKERNELEXPORT ParticleIndexPairsAdaptor
88#ifndef SWIG
89 // suppress swig warning that doesn't make sense and I can't make go away
90 : public ParticleIndexPairs,
91 InputAdaptor
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
105 ParticleIndexPairsAdaptor(const ParticlePairsTemp &ps);
106 ParticleIndexPairsAdaptor(const ParticleIndexPairs &pi)
107 : ParticleIndexPairs(pi) {}
108 ParticleIndexPairsAdaptor() {}
109};
110
111IMPKERNEL_END_NAMESPACE
112
113#endif /* IMPKERNEL_PARTICLE_INDEX_H */
Basic types used by IMP.
Interface to specialized Particle types (e.g. atoms).
Definition Decorator.h:119
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Class to handle individual particles of a Model object.
Definition Particle.h:45
Index< ParticleIndexTag > ParticleIndex
Definition base_types.h:196
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
Vector< Pointer< Particle > > Particles
A list of reference-counted Particle objects.
Definition base_types.h:138
IMP::Vector< ParticleIndexPair, std::allocator< ParticleIndexPair > > ParticleIndexPairs
Definition base_types.h:208
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Definition base_types.h:199
Array< 2, ParticleIndex > ParticleIndexPair
An ordered pair of particles, each identified by its ParticleIndex.
Definition base_types.h:202
IMP::Vector< ParticlePair > ParticlePairsTemp
Definition base_types.h:181
ParticleIndexes get_indexes(const ParticlesTemp &ps)
Get the indexes from a list of particles.
A smart pointer to a reference counted object.
Definition Pointer.h:88
Smart pointer to Object-derived classes that does not refcount.
Definition WeakPointer.h:78