IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
TripletContainer.h
Go to the documentation of this file.
1// Autogenerated by tools/build/make_containers.py
2// from tools/build/container_templates/kernel/ClassnameContainer.h
3// Do not edit - any changes will be lost!
4
5/**
6 * \file IMP/TripletContainer.h
7 * \brief A container for Triplets.
8 *
9 * Copyright 2007-2022 IMP Inventors. All rights reserved.
10 */
11
12#ifndef IMPKERNEL_TRIPLET_CONTAINER_H
13#define IMPKERNEL_TRIPLET_CONTAINER_H
14
15#include <IMP/kernel_config.h>
16#include "internal/IndexingIterator.h"
17#include "Particle.h"
18#include "container_base.h"
19#include "internal/container_helpers.h"
21#include "base_types.h"
23#include <IMP/check_macros.h>
24#include <IMP/Pointer.h>
25#include <IMP/InputAdaptor.h>
26#include <IMP/utility_macros.h>
28#include <algorithm>
29#include <cereal/access.hpp>
30#include <cereal/types/base_class.hpp>
31
32IMPKERNEL_BEGIN_NAMESPACE
33class TripletModifier;
34class TripletScore;
35
36//! A shared container for Triplets
37/** Stores a shared collection of Triplets.
38 */
39class IMPKERNELEXPORT TripletContainer : public Container {
40 public:
41 typedef ParticleTriplet ContainedType;
42 typedef ParticleTripletsTemp ContainedTypes;
43 typedef ParticleIndexTriplets ContainedIndexTypes;
44 typedef ParticleIndexTriplet ContainedIndexType;
45 typedef TripletModifier Modifier;
46 typedef const ParticleIndexTriplet& PassContainedIndexType;
47
48 //! Just use apply() in the base class
49 void apply_generic(const TripletModifier *m) const;
50
51 //! Just use apply_moved() in the base class
53 const ParticleIndexes &moved_pis,
54 const ParticleIndexes &reset_pis) const;
55
56 //! Apply a TripletModifier to the contents
57 void apply(const TripletModifier *sm) const;
58
59 //! Apply a TripletModifier to the contents
61 const ParticleIndexes &moved_pis,
62 const ParticleIndexes &reset_pis) const;
63
64 /** Get all the indexes that might possibly be contained in the
65 container, useful with dynamic containers. For example,
66 with a container::ClosePairContainer, this is the list
67 of all pairs taken from the input list (those that are far apart
68 in addition to those that are close).
69 */
71
72 const ParticleIndexTriplets &get_contents() const {
73 if (get_provides_access())
74 return get_access();
75 else {
76 std::size_t nhash = get_contents_hash();
77 if (contents_hash_ != nhash || !cache_initialized_) {
78 contents_hash_ = nhash;
79 cache_initialized_ = true;
80 get_indexes_in_place(contents_cache_); // inheriting class could implement this faster than get_indexes()
81 }
82 return contents_cache_;
83 }
84 }
85
86 /** Get all the indexes contained in the container.
87
88 This should be protected but isn't for compatibility reasons.
89
90 External callers should use get_contents().
91 */
93
94
95#ifndef IMP_DOXYGEN
96
97 ParticleTripletsTemp get() const {
98 return IMP::internal::get_particle(get_model(), get_indexes());
99 }
100
101 ParticleTriplet get(unsigned int i) const {
102 return IMP::internal::get_particle(get_model(), get_indexes()[i]);
103 }
104
105 //! Return size of current container content
106 //! Note that this may be expensive since it may involve
107 //! refreshing of the container
108 unsigned int get_number() const { return get_indexes().size(); }
109#ifndef SWIG
110 bool get_provides_access() const;
111 virtual const ParticleIndexTriplets &get_access() const {
112 IMP_THROW("Object not implemented properly.", IndexException);
113 }
114
115 template <class Functor>
116 Functor for_each(Functor f) {
118 // use boost range instead
119 return std::for_each(vs.begin(), vs.end(), f);
120 }
121
122#endif
123#endif
124
125 protected:
126 TripletContainer(Model *m,
127 std::string name = "TripletContainer %1%");
128 TripletContainer() {}
129
130 virtual void do_apply(const TripletModifier *sm) const = 0;
131 virtual void do_apply_moved(const TripletModifier *sm,
132 const ParticleIndexes &moved_pis,
133 const ParticleIndexes &reset_pis) const {
134 IMP_UNUSED(moved_pis);
135 IMP_UNUSED(reset_pis);
136 do_apply(sm);
137 }
138 virtual bool do_get_provides_access() const { return false; }
139
140#if !defined(SWIG) && !defined(IMP_DOXYGEN)
141 //! Insert the contents of the container into output
142 //! Could be reimplemented to save time in terms of e.g. memory
143 //! allocation compared with calling get_indexes()
144 virtual void get_indexes_in_place(ParticleIndexTriplets& output) const{
145 output= get_indexes();
146 }
147#endif
148
150
151 private:
152 mutable std::size_t contents_hash_;
153 mutable ParticleIndexTriplets contents_cache_;
154 mutable bool cache_initialized_;
155
156 friend class cereal::access;
157
158 template<class Archive> void serialize(Archive &ar) {
159 ar(cereal::base_class<Container>(this));
160 // clear cache on read
161 if (std::is_base_of<cereal::detail::InputArchiveBase, Archive>::value) {
162 contents_hash_ = -1;
163 cache_initialized_ = false;
164 }
165 }
166
167};
168
169/** This class allows either a list or a container to be
170 accepted as input.
171*/
172class IMPKERNELEXPORT TripletContainerAdaptor :
173#if !defined(SWIG) && !defined(IMP_DOXYGEN)
174 public Pointer<TripletContainer>
175#else
176 public InputAdaptor
177#endif
178 {
180
181 public:
182 TripletContainerAdaptor() {}
183
184 /**
185 Constructs the adaptor pointing to c (so if the contents of c are changed
186 dynamically, so do the contents of the adaptor, and vice versa)
187 */
189
190 /**
191 Constructs the adaptor pointing to c (so if the contents of c are changed
192 dynamically, so do the contents of the adaptor, and vice versa)
193 */
194 template <class C>
195 TripletContainerAdaptor(IMP::internal::PointerBase<C> c)
196 : P(c) {}
197
198 /**
199 Adapts the non-empty list t to TripletContainer
200
201 @param t a non-empty list of ParticleTripletsTemp
202 */
204
205 /** Set the name of the resulting container if it is currently the
206 default value. */
207 void set_name_if_default(std::string name);
208};
209
210IMPKERNEL_END_NAMESPACE
211
212#endif /* IMPKERNEL_TRIPLET_CONTAINER_H */
Class for adding derivatives from restraints to the model.
Convenience class to accept multiple input types.
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
A nullptr-initialized pointer to an IMP Object.
Basic types used by IMP.
Helper macros for throwing and handling exceptions.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
std::size_t get_contents_hash() const
void set_name_if_default(std::string name)
TripletContainerAdaptor(TripletContainer *c)
TripletContainerAdaptor(IMP::internal::PointerBase< C > c)
TripletContainerAdaptor(const ParticleTripletsTemp &t)
A shared container for Triplets.
void apply(const TripletModifier *sm) const
Apply a TripletModifier to the contents.
virtual ParticleIndexTriplets get_range_indexes() const =0
void apply_generic(const TripletModifier *m) const
Just use apply() in the base class.
void apply_moved(const TripletModifier *sm, const ParticleIndexes &moved_pis, const ParticleIndexes &reset_pis) const
Apply a TripletModifier to the contents.
void apply_generic_moved(const TripletModifier *m, const ParticleIndexes &moved_pis, const ParticleIndexes &reset_pis) const
Just use apply_moved() in the base class.
virtual ParticleIndexTriplets get_indexes() const =0
A base class for modifiers of ParticleTripletsTemp.
Abstract base class for containers of particles.
Control display of deprecation information.
Array< 3, ParticleIndex > ParticleIndexTriplet
An ordered triplet of particles, each identified by its ParticleIndex.
Definition base_types.h:204
IMP::Vector< ParticleTriplet > ParticleTripletsTemp
Definition base_types.h:184
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Definition base_types.h:199
Array< 3, WeakPointer< Particle >, Particle * > ParticleTriplet
Definition base_types.h:183
IMP::Vector< ParticleIndexTriplet, std::allocator< ParticleIndexTriplet > > ParticleIndexTriplets
Definition base_types.h:209
ParticleIndexes get_indexes(const ParticlesTemp &ps)
Get the indexes from a list of particles.
Macros to help with reference counting.
#define IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(Name)
A smart pointer to a reference counted object.
Definition Pointer.h:88
Various general useful macros for IMP.
#define IMP_UNUSED(variable)