ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/visitors/OtherVisitor.cpp
Revision: 1625
Committed: Thu Oct 21 16:22:01 2004 UTC (19 years, 8 months ago) by tim
File size: 12583 byte(s)
Log Message:
replace old GebericData with  new GenericData

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

Properties

Name Value
svn:executable *