IMP  2.1.1
The Integrative Modeling Platform
VectorD.h
Go to the documentation of this file.
1 /**
2  * \file IMP/algebra/VectorD.h \brief Simple D vector class.
3  *
4  * Copyright 2007-2013 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPALGEBRA_VECTOR_D_H
9 #define IMPALGEBRA_VECTOR_D_H
10 
11 #include <IMP/algebra/algebra_config.h>
12 #include "GeometricPrimitiveD.h"
13 #include <IMP/base/types.h>
14 #include <IMP/base/check_macros.h>
15 #include <IMP/base/exception.h>
16 #include <IMP/base/utility.h>
17 #include <IMP/base/InputAdaptor.h>
18 #include <IMP/base/random.h>
19 #include "internal/vector.h"
20 
21 #include <limits>
22 #include <cmath>
23 #include <boost/random/normal_distribution.hpp>
24 #include <boost/static_assert.hpp>
25 
26 #if IMP_HAS_CHECKS >= IMP_USAGE
27 #define IMP_VECTOR_CHECK check_vector()
28 #define IMP_VECTOR_CHECK_INDEX(i) check_index(i)
29 #define IMP_VECTOR_CHECK_COMPATIBLE(o) \
30  check_compatible_vector(o); \
31  o.check_vector()
32 #else
33 #define IMP_VECTOR_CHECK
34 #define IMP_VECTOR_CHECK_INDEX(i)
35 #define IMP_VECTOR_CHECK_COMPATIBLE(o)
36 #endif
37 
38 IMPALGEBRA_BEGIN_NAMESPACE
39 //! A Cartesian vector in D-dimensions.
40 /** Store a vector of Cartesian coordinates. It supports all expected
41  mathematical operators, including using * for the dot product.
42  \see Vector3D
43  \see Vector2D
44 
45  \geometry
46  */
47 template <int D>
48 class VectorD : public GeometricPrimitiveD<D> {
49  void check_vector() const {
50  IMP_USAGE_CHECK(!data_.get_is_null(),
51  "Attempt to use uninitialized vector.");
52  }
53  template <int OD>
54  void check_compatible_vector(const VectorD<OD> &o) const {
56  IMP_USAGE_CHECK(o.get_dimension() == get_dimension(),
57  "Dimensions don't match: " << get_dimension() << " vs "
58  << o.get_dimension());
59  }
60  void check_index(unsigned int i) const {
61 #if IMP_HAS_CHECKS < IMP_INTERNAL
62  IMP_UNUSED(i);
63 #endif
64  IMP_INTERNAL_CHECK(i < data_.get_dimension(),
65  "Invalid component of vector requested: "
66  << i << " of " << get_dimension());
67  }
68 
69  public:
70 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
71  // to shut off deprecation warning
72  VectorD(const Floats &f, bool) {
73  if (D != -1 && static_cast<int>(f.size()) != D) {
74  IMP_THROW("Expected " << D << " but got " << f.size(),
76  }
77  data_.set_coordinates(f.begin(), f.end());
78  }
79  template <int OD>
80  VectorD(const VectorD<OD> &o) {
81  BOOST_STATIC_ASSERT(D == -1 || OD == -1 || D == OD);
83  D == -1 || o.get_dimension() == static_cast<unsigned int>(D),
84  "Dimensions don't match in conversion");
85  data_.set_coordinates(o.coordinates_begin(), o.coordinates_end());
86  }
87  template <int OD>
88  VectorD &operator=(const VectorD<OD> &o) {
89  BOOST_STATIC_ASSERT(D == -1 || OD == -1 || D == OD);
90  IMP_USAGE_CHECK(D == -1 || o.get_dimension() == D,
91  "Dimensions don't match in conversion");
92  data_.set_coordinates(o.coordinates_begin(), o.coordinates_end());
93  }
94 #endif
95 
96 /** \throw base::ValueException if f.size() is not appropriate.
97  \note Only use this from python. */
98 #ifndef SWIG
99  IMP_DEPRECATED_ATTRIBUTE
100 #endif
101  VectorD(const Floats &f) {
102  if (D != -1 && static_cast<int>(f.size()) != D) {
103  IMP_THROW("Expected " << D << " but got " << f.size(),
105  }
106  data_.set_coordinates(f.begin(), f.end());
107  }
108 
109  /** The distance between b and e must be equal to D.
110  */
111  template <class It>
112  VectorD(It b, It e) {
113  data_.set_coordinates(b, e);
114  }
115 
116  //! Initialize the 1-vector from its value.
117  explicit VectorD(double x) {
118 /* Note that MSVC gets confused with static asserts if we try to subclass
119  VectorD, as we do for example in the various IMP::display Geometry
120  subclasses, so replace with runtime checks. */
121 #if defined(IMP_SWIG_WRAPPER) || defined(_MSC_VER)
122  IMP_USAGE_CHECK(D == 1 || D == -1, "Need " << D << " to construct a " << D
123  << "-vector.");
124 #else
125  BOOST_STATIC_ASSERT(D == 1);
126 #endif
127  data_.set_coordinates(&x, &x + 1);
128  }
129 
130  //! Initialize a 2-vector from separate x,y values.
131  VectorD(double x, double y) {
132 #if defined(IMP_SWIG_WRAPPER) || defined(_MSC_VER)
133  IMP_USAGE_CHECK(D == 2 || D == -1, "Need " << D << " to construct a " << D
134  << "-vector.");
135 #else
136  BOOST_STATIC_ASSERT(D == 2);
137 #endif
138  double d[] = {x, y};
139  data_.set_coordinates(d, d + 2);
140  }
141 
142  //! Initialize a 3-vector from separate x,y,z values.
143  VectorD(double x, double y, double z) {
144 #ifdef IMP_SWIG_WRAPPER
145  IMP_USAGE_CHECK(D == 3 || D == -1, "Need " << D << " to construct a " << D
146  << "-vector.");
147 #else
148  BOOST_STATIC_ASSERT(D == 3);
149 #endif
150  double d[] = {x, y, z};
151  data_.set_coordinates(d, d + 3);
152  }
153 
154  //! Initialize a 4-vector from separate w,x,y,z values.
155  VectorD(double x0, double x1, double x2, double x3) {
156 #if defined(IMP_SWIG_WRAPPER) || defined(_MSC_VER)
157  IMP_USAGE_CHECK(D == 4 || D == -1, "Need " << D << " to construct a " << D
158  << "-vector.");
159 #else
160  BOOST_STATIC_ASSERT(D == 4);
161 #endif
162  double d[] = {x0, x1, x2, x3};
163  data_.set_coordinates(d, d + 4);
164  }
165 
166  //! Default constructor
167  VectorD() {}
168 
169  /** Return the ith Cartesian coordinate. In 3D use [0] to get
170  the x coordinate etc.*/
171  inline double operator[](unsigned int i) const {
172  IMP_VECTOR_CHECK_INDEX(i);
173  IMP_VECTOR_CHECK;
174  return data_.get_data()[i];
175  }
176  /** Return the ith Cartesian coordinate. In 3D use [0] to get
177  the x coordinate etc. */
178  inline double &operator[](unsigned int i) {
179  IMP_VECTOR_CHECK_INDEX(i);
180  return data_.get_data()[i];
181  }
182 
183  double get_scalar_product(const VectorD<D> &o) const {
184  IMP_VECTOR_CHECK_COMPATIBLE(o);
185  IMP_VECTOR_CHECK;
186  double ret = 0;
187  for (unsigned int i = 0; i < get_dimension(); ++i) {
188  ret += operator[](i) * o.operator[](i);
189  }
190  return ret;
191  }
192 
193  double get_squared_magnitude() const { return get_scalar_product(*this); }
194 
195  double get_magnitude() const { return std::sqrt(get_squared_magnitude()); }
196 
197  /**
198  Returns a unit vector pointing at the same direction as this vector.
199 
200  @note If the magnitude of this vector is smaller than 1e-12
201  (an arbitrarily selected small number), returns a unit
202  vector pointing at a random direction
203  */
205  const double tiny_double = 1e-12;
206  double mag = get_magnitude();
207  if (mag > tiny_double) {
208  return operator/(mag);
209  } else {
210  // avoid division by zero - return random unit v
211  // NOTE: (1) avoids vector_generators / SphereD to prevent recursiveness
212  // (2) D might be -1, so use get_dimension()
213  VectorD<D> ret(*this);
214  boost::variate_generator<boost::rand48, boost::normal_distribution<> >
216  ::boost::normal_distribution<>(0, 1.0));
217  for (unsigned int i = 0; i < get_dimension(); ++i) {
218  ret[i] = generator();
219  }
220  return ret.get_unit_vector();
221  }
222  }
223 
224 #ifndef IMP_DOXYGEN
225  double operator*(const VectorD<D> &o) const {
226  IMP_VECTOR_CHECK_COMPATIBLE(o);
227  return get_scalar_product(o);
228  }
229 
230  VectorD operator*(double s) const {
231  IMP_VECTOR_CHECK;
232  VectorD ret = *this;
233  ret *= s;
234  return ret;
235  }
236 
237  VectorD operator/(double s) const {
238  IMP_VECTOR_CHECK;
239  VectorD ret = *this;
240  ret /= s;
241  return ret;
242  }
243 
244  VectorD operator-() const {
245  IMP_VECTOR_CHECK;
246  VectorD ret = *this;
247  for (unsigned int i = 0; i < get_dimension(); ++i) {
248  ret[i] = -ret[i];
249  }
250  return ret;
251  }
252 
253  VectorD operator-(const VectorD &o) const {
254  IMP_VECTOR_CHECK_COMPATIBLE(o);
255  IMP_VECTOR_CHECK;
256  VectorD ret = *this;
257  ret -= o;
258  return ret;
259  }
260 
261  VectorD operator+(const VectorD &o) const {
262  IMP_VECTOR_CHECK_COMPATIBLE(o);
263  IMP_VECTOR_CHECK;
264  VectorD ret = *this;
265  ret += o;
266  return ret;
267  }
268 
269  VectorD &operator+=(const VectorD &o) {
270  IMP_VECTOR_CHECK_COMPATIBLE(o);
271  IMP_VECTOR_CHECK;
272  for (unsigned int i = 0; i < get_dimension(); ++i) {
273  operator[](i) += o[i];
274  }
275  return *this;
276  }
277 
278  VectorD &operator-=(const VectorD &o) {
279  IMP_VECTOR_CHECK_COMPATIBLE(o);
280  IMP_VECTOR_CHECK;
281  for (unsigned int i = 0; i < get_dimension(); ++i) {
282  operator[](i) -= o[i];
283  }
284  return *this;
285  }
286 
287  VectorD &operator/=(double f) {
288  IMP_VECTOR_CHECK;
289  for (unsigned int i = 0; i < get_dimension(); ++i) {
290  operator[](i) /= f;
291  }
292  return *this;
293  }
294 
295  VectorD &operator*=(double f) {
296  IMP_VECTOR_CHECK;
297  for (unsigned int i = 0; i < get_dimension(); ++i) {
298  operator[](i) *= f;
299  }
300  return *this;
301  }
302 
303  void show(std::ostream &out, std::string delim, bool parens = true) const {
304  IMP_VECTOR_CHECK;
305  if (parens) out << "(";
306  for (unsigned int i = 0; i < get_dimension(); ++i) {
307  out << operator[](i);
308  if (i != get_dimension() - 1) {
309  out << delim;
310  }
311  }
312  if (parens) out << ")";
313  }
314  IMP_SHOWABLE_INLINE(VectorD, show(out, ", "););
315 #endif
316 
317 #ifndef SWIG
318  typedef double *CoordinateIterator;
319  CoordinateIterator coordinates_begin() { return data_.get_data(); }
320  CoordinateIterator coordinates_end() {
321  return data_.get_data() + get_dimension();
322  }
323  typedef const double *CoordinateConstIterator;
324  CoordinateConstIterator coordinates_begin() const { return data_.get_data(); }
325  CoordinateConstIterator coordinates_end() const {
326  return data_.get_data() + get_dimension();
327  }
328 #endif
329 
330 #ifndef SWIG
331  // For some reason, this method breaks IMP::atom::get_rmsd() in Python, so
332  // hide it from SWIG
333  Floats get_coordinates() const {
334  return Floats(coordinates_begin(), coordinates_end());
335  }
336 #endif
337 
338 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
339  const double *get_data() const { return data_.get_data(); }
340 #endif
341  unsigned int get_dimension() const { return data_.get_dimension(); }
342 
343  private:
344 
345  internal::VectorData<double, D, false> data_;
346 };
347 
348 #ifndef IMP_DOXYGEN
349 
350 template <int D>
351 inline std::ostream &operator<<(std::ostream &out, const VectorD<D> &v) {
352  v.show(out);
353  return out;
354 }
355 
356 template <int D>
357 inline std::istream &operator>>(std::istream &in, VectorD<D> &v) {
358  for (unsigned int i = 0; i < D; ++i) {
359  in >> v[i];
360  }
361  return in;
362 }
363 
364 #endif
365 
366 //! lexicographic comparison of two vectors
367 /** Note that this is not very reliable and probably should not be used.
368  See VectorD
369  */
370 template <int D>
371 inline int compare(const VectorD<D> &a, const VectorD<D> &b) {
372  IMP_USAGE_CHECK(a.get_dimension() == b.get_dimension(),
373  "Dimensions don't match.");
374  for (unsigned int i = 0; i < a.get_dimension(); ++i) {
375  if (a[i] < b[i])
376  return -1;
377  else if (a[i] > b[i])
378  return 1;
379  }
380  return 0;
381 }
382 
383 /** See VectorD */
384 template <int D>
385 inline VectorD<D> operator*(double s, const VectorD<D> &o) {
386  return o * s;
387 }
388 
389 //! compute the squared distance between two vectors
390 /** See VectorD
391  */
392 template <int D>
393 inline double get_squared_distance(const VectorD<D> &v1, const VectorD<D> &v2) {
394  return (v1 - v2).get_squared_magnitude();
395 }
396 
397 //! compute the distance between two vectors
398 /** See VectorD
399  */
400 template <int D>
401 inline double get_distance(const VectorD<D> &v1, const VectorD<D> &v2) {
402  return std::sqrt(get_squared_distance(v1, v2));
403 }
404 
405 //! Return the basis vector for the given coordinate
406 /** Return the unit vector pointing in the direction of the requested
407  coordinate. That is
408  \code
409  get_basis_vector_d<3>(2)== Vector3D(0,0,1);
410  \endcode
411  See VectorD
412  */
413 template <int D>
414 inline VectorD<D> get_basis_vector_d(unsigned int coordinate) {
415  IMP_USAGE_CHECK(coordinate < D, "There are only " << D << " basis vectors");
416  double vs[D];
417  for (unsigned int i = 0; i < D; ++i) {
418  if (i == coordinate)
419  vs[i] = 1;
420  else
421  vs[i] = 0;
422  }
423  return VectorD<D>(vs, vs + D);
424 }
425 
426 //! Return a dynamically sized basis vector
427 inline VectorD<-1> get_basis_vector_kd(int D, unsigned int coordinate) {
428  IMP_USAGE_CHECK(D > 0, "D must be positive");
429  IMP_USAGE_CHECK(coordinate < static_cast<unsigned int>(D),
430  "There are only " << D << " basis vectors");
431  boost::scoped_array<double> vs(new double[D]);
432  for (int i = 0; i < D; ++i) {
433  if (i == static_cast<int>(coordinate))
434  vs[i] = 1;
435  else
436  vs[i] = 0;
437  }
438  return VectorD<-1>(vs.get(), vs.get() + D);
439 }
440 
441 //! Return a vector of zeros
442 template <int D>
444  IMP_USAGE_CHECK(D > 0, "D must be positive");
445  VectorD<D> ret;
446  for (int i = 0; i < D; ++i) {
447  ret[i] = 0;
448  }
449  return ret;
450 }
451 
452 //! Return a dynamically sized vector of zeros
453 template <int D>
455  IMP_USAGE_CHECK(D == Di, "D must be positive");
456  IMP_UNUSED(Di);
457  return get_zero_vector_d<D>();
458 }
459 
460 //! Return a dynamically sized vector of zeros
461 inline VectorD<-1> get_zero_vector_kd(int D) {
462  IMP_USAGE_CHECK(D > 0, "D must be positive");
463  Floats vs(D, 0);
464  return VectorD<-1>(vs.begin(), vs.end());
465 }
466 
467 //! Return a vector of ones (or another constant)
468 template <int D>
469 inline VectorD<D> get_ones_vector_d(double v = 1) {
470  IMP_USAGE_CHECK(D > 0, "D must be positive");
471  VectorD<D> ret;
472  for (unsigned int i = 0; i < D; ++i) {
473  ret[i] = v;
474  }
475  return ret;
476 }
477 
478 //! Return a vector of ones (or another constant)
479 /** Di must equal D. */
480 template <int D>
481 inline VectorD<D> get_ones_vector_kd(unsigned int Di, double v = 1) {
482  IMP_USAGE_CHECK(D == Di, "D must be equal");
483  IMP_UNUSED(Di);
484  return get_ones_vector_d<D>(v);
485 }
486 
487 //! Return a vector of ones (or another constant)
488 inline VectorD<-1> get_ones_vector_kd(unsigned int D, double v = 1) {
489  IMP_USAGE_CHECK(D > 0, "D must be positive");
490  boost::scoped_array<double> vv(new double[D]);
491  for (unsigned int i = 0; i < D; ++i) {
492  vv[i] = v;
493  }
494  return VectorD<-1>(vv.get(), vv.get() + D);
495 }
496 
497 #ifndef SWIG
498 
499 /** \name Norms
500  We define a number of standard, \f$L^p\f$, norms on VectorD.
501  - \f$L^1\f$ is the Manhattan distance, the sum of the components
502  - \f$L^2\f$ is the standard Euclidean length
503  - \f$L^{\inf}\f$ is the maximum of the components
504  @{
505 */
506 
507 template <int D>
508 inline double get_l2_norm(const VectorD<D> &v) {
509  return v.get_magnitude();
510 }
511 
512 template <int D>
513 inline double get_l1_norm(const VectorD<D> &v) {
514  double n = std::abs(v[0]);
515  for (unsigned int i = 1; i < v.get_dimension(); ++i) {
516  n += std::abs(v[i]);
517  }
518  return n;
519 }
520 
521 template <int D>
522 inline double get_linf_norm(const VectorD<D> &v) {
523  double n = std::abs(v[0]);
524  for (unsigned int i = 1; i < v.get_dimension(); ++i) {
525  n = std::max(n, std::abs(v[i]));
526  }
527  return n;
528 }
529 
530 /** @} */
531 
532 #ifndef IMP_DOXYGEN
533 
534 template <int D>
535 struct SpacesIO {
536  const VectorD<D> &v_;
537  SpacesIO(const VectorD<D> &v) : v_(v) {}
538 };
539 
540 template <int D>
541 struct CommasIO {
542  const VectorD<D> &v_;
543  CommasIO(const VectorD<D> &v) : v_(v) {}
544 };
545 template <int D>
546 inline std::ostream &operator<<(std::ostream &out, const SpacesIO<D> &s) {
547  s.v_.show(out, " ", false);
548  return out;
549 }
550 template <int D>
551 inline std::ostream &operator<<(std::ostream &out, const CommasIO<D> &s) {
552  s.v_.show(out, ", ", false);
553  return out;
554 }
555 
556 //! Use this before outputing to delimited vector entries with a space
557 /** std::cout << spaces_io(v);
558  produces "1.0 2.0 3.0"
559  See VectorD
560  */
561 template <int D>
562 inline SpacesIO<D> spaces_io(const VectorD<D> &v) {
563  return SpacesIO<D>(v);
564 }
565 
566 //! Use this before outputing to delimited vector entries with a comma
567 /** std::cout << commas_io(v);
568  produces "1.0, 2.0, 3.0"
569  See VectorD
570  */
571 template <int D>
572 inline CommasIO<D> commas_io(const VectorD<D> &v) {
573  return CommasIO<D>(v);
574 }
575 #endif // doxygen
576 
577 #endif // swig
578 /** 1D vector typedef for swig */
580 /** 1D vectors typedef for swig */
582 /** 2D vector typedef for swig */
584 /** 2D vectors typedef for swig */
586 /** 3D vector typedef for swig */
588 /** 3D vectors typedef for swig */
590 /** 4D vector typedef for swig */
592 /** 4D vectors typedef for swig */
594 /** 5D vector typedef for swig */
596 /** 5D vectors typedef for swig */
598 /** 6D vector typedef for swig */
600 /** 6D vector typedef for swig */
602 /** KD vector typedef for swig */
603 typedef VectorD<-1> VectorKD;
604 /** KD vectors typedef for swig */
606 
607 /** See VectorD */
608 template <int D>
609 inline const VectorD<D> &get_vector_d_geometry(const VectorD<D> &g) {
610  return g;
611 }
612 /** See VectorD */
613 template <int D>
614 inline void set_vector_d_geometry(VectorD<D> &g, const VectorD<D> &v) {
615  g = v;
616 }
617 
618 /** See VectorD
619  Return the vector that is the elementwise product of the two.
620 */
621 template <int D>
623  const algebra::VectorD<D> &b) {
624  VectorD<D> ret(a);
625  for (unsigned int i = 0; i < ret.get_dimension(); ++i) {
626  ret[i] *= b[i];
627  }
628  return ret;
629 }
630 
631 /** See VectorD
632  Return the vector that is the elementwise product of the two.
633 */
634 template <int D>
636  const algebra::VectorD<D> &b) {
637  IMP_USAGE_CHECK(a.size() == b.get_dimension(), "Dimensions don't match,");
638  VectorD<D> ret(b);
639  for (unsigned int i = 0; i < ret.get_dimension(); ++i) {
640  ret[i] *= a[i];
641  }
642  return ret;
643 }
644 
645 /** A class to flexibly accept vectors as inputs to functions.
646  See VectorD
647  */
648 template <int D>
649 class VectorInputD : public VectorD<D>, public base::InputAdaptor {
650  public:
651  VectorInputD(const VectorD<D> &v) : VectorD<D>(v) {}
652  VectorInputD(const Floats &v) : VectorD<D>(v, true) {}
653 };
654 
655 /** Also accept floating point values for Vector1Ds
656 
657  See VectorD
658  */
659 template <>
660 class VectorInputD<1> : public VectorD<1>, public base::InputAdaptor {
661  public:
662  VectorInputD(const VectorD<1> &v) : VectorD<1>(v) {}
663  VectorInputD(const Floats &v) : VectorD<1>(v, true) {}
664  VectorInputD(double v) : VectorD<1>(v) {}
665 };
666 
667 /** Typedef for python. */
669 /** Typedef for python. */
671 /** Typedef for python. */
673 /** Typedef for python.*/
675 /** Typedef for python. */
677 /** Typedef for python. */
679 /** Typedef for python. */
681 /** Typedef for python. */
683 /** Typedef for python. */
685 /** Typedef for python. */
687 /** Typedef for python. */
689 /** Typedef for python. */
691 /** Typedef for python. */
693 /** Typedef for python. */
695 
696 IMPALGEBRA_END_NAMESPACE
697 
698 #endif /* IMPALGEBRA_VECTOR_D_H */
Basic types used by IMP.
Basic types used by IMP.
VectorD(double x)
Initialize the 1-vector from its value.
Definition: VectorD.h:117
base::Vector< VectorInputD< 1 > > VectorInput1Ds
Definition: VectorD.h:670
VectorD< D > get_elementwise_product(const algebra::VectorD< D > &a, const algebra::VectorD< D > &b)
Definition: VectorD.h:622
VectorD< 6 > Vector6D
Definition: VectorD.h:599
VectorD< 2 > Vector2D
Definition: VectorD.h:583
VectorInputD< 3 > VectorInput3D
Definition: VectorD.h:676
base::Vector< VectorInputD<-1 > > VectorInputKDs
Definition: VectorD.h:694
VectorInputD< 2 > VectorInput2D
Definition: VectorD.h:672
void set_vector_d_geometry(VectorD< D > &g, const VectorD< D > &v)
Definition: VectorD.h:614
double operator[](unsigned int i) const
Definition: VectorD.h:171
VectorD(const Floats &f)
Definition: VectorD.h:101
VectorD< D > get_zero_vector_kd(int Di)
Return a dynamically sized vector of zeros.
Definition: VectorD.h:454
VectorD< 5 > Vector5D
Definition: VectorD.h:595
RandomNumberGenerator random_number_generator
A shared random number generator.
base::Vector< VectorD< 1 > > Vector1Ds
Definition: VectorD.h:581
base::Vector< VectorInputD< 6 > > VectorInput6Ds
Definition: VectorD.h:690
VectorInputD<-1 > VectorInputKD
Definition: VectorD.h:692
base::Vector< VectorD< 2 > > Vector2Ds
Definition: VectorD.h:585
#define IMP_UNUSED(variable)
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
double get_squared_distance(const VectorD< D > &v1, const VectorD< D > &v2)
compute the squared distance between two vectors
Definition: VectorD.h:393
Random number generators used by IMP.
VectorD(double x, double y)
Initialize a 2-vector from separate x,y values.
Definition: VectorD.h:131
VectorD()
Default constructor.
Definition: VectorD.h:167
VectorInputD< 5 > VectorInput5D
Definition: VectorD.h:684
base::Vector< VectorD< 5 > > Vector5Ds
Definition: VectorD.h:597
VectorD(It b, It e)
Definition: VectorD.h:112
VectorD< 4 > Vector4D
Definition: VectorD.h:591
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
VectorD< D > get_ones_vector_kd(unsigned int Di, double v=1)
Return a vector of ones (or another constant)
Definition: VectorD.h:481
VectorD<-1 > get_basis_vector_kd(int D, unsigned int coordinate)
Return a dynamically sized basis vector.
Definition: VectorD.h:427
VectorD(double x0, double x1, double x2, double x3)
Initialize a 4-vector from separate w,x,y,z values.
Definition: VectorD.h:155
#define IMP_USAGE_CHECK_VARIABLE(variable)
base::Vector< VectorD< 3 > > Vector3Ds
Definition: VectorD.h:589
double get_distance(const Plane3D &pln, const Vector3D &p)
Return the distance between a plane and a point in 3D.
Definition: Plane3D.h:68
base::Vector< VectorInputD< 4 > > VectorInput4Ds
Definition: VectorD.h:682
base::Vector< VectorInputD< 2 > > VectorInput2Ds
Definition: VectorD.h:674
base::Vector< VectorD< 4 > > Vector4Ds
Definition: VectorD.h:593
VectorD< D > operator*(double s, const VectorD< D > &o)
Definition: VectorD.h:385
base::Vector< VectorInputD< 3 > > VectorInput3Ds
Definition: VectorD.h:678
A Cartesian vector in D-dimensions.
Definition: VectorD.h:48
Basic types used by IMP.
int compare(const VectorD< D > &a, const VectorD< D > &b)
lexicographic comparison of two vectors
Definition: VectorD.h:371
base::Vector< VectorD< 6 > > Vector6Ds
Definition: VectorD.h:601
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
VectorD< D > get_zero_vector_d()
Return a vector of zeros.
Definition: VectorD.h:443
VectorD(double x, double y, double z)
Initialize a 3-vector from separate x,y,z values.
Definition: VectorD.h:143
VectorD< D > get_basis_vector_d(unsigned int coordinate)
Return the basis vector for the given coordinate.
Definition: VectorD.h:414
Various general useful functions for IMP.
VectorD< 1 > Vector1D
Definition: VectorD.h:579
base::Vector< VectorD<-1 > > VectorKDs
Definition: VectorD.h:605
Exception definitions and assertions.
VectorD< D > get_ones_vector_d(double v=1)
Return a vector of ones (or another constant)
Definition: VectorD.h:469
void show(Hierarchy h, std::ostream &out=std::cout)
Print out a molecular hierarchy.
IMP::base::Vector< Float > Floats
Standard way to pass a bunch of Float values.
Definition: base/types.h:47
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
VectorD< 3 > Vector3D
Definition: VectorD.h:587
VectorD get_unit_vector() const
Definition: VectorD.h:204
VectorInputD< 4 > VectorInput4D
Definition: VectorD.h:680
Exception definitions and assertions.
VectorInputD< 1 > VectorInput1D
Definition: VectorD.h:668
VectorD<-1 > VectorKD
Definition: VectorD.h:603
VectorInputD< 6 > VectorInput6D
Definition: VectorD.h:688
An exception for an invalid value being passed to IMP.
base::Vector< VectorInputD< 5 > > VectorInput5Ds
Definition: VectorD.h:686
double & operator[](unsigned int i)
Definition: VectorD.h:178