IMP logo
XYZ.h
Go to the documentation of this file.
1 /**
2  * \file XYZ.h \brief Simple xyz decorator.
3  *
4  * Copyright 2007-2012 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPCORE_XY_Z_H
9 #define IMPCORE_XY_Z_H
10 
11 #include "core_config.h"
12 #include "../macros.h"
13 #include "internal/dihedral_helpers.h"
14 
15 #include <IMP/Decorator.h>
16 #include <IMP/algebra/Vector3D.h>
18 #include <vector>
19 #include <limits>
20 
21 IMPCORE_BEGIN_NAMESPACE
22 
23 //! A a decorator for a particle with x,y,z coordinates.
24 /** \inlineimage{xyz.png, 50} Using the decorator one can
25  get and set coordinates and modify derivatives.
26 
27  \ingroup helper
28  \ingroup decorators
29  \pythonexample{XYZ_Decorator}
30  \see XYZR
31  */
32 class IMPCOREEXPORT XYZ: public Decorator
33 {
34  public:
35 
36  static FloatKey get_coordinate_key(unsigned int i) {
37  IMP_USAGE_CHECK(i <3, "Out of range coordinate");
38  return IMP::internal::xyzr_keys[i];
39  }
40 
42 
43  /** Create a decorator with the passed coordinates. */
44  static XYZ setup_particle(Particle *p,
45  const algebra::Vector3D &v=
46  algebra::Vector3D(0,0,0)) {
47  p->add_attribute(get_coordinate_key(0),v[0]);
48  p->add_attribute(get_coordinate_key(1),v[1]);
49  p->add_attribute(get_coordinate_key(2),v[2]);
50  return XYZ(p);
51  }
52 
53  IMP_DECORATOR_GET_SET(x, get_coordinate_key(0), Float, Float);
54  IMP_DECORATOR_GET_SET(y, get_coordinate_key(1), Float, Float);
55  IMP_DECORATOR_GET_SET(z, get_coordinate_key(2), Float, Float);
56  //! set the ith coordinate
57  void set_coordinate(unsigned int i, Float v) {
58  get_model()->get_sphere(get_particle_index())[i]=v;
59  }
60  //! set all coordinates from a vector
61  void set_coordinates(const algebra::Vector3D &v) {
62  get_model()->get_sphere(get_particle_index())[0]=v[0];
63  get_model()->get_sphere(get_particle_index())[1]=v[1];
64  get_model()->get_sphere(get_particle_index())[2]=v[2];
65  }
66 
67  //! Get the ith coordinate
68  Float get_coordinate(int i) const {
69  return get_model()->get_sphere(get_particle_index())[i];
70  }
71  //! Get the ith coordinate derivative
72  Float get_derivative(int i) const {
73  return get_derivatives()[i];
74  }
75  //! Add something to the derivative of the ith coordinate
76  void add_to_derivative(int i, Float v,
78  get_particle()->add_to_derivative(get_coordinate_key(i), v, d);
79  }
80  //! Add something to the derivative of the coordinates
81  void add_to_derivatives(const algebra::Vector3D& v,
83  get_model()->add_to_coordinate_derivatives(get_particle_index(),
84  v, d);
85  }
86  //! Get whether the coordinates are optimized
87  /** \return true only if all of them are optimized.
88  */
89  bool get_coordinates_are_optimized() const {
90  return get_particle()->get_is_optimized(get_coordinate_key(0))
91  && get_particle()->get_is_optimized(get_coordinate_key(1))
92  && get_particle()->get_is_optimized(get_coordinate_key(2));
93  }
94  //! Set whether the coordinates are optimized
95  void set_coordinates_are_optimized(bool tf) const {
96  get_particle()->set_is_optimized(get_coordinate_key(0), tf);
97  get_particle()->set_is_optimized(get_coordinate_key(1), tf);
98  get_particle()->set_is_optimized(get_coordinate_key(2), tf);
99  }
100 
101  //! Get the vector from this particle to another
102  algebra::Vector3D get_vector_to(const XYZ &b) const {
104  }
105 
106  //! Convert it to a vector.
107  /** Somewhat suspect based on wanting a Point/Vector differentiation
108  but we don't have points */
109  const algebra::Vector3D& get_coordinates() const {
110  return get_model()->get_sphere(get_particle_index()).get_center();
111  }
112 
113  //! Get the vector of derivatives.
114  /** Somewhat suspect based on wanting a Point/Vector differentiation
115  but we don't have points */
116  algebra::Vector3D get_derivatives() const {
117  return get_model()->get_coordinate_derivatives(get_particle_index());
118  }
119 
120  static bool particle_is_instance(Particle *p) {
121  IMP_USAGE_CHECK((p->has_attribute(get_coordinate_key(2))
122  && p->has_attribute(get_coordinate_key(0))
123  && p->has_attribute(get_coordinate_key(1)))
124  || (!p->has_attribute(get_coordinate_key(2))
125  && !p->has_attribute(get_coordinate_key(0))
126  && !p->has_attribute(get_coordinate_key(1))),
127  "Particle expected to either have all of x,y,z or none.");
128  return p->has_attribute(get_coordinate_key(2));
129  }
130 
131  static bool particle_is_instance(Model *m, ParticleIndex pi) {
132  return m->get_has_attribute(get_coordinate_key(2), pi);
133  }
134 
135  //! Get a vector containing the keys for x,y,z
136  /** This is quite handy for initializing movers and things.
137  */
138  static const FloatKeys& get_xyz_keys();
139 };
140 
141 //! Compute the distance between a pair of particles
142 /** \ingroup helper
143  \relatesalso XYZ
144  */
145 inline double get_distance(XYZ a, XYZ b) {
146  return algebra::get_distance(a.get_coordinates(),b.get_coordinates());
147 }
148 
149 //! Compute the dihedral angle (in radians) between the four particles
150 /** \ingroup helper
151  \relatesalso XYZ
152  */
153 inline double get_dihedral(XYZ a, XYZ b, XYZ c, XYZ d) {
154  return internal::dihedral(a, b, c, d, nullptr, nullptr, nullptr, nullptr);
155 }
156 
157 //! Apply a transformation to the particle
158 /** \relatesalso XYZ
159  \relatesalso algebra::Transformation3D
160 */
161 IMPCOREEXPORT void transform(XYZ a, const algebra::Transformation3D &tr);
163 /** \genericgeometry */
164 inline const algebra::Vector3D get_vector_d_geometry(XYZ d) {
165  return d.get_coordinates();
166 }
167 /** \genericgeometry */
168 inline void set_vector_d_geometry(XYZ d, const algebra::Vector3D &v) {
169  d.set_coordinates(v);
170 }
171 
172 IMP_DECORATORS(XYZ,XYZs, ParticlesTemp);
173 
174 
175 IMPCORE_END_NAMESPACE
176 
177 
178 #ifndef SWIG
179 // use koenig lookup
180 // swig doesn't like having the overloads in different namespaces
181 // it will do the conversion implicitly anyway
182 IMP_BEGIN_NAMESPACE
183 /** \genericgeometry */
184 inline const algebra::Vector3D get_vector_d_geometry(Particle *p) {
185  return core::XYZ(p).get_coordinates();
186 }
187 /** \genericgeometry */
188 inline void set_vector_d_geometry(Particle *p, const algebra::Vector3D &v) {
189  core::XYZ(p).set_coordinates(v);
190 }
191 
192 IMP_END_NAMESPACE
193 #endif
194 
195 #endif /* IMPCORE_XY_Z_H */

Generated on Tue May 22 2012 23:33:17 for IMP by doxygen 1.8.1