ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/restraints/MolecularRestraint.cpp
Revision: 2024
Committed: Thu Oct 16 19:13:51 2014 UTC (10 years, 6 months ago) by gezelter
File size: 7047 byte(s)
Log Message:
Added Radial and Z-projected velocity autocorrelation functions
Started to add SequentialProps program
Mucking about with angular restraint potentials

File Contents

# Content
1 /*
2 * Copyright (c) 2009 The University of Notre Dame. All Rights Reserved.
3 *
4 * The University of Notre Dame grants you ("Licensee") a
5 * non-exclusive, royalty free, license to use, modify and
6 * redistribute this software in source and binary code form, provided
7 * that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
15 * distribution.
16 *
17 * This software is provided "AS IS," without a warranty of any
18 * kind. All express or implied conditions, representations and
19 * warranties, including any implied warranty of merchantability,
20 * fitness for a particular purpose or non-infringement, are hereby
21 * excluded. The University of Notre Dame and its licensors shall not
22 * be liable for any damages suffered by licensee as a result of
23 * using, modifying or distributing the software or its
24 * derivatives. In no event will the University of Notre Dame or its
25 * licensors be liable for any lost revenue, profit or data, or for
26 * direct, indirect, special, consequential, incidental or punitive
27 * damages, however caused and regardless of the theory of liability,
28 * arising out of the use of or inability to use software, even if the
29 * University of Notre Dame has been advised of the possibility of
30 * such damages.
31 *
32 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
33 * research, please cite the appropriate papers when you publish your
34 * work. Good starting points are:
35 *
36 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
37 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
38 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
39 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 */
42
43 #include "restraints/MolecularRestraint.hpp"
44 #include "math/SquareMatrix3.hpp"
45 #include "math/SVD.hpp"
46 #include <utility>
47
48 //using namespace JAMA;
49
50 namespace OpenMD {
51
52
53 void MolecularRestraint::calcForce(std::vector<Vector3d> struc,
54 Vector3d molCom){
55
56 assert(struc.size() == ref_.size());
57
58 std::vector<Vector3d>::iterator it;
59
60 // clear out initial values:
61 pot_ = 0.0;
62 for(it = forces_.begin(); it != forces_.end(); ++it)
63 (*it) = 0.0;
64
65
66 if (restType_ & rtDisplacement) {
67 Vector3d del = molCom - refCom_;
68
69 RealType r = del.length();
70 RealType p = 0.5 * kDisp_ * r * r;
71
72 pot_ += p;
73
74 if (printRest_) restInfo_[rtDisplacement] = std::make_pair(r, p);
75
76 for(it = forces_.begin(); it != forces_.end(); ++it)
77 (*it) = -kDisp_ * del * scaleFactor_;
78 }
79
80 for(it = struc.begin(); it != struc.end(); ++it)
81 (*it) -= molCom;
82
83 // rtDisplacement = 1, so anything higher than that requires orientations:
84 if (restType_ > 1) {
85 Vector3d tBody(0.0);
86
87 Mat3x3d R(0.0);
88
89 for (unsigned int n = 0; n < struc.size(); n++){
90
91 /*
92 * correlation matrix R:
93 * R(i,j) = sum(over n): y(n,i) * x(n,j)
94 * where x(n) and y(n) are two vector sets
95 */
96
97 R += outProduct(struc[n], ref_[n]);
98 }
99
100 // SVD class uses dynamic matrices, so we must wrap the correlation
101 // matrix before calling SVD and then unwrap the results into Mat3x3d
102 // and Vector3d before we use them.
103
104 DynamicRectMatrix<RealType> Rtmp(3, 3, 0.0);
105 DynamicRectMatrix<RealType> vtmp(3, 3);
106 DynamicVector<RealType> stmp(3);
107 DynamicRectMatrix<RealType> wtmp(3, 3);
108
109 Rtmp.setSubMatrix(0, 0, R);
110
111 // Heavy lifting goes here:
112
113 JAMA::SVD<RealType> svd(Rtmp);
114
115 svd.getU(vtmp);
116 svd.getSingularValues(stmp);
117 svd.getV(wtmp);
118
119 Mat3x3d v;
120 Vector3d s;
121 Mat3x3d w_tr;
122
123 vtmp.getSubMatrix(0, 0, v);
124 stmp.getSubVector(0, s);
125 wtmp.getSubMatrix(0, 0, w_tr);
126
127 bool is_reflection = (v.determinant() * w_tr.determinant()) < 0.0;
128
129 if (is_reflection){
130 v(2, 0) = -v(2, 0);
131 v(2, 1) = -v(2, 1);
132 v(2, 2) = -v(2, 2);
133 }
134
135 RotMat3x3d Atrans = v * w_tr.transpose();
136 RotMat3x3d A = Atrans.transpose();
137
138 Vector3d eularAngles = A.toEulerAngles();
139
140
141 RealType twistAngle;
142 Vector3d swingAxis;
143
144 Quat4d quat = A.toQuaternion();
145
146 RealType swingX, swingY;
147 quat.toSwingTwist(swingX, swingY, twistAngle);
148
149 RealType dVdtwist, dVdswingX, dVdswingY;
150 RealType dTwist, dSwingX, dSwingY;
151 RealType p;
152
153 if (restType_ & rtTwist){
154 dTwist = twistAngle - twist0_;
155 /// dVdtwist = kTwist_ * sin(dTwist) ;
156 /// p = kTwist_ * (1.0 - cos(dTwist) ) ;
157 dVdtwist = kTwist_ * dTwist;
158 p = 0.5 * kTwist_ * dTwist * dTwist;
159 pot_ += p;
160 tBody -= dVdtwist * V3Z;
161 if (printRest_) restInfo_[rtTwist] = std::make_pair(twistAngle, p);
162 }
163
164 if (restType_ & rtSwingX){
165 dSwingX = swingX - swingX0_;
166 /// dVdswingX = kSwingX_ * 2.0 * sin(2.0 * dSwingX);
167 /// p = kSwingX_ * (1.0 - cos(2.0 * dSwingX));
168 dVdswingX = kSwingX_ * dSwingX;
169 p = 0.5 * kSwingX_ * dSwingX * dSwingX;
170 pot_ += p;
171 tBody -= dVdswingX * V3X;
172 if (printRest_) restInfo_[rtSwingX] = std::make_pair(swingX, p);
173 }
174 if (restType_ & rtSwingY){
175 dSwingY = swingY - swingY0_;
176 /// dVdswingY = kSwingY_ * 2.0 * sin(2.0 * dSwingY);
177 /// p = kSwingY_ * (1.0 - cos(2.0 * dSwingY));
178 dVdswingY = kSwingY_ * dSwingY;
179 p = 0.5 * kSwingX_ * dSwingY * dSwingY;
180 pot_ += p;
181 tBody -= dVdswingY * V3Y;
182 if (printRest_) restInfo_[rtSwingY] = std::make_pair(swingY, p);
183 }
184
185
186 RealType t2 = dot(tBody, tBody);
187
188 Vector3d rLab, rBody, txr, fBody, fLab;
189
190 for (unsigned int i = 0; i < struc.size(); i++) {
191
192 rLab = struc[i];
193 rBody = A * rLab;
194
195 txr = cross(tBody, rBody);
196 fBody = txr * t2;
197 fLab = Atrans * fBody;
198 fLab *= scaleFactor_;
199
200 forces_[i] += fLab;
201 }
202
203 // test the force vectors and see if it is the right orientation
204 // std::cout << struc.size() << std::endl << std::endl;
205 // for (int i = 0; i != struc.size(); ++i){
206 // std::cout << "H\t" << struc[i].x() << "\t" << struc[i].y() << "\t" << struc[i].z() << "\t";
207 // std::cout << forces_[i].x() << "\t" << forces_[i].y() << "\t" << forces_[i].z() << std::endl;
208 // }
209 }
210 }
211 }

Properties

Name Value
svn:keywords Author Id Revision Date