42 |
|
#include <cstring> |
43 |
|
#include "visitors/AtomVisitor.hpp" |
44 |
|
#include "primitives/DirectionalAtom.hpp" |
45 |
– |
#include "math/MatVec3.h" |
45 |
|
#include "primitives/RigidBody.hpp" |
46 |
|
|
47 |
|
namespace oopse { |
74 |
|
} |
75 |
|
|
76 |
|
bool SSDAtomVisitor::isSSDAtom(const std::string&atomType) { |
77 |
< |
std::vector<std::string>::iterator strIter; |
78 |
< |
|
79 |
< |
for( strIter = ssdAtomType.begin(); strIter != ssdAtomType.end(); |
81 |
< |
++strIter ) |
82 |
< |
if (*strIter == atomType) |
83 |
< |
return true; |
84 |
< |
|
85 |
< |
return false; |
77 |
> |
std::set<std::string>::iterator strIter; |
78 |
> |
strIter = ssdAtomType.find(atomType); |
79 |
> |
return strIter != ssdAtomType.end() ? true : false; |
80 |
|
} |
81 |
|
|
82 |
|
void SSDAtomVisitor::visit(DirectionalAtom *datom) { |
83 |
< |
std::vector<AtomInfo *>atoms; |
83 |
> |
std::vector<AtomInfo*>atoms; |
84 |
|
|
85 |
|
//we need to convert SSD into 4 differnet atoms |
86 |
|
//one oxygen atom, two hydrogen atoms and one pseudo atom which is the center of the mass |
214 |
|
return result; |
215 |
|
} |
216 |
|
|
217 |
< |
bool LinearAtomVisitor::isLinearAtom(const string& atomType){ |
218 |
< |
vector<string>::iterator strIter; |
219 |
< |
|
220 |
< |
for(strIter = linearAtomType.begin(); strIter != linearAtomType.end(); |
221 |
< |
++strIter) |
228 |
< |
if(*strIter == atomType) |
229 |
< |
return true; |
230 |
< |
|
231 |
< |
return false; |
217 |
> |
bool LinearAtomVisitor::isLinearAtom(const std::string& atomType){ |
218 |
> |
std::set<std::string>::iterator strIter; |
219 |
> |
strIter = linearAtomType.find(atomType); |
220 |
> |
|
221 |
> |
return strIter != linearAtomType.end() ? true : false; |
222 |
|
} |
223 |
|
|
224 |
|
void LinearAtomVisitor::visit(DirectionalAtom* datom){ |
225 |
+ |
std::vector<AtomInfo*> atoms; |
226 |
+ |
//we need to convert linear into 4 different atoms |
227 |
+ |
Vector3d c1(0.0, 0.0, -1.8); |
228 |
+ |
Vector3d c2(0.0, 0.0, -0.6); |
229 |
+ |
Vector3d c3(0.0, 0.0, 0.6); |
230 |
+ |
Vector3d c4(0.0, 0.0, 1.8); |
231 |
+ |
RotMat3x3d rotMatrix; |
232 |
+ |
RotMat3x3d rotTrans; |
233 |
+ |
AtomInfo* atomInfo; |
234 |
+ |
Vector3d pos; |
235 |
+ |
Vector3d newVec; |
236 |
+ |
Quat4d q; |
237 |
+ |
AtomData* atomData; |
238 |
+ |
GenericData* data; |
239 |
+ |
bool haveAtomData; |
240 |
|
|
241 |
< |
vector<AtomInfo*> atoms; |
241 |
> |
//if atom is not SSD atom, just skip it |
242 |
> |
if(!isLinearAtom(datom->getType())) |
243 |
> |
return; |
244 |
|
|
245 |
< |
//we need to convert linear into 4 different atoms |
246 |
< |
double c1[3] = {0.0, 0.0, -1.8}; |
247 |
< |
double c2[3] = {0.0, 0.0, -0.6}; |
248 |
< |
double c3[3] = {0.0, 0.0, 0.6}; |
249 |
< |
double c4[3] = {0.0, 0.0, 1.8}; |
250 |
< |
double rotMatrix[3][3]; |
251 |
< |
double rotTrans[3][3]; |
252 |
< |
AtomInfo* atomInfo; |
253 |
< |
double pos[3]; |
254 |
< |
double newVec[3]; |
255 |
< |
double q[4]; |
256 |
< |
AtomData* atomData; |
257 |
< |
GenericData* data; |
251 |
< |
bool haveAtomData; |
252 |
< |
|
253 |
< |
//if atom is not SSD atom, just skip it |
254 |
< |
if(!isLinearAtom(datom->getType())) |
255 |
< |
return; |
256 |
< |
|
257 |
< |
data = datom->getProperty("ATOMDATA"); |
258 |
< |
if(data != NULL){ |
259 |
< |
|
260 |
< |
atomData = dynamic_cast<AtomData*>(data); |
261 |
< |
if(atomData == NULL){ |
262 |
< |
cerr << "can not get Atom Data from " << datom->getType() << endl; |
263 |
< |
atomData = new AtomData; |
264 |
< |
haveAtomData = false; |
245 |
> |
data = datom->getPropertyByName("ATOMDATA"); |
246 |
> |
if(data != NULL){ |
247 |
> |
atomData = dynamic_cast<AtomData*>(data); |
248 |
> |
if(atomData == NULL){ |
249 |
> |
std::cerr << "can not get Atom Data from " << datom->getType() << std::endl; |
250 |
> |
atomData = new AtomData; |
251 |
> |
haveAtomData = false; |
252 |
> |
} else { |
253 |
> |
haveAtomData = true; |
254 |
> |
} |
255 |
> |
} else { |
256 |
> |
atomData = new AtomData; |
257 |
> |
haveAtomData = false; |
258 |
|
} |
266 |
– |
else |
267 |
– |
haveAtomData = true; |
268 |
– |
} |
269 |
– |
else{ |
270 |
– |
atomData = new AtomData; |
271 |
– |
haveAtomData = false; |
272 |
– |
} |
259 |
|
|
260 |
|
|
261 |
< |
datom->getPos(pos); |
262 |
< |
datom->getQ(q); |
263 |
< |
datom->getA(rotMatrix); |
261 |
> |
pos = datom->getPos(); |
262 |
> |
q = datom->getQ(); |
263 |
> |
rotMatrix = datom->getA(); |
264 |
|
|
265 |
< |
// We need A^T to convert from body-fixed to space-fixed: |
266 |
< |
transposeMat3(rotMatrix, rotTrans); |
281 |
< |
|
282 |
< |
matVecMul3(rotTrans, c1, newVec); |
283 |
< |
atomInfo = new AtomInfo; |
284 |
< |
atomInfo->AtomType = "C"; |
285 |
< |
atomInfo->pos[0] = pos[0] + newVec[0]; |
286 |
< |
atomInfo->pos[1] = pos[1] + newVec[1]; |
287 |
< |
atomInfo->pos[2] = pos[2] + newVec[2]; |
288 |
< |
atomInfo->dipole[0] = 0.0; |
289 |
< |
atomInfo->dipole[1] = 0.0; |
290 |
< |
atomInfo->dipole[2] = 0.0; |
291 |
< |
atomData->addAtomInfo(atomInfo); |
265 |
> |
// We need A^T to convert from body-fixed to space-fixed: |
266 |
> |
rotTrans = rotMatrix.transpose(); |
267 |
|
|
268 |
< |
matVecMul3(rotTrans, c2, newVec); |
269 |
< |
atomInfo = new AtomInfo; |
270 |
< |
atomInfo->AtomType = "C"; |
271 |
< |
atomInfo->pos[0] = pos[0] + newVec[0]; |
272 |
< |
atomInfo->pos[1] = pos[1] + newVec[1]; |
273 |
< |
atomInfo->pos[2] = pos[2] + newVec[2]; |
274 |
< |
atomInfo->dipole[0] = 0.0; |
275 |
< |
atomInfo->dipole[1] = 0.0; |
276 |
< |
atomInfo->dipole[2] = 0.0; |
277 |
< |
atomData->addAtomInfo(atomInfo); |
268 |
> |
newVec = rotTrans * c1; |
269 |
> |
atomInfo = new AtomInfo; |
270 |
> |
atomInfo->AtomType = "C"; |
271 |
> |
atomInfo->pos[0] = pos[0] + newVec[0]; |
272 |
> |
atomInfo->pos[1] = pos[1] + newVec[1]; |
273 |
> |
atomInfo->pos[2] = pos[2] + newVec[2]; |
274 |
> |
atomInfo->dipole[0] = 0.0; |
275 |
> |
atomInfo->dipole[1] = 0.0; |
276 |
> |
atomInfo->dipole[2] = 0.0; |
277 |
> |
atomData->addAtomInfo(atomInfo); |
278 |
|
|
279 |
< |
matVecMul3(rotTrans, c3, newVec); |
280 |
< |
atomInfo = new AtomInfo; |
281 |
< |
atomInfo->AtomType = "C"; |
282 |
< |
atomInfo->pos[0] = pos[0] + newVec[0]; |
283 |
< |
atomInfo->pos[1] = pos[1] + newVec[1]; |
284 |
< |
atomInfo->pos[2] = pos[2] + newVec[2]; |
285 |
< |
atomInfo->dipole[0] = 0.0; |
286 |
< |
atomInfo->dipole[1] = 0.0; |
287 |
< |
atomInfo->dipole[2] = 0.0; |
288 |
< |
atomData->addAtomInfo(atomInfo); |
279 |
> |
newVec = rotTrans * c2; |
280 |
> |
atomInfo = new AtomInfo; |
281 |
> |
atomInfo->AtomType = "C"; |
282 |
> |
atomInfo->pos[0] = pos[0] + newVec[0]; |
283 |
> |
atomInfo->pos[1] = pos[1] + newVec[1]; |
284 |
> |
atomInfo->pos[2] = pos[2] + newVec[2]; |
285 |
> |
atomInfo->dipole[0] = 0.0; |
286 |
> |
atomInfo->dipole[1] = 0.0; |
287 |
> |
atomInfo->dipole[2] = 0.0; |
288 |
> |
atomData->addAtomInfo(atomInfo); |
289 |
|
|
290 |
< |
matVecMul3(rotTrans, c4, newVec); |
291 |
< |
atomInfo = new AtomInfo; |
292 |
< |
atomInfo->AtomType = "C"; |
293 |
< |
atomInfo->pos[0] = pos[0] + newVec[0]; |
294 |
< |
atomInfo->pos[1] = pos[1] + newVec[1]; |
295 |
< |
atomInfo->pos[2] = pos[2] + newVec[2]; |
296 |
< |
atomInfo->dipole[0] = 0.0; |
297 |
< |
atomInfo->dipole[1] = 0.0; |
298 |
< |
atomInfo->dipole[2] = 0.0; |
299 |
< |
atomData->addAtomInfo(atomInfo); |
290 |
> |
newVec = rotTrans * c3; |
291 |
> |
atomInfo = new AtomInfo; |
292 |
> |
atomInfo->AtomType = "C"; |
293 |
> |
atomInfo->pos[0] = pos[0] + newVec[0]; |
294 |
> |
atomInfo->pos[1] = pos[1] + newVec[1]; |
295 |
> |
atomInfo->pos[2] = pos[2] + newVec[2]; |
296 |
> |
atomInfo->dipole[0] = 0.0; |
297 |
> |
atomInfo->dipole[1] = 0.0; |
298 |
> |
atomInfo->dipole[2] = 0.0; |
299 |
> |
atomData->addAtomInfo(atomInfo); |
300 |
|
|
301 |
< |
//add atom data into atom's property |
301 |
> |
newVec = rotTrans * c4; |
302 |
> |
atomInfo = new AtomInfo; |
303 |
> |
atomInfo->AtomType = "C"; |
304 |
> |
atomInfo->pos[0] = pos[0] + newVec[0]; |
305 |
> |
atomInfo->pos[1] = pos[1] + newVec[1]; |
306 |
> |
atomInfo->pos[2] = pos[2] + newVec[2]; |
307 |
> |
atomInfo->dipole[0] = 0.0; |
308 |
> |
atomInfo->dipole[1] = 0.0; |
309 |
> |
atomInfo->dipole[2] = 0.0; |
310 |
> |
atomData->addAtomInfo(atomInfo); |
311 |
|
|
312 |
< |
if(!haveAtomData){ |
329 |
< |
atomData->setID("ATOMDATA"); |
330 |
< |
datom->addProperty(atomData); |
331 |
< |
} |
312 |
> |
//add atom data into atom's property |
313 |
|
|
314 |
< |
setVisited(datom); |
314 |
> |
if(!haveAtomData){ |
315 |
> |
atomData->setID("ATOMDATA"); |
316 |
> |
datom->addProperty(atomData); |
317 |
> |
} |
318 |
|
|
319 |
+ |
setVisited(datom); |
320 |
+ |
|
321 |
|
} |
322 |
|
|
323 |
< |
const string LinearAtomVisitor::toString(){ |
323 |
> |
const std::string LinearAtomVisitor::toString(){ |
324 |
|
char buffer[65535]; |
325 |
< |
string result; |
325 |
> |
std::string result; |
326 |
|
|
327 |
|
sprintf(buffer ,"------------------------------------------------------------------\n"); |
328 |
|
result += buffer; |
380 |
|
return; |
381 |
|
|
382 |
|
pos = datom->getPos(); |
383 |
< |
u = datom->getElectroFrame().getColumn(3); |
383 |
> |
u = datom->getElectroFrame().getColumn(2); |
384 |
|
|
385 |
|
atomData = new AtomData; |
386 |
|
atomData->setID("ATOMDATA"); |