IMP logo
IMP Reference Guide  2.5.0
The Integrative Modeling Platform
XYZ.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/XYZ.h \brief Simple XYZ decorator.
3  *
4  * Copyright 2007-2015 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPCORE_XY_Z_H
9 #define IMPCORE_XY_Z_H
10 
11 #include <IMP/core/core_config.h>
12 #include <IMP/decorator_macros.h>
13 #include <IMP/Decorator.h>
14 #include <IMP/algebra/Vector3D.h>
16 #include <vector>
17 #include <limits>
18 
19 IMPCORE_BEGIN_NAMESPACE
20 
21 //! A decorator for a particle with x,y,z coordinates.
22 /** \inlineimage{xyz.png, 50} Using the decorator one can
23  get and set coordinates and modify derivatives.
24 
25  \ingroup helper
26  \ingroup decorators
27  \include XYZ_Decorator.py
28  \see XYZR
29  */
30 class IMPCOREEXPORT XYZ : public Decorator {
31  static void do_setup_particle(
32  Model *m, ParticleIndex pi,
33  // This method and the next one need to take a vector (not a ref)
34  // as otherwise, you can pass the vector from one and use it to
35  // create another. But this would resize the vector and so invalidate
36  // the passed reference. Ick.
37  const algebra::Vector3D v = algebra::Vector3D(0, 0, 0)) {
38  m->add_attribute(get_coordinate_key(0), pi, v[0]);
39  m->add_attribute(get_coordinate_key(1), pi, v[1]);
40  m->add_attribute(get_coordinate_key(2), pi, v[2]);
41  }
42 
43  public:
44  static FloatKey get_coordinate_key(unsigned int i) {
45  IMP_USAGE_CHECK(i < 3, "Out of range coordinate");
46  return IMP::internal::xyzr_keys[i];
47  }
48 
50  /** Setup the particle with unspecified coordinates. */
53 
54  IMP_DECORATOR_GET_SET(x, get_coordinate_key(0), Float, Float);
55  IMP_DECORATOR_GET_SET(y, get_coordinate_key(1), Float, Float);
56  IMP_DECORATOR_GET_SET(z, get_coordinate_key(2), Float, Float);
57  //! set the ith coordinate
58  void set_coordinate(unsigned int i, Float v) {
59  get_model()->get_sphere(get_particle_index())[i] = v;
60  }
61  //! set all coordinates from a vector
63  get_model()->get_sphere(get_particle_index())[0] = v[0];
64  get_model()->get_sphere(get_particle_index())[1] = v[1];
65  get_model()->get_sphere(get_particle_index())[2] = v[2];
66  }
67 
68  //! Get the ith coordinate
69  Float get_coordinate(int i) const {
70  return get_model()->get_sphere(get_particle_index())[i];
71  }
72  //! Get the ith coordinate derivative
73  Float get_derivative(int i) const { return get_derivatives()[i]; }
74  //! Add something to the derivative of the ith coordinate
76  get_particle()->add_to_derivative(get_coordinate_key(i), v, d);
77  }
78  //! Add something to the derivative of the coordinates
81  get_model()->add_to_coordinate_derivatives(get_particle_index(), v, d);
82  }
83  //! Get whether the coordinates are optimized
84  /** \return true only if all of them are optimized.
85  */
87  return get_particle()->get_is_optimized(get_coordinate_key(0)) &&
88  get_particle()->get_is_optimized(get_coordinate_key(1)) &&
89  get_particle()->get_is_optimized(get_coordinate_key(2));
90  }
91  //! Set whether the coordinates are optimized
92  void set_coordinates_are_optimized(bool tf) const {
93  get_particle()->set_is_optimized(get_coordinate_key(0), tf);
94  get_particle()->set_is_optimized(get_coordinate_key(1), tf);
95  get_particle()->set_is_optimized(get_coordinate_key(2), tf);
96  }
97 
98  //! Get the vector from this particle to another
100  return b.get_coordinates() - get_coordinates();
101  ;
102  }
103 
104  //! Convert it to a vector.
105  /** Somewhat suspect based on wanting a Point/Vector differentiation
106  but we don't have points */
108  return get_model()->get_sphere(get_particle_index()).get_center();
109  }
110 
111  //! Get the vector of derivatives.
112  /** Somewhat suspect based on wanting a Point/Vector differentiation
113  but we don't have points */
115  return get_model()->get_coordinate_derivatives(get_particle_index());
116  }
117 
118  static bool get_is_setup(Model *m, ParticleIndex pi) {
119  return m->get_has_attribute(get_coordinate_key(2), pi);
120  }
121 
122  //! Get a vector containing the keys for x,y,z
123  /** This is quite handy for initializing movers and things.
124  */
125  static const FloatKeys &get_xyz_keys();
126 };
127 
128 /** \genericgeometry */
129 inline void set_vector_geometry(XYZ d, const algebra::Vector3D &v) {
130  d.set_coordinates(v);
131 }
132 /** \genericgeometry */
133 inline const algebra::Vector3D get_vector_geometry(XYZ d) {
134  return d.get_coordinates();
135 }
136 
137 IMPCORE_END_NAMESPACE
138 
139 #ifndef SWIG
140 // swig doesn't like having the overloads in different namespaces
141 // it will do the conversion implicitly anyway
142 IMPKERNEL_BEGIN_NAMESPACE
143 
144 /** \genericgeometry */
145 inline const algebra::Vector3D get_vector_geometry(Particle *p) {
146  return core::XYZ(p).get_coordinates();
147 }
148 /** \genericgeometry */
149 inline void set_vector_geometry(Particle *p, const algebra::Vector3D &v) {
151 }
152 
153 inline const algebra::Vector3D get_vector_geometry(Decorator d) {
154  return core::XYZ(d).get_coordinates();
155 }
156 /** \genericgeometry */
159 }
160 
161 inline const algebra::Vector3D get_vector_geometry(
162  WeakPointer<Particle> d) {
163  return core::XYZ(d).get_coordinates();
164 }
165 /** \genericgeometry */
167  const algebra::Vector3D &v) {
169 }
170 inline const algebra::Vector3D get_vector_geometry(
171  Pointer<Particle> d) {
172  return core::XYZ(d).get_coordinates();
173 }
174 /** \genericgeometry */
176  const algebra::Vector3D &v) {
178 }
179 IMPKERNEL_END_NAMESPACE
180 
181 #endif
182 
183 IMPCORE_BEGIN_NAMESPACE
184 
185 //! Compute the distance between a pair of particles
186 /** compute the distance between the x,y,z coordinates of a and b
187  \ingroup helper
188  \see XYZ
189  */
190 inline double get_distance(XYZ a, XYZ b) {
192 }
193 
194 //! Compute the dihedral angle (in radians) between the four particles
195 /** \ingroup helper
196  \see XYZ
197  */
198 IMPCOREEXPORT double get_dihedral(XYZ a, XYZ b, XYZ c, XYZ d);
199 
200 //! Apply a transformation to the particle
201 /** \see XYZ
202  \see algebra::Transformation3D
203 */
204 IMPCOREEXPORT void transform(XYZ a, const algebra::Transformation3D &tr);
205 
206 IMP_DECORATORS(XYZ, XYZs, ParticlesTemp);
207 
208 IMPCORE_END_NAMESPACE
209 
210 #endif /* IMPCORE_XY_Z_H */
The base class for decorators.
void add_to_derivatives(const algebra::Vector3D &v, DerivativeAccumulator &d)
Add something to the derivative of the coordinates.
Definition: XYZ.h:79
#define IMP_DECORATOR_GET_SET(name, AttributeKey, Type, ReturnType)
Define methods for getting and setting a particular simple field.
Simple 3D transformation class.
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition: Decorator.h:186
Smart pointer to Object-derived classes that does not refcount.
Definition: WeakPointer.h:76
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
double get_dihedral(XYZ a, XYZ b, XYZ c, XYZ d)
Compute the dihedral angle (in radians) between the four particles.
Model * get_model() const
Returns the Model containing the particle.
Definition: Decorator.h:189
bool get_coordinates_are_optimized() const
Get whether the coordinates are optimized.
Definition: XYZ.h:86
void set_coordinate(unsigned int i, Float v)
set the ith coordinate
Definition: XYZ.h:58
void set_vector_geometry(Pointer< Particle > d, const algebra::Vector3D &v)
Definition: XYZ.h:175
A smart pointer to a reference counted object.
Definition: Pointer.h:87
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Float get_derivative(int i) const
Get the ith coordinate derivative.
Definition: XYZ.h:73
void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
void set_coordinates(const algebra::Vector3D &v)
set all coordinates from a vector
Definition: XYZ.h:62
void transform(XYZ a, const algebra::Transformation3D &tr)
Apply a transformation to the particle.
double get_distance(XYZ a, XYZ b)
Compute the distance between a pair of particles.
Definition: XYZ.h:190
Various general useful macros for IMP.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
Float get_coordinate(int i) const
Get the ith coordinate.
Definition: XYZ.h:69
#define IMP_DECORATOR_SETUP_0(Name)
const algebra::Vector3D & get_coordinates() const
Convert it to a vector.
Definition: XYZ.h:107
Simple 3D transformation class.
algebra::Vector3D get_vector_to(const XYZ &b) const
Get the vector from this particle to another.
Definition: XYZ.h:99
Particle * get_particle() const
Returns the particle decorated by this decorator.
Definition: Decorator.h:169
void set_coordinates_are_optimized(bool tf) const
Set whether the coordinates are optimized.
Definition: XYZ.h:92
algebra::Vector3D get_derivatives() const
Get the vector of derivatives.
Definition: XYZ.h:114
#define IMP_DECORATOR_METHODS(Name, Parent)
VectorD< 3 > Vector3D
Definition: VectorD.h:395
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
Simple 3D vector class.
Class to handle individual model particles.
Definition: Particle.h:37
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
void add_to_derivative(int i, Float v, DerivativeAccumulator &d)
Add something to the derivative of the ith coordinate.
Definition: XYZ.h:75
Class for adding derivatives from restraints to the model.