--- trunk/src/primitives/Bend.cpp 2006/05/17 21:51:42 963 +++ trunk/src/primitives/Bend.cpp 2008/01/23 16:38:22 1211 @@ -42,60 +42,58 @@ namespace oopse { #include "primitives/Bend.hpp" namespace oopse { - + /**@todo still a lot left to improve*/ void Bend::calcForce(RealType& angle) { Vector3d pos1 = atom1_->getPos(); Vector3d pos2 = atom2_->getPos(); Vector3d pos3 = atom3_->getPos(); - + Vector3d r21 = pos1 - pos2; RealType d21 = r21.length(); - + RealType d21inv = 1.0 / d21; - + Vector3d r23 = pos3 - pos2; RealType d23 = r23.length(); - + RealType d23inv = 1.0 / d23; - + RealType cosTheta = dot(r21, r23) / (d21 * d23); - + //check roundoff if (cosTheta > 1.0) { cosTheta = 1.0; } else if (cosTheta < -1.0) { cosTheta = -1.0; } - + RealType theta = acos(cosTheta); - + RealType dVdTheta; bendType_->calcForce(theta, potential_, dVdTheta); - //std::cout << atom1_->getType() << "\t" << atom2_->getType() << "\t" << atom3_->getType() << "\t"; - //std::cout << "theta = " << theta/M_PI * 180.0 <<", potential = " << potential_ << std::endl; - + RealType sinTheta = sqrt(1.0 - cosTheta * cosTheta); - + if (fabs(sinTheta) < 1.0E-6) { sinTheta = 1.0E-6; } - + RealType commonFactor1 = dVdTheta / sinTheta * d21inv; RealType commonFactor2 = dVdTheta / sinTheta * d23inv; - + Vector3d force1 = commonFactor1 * (r23 * d23inv - r21*d21inv*cosTheta); Vector3d force3 = commonFactor2 * (r21 * d21inv - r23*d23inv*cosTheta); - //total force in current bend is zero + // Total force in current bend is zero Vector3d force2 = force1 + force3; force2 *= -1.0; - + atom1_->addFrc(force1); atom2_->addFrc(force2); atom3_->addFrc(force3); - + angle = theta /M_PI * 180.0; }