45#include "utils/MoLocator.hpp"
51#include "types/AtomType.hpp"
52#include "utils/simError.h"
55 MoLocator::MoLocator(MoleculeStamp* theStamp, ForceField* theFF) {
58 nIntegrableObjects = myStamp->getNIntegrable();
62 void MoLocator::placeMol(
const Vector3d& offset,
const Vector3d& ort,
66 RotMat3x3d rotMat = latVec2RotMat(ort);
68 if (mol->getNIntegrableObjects() != nIntegrableObjects) {
69 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
70 "MoLocator::placeMol error.\n"
71 "\tThe number of integrable objects of MoleculeStamp is not\n"
72 "\tthe same as that of Molecule\n");
77 Molecule::IntegrableObjectIterator ii;
80 for (sd = mol->beginIntegrableObject(ii), i = 0; sd != NULL;
81 sd = mol->nextIntegrableObject(ii), ++i) {
82 newCoor = rotMat * refCoords[i];
88 if (sd->isDirectional()) {
89 sd->setA(rotMat * sd->getA());
95 void MoLocator::calcRef(
void) {
96 AtomStamp* currAtomStamp;
97 RigidBodyStamp* rbStamp;
98 std::vector<RealType> mass;
101 RealType totMassInRb;
102 RealType currAtomMass;
105 std::size_t nAtoms = myStamp->getNAtoms();
106 std::size_t nRigidBodies = myStamp->getNRigidBodies();
108 for (std::size_t i = 0; i < nAtoms; i++) {
109 currAtomStamp = myStamp->getAtomStamp(i);
111 if (!currAtomStamp->havePosition()) {
112 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
113 "MoLocator::calcRef error.\n"
114 "\tComponent %s, atom %s does not have a position specified.\n"
115 "\tThis means MoLocator cannot initalize it's position.\n",
116 myStamp->getName().c_str(), currAtomStamp->getType().c_str());
118 painCave.isFatal = 1;
123 if (myStamp->isAtomInRigidBody(i))
continue;
126 currAtomMass = getAtomMass(currAtomStamp->getType(), myFF);
127 mass.push_back(currAtomMass);
128 coor.x() = currAtomStamp->getPosX();
129 coor.y() = currAtomStamp->getPosY();
130 coor.z() = currAtomStamp->getPosZ();
131 refCoords.push_back(coor);
135 for (std::size_t i = 0; i < nRigidBodies; i++) {
136 rbStamp = myStamp->getRigidBodyStamp(i);
137 std::size_t nAtomsInRb = rbStamp->getNMembers();
144 for (std::size_t j = 0; j < nAtomsInRb; j++) {
145 currAtomStamp = myStamp->getAtomStamp(rbStamp->getMemberAt(j));
146 currAtomMass = getAtomMass(currAtomStamp->getType(), myFF);
147 totMassInRb += currAtomMass;
149 coor.x() += currAtomStamp->getPosX() * currAtomMass;
150 coor.y() += currAtomStamp->getPosY() * currAtomMass;
151 coor.z() += currAtomStamp->getPosZ() * currAtomMass;
154 mass.push_back(totMassInRb);
156 refCoords.push_back(coor);
165 for (std::size_t i = 0; i < nIntegrableObjects; i++) {
166 refMolCom += refCoords[i] * mass[i];
170 refMolCom /= molMass;
174 for (std::size_t i = 0; i < nIntegrableObjects; i++)
175 refCoords[i] -= refMolCom;
178 RealType MoLocator::getAtomMass(
const std::string& at, ForceField* myFF) {
180 AtomType* atomType = myFF->getAtomType(at);
181 if (atomType != NULL) {
182 mass = atomType->getMass();
185 std::cerr <<
"Can not find AtomType: " << at << std::endl;
190 RealType MoLocator::getMolMass(MoleculeStamp* molStamp, ForceField* myFF) {
192 RealType totMass = 0;
193 nAtoms = molStamp->getNAtoms();
195 for (std::size_t i = 0; i < nAtoms; i++) {
196 AtomStamp* currAtomStamp = molStamp->getAtomStamp(i);
197 totMass += getAtomMass(currAtomStamp->getType(), myFF);
202 RotMat3x3d MoLocator::latVec2RotMat(
const Vector3d& lv) {
203 RealType theta = acos(lv[2]);
204 RealType phi = atan2(lv[1], lv[0]);
207 return RotMat3x3d(phi, theta, psi);
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.