IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
Nuisance.h
Go to the documentation of this file.
1/**
2 * \file IMP/isd/Nuisance.h
3 * \brief A decorator for nuisance parameters particles
4 *
5 * Copyright 2007-2026 IMP Inventors. All rights reserved.
6 */
7
8#ifndef IMPISD_NUISANCE_H
9#define IMPISD_NUISANCE_H
10
11#include <IMP/isd/isd_config.h>
12
13#include <IMP/Decorator.h>
15#include <cereal/access.hpp>
16#include <cereal/types/base_class.hpp>
17
18IMPISD_BEGIN_NAMESPACE
19
20//! Add nuisance parameter to particle
21/** The value of the nuisance parameter may express data
22 or theory uncertainty. It can be initialized with or without
23 specifying its value. Default is 1. On construction, the Nuisance is
24 unbounded. It can be bounded with set_upper and set_lower. Setting it
25 to values outside of bounds results in setting it to the bound value.
26 */
27class IMPISDEXPORT Nuisance : public Decorator {
28 static void do_setup_particle(Model *m, ParticleIndex pi,
29 double nuisance = 1.0);
30
31 public:
32 IMP_DECORATOR_METHODS(Nuisance, Decorator);
34 IMP_DECORATOR_SETUP_1(Nuisance, double, nuisance);
35
36 static bool get_is_setup(Model *m, ParticleIndex pi) {
37 return m->get_has_attribute(get_nuisance_key(), pi);
38 }
39
40 static FloatKey get_nuisance_key();
41 Float get_nuisance() const {
42 return get_model()->get_attribute(get_nuisance_key(), get_particle_index());
43 }
44 void set_nuisance(Float d);
45
46 /** set upper and lower bound of nuisance by specifying
47 * either a float or another nuisance. Both can be set at the same
48 * time in which case the upper bound is the minimum of the two values.
49 * This constraint is enforced with the help of a ScoreState that will be
50 * created on-the-fly.
51 */
52 bool get_has_lower() const;
53 bool get_has_lower_float() const;
54 bool get_has_lower_particle() const;
55 Float get_lower() const;
56 static FloatKey get_lower_key();
57 static ParticleIndexKey get_lower_particle_key();
58 void set_lower(Float d);
59 void set_lower(Particle *d);
60 void remove_lower();
61
62 bool get_has_upper() const;
63 bool get_has_upper_float() const;
64 bool get_has_upper_particle() const;
65 Float get_upper() const;
66 static FloatKey get_upper_key();
67 static ParticleIndexKey get_upper_particle_key();
68 void set_upper(Float d);
69 void set_upper(Particle *d);
70 void remove_upper();
71
72 Float get_nuisance_derivative() const {
73 return get_particle()->get_derivative(get_nuisance_key());
74 }
75
76 void add_to_nuisance_derivative(Float d, DerivativeAccumulator &accum) {
77 get_particle()->add_to_derivative(get_nuisance_key(), d, accum);
78 }
79
80 bool get_nuisance_is_optimized() const {
81 return get_particle()->get_is_optimized(get_nuisance_key());
82 }
83
84 void set_nuisance_is_optimized(bool val) {
85 get_particle()->set_is_optimized(get_nuisance_key(), val);
86 }
87
88 friend class NuisanceScoreState;
89
90 private:
91 // scorestate-related bookkeeping
92 static ObjectKey get_ss_key();
93 void enforce_bounds();
94 void remove_bounds();
95};
96
97IMP_DECORATORS(Nuisance, Nuisances, ParticlesTemp);
98
99//! Constrain a Nuisance to lie within its bounds
100class IMPISDEXPORT NuisanceScoreState : public ScoreState {
101 ParticleIndex pi_;
102
103 friend class cereal::access;
104 template<class Archive> void serialize(Archive &ar) {
105 ar(cereal::base_class<ScoreState>(this), pi_);
106 }
107 IMP_OBJECT_SERIALIZE_DECL(NuisanceScoreState);
108
109 public:
110 NuisanceScoreState(Particle *p)
111 : ScoreState(p->get_model(), "NuisanceScoreState%1%"),
112 pi_(p->get_index()) {}
113
114 NuisanceScoreState() {}
115
116 ParticleIndex get_index() const { return pi_; }
117
118 friend class Nuisance;
119 virtual void do_before_evaluate() override;
120 virtual void do_after_evaluate(DerivativeAccumulator *da) override;
121 virtual ModelObjectsTemp do_get_inputs() const override;
122 virtual ModelObjectsTemp do_get_outputs() const override;
123 IMP_OBJECT_METHODS(NuisanceScoreState);
124};
125
126IMPISD_END_NAMESPACE
127
128#endif /* IMPISD_NUISANCE_H */
The base class for decorators.
Particle * get_particle() const
Returns the particle decorated by this decorator.
Definition Decorator.h:194
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
virtual ModelObjectsTemp do_get_outputs() const override
virtual ModelObjectsTemp do_get_inputs() const override
virtual void do_after_evaluate(DerivativeAccumulator *da) override
Do any necessary updates after the model score is calculated.
virtual void do_before_evaluate() override
Update the state given the current state of the model.
bool get_has_lower() const
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)
Index< ParticleIndexTag > ParticleIndex
Definition base_types.h:196
double Float
Basic floating-point value (could be float, double...).
Definition types.h:19
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< 3 > ParticleIndexKey
The type used to identify a particle attribute in the Particles.
Definition base_types.h:44
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.