IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2022 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>
16
17#include <limits>
18
19IMPMISC_BEGIN_NAMESPACE
20
21//! A decorator for a particle with x,y,z coordinates and a radius.
22/** This is mostly just a sample decorator.
23 */
24class IMPMISCEXPORT CustomXYZR : public core::XYZ {
25 static void do_setup_particle(Model *m, ParticleIndex pi,
26 FloatKey radius_key) {
27 if (!XYZ::get_is_setup(m, pi)) {
29 }
30 m->add_attribute(radius_key, pi, 0, false);
31 }
32 static void do_setup_particle(Model *m, ParticleIndex pi,
33 Float radius, FloatKey radius_key) {
34 if (!XYZ::get_is_setup(m, pi)) {
36 }
37 m->add_attribute(radius_key, pi, radius, false);
38 }
39 static void do_setup_particle(Model *m, ParticleIndex pi,
40 const algebra::Sphere3D &s,
41 FloatKey radius_key) {
42 XYZ::setup_particle(m, pi, s.get_center());
43 m->add_attribute(radius_key, pi, s.get_radius(), false);
44 }
45
46 public:
50 IMP_DECORATOR_TRAITS_SETUP_1(CustomXYZR, double, radius);
52
53 //! Check if the particle has the required attributes
54 static bool get_is_setup(Model *m, ParticleIndex pi,
55 FloatKey radius_key = get_default_radius_key()) {
56 return m->get_has_attribute(radius_key, pi);
57 }
58 IMP_DECORATOR_GET_SET(radius, get_decorator_traits(), Float, Float);
59
60 //! Return a sphere object
63 }
64
65 //! Set the attributes from a sphere
67 set_coordinates(s.get_center());
68 set_radius(s.get_radius());
69 }
70 //! Get the default radius key.
72 return IMP::internal::xyzr_keys[3];
73 }
74 void add_to_radius_derivative(double v, DerivativeAccumulator &d) {
75 get_particle()->add_to_derivative(get_decorator_traits(), v, d);
76 }
77 FloatKey get_traits() { return get_decorator_traits(); }
78};
79
80IMP_DECORATORS(CustomXYZR, CustomXYZRs, core::XYZs);
81
82//! Compute the distance between a pair of particles
83/** \see XYZR
84 */
85inline double get_distance(CustomXYZR a, CustomXYZR b) {
86 return IMP::algebra::get_distance(a.get_sphere(), b.get_sphere());
87}
88
89/** \genericgeometry */
91 return d.get_sphere();
92}
93
94/** \genericgeometry */
96 d.set_sphere(v);
97}
98
99IMPMISC_END_NAMESPACE
100
101#endif /* IMPMISC_CUSTOM_XYZ_R_H */
Simple 3D sphere class.
Decorator for a sphere-like particle.
Simple XYZ decorator.
Class for adding derivatives from restraints to the model.
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
static FloatKey get_radius_key()
Get the key for the radius.
Definition XYZR.h:76
A decorator for a particle with x,y,z coordinates.
Definition XYZ.h:30
const algebra::Vector3D & get_coordinates() const
Convert it to a vector.
Definition XYZ.h:109
void set_coordinates(const algebra::Vector3D &v)
set all coordinates from a vector
Definition XYZ.h:62
static XYZ setup_particle(Model *m, ParticleIndex pi)
Definition XYZ.h:51
A decorator for a particle with x,y,z coordinates and a radius.
Definition CustomXYZR.h:24
static FloatKey get_default_radius_key()
Get the default radius key.
Definition CustomXYZR.h:71
static bool get_is_setup(Model *m, ParticleIndex pi, FloatKey radius_key=get_default_radius_key())
Check if the particle has the required attributes.
Definition CustomXYZR.h:54
algebra::Sphere3D get_sphere() const
Return a sphere object.
Definition CustomXYZR.h:61
void set_sphere(const algebra::Sphere3D &s)
Set the attributes from a sphere.
Definition CustomXYZR.h:66
void set_radius(Float t)
Definition CustomXYZR.h:58
Float get_radius() const
Definition CustomXYZR.h:58
#define IMP_DECORATOR_GET_SET(name, AttributeKey, Type, ReturnType)
Define methods for getting and setting a particular simple field.
#define IMP_DECORATOR_TRAITS_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_DECORATOR_TRAITS_SETUP_0(Name)
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
#define IMP_DECORATOR_WITH_TRAITS_METHODS(Name, Parent, TraitsType, traits_name, default_traits)
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_sphere_d_geometry(CustomXYZR d, const algebra::Sphere3D &v)
Definition CustomXYZR.h:95
const algebra::Sphere3D get_sphere_d_geometry(CustomXYZR d)
Definition CustomXYZR.h:90
double get_distance(CustomXYZR a, CustomXYZR b)
Compute the distance between a pair of particles.
Definition CustomXYZR.h:85
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