Victor
 All Data Structures Functions Variables Friends Pages
IntCoordConverter.h
1 /* This file is part of Victor.
2 
3  Victor is free software: you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation, either version 3 of the License, or
6  (at your option) any later version.
7 
8  Victor is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with Victor. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef _INTCOORDCONVERTER_H_
18 #define _INTCOORDCONVERTER_H_
19 
20 // Includes
21 #include <iostream>
22 #include <Atom.h>
23 #include <Debug.h>
24 #include <IoTools.h>
25 #include <vglMath.h>
26 
27 namespace Victor { namespace Biopool {
28 
29  class AminoAcid;
30 
31 
32 
33  const static double EPSILON = 0.0001;
34 
35  const double RAD2DEG = 180 / M_PI;
36  const double DEG2RAD = M_PI / 180;
37 
38  const double UNDEFINED_ANGLE = DEG2RAD * 999;
39 
47  public:
48  // CONSTRUCTORS/DESTRUCTOR:
50  virtual ~IntCoordConverter();
51 
52  // PREDICATES:
53  static double getBondAngle(Atom& a1, Atom& a2, Atom& a3);
54  static double getTorsionAngle(Atom& a1, Atom& a2, Atom& a3, Atom& a4);
55  static double getBondLength(Atom& a1, Atom& a2);
57  double getAngle(vgVector3<double>& p11, vgVector3<double>& p12,
58  vgVector3<double>& p21, vgVector3<double>& p22);
60  double getAngle(vgVector3<double>& v1, vgVector3<double>& v2);
62  vgVector3<double> calculateTrans(vgVector3<double>& p1, vgVector3<double>& p2);
64  vgMatrix3<double> calculateRot(vgVector3<double>& p11, vgVector3<double>& p12,
65  vgVector3<double>& p21, vgVector3<double>& p22);
66 
67  // MODIFIERS:
68  void setBondAngle(Atom& a1, Atom& a2, Atom& a3, double angle);
69  void setBondAngle(Atom& a1, Atom& a2, Atom& a3, double angle,
70  double old_angle);
71  void setTorsionAngle(Atom& a1, Atom& a2, Atom& a3, Atom& a4, double angle);
72  void setTorsionAngle(Atom& a1, Atom& a2, Atom& a3, Atom& a4,
73  double angle, double old_angle);
74  void setBondLength(Atom& a1, Atom& a2, double length);
75 
76  void connectStructure(AminoAcid& aa, AminoAcid& prev);
77  void connectReverseStructure(AminoAcid& aa, AminoAcid& prev);
78  void zAtomToCartesian(Atom& atbLP, const double bondLength, Atom& atbAP,
79  const double bondAngle, Atom& attAP,
80  const double torsionAngle, const int chiral, Atom& at);
81 
82  // OPERATORS:
83 
84  //protected:
85  // HELPERS:
86  double normalize(double angle) const;
88  double getAngleDifference(double a, double b) const;
91  // ATTRIBUTES:
92  };
93 
94 
95  // ---------------------------------------------------------------------------
96  // IntCoordConverter
97  // -----------------x-------------------x-------------------x-----------------
98 
99 
100 
101 
102  // PREDICATES:
103 
104  // MODIFIERS:
105 
106  // OPERATORS:
107 
108  // HELPERS:
109 
115  inline
116  double
117  angle(const vgVector3<double>& a, const vgVector3<double>& b) {
118  PRECOND(a.length() * b.length() != 0.0,
119  exception);
120 
121  long double d = (a * b) / (a.length() * b.length());
122 
123  // Cope with numeric inaccurracy.
124  if (d > 1.0)
125  d = 1.0;
126  else if (d < -1.0)
127  d = -1.0;
128 
129  INVARIANT(fabs(d) <= 1.0, logic_error);
130 
131  return acos(d);
132  }
138  inline
139  double
140  angle(const vgVector3<float>& a, const vgVector3<float>& b) {
141  PRECOND(a.length() * b.length() != 0.0,
142  exception);
143 
144  long double d = (a * b) / (a.length() * b.length());
145 
146  // Cope with numeric inaccurracy.
147  if (d > 1.0)
148  d = 1.0;
149  else if (d < -1.0)
150  d = -1.0;
151 
152  INVARIANT(fabs(d) <= 1.0, logic_error);
153 
154  return acos(d);
155  }
156 
163  inline void alignVectors(vgVector3<double> v1, vgVector3<double> v2,
164  vgMatrix3<double>& res) {
165  PRECOND(v1.length() * v2.length() != 0.0, exception);
166 
167  // special case if v1 = -v2 would not rotate at all
168  if ((v1 + v2).length() < EPSILON)
169  v2.z += EPSILON;
170  vgVector3<double> axis = (v1.normalize()).cross(v2.normalize());
171  res = vgMatrix3<double>::createRotationMatrix(axis, -angle(v1.normalize(),
172  v2.normalize()));
173 
174 #ifndef NDEBUG
175  v2 = res * v2;
176  POSTCOND((v2.normalize() - v1.normalize()).length() < EPSILON, exception);
177 #endif
178  }
179 
184  inline void
185  alignVectors(vgVector3<float> v1, vgVector3<float> v2,
186  vgMatrix3<float>& res) {
187  PRECOND(v1.length() * v2.length() != 0.0, exception);
188 
189  // special case if v1 = -v2 would not rotate at all
190  if ((v1 + v2).length() < EPSILON)
191  v2.z += EPSILON;
192  vgVector3<float> axis = (v1.normalize()).cross(v2.normalize());
193  res = vgMatrix3<float>::createRotationMatrix(axis, -angle(v1.normalize(),
194  v2.normalize()));
195 
196 #ifndef NDEBUG
197  v2 = res * v2;
198  POSTCOND((v2.normalize() - v1.normalize()).length() < EPSILON, exception);
199 #endif
200  }
201 
202 }} //namespace
203 #endif //_INTCOORDCONVERTER_H_
204 
void zAtomToCartesian(Atom &atbLP, const double bondLength, Atom &atbAP, const double bondAngle, Atom &attAP, const double torsionAngle, const int chiral, Atom &at)
Definition: IntCoordConverter.cc:366
static double getTorsionAngle(Atom &a1, Atom &a2, Atom &a3, Atom &a4)
Definition: IntCoordConverter.cc:127
double getAngleDifference(double a, double b) const
Definition: IntCoordConverter.cc:168
double getAngle(vgVector3< double > &p11, vgVector3< double > &p12, vgVector3< double > &p21, vgVector3< double > &p22)
returns angle between vectors detected by couple of points
Definition: IntCoordConverter.cc:42
vgMatrix3< double > calculateRot(vgVector3< double > &p11, vgVector3< double > &p12, vgVector3< double > &p21, vgVector3< double > &p22)
calculates rotation matrix that rotate a vector into another
Definition: IntCoordConverter.cc:76
static double getBondLength(Atom &a1, Atom &a2)
Definition: IntCoordConverter.cc:112
void setBondAngle(Atom &a1, Atom &a2, Atom &a3, double angle)
Definition: IntCoordConverter.cc:183
Implements a simple atom type.
Definition: Atom.h:39
static double getBondAngle(Atom &a1, Atom &a2, Atom &a3)
Definition: IntCoordConverter.cc:95
void setTorsionAngle(Atom &a1, Atom &a2, Atom &a3, Atom &a4, double angle)
Definition: IntCoordConverter.cc:220
It mplements a simple amino acid.
Definition: AminoAcid.h:43
Implements methods to manage translation vector and angles between vectors.
Definition: IntCoordConverter.h:46
vgVector3< double > calculateTrans(vgVector3< double > &p1, vgVector3< double > &p2)
returns translation vector that translates a point into another
Definition: IntCoordConverter.cc:66