IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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>
15#include <IMP/Decorator.h>
16#include <IMP/isd/Nuisance.h>
17
18IMPISD_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 */
23class 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:
33 IMP_DECORATOR_METHODS(Switching, Nuisance);
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
63IMP_DECORATORS(Switching, Switchings, Nuisances);
64
65IMPISD_END_NAMESPACE
66
67#endif /* IMPISD_SWITCHING_H */
The base class for decorators.
A decorator for nuisance parameters particles.
A container for Pairs.
A container for Singletons.
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Add nuisance parameter to particle.
Definition Nuisance.h:27
static Nuisance setup_particle(Model *m, ParticleIndex pi)
Definition Nuisance.h:33
#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