IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
CenterOfMass.h
Go to the documentation of this file.
1/**
2 * \file IMP/atom/CenterOfMass.h
3 * \brief A decorator for particles with mass
4 *
5 * Copyright 2007-2022 IMP Inventors. All rights reserved.
6 */
7
8#ifndef IMPATOM_CENTER_OF_MASS_H
9#define IMPATOM_CENTER_OF_MASS_H
10
11#include <IMP/atom/atom_config.h>
12
14#include <IMP/core/XYZ.h>
15#include <IMP/atom/Mass.h>
16#include <IMP/Decorator.h>
18
19
20IMPATOM_BEGIN_NAMESPACE
21
22//! A particle that is the center of mass of other particles.
23/** A decorator which constrains a particle to be the center of mass of a
24 set of other particles, and whose mass is the sum of their masses.
25 The c.o.m. is updated before model
26 evaluation and its derivatives are copied to its children,
27 using a constraint that is created at setup time. The derivatives
28 propagated to each particle are scaled based on its mass relative
29 to the total mass.
30
31 \usesconstraint
32*/
33class IMPATOMEXPORT CenterOfMass : public IMP::Decorator {
35 private:
36 //! Sets up CenterOfMass over particles in pis.
37 /** pi is decorated with core::XYZ and atom::Mass decorators, its
38 coordinates are set to the current center of mass of pis, and
39 its mass is set to the sum of their masses.
40 */
41 static void do_setup_particle(Model *m, ParticleIndex pi,
42 const ParticleIndexes &pis);
43
44 /** Sets up CenterOfMass over particles passed by applying the refiner
45 over the particle pi. pi is set to have core::XYZ and atom::Mass
46 decorators, its coordinates are set to the current center of
47 mass of ref->get_refined_indexes(m, pi), and its mass is set to
48 the sum of their masses.
49 */
50 static void do_setup_particle(Model *m, ParticleIndex pi,
51 Refiner *ref);
52
53 public:
54 Float get_mass() const {
56 return pm.get_mass();
57 }
58
59 Float get_coordinate(int i) const {
61 return pxyz.get_coordinate(i);
62 }
63
64 const algebra::Vector3D &get_coordinates() const {
66 return pxyz.get_coordinates();
67 }
68
69
70 public:
72
73 /** Sets up CenterOfMass over members, and constrains CenterOfMass to be
74 computed before model evaluation and to propagate derivatives
75 following model evaluation.
76
77 pi is decorated with core::XYZ and atom::Mass decorators, its
78 coordinates are set to the current center of mass of pis, and
79 its mass is set to the sum of their masses.
80 */
82
83 /** Sets up CenterOfMass over particles passed by applying the refiner
84 over the particle pi, and constrains CenterOfMass to be computed before
85 model evaluation and to propagate derivatives following model
86 evaluation.
87
88 pi is decorated with the core::XYZ and atom::Mass decorators,
89 its coordinates are set to the current center of mass of
90 refiner->get_refined_indexes(m, pi), and its mass is set to
91 the sum of their masses.
92 */
93 IMP_DECORATOR_SETUP_1(CenterOfMass, Refiner *, refiner);
94
95 //! Make the particle no longer a center of mass.
96 static void teardown_particle(CenterOfMass com);
97
98 static bool get_is_setup(Model *m, ParticleIndex pi) {
99 return m->get_has_attribute(get_constraint_key(), pi) &&
100 IMP::atom::Mass::get_is_setup(m, pi) &&
101 IMP::core::XYZ::get_is_setup(m, pi); }
102
103
104
105 IMP_NO_DOXYGEN(typedef std::false_type DecoratorHasTraits);
106
107 };
108
109
110IMP_DECORATORS( CenterOfMass, CenterOfMasses, UNUSED );
111
112IMPATOM_END_NAMESPACE
113
114#endif /* IMPATOM_CENTER_OF_MASS_H */
Set the coordinates of the particle to be the centroid of the refined particles.
The base class for decorators.
A decorator for particles with mass.
Simple XYZ decorator.
Interface to specialized Particle types (e.g. atoms).
Definition Decorator.h:119
Particle * get_particle() const
Returns the particle decorated by this decorator.
Definition Decorator.h:194
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Take Decorator, Particle or ParticleIndex.
Abstract class to implement hierarchical methods.
Definition Refiner.h:36
static void teardown_particle(CenterOfMass com)
Make the particle no longer a center of mass.
Add mass to a particle.
Definition Mass.h:23
A decorator for a particle with x,y,z coordinates.
Definition XYZ.h:30
const algebra::Vector3D & get_coordinates() const
Convert it to a vector.
Definition XYZ.h:109
Float get_coordinate(int i) const
Get the ith coordinate.
Definition XYZ.h:69
Helper macros for implementing Decorators.
#define IMP_CONSTRAINT_DECORATOR_DECL(Name)
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
#define IMP_DECORATOR_METHODS(Name, Parent)
#define IMP_NO_DOXYGEN(x)
Hide something from doxygen.
Index< ParticleIndexTag > ParticleIndex
Definition base_types.h:196
double Float
Basic floating-point value (could be float, double...).
Definition types.h:19
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Definition base_types.h:199
VectorD< 3 > Vector3D
Definition VectorD.h:407