IMP logo
IMP Reference Guide  develop.d247202c1c,2019/10/23
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  *
5  * Copyright 2007-2019 IMP Inventors. All rights reserved.
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());
31  do_setup_particle(m, pi, s.get_radius());
32  }
33 
34  static void do_setup_particle(Model *m, ParticleIndex pi,
35  double r) {
36  m->add_attribute(get_radius_key(), pi, r, false);
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  }
43  m->add_attribute(get_radius_key(), pi, 0, false);
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) {
58  return m->get_has_attribute(get_radius_key(), pi);
59  }
60 
61  double get_radius() const { return get_sphere().get_radius(); }
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]; }
77 
78  //! add v to the derivative of the radius attribute
80  get_particle()->add_to_derivative(get_radius_key(), v, d);
81  }
82 };
83 
84 IMP_DECORATORS(XYZR, XYZRs, XYZs);
85 
86 //! Compute the sphere distance between a and b
87 /** \see XYZR
88  */
89 inline double get_distance(XYZR a, XYZR b) {
91 }
92 
93 //! Set the coordinates and radius of the first to enclose the list
94 /** \param[in] v The vector of XYZ or XYZR particles to enclose
95  \param[out] b The one whose values should be set
96  \param[in] slack An amount to add to the radius.
97  Any particle which does not have the attribute b.get_radius()
98  is assumed to have a radius of 0.
99 
100  \note This function produces tighter bounds if the \ref cgal "CGAL"
101  library is available.
102  \ingroup CGAL
103  \see XYZR
104  */
105 IMPCOREEXPORT void set_enclosing_sphere(XYZR b, const XYZs &v,
106  double slack = 0);
107 
108 //! Set the radius of the first to enclose the list
109 /** \param[in] v The vector of XYZ or XYZR particles to enclose
110  \param[out] b The one whose radius should be set
111  Any particle which does not have the attribute b.get_radius()
112  is assumed to have a radius of 0.
113 
114  \see XYZR
115  */
116 IMPCOREEXPORT void set_enclosing_radius(XYZR b, const XYZs &v);
117 
118 //! Get a sphere enclosing the set of XYZRs
119 /** \param[in] v The one whose radius should be set
120  Any particle which does not have the attribute b.get_radius()
121  is assumed to have a radius of 0.
122 
123  \see XYZR
124  */
125 IMPCOREEXPORT algebra::Sphere3D get_enclosing_sphere(const XYZs &v);
126 
127 //! Create a set of particles with random coordinates
128 /** This function is mostly to be used to keep demo code brief.
129  \param[in] m The model to add them to.
130  \param[in] num The number of particles to create.
131  \param[in] radius The radius to give them.
132  \param[in] box_side The particles have coordinates from -box_side
133  to box_side.
134  \see XYZR
135 
136  The particles coordinates are optimized.
137  */
138 IMPCOREEXPORT XYZRs create_xyzr_particles(Model *m, unsigned int num,
139  Float radius, Float box_side = 10);
140 
141 /** \class XYZRGeometry
142  \brief Display an IMP::core::XYZR particle as a ball.
143 
144  \class XYZRsGeometry
145  \brief Display an IMP::SingletonContainer of IMP::core::XYZR particles
146  as balls.
147 */
148 IMP_PARTICLE_GEOMETRY(XYZR, core::XYZR, {
149  display::SphereGeometry *g = new display::SphereGeometry(d.get_sphere());
150  ret.push_back(g);
151 });
152 
153 IMP_PARTICLE_GEOMETRY(XYZDerivative, core::XYZ, {
154  algebra::Segment3D s(d.get_coordinates(),
155  d.get_coordinates() + d.get_derivatives());
157  ret.push_back(g);
158 });
159 
160 /** \class EdgePairGeometry
161  \brief Display a segment connecting a pair of particles.
162 
163  \class EdgePairsGeometry
164  \brief Display a segment for each pair in a
165  IMP::PairContainer.
166 */
167 IMP_PARTICLE_PAIR_GEOMETRY(EdgePair, core::XYZ, {
168  ret.push_back(new display::SegmentGeometry(
169  algebra::Segment3D(d0.get_coordinates(), d1.get_coordinates())));
170 });
171 
172 IMPCORE_END_NAMESPACE
173 
174 #endif /* IMPCORE_XYZ_R_H */
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition: Decorator.h:188
static FloatKey get_radius_key()
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:191
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:89
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
void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
add particle atribute with the specied key and initial 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:171
Simple implementation of segments in 3D.
Definition: Segment3D.h:24
void add_to_radius_derivative(double v, DerivativeAccumulator &d)
add v to the derivative of the radius attribute
Definition: XYZR.h:79
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.
bool get_has_attribute(TypeKey attribute_key, ParticleIndex particle) const
return true if particle has attribute with the specified key
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.
double get_distance(const Line3D &s, const Vector3D &p)
Get closest distance between a line and a point.
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