48#include "utils/MoLocator.hpp"
54#include "types/AtomType.hpp"
55#include "utils/simError.h"
61 nIntegrableObjects = myStamp->getNIntegrable();
65 void MoLocator::placeMol(
const Vector3d& offset,
const Vector3d& ort,
69 RotMat3x3d rotMat = latVec2RotMat(ort);
71 if (mol->getNIntegrableObjects() != nIntegrableObjects) {
72 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
73 "MoLocator::placeMol error.\n"
74 "\tThe number of integrable objects of MoleculeStamp is not\n"
75 "\tthe same as that of Molecule\n");
80 Molecule::IntegrableObjectIterator ii;
83 for (sd = mol->beginIntegrableObject(ii), i = 0; sd != NULL;
84 sd = mol->nextIntegrableObject(ii), ++i) {
85 newCoor = rotMat * refCoords[i];
91 if (sd->isDirectional()) {
92 sd->setA(rotMat * sd->getA());
98 void MoLocator::calcRef(
void) {
99 AtomStamp* currAtomStamp;
100 RigidBodyStamp* rbStamp;
101 std::vector<RealType> mass;
104 RealType totMassInRb;
105 RealType currAtomMass;
108 std::size_t nAtoms = myStamp->getNAtoms();
109 std::size_t nRigidBodies = myStamp->getNRigidBodies();
111 for (std::size_t i = 0; i < nAtoms; i++) {
112 currAtomStamp = myStamp->getAtomStamp(i);
114 if (!currAtomStamp->havePosition()) {
115 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
116 "MoLocator::calcRef error.\n"
117 "\tComponent %s, atom %s does not have a position specified.\n"
118 "\tThis means MoLocator cannot initalize it's position.\n",
119 myStamp->getName().c_str(), currAtomStamp->getType().c_str());
121 painCave.isFatal = 1;
126 if (myStamp->isAtomInRigidBody(i))
continue;
129 currAtomMass = getAtomMass(currAtomStamp->getType(), myFF);
130 mass.push_back(currAtomMass);
131 coor.x() = currAtomStamp->getPosX();
132 coor.y() = currAtomStamp->getPosY();
133 coor.z() = currAtomStamp->getPosZ();
134 refCoords.push_back(coor);
138 for (std::size_t i = 0; i < nRigidBodies; i++) {
139 rbStamp = myStamp->getRigidBodyStamp(i);
140 std::size_t nAtomsInRb = rbStamp->getNMembers();
147 for (std::size_t j = 0; j < nAtomsInRb; j++) {
148 currAtomStamp = myStamp->getAtomStamp(rbStamp->getMemberAt(j));
149 currAtomMass = getAtomMass(currAtomStamp->getType(), myFF);
150 totMassInRb += currAtomMass;
152 coor.x() += currAtomStamp->getPosX() * currAtomMass;
153 coor.y() += currAtomStamp->getPosY() * currAtomMass;
154 coor.z() += currAtomStamp->getPosZ() * currAtomMass;
157 mass.push_back(totMassInRb);
159 refCoords.push_back(coor);
168 for (std::size_t i = 0; i < nIntegrableObjects; i++) {
169 refMolCom += refCoords[i] * mass[i];
173 refMolCom /= molMass;
177 for (std::size_t i = 0; i < nIntegrableObjects; i++)
178 refCoords[i] -= refMolCom;
181 RealType MoLocator::getAtomMass(
const std::string& at,
ForceField* myFF) {
183 AtomType* atomType = myFF->getAtomType(at);
184 if (atomType != NULL) {
185 mass = atomType->getMass();
188 std::cerr <<
"Can not find AtomType: " << at << std::endl;
195 RealType totMass = 0;
196 nAtoms = molStamp->getNAtoms();
198 for (std::size_t i = 0; i < nAtoms; i++) {
199 AtomStamp* currAtomStamp = molStamp->getAtomStamp(i);
200 totMass += getAtomMass(currAtomStamp->getType(), myFF);
205 RotMat3x3d MoLocator::latVec2RotMat(
const Vector3d& lv) {
206 RealType theta = acos(lv[2]);
207 RealType phi = atan2(lv[1], lv[0]);
210 return RotMat3x3d(phi, theta, psi);
Real & x()
Returns reference of the first element of Vector3.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.