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 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines