ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/primitives/Torsion.cpp
Revision: 1746
Committed: Wed Nov 17 06:37:56 2004 UTC (19 years, 9 months ago) by tim
File size: 3048 byte(s)
Log Message:
add  PolynomialBondType, PolynomialBendType, PolynomialTorsionType, HarmonicBendType and CharmmTorsionType. Need to refine the design and add document for them

File Contents

# User Rev Content
1 tim 1746 #include "primitives/Torsion.hpp"
2    
3     namespace oopse {
4    
5     Torsion::Torsion(Atom *atom1, Atom *atom2, Atom *atom3, Atom *atom4,
6     TorsionType *tt) :
7     atom1_(atom1),
8     atom2_(atom2),
9     atom3_(atom3),
10     atom4_(atom4) { }
11    
12     void Torsion::calcForce() {
13     Vector3d pos1 = atom1_->getPos();
14     Vector3d pos2 = atom2_->getPos();
15     Vector3d pos3 = atom3_->getPos();
16     Vector3d pos4 = atom4_->getPos();
17    
18     Vector3d r12 = pos1 - pos2;
19     Vector3d r23 = pos2 - pos3;
20     Vector3d r34 = pos3 - pos4;
21    
22     // Calculate the cross products and distances
23     Vector3d A = cross(r12, r23);
24     double rA = A.length();
25     Vector3d B = cross(r23, r34);
26     double rB = B.length();
27     Vector3d C = cross(r23, A);
28     double rC = C.length();
29    
30     A.normalize();
31     B.normalize();
32     C.normalize();
33    
34     // Calculate the sin and cos
35     double cos_phi = dot(A, B) ;
36     double sin_phi = dot(C, B);
37    
38     double phi = -atan2(sin_phi, cos_phi);
39    
40     double dVdPhi;
41     torsionType_->calcForce(phi, potential_, dVdPhi);
42    
43     Vector3d f1;
44     Vector3d f2;
45     Vector3d f3;
46    
47     // Next, we want to calculate the forces. In order
48     // to do that, we first need to figure out whether the
49     // sin or cos form will be more stable. For this,
50     // just look at the value of phi
51     if (fabs(sin_phi) > 0.1) {
52     // use the sin version to avoid 1/cos terms
53    
54     Vector3d dcosdA = (cos_phi * A - B) /rA;
55     Vector3d dcosdB = (cos_phi * B - A) /rB;
56    
57     double dVdcosPhi = dVdPhi / sin_phi;
58    
59     f1 = dVdcosPhi * cross(r23, dcosdA);
60     f2 = dVdcosPhi * ( cross(r34, dcosdB) - cross(r12, dcosdA));
61     f3 = dVdcosPhi * cross(r23, dcosdB);
62    
63     } else {
64     // This angle is closer to 0 or 180 than it is to
65     // 90, so use the cos version to avoid 1/sin terms
66    
67     double dVdsinPhi = -dVdPhi /cos_phi;
68     Vector3d dsindB = (sin_phi * B - C) /rB;
69     Vector3d dsindC = (sin_phi * C - B) /rC;
70    
71     f1.x = dVdsinPhi*((r23.y*r23.y + r23.z*r23.z)*dsindC.x - r23.x*r23.y*dsindC.y - r23.x*r23.z*dsindC.z);
72    
73     f1.y = dVdsinPhi*((r23.z*r23.z + r23.x*r23.x)*dsindC.y - r23.y*r23.z*dsindC.z - r23.y*r23.x*dsindC.x);
74    
75     f1.z = dVdsinPhi*((r23.x*r23.x + r23.y*r23.y)*dsindC.z - r23.z*r23.x*dsindC.x - r23.z*r23.y*dsindC.y);
76    
77     f2.x = dVdsinPhi*(-(r23.y*r12.y + r23.z*r12.z)*dsindC.x + (2.0*r23.x*r12.y - r12.x*r23.y)*dsindC.y
78     + (2.0*r23.x*r12.z - r12.x*r23.z)*dsindC.z + dsindB.z*r34.y - dsindB.y*r34.z);
79    
80     f2.y = dVdsinPhi*(-(r23.z*r12.z + r23.x*r12.x)*dsindC.y + (2.0*r23.y*r12.z - r12.y*r23.z)*dsindC.z
81     + (2.0*r23.y*r12.x - r12.y*r23.x)*dsindC.x + dsindB.x*r34.z - dsindB.z*r34.x);
82    
83     f2.z = dVdsinPhi*(-(r23.x*r12.x + r23.y*r12.y)*dsindC.z + (2.0*r23.z*r12.x - r12.z*r23.x)*dsindC.x
84     +(2.0*r23.z*r12.y - r12.z*r23.y)*dsindC.y + dsindB.y*r34.x - dsindB.x*r34.y);
85    
86     f3 = dVdsinPhi * cross(dsindB, r23);
87    
88     }
89    
90     atom1_->addFrc(f1);
91     atom2_->addFrc(f2 - f1);
92     atom3_->addFrc(f3 - f2);
93     atom4_->addFrc(-f3);
94     }
95    
96     }