Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
closure.cc
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 /* This file is contains all the same functions as `bridgeObjects.cc', but
11 * radians are assumed for all angles. Although this is easier to use in most
12 * cases, it is not backwards compatible. That's why a new file was created.
13 */
14 
15 /// @file bridge_objects.cc
16 /// @brief Solves the triaxial loop closure problem for a system of atoms
17 /// @author Evangelos A. Coutsias
18 /// @author Daniel J. Mandell
19 
20 // Unit Headers
21 #include <numeric/types.hh>
22 #include <numeric/constants.hh>
23 #include <numeric/wrap_angles.hh>
24 #include <numeric/conversions.hh>
27 
28 // Utility headers
29 #include <utility/vector1.hh>
30 
31 // C++ headers
32 #include <cmath>
33 
34 namespace numeric {
35 namespace kinematic_closure {
36 namespace radians {
37 
38 using namespace std;
40 
41 void triangle ( // {{{1
42  const utility::vector1<Real>& vbond,
43  utility::vector1<Real>& calpha,
44  utility::vector1<Real>& salpha) {
45 
46  Real d11, d12, d13, d22, d23, d33;
47  d11 = vbond[1]*vbond[1];
48  d22 = vbond[2]*vbond[2];
49  d33 = vbond[3]*vbond[3];
50  d12 = 2*vbond[1]*vbond[2];
51  d13 = 2*vbond[1]*vbond[3];
52  d23 = 2*vbond[2]*vbond[3];
53  calpha[1]=(d22-d33-d11)/d13; // exterior angle
54  salpha[1]=std::sqrt(1-calpha[1]*calpha[1]);
55  calpha[2]=(d33-d11-d22)/d12; // exterior angle
56  salpha[2]=std::sqrt(1-calpha[2]*calpha[2]);
57  calpha[3]=(d11-d22-d33)/d23; // exterior angle
58  salpha[3]=std::sqrt(1-calpha[3]*calpha[3]);
59 }
60 
61 void sincos ( // {{{1
62  const utility::vector1<Real>& theta,
63  const int flag,
64  utility::vector1<Real>& cosine,
65  utility::vector1<Real>& sine) {
66 
68  if ( flag == 1 ) {
69  for ( int i=1; i<=3; i++ ) {
70  cosine[i]=std::cos(theta[i]);
71  sine[i]=std::sin(theta[i]);
72  }
73  } else {
74  a.resize(3);
75  aa.resize(3);
76  a1.resize(3);
77  for ( int i=1; i<=3; i++ ) {
78  a[i]=std::tan(theta[i]/2);
79  aa[i]=a[i]*a[i];
80  a1[i]=1+aa[i];
81  sine[i]=2*a[i]/a1[i];
82  cosine[i]=(1-aa[i])/a1[i];
83  }
84  }
85 }
86 
87 // triaxialCoefficients {{{1
88 /*
89 * triaxialCoefficients
90 * --------------------
91 * Sets up characteristic polynomial matrices A,B,C,D from tripeptide parameters
92 */
93 
95  const utility::vector1<Real>& vb,
96  const utility::vector1<Real>& xi,
97  const utility::vector1<Real>& eta,
98  const utility::vector1<Real>& delta,
99  const utility::vector1<Real>& theta,
100  const utility::vector1<int>& order,
107  bool& feasible_triangle) {
108 
109  utility::vector1<Real> ctheta (4), calpha (4), salpha (4), cxi (3), sxi (3), ceta (4), seta (4), cdelta (3), sdelta (3), caceta (4), caseta (4), saceta (4), saseta (4), capeta (4), sapeta (4), cameta (4), sameta (4);
110  Real am, ap, cdsx, sdsx, b, bm, bp, d, dp, dm;
113 
114  // allocate p
115  for ( int i=1; i<=4; i++ ) {
116  p[i].resize(3);
117  for ( int j=1; j<=3; j++ ) {
118  p[i][j].resize(3);
119  }
120  }
121 
122  // allocate polynomial matrices
123  A.resize(3);
124  B.resize(3);
125  C.resize(3);
126  D.resize(3);
127  for ( int i=1; i<=3; i++ ) {
128  for ( int j=1; j<=3; j++ ) {
129  A[i].resize(3);
130  B[i].resize(3);
131  C[i].resize(3);
132  D[i].resize(3);
133  }
134  }
135 
136  // if triangle is feasible, compute the polynomial matrices
137  if ( (std::abs(vb[1] - vb[2]) <= vb[3]) && (vb[1] + vb[2] >= vb[3]) ) {
138  feasible_triangle = true; // we have a feasible triangle
139 
140  for ( int i=1; i<=3; i++ ) {
141  ctheta[i]=std::cos(theta[i]);
142  }
143  triangle(vb, calpha, salpha);
144  cal.resize(3);
145  sal.resize(3);
146  for ( int i=1; i<=3; i++ ) {
147  cal[i]=calpha[i];
148  sal[i]=salpha[i];
149  }
150  sincos(xi, 2, cxi, sxi);
151  sincos(eta, 2, ceta, seta);
152  sincos(delta, 2, cdelta, sdelta);
153  calpha[4] = calpha[1];
154  salpha[4] = salpha[1];
155  ceta[4] = ceta[1];
156  seta[4] = seta[1];
157  ctheta[4] = ctheta[1];
158  for ( int i=1; i<=4; i++ ) {
159  caceta[i] = calpha[i] * ceta[i];
160  caseta[i] = calpha[i] * seta[i];
161  saceta[i] = salpha[i] * ceta[i];
162  saseta[i] = salpha[i] * seta[i];
163  capeta[i] = caceta[i] - saseta[i];
164  sapeta[i] = saceta[i] + caseta[i];
165  cameta[i] = caceta[i] + saseta[i];
166  sameta[i] = saceta[i] - caseta[i];
167  }
168  for ( int i=2; i<=4; i++ ) {
169  am = cxi[i-1]*cameta[i] + ctheta[i];
170  ap = cxi[i-1]*capeta[i] + ctheta[i];
171  cdsx = cdelta[i-1]*sxi[i-1];
172  sdsx = 2*sdelta[i-1]*sxi[i-1];
173  b = 4*cdsx*seta[i];
174  bm = cdsx*sameta[i];
175  bp = cdsx*sapeta[i];
176  d = sdsx*seta[i];
177  dp = sdsx*sapeta[i];
178  dm = sdsx*sameta[i];
179  p[i][3][3]= -am -bm;
180  p[i][3][2]= -d;
181  p[i][3][1]= -ap -bp;
182  p[i][2][3]= -dm;
183  p[i][2][2]= b;
184  p[i][2][1]= -dp;
185  p[i][1][3]= -am +bm;
186  p[i][1][2]= d;
187  p[i][1][1]= -ap +bp;
188  }
189  for ( int i=1; i<=3; i++ ) {
190  for ( int j=1; j<=3; j++ ) {
191  p[1][i][j]=p[4][i][j];
192  }
193  }
194 
195  L.resize(3);
196  M.resize(3);
197  N.resize(3);
198  for ( int i=1; i<=3; i++ ) {
199  L[i].resize(3);
200  M[i].resize(3);
201  N[i].resize(3);
202  }
203  for ( int k=1; k<=3; k++ ) {
204  for ( int i=1; i<=3; i++ ) {
205  L[k][i] = p[order[1]][i][k];
206  M[k][i] = p[order[2]][k][i];
207  N[k][i] = p[order[3]][k][i];
208  }
209  }
210 
211  for ( int i=1; i<=3; i++ ) {
212  for ( int j=1; j<=3; j++ ) {
213  // not using transpose indexing so we don't take transpose in dixon
214  A[i][j] = M[i][2]*N[1][j] - M[i][1]*N[2][j];
215  B[i][j] = M[i][3]*N[1][j] - M[i][1]*N[3][j];
216  C[i][j] = M[i][3]*N[2][j] - M[i][2]*N[3][j];
217  D[i][j] = L[i][j];
218  }
219  }
220  } else {
221  feasible_triangle = false; // we have an unfeasible triangle
222  for ( int i=1; i<=3; i++ ) {
223  for ( int j=1; j<=3; j++ ) {
224  A[i][j]=0;
225  B[i][j]=0;
226  C[i][j]=0;
227  D[i][j]=0;
228  }
229  }
230  }
231 }
232 
233 // void cross {{{1
234 /*
235 * cross
236 * -----
237 * Output r is cross product of vectors L and r0
238 */
240  r.resize(3);
241  r[1]=L[2]*r0[3]-L[3]*r0[2];
242  r[2]=L[3]*r0[1]-L[1]*r0[3];
243  r[3]=L[1]*r0[2]-L[2]*r0[1];
244 }
245 
246 // void frame {{{1
247 /*
248 * frame
249 * -----
250 * construct body frame for r1 origin
251 * r2 r1-->r2: positive x axis
252 * r3 on pos. y side of xy plane
253 */
255  Real norm1, norm3;
256 
257  // utility::vector1<Real> cross1 (3), cross3 (3), cross11 (3), cross12 (3), cross31 (3), cross32 (3);
258  utility::vector1<Real> dR3R2 (3);
259  U.resize(3);
260  for ( int i=1; i<=3; i++ ) {
261  U[i].resize(3);
262  }
263  for ( int i=1; i<=3; i++ ) {
264  U[1][i]=R[2][i]-R[1][i];
265  }
266  norm1=std::sqrt(U[1][1]*U[1][1] + U[1][2]*U[1][2] + U[1][3]*U[1][3]);
267  for ( int i=1; i<=3; i++ ) {
268  U[1][i] /= norm1;
269  dR3R2[i]=R[3][i]-R[2][i];
270  }
271  cross(U[1], dR3R2, U[3]);
272  norm3=std::sqrt(U[3][1]*U[3][1] + U[3][2]*U[3][2] + U[3][3]*U[3][3]);
273  for ( int i=1; i<=3; i++ ) {
274  U[3][i] /= norm3;
275  }
276  cross(U[3], U[1], U[2]);
277 }
278 
280  const utility::vector1<Real>& a,
281  const utility::vector1<Real>& b) {
282 
283  return std::sqrt(std::pow(a[1]-b[1],2) + std::pow(a[2]-b[2],2) + std::pow(a[3]-b[3],2));
284 }
285 
286 Real scpn( // {{{1
287  const utility::vector1<Real>& a,
288  const utility::vector1<Real>& b,
289  const utility::vector1<Real>& c) {
290 
291  Real d=0;
292  for ( int i=1; i<=3; i++ ) {
293  d += (a[i]-b[i]) * (c[i]-b[i]);
294  }
295  return d;
296 }
297 
298 // Real bondangle( // {{{1
299 /// @details @returns the bond angle between the given vectors in radians.
301  const utility::vector1<Real>& a,
302  const utility::vector1<Real>& b,
303  const utility::vector1<Real>& c) {
304 
305  Real r = scpn(a,b,c) / (eucDistance(a,b) * eucDistance(b,c));
306  Real ang = std::atan2(sqrt(1-r*r), (Real) r);
307  return ang;
308 }
309 
310 // Real torsion( // {{{1
311 /// @details @returns the torsion angle between the given vectors in radians.
313  const utility::vector1<Real>& a,
314  const utility::vector1<Real>& b,
315  const utility::vector1<Real>& c,
316  const utility::vector1<Real>& d) {
317 
318  Real f, y, z, chi;
319  utility::vector1<Real> r (3), sc1 (3), sc2 (3), sc3 (3), cs12, cs31;
321  for ( int i=1; i<=3; i++ ) {
322  s[i].resize(3);
323  }
324 
325  if ( b==c ) {
327  }
328 
329  for ( int i=1; i<=3; i++ ) {
330  r[i] = d[i] - b[i];
331  s[i][1] = c[i] - b[i];
332  s[i][2] = a[i] - b[i];
333  sc1[i] = s[i][1];
334  sc2[i] = s[i][2];
335  }
336  cross(sc1, sc2, cs12);
337  for ( int i=1; i<=3; i++ ) {
338  s[i][3] = cs12[i];
339  sc3[i] = s[i][3];
340  }
341  cross(sc3, sc1, cs31);
342  for ( int i=1; i<=3; i++ ) {
343  s[i][2] = cs31[i];
344  }
345  for ( int i=2; i<=3; i++ ) {
346  f = std::sqrt( pow(s[1][i],2) + pow(s[2][i],2) + pow(s[3][i],2));
347  s[1][i] /= f;
348  s[2][i] /= f;
349  s[3][i] /= f;
350  }
351 
352  y = r[1]*s[1][2] + r[2]*s[2][2] + r[3]*s[3][2];
353  z = r[1]*s[1][3] + r[2]*s[2][3] + r[3]*s[3][3];
354 
355  chi = atan2(z,y);
356  return wrap_2pi(chi);
357 }
358 
359 void chainParams( // {{{1
360  const int& n,
362  Real& vbond,
363  Real& xi,
364  Real& eta,
365  Real& delta,
368 
369  //utility::vector1<Real> ac1 (3), ac2 (3), acn (3), acneg1 (3);
371  // R0.resize(3);
372  // for (int i=1; i<=3; i++) {
373  // ac1[i] = atoms[i][1];
374  // ac2[i] = atoms[i][2];
375  // acn[i] = atoms[i][n];
376  // acneg1[i]= atoms[i][n-1];
377  // R0[i] = ac1[i];
378  // }
379  a1n2[1]=atoms[1];
380  a1n2[2]=atoms[n];
381  a1n2[3]=atoms[2];
382 
383  // printVector(acn);
384  // printVector(ac1);
385 
386  R0=atoms[1];
387  frame(a1n2, Q);
388  vbond=eucDistance(atoms[n], atoms[1]);
389  xi=bondangle(atoms[n-1], atoms[n], atoms[1]);
390  eta=bondangle(atoms[n], atoms[1], atoms[2]);
391  delta=torsion(atoms[n-1], atoms[n], atoms[1], atoms[2]);
392 
393  // frame(a1n2, Q);
394  // vbond=eucDistance(acn, ac1);
395  // xi=bondangle(acneg1, acn, ac1);
396  // eta=bondangle(acn, ac1, ac2);
397  // delta=torsion(acneg1, acn, ac1, ac2);
398 }
399 
400 
401 // void chainXYZ {{{1
402 /* Generates a set of cartesian coordinates (atoms) given the supplied bond angles, bond lengths, and torsions
403 * of a peptide chain
404 */
405 void chainXYZ(const int& n,
406  const utility::vector1<Real>& b_len1,
407  const utility::vector1<Real>& b_ang1,
408  const utility::vector1<Real>& t_ang1,
409  const bool space,
410  const utility::vector1<Real>& R0,
413 )
414 {
415  Real ca, sa, ct, st; // cos(b_ang[2]), sin(b_ang[2]), cos(t_ang[2]), sin(t_ang[2]),
416  Real ba;
417  int n1, n2, j1, j2;
418  utility::vector1<Real> b_len, b_ang (n), t_ang (n);//, cos_a (n), cos_t (n), sin_a (n), sin_t (n);
419  utility::vector1<Real> v(3), s(3);
420  utility::vector1<utility::vector1<Real> > U (3); // rotation matrix
421 
422  atoms.resize(n);
423  b_len = b_len1; // only defined for consistent naming
424  // convert angles to radians and allocate atom vectors
425  for ( int i=1; i<=n; i++ ) {
426  t_ang[i] = t_ang1[i];
427  b_ang[i] = b_ang1[i];
428  atoms[i].resize(3);
429  }
430  // place the first atom at the origin
431  for ( int i=1; i<=n; i++ ) {
432  for ( int j=1; j<=3; j++ ) {
433  atoms[i][j]=0.0;
434  }
435  }
436  // place the second atom at bond length along x-axis from first atom
437  atoms[2][1] = b_len[1];
438  // third atom shows that b_ang is interior
439  ca = std::cos(b_ang[2]);
440  sa = std::sin(b_ang[2]);
441  atoms[3][1] = b_len[1] - b_len[2] * ca;
442  atoms[3][2] = b_len[2] * sa;
443 
444  // initialize rotation matrix
445  for ( int i=1; i<=3; i++ ) {
446  U[i].resize(3);
447  }
448  U[1][1] = -ca;
449  U[2][1] = -sa;
450  U[1][2] = sa;
451  U[2][2] = -ca;
452  for ( int i=1; i<=2; i++ ) {
453  U[3][i] = 0;
454  U[i][3] = 0;
455  }
456  U[3][3] = 1;
457 
458  // all other atoms
459  n1 = n-1;
460  n2 = n-2;
461  j1 = 3;
462  j2 = 2;
463  for ( int j=4; j<=n1; j++ ) {
464  ca = std::cos(b_ang[j1]);
465  sa = std::sin(b_ang[j1]);
466  ct = std::cos(t_ang[j2]);
467  st = std::sin(t_ang[j2]);
468  for ( int i=1; i<=3; i++ ) {
469  s[i] = U[2][i];
470  }
471  for ( int i=1; i<=3; i++ ) {
472  U[2][i] = s[i]*ct + U[3][i]*st;
473  }
474  for ( int i=1; i<=3; i++ ) {
475  U[3][i] = -s[i]*st + U[3][i]*ct;
476  }
477  for ( int i=1; i<=3; i++ ) {
478  s[i] = U[2][i];
479  }
480  for ( int i=1; i<=3; i++ ) {
481  U[2][i] = -s[i]*ca - U[1][i]*sa;
482  }
483  for ( int i=1; i<=3; i++ ) {
484  U[1][i] = s[i]*sa - U[1][i]*ca;
485  }
486  for ( int i=1; i<=3; i++ ) {
487  atoms[j][i] = atoms[j1][i] + b_len[j1] * U[1][i];
488  }
489  j2 = j1;
490  j1 = j;
491  }
492  ca = std::cos(b_ang[n1]);
493  sa = std::sin(b_ang[n1]);
494  ct = std::cos(t_ang[n2]);
495  st = std::sin(t_ang[n2]);
496  v[1] = -b_len[n1] * ca;
497  ba = b_len[n1] * sa;
498  v[2] = ba * ct;
499  v[3] = ba * st;
500  // implementing s = U*v'
501  for ( int i=1; i<=3; i++ ) {
502  s[i] = (U[1][i] * v[1]) + (U[2][i] * v[2]) + (U[3][i] * v[3]);
503  }
504  for ( int i=1; i<=3; i++ ) {
505  atoms[n][i] = atoms[n1][i] + s[i];
506  }
507  // check atoms here but still need to implement space and frame
508  if ( space == true ) {
509  // implement:
510  // for i = 1:n
511  // atoms(:,i) = R0 + Q*atoms(:,i);
512  // end
513  utility::vector1<Real> spaceatoms (3); // holder for inner-loop coordinates
514  for ( int ind=1; ind<=n; ind++ ) {
515  for ( int i=1; i<=3; i++ ) {
516  Real inner_sum=0.0;
517  for ( int j=1; j<=3; j++ ) {
518  inner_sum += (Q[i][j] * atoms[ind][j]);
519  }
520  spaceatoms[i]=R0[i]+inner_sum;
521  }
522  for ( int k=1; k<=3; k++ ) {
523  atoms[ind][k]=spaceatoms[k];
524  }
525  }
526  }
527  /*
528  else if (index[1] != 1 || index[2] != 2 || index[3] != 3) {
529  utility::vector1<Real> Ra (3);
530  utility::vector1<utility::vector1<Real> > RR (3), Qa (3), body_atoms(n);
531  //printMatrix(atoms);
532  for (int i=1; i<=3; i++) {
533  RR[i].resize(3);
534  Ra[i] = -atoms[index[1]][i];
535  }
536  //printVector(Ra);
537  for (int i=1; i<=3; i++) {
538  for (int j=1; j<=3; j++) {
539  RR[j][i]=atoms[index[j]][i];
540  }
541  }
542  //printMatrix(RR);
543  frame(RR, Qa);
544  //printMatrix(Qa);
545  for (int ind=1; ind<=n; ind++) {
546  // implement atoms(:,i) = Qa'*(atoms(:,i)+Ra);
547  body_atoms[ind].resize(3);
548  for (int i=1; i<=3; i++) {
549  Real inner_sum=0.0;
550  for (int j=1; j<=3; j++) {
551  inner_sum += Qa[i][j] * (atoms[ind][j] + Ra[j]);
552  }
553  body_atoms[ind][i] = inner_sum;
554  }
555  }
556  atoms = body_atoms;
557  //exit(0);
558  }
559  */
560 }
561 
562 
563 // void chainXYZ {{{1
564 
565 void chainXYZ(
566  const int& n,
567  const utility::vector1<Real>& b_len,
568  const utility::vector1<Real>& b_ang,
569  const utility::vector1<Real>& t_ang,
571 
572  utility::vector1<Real> dummy_R0;
574 
575  chainXYZ(n, b_len, b_ang, t_ang, false, dummy_R0, dummy_Q, atoms);
576 }
577 
578 // void chainTORS {{{1
579 /* chainTORS
580 // ---------
581 // calculates torsions, bond angles, bond lengths from atoms
582 // for a linear chain
583 // calculates angles in degrees
584 //
585 // (j-1) -------- (j)
586 // b_ang(j) \
587 // t_ang(j) \b_len(j)
588 // \
589 // (j+1) ------ (j+2)
590 //
591 */
592 
593 void chainTORS (
594  const int& n,
596  utility::vector1<Real>& t_ang,
597  utility::vector1<Real>& b_ang,
598  utility::vector1<Real>& b_len,
601 
602  t_ang.resize(n);
603  b_ang.resize(n);
604  b_len.resize(n);
606  for ( int i=1; i<=3; i++ ) {
607  framein[i]=atoms[i];
608  }
609  R0=atoms[1];
610  frame(framein,Q);
611  for ( int j=1; j <= n-1; j++ ) {
612  b_len[j] = eucDistance( atoms[j], atoms[j+1] );
613  }
614  b_len[n] = eucDistance( atoms[n], atoms[1] );
615  for ( int j=2; j <= n-1; j++ ) {
616  b_ang[j] = bondangle( atoms[j-1], atoms[j], atoms[j+1] );
617  }
618  b_ang[n] = 0; //bondangle( atoms[n-1], atoms[n], atoms[1] );
619  b_ang[1] = 0; //bondangle( atoms[n], atoms[1], atoms[2] );
620 
621  if ( n >= 4 ) {
622  for ( int j=2; j <= n-2; j++ ) {
623  t_ang[j] = torsion( atoms[j-1], atoms[j], atoms[j+1], atoms[j+2] );
624  }
625  t_ang[n-1] = 0; //torsion( atoms[n-2], atoms[n-1], atoms[n], atoms[1] );
626  t_ang[n] = 0; //torsion( atoms[n-1], atoms[n], atoms[1], atoms[2] );
627  t_ang[1] = 0; //torsion( atoms[n] , atoms[1], atoms[2], atoms[3] );
628  } else {
629  for ( int j=1; j<=n; j++ ) {
630  t_ang[j]=0.0;
631  }
632  }
633 }
634 
635 void rotateX( // {{{1
637  const Real& c,
638  const Real& s,
640 
641  int dim1=R.size();
642  Rx.resize(dim1);
643  for ( int i=1; i<=dim1; i++ ) {
644  Rx[i].resize(R[i].size());
645  Rx[i][1] = R[i][1];
646  Rx[i][2] = c*R[i][2] - s*R[i][3];
647  Rx[i][3] = s*R[i][2] + c*R[i][3];
648  }
649 }
650 
651 void rotateY( // {{{1
653  const Real& c,
654  const Real& s,
656 
657  int dim1=R.size();
658  Ry.resize(dim1);
659  for ( int i=1; i<=dim1; i++ ) {
660  Ry[i].resize(R[i].size());
661  Ry[i][1] = c*R[i][1] + s*R[i][3];
662  Ry[i][2] = R[i][2];
663  Ry[i][3] = -s*R[i][1] + c*R[i][3];
664  }
665 }
666 
667 void rotateZ( // {{{1
669  const Real& c,
670  const Real& s,
672 
673  int dim1=R.size();
674  Rz.resize(dim1);
675  for ( int i=1; i<=dim1; i++ ) {
676  Rz[i].resize(R[i].size());
677  Rz[i][1] = c*R[i][1] - s*R[i][2];
678  Rz[i][2] = s*R[i][1] + c*R[i][2];
679  Rz[i][3] = R[i][3];
680  }
681 }
682 
683 void to_radians ( // {{{1
685 
687  for ( Size i = 1; i < degrees.size(); i++ ) {
688  to_radians(degrees[i]);
689  }
690 }
691 // }}}1
692 void to_degrees ( // {{{1
694 
696  for ( Size i = 1; i < radians.size(); i++ ) {
697  to_degrees(radians[i]);
698  }
699 }
700 // }}}1
701 
702 // void bridge_objects ( // {{{1
703 ////////////////////////////////////////////////////////////////////////////////
704 ///
705 /// @brief
706 /// Solve the triaxial loop closure problem for a system of atoms
707 ///
708 /// @details
709 ///
710 /// @param[in] atoms - matrix of cartesian coordinates of N-CA-C atoms indexed
711 /// as atoms[atom][dimension]
712 /// @param[in] dt - desired torsions for each atom (radians)
713 /// @param[in] da - desired bond angle for each atom (radians)
714 /// @param[in] db - desired bond length for each atom (radians)
715 /// @param[in] pivots - 3 indices (base 1) of atoms to be used as loop closure pivots
716 /// @param[in] order - length 3 vector giving order to solve for the tau parameters (use 1,2,3 if unsure)
717 /// @param[out] t_ang - matrix giving torsion angles for each atom for each solution, indexed as t_ang[solution][atom] (radians)
718 /// @param[out] b_ang - matrix giving bond angles for each atom for each solution, indexed as b_ang[solution][atom] (radians)
719 /// @param[out] b_len - matrix giving bond lengths for each atom for each solution, indexed as b_len[solution][atom] (radians)
720 /// @param[out] nsol - number of solutions found
721 ///
722 /// @global_read
723 ///
724 /// @global_write
725 ///
726 /// @return
727 ///
728 /// @remarks
729 /// dt, da, and db are cast to Real precision when placed in t_ang1,2, b_ang1,2 and b_len1,2.
730 /// Solution is carried out in Real precision.
731 /// Solutions are cast back to Reals when placed into t_ang.
732 ///
733 /// @references
734 ///
735 /// @author Evangelos A. Coutsias
736 /// @author Daniel J. Mandell
737 ///
738 ////////////////////////////////////////////////////////////////////////////////
739 
742  const utility::vector1<Real> & dt,
743  const utility::vector1<Real> & da,
744  const utility::vector1<Real> & db,
745  const utility::vector1<int>& pivots,
746  const utility::vector1<int>& order,
750  int& nsol) {
751 
752  utility::vector1<Real> R0 (3) /* for chainXYZ interface */, R1 (3), R2 (3), R3 (3); // origins of triangle pieces
753  utility::vector1<utility::vector1<Real> > Q0; // for chainXYZ interface
754  utility::vector1<utility::vector1<Real> > chain1, chain2, chain3, fchain1, fchain2, fchain3; // 3 triangle pieces
755  utility::vector1<utility::vector1<Real> > chain1a, chain1b, chain2a, chain2b, chain12, chain12rX; // reconstructions of the molecular chain
756  utility::vector1<Real> t_ang1, b_ang1, b_len1, t_ang2, b_ang2, b_len2; // torsions, angles, lengths of chains 1,2
757  utility::vector1<Real> vbond (3), xi (3), eta (3), delta (3), theta (3); // triaxial parameters for each pivot
758  utility::vector1<Real> cal, sal;
759  utility::vector1<utility::vector1<Real> > frame1, frame2, frame3;
760  utility::vector1<utility::vector1<Real> > A, B, C, D; // dixon matrices
761  utility::vector1<utility::vector1<Real> > cosines, sines, taus;
763  int k1, k2, k3, l1, l2, l3, l3a, l3b;
764  int ind;
765  int N=atoms.size(); // number of atoms in chain
766  bool feasible_triangle;
767 
768  k1 = pivots[1];
769  k2 = pivots[2];
770  k3 = pivots[3];
771  l1 = k2-k1+1;
772  l2 = k3-k2+1;
773  l3a = N-k3+1;
774  l3b = k1;
775  l3 = l3a + l3b;
776  chain1.resize(l1);
777  chain2.resize(l2);
778  chain3.resize(l3);
779  t_ang1.resize(l1);
780  t_ang2.resize(l2);
781  b_ang1.resize(l1);
782  b_ang2.resize(l2);
783  b_len1.resize(l1);
784  b_len2.resize(l2);
785 
786  // break the designed torsions, angles, and lengths into 3 chains (3rd
787  // chain's coords set directly)
788  ind=1;
789  for ( int i=pivots[1]; i<=pivots[2]; i++ ) {
790  t_ang1[ind++]=dt[i];
791  }
792  ind=1;
793  for ( int i=pivots[2]; i<=pivots[3]; i++ ) {
794  t_ang2[ind++]=dt[i];
795  }
796  ind=1;
797  for ( int i=pivots[1]; i<=pivots[2]; i++ ) {
798  b_ang1[ind++]=da[i];
799  }
800  ind=1;
801  for ( int i=pivots[2]; i<=pivots[3]; i++ ) {
802  b_ang2[ind++]=da[i];
803  }
804  ind=1;
805  for ( int i=pivots[1]; i<=pivots[2]; i++ ) {
806  b_len1[ind++] = db[i];
807  }
808  ind=1;
809  for ( int i=pivots[2]; i<=pivots[3]; i++ ) {
810  b_len2[ind++] = db[i];
811  }
812 
813  chainXYZ( l1, b_len1, b_ang1, t_ang1, false, R0, Q0, chain1 );
814  chainXYZ( l2, b_len2, b_ang2, t_ang2, false, R0, Q0, chain2 );
815 
816  // set chain 3 directly from original atoms
817  ind=1;
818  for ( int i=k3; i<=N; i++ ) {
819  chain3[ind++] = atoms[i];
820  }
821  for ( int i=1; i<=k1; i++ ) {
822  chain3[ind++] = atoms[i];
823  }
824 
825  // compute pivot triangle parameters
826  chainParams( l1, chain1, vbond[1], xi[1], eta[1], delta[1], R1, frame1 );
827  for ( int i=1; i<=l1; i++ ) {
828  for ( int j=1; j<=3; j++ ) {
829  chain1[i][j] -= R1[j];
830  }
831  }
832  multTransMatrix(frame1, chain1, fchain1);
833  chainParams( l2, chain2, vbond[2], xi[2], eta[2], delta[2], R2, frame2 );
834  for ( int i=1; i<=l2; i++ ) {
835  for ( int j=1; j<=3; j++ ) {
836  chain2[i][j] -= R2[j];
837  }
838  }
839  multTransMatrix(frame2, chain2, fchain2);
840  chainParams( l3, chain3, vbond[3], xi[3], eta[3], delta[3], R3, frame3 );
841  for ( int i=1; i<=3; i++ ) {
842  theta[i] = da[pivots[i]]; // use the designed bond angles
843  }
844  fchain3=chain3; // for naming consistency
845 
846  // check feasibility of arrangement and define polynomial coefficients
847  triaxialCoefficients( vbond, xi, eta, delta, theta, order, A, B, C, D, cal, sal, feasible_triangle);
848 
849  if ( feasible_triangle == false ) {
850  nsol = 0;
851  return;
852  }
853 
854  // find the solutions
855  dixon_eig(A, B, C, D, order, cosines, sines, taus, nsol);
856 
857  // reconstruct the molecular chain with new torsions
858  loop.resize(nsol);
859  t_ang.resize(nsol);
860  b_ang.resize(nsol);
861  b_len.resize(nsol);
862  for ( int j=1; j<=nsol; j++ ) {
863  rotateX(fchain1, cosines[j][1], sines[j][1], chain1a);
864  rotateZ(chain1a, cal[1], sal[1], chain1b);
865  for ( unsigned k=1; k<=chain1b.size(); k++ ) {
866  chain1b[k][1] += vbond[3];
867  }
868  rotateX(fchain2, cosines[j][2], sines[j][2], chain2a);
869  rotateZ(chain2a, cal[3], -sal[3], chain2b);
870  for ( unsigned k=1; k<=chain2b.size(); k++ ) {
871  chain2b[k][1] -= chain2b[l2][1];
872  chain2b[k][2] -= chain2b[l2][2];
873  }
874  // implementing chain12 = [chain1b(:,2:l1), chain2b(:,2:l2-1)];
875  int chain12len = (l1-1) + (l2-2);
876  chain12.resize(chain12len);
877  int ind = 1;
878  for ( int k=2; k<=l1; k++ ) {
879  chain12[ind].resize(3);
880  for ( int n=1; n<=3; n++ ) {
881  chain12[ind][n] = chain1b[k][n];
882  }
883  ind++;
884  }
885  for ( int k=2; k<=l2-1; k++ ) {
886  chain12[ind].resize(3);
887  for ( int n=1; n<=3; n++ ) {
888  chain12[ind][n] = chain2b[k][n];
889  }
890  ind++;
891  }
892  rotateX(chain12, cosines[j][3], -sines[j][3], chain12rX);
893  multMatrix(frame3, chain12rX, chain12);
894  for ( int k=1; k<=chain12len; k++ ) {
895  for ( int n=1; n<=3; n++ ) {
896  chain12[k][n] += R3[n];
897  }
898  }
899 
900  // populate the loop table with the cartesian solutions
901  loop[j].resize(N);
902  for ( int k=1; k<=l3b; k++ ) {
903  loop[j][k].resize(3);
904  for ( int kk=1; kk<=3; kk++ ) {
905  loop[j][k][kk] = chain3[l3a+k][kk];
906  }
907  }
908  for ( int k=1; k<= l1 + l2 - 3; k++ ) {
909  loop[j][l3b+k].resize(3);
910  for ( int kk=1; kk<=3; kk++ ) {
911  loop[j][l3b+k][kk] = chain12[k][kk];
912  }
913  }
914  for ( int k=1; k<=l3a; k++ ) {
915  loop[j][l3b+l1+l2-3+k].resize(3);
916  for ( int kk=1; kk<=3; kk++ ) {
917  loop[j][l3b+l1+l2-3+k][kk] = chain3[k][kk];
918  }
919  }
920 
921  // calculate the 6 closure torsions and place them (with Real precision)
922  // into the output vector together with the designed torsions, angles, and
923  // lengths (which are copied directly from the input)
924  int pivots2m1 = pivots[2]-1, pivots2p1 = pivots[2]+1,
925  pivots3m1 = pivots[3]-1, pivots3p1 = pivots[3]+1;
926 
927  t_ang[j] = dt;
928  b_ang[j] = da;
929  b_len[j] = db;
930  t_ang[j][4] = static_cast<Real> (torsion(loop[j][3],loop[j][4],loop[j][5],loop[j][6])); // pivot 1 always atom 5
931  t_ang[j][5] = static_cast<Real> (torsion(loop[j][4],loop[j][5],loop[j][6],loop[j][7]));
932  t_ang[j][pivots2m1] = static_cast<Real> (torsion(loop[j][pivots[2]-2],loop[j][pivots2m1],
933  loop[j][pivots[2]],loop[j][pivots2p1]));
934  t_ang[j][pivots[2]] = static_cast<Real> (torsion(loop[j][pivots2m1],loop[j][pivots[2]],
935  loop[j][pivots2p1],loop[j][pivots[2]+2]));
936  t_ang[j][pivots3m1] = static_cast<Real> (torsion(loop[j][pivots[3]-2],loop[j][pivots3m1],
937  loop[j][pivots[3]],loop[j][pivots3p1]));
938  t_ang[j][pivots[3]] = static_cast<Real> (torsion(loop[j][pivots3m1],loop[j][pivots[3]],
939  loop[j][pivots3p1],loop[j][pivots[3]+2]));
940  }
941 }
942 // }}}1
943 
944 }
945 }
946 }
void multTransMatrix(const utility::vector1< utility::vector1< Real > > &A, const utility::vector1< utility::vector1< Real > > &B, utility::vector1< utility::vector1< Real > > &C)
platform::Size Size
Definition: types.hh:42
dictionary size
Definition: amino_acids.py:44
void triaxialCoefficients(const utility::vector1< Real > &vb, const utility::vector1< Real > &xi, const utility::vector1< Real > &eta, const utility::vector1< Real > &delta, const utility::vector1< Real > &theta, const utility::vector1< int > &order, utility::vector1< utility::vector1< Real > > &A, utility::vector1< utility::vector1< Real > > &B, utility::vector1< utility::vector1< Real > > &C, utility::vector1< utility::vector1< Real > > &D, utility::vector1< Real > &cal, utility::vector1< Real > &sal, bool &feasible_triangle)
Definition: closure.cc:94
char space()
Space Character.
Conversions between degrees and radians.
void to_degrees(utility::vector1< Real > &radians)
Definition: closure.cc:692
void frame(const utility::vector1< utility::vector1< Real > > &R, utility::vector1< utility::vector1< Real > > &U)
Definition: closure.cc:254
Real eucDistance(const utility::vector1< Real > &a, const utility::vector1< Real > &b)
Definition: closure.cc:279
Real scpn(const utility::vector1< Real > &a, const utility::vector1< Real > &b, const utility::vector1< Real > &c)
Definition: closure.cc:286
void triangle(const utility::vector1< Real > &vbond, utility::vector1< Real > &calpha, utility::vector1< Real > &salpha)
Definition: closure.cc:41
void cross(const utility::vector1< Real > &L, const utility::vector1< Real > &r0, utility::vector1< Real > &r)
Definition: closure.cc:239
#define C(a, b)
Definition: functions.cc:27
tuple p
Definition: docking.py:9
T & to_degrees(T &radians)
Degrees from radians.
Definition: conversions.hh:104
void chainParams(const int &n, const utility::vector1< utility::vector1< Real > > &atoms, Real &vbond, Real &xi, Real &eta, Real &delta, utility::vector1< Real > &R0, utility::vector1< utility::vector1< Real > > &Q)
Definition: closure.cc:359
def z
Functions to wrap angles in different ranges. author Kale Kundert (kale.kundert@ucsf.edu)
T abs(T const &x)
std::abs( x ) == | x |
Definition: Fmath.hh:295
void sincos(const utility::vector1< Real > &theta, const int flag, utility::vector1< Real > &cosine, utility::vector1< Real > &sine)
Definition: closure.cc:61
Header file for dixon code for ALC.
Real bondangle(const utility::vector1< Real > &a, const utility::vector1< Real > &b, const utility::vector1< Real > &c)
Definition: closure.cc:300
T wrap_2pi(T const &angle)
Wrap the given angle in the range [0, 2 * pi).
Definition: wrap_angles.hh:25
T degrees(T const &radians)
Degrees of radians.
Definition: conversions.hh:80
std::string L(int const w, bool const &t)
Logical Format.
Definition: format.cc:289
rosetta project type declarations. Should be kept updated with core/types.hh. This exists because num...
void rotateX(const utility::vector1< utility::vector1< Real > > &R, const Real &c, const Real &s, utility::vector1< utility::vector1< Real > > &Rx)
Definition: closure.cc:635
void chainTORS(const int &n, const utility::vector1< utility::vector1< Real > > &atoms, utility::vector1< Real > &t_ang, utility::vector1< Real > &b_ang, utility::vector1< Real > &b_len, utility::vector1< Real > &R0, utility::vector1< utility::vector1< Real > > &Q)
Definition: closure.cc:593
void chainXYZ(const int &n, const utility::vector1< Real > &b_len1, const utility::vector1< Real > &b_ang1, const utility::vector1< Real > &t_ang1, const bool space, const utility::vector1< Real > &R0, const utility::vector1< utility::vector1< Real > > &Q, utility::vector1< utility::vector1< Real > > &atoms)
Definition: closure.cc:405
void dixon_eig(PseudoMatrix const &A, PseudoMatrix const &B, PseudoMatrix const &C, PseudoMatrix const &D, vector1< int > const &, PseudoMatrix &cos, PseudoMatrix &sin, PseudoMatrix &u, int &num_solutions)
Definition: dixon.cc:431
void multMatrix(const utility::vector1< utility::vector1< Real > > &A, const utility::vector1< utility::vector1< Real > > &B, utility::vector1< utility::vector1< Real > > &C)
DimensionExpressionPow pow(Dimension const &dim1, Dimension const &dim2)
pow( Dimension, Dimension )
void bridge_objects(const utility::vector1< utility::vector1< Real > > &atoms, const utility::vector1< Real > &dt, const utility::vector1< Real > &da, const utility::vector1< Real > &db, const utility::vector1< int > &pivots, const utility::vector1< int > &order, utility::vector1< utility::vector1< Real > > &t_ang, utility::vector1< utility::vector1< Real > > &b_ang, utility::vector1< utility::vector1< Real > > &b_len, int &nsol)
Solve the triaxial loop closure problem for a system of atoms.
Definition: closure.cc:740
vector1: std::vector with 1-based indexing
void rotateZ(const utility::vector1< utility::vector1< Real > > &R, const Real &c, const Real &s, utility::vector1< utility::vector1< Real > > &Rz)
Definition: closure.cc:667
void rotateY(const utility::vector1< utility::vector1< Real > > &R, const Real &c, const Real &s, utility::vector1< utility::vector1< Real > > &Ry)
Definition: closure.cc:651
void to_radians(utility::vector1< Real > &degrees)
Definition: closure.cc:683
Real torsion(const utility::vector1< Real > &a, const utility::vector1< Real > &b, const utility::vector1< Real > &c, const utility::vector1< Real > &d)
Definition: closure.cc:312
Common numeric constants in varying precisions.
T radians(T const &degrees)
Radians of degrees.
Definition: conversions.hh:32
Header file for kinematic_closure_helpers.cc.
T & to_radians(T &degrees)
Radians from degrees.
Definition: conversions.hh:56
std::string A(int const w, char const c)
char Format
Definition: format.cc:175
def y