Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
xyz.functions.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file numeric/xyz.functions.hh
11 /// @brief xyzVector and xyzMatrix functions
12 /// @author Frank M. D'Ippolito (Objexx@objexx.com)
13 /// @author Stuart G. Mentzer (Stuart_Mentzer@objexx.com)
14 
15 
16 #ifndef INCLUDED_numeric_xyz_functions_hh
17 #define INCLUDED_numeric_xyz_functions_hh
18 
19 
20 // Package headers
21 #include <numeric/conversions.hh>
22 #include <numeric/NumericTraits.hh>
24 #include <numeric/xyzVector.hh>
25 #include <numeric/xyzMatrix.hh>
27 
28 
29 //utility headers
30 #include <utility/string_util.hh>
31 #include <utility/vector1.hh>
32 
33 // C++ headers
34 #include <cmath>
35 #include <cstdlib>
36 #include <vector>
37 
38 //ObjexxFCL headers
39 #include <ObjexxFCL/FArray2D.hh>
40 
41 namespace numeric {
42 
43 
44 // Products
45 
46 
47 /// @brief xyzMatrix * xyzVector
48 /// @note Same as product( xyzMatrix, xyzVector )
49 //template< typename T >
50 //inline
51 //xyzVector< T >
52 //operator *( xyzMatrix< T > const & m, xyzVector< T > const & v )
53 //{
54 // return xyzVector< T >(
55 // m.xx_ * v.x_ + m.xy_ * v.y_ + m.xz_ * v.z_,
56 // m.yx_ * v.x_ + m.yy_ * v.y_ + m.yz_ * v.z_,
57 // m.zx_ * v.x_ + m.zy_ * v.y_ + m.zz_ * v.z_
58 // );
59 //}
60 
61 /// @brief return the point closest to point p3 that lies on the line
62 /// defined by p1 and p2
63 template< typename T >
64 inline
67 {
68  xyzVector<T> u = p2-p1;
69  xyzVector<T> pq = q-p1;
70  xyzVector<T> w2 = pq-(u*(dot_product(pq,u)/u.magnitude_squared()));
71  xyzVector<T> point = q-w2;
72  return point;
73 }
74 
75 /// @brief calculate center of mass for coordinates
76 template< typename T >
77 inline
80 {
81  xyzVector< T > center_of_mass( 0.0, 0.0, 0.0 );
82  for ( typename utility::vector1< xyzVector< T > >::const_iterator it = coords.begin();
83  it != coords.end();
84  ++it ) {
85  center_of_mass += *it;
86  }
87  center_of_mass /= coords.size();
88  return center_of_mass;
89 }
90 
91 /// @brief xyzMatrix * xyzVector product
92 /// @note Same as xyzMatrix * xyzVector
93 template< typename T >
94 inline
96 product( xyzMatrix< T > const & m, xyzVector< T > const & v )
97 {
98  return xyzVector< T >(
99  m.xx_ * v.x_ + m.xy_ * v.y_ + m.xz_ * v.z_,
100  m.yx_ * v.x_ + m.yy_ * v.y_ + m.yz_ * v.z_,
101  m.zx_ * v.x_ + m.zy_ * v.y_ + m.zz_ * v.z_
102  );
103 }
104 
105 
106 /// @brief xyzMatrix * xyzVector in-place product
107 /// @note Input xyzVector is modified
108 template< typename T >
109 inline
112 {
113  T const x = m.xx_ * v.x_ + m.xy_ * v.y_ + m.xz_ * v.z_;
114  T const y = m.yx_ * v.x_ + m.yy_ * v.y_ + m.yz_ * v.z_;
115  v.z_ = m.zx_ * v.x_ + m.zy_ * v.y_ + m.zz_ * v.z_;
116  v.x_ = x;
117  v.y_ = y;
118  return v;
119 }
120 
121 
122 /// @brief xyzMatrix^T * xyzVector product
123 template< typename T >
124 inline
127 {
128  return xyzVector< T >(
129  m.xx_ * v.x_ + m.yx_ * v.y_ + m.zx_ * v.z_,
130  m.xy_ * v.x_ + m.yy_ * v.y_ + m.zy_ * v.z_,
131  m.xz_ * v.x_ + m.yz_ * v.y_ + m.zz_ * v.z_
132  );
133 }
134 
135 
136 /// @brief xyzMatrix^T * xyzVector in-place transpose product
137 /// @note Input xyzVector is modified
138 template< typename T >
139 inline
142 {
143  T const x = m.xx_ * v.x_ + m.yx_ * v.y_ + m.zx_ * v.z_;
144  T const y = m.xy_ * v.x_ + m.yy_ * v.y_ + m.zy_ * v.z_;
145  v.z_ = m.xz_ * v.x_ + m.yz_ * v.y_ + m.zz_ * v.z_;
146  v.x_ = x;
147  v.y_ = y;
148  return v;
149 }
150 
151 
152 /// @brief xyzVector xyzVector outer product
153 template< typename T >
154 inline
157 {
158  return xyzMatrix< T >(
159  a.x_ * b.x_, a.x_ * b.y_, a.x_ * b.z_,
160  a.y_ * b.x_, a.y_ * b.y_, a.y_ * b.z_,
161  a.z_ * b.x_, a.z_ * b.y_, a.z_ * b.z_
162  );
163 }
164 
165 //Averages
166 
167 
168 /// @brief geometric center
169 /// @note compute the geometric center of a list of points
170 /*
171 template<typename T>
172 inline
173 xyzVector<T>
174 geometric_center(std::vector<xyzVector<T> > const & points)
175 {
176 xyzVector<T> total(0.0,0.0,0.0);
177 std::vector<xyzVector<T> >::iterator points_it = points.begin();
178 for(; points_it != points.end();++points_it)
179 {
180 total += *points_it;
181 }
182 return total/points.size();
183 }
184 */
185 
186 // Projections
187 
188 
189 /// @brief Projection matrix onto the line through a vector
190 template< typename T >
191 inline
194 {
195  return ( xyzMatrix< T >(
196  v.x_ * v.x_, v.x_ * v.y_, v.x_ * v.z_,
197  v.y_ * v.x_, v.y_ * v.y_, v.y_ * v.z_,
198  v.z_ * v.x_, v.z_ * v.y_, v.z_ * v.z_
199  ) /= v.length_squared() );
200 }
201 
202 template< typename T >
203 inline
206  T D = a.det();
207  return xyzMatrix< T >(
208  (a.yy_*a.zz_-a.yz_*a.zy_)/D, -(a.xy_*a.zz_-a.xz_*a.zy_)/D, (a.xy_*a.yz_-a.xz_*a.yy_)/D,
209  -(a.yx_*a.zz_-a.zx_*a.yz_)/D, (a.xx_*a.zz_-a.xz_*a.zx_)/D, -(a.xx_*a.yz_-a.xz_*a.yx_)/D,
210  (a.yx_*a.zy_-a.zx_*a.yy_)/D, -(a.xx_*a.zy_-a.xy_*a.zx_)/D, (a.xx_*a.yy_-a.xy_*a.yx_)/D
211  );
212 }
213 
214 
215 // Angles
216 
217 
218 /// @brief Plane angle in radians: angle value passed
219 /// @note Given thre positions in a chain ( p1, p2, p3 ), calculates the plane
220 /// angle in radians between the vectors p2->p1 and p2->p3
221 /// @note Angle returned is on [ 0, pi ]
222 template< typename T >
223 inline
224 void
226  xyzVector< T > const & p1,
227  xyzVector< T > const & p2,
228  xyzVector< T > const & p3,
229  T & angle // Angle (radians)
230 )
231 {
232  // Two normalized directional vectors hold the relative directions of
233  // p1 and p3 relative to p2
234  xyzVector< T > const a( ( p2 - p1 ).normalize_or_zero() );
235  xyzVector< T > const b( ( p2 - p3 ).normalize_or_zero() );
236 
237  angle = std::acos( sin_cos_range( dot(a, b) ) );
238 }
239 
240 
241 /// @brief Plane angle in radians: angle value returned
242 /// @note Given three positions in a chain ( p1, p2, p3 ), calculates the plane
243 /// angle in radians between the vectors p2->p1 and p2->p3
244 /// @note Angle returned is on [ 0, pi ]
245 template< typename T >
246 inline
247 T // Angle (radians)
249  xyzVector< T > const & p1,
250  xyzVector< T > const & p2,
251  xyzVector< T > const & p3
252 )
253 {
254  T angle;
255  angle_radians( p1, p2, p3, angle );
256  return angle;
257 }
258 
259 // PyRosetta, creating concreate function for template one
260 inline double angle_radians_double(
261  xyzVector< double > const & p1,
262  xyzVector< double > const & p2,
263  xyzVector< double > const & p3) { return angle_radians(p1, p2, p3); }
264 
265 
266 /// @brief Plane angle in degrees: angle value returned
267 /// @note Given three positions in a chain ( p1, p2, p3 ), calculates the plane
268 /// angle in degrees between the vectors p2->p1 and p2->p3
269 /// @note Angle returned is on [ 0, 180 ]
270 template< typename T >
271 inline
272 T // Angle (degrees)
274  xyzVector< T > const & p1,
275  xyzVector< T > const & p2,
276  xyzVector< T > const & p3
277 )
278 {
279  T angle;
280  angle_radians( p1, p2, p3, angle );
281  return conversions::degrees(angle);
282 }
283 
284 // PyRosetta, creating concreate function for template one
285 inline double angle_degrees_double(
286  xyzVector< double > const & p1,
287  xyzVector< double > const & p2,
288  xyzVector< double > const & p3) { return angle_degrees(p1, p2, p3); }
289 
290 
291 /// @brief Angle between two vectors in radians
292 /// @note Given two vectors (p1->p2 & p3->p4),
293 /// calculate the angle between them
294 /// @note Angle returned is on [ 0, pi ]
295 template< typename T >
296 inline
297 T // Angle (radians)
299  xyzVector< T > const & p1,
300  xyzVector< T > const & p2,
301  xyzVector< T > const & p3,
302  xyzVector< T > const & p4
303 )
304 {
305  xyzVector< T > const a( ( p2 - p1 ).normalize_or_zero() );
306  xyzVector< T > const b( ( p4 - p3 ).normalize_or_zero() );
307 
308  T angle = std::acos( sin_cos_range( dot(a, b) ) );
309  return angle;
310 }
311 
312 // PyRosetta, creating concreate function for template one
313 inline double angle_radians_double(
314  xyzVector< double > const & p1,
315  xyzVector< double > const & p2,
316  xyzVector< double > const & p3,
317  xyzVector< double > const & p4) { return angle_radians(p1, p2, p3, p4); }
318 
319 
320 /// @brief Angle between two vectors in radians
321 /// @note Given two vectors (p1->p2 & p3->p4),
322 /// calculate the angle between them
323 /// @note Angle returned is on [ 0, pi ]
324 template< typename T >
325 inline
326 T // Angle (radians)
328  xyzVector< T > const & p1,
329  xyzVector< T > const & p2,
330  xyzVector< T > const & p3,
331  xyzVector< T > const & p4
332 )
333 {
334  T angle = angle_radians( p1, p2, p3, p4 );
335  return conversions::degrees(angle);
336 }
337 
338 // PyRosetta, creating concreate function for template one
339 inline double angle_degrees_double(
340  xyzVector< double > const & p1,
341  xyzVector< double > const & p2,
342  xyzVector< double > const & p3,
343  xyzVector< double > const & p4) { return angle_degrees(p1, p2, p3, p4); }
344 
345 
346 /// @brief Dihedral (torsion) angle in radians: angle value passed
347 /// @note Given four positions in a chain ( p1, p2, p3, p4 ), calculates the dihedral
348 /// (torsion) angle in radians between the vectors p2->p1 and p3->p4 while sighting
349 /// along the axis defined by the vector p2->p3 (positive indicates right handed twist)
350 /// @note Angle returned is on [ -pi, pi ]
351 /// @note Degenerate cases are handled and assigned a zero angle but assumed rare
352 /// (wrt performance tuning)
353 /// @note For a reference on the determination of the dihedral angle formula see:
354 /// http://www.math.fsu.edu/~quine/IntroMathBio_04/torsion_pdb/torsion_pdb.pdf
355 template< typename T >
356 inline
357 void
359  xyzVector< T > const & p1,
360  xyzVector< T > const & p2,
361  xyzVector< T > const & p3,
362  xyzVector< T > const & p4,
363  T & angle // Angle (radians)
364 )
365 {
366  static T const ZERO( 0 );
367 
368  // Three normalized directional vectors hold the relative directions of
369  // the points (the dihedral angle formula used below is only valid for
370  // normalized vectors)
371  xyzVector< T > const a( ( p2 - p1 ).normalize_or_zero() );
372  xyzVector< T > const b( ( p3 - p2 ).normalize_or_zero() );
373  xyzVector< T > const c( ( p4 - p3 ).normalize_or_zero() );
374 
375  // Compute the dihedral angle: Degenerate cases are assigned a zero angle by definition
376  // Degenerate cases: Coincident adjacent points or parallel adjacent directional vectors
377  if ( ( b == ZERO ) ) { // p2 == p3: Handle specially: atan2( 0, -dot( a, c ) ) == 0 or pi
378  angle = ZERO;
379  } else { // Use the formula
380  // Degenerate cases a == 0, c == 0, a||b, and b||c give x == y == 0
381  T const x = -dot( a, c ) + ( dot( a, b ) * dot( b, c ) );
382  T const y = dot( a, cross( b, c ) );
383  // Angle in [ -pi, pi ]
384  angle = ( ( y != ZERO ) || ( x != ZERO ) ? std::atan2( y, x ) : ZERO );
385  }
386 }
387 
388 // PyRosetta, creating concreate function for template one
390  xyzVector< double > const & p1,
391  xyzVector< double > const & p2,
392  xyzVector< double > const & p3,
393  xyzVector< double > const & p4,
394  double & angle // Angle (radians)
395 ) { dihedral_radians(p1, p2, p3, p4, angle); }
396 
397 
398 /// @brief Dihedral (torsion) angle in radians: angle value returned
399 /// @note Given four positions in a chain ( p1, p2, p3, p4 ), calculates the dihedral
400 /// (torsion) angle in radians between the vectors p2->p1 and p3->p4 while sighting
401 /// along the axis defined by the vector p2->p3 (positive indicates right handed twist)
402 /// @note Angle returned is on [ -pi, pi ]
403 /// @note Degenerate cases are handled and assigned a zero angle but assumed rare
404 /// (wrt performance tuning)
405 /// @note For a reference on the determination of the dihedral angle formula see:
406 /// http://www.math.fsu.edu/~quine/IntroMathBio_04/torsion_pdb/torsion_pdb.pdf
407 template< typename T >
408 inline
409 T // Angle (radians)
411  xyzVector< T > const & p1,
412  xyzVector< T > const & p2,
413  xyzVector< T > const & p3,
414  xyzVector< T > const & p4
415 )
416 {
417  T angle;
418  dihedral_radians( p1, p2, p3, p4, angle );
419  return angle;
420 }
421 
422 // PyRosetta, creating concreate function for template one
424  xyzVector< double > const & p1,
425  xyzVector< double > const & p2,
426  xyzVector< double > const & p3,
427  xyzVector< double > const & p4
428 ) { return dihedral_radians(p1, p2, p3, p4); }
429 
430 
431 /// @brief Dihedral (torsion) angle in degrees: angle value passed
432 template< typename T >
433 inline
434 void
436  xyzVector< T > const & p1,
437  xyzVector< T > const & p2,
438  xyzVector< T > const & p3,
439  xyzVector< T > const & p4,
440  T & angle // Angle (degrees)
441 )
442 {
443  dihedral_radians( p1, p2, p3, p4, angle );
444  conversions::to_degrees( angle );
445 }
446 
447 // PyRosetta, creating concreate function for template one
449  xyzVector< double > const & p1,
450  xyzVector< double > const & p2,
451  xyzVector< double > const & p3,
452  xyzVector< double > const & p4,
453  double & angle // Angle (radians)
454 ) { dihedral_degrees(p1, p2, p3, p4, angle); }
455 
456 
457 /// @brief Dihedral (torsion) angle in degrees: angle value returned
458 template< typename T >
459 inline
460 T // Angle (degrees)
462  xyzVector< T > const & p1,
463  xyzVector< T > const & p2,
464  xyzVector< T > const & p3,
465  xyzVector< T > const & p4
466 )
467 {
468  return conversions::degrees( dihedral_radians( p1, p2, p3, p4 ) );
469 }
470 
471 
472 // PyRosetta, creating concreate function for template one
474  xyzVector< double > const & p1,
475  xyzVector< double > const & p2,
476  xyzVector< double > const & p3,
477  xyzVector< double > const & p4
478 ) { return dihedral_degrees(p1, p2, p3, p4); }
479 
480 
481 /// @brief Dihedral (torsion) angle in degrees: angle value passed
482 /// @note This is a Rosetta++ compatibility version that operates in degrees
483 template< typename T >
484 inline
485 void
487  xyzVector< T > const & p1,
488  xyzVector< T > const & p2,
489  xyzVector< T > const & p3,
490  xyzVector< T > const & p4,
491  T & angle // Angle (degrees)
492 )
493 {
494  dihedral_radians( p1, p2, p3, p4, angle );
495  conversions::to_degrees( angle );
496 }
497 
498 // PyRosetta, creating concreate function for template one
499 inline void dihedral_double(
500  xyzVector< double > const & p1,
501  xyzVector< double > const & p2,
502  xyzVector< double > const & p3,
503  xyzVector< double > const & p4,
504  double & angle // Angle (degrees)
505 ) { dihedral(p1, p2, p3, p4, angle); }
506 
507 
508 /// @brief Dihedral (torsion) angle in degrees: angle value returned
509 /// @note This is a Rosetta++ compatibility version that operates in degrees
510 template< typename T >
511 inline
512 T // Angle (degrees)
514  xyzVector< T > const & p1,
515  xyzVector< T > const & p2,
516  xyzVector< T > const & p3,
517  xyzVector< T > const & p4
518 )
519 {
520  return conversions::degrees( dihedral_radians( p1, p2, p3, p4 ) );
521 }
522 
523 
524 // PyRosetta, creating concreate function for template one
525 inline double dihedral_double(
526  xyzVector< double > const & p1,
527  xyzVector< double > const & p2,
528  xyzVector< double > const & p3,
529  xyzVector< double > const & p4
530 ) { return dihedral(p1, p2, p3, p4); }
531 
532 
533 // @brief Rotation matrix for rotation from axis-angle representation
534 // @note Magnitude of rotation (in radians) is taken as axis_angle.magnitude
535 template< typename T >
536 inline
538 rotation_matrix(xyzVector< T > const & axis_angle)
539 {
540  // rotation_matrix performs axis vector normalization
541  return rotation_matrix(axis_angle, axis_angle.magnitude());
542 }
543 
544 /// @brief Rotation matrix for rotation about an axis by an angle in radians
545 template< typename T >
546 inline
549  xyzVector< T > const & axis,
550  T const & theta // Angle (radians)
551 )
552 {
553  xyzVector< T > const n( axis.normalized() );
554 
555  T const sin_theta( std::sin( theta ) );
556  T const cos_theta( std::cos( theta ) );
557 
558  xyzMatrix< T > R( projection_matrix( n ) *= ( T( 1 ) - cos_theta ) );
559 
560  R.xx_ += cos_theta; R.xy_ -= sin_theta * n.z_; R.xz_ += sin_theta * n.y_;
561  R.yx_ += sin_theta * n.z_; R.yy_ += cos_theta; R.yz_ -= sin_theta * n.x_;
562  R.zx_ -= sin_theta * n.y_; R.zy_ += sin_theta * n.x_; R.zz_ += cos_theta;
563 
564  return R;
565 }
566 
567 
568 /// @brief Rotation matrix for rotation about an axis by an angle in radians
569 template< typename T >
570 inline
573  xyzVector< T > const & axis,
574  T const & theta // Angle (radians)
575 )
576 {
577  return rotation_matrix( axis, theta );
578 }
579 
580 
581 /// @brief Rotation matrix for rotation about an axis by an angle in degrees
582 template< typename T >
583 inline
586  xyzVector< T > const & axis,
587  T const & theta // Angle (degrees)
588 )
589 {
590  return rotation_matrix( axis, conversions::radians( theta ) );
591 }
592 
593 
594 /// @brief Rotation matrix for rotation about the x axis by an angle in radians
595 template< typename T >
596 inline
599  T const & theta // Angle (radians)
600 )
601 {
602  T const sin_theta( std::sin( theta ) );
603  T const cos_theta( std::cos( theta ) );
604 
605  return xyzMatrix< T >::rows(
606  T( 1 ), T( 0 ), T( 0 ),
607  T( 0 ), cos_theta, -sin_theta,
608  T( 0 ), sin_theta, cos_theta
609  );
610 }
611 
612 
613 /// @brief Rotation matrix for rotation about the x axis by an angle in radians
614 template< typename T >
615 inline
618  T const & theta // Angle (radians)
619 )
620 {
621  return x_rotation_matrix( theta );
622 }
623 
624 
625 /// @brief Rotation matrix for rotation about the x axis by an angle in degrees
626 template< typename T >
627 inline
630  T const & theta // Angle (degrees)
631 )
632 {
633  return x_rotation_matrix( conversions::radians( theta ) );
634 }
635 
636 
637 /// @brief Rotation matrix for rotation about the y axis by an angle in radians
638 template< typename T >
639 inline
642  T const & theta // Angle (radians)
643 )
644 {
645  T const sin_theta( std::sin( theta ) );
646  T const cos_theta( std::cos( theta ) );
647 
648  return xyzMatrix< T >::rows(
649  cos_theta, T( 0 ), sin_theta,
650  T( 0 ), T( 1 ), T( 0 ),
651  -sin_theta, T( 0 ), cos_theta
652  );
653 }
654 
655 
656 /// @brief Rotation matrix for rotation about the y axis by an angle in radians
657 template< typename T >
658 inline
661  T const & theta // Angle (radians)
662 )
663 {
664  return y_rotation_matrix( theta );
665 }
666 
667 
668 /// @brief Rotation matrix for rotation about the y axis by an angle in degrees
669 template< typename T >
670 inline
673  T const & theta // Angle (degrees)
674 )
675 {
676  return y_rotation_matrix( conversions::radians( theta ) );
677 }
678 
679 
680 /// @brief Rotation matrix for rotation about the z axis by an angle in radians
681 template< typename T >
682 inline
685  T const & theta // Angle (radians)
686 )
687 {
688  T const sin_theta = static_cast< T > ( std::sin( theta ) );
689  T const cos_theta = static_cast< T > ( std::cos( theta ) );
690 
691  return xyzMatrix< T >::rows(
692  cos_theta, -sin_theta, T( 0 ),
693  sin_theta, cos_theta, T( 0 ),
694  T( 0 ) , T( 0 ), T( 1 )
695  );
696 }
697 
698 
699 /// @brief Rotation matrix for rotation about the z axis by an angle in radians
700 template< typename T >
701 inline
704  T const & theta // Angle (radians)
705 )
706 {
707  return z_rotation_matrix( theta );
708 }
709 
710 
711 /// @brief Rotation matrix for rotation about the z axis by an angle in degrees
712 template< typename T >
713 inline
716  T const & theta // Angle (degrees)
717 )
718 {
719  return z_rotation_matrix( conversions::radians( theta ) );
720 }
721 
722 
723 /// @brief Helper function to find the rotation to optimally transform the vectors A1-B1 to vectors A2-B2
724 template< typename T >
725 inline
728  xyzVector< T > A1,
729  xyzVector< T > B1,
730  xyzVector< T > A2,
731  xyzVector< T > B2 ) {
732  // 1) find rotation to align canonic +z to each vector pair's +z (defined as the avg of the two vectors)
733  xyzVector< T > X1 = (A1+B1); X1.normalize();
734  xyzVector< T > X2 = (A2+B2); X2.normalize();
735 
736  T cb1 = X1[2], sb1 = sqrt(1-(X1[2]*X1[2]));
737  T Rg1 = sqrt((X1[0]*X1[0])+(X1[1]*X1[1]));
738  T cg1 = X1[1]/Rg1, sg1 = X1[0]/Rg1;
739 
740  T cb2 = X2[2], sb2 = sqrt(1-(X2[2]*X2[2]));
741  T Rg2 = sqrt((X2[0]*X2[0])+(X2[1]*X2[1]));
742  T cg2 = X2[1]/Rg2, sg2 = X2[0]/Rg2;
743 
744  xyzMatrix< T > R1gb, R2gb, R1gb_i, R2gb_i;
745  R1gb.xx( cg1 ); R1gb.xy(cb1*sg1); R1gb.xz(sb1*sg1);
746  R1gb.yx(-sg1 ); R1gb.yy(cb1*cg1); R1gb.yz(sb1*cg1);
747  R1gb.zx( 0 ); R1gb.zy(-sb1) ; R1gb.zz(cb1);
748 
749  R2gb.xx( cg2 ); R2gb.xy(cb2*sg2); R2gb.xz(sb2*sg2);
750  R2gb.yx(-sg2 ); R2gb.yy(cb2*cg2); R2gb.yz(sb2*cg2);
751  R2gb.zx( 0 ); R2gb.zy(-sb2) ; R2gb.zz(cb2);
752 
753  R1gb_i = numeric::inverse( R1gb );
754  R2gb_i = numeric::inverse( R2gb );
755 
756  // 2) now choose one of the two vectors (A1/A2) to define the xz plane
757  A1.normalize();
758  A2.normalize();
759  numeric::xyzVector< T > RgbA1 = R1gb_i*A1;
760  numeric::xyzVector< T > RgbA2 = R2gb_i*A2;
761 
762  T Ra1 = sqrt((RgbA1[0]*RgbA1[0])+(RgbA1[1]*RgbA1[1]));
763  T Ra2 = sqrt((RgbA2[0]*RgbA2[0])+(RgbA2[1]*RgbA2[1]));
764  T ca1 = RgbA1[1]/Ra1, sa1 = RgbA1[0]/Ra1;
765  T ca2 = RgbA2[1]/Ra2, sa2 = RgbA2[0]/Ra2;
766 
767  numeric::xyzMatrix< T > R1, R2, R1_i, R;
768  R1.xx( -sa1*cb1*sg1 + ca1*cg1 ); R1.xy( ca1*cb1*sg1 + sa1*cg1 ); R1.xz( sb1*sg1 );
769  R1.yx( -sa1*cb1*cg1 - ca1*sg1 ); R1.yy( ca1*cb1*cg1 - sa1*sg1 ); R1.yz( sb1*cg1 );
770  R1.zx( sa1*sb1 ); R1.zy( -ca1*sb1 ); R1.zz( cb1 );
771 
772  R2.xx( -sa2*cb2*sg2 + ca2*cg2 ); R2.xy( ca2*cb2*sg2 + sa2*cg2 ); R2.xz( sb2*sg2 );
773  R2.yx( -sa2*cb2*cg2 - ca2*sg2 ); R2.yy( ca2*cb2*cg2 - sa2*sg2 ); R2.yz( sb2*cg2 );
774  R2.zx( sa2*sb2 ); R2.zy( -ca2*sb2 ); R2.zz( cb2 );
775 
776  // 3) the rotation matrix first rotates 1 to canonical, then canonical to 2
777  R1_i = numeric::inverse( R1 );
778  R = R2*R1_i;
779 
780  return R;
781 }
782 
783 /// @brief Transformation from rotation matrix to magnitude of helical rotation
784 /// @note Input matrix must be orthogonal
785 /// @note Orientation of axis chosen so that the angle of rotation is non-negative [0,pi]
786 // @note numeric::rotation_axis returns both axis and angle of rotation
787 template< typename T >
788 inline
789 T
791 {
792  using std::abs;
793  using std::acos;
794  using std::sqrt;
795 
796  // This would be good here but slow and unclear what tolerance to use
797  // assert( rm.orthogonal() );
798 
799  static T const ZERO( 0 );
800  static T const ONE( 1 );
801  static T const TWO( 2 );
802 
803  T const cos_theta = sin_cos_range( ( R.trace() - ONE ) / TWO );
804 
805  T const tolerance = NumericTraits< T >::sin_cos_tolerance();
806  if ( cos_theta > -ONE + tolerance && cos_theta < ONE - tolerance ) {
807  return acos( cos_theta );
808  } else if ( cos_theta >= ONE - tolerance ) {
809  // R is the identity matrix, return an arbitrary axis of rotation
810  return ZERO;
811  } else { // cos_theta <= -ONE + tolerance
812  return NumericTraits< T >::pi(); // theta == pi
813  }
814 }
815 
816 /// @brief Transformation from rotation matrix to helical axis of rotation
817 /// @note Input matrix must be orthogonal
818 /// @note Angle of rotation is also returned
819 /// @note Orientation of axis chosen so that the angle of rotation is non-negative [0,pi]
820 template< typename T >
821 inline
823 rotation_axis( xyzMatrix< T > const & R, T & theta )
824 {
825  using std::abs;
826  using std::acos;
827  using std::sqrt;
828 
829  // This would be good here but slow and unclear what tolerance to use
830  // assert( rm.orthogonal() );
831 
832  static T const ZERO( 0 );
833  static T const ONE( 1 );
834  static T const TWO( 2 );
835 
836  T const cos_theta = sin_cos_range( ( R.trace() - ONE ) / TWO );
837 
838  T const tolerance = NumericTraits< T >::sin_cos_tolerance();
839  if ( cos_theta > -ONE + tolerance && cos_theta < ONE - tolerance ) {
840  // Compute sign and absolute value of axis vector elements from matrix elements
841  // Sign of axis vector is chosen to correspond to a positive sin_theta value
842  T x = ( R.zy_ > R.yz_ ? ONE : -ONE ) *
843  sqrt( max( ZERO, ( R.xx_ - cos_theta ) / ( ONE - cos_theta ) ) );
844  T y = ( R.xz_ > R.zx_ ? ONE : -ONE ) *
845  sqrt( max( ZERO, ( R.yy_ - cos_theta ) / ( ONE - cos_theta ) ) );
846  T z = ( R.yx_ > R.xy_ ? ONE : -ONE ) *
847  sqrt( max( ZERO, ( R.zz_ - cos_theta ) / ( ONE - cos_theta ) ) );
848  // Above method appears to cover a greater range of cases than the original method:
849  //
850  // return ( xyzVector< T >( R.zy_ - R.yz_, R.xz_ - R.zx_, R.yx_ - R.xy_ )
851  // /= ( TWO * sine_theta ) );
852  //
853  // and is more stable for small sine_theta
854 
855  theta = acos( cos_theta );
856  assert( std::abs( x*x + y*y + z*z - 1 ) <= T( 0.01 ) );
857 
858  return xyzVector< T >( x, y, z );
859  } else if ( cos_theta >= ONE - tolerance ) {
860  // R is the identity matrix, return an arbitrary axis of rotation
861  theta = ZERO;
862  return xyzVector< T >( ONE, ZERO, ZERO );
863  } else { // cos_theta <= -ONE + tolerance
864  // R is of the form 2*n*n^T - I, theta == pi
865  xyzMatrix< T > const nnT( xyzMatrix< T >( R ).add_diagonal( ONE, ONE, ONE ) /= TWO );
866  T x, y, z;
867  // Since theta = pi, both n and -n are equally valid axis vectors
868  // Use convention to take first non-zero coordinate positive
869  if ( nnT.xx_ > ZERO + tolerance ) {
870  // Note: x is positive, but negative would also work
871  x = sqrt( nnT.xx_ );
872  y = nnT.yx_ / x;
873  z = nnT.zx_ / x;
874  } else if ( nnT.yy_ > ZERO + tolerance ) {
875  // nnT.xx_ = n.x_ == ZERO, in this case
876  x = ZERO;
877  // Note: y is positive, but negative would also work
878  y = sqrt( nnT.yy_ );
879  z = nnT.zy_ / y;
880  } else { // nnT.yy_ = n.y_ == ZERO, also, in this case
881  // If we get here nnT.zz_ must be positive!
882  assert( nnT.zz_ > ZERO + tolerance );
883  x = ZERO;
884  y = ZERO;
885  // Note: z is positive, but negative would also work
886  z = sqrt( nnT.zz_ );
887  }
888  theta = NumericTraits< T >::pi(); // theta == pi
889  // For a valid orthogonal matrix R, axis should be a normal vector
890  assert( std::abs( x*x + y*y + z*z - 1 ) <= T( 0.01 ) );
891  return xyzVector< T >( x, y, z );
892  }
893 }
894 
895 /// @brief Transformation from rotation matrix to compact axis-angle representation
896 /// @note Input matrix must be orthogonal
897 /// @note Orientation of axis chosen so that the angle of rotation is non-negative [0,pi]
898 // @note Resulting vector will be oriented in axis of rotation with magnitude equal to magnitude of rotation.
899 template< typename T>
900 inline
903 {
904  T theta;
905  xyzVector< T > vec = rotation_axis(R, theta);
906 
907  return vec * theta;
908 }
909 
910 // Eigenvalues/vectors
911 
912 
913 /// @brief Classic Jacobi algorithm for the eigenvalues of a real symmetric matrix
914 /// @note Use eigenvector_jacobi if eigenvectors are also desired
915 template< typename T >
916 inline
919 {
920  using std::abs;
921 
922  // May need a tolerance based test here
923  assert( ( a.xy_ == a.yx_ ) && ( a.xz_ == a.zx_ ) && ( a.yz_ == a.zy_ ) );
924 
925  // Copy matrix as it will be modified by the algorithm
926  xyzMatrix< T > m( a );
927 
928  // Initialize the off-diagonal, upper-triangular sum of squares
929  T off = ( m.xy_ * m.xy_ ) + ( m.xz_ * m.xz_ ) + ( m.yz_ * m.yz_ );
930 
931  int i, j, n_iterations = 0;
932  xyzMatrix< T > r;
933  while ( off > tol ) {
934  ++n_iterations;
935 
936  // Ensure number of iterations does not exceed 50:
937  // otherwise, re-evaluate stopping criterion
938  assert( n_iterations <= 50 );
939 
940  // Determine index of upper-triangular element that will be zeroed out
941  if ( std::abs( m.xy_ ) >= std::abs( m.xz_ ) ) {
942  if ( std::abs( m.xy_ ) >= std::abs( m.yz_ ) ) {
943  i = 1; j = 2;
944  } else {
945  i = 2; j = 3;
946  }
947  } else if ( std::abs( m.xz_ ) >= std::abs( m.yz_ ) ) {
948  i = 1; j = 3;
949  } else {
950  i = 2; j = 3;
951  }
952 
953  // After four iterations, skip the rotation if the off-diagonal element is small
954  T const ij_scaled = std::abs( T( 100 ) * m(i,j) );
955  if ( ( n_iterations > 4 )
956  && std::abs( m(i,i) ) + ij_scaled == std::abs( m(i,i) )
957  && std::abs( m(j,j) ) + ij_scaled == std::abs( m(j,j) ) ) {
958  m(i,j) = m(j,i) = T( 0 );
959  } else {
960  // Compute the rotation matrix
961  jacobi_rotation( m, i, j, r );
962 
963  // Zero out the i,j and j,i elements
964  m.right_multiply_by( r );
966  }
967 
968  // Recalculate the off-diagonal, upper-triangular sum of squares
969  off = ( m.xy_ * m.xy_ ) + ( m.xz_ * m.xz_ ) + ( m.yz_ * m.yz_ );
970  }
971 
972  return xyzVector< T >( m.xx_, m.yy_, m.zz_ );
973 }
974 
975 
976 /// @brief Classic Jacobi algorithm for the eigenvalues and eigenvectors of a
977 /// real symmetric matrix
978 /// @note Use eigenvalue_jacobi if eigenvectors are not desired
979 template< typename T >
980 inline
983 {
984  using std::abs;
985 
986  // May need a tolerance based test here
987  assert( ( a.xy_ == a.yx_ ) && ( a.xz_ == a.zx_ ) && ( a.yz_ == a.zy_ ) );
988 
989  // Copy matrix as it will be modified by the algorithm
990  xyzMatrix< T > m( a );
991 
992  // Initialize the off-diagonal, upper-triangular sum of squares
993  T off = ( m.xy_ * m.xy_ ) + ( m.xz_ * m.xz_ ) + ( m.yz_ * m.yz_ );
994 
995  J.to_identity();
996  int i, j, n_iterations = 0;
997  xyzMatrix< T > r;
998  while ( off > tol ) {
999  ++n_iterations;
1000 
1001  // Ensure number of iterations does not exceed 50:
1002  // otherwise, re-evaluate stopping criterion
1003  assert( n_iterations <= 50 );
1004 
1005  // Determine index of upper-triangular element that will be zeroed out
1006  if ( std::abs( m.xy_ ) >= std::abs( m.xz_ ) ) {
1007  if ( std::abs( m.xy_ ) >= std::abs( m.yz_ ) ) {
1008  i = 1; j = 2;
1009  } else {
1010  i = 2; j = 3;
1011  }
1012  } else if ( std::abs( m.xz_ ) >= std::abs( m.yz_ ) ) {
1013  i = 1; j = 3;
1014  } else {
1015  i = 2; j = 3;
1016  }
1017 
1018  // After four iterations, skip the rotation if the off-diagonal element is small
1019  T const ij_scaled = std::abs( T( 100 ) * m(i,j) );
1020  if ( ( n_iterations > 4 )
1021  && std::abs( m(i,i) ) + ij_scaled == std::abs( m(i,i) )
1022  && std::abs( m(j,j) ) + ij_scaled == std::abs( m(j,j) ) ) {
1023  m(i,j) = m(j,i) = T( 0 );
1024  } else {
1025  // Compute the rotation matrix
1026  jacobi_rotation( m, i, j, r );
1027 
1028  // Zero out the i,j and j,i elements
1029  m.right_multiply_by( r );
1031 
1032  // Accumulate the rotation transformations to form the matrix of eigenvectors
1033  J *= r;
1034  }
1035 
1036  // Recalculate the off-diagonal, upper-triangular sum of squares
1037  off = ( m.xy_ * m.xy_ ) + ( m.xz_ * m.xz_ ) + ( m.yz_ * m.yz_ );
1038  }
1039 
1040  return xyzVector< T >( m.xx_, m.yy_, m.zz_ );
1041 }
1042 
1043 
1044 /// @brief Jacobi rotation
1045 /// @note Compute the orthogonal transformation used to zero out a pair of
1046 /// off-diagonal elements
1047 template< typename T >
1048 inline
1049 void
1050 jacobi_rotation( xyzMatrix< T > const & m, int const i, int const j, xyzMatrix< T > & r )
1051 {
1052  using std::abs;
1053  using std::sqrt;
1054 
1055  assert( ( i > 0 ) && ( i <= 3 ) );
1056  assert( ( j > 0 ) && ( j <= 3 ) );
1057  assert( i != j );
1058 
1059  static T const ZERO( 0 );
1060  static T const ONE( 1 );
1061 
1062  T const tau = ( m(i,i) - m(j,j) ) / ( 2 * m(i,j) );
1063  T const t = ( tau < ZERO ? -ONE : ONE ) / ( std::abs( tau ) + sqrt( ONE + ( tau * tau ) ) );
1064 
1065  T const c = ONE / sqrt( ONE + ( t * t ) );
1066  T const s = c * t;
1067 
1068  r.to_identity();
1069  r(i,i) = c; r(i,j) = -s;
1070  r(j,i) = s; r(j,j) = c;
1071 }
1072 
1073 template<typename T>
1074 inline
1075 sphericalVector<T>
1077 {
1078 
1079  sphericalVector<T> spherical;
1080  spherical.radius(sqrt((xyz.x()*xyz.x())+(xyz.y()*xyz.y())+(xyz.z()*xyz.z())));
1081  spherical.theta(acos(xyz.z()/spherical.radius())*(1/numeric::constants::f::pi_over_180)) ;
1082  spherical.phi(atan2((xyz.y()),(xyz.x()))*(1/numeric::constants::f::pi_over_180));
1083  return spherical;
1084 }
1085 
1086 template<typename T>
1087 inline
1088 xyzVector<T>
1090 {
1091  xyzVector<T> xyz;
1092  xyz.x(spherical.radius()*sin(spherical.theta()*numeric::constants::f::pi_over_180)*cos(spherical.phi()*numeric::constants::f::pi_over_180));
1093  xyz.y(spherical.radius()*sin(spherical.theta()*numeric::constants::f::pi_over_180)*sin(spherical.phi()*numeric::constants::f::pi_over_180));
1094  xyz.z(spherical.radius()*cos(spherical.theta()*numeric::constants::f::pi_over_180));
1095  return xyz;
1096 }
1097 
1098 
1099 /// @brief convert a string of comma separated values "0.2,0.4,0.3" to an xyzVector
1100 template<typename T>
1101 inline
1102 xyzVector<T>
1103 comma_seperated_string_to_xyz(std::string triplet)
1104 {
1105  utility::vector1<std::string> split_string(utility::string_split(triplet, ','));
1106  runtime_assert(split_string.size() == 3);
1107  xyzVector<T> xyz;
1108  xyz.x(utility::from_string(split_string[1],T(0.0)));
1109  xyz.y(utility::from_string(split_string[2],T(0.0)));
1110  xyz.z(utility::from_string(split_string[3],T(0.0)));
1111  return xyz;
1112 
1113 }
1114 
1115 
1116 /// @brief convert a vector1 of xyzVectors to an FArray2D
1117 template<typename T>
1118 inline
1121 {
1123  for ( numeric::Real index = 1; index <= input.size(); ++index ) {
1124  output(1,(int)index) = input[(int)index].x(); // bazzoli: added cast to silence warning.
1125  output(2,(int)index) = input[(int)index].y();
1126  output(3,(int)index) = input[(int)index].z();
1127  }
1128  return output;
1129 }
1130 
1131 /// @brief convert an FArray2D to a vector of xyzVectors
1132 template<typename T>
1133 inline
1136 {
1137  assert(input.size1() == 3);
1139  for ( numeric::Real index = 1; index <= input.size2(); ++index ) {
1140  output[(int)index].x(input(1,(int)index));
1141  output[(int)index].y(input(2,(int)index));
1142  output[(int)index].z(input(3,(int)index));
1143  }
1144 
1145  return output;
1146 }
1147 
1148 /// @brief convert a 3x3 FArray 2D to an xyzMatrix
1149 template<typename T>
1150 inline
1153 {
1154  assert(input.size1() == 3 && input.size2() == 3);
1155 
1156  return xyzMatrix<T>::rows(
1157  input(1,1),input(1,2),input(1,3),
1158  input(2,1),input(2,2),input(2,3),
1159  input(3,1),input(3,2),input(3,3)
1160  );
1161 }
1162 
1163 /// @brief convert an xyzMatrix to a 3x3 FArray 2D
1164 template<typename T>
1165 inline
1167 {
1169  output(1,1) = input.xx();
1170  output(1,2) = input.xy();
1171  output(1,3) = input.xz();
1172  output(2,1) = input.yx();
1173  output(2,2) = input.yy();
1174  output(2,3) = input.yz();
1175  output(3,1) = input.zx();
1176  output(3,2) = input.zy();
1177  output(3,3) = input.zz();
1178 
1179  return output;
1180 
1181 }
1182 
1183 } // namespace numeric
1184 
1185 
1186 #endif // INCLUDED_numeric_xyz_functions_HH
xyzVector< T > eigenvector_jacobi(xyzMatrix< T > const &a, T const &tol, xyzMatrix< T > &J)
Classic Jacobi algorithm for the eigenvalues and eigenvectors of a real symmetric matrix...
void normalized(xyzVector &a) const
Normalized.
Definition: xyzVector.hh:735
Type const pi_over_180
Definition: constants.cc:40
xyzMatrix< T > z_rotation_matrix(T const &theta)
Rotation matrix for rotation about the z axis by an angle in radians.
xyzVector< T > comma_seperated_string_to_xyz(std::string triplet)
convert a string of comma separated values "0.2,0.4,0.3" to an xyzVector
Numeric type traits.
Value const & zz() const
Value zz const.
Definition: xyzMatrix.hh:1623
xyzMatrix< T > y_rotation_matrix_degrees(T const &theta)
Rotation matrix for rotation about the y axis by an angle in degrees.
Value det() const
Determinant.
Definition: xyzMatrix.hh:1794
void angle_radians(xyzVector< T > const &p1, xyzVector< T > const &p2, xyzVector< T > const &p3, T &angle)
Plane angle in radians: angle value passed.
void dihedral_radians_double(xyzVector< double > const &p1, xyzVector< double > const &p2, xyzVector< double > const &p3, xyzVector< double > const &p4, double &angle)
utility::keys::KeyLookup< KeyType >::const_iterator const_iterator
Key collection iterators.
static xyzMatrix rows(Value const &xx_a, Value const &xy_a, Value const &xz_a, Value const &yx_a, Value const &yy_a, Value const &yz_a, Value const &zx_a, Value const &zy_a, Value const &zz_a)
Row-ordered value named constructor.
Definition: xyzMatrix.hh:322
Value magnitude_squared() const
Magnitude squared.
Definition: xyzVector.hh:1683
void dihedral_radians(xyzVector< T > const &p1, xyzVector< T > const &p2, xyzVector< T > const &p3, xyzVector< T > const &p4, T &angle)
Dihedral (torsion) angle in radians: angle value passed.
xyzVector< T > rotation_axis(xyzMatrix< T > const &R, T &theta)
Transformation from rotation matrix to helical axis of rotation.
Value x_
Coordinates of the 3 coordinate vector.
Definition: xyzVector.hh:2062
NumericTraits: Numeric type traits.
xyzMatrix< T > rotation_matrix(xyzVector< T > const &axis, T const &theta)
Rotation matrix for rotation about an axis by an angle in radians.
def x
Value const & z() const
Value z const.
Definition: xyzVector.hh:1620
void dihedral(xyzVector< T > const &p1, xyzVector< T > const &p2, xyzVector< T > const &p3, xyzVector< T > const &p4, T &angle)
Dihedral (torsion) angle in degrees: angle value passed.
string output
Definition: contacts.py:31
xyzMatrix< T > alignVectorSets(xyzVector< T > A1, xyzVector< T > B1, xyzVector< T > A2, xyzVector< T > B2)
Helper function to find the rotation to optimally transform the vectors A1-B1 to vectors A2-B2...
Value length_squared() const
Length squared.
Definition: xyzVector.hh:1647
xyzMatrix & left_multiply_by_transpose(xyzMatrix< U > const &m)
Left multiply by transpose xyzMatrix.
Definition: xyzMatrix.hh:1236
def angle
Definition: Equations.py:36
#define runtime_assert(_Expression)
Assert that the condition holds. Evaluated for both debug and release builds.
Definition: exit.hh:63
Value const & radius() const
Value z const.
Value magnitude() const
Magnitude.
Definition: xyzVector.hh:1674
Conversions between degrees and radians.
xyzMatrix< T > x_rotation_matrix_radians(T const &theta)
Rotation matrix for rotation about the x axis by an angle in radians.
void jacobi_rotation(xyzMatrix< T > const &m, int const i, int const j, xyzMatrix< T > &r)
Jacobi rotation.
Fast 3x3 matrix.
xyzVector< Real > xyz(Real const &r1, Real const &omega1, Real const &t, Real const &dz1, Real const &delta_omega1, Real const &delta_z1)
Returns the x-, y-, and z-coordinates of a point on a helix given r1, omega1, and t...
Definition: HelixParams.cc:67
Value const & yx() const
Value yx const.
Definition: xyzMatrix.hh:1533
Value const & xx() const
Value xx const.
Definition: xyzMatrix.hh:1479
xyzMatrix< T > projection_matrix(xyzVector< T > const &v)
geometric center
utility::vector1< xyzVector< T > > FArray_to_vector_of_xyzvectors(ObjexxFCL::FArray2D< T > const &input)
convert an FArray2D to a vector of xyzVectors
T sin_cos_range(T const &x, T const &tol=T(.001))
Adjust a sine or cosine value to the valid [-1,1] range if within a specified tolerance or exit with ...
utility::vector1< std::string > string_split(std::string const &in, char splitchar)
Definition: string_util.cc:158
xyzVector< T > rotation_axis_angle(xyzMatrix< T > const &R)
Transformation from rotation matrix to compact axis-angle representation.
Value const & yz() const
Value yz const.
Definition: xyzMatrix.hh:1569
Value const & yy() const
Value yy const.
Definition: xyzMatrix.hh:1551
void dihedral_degrees(xyzVector< T > const &p1, xyzVector< T > const &p2, xyzVector< T > const &p3, xyzVector< T > const &p4, T &angle)
Dihedral (torsion) angle in degrees: angle value passed.
xyzMatrix< T > x_rotation_matrix(T const &theta)
Rotation matrix for rotation about the x axis by an angle in radians.
xyzMatrix< T > z_rotation_matrix_degrees(T const &theta)
Rotation matrix for rotation about the z axis by an angle in degrees.
Fstring::size_type index(Fstring const &s, Fstring const &ss)
First Index Position of a Substring in an Fstring.
Definition: Fstring.hh:2180
ObjexxFCL::FArray2D< T > vector_of_xyzvectors_to_FArray(utility::vector1< xyzVector< T > > const &input)
convert a vector1 of xyzVectors to an FArray2D
xyzMatrix & to_identity()
Set to the identity xyzMatrix.
Definition: xyzMatrix.hh:988
T const from_string(std::string const &s, T)
Definition: string_util.hh:213
Value const & y() const
Value y const.
Definition: xyzVector.hh:1602
double angle_degrees_double(xyzVector< double > const &p1, xyzVector< double > const &p2, xyzVector< double > const &p3)
sphericalVector: Fast spherical-coordinate numeric vector
xyzVector< T > & inplace_product(xyzMatrix< T > const &m, xyzVector< T > &v)
xyzMatrix * xyzVector in-place product
xyzVector< T > & inplace_transpose_product(xyzMatrix< T > const &m, xyzVector< T > &v)
xyzMatrix^T * xyzVector in-place transpose product
xyzMatrix< T > y_rotation_matrix(T const &theta)
Rotation matrix for rotation about the y axis by an angle in radians.
Value trace() const
Trace.
Definition: xyzMatrix.hh:1805
short int max(short int const a, short int const b)
max( short int, short int )
void dihedral_degrees_double(xyzVector< double > const &p1, xyzVector< double > const &p2, xyzVector< double > const &p3, xyzVector< double > const &p4, double &angle)
T & to_degrees(T &radians)
Degrees from radians.
Definition: conversions.hh:104
xyzMatrix< T > x_rotation_matrix_degrees(T const &theta)
Rotation matrix for rotation about the x axis by an angle in degrees.
xyzVector< T > closest_point_on_line(xyzVector< T > const &p1, xyzVector< T > const &p2, xyzVector< T > const &q)
xyzMatrix * xyzVector
def z
Fast spherical-coordinate numeric vector.
xyzMatrix< T > y_rotation_matrix_radians(T const &theta)
Rotation matrix for rotation about the y axis by an angle in radians.
T rotation_angle(xyzMatrix< T > const &R)
Transformation from rotation matrix to magnitude of helical rotation.
T abs(T const &x)
std::abs( x ) == | x |
Definition: Fmath.hh:295
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
xyzMatrix< T > rotation_matrix_radians(xyzVector< T > const &axis, T const &theta)
Rotation matrix for rotation about an axis by an angle in radians.
T angle_degrees(xyzVector< T > const &p1, xyzVector< T > const &p2, xyzVector< T > const &p3)
Plane angle in degrees: angle value returned.
void product(ForwardIterator probs1_first, ForwardIterator probs1_last, ForwardIterator probs2_first, ForwardIterator probs2_last)
Multiplies two probability vectors with one another. Probability vectors are assumed to have equal le...
Definition: prob_util.hh:56
T degrees(T const &radians)
Degrees of radians.
Definition: conversions.hh:80
xyzVector< T > center_of_mass(utility::vector1< xyzVector< T > > const &coords)
calculate center of mass for coordinates
xyzMatrix< T > inverse(xyzMatrix< T > const &a)
Value const & zx() const
Value zx const.
Definition: xyzMatrix.hh:1587
double Real
Definition: types.hh:39
Value const & x() const
Value x const.
Definition: xyzVector.hh:1584
xyzVector< T > spherical_to_xyz(sphericalVector< T > const &spherical)
xyzTriple< T > cross(xyzTriple< T > const &a, xyzTriple< T > const &b)
Cross product.
xyzVector & normalize()
Normalize.
Definition: xyzVector.hh:700
xyzMatrix< T > rotation_matrix_degrees(xyzVector< T > const &axis, T const &theta)
Rotation matrix for rotation about an axis by an angle in degrees.
T dot_product(Quaternion< T > const &q1, Quaternion< T > const &q2)
Dot product.
size_type size1() const
Size of Dimension 1.
Definition: FArray2.hh:507
Value const & zy() const
Value zy const.
Definition: xyzMatrix.hh:1605
float tol
Definition: loops_kic.py:75
vector1: std::vector with 1-based indexing
xyzMatrix< T > outer_product(xyzVector< T > const &a, xyzVector< T > const &b)
xyzVector xyzVector outer product
sphericalVector< T > xyz_to_spherical(xyzVector< T > const &xyz)
Value xx_
Elements of the 3x3 matrix.
Definition: xyzMatrix.hh:2078
void dihedral_double(xyzVector< double > const &p1, xyzVector< double > const &p2, xyzVector< double > const &p3, xyzVector< double > const &p4, double &angle)
xyzMatrix< T > z_rotation_matrix_radians(T const &theta)
Rotation matrix for rotation about the z axis by an angle in radians.
numeric::xyzMatrix< T > FArray_to_xyzmatrix(ObjexxFCL::FArray2D< T > const &input)
convert a 3x3 FArray 2D to an xyzMatrix
T radians(T const &degrees)
Radians of degrees.
Definition: conversions.hh:32
Some std::string helper functions.
Fast (x,y,z)-coordinate numeric vector.
size_type size2() const
Size of Dimension 2.
Definition: FArray2D.hh:541
Trigonometric functions.
Value const & theta() const
Value y const.
Value const & xz() const
Value xz const.
Definition: xyzMatrix.hh:1515
Value const & phi() const
Value x const.
static Type pi()
pi
Value const & xy() const
Value xy const.
Definition: xyzMatrix.hh:1497
xyzVector< T > eigenvalue_jacobi(xyzMatrix< T > const &a, T const &tol)
Classic Jacobi algorithm for the eigenvalues of a real symmetric matrix.
T dot(Quaternion< T > const &q1, Quaternion< T > const &q2)
Dot product.
def y
xyzMatrix & right_multiply_by(xyzMatrix< U > const &m)
Right multiply by xyzMatrix.
Definition: xyzMatrix.hh:1146
ObjexxFCL::FArray2D< T > xyzmatrix_to_FArray(numeric::xyzMatrix< T > const &input)
convert an xyzMatrix to a 3x3 FArray 2D
numeric::xyzVector< core::Real > point
xyzVector< T > transpose_product(xyzMatrix< T > const &m, xyzVector< T > const &v)
xyzMatrix^T * xyzVector product
FArray2D: Fortran-Compatible 2D Array.
Definition: FArray2.hh:27
double angle_radians_double(xyzVector< double > const &p1, xyzVector< double > const &p2, xyzVector< double > const &p3)