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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines