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 1874 by gezelter, Wed May 15 15:09:35 2013 UTC

# Line 35 | Line 35
35   *                                                                      
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).                        
38 > * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).          
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 44 | Line 45
45   #include "primitives/RigidBody.hpp"
46   #include "primitives/Molecule.hpp"
47   #include "brains/SimInfo.hpp"
48 + #include "brains/Thermo.hpp"
49 +
50   namespace OpenMD {
51  
52    void WrappingVisitor::visit(Atom *atom) {
# Line 76 | Line 79 | namespace OpenMD {
79  
80      Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
81      
82 <    for( atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i) ) {
82 >    for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
83 >         atomInfo = atomData->nextAtomInfo(i) ) {
84 >
85        Vector3d newPos = atomInfo->pos - origin_;
86        currSnapshot->wrapVector(newPos);
87        atomInfo->pos = newPos;
88 +
89      }
90    }
91  
92    void WrappingVisitor::update() {
93      if (useCom_){
94 <      origin_ = info->getCom();
94 >      Thermo thermo(info);
95 >      origin_ = thermo.getCom();
96      }
97    }
98    
# Line 178 | Line 185 | namespace OpenMD {
185      std::vector<AtomInfo *>::iterator i;
186  
187      for( dirIter = dir.begin(); dirIter != dir.end(); ++dirIter ) {
188 <      for( i = infoList.begin(); i != infoList.end(); i++ ) {
188 >      for( i = infoList.begin(); i != infoList.end(); ++i ) {
189          newAtomInfo = new AtomInfo();
190          *newAtomInfo = *(*i);
191  
# Line 193 | Line 200 | namespace OpenMD {
200    const std::string ReplicateVisitor::toString() {
201      char                            buffer[65535];
202      std::string                     result;
196    std::set<std::string>::iterator i;
203  
204 +
205      sprintf(buffer,
206 <            "------------------------------------------------------------------\n");
206 >            "--------------------------------------------------------------\n");
207      result += buffer;
208  
209      sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
# Line 217 | Line 224 | namespace OpenMD {
224      result += buffer;
225  
226      sprintf(buffer,
227 <            "------------------------------------------------------------------\n");
227 >            "--------------------------------------------------------------\n");
228      result += buffer;
229  
230      return result;
231    }
232  
233 <  //----------------------------------------------------------------------------//
233 >  //------------------------------------------------------------------------//
234  
235 <  XYZVisitor::XYZVisitor(SimInfo *info) :
236 <    BaseVisitor(), seleMan(info), evaluator(info){
237 <      this->info = info;
238 <      visitorName = "XYZVisitor";
239 <
240 <      evaluator.loadScriptString("select all");
241 <
242 <      if (!evaluator.isDynamic()) {
243 <        seleMan.setSelectionSet(evaluator.evaluate());
244 <      }
245 <      posOnly_ = false;
235 >  XYZVisitor::XYZVisitor(SimInfo *info) : BaseVisitor(), seleMan(info),
236 >                                          evaluator(info), doPositions_(true),
237 >                                          doVelocities_(false),
238 >                                          doForces_(false), doVectors_(false),
239 >                                          doCharges_(false),
240 >                                          doElectricFields_(false) {
241 >    this->info = info;
242 >    visitorName = "XYZVisitor";
243 >    
244 >    evaluator.loadScriptString("select all");
245 >    
246 >    if (!evaluator.isDynamic()) {
247 >      seleMan.setSelectionSet(evaluator.evaluate());
248      }
249 <
249 >  }
250 >  
251    XYZVisitor::XYZVisitor(SimInfo *info, const std::string& script) :
252 <    BaseVisitor(), seleMan(info), evaluator(info) {
253 <      this->info = info;
254 <      visitorName = "XYZVisitor";
255 <
256 <      evaluator.loadScriptString(script);
257 <
258 <      if (!evaluator.isDynamic()) {
259 <        seleMan.setSelectionSet(evaluator.evaluate());
260 <      }
261 <      posOnly_ = false;
252 >    BaseVisitor(), seleMan(info), evaluator(info), doPositions_(true),
253 >    doVelocities_(false), doForces_(false), doVectors_(false),
254 >    doCharges_(false), doElectricFields_(false) {
255 >    
256 >    this->info = info;
257 >    visitorName = "XYZVisitor";
258 >    
259 >    evaluator.loadScriptString(script);
260 >    
261 >    if (!evaluator.isDynamic()) {
262 >      seleMan.setSelectionSet(evaluator.evaluate());
263      }
264 +  }
265      
266    void XYZVisitor::visit(Atom *atom) {
267      if (isSelected(atom))
# Line 260 | Line 272 | namespace OpenMD {
272      if (isSelected(datom))
273        internalVisit(datom);
274    }
275 <
275 >  
276    void XYZVisitor::visit(RigidBody *rb) {
277      if (isSelected(rb))
278        internalVisit(rb);
279    }
280 <
280 >  
281    void XYZVisitor::update() {
282      //if dynamic, we need to re-evaluate the selection
283      if (evaluator.isDynamic()) {
284        seleMan.setSelectionSet(evaluator.evaluate());
285      }
286    }
287 <
287 >  
288    void XYZVisitor::internalVisit(StuntDouble *sd) {
289      GenericData *                     data;
290      AtomData *                        atomData;
291      AtomInfo *                        atomInfo;
292      std::vector<AtomInfo *>::iterator i;
293      char                              buffer[1024];
294 <
294 >    
295      //if there is not atom data, just skip it
296      data = sd->getPropertyByName("ATOMDATA");
297 <
297 >    
298      if (data != NULL) {
299        atomData = dynamic_cast<AtomData *>(data);
300 <
300 >      
301        if (atomData == NULL)
302          return;
303      } else
304        return;
305  
306 <    AtomType* at = dynamic_cast<Atom *>(sd)->getAtomType();
307 <    std::string bn = baseTypeName(at);
308 <
309 <    if (posOnly_){
310 <      for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
311 <           atomInfo = atomData->nextAtomInfo(i) ) {
312 <        if (atomInfo->hasCharge) {
313 <          sprintf(buffer,
314 <                  "%s%15.8f%15.8f%15.8f%15.8f",
315 <                  bn.c_str(),
316 <                  atomInfo->pos[0],
317 <                  atomInfo->pos[1],
318 <                  atomInfo->pos[2],
319 <                  atomInfo->charge);
320 <        } 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);
306 >    for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
307 >         atomInfo = atomData->nextAtomInfo(i) ) {
308 >    
309 >      std::string line;
310 >      sprintf(buffer, "%s", atomInfo->atomTypeName.c_str());
311 >      line += buffer;
312 >      
313 >      if (doPositions_){
314 >        sprintf(buffer, "%15.8f%15.8f%15.8f", atomInfo->pos[0],
315 >                atomInfo->pos[1], atomInfo->pos[2]);
316 >        line += buffer;
317 >      }      
318 >      if (doCharges_ && atomInfo->hasCharge) {
319 >        sprintf(buffer, "%15.8f", atomInfo->charge);
320 >        line += buffer;
321        }
322 <    }else{
323 <      for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
324 <           atomInfo = atomData->nextAtomInfo(i) ) {
325 <        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);
322 >      if (doVectors_ && atomInfo->hasVector) {
323 >        sprintf(buffer, "%15.8f%15.8f%15.8f", atomInfo->vec[0],
324 >                atomInfo->vec[1], atomInfo->vec[2]);
325 >        line += buffer;
326        }
327 <    }
327 >      if (doVelocities_ && atomInfo->hasVelocity) {
328 >        sprintf(buffer, "%15.8f%15.8f%15.8f", atomInfo->vel[0],
329 >                atomInfo->vel[1], atomInfo->vel[2]);
330 >        line += buffer;
331 >      }
332 >      if (doForces_ && atomInfo->hasForce) {
333 >        sprintf(buffer, "%15.8f%15.8f%15.8f", atomInfo->frc[0],
334 >                atomInfo->frc[1], atomInfo->frc[2]);
335 >        line += buffer;
336 >      }      
337 >      if (doElectricFields_ && atomInfo->hasElectricField) {
338 >        sprintf(buffer, "%15.8f%15.8f%15.8f", atomInfo->eField[0],
339 >                atomInfo->eField[1], atomInfo->eField[2]);
340 >        line += buffer;
341 >      }      
342 >      frame.push_back(line);
343 >    }    
344    }
345  
346    bool XYZVisitor::isSelected(StuntDouble *sd) {
# Line 352 | Line 350 | namespace OpenMD {
350    void XYZVisitor::writeFrame(std::ostream &outStream) {
351      std::vector<std::string>::iterator i;
352      char buffer[1024];
353 <
354 <    if (frame.size() == 0)
353 >    
354 >    if (frame.empty())
355        std::cerr << "Current Frame does not contain any atoms" << std::endl;
356 <
356 >    
357      //total number of atoms  
358      outStream << frame.size() << std::endl;
359 <
359 >    
360      //write comment line
361      Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
362      Mat3x3d box = currSnapshot->getHmat();
# Line 369 | Line 367 | namespace OpenMD {
367              box(0, 0), box(0, 1), box(0, 2),
368              box(1, 0), box(1, 1), box(1, 2),
369              box(2, 0), box(2, 1), box(2, 2));
370 <
370 >    
371      outStream << buffer << std::endl;
372 <
372 >    
373      for( i = frame.begin(); i != frame.end(); ++i )
374        outStream << *i << std::endl;
375    }
376 <
376 >  
377    std::string XYZVisitor::trimmedName(const std::string&atomTypeName) {    
378      return atomTypeName.substr(0, atomTypeName.find('-'));
379    }
380 <
383 <  std::string XYZVisitor::baseTypeName(AtomType* at) {
384 <    std::vector<AtomType*> ayb = at->allYourBase();
385 <    return ayb[ayb.size()-1]->getName();
386 <  }
387 <
380 >  
381    const std::string XYZVisitor::toString() {
382      char        buffer[65535];
383      std::string result;
384 <
384 >    
385      sprintf(buffer,
386              "------------------------------------------------------------------\n");
387      result += buffer;
388 <
388 >    
389      sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
390      result += buffer;
391 <
391 >    
392      sprintf(buffer,
393              "Visitor Description: assemble the atom data and output xyz file\n");
394      result += buffer;
# Line 403 | Line 396 | namespace OpenMD {
396      sprintf(buffer,
397              "------------------------------------------------------------------\n");
398      result += buffer;
399 <
399 >    
400      return result;
401    }
402 <
402 >  
403    //----------------------------------------------------------------------------//
404 <
404 >  
405    void PrepareVisitor::internalVisit(Atom *atom) {
406      GenericData *data;
407 <    AtomData *   atomData;
415 <
407 >    
408      //if visited property is  existed, remove it
409      data = atom->getPropertyByName("VISITED");
410 <
410 >    
411      if (data != NULL) {
412        atom->removeProperty("VISITED");
413      }
414 <
414 >    
415      //remove atomdata
416      data = atom->getPropertyByName("ATOMDATA");
417  
418      if (data != NULL) {
419 <      atomData = dynamic_cast<AtomData *>(data);
419 >      AtomData* atomData = dynamic_cast<AtomData *>(data);
420  
421        if (atomData != NULL)
422          atom->removeProperty("ATOMDATA");
# Line 488 | Line 480 | namespace OpenMD {
480      visitorName = "WaterTypeVisitor";
481      waterTypeList.insert("TIP3P_RB_0");
482      waterTypeList.insert("TIP4P_RB_0");
483 +    waterTypeList.insert("TIP4P-Ew_RB_0");
484      waterTypeList.insert("TIP5P_RB_0");
485 +    waterTypeList.insert("TIP5P-E_RB_0");
486      waterTypeList.insert("SPCE_RB_0");
487 +    waterTypeList.insert("SPC_RB_0");
488    }
489  
490    void WaterTypeVisitor::visit(RigidBody *rb) {
491      std::string rbName;
492      std::vector<Atom *> myAtoms;
493      std::vector<Atom *>::iterator atomIter;
499    GenericData* data;
500    AtomData* atomData;
501    AtomInfo* atomInfo;
494      std::vector<AtomInfo *>::iterator i;
495 +    AtomData* atomData;
496  
497      rbName = rb->getType();
498 <
498 >    
499      if (waterTypeList.find(rbName) != waterTypeList.end()) {
500        myAtoms = rb->getAtoms();
501 <
501 >      
502        for( atomIter = myAtoms.begin(); atomIter != myAtoms.end();
503             ++atomIter ) {
504 <        data = (*atomIter)->getPropertyByName("ATOMDATA");
505 <
504 >        GenericData* data = (*atomIter)->getPropertyByName("ATOMDATA");
505 >        
506          if (data != NULL) {
507            atomData = dynamic_cast<AtomData *>(data);
508 <
508 >          
509            if (atomData == NULL)
510              continue;
511          } else
512            continue;
513 <
514 <        for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
513 >        
514 >        for( AtomInfo* atomInfo = atomData->beginAtomInfo(i); atomInfo;
515               atomInfo = atomData->nextAtomInfo(i) ) {
516            atomInfo->atomTypeName = trimmedName(atomInfo->atomTypeName);
517 <        } //end for(atomInfo)
518 <      }     //end for(atomIter)
519 <    }         //end if (waterTypeList.find(rbName) != waterTypeList.end())
517 >        }
518 >      }  
519 >    }
520    }
521  
522    std::string WaterTypeVisitor::trimmedName(const std::string&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 1874 by gezelter, Wed May 15 15:09:35 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines