IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
Weight.h
Go to the documentation of this file.
1/**
2 * \file IMP/isd/Weight.h
3 * \brief Add weights constrained to the unit simplex to a particle.
4 *
5 * Copyright 2007-2022 IMP Inventors. All rights reserved.
6 *
7 */
8
9#ifndef IMPISD_WEIGHT_H
10#define IMPISD_WEIGHT_H
11
12#include <IMP/isd/isd_config.h>
14#include <IMP/Particle.h>
16#include <IMP/Model.h>
17#include <IMP/Decorator.h>
18
19IMPISD_BEGIN_NAMESPACE
20
21static const int IMPISD_MAX_WEIGHTS = 1000;
22
23//! Add weights to a particle.
24/** Weights are constrained to the unit simplex.
25
26 \see algebra::UnitSimplexD
27 \ingroup decorators
28*/
29class IMPISDEXPORT Weight : public Decorator {
30
31 static void do_setup_particle(Model *m, ParticleIndex pi);
32
33 static void do_setup_particle(Model *m, ParticleIndex pi, Int nweights);
34
35 static void do_setup_particle(Model *m, ParticleIndex pi,
36 const algebra::VectorKD& w);
37
38 //! Add unit simplex constraint.
39 static void add_constraint(Model *m, ParticleIndex pi);
40
41 static ObjectKey get_constraint_key();
42
43 public:
44 IMP_DECORATOR_METHODS(Weight, Decorator);
45
46 //! Set up an empty Weight.
47 /** Weights must be added with add_weight() before use. */
49
50 //! Set up Weight with a fixed number of weights.
51 /** All weights are initialized with the same value. */
52 IMP_DECORATOR_SETUP_1(Weight, Int, nweights);
53
54 //! Set up Weight from the provided weight vector.
56
57 //! Get number of weights key
59
60 //! Get ith weight key
61 static FloatKey get_weight_key(int i);
62
63 //! Get all weight keys
65
66 //! Get the ith weight
67 Float get_weight(int i) const;
68
69 //! Get all weights
71
72 //! Set the ith weight lazily.
73 /** Delay enforcing the simplex constraint until Model::update(). */
74 void set_weight_lazy(int i, Float wi);
75
76 //! Set all the weights
77 /** Delay enforcing the simplex constraint until Model::update(). */
79
80 //! Set all weights, enforcing the simplex constraint
81 /** \see algebra::get_projected */
83
84 //! Get weights are optimized
86
87 //! Set weights are optimized
89
90 //! Get derivative wrt ith weight.
92
93 //! Get derivatives wrt all weights.
95
96 //! Add to derivative wrt ith weight.
98 const DerivativeAccumulator &da);
99
100 //! Add to derivatives wrt all weights.
102 const DerivativeAccumulator &da);
103
104 //! Extend the weight vector by one element lazily.
105 /** This should only be called during set-up and cannot be called
106 for an optimized Weight.
107 This version delays enforcing the simplex constraint until
108 Model::update().
109 */
110 void add_weight_lazy(Float wi = 0);
111
112 //! Extend the weight vector by one element.
113 /** This should only be called during set-up and cannot be called
114 for an optimized Weight.
115 */
116 void add_weight(Float wi = 0);
117
118 //! Get number of weights.
120
121 //! Get unit simplex on which weight vector lies.
122 algebra::UnitSimplexKD get_unit_simplex() const;
123
124 //! Set number of weights lazily
125 /** This should only be called during set-up and cannot be called
126 for an optimized Weight. New weights are initialized to 0.
127 This version delays enforcing the simplex constraint until
128 Model::update().
129 */
131
132 //! Set number of weights.
133 /** This should only be called during set-up and cannot be called
134 for an optimized Weight. New weights are initialized to 0.
135 */
137
138 static bool get_is_setup(Model *m, ParticleIndex pi);
139};
140
141IMP_DECORATORS(Weight, Weights, Decorators);
142
143
144#if !defined(IMP_DOXYGEN) && !defined(SWIG)
145class IMPISDEXPORT WeightSimplexConstraint : public IMP::Constraint {
146 private:
147 ParticleIndex pi_;
148
149 private:
150 WeightSimplexConstraint(Particle *p)
151 : IMP::Constraint(p->get_model(), "WeightSimplexConstraint%1%")
152 , pi_(p->get_index()) {}
153
154 public:
155 friend class Weight;
156 virtual void do_update_attributes() override;
157 virtual void do_update_derivatives(DerivativeAccumulator *da) override;
158 virtual ModelObjectsTemp do_get_inputs() const override;
159 virtual ModelObjectsTemp do_get_outputs() const override;
160 IMP_OBJECT_METHODS(WeightSimplexConstraint);
161};
162#endif
163
164IMPISD_END_NAMESPACE
165
166#endif /* IMPISD_WEIGHT_H */
The base class for decorators.
Storage of a model, its restraints, constraints and particles.
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
Simple unit simplex class.
Implement a constraint on the Model.
Definition Constraint.h:49
Class for adding derivatives from restraints to the model.
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
Add weights to a particle.
Definition Weight.h:29
void set_weights_lazy(const algebra::VectorKD &w)
Set all the weights.
void set_number_of_weights_lazy(Int nweights)
Set number of weights lazily.
void add_to_weight_derivative(int i, Float dwi, const DerivativeAccumulator &da)
Add to derivative wrt ith weight.
Float get_weight_derivative(int i) const
Get derivative wrt ith weight.
Float get_weight(int i) const
Get the ith weight.
void set_weights(const algebra::VectorKD &w)
Set all weights, enforcing the simplex constraint.
algebra::UnitSimplexKD get_unit_simplex() const
Get unit simplex on which weight vector lies.
void set_weights_are_optimized(bool tf)
Set weights are optimized.
FloatKeys get_weight_keys() const
Get all weight keys.
static IntKey get_number_of_weights_key()
Get number of weights key.
void set_number_of_weights(Int nweights)
Set number of weights.
bool get_weights_are_optimized() const
Get weights are optimized.
Int get_number_of_weights() const
Get number of weights.
void set_weight_lazy(int i, Float wi)
Set the ith weight lazily.
void add_weight_lazy(Float wi=0)
Extend the weight vector by one element lazily.
algebra::VectorKD get_weights() const
Get all weights.
void add_weight(Float wi=0)
Extend the weight vector by one element.
void add_to_weights_derivatives(const algebra::VectorKD &dw, const DerivativeAccumulator &da)
Add to derivatives wrt all weights.
algebra::VectorKD get_weights_derivatives() const
Get derivatives wrt all weights.
static FloatKey get_weight_key(int i)
Get ith weight key.
Helper macros for implementing Decorators.
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_DECORATOR_SETUP_0(Name)
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
#define IMP_DECORATOR_METHODS(Name, Parent)
Base functionality and abstract base classes for representation, scoring and sampling.
Index< ParticleIndexTag > ParticleIndex
Definition base_types.h:196
double Float
Basic floating-point value (could be float, double...).
Definition types.h:19
int Int
Basic integer value.
Definition types.h:34
VectorD<-1 > VectorKD
Definition VectorD.h:423
Key< 0 > FloatKey
The type used to identify float attributes in the Particles.
Definition base_types.h:32
Key< 4 > ObjectKey
The type used to identify an Object attribute.
Definition base_types.h:48
Key< 1 > IntKey
The type used to identify int attributes in the Particles.
Definition base_types.h:36
IMP::Vector< FloatKey > FloatKeys
Definition base_types.h:33
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition base_types.h:122
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.