IMP logo
IMP Reference Guide  2.14.0
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-2020 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPISD_NUISANCE_H
9 #define IMPISD_NUISANCE_H
10 
11 #include "isd_config.h"
12 
13 #include <IMP/Decorator.h>
14 #include <IMP/decorator_macros.h>
15 
16 IMPISD_BEGIN_NAMESPACE
17 
18 //! Add nuisance parameter to particle
19 /** The value of the nuisance parameter may express data
20  or theory uncertainty. It can be initialized with or without
21  specifying its value. Default is 1. On construction, the Nuisance is
22  unbounded. It can be bounded with set_upper and set_lower. Setting it
23  to values outside of bounds results in setting it to the bound value.
24  */
25 class IMPISDEXPORT Nuisance : public Decorator {
26  static void do_setup_particle(Model *m, ParticleIndex pi,
27  double nuisance = 1.0);
28 
29  public:
32  IMP_DECORATOR_SETUP_1(Nuisance, double, nuisance);
33 
34  static bool get_is_setup(Model *m, ParticleIndex pi) {
35  return m->get_has_attribute(get_nuisance_key(), pi);
36  }
37 
38  static FloatKey get_nuisance_key();
39  Float get_nuisance() const {
40  return get_particle()->get_value(get_nuisance_key());
41  }
42  void set_nuisance(Float d);
43 
44  /** set upper and lower bound of nuisance by specifying
45  * either a float or another nuisance. Both can be set at the same
46  * time in which case the upper bound is the minimum of the two values.
47  * This constraint is enforced with the help of a ScoreState that will be
48  * created on-the-fly.
49  */
50  bool get_has_lower() const;
51  Float get_lower() const;
52  static FloatKey get_lower_key();
53  static ParticleIndexKey get_lower_particle_key();
54  void set_lower(Float d);
55  void set_lower(Particle *d);
56  void remove_lower();
57 
58  bool get_has_upper() const;
59  Float get_upper() const;
60  static FloatKey get_upper_key();
61  static ParticleIndexKey get_upper_particle_key();
62  void set_upper(Float d);
63  void set_upper(Particle *d);
64  void remove_upper();
65 
66  Float get_nuisance_derivative() const {
67  return get_particle()->get_derivative(get_nuisance_key());
68  }
69 
70  void add_to_nuisance_derivative(Float d, DerivativeAccumulator &accum) {
71  get_particle()->add_to_derivative(get_nuisance_key(), d, accum);
72  }
73 
74  bool get_nuisance_is_optimized() const {
75  return get_particle()->get_is_optimized(get_nuisance_key());
76  }
77 
78  void set_nuisance_is_optimized(bool val) {
79  get_particle()->set_is_optimized(get_nuisance_key(), val);
80  }
81 
82  friend class NuisanceScoreState;
83 
84  private:
85  // scorestate-related bookkeeping
86  static ObjectKey get_ss_key();
87  void enforce_bounds();
88  void remove_bounds();
89 };
90 
91 IMP_DECORATORS(Nuisance, Nuisances, ParticlesTemp);
92 
93 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
94 class IMPISDEXPORT NuisanceScoreState : public ScoreState {
95  private:
97 
98  private:
99  NuisanceScoreState(Particle *p)
100  : ScoreState(p->get_model(), "NuisanceScoreState%1%"), p_(p) {}
101 
102  public:
103  friend class Nuisance;
104  virtual void do_before_evaluate() IMP_OVERRIDE;
105  virtual void do_after_evaluate(DerivativeAccumulator *da) IMP_OVERRIDE;
106  virtual ModelObjectsTemp do_get_inputs() const IMP_OVERRIDE;
107  virtual ModelObjectsTemp do_get_outputs() const IMP_OVERRIDE;
108  IMP_OBJECT_METHODS(NuisanceScoreState);
109 };
110 #endif
111 
112 IMPISD_END_NAMESPACE
113 
114 #endif /* IMPISD_NUISANCE_H */
The base class for decorators.
Smart pointer to Object-derived classes that does not refcount.
Definition: WeakPointer.h:76
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition: base_types.h:86
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Add nuisance parameter to particle.
Definition: Nuisance.h:25
Various general useful macros for IMP.
#define IMP_DECORATOR_SETUP_0(Name)
Particle * get_particle() const
Returns the particle decorated by this decorator.
Definition: Decorator.h:171
Key< 4 > ObjectKey
The type used to identify an Object attribute.
Definition: base_types.h:48
Interface to specialized Particle types (e.g. atoms)
Definition: Decorator.h:118
#define IMP_DECORATOR_METHODS(Name, Parent)
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
Class to handle individual particles of a Model object.
Definition: Particle.h:41
#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
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.