IMP  2.0.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 public:
27 
28  static Switching setup_particle(Particle *p, double switching=0.5)
29  {
30  if (!Nuisance::particle_is_instance(p))
31  Nuisance::setup_particle(p,switching);
32  Nuisance(p).set_lower(0.);
33  Nuisance(p).set_upper(1.);
34  return Switching(p);
35  }
36 
37  static bool particle_is_instance(Particle *p) {
38  return Nuisance::particle_is_instance(p) && Nuisance(p).get_lower()>=0
39  && Nuisance(p).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  {
50  add_to_nuisance_derivative(d, accum);
51  }
52 
53  Float get_switching_derivative() const
54  {
55  return get_nuisance_derivative();
56  }
57 
58  static FloatKey get_switching_key() { return get_nuisance_key(); }
59 
60  bool get_switching_is_optimized() const
61  {
62  return get_nuisance_is_optimized();
63  }
64 
65  void set_switching_is_optimized(bool val)
66  {
67  set_nuisance_is_optimized(val);
68  }
69 
70 };
71 
72 IMP_DECORATORS(Switching, Switchings, Nuisances);
73 
74 IMPISD_END_NAMESPACE
75 
76 #endif /* IMPISD_SWITCHING_H */