--- trunk/src/primitives/Inversion.cpp 2009/11/25 20:02:06 1390 +++ trunk/src/primitives/Inversion.cpp 2015/03/05 15:35:37 2067 @@ -35,30 +35,42 @@ * * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). - * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). - * [4] Vardeman & Gezelter, in progress (2009). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ +#include "config.h" +#include + #include "primitives/Inversion.hpp" namespace OpenMD { Inversion::Inversion(Atom *atom1, Atom *atom2, Atom *atom3, - Atom *atom4, InversionType *it) : - atom1_(atom1), atom2_(atom2), atom3_(atom3), atom4_(atom4), - inversionType_(it) { } + Atom *atom4, InversionType *it) : + ShortRangeInteraction(), inversionType_(it) { + + atoms_.resize(4); + atoms_[0] = atom1; + atoms_[1] = atom2; + atoms_[2] = atom3; + atoms_[3] = atom4; + + inversionKey_ = inversionType_->getKey(); + } - void Inversion::calcForce(RealType& angle) { + void Inversion::calcForce(RealType& angle, bool doParticlePot) { // In OpenMD's version of an inversion, the central atom // comes first. However, to get the planarity in a typical cosine // version of this potential (i.e. Amber-style), the central atom // is treated as atom *3* in a standard torsion form: - Vector3d pos1 = atom2_->getPos(); - Vector3d pos2 = atom3_->getPos(); - Vector3d pos3 = atom1_->getPos(); - Vector3d pos4 = atom4_->getPos(); + Vector3d pos1 = atoms_[1]->getPos(); + Vector3d pos2 = atoms_[2]->getPos(); + Vector3d pos3 = atoms_[0]->getPos(); + Vector3d pos4 = atoms_[3]->getPos(); Vector3d r31 = pos1 - pos3; Vector3d r23 = pos3 - pos2; @@ -69,12 +81,9 @@ namespace OpenMD { RealType rA = A.length(); Vector3d B = cross(r43, r23); RealType rB = B.length(); - //Vector3d C = cross(r23, A); - //RealType rC = C.length(); A.normalize(); B.normalize(); - //C.normalize(); // Calculate the sin and cos RealType cos_phi = dot(A, B) ; @@ -82,7 +91,22 @@ namespace OpenMD { if (cos_phi < -1.0) cos_phi = -1.0; RealType dVdcosPhi; - inversionType_->calcForce(cos_phi, potential_, dVdcosPhi); + switch (inversionKey_) { + case itCosAngle: + inversionType_->calcForce(cos_phi, potential_, dVdcosPhi); + break; + case itAngle: + RealType phi = acos(cos_phi); + RealType dVdPhi; + inversionType_->calcForce(phi, potential_, dVdPhi); + RealType sin_phi = sqrt(1.0 - cos_phi * cos_phi); + if (fabs(sin_phi) < 1.0E-6) { + sin_phi = 1.0E-6; + } + dVdcosPhi = dVdPhi / sin_phi; + break; + } + Vector3d f1 ; Vector3d f2 ; Vector3d f3 ; @@ -104,16 +128,18 @@ namespace OpenMD { // Confusing enough? Good. - atom2_->addFrc(f1); - atom1_->addFrc(f2 - f1 + f3); - atom4_->addFrc(-f2); - atom3_->addFrc(-f3); + atoms_[1]->addFrc(f1); + atoms_[0]->addFrc(f2 - f1 + f3); + atoms_[3]->addFrc(-f2); + atoms_[2]->addFrc(-f3); - atom1_->addParticlePot(potential_); - atom2_->addParticlePot(potential_); - atom3_->addParticlePot(potential_); - atom4_->addParticlePot(potential_); - + if (doParticlePot) { + atoms_[0]->addParticlePot(potential_); + atoms_[1]->addParticlePot(potential_); + atoms_[2]->addParticlePot(potential_); + atoms_[3]->addParticlePot(potential_); + } + angle = acos(cos_phi) /M_PI * 180.0; }