IMP logo
IMP Reference Guide  2.22.0
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>
17 #include <IMP/decorator_macros.h>
18 
19 
20 IMPATOM_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 */
33 class 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 {
60  IMP::core::XYZ pxyz( get_particle() );
61  return pxyz.get_coordinate(i);
62  }
63 
64  const algebra::Vector3D &get_coordinates() const {
65  IMP::core::XYZ pxyz( get_particle() );
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  */
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 
110 IMP_DECORATORS( CenterOfMass, CenterOfMasses, UNUSED );
111 
112 IMPATOM_END_NAMESPACE
113 
114 #endif /* IMPATOM_CENTER_OF_MASS_H */
The base class for decorators.
Add mass to a particle.
Definition: Mass.h:23
A decorator for particles with mass.
double get_mass(ResidueType c)
Get the mass from the residue type.
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_CONSTRAINT_DECORATOR_DECL(Name)
Simple XYZ decorator.
Take Decorator, Particle or ParticleIndex.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
#define IMP_NO_DOXYGEN(x)
Hide something from doxygen.
Helper macros for implementing Decorators.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
Float get_coordinate(int i) const
Get the ith coordinate.
Definition: XYZ.h:69
const algebra::Vector3D & get_coordinates() const
Convert it to a vector.
Definition: XYZ.h:109
Particle * get_particle() const
Returns the particle decorated by this decorator.
Definition: Decorator.h:194
Interface to specialized Particle types (e.g. atoms)
Definition: Decorator.h:119
#define IMP_DECORATOR_METHODS(Name, Parent)
VectorD< 3 > Vector3D
Definition: VectorD.h:408
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:19
Abstract class to implement hierarchical methods.
Definition: Refiner.h:34
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
bool get_has_attribute(TypeKey attribute_key, ParticleIndex particle) const
return true if particle has attribute with the specified key
A particle that is the center of mass of other particles.
Definition: CenterOfMass.h:33
Set the coordinates of the particle to be the centroid of the refined particles.