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 /// @param[in] offset_val - A small offset temporarily added or subtracted from z-coordinates to ensure that determinants are nonzero. Defaults to 1e-7.
176 /// @param[in] relalign - If true, the small offset is subtracted off again before final output. False by default (legacy behaviour).
177 ///
178 /// @global_read
179 ///
180 /// @global_write
181 ///
182 /// @remarks
183 /// det is a double precision real
184 /// (xx,yy) can be same arrays as (xx_0,yy_0) if desired
185 ///
186 /// @references
187 ///
188 /// @author charlie strauss 2001
189 ///
190 /////////////////////////////////////////////////////////////////////////////////
191 void
192 rmsfitca2(
193  int npoints,
197  int natsel,
198  double & esq,
199  double const & offset_val=1.0e-7,
200  bool const realign = false
201 );
202 
203 //////////////////////////////////////////////////////////////////
204 ///
205 /// @brief
206 ///
207 /// @details
208 /// This function gets its alignment info via a namespace!
209 /// Alignment (rotation matrix) and rms(esq) are computed on the basis
210 /// of residues previously designated by calls to add_rms().
211 /// However, the rotation is applied to all Npoints of XX0,yy0 with the
212 /// results returned in xx,yy.
213 ///
214 /// most of this is double for good reasons.
215 /// first there are some large differences of small numbers.
216 /// second the rsymm_eignen() function can internally have numbers
217 /// larger than the largest double number. (you could do some fancy foot work
218 /// to rescale m_moment if you really had a problem with this.)
219 ///
220 /// @param npoints - [in/out]? -
221 /// @param xx0 - [in/out]? -
222 /// @param xx - [in/out]? -
223 /// @param yy0 - [in/out]? -
224 /// @param yy - [in/out]? -
225 /// @param esq - [in/out]? -
226 ///
227 /// @global_read
228 ///
229 /// @global_write
230 ///
231 /// @remarks
232 /// NOTE: det is a double precision real
233 /// NOTE: (xx,yy) can be same arrays as (xx_0,yy_0) if desired
234 ///
235 /// @references
236 ///
237 /// @author
238 ///
239 ////////////////////////////////////////////////////////////////////////////////
240 void
241 rmsfitca3(
242  int npoints, // number of points to fit
247  double & esq
248 );
249 
250 
251 ////////////////////////////////////////////////////////////////////////////////
252 ///
253 /// @brief computes the eigen values of a real symmetric 3x3 matrix
254 ///
255 /// @details
256 /// the method used is a deterministic analytic result that I hand factored.(whew!)
257 /// Amusingly, while I suspect this factorization is not yet optimal in the
258 /// number of calcs required
259 /// I cannot find a signifcantly better one.
260 /// (if it were optimal I suspect I would not have to compute imaginary numbers that
261 /// I know must eventually cancel out to give a net real result.)
262 /// this method relys on the fact that an analytic factoring of an order 3 polynomial exists.
263 /// m(3,3) is a 3x3 real symmetric matrix: only the upper triangle is actually used
264 /// ev(3) is a real vector of eigen values, not neccesarily in sorted order.
265 ///
266 /// @param m - [in/out]? -
267 /// @param ev - [in/out]? -
268 ///
269 /// @global_read
270 ///
271 /// @global_write
272 ///
273 /// @remarks
274 ///
275 /// @references
276 ///
277 /// @author charlie strauss 2001
278 ///
279 /////////////////////////////////////////////////////////////////////////////////
280 void
284 );
285 
286 ////////////////////////////////////////////////////////////////////////////////
287 ///
288 /// @brief finds a (proper) rotation matrix that minimizes the rms.
289 ///
290 /// @details this computes the rotation matrix based on the eigenvectors of m that gives the
291 /// the mimimum rms. this is determined using mm the cross moments matrix.
292 ///
293 /// for best results the third eigen value should be the
294 /// smallest eigen value!
295 ///
296 ///
297 /// @param mm - [in/out]? -
298 /// @param m - [in/out]? -
299 /// @param ev - [in/out]? -
300 /// @param rot - [in/out]? -
301 ///
302 /// @global_read
303 ///
304 /// @global_write
305 ///
306 /// @remarks
307 ///
308 /// @references
309 ///
310 /// @author charlie strauss (cems) 2001
311 ///
312 /////////////////////////////////////////////////////////////////////////////////
313 void
319 );
320 
321 ////////////////////////////////////////////////////////////////////////////////
322 ///
323 /// @brief
324 /// Author: charlie strauss (cems) 2001
325 /// given original matrix plus its eigen values
326 /// compute the eigen vectors.
327 /// USAGE notice: for computing min rms rotations be sure to call this
328 /// with the lowest eigen value in Ev(3).
329 ///
330 /// The minimal factorization of the eigenvector problem I have derived below has a puzzling
331 /// or, rather, interesting assymetry. Namely, it doesn't matter what
332 /// either ZZ=M(3,3) is or what Ev(3) is!
333 /// One reason for this is that of course all we need to know is contained in the
334 /// M matrix in the firstplace, so the eigen values overdetermine the problem
335 /// We are just exploiting the redundant info in the eigen values to hasten the solution.
336 /// What I dont know is if infact there exists any symmetic form using the eigen values.
337 ///
338 /// we deliberately introduce another assymetry for numerical stability, and
339 /// to force proper rotations (since eigen vectors are not unique within a sign change).
340 /// first, we explicitly numerically norm the vectors to 1 rather than assuming the
341 /// algebra will do it with enough accuracy. ( and its faster to boot!)
342 /// second, we explicitly compute the third vector as being the cross product of the
343 /// previous two rather than using the M matrix and third eigen value.
344 /// If you arrange the eigen values so that the third eigen value is the lowest
345 /// then this guarantees a stable result under the case of either very small
346 /// eigen value or degenerate eigen values.
347 /// this norm, and ignoring the third eigen value also gaurentee us the even if the
348 /// eigen vectors are not perfectly accurate that, at least, the matrix
349 /// that results is a pure orthonormal rotation matrix, which for most applications
350 /// is the most important form of accuracy.
351 ///
352 /// @details
353 ///
354 /// @param m - [in/out]? -
355 /// @param ev - [in/out]? -
356 /// @param mvec - [in/out]? -
357 ///
358 /// @global_read
359 ///
360 /// @global_write
361 ///
362 /// @remarks
363 ///
364 /// @references
365 ///
366 /// @author
367 ///
368 /////////////////////////////////////////////////////////////////////////////////
369 
370 void
375 );
376 
377 
378 } // end namespace model_quality
379 } // end namespace numeric
380 
381 #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:972
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 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:959
void rmsfitca2(int npoints, ObjexxFCL::FArray2A< double > xx, ObjexxFCL::FArray2A< double > yy, ObjexxFCL::FArray1A< double > ww, int natsel, double &esq, double const &offset_val, bool const realign)
computes the rms between two weighted point vectors.
Definition: rms.cc:627
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:790
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:1103
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:1056
FArray2D: Fortran-Compatible 2D Array.
Definition: FArray2.hh:27