ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-4/src/visitors/OtherVisitor.cpp
Revision: 1818
Committed: Wed Dec 1 20:05:49 2004 UTC (19 years, 6 months ago) by tim
File size: 14422 byte(s)
Log Message:
visitors get built

File Contents

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

Properties

Name Value
svn:executable *