Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Stub.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 core/kinematics/Stub.hh
11 /// @brief Stub class
12 /// @author Phil Bradley
13 
14 
15 #ifndef INCLUDED_core_kinematics_Stub_hh
16 #define INCLUDED_core_kinematics_Stub_hh
17 
18 
19 // Unit headers
22 // AUTO-REMOVED #include <core/kinematics/types.hh>
23 
24 // Numeric headers
25 #include <numeric/xyzMatrix.hh>
26 #include <numeric/xyzVector.hh>
27 // AUTO-REMOVED #include <numeric/xyz.functions.hh> // Do not remove, it is required for global2local and local2global
28 
29 // C++ headers
30 #include <cmath>
31 
32 #include <core/types.hh>
33 #include <utility/vector1.hh>
34 
35 namespace core {
36 namespace kinematics {
37 
38 
39 /////////////////////////////////////////////////////////////////////////////
40 /// @brief Stub class -- an object of orthogonal coordinate frame
41 ///
42 /// @details an orthogonal coord frame M (matrix) centered at point V (vector),
43 /// defined by four points, one is for the center and the other three for
44 /// calculating the orthogonal frame. For example, a stub can be derived from
45 /// a backbone triplet N-CA-C centered at CA.
46 ///
47 /// See @ref atomtree_overview "AtomTree overview and concepts" for details.
48 ///
49 class Stub
50 {
51 
52 public: // Types
53 
56 
57 public: // Creation
58 
59  /// @brief constructor -- sets to "default" stub
60  inline
61  Stub():
62  M( Matrix::identity() ),
63  v( 0.0 )
64  {}
65 
66  /// @brief copy constructor
67  inline
69  Matrix const & M_in,
70  Vector const & v_in
71  ):
72  M( M_in ),
73  v( v_in )
74  {}
75 
76  /// ctor from RT object
77  Stub( RT const & rt );
78 
79 
80  /// @brief constructor by four points
81  ///
82  /// @details first point is the center (V) and the rest three are used to
83  /// construct the coord frame (M). see member functon from_four_points(...)
84 
85  // construct a stub centered at v_in, as would come from building
86  // c then b then a
87  inline
89  Vector const & center,
90  Vector const & a,
91  Vector const & b,
92  Vector const & c
93  )
94  {
95  this->from_four_points( center, a, b, c );
96  }
97 
98  /// @brief constructor by three points
99  ///
100  /// @details first point is the center (V) and all the three are used to
101  /// construct the coord frame (M). see member functon from_four_points(...)
102 
103  // construct a stub as would come from building
104  // c then b then a
105  inline
107  Vector const & a,
108  Vector const & b,
109  Vector const & c
110  )
111  {
112  this->from_four_points( a, a, b, c );
113  }
114 
115 public: // Methods
116 
117  ///@brief build a stub from a center and other three points a, b, c
118  void
120  Vector const & center,
121  Vector const & a,
122  Vector const & b,
123  Vector const & c
124  );
125 
126  ///@brief check if the stub is orthogonal under the tolerance cutoff
127  bool
128  is_orthogonal( double const & tolerance ) const
129  {
130  Matrix delta( M * M.transposed() - Matrix::identity() );
131  return ( ( delta.col_x().length() +
132  delta.col_y().length() +
133  delta.col_z().length() ) < tolerance );
134  }
135 
136  ///@brief convert a global reference (lab) frame vector to our local (stub) frame
137  Vector
138  global2local( Vector const & xyz ) const
139  {
140  return M.transposed() * ( xyz - v );
141  }
142 
143  ///@brief convert a local reference (stub) frame vector to the global (lab) frame
144  Vector
145  local2global( Vector const & xyz ) const
146  {
147  return M * xyz + v;
148  }
149 
150  ///@brief Build a vector in the global lab frame from the spherical coords used in the atomtree
151  ///
152  ///@details theta is the angle between the postive x and the vector (0<=theta<=pi),
153  ///phi is the angle between the y-z plane projection of the vector and the positive y (0<=theta<=2*pi),
154  ///d is the length of the vector
155  ///
156  ///@note These are non-standard in the choice of axis for historical reasons --PB
157  ///
158  Vector
159  spherical( Real const phi, Real const theta, Real const d ) const
160  {
161  Real const d_sin_theta( d * std::sin( theta ) );
162  return local2global( Vector(
163  d * std::cos( theta ),
164  d_sin_theta * std::cos( phi ),
165  d_sin_theta * std::sin( phi ) ) );
166  }
167 
168  /// @brief Build stubatom coords that would yield this stub
169  Vector
170  build_fake_xyz( Size const index ) const;
171 
172 
173 public: // Fields
174  ///@brief coord frame by 3x3 matrix, each column is a unit vector
176  ///@brief center point by a vector
178 
179 }; // Stub
180 
181 /// @brief root sqared deviation between two stubs
182 inline
183 double
185  Stub const & a,
186  Stub const & b
187 )
188 {
189  using namespace numeric;
190  return std::sqrt(
191  a.M.col_x().distance_squared(b.M.col_x() ) +
192  a.M.col_y().distance_squared(b.M.col_y() ) +
193  a.M.col_z().distance_squared(b.M.col_z() ) +
194  a.v.distance_squared( b.v )
195  );
196 }
197 
198 
199 std::ostream &
200 operator<<( std::ostream & os, Stub const & a );
201 
202 /// @brief Globals
203 extern Stub default_stub;
204 
205 
206 } // namespace kinematics
207 } // namespace core
208 
209 
210 #endif // INCLUDED_core_kinematics_Stub_HH