IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2022 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"
17#include <limits>
18
19IMPCORE_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 */
27class 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)) {
42 }
43 m->add_attribute(get_radius_key(), pi, 0, false);
44 }
45
46 public:
47 IMP_DECORATOR_METHODS(XYZR, XYZ);
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
68 return get_model()->get_sphere(get_particle_index());
69 }
70
71 //! Set the attributes from a sphere
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
84IMP_DECORATORS(XYZR, XYZRs, XYZs);
85
86//! Compute the sphere distance between a and b
87/** \see XYZR
88 */
89inline double get_distance(XYZR a, XYZR b) {
90 return IMP::algebra::get_distance(a.get_sphere(), b.get_sphere());
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 */
105IMPCOREEXPORT 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 */
116IMPCOREEXPORT 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 */
125IMPCOREEXPORT 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 */
138IMPCOREEXPORT 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*/
148IMP_PARTICLE_GEOMETRY(XYZR, core::XYZR, {
149 display::SphereGeometry *g = new display::SphereGeometry(d.get_sphere());
150 ret.push_back(g);
151});
152
153IMP_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*/
167IMP_PARTICLE_PAIR_GEOMETRY(EdgePair, core::XYZ, {
168 ret.push_back(new display::SegmentGeometry(
169 algebra::Segment3D(d0.get_coordinates(), d1.get_coordinates())));
170});
171
172IMPCORE_END_NAMESPACE
173
174#endif /* IMPCORE_XYZ_R_H */
Simple 3D sphere class.
Simple XYZ decorator.
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition Decorator.h:211
Model * get_model() const
Returns the Model containing the particle.
Definition Decorator.h:214
Particle * get_particle() const
Returns the particle decorated by this decorator.
Definition Decorator.h:194
Class for adding derivatives from restraints to the model.
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Simple implementation of segments in 3D.
Definition Segment3D.h:24
A decorator for a particle with x,y,z coordinates and a radius.
Definition XYZR.h:27
static FloatKey get_radius_key()
Get the key for the radius.
Definition XYZR.h:76
void add_to_radius_derivative(double v, DerivativeAccumulator &d)
add v to the derivative of the radius attribute
Definition XYZR.h:79
void set_sphere(const algebra::Sphere3D &s)
Set the attributes from a sphere.
Definition XYZR.h:72
static bool get_is_setup(Model *m, ParticleIndex pi)
Check if the particle has the required attributes.
Definition XYZR.h:57
const algebra::Sphere3D & get_sphere() const
Return a sphere object.
Definition XYZR.h:67
A decorator for a particle with x,y,z coordinates.
Definition XYZ.h:30
static XYZ setup_particle(Model *m, ParticleIndex pi)
Definition XYZ.h:51
The base class for geometry.
#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)
macros for display classes
SphereD< 3 > Sphere3D
Typedef for Python.
Definition SphereD.h:103
double get_distance(const Line3D &s, const Vector3D &p)
Get closest distance between a line and a point.
void set_enclosing_radius(XYZR b, const XYZs &v)
Set the radius of the first to enclose the list.
void set_enclosing_sphere(XYZR b, const XYZs &v, double slack=0)
Set the coordinates and radius of the first to enclose the list.
algebra::Sphere3D get_enclosing_sphere(const XYZs &v)
Get a sphere enclosing the set of XYZRs.
XYZRs create_xyzr_particles(Model *m, unsigned int num, Float radius, Float box_side=10)
Create a set of particles with random coordinates.
double get_distance(const Surface &s, const XYZR &d)
Get distance from sphere to surface.
Definition Surface.h:153
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
Represent an XYZR particle with a sphere.
Implement geometry for the basic shapes from IMP.algebra.