IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
CentroidOfRefined.h
Go to the documentation of this file.
1/**
2 * \file IMP/core/CentroidOfRefined.h
3 * \brief Set the coordinates of the particle to be the centroid of the
4 * refined particles.
5 *
6 * Copyright 2007-2026 IMP Inventors. All rights reserved.
7 */
8
9#ifndef IMPCORE_CENTROID_OF_REFINED_H
10#define IMPCORE_CENTROID_OF_REFINED_H
11
12#include <IMP/core/core_config.h>
13#include "XYZ.h"
14#include <IMP/Refiner.h>
15#include <IMP/macros.h>
16#include <IMP/Pointer.h>
17#include <IMP/Decorator.h>
20#include <cereal/access.hpp>
21#include <cereal/types/base_class.hpp>
22
23
24IMPCORE_BEGIN_NAMESPACE
25
26//! Set a particle to be the centroid of the refined particles.
27/** Set the coordinates (or any float keys) of the particle to be the
28 centroid of the corresponding keys in a set of fine particles.
29 An exception is thrown if there are no refined particles. The weight
30 FloatKey can be used to reweight the centroid computation, or it can be set
31 to FloatKey() and then all the weights will be equal to 1.0.
32
33 \see CoverRefined
34 \see DerivativesToRefined
35 \see DerivativesFromRefined
36 */
37class IMPCOREEXPORT CentroidOfRefined : public SingletonModifier {
39 FloatKeys ks_;
40 FloatKey w_;
41
42 friend class cereal::access;
43 template<class Archive> void serialize(Archive &ar) {
44 ar(cereal::base_class<SingletonModifier>(this), refiner_, ks_, w_);
45 }
47
48 public:
49 //! Set the keys ks to be the average of the refined particles.
50 /**
51 @param r refiner used to retrieve the set of fine particles
52 @param weight a key used to reweight the contribution of each
53 fine particle to the centroid (eg, mass). In the
54 centroid, this key will be set by apply_index() to
55 the sum of all weights. A default weight of 1.0 is
56 used if weight equals FloatKey().
57 @param ks the keys over which the centroid is calculated
58 */
61
63
64 Refiner *get_refiner() const { return refiner_; }
65 FloatKey get_weight() const { return w_; }
66 FloatKeys get_keys() const { return ks_; }
67
68 bool get_is_weight_null() const { return w_ == FloatKey(); }
69
70 /**
71 Compute the weighted centroid of the keys of refine particles (as passed in
72 the constructor), and store the centroid values in the corresponding keys of
73 particle pi. The sum of all weight of the refined particles are stored
74 in the corresponding weight key of pi (it is assumed that pi has this key).
75
76 @param m the model of pi
77 @param pi the centroid particle
78 */
79 virtual void apply_index(Model *m, ParticleIndex pi) const
80 override;
81
83 Model *m, const ParticleIndexes &pis) const override;
84
86 Model *m, const ParticleIndexes &pis) const override;
87
89
91};
92
93//! A particle that is the geometric centroid of other particles.
94/** A decorator which constrains a particle to be the centroid of a
95 set of other particles. The centroid is updated before model
96 evaluation and its derivatives are copied to its children,
97 using a constraint that is created at setup time.
98
99 \usesconstraint
100*/
102 Centroid is computed before each evaluation);
103
104
105IMPCORE_END_NAMESPACE
106
107#endif /* IMPCORE_CENTROID_OF_REFINED_H */
The base class for decorators.
Accumulate the derivatives of the refined particles.
A nullptr-initialized pointer to an IMP Object.
Refine a particle into a list of particles.
A Modifier on ParticlesTemp.
Simple XYZ decorator.
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Abstract class to implement hierarchical methods.
Definition Refiner.h:36
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
virtual void apply_index(Model *m, ParticleIndex pi) const override
CentroidOfRefined(Refiner *r, FloatKey weight=FloatKey(), FloatKeys ks=XYZ::get_xyz_keys())
Set the keys ks to be the average of the refined particles.
virtual ModelObjectsTemp do_get_outputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the outputs.
A particle that is the geometric centroid of other particles.
A decorator for a particle with x,y,z coordinates.
Definition XYZ.h:30
static const FloatKeys & get_xyz_keys()
Get a vector containing the keys for x,y,z.
#define IMP_SUMMARIZE_DECORATOR_DECL(Name, Parent, Members, SetupDoc)
Create a decorator that computes some sort of summary info on a set.
Various general useful macros for IMP.
Index< ParticleIndexTag > ParticleIndex
Definition base_types.h:196
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Definition base_types.h:199
Key< 0 > FloatKey
The type used to identify float attributes in the Particles.
Definition base_types.h:32
IMP::Vector< FloatKey > FloatKeys
Definition base_types.h:33
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition base_types.h:122
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
#define IMP_SINGLETON_MODIFIER_METHODS(Name)
A smart pointer to a ref-counted Object that is a class member.
Definition Pointer.h:144