IMP Reference Guide  2.5.0 The Integrative Modeling Platform
XYZR.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/XYZR.h
3  * \brief Decorator for a sphere-like particle.
4  *
6  *
7  */
8
9 #ifndef IMPCORE_XYZ_R_H
10 #define IMPCORE_XYZ_R_H
11
12 #include "XYZ.h"
13 #include <IMP/algebra/Sphere3D.h>
17 #include <limits>
18
19 IMPCORE_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  \include XYZR_Decorator.py
26  */
27 class IMPCOREEXPORT XYZR : public XYZ {
28  static void do_setup_particle(Model *m, ParticleIndex pi,
29  const algebra::Sphere3D s) {
30  XYZ::setup_particle(m, pi, s.get_center());
32  }
33
34  static void do_setup_particle(Model *m, ParticleIndex pi,
35  double r) {
37  }
38
39  static void do_setup_particle(Model *m, ParticleIndex pi) {
40  if (!XYZ::get_is_setup(m, pi)) {
41  XYZ::setup_particle(m, pi);
42  }
44  }
45
46  public:
49  /** Setup an XYZ particle as an XYZR particle. */
52
53  /** Add the coordinates and radius from the sphere to the particle.
54  */
55
56  //! Check if the particle has the required attributes
57  static bool get_is_setup(Model *m, ParticleIndex pi) {
59  }
60
62  void set_radius(double r) const {
63  get_model()->get_sphere(get_particle_index())[3] = r;
64  }
65
66  //! Return a sphere object
67  const algebra::Sphere3D &get_sphere() const {
68  return get_model()->get_sphere(get_particle_index());
69  }
70
71  //! Set the attributes from a sphere
72  void set_sphere(const algebra::Sphere3D &s) {
73  get_model()->get_sphere(get_particle_index()) = s;
74  }
75  //! Get the key for the radius.
76  static FloatKey get_radius_key() { return IMP::internal::xyzr_keys[3]; }
79  }
80 };
81
82 IMP_DECORATORS(XYZR, XYZRs, XYZs);
83
84 //! Compute the sphere distance between a and b
85 /** \see XYZR
86  */
87 inline double get_distance(XYZR a, XYZR b) {
89 }
90
91 //! Set the coordinates and radius of the first to enclose the list
92 /** \param[in] v The vector of XYZ or XYZR particles to enclose
93  \param[out] b The one whose values should be set
95  Any particle which does not have the attribute b.get_radius()
96  is assumed to have a radius of 0.
97
98  \note This function produces tighter bounds if the \ref cgal "CGAL"
99  library is available.
100  \ingroup CGAL
101  \see XYZR
102  */
103 IMPCOREEXPORT void set_enclosing_sphere(XYZR b, const XYZs &v,
104  double slack = 0);
105
106 //! Set the radius of the first to enclose the list
107 /** \param[in] v The vector of XYZ or XYZR particles to enclose
108  \param[out] b The one whose radius should be set
109  Any particle which does not have the attribute b.get_radius()
110  is assumed to have a radius of 0.
111
112  \see XYZR
113  */
114 IMPCOREEXPORT void set_enclosing_radius(XYZR b, const XYZs &v);
115
116 //! Get a sphere enclosing the set of XYZRs
117 /** \param[in] v The one whose radius should be set
118  Any particle which does not have the attribute b.get_radius()
119  is assumed to have a radius of 0.
120
121  \see XYZR
122  */
123 IMPCOREEXPORT algebra::Sphere3D get_enclosing_sphere(const XYZs &v);
124
125 //! Create a set of particles with random coordinates
126 /** This function is mostly to be used to keep demo code brief.
127  \param[in] m The model to add them to.
128  \param[in] num The number of particles to create.
130  \param[in] box_side The particles have coordinates from -box_side
131  to box_side.
132  \see XYZR
133
134  The particles coordinates are optimized.
135  */
136 IMPCOREEXPORT XYZRs create_xyzr_particles(Model *m, unsigned int num,
137  Float radius, Float box_side = 10);
138
139 /** \class XYZRGeometry
140  \brief Display an IMP::core::XYZR particle as a ball.
141
142  \class XYZRsGeometry
143  \brief Display an IMP::SingletonContainer of IMP::core::XYZR particles
144  as balls.
145 */
146 IMP_PARTICLE_GEOMETRY(XYZR, core::XYZR, {
147  display::SphereGeometry *g = new display::SphereGeometry(d.get_sphere());
148  ret.push_back(g);
149 });
150
151 IMP_PARTICLE_GEOMETRY(XYZDerivative, core::XYZ, {
152  algebra::Segment3D s(d.get_coordinates(),
153  d.get_coordinates() + d.get_derivatives());
155  ret.push_back(g);
156 });
157
158 /** \class EdgePairGeometry
159  \brief Display a segment connecting a pair of particles.
160
161  \class EdgePairsGeometry
162  \brief Display a segment for each pair in a
163  IMP::PairContainer.
164 */
165 IMP_PARTICLE_PAIR_GEOMETRY(EdgePair, core::XYZ, {
166  ret.push_back(new display::SegmentGeometry(
167  algebra::Segment3D(d0.get_coordinates(), d1.get_coordinates())));
168 });
169
170 IMPCORE_END_NAMESPACE
171
172 #endif /* IMPCORE_XYZ_R_H */
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition: Decorator.h:186
Get the key for the radius.
Definition: XYZR.h:76
The base class for geometry.
XYZRs create_xyzr_particles(Model *m, unsigned int num, Float radius, Float box_side=10)
Create a set of particles with random coordinates.
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
Model * get_model() const
Returns the Model containing the particle.
Definition: Decorator.h:189
macros for display classes
static XYZ setup_particle(Model *m, ParticleIndex pi)
Definition: XYZ.h:51
double get_distance(XYZR a, XYZR b)
Compute the sphere distance between a and b.
Definition: XYZR.h:87
Simple XYZ decorator.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
const algebra::Sphere3D & get_sphere() const
Return a sphere object.
Definition: XYZR.h:67
Implement geometry for the basic shapes from IMP.algebra.
static bool get_is_setup(Model *m, ParticleIndex pi)
Check if the particle has the required attributes.
Definition: XYZR.h:57
double get_distance(const Plane3D &pln, const Vector3D &p)
Return the distance between a plane and a point in 3D.
Definition: Plane3D.h:63
void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
void set_sphere(const algebra::Sphere3D &s)
Set the attributes from a sphere.
Definition: XYZR.h:72
Represent an XYZR particle with a sphere.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
#define IMP_DECORATOR_SETUP_0(Name)
Particle * get_particle() const
Returns the particle decorated by this decorator.
Definition: Decorator.h:169
Simple implementation of segments in 3D.
Definition: Segment3D.h:24
algebra::Sphere3D get_enclosing_sphere(const XYZs &v)
Get a sphere enclosing the set of XYZRs.
#define IMP_DECORATOR_METHODS(Name, Parent)
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
void set_enclosing_radius(XYZR b, const XYZs &v)
Set the radius of the first to enclose the list.
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
Simple 3D sphere class.
void set_enclosing_sphere(XYZR b, const XYZs &v, double slack=0)
Set the coordinates and radius of the first to enclose the list.
Class for adding derivatives from restraints to the model.
A decorator for a particle with x,y,z coordinates and a radius.
Definition: XYZR.h:27