1 |
#include "OtherVisitor.hpp" |
2 |
#include "DirectionalAtom.hpp" |
3 |
#include "RigidBody.hpp" |
4 |
#include "Molecule.hpp" |
5 |
#include "SimInfo.hpp" |
6 |
//----------------------------------------------------------------------------// |
7 |
void IgnoreVisitor::visit(Atom* atom){ |
8 |
if(isIgnoreType(atom->getType())) |
9 |
internalVisit(atom); |
10 |
} |
11 |
|
12 |
void IgnoreVisitor::visit(DirectionalAtom* datom){ |
13 |
if(isIgnoreType(datom->getType())) |
14 |
internalVisit(datom); |
15 |
} |
16 |
|
17 |
void IgnoreVisitor::visit(RigidBody* rb){ |
18 |
vector<Atom*> myAtoms; |
19 |
vector<Atom*>::iterator atomIter; |
20 |
AtomInfo* atomInfo; |
21 |
|
22 |
if(isIgnoreType(rb->getType())){ |
23 |
|
24 |
internalVisit(rb); |
25 |
|
26 |
myAtoms = rb->getAtoms(); |
27 |
|
28 |
for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter) |
29 |
internalVisit(*atomIter); |
30 |
|
31 |
} |
32 |
|
33 |
} |
34 |
|
35 |
bool IgnoreVisitor::isIgnoreType(const string& name){ |
36 |
return itList.find(name) != itList.end() ? true : false; |
37 |
} |
38 |
|
39 |
void IgnoreVisitor::internalVisit(StuntDouble* sd){ |
40 |
GenericData* data; |
41 |
data = sd->getProperty("IGNORE"); |
42 |
|
43 |
//if this stuntdoulbe is already marked as ignore just skip it |
44 |
if (data == NULL){ |
45 |
data = new GenericData; |
46 |
data->setID("IGNORE"); |
47 |
sd->addProperty(data); |
48 |
} |
49 |
|
50 |
} |
51 |
|
52 |
const string IgnoreVisitor::toString(){ |
53 |
char buffer[65535]; |
54 |
string result; |
55 |
set<string>::iterator i; |
56 |
|
57 |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
58 |
result += buffer; |
59 |
|
60 |
sprintf(buffer ,"Visitor name: %s", visitorName.c_str()); |
61 |
result += buffer; |
62 |
|
63 |
sprintf(buffer ,"Visitor Description: ignore stuntdoubles\n"); |
64 |
result += buffer; |
65 |
|
66 |
//print the ignore type list |
67 |
sprintf(buffer , "Ignore type list contains below types:\n"); |
68 |
result += buffer; |
69 |
|
70 |
for(i = itList.begin(); i != itList.end(); ++i){ |
71 |
sprintf(buffer ,"%s\t", i->c_str()); |
72 |
result += buffer; |
73 |
|
74 |
} |
75 |
sprintf(buffer ,"\n"); |
76 |
result += buffer; |
77 |
|
78 |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
79 |
result += buffer; |
80 |
|
81 |
return result; |
82 |
} |
83 |
|
84 |
//----------------------------------------------------------------------------// |
85 |
|
86 |
void WrappingVisitor::visit(Atom* atom){ |
87 |
internalVisit(atom); |
88 |
} |
89 |
void WrappingVisitor::visit(DirectionalAtom* datom){ |
90 |
internalVisit(datom); |
91 |
} |
92 |
|
93 |
void WrappingVisitor::visit(RigidBody* rb){ |
94 |
internalVisit(rb); |
95 |
} |
96 |
|
97 |
void WrappingVisitor::internalVisit(StuntDouble* sd){ |
98 |
GenericData* data; |
99 |
AtomData* atomData; |
100 |
AtomInfo* atomInfo; |
101 |
vector<AtomInfo*>::iterator i; |
102 |
|
103 |
data = sd->getProperty("ATOMDATA"); |
104 |
if(data != NULL){ |
105 |
atomData = dynamic_cast<AtomData*>(data); |
106 |
if(atomData == NULL) |
107 |
return; |
108 |
} |
109 |
else |
110 |
return; |
111 |
|
112 |
for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)) |
113 |
info->wrapVector(atomInfo->pos); |
114 |
|
115 |
|
116 |
} |
117 |
|
118 |
const string WrappingVisitor::toString(){ |
119 |
char buffer[65535]; |
120 |
string result; |
121 |
|
122 |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
123 |
result += buffer; |
124 |
|
125 |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
126 |
result += buffer; |
127 |
|
128 |
sprintf(buffer ,"Visitor Description: wrapping atoms back to periodic box\n"); |
129 |
result += buffer; |
130 |
|
131 |
sprintf(buffer,"------------------------------------------------------------------\n"); |
132 |
result += buffer; |
133 |
|
134 |
return result; |
135 |
} |
136 |
|
137 |
//----------------------------------------------------------------------------// |
138 |
|
139 |
ReplicateVisitor::ReplicateVisitor(SimInfo* info, IntVec3 opt) : BaseVisitor(){ |
140 |
this->info = info; |
141 |
visitorName = "ReplicateVisitor"; |
142 |
this->replicateOpt = opt; |
143 |
//generate the replicate directions |
144 |
for(int i = 0; i <= replicateOpt[0]; i ++) |
145 |
for(int j = 0; j <= replicateOpt[1]; j ++) |
146 |
for(int k = 0; k <= replicateOpt[2]; k ++) |
147 |
//skip original frame |
148 |
if(i == 0 && j ==0 && k ==0) |
149 |
continue; |
150 |
else |
151 |
dir.push_back(IntVec3(i, j, k)); |
152 |
|
153 |
} |
154 |
void ReplicateVisitor::visit(Atom* atom){ |
155 |
internalVisit(atom); |
156 |
} |
157 |
void ReplicateVisitor::visit(DirectionalAtom* datom){ |
158 |
internalVisit(datom); |
159 |
} |
160 |
|
161 |
void ReplicateVisitor::visit(RigidBody* rb){ |
162 |
internalVisit(rb); |
163 |
} |
164 |
|
165 |
void ReplicateVisitor::internalVisit(StuntDouble* sd){ |
166 |
GenericData* data; |
167 |
AtomData* atomData; |
168 |
AtomInfo* atomInfo; |
169 |
double box[3][3]; |
170 |
vector<AtomInfo*> atomInfoList; |
171 |
IntVec3 dir; |
172 |
|
173 |
//if there is not atom data, just skip it |
174 |
data = sd->getProperty("ATOMDATA"); |
175 |
if(data != NULL){ |
176 |
atomData = dynamic_cast<AtomData*>(data); |
177 |
if(atomData == NULL) |
178 |
return; |
179 |
} |
180 |
else |
181 |
return; |
182 |
|
183 |
|
184 |
info->getBoxM(box); |
185 |
|
186 |
atomInfoList = atomData->getData(); |
187 |
|
188 |
replicate(atomInfoList, atomData, box); |
189 |
|
190 |
} |
191 |
|
192 |
void ReplicateVisitor::replicate(vector<AtomInfo*>& infoList, AtomData* data, double boxM[3][3]){ |
193 |
AtomInfo * newAtomInfo; |
194 |
vector<IntVec3>::iterator dirIter; |
195 |
vector<AtomInfo*>::iterator i; |
196 |
|
197 |
for(dirIter = dir.begin(); dirIter != dir.end(); ++dirIter){ |
198 |
for(i = infoList.begin(); i != infoList.end(); i++){ |
199 |
newAtomInfo = new AtomInfo; |
200 |
*newAtomInfo = *(*i); |
201 |
|
202 |
for(int j = 0; j < 3; j++) |
203 |
newAtomInfo->pos[j] += (*dirIter)[0] * boxM[j][0] + (*dirIter)[1]* boxM[j][1] + (*dirIter)[2] * boxM[j][2]; |
204 |
|
205 |
data->addAtomInfo(newAtomInfo); |
206 |
} |
207 |
}// end for(dirIter) |
208 |
} |
209 |
|
210 |
const string ReplicateVisitor::toString(){ |
211 |
char buffer[65535]; |
212 |
string result; |
213 |
set<string>::iterator i; |
214 |
|
215 |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
216 |
result += buffer; |
217 |
|
218 |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
219 |
result += buffer; |
220 |
|
221 |
sprintf(buffer ,"Visitor Description: replicate the atoms in different direction\n"); |
222 |
result += buffer; |
223 |
|
224 |
//print the replicate direction |
225 |
sprintf(buffer , "repeatX = %d:\n", replicateOpt[0]); |
226 |
result += buffer; |
227 |
|
228 |
sprintf(buffer , "repeatY = %d:\n", replicateOpt[1]); |
229 |
result += buffer; |
230 |
|
231 |
sprintf(buffer , "repeatZ = %d:\n", replicateOpt[2]); |
232 |
result += buffer; |
233 |
|
234 |
|
235 |
sprintf(buffer,"------------------------------------------------------------------\n"); |
236 |
result += buffer; |
237 |
|
238 |
return result; |
239 |
} |
240 |
|
241 |
//----------------------------------------------------------------------------// |
242 |
|
243 |
XYZVisitor::XYZVisitor(SimInfo* info, bool printDipole) : BaseVisitor(){ |
244 |
this->info = info; |
245 |
visitorName = "XYZVisitor"; |
246 |
this->printDipole = printDipole; |
247 |
} |
248 |
|
249 |
void XYZVisitor::visit(Atom* atom){ |
250 |
if(!isIgnore(atom)) |
251 |
internalVisit(atom); |
252 |
} |
253 |
|
254 |
void XYZVisitor::visit(DirectionalAtom* datom){ |
255 |
if(!isIgnore(datom)) |
256 |
internalVisit(datom); |
257 |
} |
258 |
|
259 |
void XYZVisitor::visit(RigidBody* rb){ |
260 |
if(!isIgnore(rb)) |
261 |
internalVisit(rb); |
262 |
|
263 |
} |
264 |
|
265 |
void XYZVisitor::internalVisit(StuntDouble* sd){ |
266 |
GenericData* data; |
267 |
AtomData* atomData; |
268 |
AtomInfo* atomInfo; |
269 |
vector<AtomInfo*>::iterator i; |
270 |
char buffer[1024]; |
271 |
|
272 |
//if there is not atom data, just skip it |
273 |
data = sd->getProperty("ATOMDATA"); |
274 |
if(data != NULL){ |
275 |
atomData = dynamic_cast<AtomData*>(data); |
276 |
if(atomData == NULL) |
277 |
return; |
278 |
} |
279 |
else |
280 |
return; |
281 |
|
282 |
for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){ |
283 |
|
284 |
if(printDipole) |
285 |
sprintf(buffer, "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f", |
286 |
atomInfo->AtomType.c_str(), |
287 |
atomInfo->pos[0], |
288 |
atomInfo->pos[1], |
289 |
atomInfo->pos[2], |
290 |
atomInfo->dipole[0], |
291 |
atomInfo->dipole[1], |
292 |
atomInfo->dipole[2]); |
293 |
else |
294 |
sprintf(buffer, "%s%15.8f%15.8f%15.8f", |
295 |
atomInfo->AtomType.c_str(), |
296 |
atomInfo->pos[0], |
297 |
atomInfo->pos[1], |
298 |
atomInfo->pos[2]); |
299 |
|
300 |
frame.push_back(buffer); |
301 |
|
302 |
} |
303 |
|
304 |
} |
305 |
|
306 |
bool XYZVisitor::isIgnore(StuntDouble* sd){ |
307 |
GenericData* data; |
308 |
|
309 |
data = sd->getProperty("IGNORE"); |
310 |
return data ==NULL ? false : true; |
311 |
} |
312 |
|
313 |
void XYZVisitor::writeFrame(ostream& outStream){ |
314 |
vector<string>::iterator i; |
315 |
double box[3][3]; |
316 |
char buffer[1024]; |
317 |
|
318 |
if(frame.size() == 0) |
319 |
cerr << "Current Frame does not contain any atoms" << endl; |
320 |
|
321 |
//total number of atoms |
322 |
outStream << frame.size() << endl; |
323 |
|
324 |
//write comment line |
325 |
info->getBoxM(box); |
326 |
sprintf(buffer,"%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f", |
327 |
info->getTime(), |
328 |
box[0][0], box[0][1], box[0][2], |
329 |
box[1][0], box[1][1], box[1][2], |
330 |
box[2][0], box[2][1], box[2][2]); |
331 |
|
332 |
outStream << buffer << endl; |
333 |
|
334 |
for(i = frame.begin(); i != frame.end(); ++i) |
335 |
outStream << *i << endl; |
336 |
} |
337 |
|
338 |
const string XYZVisitor::toString(){ |
339 |
char buffer[65535]; |
340 |
string result; |
341 |
|
342 |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
343 |
result += buffer; |
344 |
|
345 |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
346 |
result += buffer; |
347 |
|
348 |
sprintf(buffer ,"Visitor Description: assemble the atom data and output xyz file\n"); |
349 |
result += buffer; |
350 |
|
351 |
sprintf(buffer,"------------------------------------------------------------------\n"); |
352 |
result += buffer; |
353 |
|
354 |
return result; |
355 |
} |
356 |
|
357 |
//----------------------------------------------------------------------------// |
358 |
|
359 |
void PrepareVisitor::internalVisit(Atom * atom){ |
360 |
GenericData* data; |
361 |
AtomData* atomData; |
362 |
|
363 |
//if visited property is existed, remove it |
364 |
data = atom->getProperty("VISITED"); |
365 |
if(data != NULL){ |
366 |
atom->removeProperty("VISITED"); |
367 |
} |
368 |
|
369 |
//remove atomdata |
370 |
data = atom->getProperty("ATOMDATA"); |
371 |
if(data != NULL){ |
372 |
atomData = dynamic_cast<AtomData*>(data); |
373 |
if(atomData != NULL) |
374 |
atom->removeProperty("ATOMDATA"); |
375 |
} |
376 |
|
377 |
} |
378 |
|
379 |
void PrepareVisitor::internalVisit(RigidBody * rb){ |
380 |
GenericData* data; |
381 |
AtomData* atomData; |
382 |
vector<Atom*> myAtoms; |
383 |
vector<Atom*>::iterator atomIter; |
384 |
|
385 |
//if visited property is existed, remove it |
386 |
data = rb->getProperty("VISITED"); |
387 |
if(data != NULL){ |
388 |
rb->removeProperty("VISITED"); |
389 |
} |
390 |
|
391 |
//remove atomdata |
392 |
data = rb->getProperty("ATOMDATA"); |
393 |
if(data != NULL){ |
394 |
atomData = dynamic_cast<AtomData*>(data); |
395 |
if(atomData != NULL) |
396 |
rb->removeProperty("ATOMDATA"); |
397 |
} |
398 |
|
399 |
myAtoms = rb->getAtoms(); |
400 |
|
401 |
for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter) |
402 |
internalVisit (*atomIter); |
403 |
} |
404 |
|
405 |
const string PrepareVisitor::toString(){ |
406 |
char buffer[65535]; |
407 |
string result; |
408 |
|
409 |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
410 |
result += buffer; |
411 |
|
412 |
sprintf(buffer ,"Visitor name: %s", visitorName.c_str()); |
413 |
result += buffer; |
414 |
|
415 |
sprintf(buffer ,"Visitor Description: prepare for operation of other vistors\n"); |
416 |
result += buffer; |
417 |
|
418 |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
419 |
result += buffer; |
420 |
|
421 |
return result; |
422 |
} |
423 |
|
424 |
//----------------------------------------------------------------------------// |
425 |
|
426 |
WaterTypeVisitor:: WaterTypeVisitor(){ |
427 |
visitorName = "WaterTypeVisitor"; |
428 |
waterTypeList.insert("TIP3P_RB_0"); |
429 |
waterTypeList.insert("TIP4P_RB_0"); |
430 |
waterTypeList.insert("TIP5P_RB_0"); |
431 |
waterTypeList.insert("SPCE_RB_0"); |
432 |
} |
433 |
|
434 |
|
435 |
void WaterTypeVisitor:: visit(RigidBody* rb){ |
436 |
string rbName; |
437 |
vector<Atom*> myAtoms; |
438 |
vector<Atom*>::iterator atomIter; |
439 |
GenericData* data; |
440 |
AtomData* atomData; |
441 |
AtomInfo* atomInfo; |
442 |
vector<AtomInfo*>::iterator i; |
443 |
|
444 |
rbName = rb->getType(); |
445 |
|
446 |
if(waterTypeList.find(rbName) != waterTypeList.end()){ |
447 |
|
448 |
myAtoms = rb->getAtoms(); |
449 |
for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter){ |
450 |
|
451 |
data = (*atomIter)->getProperty("ATOMDATA"); |
452 |
if(data != NULL){ |
453 |
atomData = dynamic_cast<AtomData*>(data); |
454 |
if(atomData == NULL) |
455 |
continue; |
456 |
} |
457 |
else |
458 |
continue; |
459 |
|
460 |
for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){ |
461 |
replaceType(atomInfo->AtomType); |
462 |
}//end for(atomInfo) |
463 |
|
464 |
}//end for(atomIter) |
465 |
|
466 |
}//end if (waterTypeList.find(rbName) != waterTypeList.end()) |
467 |
|
468 |
} |
469 |
|
470 |
void WaterTypeVisitor:: replaceType(string& atomType){ |
471 |
atomType = atomType.substr(0, atomType.find('_')); |
472 |
} |
473 |
|
474 |
const string WaterTypeVisitor:: toString(){ |
475 |
char buffer[65535]; |
476 |
string result; |
477 |
|
478 |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
479 |
result += buffer; |
480 |
|
481 |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
482 |
result += buffer; |
483 |
|
484 |
sprintf(buffer ,"Visitor Description: Replace the atom type in water model\n"); |
485 |
result += buffer; |
486 |
|
487 |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
488 |
result += buffer; |
489 |
|
490 |
return result; |
491 |
} |
492 |
|