Simpatico  v1.10
Torsion.h
1 #ifndef SIMP_TORSION_H
2 #define SIMP_TORSION_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/space/Vector.h>
12 
13 #include <cmath>
14 
15 namespace Simp
16 {
17 
18  using namespace Util;
19 
34  struct Torsion
35  {
36 
37  public:
38 
42  double cosPhi;
43 
53  bool computeAngle(const Vector& b1, const Vector& b2, const Vector& b3);
54 
58  double sinPhi() const;
59 
65  double phi() const;
66 
67  };
68 
69  // Inline method definitions
70 
71  /*
72  * Calculate cosPhi.
73  */
74  inline bool
75  Torsion::computeAngle(const Vector& b1, const Vector& b2, const Vector& b3)
76  {
77  Vector v1, v2;
78  double d1, d2;
79 
80  v1.cross(b1, b2);
81  d1 = v1.square();
82  if (d1 < 1.0E-10) {
83  return 1;
84  }
85  d1 = sqrt(d1);
86 
87  v2.cross(b2, b3);
88  d2 = v2.square();
89  if (d2 < 1.0E-10) {
90  return 1; // error code
91  }
92  d2 = sqrt(d2);
93 
94  cosPhi = v1.dot(v2)/(d1*d2);
95  return 0; // Normal completion
96  }
97 
98  /*
99  * Return value sin(phi) for precomputed cos(phi).
100  */
101  inline
102  double Torsion::sinPhi() const
103  { return sqrt(1.0 - cosPhi*cosPhi); }
104 
105  /*
106  * Return phi in radians for precomputed cos(phi).
107  */
108  inline
109  double Torsion::phi() const
110  { return std::acos(cosPhi); }
111 
112 }
113 #endif
A Vector is a Cartesian vector.
Definition: Vector.h:75
double dot(const Vector &v) const
Return dot product of this vector and vector v.
Definition: Vector.h:632
double cosPhi
Cosine of dihedral angle.
Definition: Torsion.h:42
Classes used by all simpatico molecular simulations.
double sinPhi() const
Return value of sin(phi) for precomputed cos(phi).
Definition: Torsion.h:102
Vector & cross(const Vector &v1, const Vector &v2)
Calculate cross product of vectors v1 and v2.
Definition: Vector.h:714
Utility classes for scientific computation.
Definition: accumulators.mod:1
double phi() const
Return value of phi in radians for precomputed cos(phi).
Definition: Torsion.h:109
bool computeAngle(const Vector &b1, const Vector &b2, const Vector &b3)
Compute cosPhi.
Definition: Torsion.h:75
Computes dihedral / torsion angle involving 3 bonds.
Definition: Torsion.h:34
double square() const
Return square magnitude of this vector.
Definition: Vector.h:616