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 1390 by gezelter, Wed Nov 25 20:02:06 2009 UTC vs.
branches/development/src/visitors/OtherVisitor.cpp (file contents), Revision 1465 by chuckv, Fri Jul 9 23:08:25 2010 UTC

# Line 223 | Line 223 | namespace OpenMD {
223      return result;
224    }
225  
226 <  //----------------------------------------------------------------------------//
226 >  //------------------------------------------------------------------------//
227  
228 <  XYZVisitor::XYZVisitor(SimInfo *info) :
229 <    BaseVisitor(), seleMan(info), evaluator(info){
230 <      this->info = info;
231 <      visitorName = "XYZVisitor";
232 <
233 <      evaluator.loadScriptString("select all");
234 <
235 <      if (!evaluator.isDynamic()) {
236 <        seleMan.setSelectionSet(evaluator.evaluate());
237 <      }
238 <      posOnly_ = false;
228 >  XYZVisitor::XYZVisitor(SimInfo *info) : BaseVisitor(), seleMan(info),
229 >                                          evaluator(info), doPositions_(true),
230 >                                          doVelocities_(false),
231 >                                          doForces_(false), doVectors_(false),
232 >                                          doCharges_(false) {
233 >    this->info = info;
234 >    visitorName = "XYZVisitor";
235 >    
236 >    evaluator.loadScriptString("select all");
237 >    
238 >    if (!evaluator.isDynamic()) {
239 >      seleMan.setSelectionSet(evaluator.evaluate());
240      }
241 <
241 >  }
242 >  
243    XYZVisitor::XYZVisitor(SimInfo *info, const std::string& script) :
244 <    BaseVisitor(), seleMan(info), evaluator(info) {
245 <      this->info = info;
246 <      visitorName = "XYZVisitor";
247 <
248 <      evaluator.loadScriptString(script);
249 <
250 <      if (!evaluator.isDynamic()) {
251 <        seleMan.setSelectionSet(evaluator.evaluate());
252 <      }
253 <      posOnly_ = false;
244 >    BaseVisitor(), seleMan(info), evaluator(info), doPositions_(true),
245 >    doVelocities_(false), doForces_(false), doVectors_(false),
246 >    doCharges_(false) {
247 >    
248 >    this->info = info;
249 >    visitorName = "XYZVisitor";
250 >    
251 >    evaluator.loadScriptString(script);
252 >    
253 >    if (!evaluator.isDynamic()) {
254 >      seleMan.setSelectionSet(evaluator.evaluate());
255      }
256 +  }
257      
258    void XYZVisitor::visit(Atom *atom) {
259      if (isSelected(atom))
# Line 260 | Line 264 | namespace OpenMD {
264      if (isSelected(datom))
265        internalVisit(datom);
266    }
267 <
267 >  
268    void XYZVisitor::visit(RigidBody *rb) {
269      if (isSelected(rb))
270        internalVisit(rb);
271    }
272 <
272 >  
273    void XYZVisitor::update() {
274      //if dynamic, we need to re-evaluate the selection
275      if (evaluator.isDynamic()) {
276        seleMan.setSelectionSet(evaluator.evaluate());
277      }
278    }
279 <
279 >  
280    void XYZVisitor::internalVisit(StuntDouble *sd) {
281      GenericData *                     data;
282      AtomData *                        atomData;
283      AtomInfo *                        atomInfo;
284      std::vector<AtomInfo *>::iterator i;
285      char                              buffer[1024];
286 <
286 >    
287      //if there is not atom data, just skip it
288      data = sd->getPropertyByName("ATOMDATA");
289 <
289 >    
290      if (data != NULL) {
291        atomData = dynamic_cast<AtomData *>(data);
292 <
292 >      
293        if (atomData == NULL)
294          return;
295      } else
296        return;
297  
298 <    AtomType* at = dynamic_cast<Atom *>(sd)->getAtomType();
299 <    std::string bn = baseTypeName(at);
300 <
301 <    if (posOnly_){
302 <      for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
303 <           atomInfo = atomData->nextAtomInfo(i) ) {
304 <        if (atomInfo->hasCharge) {
305 <          sprintf(buffer,
306 <                  "%s%15.8f%15.8f%15.8f%15.8f",
307 <                  bn.c_str(),
308 <                  atomInfo->pos[0],
309 <                  atomInfo->pos[1],
310 <                  atomInfo->pos[2],
311 <                  atomInfo->charge);
312 <        } else {
309 <          sprintf(buffer,
310 <                "%s%15.8f%15.8f%15.8f",
311 <                  bn.c_str(),
312 <                  atomInfo->pos[0],
313 <                  atomInfo->pos[1],
314 <                  atomInfo->pos[2]);
315 <        }
316 <        frame.push_back(buffer);
298 >    for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
299 >         atomInfo = atomData->nextAtomInfo(i) ) {
300 >    
301 >      std::string line;
302 >      sprintf(buffer, "%s", atomInfo->atomTypeName.c_str());
303 >      line += buffer;
304 >      
305 >      if (doPositions_){
306 >        sprintf(buffer, "%15.8f%15.8f%15.8f", atomInfo->pos[0],
307 >                atomInfo->pos[1], atomInfo->pos[2]);
308 >        line += buffer;
309 >      }      
310 >      if (doCharges_ && atomInfo->hasCharge) {
311 >        sprintf(buffer, "%15.8f", atomInfo->charge);
312 >        line += buffer;
313        }
314 <    }else{
315 <      for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
316 <           atomInfo = atomData->nextAtomInfo(i) ) {
317 <        if (atomInfo->hasCharge) {
322 <        sprintf(buffer,
323 <                "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
324 <                bn.c_str(),
325 <                atomInfo->pos[0],
326 <                atomInfo->pos[1],
327 <                atomInfo->pos[2],
328 <                atomInfo->charge,
329 <                atomInfo->dipole[0],
330 <                atomInfo->dipole[1],
331 <                atomInfo->dipole[2]);
332 <        } else {
333 <        sprintf(buffer,
334 <                "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
335 <                bn.c_str(),
336 <                atomInfo->pos[0],
337 <                atomInfo->pos[1],
338 <                atomInfo->pos[2],
339 <                atomInfo->dipole[0],
340 <                atomInfo->dipole[1],
341 <                atomInfo->dipole[2]);
342 <        }
343 <        frame.push_back(buffer);
314 >      if (doVectors_ && atomInfo->hasVector) {
315 >        sprintf(buffer, "%15.8f%15.8f%15.8f", atomInfo->vec[0],
316 >                atomInfo->vec[1], atomInfo->vec[2]);
317 >        line += buffer;
318        }
319 <    }
319 >      if (doVelocities_ && atomInfo->hasVelocity) {
320 >        sprintf(buffer, "%15.8f%15.8f%15.8f", atomInfo->vel[0],
321 >                atomInfo->vel[1], atomInfo->vel[2]);
322 >        line += buffer;
323 >      }
324 >      if (doForces_ && atomInfo->hasForce) {
325 >        sprintf(buffer, "%15.8f%15.8f%15.8f", atomInfo->frc[0],
326 >                atomInfo->frc[1], atomInfo->frc[2]);
327 >        line += buffer;
328 >      }      
329 >      frame.push_back(line);
330 >    }    
331    }
332  
333    bool XYZVisitor::isSelected(StuntDouble *sd) {
# Line 352 | Line 337 | namespace OpenMD {
337    void XYZVisitor::writeFrame(std::ostream &outStream) {
338      std::vector<std::string>::iterator i;
339      char buffer[1024];
340 <
340 >    
341      if (frame.size() == 0)
342        std::cerr << "Current Frame does not contain any atoms" << std::endl;
343 <
343 >    
344      //total number of atoms  
345      outStream << frame.size() << std::endl;
346 <
346 >    
347      //write comment line
348      Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
349      Mat3x3d box = currSnapshot->getHmat();
# Line 369 | Line 354 | namespace OpenMD {
354              box(0, 0), box(0, 1), box(0, 2),
355              box(1, 0), box(1, 1), box(1, 2),
356              box(2, 0), box(2, 1), box(2, 2));
357 <
357 >    
358      outStream << buffer << std::endl;
359 <
359 >    
360      for( i = frame.begin(); i != frame.end(); ++i )
361        outStream << *i << std::endl;
362    }
363 <
363 >  
364    std::string XYZVisitor::trimmedName(const std::string&atomTypeName) {    
365      return atomTypeName.substr(0, atomTypeName.find('-'));
366    }
367 <
383 <  std::string XYZVisitor::baseTypeName(AtomType* at) {
384 <    std::vector<AtomType*> ayb = at->allYourBase();
385 <    return ayb[ayb.size()-1]->getName();
386 <  }
387 <
367 >  
368    const std::string XYZVisitor::toString() {
369      char        buffer[65535];
370      std::string result;
371 <
371 >    
372      sprintf(buffer,
373              "------------------------------------------------------------------\n");
374      result += buffer;
375 <
375 >    
376      sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
377      result += buffer;
378 <
378 >    
379      sprintf(buffer,
380              "Visitor Description: assemble the atom data and output xyz file\n");
381      result += buffer;
# Line 403 | Line 383 | namespace OpenMD {
383      sprintf(buffer,
384              "------------------------------------------------------------------\n");
385      result += buffer;
386 <
386 >    
387      return result;
388    }
389 <
389 >  
390    //----------------------------------------------------------------------------//
391 <
391 >  
392    void PrepareVisitor::internalVisit(Atom *atom) {
393      GenericData *data;
394      AtomData *   atomData;
395 <
395 >    
396      //if visited property is  existed, remove it
397      data = atom->getPropertyByName("VISITED");
398 <
398 >    
399      if (data != NULL) {
400        atom->removeProperty("VISITED");
401      }
402 <
402 >    
403      //remove atomdata
404      data = atom->getPropertyByName("ATOMDATA");
405  
# Line 488 | Line 468 | namespace OpenMD {
468      visitorName = "WaterTypeVisitor";
469      waterTypeList.insert("TIP3P_RB_0");
470      waterTypeList.insert("TIP4P_RB_0");
471 +    waterTypeList.insert("TIP4P-Ew_RB_0");
472      waterTypeList.insert("TIP5P_RB_0");
473 +    waterTypeList.insert("TIP5P-E_RB_0");
474      waterTypeList.insert("SPCE_RB_0");
475 +    waterTypeList.insert("SPC_RB_0");
476    }
477  
478    void WaterTypeVisitor::visit(RigidBody *rb) {
# Line 502 | Line 485 | namespace OpenMD {
485      std::vector<AtomInfo *>::iterator i;
486  
487      rbName = rb->getType();
488 <
488 >    
489      if (waterTypeList.find(rbName) != waterTypeList.end()) {
490        myAtoms = rb->getAtoms();
491  
492        for( atomIter = myAtoms.begin(); atomIter != myAtoms.end();
493             ++atomIter ) {
494          data = (*atomIter)->getPropertyByName("ATOMDATA");
495 <
495 >        
496          if (data != NULL) {
497            atomData = dynamic_cast<AtomData *>(data);
498 <
498 >          
499            if (atomData == NULL)
500              continue;
501          } else
502            continue;
503 <
503 >        
504          for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
505               atomInfo = atomData->nextAtomInfo(i) ) {
506            atomInfo->atomTypeName = trimmedName(atomInfo->atomTypeName);

Comparing:
trunk/src/visitors/OtherVisitor.cpp (property svn:keywords), Revision 1390 by gezelter, Wed Nov 25 20:02:06 2009 UTC vs.
branches/development/src/visitors/OtherVisitor.cpp (property svn:keywords), Revision 1465 by chuckv, Fri Jul 9 23:08:25 2010 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines