61 assert(struc.size() == ref_.size());
63 std::vector<Vector3d>::iterator it;
67 for (it = forces_.begin(); it != forces_.end(); ++it)
70 if (restType_ & rtDisplacement) {
71 Vector3d del = molCom - refCom_;
74 RealType p = 0.5 * kDisp_ * r * r;
78 if (printRest_) restInfo_[rtDisplacement] = std::make_pair(r, p);
80 for (it = forces_.begin(); it != forces_.end(); ++it)
81 (*it) += -kDisp_ * del * scaleFactor_;
84 if (restType_ & rtDisplacementX) {
85 Vector3d del = molCom - refCom_;
88 RealType p = 0.5 * kDispX_ * r * r;
92 if (printRest_) restInfo_[rtDisplacementX] = std::make_pair(r, p);
94 for (it = forces_.begin(); it != forces_.end(); ++it)
95 (*it) += -kDispX_ * r * V3X * scaleFactor_;
98 if (restType_ & rtDisplacementY) {
99 Vector3d del = molCom - refCom_;
101 RealType r = del.
y();
102 RealType p = 0.5 * kDispY_ * r * r;
106 if (printRest_) restInfo_[rtDisplacementY] = std::make_pair(r, p);
108 for (it = forces_.begin(); it != forces_.end(); ++it)
109 (*it) += -kDispY_ * r * V3Y * scaleFactor_;
112 if (restType_ & rtDisplacementZ) {
113 Vector3d del = molCom - refCom_;
115 RealType r = del.
z();
116 RealType p = 0.5 * kDispZ_ * r * r;
120 if (printRest_) restInfo_[rtDisplacementZ] = std::make_pair(r, p);
122 for (it = forces_.begin(); it != forces_.end(); ++it)
123 (*it) += -kDispZ_ * r * V3Z * scaleFactor_;
126 if (restType_ & rtAbsoluteZ) {
127 RealType r = molCom(2) - posZ0_;
128 RealType p = 0.5 * kAbs_ * r * r;
129 Vector3d frc = Vector3d(0.0, 0.0, -kAbs_ * r);
133 if (printRest_) restInfo_[rtAbsoluteZ] = std::make_pair(r, p);
135 for (it = forces_.begin(); it != forces_.end(); ++it)
136 (*it) += frc * scaleFactor_;
141 if (restType_ >= 32) {
146 for (
unsigned int n = 0; n < struc.size(); n++) {
158 R += outProduct(struc[n], ref_[n]);
170 Rtmp.setSubMatrix(0, 0, R);
184 vtmp.getSubMatrix(0, 0, v);
185 stmp.getSubVector(0, s);
186 wtmp.getSubMatrix(0, 0, w_tr);
196 RotMat3x3d Atrans = v * w_tr.transpose();
197 RotMat3x3d A = Atrans.transpose();
202 RealType swingX, swingY;
204 quat.toTwistSwing(twistAngle, swingX, swingY);
206 RealType dVdtwist, dVdswingX, dVdswingY;
207 RealType dTwist, dSwingX, dSwingY;
210 if (restType_ & rtTwist) {
211 dTwist = twistAngle - twist0_;
214 dVdtwist = kTwist_ * dTwist;
215 p = 0.5 * kTwist_ * dTwist * dTwist;
217 tBody -= dVdtwist * V3Z;
218 if (printRest_) restInfo_[rtTwist] = std::make_pair(twistAngle, p);
221 if (restType_ & rtSwingX) {
222 dSwingX = swingX - swingX0_;
225 dVdswingX = kSwingX_ * dSwingX;
226 p = 0.5 * kSwingX_ * dSwingX * dSwingX;
228 tBody -= dVdswingX * V3X;
229 if (printRest_) restInfo_[rtSwingX] = std::make_pair(swingX, p);
231 if (restType_ & rtSwingY) {
232 dSwingY = swingY - swingY0_;
235 dVdswingY = kSwingY_ * dSwingY;
236 p = 0.5 * kSwingX_ * dSwingY * dSwingY;
238 tBody -= dVdswingY * V3Y;
239 if (printRest_) restInfo_[rtSwingY] = std::make_pair(swingY, p);
242 RealType t2 =
dot(tBody, tBody);
244 Vector3d rLab, rBody, txr, fBody, fLab;
246 for (
unsigned int i = 0; i < struc.size(); i++) {
250 txr =
cross(tBody, rBody);
252 fLab = Atrans * fBody;
253 fLab *= scaleFactor_;