Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
rms.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/model_quality/rms.hh
11 /// @brief RMS stuff imported from rosetta++
12 /// @author James Thompson
13 /// @date Wed Aug 22 12:10:37 2007
14 
15 
16 #ifndef INCLUDED_numeric_model_quality_rms_HH
17 #define INCLUDED_numeric_model_quality_rms_HH
18 
19 #include <numeric/types.hh>
20 #include <numeric/xyzVector.hh>
21 #include <numeric/xyzMatrix.hh>
22 
23 #include <ObjexxFCL/FArray1D.hh>
24 #include <ObjexxFCL/FArray2D.hh>
25 #include <ObjexxFCL/FArray1A.hh>
26 #include <ObjexxFCL/FArray2A.hh>
27 
28 #include <utility/vector1.hh>
29 
30 namespace numeric {
31 namespace model_quality {
32 
34 calc_rms(
35  utility::vector1< xyzVector< Real > > p1_coords,
36  utility::vector1< xyzVector< Real > > p2_coords
37 );
38 
41  int natoms,
44 );
45 
48  int natoms,
51 );
52 
53 void
56  int n,
57  int np,
58  int transposeA,
60  int m,
61  int transposeB,
63 );
64 
65 void
68  int n,
69  int np,
70  int transposeA,
72  int m,
73  int transposeB,
75 );
76 
77 void
79 
80 void
82  float & rms_out,
86  int npoints,
87  numeric::Real ctx
88 );
89 
90 void
91 findUU(
95  int Npoints,
97  numeric::Real & sigma3
98 );
99 
100 void
101 findUU(
105  int Npoints,
107  numeric::Real & sigma3
108 );
109 
110 void
111 MatrixMult(
113  int n,
114  int np,
115  int transposeA,
117  int m,
118  int transposeB,
120 );
121 
122 // functions required for maxsub to work properly
123 
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 ///
127 /// @brief determinant of a 3x3 matrix
128 ///
129 /// @details
130 /// cute factoid: det of a 3x3 is the dot product of one row with the cross
131 /// product of the other two. This explains why a right hand coordinate system
132 /// has a positive determinant. cute huh?
133 ///
134 /// @param m - [in/out]? -
135 ///
136 /// @return
137 ///
138 /// @global_read
139 ///
140 /// @global_write
141 ///
142 /// @remarks
143 ///
144 /// @references
145 ///
146 /// @author charlie strauss 2001
147 ///
148 /////////////////////////////////////////////////////////////////////////////////
149 double
151 
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 ///
155 /// @brief computes the rms between two weighted point vectors.
156 ///
157 /// @details
158 /// xx_0,yy_0 are the input vectors of of points and ww is their weights
159 /// xx,yy are by product output vectors of the same points offset to remove center of mass
160 /// det is an out value of the determinant of the cross moment matrix
161 /// returned value is the rms
162 ///
163 /// most of this is double for good reasons. first there are some large
164 /// differences of small numbers. and second the rsymm_eignen() function can
165 /// internally have numbers larger than the largest double number.
166 /// (you could do some fancy foot work to rescale things if you really
167 /// had a problem with this.)
168 ///
169 /// @param npoints - [in/out]? -
170 /// @param xx - [in/out]? -
171 /// @param yy - [in/out]? -
172 /// @param ww - [in/out]? -
173 /// @param natsel - [in/out]? -
174 /// @param esq - [in/out]? -
175 ///
176 /// @global_read
177 ///
178 /// @global_write
179 ///
180 /// @remarks
181 /// det is a double precision real
182 /// (xx,yy) can be same arrays as (xx_0,yy_0) if desired
183 ///
184 /// @references
185 ///
186 /// @author charlie strauss 2001
187 ///
188 /////////////////////////////////////////////////////////////////////////////////
189 void
190 rmsfitca2(
191  int npoints,
195  int natsel,
196  double & esq
197 );
198 
199 //////////////////////////////////////////////////////////////////
200 ///
201 /// @brief
202 ///
203 /// @details
204 /// This function gets its alignment info via a namespace!
205 /// Alignment (rotation matrix) and rms(esq) are computed on the basis
206 /// of residues previously designated by calls to add_rms().
207 /// However, the rotation is applied to all Npoints of XX0,yy0 with the
208 /// results returned in xx,yy.
209 ///
210 /// most of this is double for good reasons.
211 /// first there are some large differences of small numbers.
212 /// second the rsymm_eignen() function can internally have numbers
213 /// larger than the largest double number. (you could do some fancy foot work
214 /// to rescale m_moment if you really had a problem with this.)
215 ///
216 /// @param npoints - [in/out]? -
217 /// @param xx0 - [in/out]? -
218 /// @param xx - [in/out]? -
219 /// @param yy0 - [in/out]? -
220 /// @param yy - [in/out]? -
221 /// @param esq - [in/out]? -
222 ///
223 /// @global_read
224 ///
225 /// @global_write
226 ///
227 /// @remarks
228 /// NOTE: det is a double precision real
229 /// NOTE: (xx,yy) can be same arrays as (xx_0,yy_0) if desired
230 ///
231 /// @references
232 ///
233 /// @author
234 ///
235 ////////////////////////////////////////////////////////////////////////////////
236 void
237 rmsfitca3(
238  int npoints, // number of points to fit
243  double & esq
244 );
245 
246 
247 ////////////////////////////////////////////////////////////////////////////////
248 ///
249 /// @brief computes the eigen values of a real symmetric 3x3 matrix
250 ///
251 /// @details
252 /// the method used is a deterministic analytic result that I hand factored.(whew!)
253 /// Amusingly, while I suspect this factorization is not yet optimal in the
254 /// number of calcs required
255 /// I cannot find a signifcantly better one.
256 /// (if it were optimal I suspect I would not have to compute imaginary numbers that
257 /// I know must eventually cancel out to give a net real result.)
258 /// this method relys on the fact that an analytic factoring of an order 3 polynomial exists.
259 /// m(3,3) is a 3x3 real symmetric matrix: only the upper triangle is actually used
260 /// ev(3) is a real vector of eigen values, not neccesarily in sorted order.
261 ///
262 /// @param m - [in/out]? -
263 /// @param ev - [in/out]? -
264 ///
265 /// @global_read
266 ///
267 /// @global_write
268 ///
269 /// @remarks
270 ///
271 /// @references
272 ///
273 /// @author charlie strauss 2001
274 ///
275 /////////////////////////////////////////////////////////////////////////////////
276 void
280 );
281 
282 ////////////////////////////////////////////////////////////////////////////////
283 ///
284 /// @brief finds a (proper) rotation matrix that minimizes the rms.
285 ///
286 /// @details this computes the rotation matrix based on the eigenvectors of m that gives the
287 /// the mimimum rms. this is determined using mm the cross moments matrix.
288 ///
289 /// for best results the third eigen value should be the
290 /// smallest eigen value!
291 ///
292 ///
293 /// @param mm - [in/out]? -
294 /// @param m - [in/out]? -
295 /// @param ev - [in/out]? -
296 /// @param rot - [in/out]? -
297 ///
298 /// @global_read
299 ///
300 /// @global_write
301 ///
302 /// @remarks
303 ///
304 /// @references
305 ///
306 /// @author charlie strauss (cems) 2001
307 ///
308 /////////////////////////////////////////////////////////////////////////////////
309 void
315 );
316 
317 ////////////////////////////////////////////////////////////////////////////////
318 ///
319 /// @brief
320 /// Author: charlie strauss (cems) 2001
321 /// given original matrix plus its eigen values
322 /// compute the eigen vectors.
323 /// USAGE notice: for computing min rms rotations be sure to call this
324 /// with the lowest eigen value in Ev(3).
325 ///
326 /// The minimal factorization of the eigenvector problem I have derived below has a puzzling
327 /// or, rather, interesting assymetry. Namely, it doesn't matter what
328 /// either ZZ=M(3,3) is or what Ev(3) is!
329 /// One reason for this is that of course all we need to know is contained in the
330 /// M matrix in the firstplace, so the eigen values overdetermine the problem
331 /// We are just exploiting the redundant info in the eigen values to hasten the solution.
332 /// What I dont know is if infact there exists any symmetic form using the eigen values.
333 ///
334 /// we deliberately introduce another assymetry for numerical stability, and
335 /// to force proper rotations (since eigen vectors are not unique within a sign change).
336 /// first, we explicitly numerically norm the vectors to 1 rather than assuming the
337 /// algebra will do it with enough accuracy. ( and its faster to boot!)
338 /// second, we explicitly compute the third vector as being the cross product of the
339 /// previous two rather than using the M matrix and third eigen value.
340 /// If you arrange the eigen values so that the third eigen value is the lowest
341 /// then this guarantees a stable result under the case of either very small
342 /// eigen value or degenerate eigen values.
343 /// this norm, and ignoring the third eigen value also gaurentee us the even if the
344 /// eigen vectors are not perfectly accurate that, at least, the matrix
345 /// that results is a pure orthonormal rotation matrix, which for most applications
346 /// is the most important form of accuracy.
347 ///
348 /// @details
349 ///
350 /// @param m - [in/out]? -
351 /// @param ev - [in/out]? -
352 /// @param mvec - [in/out]? -
353 ///
354 /// @global_read
355 ///
356 /// @global_write
357 ///
358 /// @remarks
359 ///
360 /// @references
361 ///
362 /// @author
363 ///
364 /////////////////////////////////////////////////////////////////////////////////
365 
366 void
371 );
372 
373 
374 } // end namespace model_quality
375 } // end namespace numeric
376 
377 #endif
void fixEigenvector(FArray2A< numeric::Real > m_v)
Definition: rms.cc:610
void calc_rms_fast(float &rms_out, FArray2A< numeric::Real > xx, FArray2A< numeric::Real > yy, FArray1A< numeric::Real > ww, int npoints, numeric::Real ctx)
companion function for findUU ( it is optional ) computes the minimum RMS deviation beteen XX and YY ...
Definition: rms.cc:138
FArray2A: Fortran-Compatible 2D Argument Array.
Definition: FArray2.hh:29
FArray1A: Fortran-Compatible 1D Argument Array.
Definition: FArray1.hh:32
FArray1: Fortran-Compatible 1D Array Abstract Base Class.
Definition: FArray1.fwd.hh:27
Fast 3x3 matrix.
void rsym_eigenval(ObjexxFCL::FArray2A< double > m, ObjexxFCL::FArray1A< double > ev)
computes the eigen values of a real symmetric 3x3 matrix
Definition: rms.cc:966
xyzVector: Fast (x,y,z)-coordinate numeric vector
FArray2: Fortran-Compatible 2D Array Abstract Base Class.
Definition: FArray2.fwd.hh:27
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
numeric::Real rms_wrapper_slow_and_correct(int natoms, FArray2D< numeric::Real > p1a, FArray2D< numeric::Real > p2a)
Definition: rms.cc:67
rosetta project type declarations. Should be kept updated with core/types.hh. This exists because num...
void MatrixMult(FArray2A< numeric::Real > A, int n, int np, int transposeA, FArray2A< numeric::Real > B, int m, int transposeB, FArray2A< numeric::Real > AxB_out)
Definition: rms.cc:532
void rmsfitca2(int npoints, ObjexxFCL::FArray2A< double > xx, ObjexxFCL::FArray2A< double > yy, ObjexxFCL::FArray1A< double > ww, int natsel, double &esq)
computes the rms between two weighted point vectors.
Definition: rms.cc:627
void BlankMatrixMult(FArray2A< numeric::Real > A, int n, int np, int transposeA, FArray2A< numeric::Real > B, int m, int transposeB, FArray2A< numeric::Real > AxB_out)
Definition: rms.cc:473
numeric::Real rms_wrapper(int natoms, FArray2D< numeric::Real > p1a, FArray2D< numeric::Real > p2a)
Definition: rms.cc:91
vector1: std::vector with 1-based indexing
xyzMatrix: Fast 3x3 xyz matrix template
void findUU(FArray2< numeric::Real > &XX, FArray2< numeric::Real > &YY, FArray1< numeric::Real > const &WW, int Npoints, FArray2< numeric::Real > &UU, numeric::Real &sigma3)
intended to rotate one protein xyz array onto another one such that the point-by-point rms is minimiz...
Definition: rms.cc:224
double det3(FArray2A< double > m)
determinant of a 3x3 matrix
Definition: rms.cc:953
Fast (x,y,z)-coordinate numeric vector.
void rmsfitca3(int npoints, ObjexxFCL::FArray2A< double > xx0, ObjexxFCL::FArray2A< double > xx, ObjexxFCL::FArray2A< double > yy0, ObjexxFCL::FArray2A< double > yy, double &esq)
Definition: rms.cc:784
numeric::Real calc_rms(utility::vector1< xyzVector< Real > > p1_coords, utility::vector1< xyzVector< Real > > p2_coords)
Definition: rms.cc:47
void rsym_evector(ObjexxFCL::FArray2A< double > m, ObjexxFCL::FArray1A< double > ev, ObjexxFCL::FArray2A< double > mvec)
Author: charlie strauss (cems) 2001 given original matrix plus its eigen values compute the eigen vec...
Definition: rms.cc:1097
void rsym_rotation(ObjexxFCL::FArray2A< double > mm, ObjexxFCL::FArray2A< double > m, ObjexxFCL::FArray1A< double > ev, ObjexxFCL::FArray2A< double > rot)
finds a (proper) rotation matrix that minimizes the rms.
Definition: rms.cc:1050
FArray2D: Fortran-Compatible 2D Array.
Definition: FArray2.hh:27