IMP  2.1.0
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-2013 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 betweeen 0 and 1.
22  */
23 class IMPISDEXPORT Switching: public Nuisance
24 {
25  static void do_setup_particle(kernel::Model *m, kernel::ParticleIndex pi,
26  double switching=0.5)
27  {
28  if (!Nuisance::get_is_setup(m, pi))
29  Nuisance::setup_particle(m, pi,switching);
30  Nuisance(m, pi).set_lower(0.);
31  Nuisance(m, pi).set_upper(1.);
32  }
33 public:
36  IMP_DECORATOR_SETUP_1(Switching, double, switching);
37 
38  static bool get_is_setup(kernel::Model *m, kernel::ParticleIndex pi) {
39  return Nuisance::get_is_setup(m, pi) && Nuisance(m, pi).get_lower()>=0
40  && Nuisance(m, pi).get_upper()<=1;
41  }
42 
43  Float get_switching() const {
44  return Nuisance(get_particle()).get_nuisance();
45  }
46 
47  void set_switching(Float d) { set_nuisance(d); }
48 
49  void add_to_switching_derivative(Float d, DerivativeAccumulator &accum)
50  {
51  add_to_nuisance_derivative(d, accum);
52  }
53 
54  Float get_switching_derivative() const
55  {
56  return get_nuisance_derivative();
57  }
58 
59  static FloatKey get_switching_key() { return get_nuisance_key(); }
60 
61  bool get_switching_is_optimized() const
62  {
63  return get_nuisance_is_optimized();
64  }
65 
66  void set_switching_is_optimized(bool val)
67  {
68  set_nuisance_is_optimized(val);
69  }
70 
71 };
72 
73 IMP_DECORATORS(Switching, Switchings, Nuisances);
74 
75 IMPISD_END_NAMESPACE
76 
77 #endif /* IMPISD_SWITCHING_H */
Import IMP/kernel/Decorator.h in the namespace.
static Nuisance setup_particle(kernel::Model *m, ParticleIndex pi)
Definition: Nuisance.h:33
Import IMP/kernel/SingletonContainer.h in the namespace.
Particle * get_particle() const
IMP::kernel::DerivativeAccumulator DerivativeAccumulator
#define IMP_DECORATOR_METHODS(Name, Parent)
A decorator for nuisance parameters particles.
Add switching parameter to particle.
Definition: Switching.h:23
Import IMP/kernel/PairContainer.h in the namespace.
#define IMP_DECORATOR_SETUP_0(Name)
Add nuisance parameter to particle.
Definition: Nuisance.h:26
double Float
Basic floating-point value (could be float, double...)
Definition: base/types.h:20
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
Key< 0, true > FloatKey
The type used to identify float attributes in the Particles.
Class for storing model, its restraints, constraints, and particles.