ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/visitors/OtherVisitor.cpp
(Generate patch)

Comparing trunk/src/visitors/OtherVisitor.cpp (file contents):
Revision 413 by tim, Wed Mar 9 17:30:29 2005 UTC vs.
Revision 1219 by xsun, Wed Jan 23 21:23:32 2008 UTC

# Line 46 | Line 46 | namespace oopse {
46   #include "brains/SimInfo.hpp"
47   namespace oopse {
48  
49 < void WrappingVisitor::visit(Atom *atom) {
50 < internalVisit(atom);
51 < }
49 >  void WrappingVisitor::visit(Atom *atom) {
50 >    internalVisit(atom);
51 >  }
52  
53 < void WrappingVisitor::visit(DirectionalAtom *datom) {
54 < internalVisit(datom);
55 < }
53 >  void WrappingVisitor::visit(DirectionalAtom *datom) {
54 >    internalVisit(datom);
55 >  }
56  
57 < void WrappingVisitor::visit(RigidBody *rb) {
58 < internalVisit(rb);
59 < }
57 >  void WrappingVisitor::visit(RigidBody *rb) {
58 >    internalVisit(rb);
59 >  }
60  
61 < void WrappingVisitor::internalVisit(StuntDouble *sd) {
61 >  void WrappingVisitor::internalVisit(StuntDouble *sd) {
62      GenericData *                     data;
63      AtomData *                        atomData;
64      AtomInfo *                        atomInfo;
# Line 67 | Line 67 | void WrappingVisitor::internalVisit(StuntDouble *sd) {
67      data = sd->getPropertyByName("ATOMDATA");
68  
69      if (data != NULL) {
70 <        atomData = dynamic_cast<AtomData *>(data);
70 >      atomData = dynamic_cast<AtomData *>(data);
71  
72 <        if (atomData == NULL)
73 <            return;
72 >      if (atomData == NULL)
73 >        return;
74      } else
75 <        return;
75 >      return;
76  
77      Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
78      
79      for( atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i) ) {
80 <        currSnapshot->wrapVector(atomInfo->pos);
80 >      Vector3d newPos = atomInfo->pos - origin_;
81 >      currSnapshot->wrapVector(newPos);
82 >      atomInfo->pos = newPos;
83      }
84 < }
84 >  }
85  
86 < const std::string WrappingVisitor::toString() {
86 >  void WrappingVisitor::update() {
87 >    if (useCom_){
88 >      origin_ = info->getCom();
89 >    }
90 >  }
91 >  
92 >  const std::string WrappingVisitor::toString() {
93      char        buffer[65535];
94      std::string result;
95  
# Line 101 | Line 109 | const std::string WrappingVisitor::toString() {
109      result += buffer;
110  
111      return result;
112 < }
112 >  }
113  
114 < //----------------------------------------------------------------------------//
114 >  //----------------------------------------------------------------------------//
115  
116 < ReplicateVisitor::ReplicateVisitor(SimInfo *info, Vector3i opt) :
116 >  ReplicateVisitor::ReplicateVisitor(SimInfo *info, Vector3i opt) :
117      BaseVisitor() {
118 <    this->info = info;
119 <    visitorName = "ReplicateVisitor";
120 <    this->replicateOpt = opt;
118 >      this->info = info;
119 >      visitorName = "ReplicateVisitor";
120 >      this->replicateOpt = opt;
121  
122 <    //generate the replicate directions
123 <    for( int i = 0; i <= replicateOpt[0]; i++ ) {
122 >      //generate the replicate directions
123 >      for( int i = 0; i <= replicateOpt[0]; i++ ) {
124          for( int j = 0; j <= replicateOpt[1]; j++ ) {
125 <            for( int k = 0; k <= replicateOpt[2]; k++ ) {
126 <                //skip original frame
127 <                if (i == 0 && j == 0 && k == 0) {
128 <                    continue;
129 <                } else {
130 <                    dir.push_back(Vector3i(i, j, k));
131 <                }
132 <            }
125 >          for( int k = 0; k <= replicateOpt[2]; k++ ) {
126 >            //skip original frame
127 >            if (i == 0 && j == 0 && k == 0) {
128 >              continue;
129 >            } else {
130 >              dir.push_back(Vector3i(i, j, k));
131 >            }
132 >          }
133          }
134 <    }
134 >      }
135      
136 < }
136 >    }
137  
138 < void ReplicateVisitor::visit(Atom *atom) {
139 < internalVisit(atom);
140 < }
138 >  void ReplicateVisitor::visit(Atom *atom) {
139 >    internalVisit(atom);
140 >  }
141  
142 < void ReplicateVisitor::visit(DirectionalAtom *datom) {
143 < internalVisit(datom);
144 < }
142 >  void ReplicateVisitor::visit(DirectionalAtom *datom) {
143 >    internalVisit(datom);
144 >  }
145  
146 < void ReplicateVisitor::visit(RigidBody *rb) {
147 < internalVisit(rb);
148 < }
146 >  void ReplicateVisitor::visit(RigidBody *rb) {
147 >    internalVisit(rb);
148 >  }
149  
150 < void ReplicateVisitor::internalVisit(StuntDouble *sd) {
150 >  void ReplicateVisitor::internalVisit(StuntDouble *sd) {
151      GenericData *          data;
152      AtomData *             atomData;
153  
# Line 147 | Line 155 | void ReplicateVisitor::internalVisit(StuntDouble *sd)
155      data = sd->getPropertyByName("ATOMDATA");
156  
157      if (data != NULL) {
158 <        atomData = dynamic_cast<AtomData *>(data);
158 >      atomData = dynamic_cast<AtomData *>(data);
159  
160 <        if (atomData == NULL) {
161 <            return;
162 <        }
160 >      if (atomData == NULL) {
161 >        return;
162 >      }
163      } else {
164 <        return;
164 >      return;
165      }
166  
167      Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
# Line 162 | Line 170 | void ReplicateVisitor::internalVisit(StuntDouble *sd)
170      std::vector<AtomInfo *> atomInfoList = atomData->getData();
171  
172      replicate(atomInfoList, atomData, box);
173 < }
173 >  }
174  
175 < void ReplicateVisitor::replicate(std::vector<AtomInfo *>&infoList, AtomData *data, const Mat3x3d& box) {
175 >  void ReplicateVisitor::replicate(std::vector<AtomInfo *>&infoList, AtomData *data, const Mat3x3d& box) {
176      AtomInfo* newAtomInfo;
177      std::vector<Vector3i>::iterator dirIter;
178      std::vector<AtomInfo *>::iterator i;
179  
180      for( dirIter = dir.begin(); dirIter != dir.end(); ++dirIter ) {
181 <        for( i = infoList.begin(); i != infoList.end(); i++ ) {
182 <            newAtomInfo = new AtomInfo();
183 <            *newAtomInfo = *(*i);
181 >      for( i = infoList.begin(); i != infoList.end(); i++ ) {
182 >        newAtomInfo = new AtomInfo();
183 >        *newAtomInfo = *(*i);
184  
185 <            for( int j = 0; j < 3; j++ )
186 <                newAtomInfo->pos[j] += (*dirIter)[0]*box(j, 0) + (*dirIter)[1]*box(j, 1) + (*dirIter)[2]*box(j, 2);
185 >        for( int j = 0; j < 3; j++ )
186 >          newAtomInfo->pos[j] += (*dirIter)[0]*box(j, 0) + (*dirIter)[1]*box(j, 1) + (*dirIter)[2]*box(j, 2);
187  
188 <            data->addAtomInfo(newAtomInfo);
189 <        }
188 >        data->addAtomInfo(newAtomInfo);
189 >      }
190      } // end for(dirIter)  
191 < }
191 >  }
192  
193 < const std::string ReplicateVisitor::toString() {
193 >  const std::string ReplicateVisitor::toString() {
194      char                            buffer[65535];
195      std::string                     result;
196      std::set<std::string>::iterator i;
# Line 213 | Line 221 | const std::string ReplicateVisitor::toString() {
221      result += buffer;
222  
223      return result;
224 < }
217 <
218 < //----------------------------------------------------------------------------//
224 >  }
225  
226 < XYZVisitor::XYZVisitor(SimInfo *info) :
226 >  //----------------------------------------------------------------------------//
227 >
228 >  XYZVisitor::XYZVisitor(SimInfo *info) :
229      BaseVisitor(), seleMan(info), evaluator(info){
230 <    this->info = info;
231 <    visitorName = "XYZVisitor";
230 >      this->info = info;
231 >      visitorName = "XYZVisitor";
232  
233 <    evaluator.loadScriptString("select all");
233 >      evaluator.loadScriptString("select all");
234  
235 <    if (!evaluator.isDynamic()) {
235 >      if (!evaluator.isDynamic()) {
236          seleMan.setSelectionSet(evaluator.evaluate());
237 +      }
238 +      posOnly_ = false;
239      }
240  
241 < }
232 <
233 < XYZVisitor::XYZVisitor(SimInfo *info, const std::string& script) :
241 >  XYZVisitor::XYZVisitor(SimInfo *info, const std::string& script) :
242      BaseVisitor(), seleMan(info), evaluator(info) {
243 <    this->info = info;
244 <    visitorName = "XYZVisitor";
243 >      this->info = info;
244 >      visitorName = "XYZVisitor";
245  
246 <    evaluator.loadScriptString(script);
246 >      evaluator.loadScriptString(script);
247  
248 <    if (!evaluator.isDynamic()) {
248 >      if (!evaluator.isDynamic()) {
249          seleMan.setSelectionSet(evaluator.evaluate());
250 +      }
251 +      posOnly_ = false;
252      }
243          
244 }
253      
254 < void XYZVisitor::visit(Atom *atom) {
254 >  void XYZVisitor::visit(Atom *atom) {
255      if (isSelected(atom))
256 <        internalVisit(atom);
257 < }
256 >      internalVisit(atom);
257 >  }
258  
259 < void XYZVisitor::visit(DirectionalAtom *datom) {
259 >  void XYZVisitor::visit(DirectionalAtom *datom) {
260      if (isSelected(datom))
261 <        internalVisit(datom);
262 < }
261 >      internalVisit(datom);
262 >  }
263  
264 < void XYZVisitor::visit(RigidBody *rb) {
264 >  void XYZVisitor::visit(RigidBody *rb) {
265      if (isSelected(rb))
266 <        internalVisit(rb);
267 < }
266 >      internalVisit(rb);
267 >  }
268  
269 < void XYZVisitor::update() {
269 >  void XYZVisitor::update() {
270      //if dynamic, we need to re-evaluate the selection
271      if (evaluator.isDynamic()) {
272 <       seleMan.setSelectionSet(evaluator.evaluate());
272 >      seleMan.setSelectionSet(evaluator.evaluate());
273      }
274 < }
274 >  }
275  
276 < void XYZVisitor::internalVisit(StuntDouble *sd) {
276 >  void XYZVisitor::internalVisit(StuntDouble *sd) {
277      GenericData *                     data;
278      AtomData *                        atomData;
279      AtomInfo *                        atomInfo;
# Line 276 | Line 284 | void XYZVisitor::internalVisit(StuntDouble *sd) {
284      data = sd->getPropertyByName("ATOMDATA");
285  
286      if (data != NULL) {
287 <        atomData = dynamic_cast<AtomData *>(data);
287 >      atomData = dynamic_cast<AtomData *>(data);
288  
289 <        if (atomData == NULL)
290 <            return;
289 >      if (atomData == NULL)
290 >        return;
291      } else
292 <        return;
292 >      return;
293  
294 <    for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
295 <        atomInfo = atomData->nextAtomInfo(i) ) {
296 <        sprintf(buffer,
297 <                "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
298 <                atomInfo->atomTypeName.c_str(),
299 <                atomInfo->pos[0],
300 <                atomInfo->pos[1],
301 <                atomInfo->pos[2],
302 <                atomInfo->dipole[0],
303 <                atomInfo->dipole[1],
304 <                atomInfo->dipole[2]);
305 <        frame.push_back(buffer);
306 <    }
307 < }
308 <
309 < bool XYZVisitor::isSelected(StuntDouble *sd) {
294 >    if (posOnly_){
295 >      for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
296 >           atomInfo = atomData->nextAtomInfo(i) ) {
297 >        if (atomInfo->hasCharge) {
298 >          sprintf(buffer,
299 >                "%s%15.8f%15.8f%15.8f%15.8f",
300 >                atomInfo->atomTypeName.c_str(),
301 >                atomInfo->pos[0],
302 >                atomInfo->pos[1],
303 >                atomInfo->pos[2],
304 >                atomInfo->charge);
305 >        } else {
306 >          sprintf(buffer,
307 >                "%s%15.8f%15.8f%15.8f",
308 >                atomInfo->atomTypeName.c_str(),
309 >                atomInfo->pos[0],
310 >                atomInfo->pos[1],
311 >                atomInfo->pos[2]);
312 >        }
313 >        frame.push_back(buffer);
314 >      }
315 >    }else{
316 >      for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
317 >           atomInfo = atomData->nextAtomInfo(i) ) {
318 >        if (atomInfo->hasCharge) {
319 >        sprintf(buffer,
320 >                "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
321 >                atomInfo->atomTypeName.c_str(),
322 >                atomInfo->pos[0],
323 >                atomInfo->pos[1],
324 >                atomInfo->pos[2],
325 >                atomInfo->charge,
326 >                atomInfo->dipole[0],
327 >                atomInfo->dipole[1],
328 >                atomInfo->dipole[2]);
329 >        } else {
330 >        sprintf(buffer,
331 >                "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
332 >                atomInfo->atomTypeName.c_str(),
333 >                atomInfo->pos[0],
334 >                atomInfo->pos[1],
335 >                atomInfo->pos[2],
336 >                atomInfo->dipole[0],
337 >                atomInfo->dipole[1],
338 >                atomInfo->dipole[2]);
339 >        }
340 >        frame.push_back(buffer);
341 >      }
342 >    }
343 >  }
344 >
345 >  bool XYZVisitor::isSelected(StuntDouble *sd) {
346      return seleMan.isSelected(sd);
347 < }
347 >  }
348  
349 < void XYZVisitor::writeFrame(std::ostream &outStream) {
349 >  void XYZVisitor::writeFrame(std::ostream &outStream) {
350      std::vector<std::string>::iterator i;
351      char buffer[1024];
352  
353      if (frame.size() == 0)
354 <        std::cerr << "Current Frame does not contain any atoms" << std::endl;
354 >      std::cerr << "Current Frame does not contain any atoms" << std::endl;
355  
356      //total number of atoms  
357      outStream << frame.size() << std::endl;
# Line 326 | Line 370 | void XYZVisitor::writeFrame(std::ostream &outStream) {
370      outStream << buffer << std::endl;
371  
372      for( i = frame.begin(); i != frame.end(); ++i )
373 <        outStream << *i << std::endl;
374 < }
373 >      outStream << *i << std::endl;
374 >  }
375  
376 < const std::string XYZVisitor::toString() {
376 >  const std::string XYZVisitor::toString() {
377      char        buffer[65535];
378      std::string result;
379  
# Line 349 | Line 393 | const std::string XYZVisitor::toString() {
393      result += buffer;
394  
395      return result;
396 < }
396 >  }
397  
398 < //----------------------------------------------------------------------------//
398 >  //----------------------------------------------------------------------------//
399  
400 < void PrepareVisitor::internalVisit(Atom *atom) {
400 >  void PrepareVisitor::internalVisit(Atom *atom) {
401      GenericData *data;
402      AtomData *   atomData;
403  
# Line 361 | Line 405 | void PrepareVisitor::internalVisit(Atom *atom) {
405      data = atom->getPropertyByName("VISITED");
406  
407      if (data != NULL) {
408 <    atom->removeProperty("VISITED");
408 >      atom->removeProperty("VISITED");
409      }
410  
411      //remove atomdata
412      data = atom->getPropertyByName("ATOMDATA");
413  
414      if (data != NULL) {
415 <        atomData = dynamic_cast<AtomData *>(data);
415 >      atomData = dynamic_cast<AtomData *>(data);
416  
417 <        if (atomData != NULL)
418 <            atom->removeProperty("ATOMDATA");
417 >      if (atomData != NULL)
418 >        atom->removeProperty("ATOMDATA");
419      }
420 < }
420 >  }
421  
422 < void PrepareVisitor::internalVisit(RigidBody *rb) {
422 >  void PrepareVisitor::internalVisit(RigidBody *rb) {
423      GenericData* data;
424      AtomData* atomData;
425      std::vector<Atom *> myAtoms;
# Line 385 | Line 429 | void PrepareVisitor::internalVisit(RigidBody *rb) {
429      data = rb->getPropertyByName("VISITED");
430  
431      if (data != NULL) {
432 <    rb->removeProperty("VISITED");
432 >      rb->removeProperty("VISITED");
433      }
434  
435      //remove atomdata
436      data = rb->getPropertyByName("ATOMDATA");
437  
438      if (data != NULL) {
439 <        atomData = dynamic_cast<AtomData *>(data);
439 >      atomData = dynamic_cast<AtomData *>(data);
440  
441 <        if (atomData != NULL)
442 <            rb->removeProperty("ATOMDATA");
441 >      if (atomData != NULL)
442 >        rb->removeProperty("ATOMDATA");
443      }
444  
445      myAtoms = rb->getAtoms();
446  
447      for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter )
448 <        internalVisit(*atomIter);
449 < }
448 >      internalVisit(*atomIter);
449 >  }
450  
451 < const std::string PrepareVisitor::toString() {
452 <     char buffer[65535];
453 <     std::string result;
451 >  const std::string PrepareVisitor::toString() {
452 >    char buffer[65535];
453 >    std::string result;
454  
455 <     sprintf(buffer,
456 <             "------------------------------------------------------------------\n");
457 <     result += buffer;
455 >    sprintf(buffer,
456 >            "------------------------------------------------------------------\n");
457 >    result += buffer;
458  
459 <     sprintf(buffer, "Visitor name: %s", visitorName.c_str());
460 <     result += buffer;
459 >    sprintf(buffer, "Visitor name: %s", visitorName.c_str());
460 >    result += buffer;
461  
462 <     sprintf(buffer,
463 <             "Visitor Description: prepare for operation of other vistors\n");
464 <     result += buffer;
462 >    sprintf(buffer,
463 >            "Visitor Description: prepare for operation of other vistors\n");
464 >    result += buffer;
465  
466 <     sprintf(buffer,
467 <             "------------------------------------------------------------------\n");
468 <     result += buffer;
466 >    sprintf(buffer,
467 >            "------------------------------------------------------------------\n");
468 >    result += buffer;
469  
470 <     return result;
471 < }
470 >    return result;
471 >  }
472  
473 < //----------------------------------------------------------------------------//
473 >  //----------------------------------------------------------------------------//
474  
475 < WaterTypeVisitor::WaterTypeVisitor() {
475 >  WaterTypeVisitor::WaterTypeVisitor() {
476      visitorName = "WaterTypeVisitor";
477      waterTypeList.insert("TIP3P_RB_0");
478      waterTypeList.insert("TIP4P_RB_0");
479      waterTypeList.insert("TIP5P_RB_0");
480      waterTypeList.insert("SPCE_RB_0");
481 < }
481 >  }
482  
483 < void WaterTypeVisitor::visit(RigidBody *rb) {
483 >  void WaterTypeVisitor::visit(RigidBody *rb) {
484      std::string rbName;
485      std::vector<Atom *> myAtoms;
486      std::vector<Atom *>::iterator atomIter;
# Line 448 | Line 492 | void WaterTypeVisitor::visit(RigidBody *rb) {
492      rbName = rb->getType();
493  
494      if (waterTypeList.find(rbName) != waterTypeList.end()) {
495 <        myAtoms = rb->getAtoms();
495 >      myAtoms = rb->getAtoms();
496  
497 <        for( atomIter = myAtoms.begin(); atomIter != myAtoms.end();
498 <            ++atomIter ) {
499 <            data = (*atomIter)->getPropertyByName("ATOMDATA");
497 >      for( atomIter = myAtoms.begin(); atomIter != myAtoms.end();
498 >           ++atomIter ) {
499 >        data = (*atomIter)->getPropertyByName("ATOMDATA");
500  
501 <            if (data != NULL) {
502 <                atomData = dynamic_cast<AtomData *>(data);
501 >        if (data != NULL) {
502 >          atomData = dynamic_cast<AtomData *>(data);
503  
504 <                if (atomData == NULL)
505 <                    continue;
506 <            } else
507 <                continue;
504 >          if (atomData == NULL)
505 >            continue;
506 >        } else
507 >          continue;
508  
509 <            for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
510 <                 atomInfo = atomData->nextAtomInfo(i) ) {
511 <              atomInfo->atomTypeName = trimmedName(atomInfo->atomTypeName);
512 <            } //end for(atomInfo)
513 <        }     //end for(atomIter)
509 >        for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
510 >             atomInfo = atomData->nextAtomInfo(i) ) {
511 >          atomInfo->atomTypeName = trimmedName(atomInfo->atomTypeName);
512 >        } //end for(atomInfo)
513 >      }     //end for(atomIter)
514      }         //end if (waterTypeList.find(rbName) != waterTypeList.end())
515 < }
515 >  }
516  
517    std::string WaterTypeVisitor::trimmedName(const std::string&atomTypeName) {
518      return atomTypeName.substr(0, atomTypeName.find('_'));
519    }
520  
521 < const std::string WaterTypeVisitor::toString() {
521 >  const std::string WaterTypeVisitor::toString() {
522      char buffer[65535];
523      std::string result;
524  
# Line 494 | Line 538 | const std::string WaterTypeVisitor::toString() {
538      result += buffer;
539  
540      return result;
541 < }
541 >  }
542  
543   } //namespace oopse

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines