IMP logo
IMP Reference Guide  2.18.0
The Integrative Modeling Platform
Diffusion.h
Go to the documentation of this file.
1 /**
2  * \file IMP/atom/Diffusion.h
3  * \brief A decorator for a diffusing particle.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPATOM_DIFFUSION_H
10 #define IMPATOM_DIFFUSION_H
11 
12 #include <IMP/atom/atom_config.h>
13 
14 #include <IMP/core/XYZR.h>
15 #include <IMP/algebra/Vector3D.h>
16 #include <IMP/internal/constants.h>
17 
18 #include <vector>
19 #include <limits>
20 
21 IMPATOM_BEGIN_NAMESPACE
22 
23 //! A decorator for a diffusing particle with a diffusion coefficient.
24 /** \ingroup helper
25  \ingroup decorators
26  \see BrownianDynamics
27 
28  Diffusion is used to decorate a diffusing particle with a diffusion
29  coefficient D. D is assumed to be in units of \f$A^2/fs\f$.
30 
31  \see RigidBodyDiffusion
32  */
33 class IMPATOMEXPORT Diffusion : public IMP::core::XYZ {
34  static void do_setup_particle(Model *m, ParticleIndex pi,
35  Float D) {
36  IMP_USAGE_CHECK(XYZ::get_is_setup(m, pi),
37  "Particle must already be an XYZ particle");
38  m->add_attribute(get_diffusion_coefficient_key(), pi, D);
39  }
40  static void do_setup_particle(Model *m, ParticleIndex pi,
41  const algebra::Vector3D &v, Float D) {
42  XYZ::setup_particle(m, pi, v);
43  do_setup_particle(m, pi, D);
44  }
45 
46  /**
47  Same as do_setup_particle(m, pi, D) but D is automatically set
48  to IMP::atom::get_einstein_diffusion_coefficient(radius) for radius
49  IMP::core::XYZR(m, pi).get_radius().
50 
51  Note a different D should probably be set manually if the temperature is
52  not the default IMP temperature (297.15).
53  */
54  static void do_setup_particle(Model *m, ParticleIndex pi);
55 
56  public:
58  /**
59  Decorates the particle as a Diffusion particle with a
60  diffusion coefficient D.
61  */
63  /**
64  Decorates the particle as a core::XYZ particle with
65  coordinates v and as a Diffusion particle with a
66  diffusion coefficient D.
67  */
69  /**
70  Decorates the particle as a Diffusion particle with the
71  diffusion coefficient of a particle with a stokes radius
72  of core::XYZR(m, pi).get_radius() at the default IMP
73  temperature (297.15K).
74 
75  \Note: It assumed particle is already a core::XYZR particle.
76  */
78 
79  //! Return true if the particle is an instance of Diffusion
80  static bool get_is_setup(Model *m, ParticleIndex p) {
81  return m->get_has_attribute(get_diffusion_coefficient_key(), p);
82  }
83  //! set diffusion coefficient in \f$A^2/fs\f$
84  void set_diffusion_coefficient(double d) {
85  get_particle()->set_value(get_diffusion_coefficient_key(), d);
86 
87  }
88  //! get diffusion coefficient in \f$A^2/fs\f$
89  double get_diffusion_coefficient() const {
90  return get_model()->get_attribute(get_diffusion_coefficient_key(),
92  }
93  //! Get the D key
94  static FloatKey get_diffusion_coefficient_key();
95 };
96 
97 IMPATOMEXPORT double get_diffusion_coefficient_from_cm2_per_second(double din);
98 
99 IMP_DECORATORS(Diffusion, Diffusions, core::XYZs);
100 
101 /** A rigid body that is diffusing, so it also has a rotation diffusion
102  coefficient. The units on the rotational coefficient are
103  \f$radians^2/fs\f$.
104 
105  The translational and rotational diffusion coefficients are set automatically
106  using IMP::atom::get_einstein_diffusion_coefficient(radius) and
107  IMP::atom::get_einstein_rotational_diffusion_coefficient(radius) for radius
108  IMP::core::XYZR(m, pi).get_radius().
109 
110  Note that different translational and rotational coefficients should probably
111  be set manually if the temperature is not the default IMP temperature.
112 */
113 class IMPATOMEXPORT RigidBodyDiffusion : public Diffusion {
114  static void do_setup_particle(Model *m, ParticleIndex pi);
115 
116  public:
118  //! All diffusion coefficients are determined from the radius
120 
121  //! returns the rotational diffusion coefficient in \f$radians^2/fs\f$
123  return get_model()->get_attribute
124  (get_rotational_diffusion_coefficient_key(),
126  }
127 
128 
129  //! sets the rotational diffusion coefficient in \f$radians^2/fs\f$
131  return get_particle()->set_value(get_rotational_diffusion_coefficient_key(),
132  d);
133  }
134 
135  //! Return true if the particle is an instance of an Diffusion
136  static bool get_is_setup(Model *m, ParticleIndex p) {
137  return m->get_has_attribute(get_rotational_diffusion_coefficient_key(), p);
138  }
139 
140  //! Get the D key
141  static FloatKey get_rotational_diffusion_coefficient_key();
142 };
143 
144 IMP_DECORATORS(RigidBodyDiffusion, RigidBodyDiffusions, Diffusions);
145 
146 IMPATOM_END_NAMESPACE
147 
148 #endif /* IMPATOM_DIFFUSION_H */
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition: Decorator.h:190
static bool get_is_setup(Model *m, ParticleIndex p)
Return true if the particle is an instance of an Diffusion.
Definition: Diffusion.h:136
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
Model * get_model() const
Returns the Model containing the particle.
Definition: Decorator.h:193
static XYZ setup_particle(Model *m, ParticleIndex pi)
Definition: XYZ.h:51
double get_diffusion_coefficient() const
get diffusion coefficient in
Definition: Diffusion.h:89
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:73
void set_rotational_diffusion_coefficient(double d) const
sets the rotational diffusion coefficient in
Definition: Diffusion.h:130
void set_diffusion_coefficient(double d)
set diffusion coefficient in
Definition: Diffusion.h:84
void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
add particle atribute with the specied key and initial value
#define IMP_DECORATOR_SETUP_2(Name, FirstArgumentType, first_argument_name,SecondArgumentType, second_argument_name)
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
#define IMP_DECORATOR_SETUP_0(Name)
static bool get_is_setup(Model *m, ParticleIndex p)
Return true if the particle is an instance of Diffusion.
Definition: Diffusion.h:80
Particle * get_particle() const
Returns the particle decorated by this decorator.
Definition: Decorator.h:173
#define IMP_DECORATOR_METHODS(Name, Parent)
VectorD< 3 > Vector3D
Definition: VectorD.h:421
double get_rotational_diffusion_coefficient() const
returns the rotational diffusion coefficient in
Definition: Diffusion.h:122
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:19
Simple 3D vector class.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
#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
A decorator for a diffusing particle with a diffusion coefficient.
Definition: Diffusion.h:33
Type get_attribute(TypeKey attribute_key, ParticleIndex particle)
get the value of the particle attribute with the specified key
Decorator for a sphere-like particle.