IMP  2.0.1
The Integrative Modeling Platform
CustomXYZR.h
Go to the documentation of this file.
1 /**
2  * \file IMP/misc/CustomXYZR.h
3  * \brief Decorator for a sphere-like particle.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPMISC_CUSTOM_XYZ_R_H
10 #define IMPMISC_CUSTOM_XYZ_R_H
11 
12 #include <IMP/misc/misc_config.h>
13 #include <IMP/core/XYZ.h>
14 #include <IMP/core/XYZR.h>
15 #include <IMP/algebra/Sphere3D.h>
16 
17 #include <limits>
18 
19 IMPMISC_BEGIN_NAMESPACE
20 
21 //! A decorator for a particle with x,y,z coordinates and a radius.
22 /** \ingroup decorators
23 
24  A simple example illustrating some of the functionality.
25  \pythonexample{XYZR_Decorator}
26  */
27 class IMPMISCEXPORT CustomXYZR:
28  public core::XYZ
29 {
30 public:
32  radius_key, get_default_radius_key());
33 
34  /** Create a decorator using radius_key to store the FloatKey.
35  \param[in] p The particle to wrap.
36  \param[in] radius_key The (optional) key name to use.
37  The default is "radius".
38  */
40  FloatKey radius_key= get_default_radius_key()) {
41  if (!XYZ::particle_is_instance(p)) {
43  }
44  p->add_attribute(radius_key, 0, false);
45  return CustomXYZR(p, radius_key);
46  }
47 
48 
49  /** Create a decorator using radius_key to store the FloatKey.
50  The particle should already be an XYZ particle.
51  \param[in] p The particle to wrap.
52  \param[in] radius The radius to set initially
53  \param[in] radius_key The (optional) key name to use.
54  The default is "radius".
55  */
57  Float radius,
58  FloatKey radius_key= get_default_radius_key()) {
59  p->add_attribute(radius_key, radius, false);
60  return CustomXYZR(p, radius_key);
61  }
62 
63  /** Create a decorator using radius_key to store the FloatKey.
64  \param[in] p The particle to wrap.
65  \param[in] s The sphere to use to set the position and radius
66  \param[in] radius_key The (optional) key name to use.
67  The default is "radius".
68  */
70  const algebra::Sphere3D &s,
71  FloatKey radius_key= get_default_radius_key()) {
72  XYZ::setup_particle(p, s.get_center());
73  p->add_attribute(radius_key, s.get_radius(), false);
74  return CustomXYZR(p, radius_key);
75  }
76 
77  //! Check if the particle has the required attributes
78  static bool particle_is_instance(Particle *p,
79  FloatKey radius_key= get_default_radius_key()) {
80  return p->has_attribute(radius_key);
81  }
82  IMP_DECORATOR_GET_SET(radius, get_radius_key(), Float, Float);
83 
84 
85  //! Return a sphere object
87  return algebra::Sphere3D(get_coordinates(), get_radius());
88  }
89 
90  //! Set the attributes from a sphere
91  void set_sphere(const algebra::Sphere3D &s) {
92  set_coordinates(s.get_center());
93  set_radius(s.get_radius());
94  }
95  //! Get the default radius key.
97  return IMP::internal::xyzr_keys[3];
98  }
99  void add_to_radius_derivative(double v,
101  get_particle()->add_to_derivative(get_radius_key(), v, d);
102  }
103  FloatKey get_traits() {
104  return get_radius_key();
105  }
106 };
107 
108 IMP_DECORATORS(CustomXYZR,CustomXYZRs, core::XYZs);
109 
110 //! Compute the distance between a pair of particles
111 /** \relatesalso XYZR
112  */
113 inline double get_distance(CustomXYZR a, CustomXYZR b) {
115 }
116 
117 /** \genericgeometry */
119  return d.get_sphere();
120 }
121 
122 /** \genericgeometry */
124  d.set_sphere(v);
125 }
126 
127 IMPMISC_END_NAMESPACE
128 
129 #endif /* IMPMISC_CUSTOM_XYZ_R_H */