| 1 |
#include <cstring> |
| 2 |
#include "AtomVisitor.hpp" |
| 3 |
#include "DirectionalAtom.hpp" |
| 4 |
#include "MatVec3.h" |
| 5 |
#include "RigidBody.hpp" |
| 6 |
|
| 7 |
void BaseAtomVisitor::visit(RigidBody* rb){ |
| 8 |
//vector<Atom*> myAtoms; |
| 9 |
//vector<Atom*>::iterator atomIter; |
| 10 |
|
| 11 |
//myAtoms = rb->getAtoms(); |
| 12 |
|
| 13 |
//for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter) |
| 14 |
// (*atomIter)->accept(this); |
| 15 |
} |
| 16 |
|
| 17 |
void BaseAtomVisitor::setVisited(Atom* atom){ |
| 18 |
GenericData* data; |
| 19 |
data = atom->getProperty("VISITED"); |
| 20 |
|
| 21 |
//if visited property is not existed, add it as new property |
| 22 |
if(data == NULL){ |
| 23 |
data = new GenericData(); |
| 24 |
data->setID("VISITED"); |
| 25 |
atom->addProperty(data); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
bool BaseAtomVisitor::isVisited(Atom* atom){ |
| 30 |
GenericData* data; |
| 31 |
data = atom->getProperty("VISITED"); |
| 32 |
return data == NULL ? false : true; |
| 33 |
} |
| 34 |
|
| 35 |
void SSDAtomVisitor::visit(DirectionalAtom* datom){ |
| 36 |
|
| 37 |
vector<AtomInfo*> atoms; |
| 38 |
|
| 39 |
//we need to convert SSD into 4 differnet atoms |
| 40 |
//one oxygen atom, two hydrogen atoms and one pseudo atom which is the center of the mass |
| 41 |
//of the water with a dipole moment |
| 42 |
double h1[3] = {0.0, -0.75695, 0.5206}; |
| 43 |
double h2[3] = {0.0, 0.75695, 0.5206}; |
| 44 |
double ox[3] = {0.0, 0.0, -0.0654}; |
| 45 |
double u[3] = {0, 0, 1}; |
| 46 |
double rotMatrix[3][3]; |
| 47 |
AtomInfo* atomInfo; |
| 48 |
double pos[3]; |
| 49 |
double vel[3]; |
| 50 |
double newVec[3]; |
| 51 |
double q[4]; |
| 52 |
AtomData* atomData; |
| 53 |
GenericData* data; |
| 54 |
bool haveAtomData; |
| 55 |
|
| 56 |
//if atom is not SSD atom, just skip it |
| 57 |
if(!strcmp(datom->getType(), "SSD")) |
| 58 |
return; |
| 59 |
|
| 60 |
data = datom->getProperty("ATOMDATA"); |
| 61 |
if(data != NULL){ |
| 62 |
|
| 63 |
atomData = dynamic_cast<AtomData*>(data); |
| 64 |
if(atomData == NULL){ |
| 65 |
cerr << "can not get Atom Data from " << datom->getType() << endl; |
| 66 |
atomData = new AtomData; |
| 67 |
haveAtomData = false; |
| 68 |
} |
| 69 |
else |
| 70 |
haveAtomData = true; |
| 71 |
} |
| 72 |
else{ |
| 73 |
atomData = new AtomData; |
| 74 |
haveAtomData = false; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
datom->getPos(pos); |
| 79 |
datom->getQ(q); |
| 80 |
datom->getA(rotMatrix); |
| 81 |
|
| 82 |
//center of mass of the water molecule |
| 83 |
matVecMul3(rotMatrix, u, newVec); |
| 84 |
atomInfo = new AtomInfo; |
| 85 |
atomInfo->AtomType = "X"; |
| 86 |
atomInfo->pos[0] = pos[0]; |
| 87 |
atomInfo->pos[1] = pos[1]; |
| 88 |
atomInfo->pos[2] = pos[2]; |
| 89 |
atomInfo->dipole[0] = newVec[0]; |
| 90 |
atomInfo->dipole[1] = newVec[1]; |
| 91 |
atomInfo->dipole[2] = newVec[2]; |
| 92 |
|
| 93 |
atomData->addAtomInfo(atomInfo); |
| 94 |
|
| 95 |
//oxygen |
| 96 |
matVecMul3(rotMatrix, ox, newVec); |
| 97 |
atomInfo = new AtomInfo; |
| 98 |
atomInfo->AtomType = "O"; |
| 99 |
atomInfo->pos[0] = pos[0] + newVec[0]; |
| 100 |
atomInfo->pos[1] = pos[1] + newVec[1]; |
| 101 |
atomInfo->pos[2] = pos[2] + newVec[2]; |
| 102 |
atomInfo->dipole[0] = 0.0; |
| 103 |
atomInfo->dipole[1] = 0.0; |
| 104 |
atomInfo->dipole[2] = 0.0; |
| 105 |
atomData->addAtomInfo(atomInfo); |
| 106 |
|
| 107 |
|
| 108 |
//hydrogen1 |
| 109 |
matVecMul3(rotMatrix, h1, newVec); |
| 110 |
atomInfo = new AtomInfo; |
| 111 |
atomInfo->AtomType = "H"; |
| 112 |
atomInfo->pos[0] = pos[0] + newVec[0]; |
| 113 |
atomInfo->pos[1] = pos[1] + newVec[1]; |
| 114 |
atomInfo->pos[2] = pos[2] + newVec[2]; |
| 115 |
atomInfo->dipole[0] = 0.0; |
| 116 |
atomInfo->dipole[1] = 0.0; |
| 117 |
atomInfo->dipole[2] = 0.0; |
| 118 |
atomData->addAtomInfo(atomInfo); |
| 119 |
|
| 120 |
//hydrogen2 |
| 121 |
matVecMul3(rotMatrix, h2, newVec); |
| 122 |
atomInfo = new AtomInfo; |
| 123 |
atomInfo->AtomType = "H"; |
| 124 |
atomInfo->pos[0] = pos[0] + newVec[0]; |
| 125 |
atomInfo->pos[1] = pos[1] + newVec[1]; |
| 126 |
atomInfo->pos[2] = pos[2] + newVec[2]; |
| 127 |
atomInfo->dipole[0] = 0.0; |
| 128 |
atomInfo->dipole[1] = 0.0; |
| 129 |
atomInfo->dipole[2] = 0.0; |
| 130 |
atomData->addAtomInfo(atomInfo); |
| 131 |
|
| 132 |
//add atom data into atom's property |
| 133 |
|
| 134 |
if(!haveAtomData){ |
| 135 |
atomData->setID("ATOMDATA"); |
| 136 |
datom->addProperty(atomData); |
| 137 |
} |
| 138 |
|
| 139 |
setVisited(datom); |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
void DefaultAtomVisitor::visit(Atom* atom){ |
| 144 |
AtomData* atomData; |
| 145 |
AtomInfo* atomInfo; |
| 146 |
double pos[3]; |
| 147 |
|
| 148 |
if(isVisited(atom)) |
| 149 |
return; |
| 150 |
|
| 151 |
atomInfo =new AtomInfo; |
| 152 |
|
| 153 |
atomData = new AtomData; |
| 154 |
atomData->setID("ATOMDATA"); |
| 155 |
|
| 156 |
atom->getPos(pos); |
| 157 |
atomInfo->AtomType = atom->getType(); |
| 158 |
atomInfo->pos[0] = pos[0]; |
| 159 |
atomInfo->pos[1] = pos[1]; |
| 160 |
atomInfo->pos[2] = pos[2]; |
| 161 |
atomInfo->dipole[0] = 0.0; |
| 162 |
atomInfo->dipole[1] = 0.0; |
| 163 |
atomInfo->dipole[2] = 0.0; |
| 164 |
|
| 165 |
|
| 166 |
atomData->addAtomInfo(atomInfo); |
| 167 |
|
| 168 |
atom->addProperty(atomData); |
| 169 |
|
| 170 |
setVisited(atom); |
| 171 |
} |
| 172 |
void DefaultAtomVisitor::visit(DirectionalAtom* datom){ |
| 173 |
AtomData* atomData; |
| 174 |
AtomInfo* atomInfo; |
| 175 |
double pos[3]; |
| 176 |
double u[3]; |
| 177 |
|
| 178 |
if(isVisited(datom)) |
| 179 |
return; |
| 180 |
|
| 181 |
datom->getPos(pos); |
| 182 |
datom->getU(u); |
| 183 |
|
| 184 |
atomData = new AtomData; |
| 185 |
atomData->setID("ATOMDATA"); |
| 186 |
atomInfo =new AtomInfo; |
| 187 |
|
| 188 |
atomInfo->AtomType = datom->getType(); |
| 189 |
atomInfo->pos[0] = pos[0]; |
| 190 |
atomInfo->pos[1] = pos[1]; |
| 191 |
atomInfo->pos[2] = pos[2]; |
| 192 |
atomInfo->dipole[0] = u[0]; |
| 193 |
atomInfo->dipole[1] = u[1]; |
| 194 |
atomInfo->dipole[2] = u[2]; |
| 195 |
|
| 196 |
atomData->addAtomInfo(atomInfo); |
| 197 |
|
| 198 |
datom->addProperty(atomData); |
| 199 |
|
| 200 |
setVisited(datom); |
| 201 |
} |
| 202 |
|