IMP logo
IMP Reference Guide  develop.d97d4ead1f,2024/11/21
The Integrative Modeling Platform
Switching.h
Go to the documentation of this file.
1 /**
2  * \file IMP/isd/Switching.h
3  * \brief A decorator for switching parameters particles
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPISD_SWITCHING_H
9 #define IMPISD_SWITCHING_H
10 
11 #include <IMP/isd/isd_config.h>
12 
13 #include <IMP/PairContainer.h>
14 #include <IMP/SingletonContainer.h>
15 #include <IMP/Decorator.h>
16 #include <IMP/isd/Nuisance.h>
17 
18 IMPISD_BEGIN_NAMESPACE
19 
20 //! Add switching parameter to particle
21 /** This is just syntactic sugar for a Nuisance bounded to be between 0 and 1.
22  */
23 class IMPISDEXPORT Switching : public Nuisance {
24  static void do_setup_particle(Model *m, ParticleIndex pi,
25  double switching = 0.5) {
26  if (!Nuisance::get_is_setup(m, pi))
27  Nuisance::setup_particle(m, pi, switching);
28  Nuisance(m, pi).set_lower(0.);
29  Nuisance(m, pi).set_upper(1.);
30  }
31 
32  public:
35  IMP_DECORATOR_SETUP_1(Switching, double, switching);
36 
37  static bool get_is_setup(Model *m, ParticleIndex pi) {
38  return Nuisance::get_is_setup(m, pi) && Nuisance(m, pi).get_lower() >= 0 &&
39  Nuisance(m, pi).get_upper() <= 1;
40  }
41 
42  Float get_switching() const {
43  return Nuisance(get_particle()).get_nuisance();
44  }
45 
46  void set_switching(Float d) { set_nuisance(d); }
47 
48  void add_to_switching_derivative(Float d, DerivativeAccumulator &accum) {
49  add_to_nuisance_derivative(d, accum);
50  }
51 
52  Float get_switching_derivative() const { return get_nuisance_derivative(); }
53 
54  static FloatKey get_switching_key() { return get_nuisance_key(); }
55 
56  bool get_switching_is_optimized() const {
57  return get_nuisance_is_optimized();
58  }
59 
60  void set_switching_is_optimized(bool val) { set_nuisance_is_optimized(val); }
61 };
62 
63 IMP_DECORATORS(Switching, Switchings, Nuisances);
64 
65 IMPISD_END_NAMESPACE
66 
67 #endif /* IMPISD_SWITCHING_H */
The base class for decorators.
static Nuisance setup_particle(Model *m, ParticleIndex pi)
Definition: Nuisance.h:33
Key< 0 > FloatKey
The type used to identify float attributes in the Particles.
Definition: base_types.h:32
A container for Singletons.
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
A decorator for nuisance parameters particles.
Add switching parameter to particle.
Definition: Switching.h:23
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
A container for Pairs.
Add nuisance parameter to particle.
Definition: Nuisance.h:27
#define IMP_DECORATOR_SETUP_0(Name)
Particle * get_particle() const
Returns the particle decorated by this decorator.
Definition: Decorator.h:194
#define IMP_DECORATOR_METHODS(Name, Parent)
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:19
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.