Simpatico  v1.10
TorsionForce.h
1 #ifndef SIMP_TORSION_FORCE_H
2 #define SIMP_TORSION_FORCE_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 "Torsion.h"
12 
13 #include <cmath>
14 
15 namespace Simp
16 {
17 
18  using namespace Util;
19 
44  struct TorsionForce : public Torsion
45  {
46 
47  public:
48 
53 
58 
63 
73  bool computeDerivatives(const Vector& b1, const Vector& b2, const Vector& b3);
74 
75  };
76 
77  // Inline method definitions
78 
79  /*
80  * Calculate cosPhi.
81  */
82  inline bool
84  const Vector& b1, const Vector& b2, const Vector& b3)
85  {
86  Vector u1, u2, t1, t2;
87  double r1, r2;
88 
89  u1.cross(b1, b2);
90  r1 = u1.square();
91  if (r1 < 1.0E-10) {
92  return 1; // Error code
93  }
94  r1 = sqrt(r1);
95  u1 /= r1;
96 
97  u2.cross(b2, b3);
98  r2 = u2.square();
99  if (r2 < 1.0E-10) {
100  return 1; // Error code
101  }
102  r2 = sqrt(r2);
103  u2 /= r2;
104 
105  cosPhi = u1.dot(u2);
106 
107  t1.multiply(u1, -cosPhi);
108  t1 += u2;
109  t1 *= 1.0 / r1;
110 
111  t2.multiply(u2, -cosPhi);
112  t2 += u1;
113  t2 *= 1.0 / r2;
114 
115  d1.cross(b2, t1);
116  d3.cross(t2, b2);
117 
118  d2.cross(t1, b1);
119  t1.cross(b3, t2);
120  d2 += t1;
121 
122  return 0; // Normal completion
123  }
124 
125 }
126 #endif
Vector d1
Vector of derivatives d1[i] = d(cosPhi)/d(b1[i])
Definition: TorsionForce.h:52
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
bool computeDerivatives(const Vector &b1, const Vector &b2, const Vector &b3)
Compute cosPhi and derivatives.
Definition: TorsionForce.h:83
double cosPhi
Cosine of dihedral angle.
Definition: Torsion.h:42
Vector & multiply(const Vector &v, double s)
Multiply a vector v by a scalar s.
Definition: Vector.h:686
Classes used by all simpatico molecular simulations.
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
Computes derivatives of dihedral angle with respect to bond vectors.
Definition: TorsionForce.h:44
Vector d2
Vector of derivatives d2[i] = d(cosPhi)/d(b2[i])
Definition: TorsionForce.h:57
Vector d3
Vector of derivatives d3[i] = d(cosPhi)/d(b3[i])
Definition: TorsionForce.h:62
Computes dihedral / torsion angle involving 3 bonds.
Definition: Torsion.h:34
double square() const
Return square magnitude of this vector.
Definition: Vector.h:616