IMP logo
IMP Reference Guide  2.7.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-2017 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 /** 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 derivative of the ith coordinate, as accumulated by
73  //! add_to_derivative()
74  Float get_derivative(int i) const { return get_derivatives()[i]; }
75 
76  //! Add v to the derivative of the ith coordinate, used by various
77  //!
79  get_particle()->add_to_derivative(get_coordinate_key(i), v, d);
80  }
81  //! Add the vector v to the derivative vector of the x,y,z coordinates
84  get_model()->add_to_coordinate_derivatives(get_particle_index(), v, d);
85  }
86  //! Get whether the coordinates are optimized
87  /** \return true only if all of them are optimized.
88  */
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
103  return b.get_coordinates() - get_coordinates();
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 */
110  return get_model()->get_sphere(get_particle_index()).get_center();
111  }
112 
113  //! Get the vector of derivatives accumulated by add_to_derivatives().
114  /** Somewhat suspect based on wanting a Point/Vector differentiation
115  but we don't have points */
117  return get_model()->get_coordinate_derivatives(get_particle_index());
118  }
119 
120  static bool get_is_setup(Model *m, ParticleIndex pi) {
121  return m->get_has_attribute(get_coordinate_key(2), pi);
122  }
123 
124  //! Get a vector containing the keys for x,y,z
125  /** This is quite handy for initializing movers and things.
126  */
127  static const FloatKeys &get_xyz_keys();
128 };
129 
130 /** \genericgeometry */
131 inline void set_vector_geometry(XYZ d, const algebra::Vector3D &v) {
132  d.set_coordinates(v);
133 }
134 /** \genericgeometry */
135 inline const algebra::Vector3D get_vector_geometry(XYZ d) {
136  return d.get_coordinates();
137 }
138 
139 IMPCORE_END_NAMESPACE
140 
141 #ifndef SWIG
142 // swig doesn't like having the overloads in different namespaces
143 // it will do the conversion implicitly anyway
144 IMPKERNEL_BEGIN_NAMESPACE
145 
146 /** \genericgeometry */
147 inline const algebra::Vector3D get_vector_geometry(Particle *p) {
148  return core::XYZ(p).get_coordinates();
149 }
150 /** \genericgeometry */
151 inline void set_vector_geometry(Particle *p, const algebra::Vector3D &v) {
153 }
154 
155 inline const algebra::Vector3D get_vector_geometry(Decorator d) {
156  return core::XYZ(d).get_coordinates();
157 }
158 /** \genericgeometry */
161 }
162 
163 inline const algebra::Vector3D get_vector_geometry(
164  WeakPointer<Particle> d) {
165  return core::XYZ(d).get_coordinates();
166 }
167 /** \genericgeometry */
169  const algebra::Vector3D &v) {
171 }
172 inline const algebra::Vector3D get_vector_geometry(
173  Pointer<Particle> d) {
174  return core::XYZ(d).get_coordinates();
175 }
176 /** \genericgeometry */
178  const algebra::Vector3D &v) {
180 }
181 IMPKERNEL_END_NAMESPACE
182 
183 #endif
184 
185 IMPCORE_BEGIN_NAMESPACE
186 
187 //! Compute the distance between a pair of particles
188 /** compute the distance between the x,y,z coordinates of a and b
189  \ingroup helper
190  \see XYZ
191  */
192 inline double get_distance(XYZ a, XYZ b) {
194 }
195 
196 //! Compute the dihedral angle (in radians) between the four particles
197 /** \ingroup helper
198  \see XYZ
199  */
200 IMPCOREEXPORT double get_dihedral(XYZ a, XYZ b, XYZ c, XYZ d);
201 
202 //! Apply a transformation to the particle
203 /** \see XYZ
204  \see algebra::Transformation3D
205 */
206 IMPCOREEXPORT void transform(XYZ a, const algebra::Transformation3D &tr);
207 
208 IMP_DECORATORS(XYZ, XYZs, ParticlesTemp);
209 
210 IMPCORE_END_NAMESPACE
211 
212 #endif /* IMPCORE_XY_Z_H */
The base class for decorators.
void add_to_derivatives(const algebra::Vector3D &v, DerivativeAccumulator &d)
Add the vector v to the derivative vector of the x,y,z coordinates.
Definition: XYZ.h:82
#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:188
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:191
bool get_coordinates_are_optimized() const
Get whether the coordinates are optimized.
Definition: XYZ.h:89
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:177
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
Definition: XYZ.h:74
void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
add particle atribute with the specied key and initial 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:192
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:109
Simple 3D transformation class.
algebra::Vector3D get_vector_to(const XYZ &b) const
Get the vector from this particle to another.
Definition: XYZ.h:102
Particle * get_particle() const
Returns the particle decorated by this decorator.
Definition: Decorator.h:171
Interface to specialized Particle types (e.g. atoms)
Definition: Decorator.h:118
void set_coordinates_are_optimized(bool tf) const
Set whether the coordinates are optimized.
Definition: XYZ.h:95
algebra::Vector3D get_derivatives() const
Get the vector of derivatives accumulated by add_to_derivatives().
Definition: XYZ.h:116
#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 particles of a Model object.
Definition: Particle.h:41
#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.
bool get_has_attribute(TypeKey attribute_key, ParticleIndex particle) const
return true if particle has attribute with the specified key
void add_to_derivative(int i, Float v, DerivativeAccumulator &d)
Definition: XYZ.h:78
Class for adding derivatives from restraints to the model.