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 3 by tim, Fri Sep 24 16:27:58 2004 UTC vs.
branches/development/src/visitors/OtherVisitor.cpp (file contents), Revision 1701 by kstocke1, Thu Apr 5 19:37:58 2012 UTC

# Line 1 | Line 1
1 + /*
2 + * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 + *
4 + * The University of Notre Dame grants you ("Licensee") a
5 + * non-exclusive, royalty free, license to use, modify and
6 + * redistribute this software in source and binary code form, provided
7 + * that the following conditions are met:
8 + *
9 + * 1. Redistributions of source code must retain the above copyright
10 + *    notice, this list of conditions and the following disclaimer.
11 + *
12 + * 2. Redistributions in binary form must reproduce the above copyright
13 + *    notice, this list of conditions and the following disclaimer in the
14 + *    documentation and/or other materials provided with the
15 + *    distribution.
16 + *
17 + * This software is provided "AS IS," without a warranty of any
18 + * kind. All express or implied conditions, representations and
19 + * warranties, including any implied warranty of merchantability,
20 + * fitness for a particular purpose or non-infringement, are hereby
21 + * excluded.  The University of Notre Dame and its licensors shall not
22 + * be liable for any damages suffered by licensee as a result of
23 + * using, modifying or distributing the software or its
24 + * derivatives. In no event will the University of Notre Dame or its
25 + * licensors be liable for any lost revenue, profit or data, or for
26 + * direct, indirect, special, consequential, incidental or punitive
27 + * damages, however caused and regardless of the theory of liability,
28 + * arising out of the use of or inability to use software, even if the
29 + * University of Notre Dame has been advised of the possibility of
30 + * such damages.
31 + *
32 + * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 + * research, please cite the appropriate papers when you publish your
34 + * work.  Good starting points are:
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]  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"
44   #include "primitives/DirectionalAtom.hpp"
45   #include "primitives/RigidBody.hpp"
46   #include "primitives/Molecule.hpp"
47   #include "brains/SimInfo.hpp"
48 < //----------------------------------------------------------------------------//
49 < void IgnoreVisitor::visit(Atom* atom){
50 <  if(isIgnoreType(atom->getType()))
48 > namespace OpenMD {
49 >
50 >  void WrappingVisitor::visit(Atom *atom) {
51      internalVisit(atom);
52 < }
52 >  }
53  
54 < void IgnoreVisitor::visit(DirectionalAtom* datom){
13 <  if(isIgnoreType(datom->getType()))
54 >  void WrappingVisitor::visit(DirectionalAtom *datom) {
55      internalVisit(datom);
56 < }
56 >  }
57  
58 < void IgnoreVisitor::visit(RigidBody* rb){
18 <  vector<Atom*> myAtoms;
19 <  vector<Atom*>::iterator atomIter;
20 <  AtomInfo* atomInfo;
21 <  
22 <  if(isIgnoreType(rb->getType())){
23 <    
58 >  void WrappingVisitor::visit(RigidBody *rb) {
59      internalVisit(rb);
60 +  }
61  
62 <    myAtoms = rb->getAtoms();    
63 <    
64 <    for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter)
65 <      internalVisit(*atomIter);
62 >  void WrappingVisitor::internalVisit(StuntDouble *sd) {
63 >    GenericData *                     data;
64 >    AtomData *                        atomData;
65 >    AtomInfo *                        atomInfo;
66 >    std::vector<AtomInfo *>::iterator i;
67  
68 <  }
32 <  
33 < }
68 >    data = sd->getPropertyByName("ATOMDATA");
69  
70 < bool IgnoreVisitor::isIgnoreType(const string& name){
71 <  return itList.find(name) != itList.end() ? true : false;
37 < }
70 >    if (data != NULL) {
71 >      atomData = dynamic_cast<AtomData *>(data);
72  
73 < void IgnoreVisitor::internalVisit(StuntDouble* sd){
74 <  GenericData* data;
75 <  data = sd->getProperty("IGNORE");
73 >      if (atomData == NULL)
74 >        return;
75 >    } else
76 >      return;
77  
78 <  //if this stuntdoulbe is already marked as ignore just skip it
44 <  if (data == NULL){
45 <    data = new GenericData;
46 <    data->setID("IGNORE");
47 <    sd->addProperty(data);
48 <  }
78 >    Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
79      
80 < }
80 >    for( atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i) ) {
81 >      Vector3d newPos = atomInfo->pos - origin_;
82 >      currSnapshot->wrapVector(newPos);
83 >      atomInfo->pos = newPos;
84 >    }
85 >  }
86  
87 < const string IgnoreVisitor::toString(){
88 <  char buffer[65535];
89 <  string result;
90 <  set<string>::iterator i;
87 >  void WrappingVisitor::update() {
88 >    if (useCom_){
89 >      origin_ = info->getCom();
90 >    }
91 >  }
92    
93 <  sprintf(buffer ,"------------------------------------------------------------------\n");
94 <  result += buffer;
93 >  const std::string WrappingVisitor::toString() {
94 >    char        buffer[65535];
95 >    std::string result;
96  
97 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
98 <  result += buffer;
97 >    sprintf(buffer,
98 >            "------------------------------------------------------------------\n");
99 >    result += buffer;
100  
101 <  sprintf(buffer ,"Visitor Description: ignore  stuntdoubles\n");
102 <  result += buffer;
101 >    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
102 >    result += buffer;
103  
104 <  //print the ignore type list
105 <  sprintf(buffer , "Ignore type list contains below types:\n");
106 <  result += buffer;
104 >    sprintf(buffer,
105 >            "Visitor Description: wrapping atoms back to periodic box\n");
106 >    result += buffer;
107  
108 <  for(i = itList.begin(); i != itList.end(); ++i){
109 <    sprintf(buffer ,"%s\t", i->c_str());
108 >    sprintf(buffer,
109 >            "------------------------------------------------------------------\n");
110      result += buffer;
111  
112 +    return result;
113    }
75  sprintf(buffer ,"\n");
76  result += buffer;
114  
115 <  sprintf(buffer ,"------------------------------------------------------------------\n");
79 <  result += buffer;
115 >  //----------------------------------------------------------------------------//
116  
117 <  return result;
118 < }
117 >  ReplicateVisitor::ReplicateVisitor(SimInfo *info, Vector3i opt) :
118 >    BaseVisitor() {
119 >      this->info = info;
120 >      visitorName = "ReplicateVisitor";
121 >      this->replicateOpt = opt;
122  
123 < //----------------------------------------------------------------------------//
123 >      //generate the replicate directions
124 >      for( int i = 0; i <= replicateOpt[0]; i++ ) {
125 >        for( int j = 0; j <= replicateOpt[1]; j++ ) {
126 >          for( int k = 0; k <= replicateOpt[2]; k++ ) {
127 >            //skip original frame
128 >            if (i == 0 && j == 0 && k == 0) {
129 >              continue;
130 >            } else {
131 >              dir.push_back(Vector3i(i, j, k));
132 >            }
133 >          }
134 >        }
135 >      }
136 >    
137 >    }
138  
139 < void WrappingVisitor::visit(Atom* atom){
140 <  internalVisit(atom);
141 < }
89 < void WrappingVisitor::visit(DirectionalAtom* datom){
90 <  internalVisit(datom);
91 < }
139 >  void ReplicateVisitor::visit(Atom *atom) {
140 >    internalVisit(atom);
141 >  }
142  
143 < void WrappingVisitor::visit(RigidBody* rb){
144 <  internalVisit(rb);
145 < }
143 >  void ReplicateVisitor::visit(DirectionalAtom *datom) {
144 >    internalVisit(datom);
145 >  }
146  
147 < void WrappingVisitor::internalVisit(StuntDouble* sd){
148 <  GenericData* data;
99 <  AtomData* atomData;
100 <  AtomInfo* atomInfo;
101 <  vector<AtomInfo*>::iterator i;
102 <
103 <  data = sd->getProperty("ATOMDATA");
104 <  if(data != NULL){
105 <    atomData = dynamic_cast<AtomData*>(data);  
106 <    if(atomData == NULL)
107 <      return;
147 >  void ReplicateVisitor::visit(RigidBody *rb) {
148 >    internalVisit(rb);
149    }
109  else
110    return;
150  
151 <  for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i))
152 <    info->wrapVector(atomInfo->pos);
151 >  void ReplicateVisitor::internalVisit(StuntDouble *sd) {
152 >    GenericData *          data;
153 >    AtomData *             atomData;
154  
155 <  
156 < }
155 >    //if there is not atom data, just skip it
156 >    data = sd->getPropertyByName("ATOMDATA");
157  
158 < const string WrappingVisitor::toString(){
159 <  char buffer[65535];
120 <  string result;
121 <  
122 <  sprintf(buffer ,"------------------------------------------------------------------\n");
123 <  result += buffer;
158 >    if (data != NULL) {
159 >      atomData = dynamic_cast<AtomData *>(data);
160  
161 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
162 <  result += buffer;
161 >      if (atomData == NULL) {
162 >        return;
163 >      }
164 >    } else {
165 >      return;
166 >    }
167  
168 <  sprintf(buffer ,"Visitor Description: wrapping atoms back to periodic box\n");
169 <  result += buffer;
130 <
131 <  sprintf(buffer,"------------------------------------------------------------------\n");
132 <  result += buffer;
168 >    Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
169 >    Mat3x3d box = currSnapshot->getHmat();
170  
171 <  return result;
135 < }
171 >    std::vector<AtomInfo *> atomInfoList = atomData->getData();
172  
173 < //----------------------------------------------------------------------------//
173 >    replicate(atomInfoList, atomData, box);
174 >  }
175  
176 < ReplicateVisitor::ReplicateVisitor(SimInfo* info, IntVec3 opt) : BaseVisitor(){
177 <  this->info = info;
178 <  visitorName = "ReplicateVisitor";
179 <  this->replicateOpt = opt;
143 <  //generate the replicate directions
144 <  for(int i = 0; i <= replicateOpt[0]; i ++)
145 <    for(int j = 0; j <= replicateOpt[1]; j ++)
146 <      for(int k = 0; k <= replicateOpt[2]; k ++)
147 <        //skip original frame
148 <        if(i == 0 && j ==0 && k ==0)
149 <          continue;
150 <        else
151 <          dir.push_back(IntVec3(i, j, k));
152 <  
153 < }
154 < void ReplicateVisitor::visit(Atom* atom){
155 <  internalVisit(atom);
156 < }
157 < void ReplicateVisitor::visit(DirectionalAtom* datom){
158 <  internalVisit(datom);
159 < }
176 >  void ReplicateVisitor::replicate(std::vector<AtomInfo *>&infoList, AtomData *data, const Mat3x3d& box) {
177 >    AtomInfo* newAtomInfo;
178 >    std::vector<Vector3i>::iterator dirIter;
179 >    std::vector<AtomInfo *>::iterator i;
180  
181 < void ReplicateVisitor::visit(RigidBody* rb){
182 <  internalVisit(rb);
183 < }
181 >    for( dirIter = dir.begin(); dirIter != dir.end(); ++dirIter ) {
182 >      for( i = infoList.begin(); i != infoList.end(); i++ ) {
183 >        newAtomInfo = new AtomInfo();
184 >        *newAtomInfo = *(*i);
185  
186 < void ReplicateVisitor::internalVisit(StuntDouble* sd){
187 <  GenericData* data;
188 <  AtomData* atomData;
189 <  AtomInfo* atomInfo;
190 <  double box[3][3];
191 <  vector<AtomInfo*> atomInfoList;
171 <  IntVec3 dir;
172 <  
173 <  //if there is not atom data, just skip it
174 <  data = sd->getProperty("ATOMDATA");
175 <  if(data != NULL){
176 <    atomData = dynamic_cast<AtomData*>(data);  
177 <    if(atomData == NULL)
178 <      return;
186 >        for( int j = 0; j < 3; j++ )
187 >          newAtomInfo->pos[j] += (*dirIter)[0]*box(j, 0) + (*dirIter)[1]*box(j, 1) + (*dirIter)[2]*box(j, 2);
188 >
189 >        data->addAtomInfo(newAtomInfo);
190 >      }
191 >    } // end for(dirIter)  
192    }
180  else
181    return;
193  
194 <  
195 <  info->getBoxM(box);
194 >  const std::string ReplicateVisitor::toString() {
195 >    char                            buffer[65535];
196 >    std::string                     result;
197 >    std::set<std::string>::iterator i;
198  
199 <  atomInfoList = atomData->getData();
200 <  
201 <  replicate(atomInfoList, atomData, box);
199 >    sprintf(buffer,
200 >            "------------------------------------------------------------------\n");
201 >    result += buffer;
202  
203 < }
203 >    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
204 >    result += buffer;
205  
206 < void ReplicateVisitor::replicate(vector<AtomInfo*>& infoList, AtomData* data, double boxM[3][3]){
207 <  AtomInfo * newAtomInfo;
208 <  vector<IntVec3>::iterator dirIter;
195 <  vector<AtomInfo*>::iterator i;
196 <  
197 <  for(dirIter = dir.begin(); dirIter != dir.end(); ++dirIter){
198 <    for(i = infoList.begin(); i != infoList.end(); i++){
199 <      newAtomInfo = new AtomInfo;
200 <      *newAtomInfo = *(*i);    
206 >    sprintf(buffer,
207 >            "Visitor Description: replicate the atoms in different direction\n");
208 >    result += buffer;
209  
210 <      for(int j = 0; j < 3; j++)
211 <        newAtomInfo->pos[j] +=   (*dirIter)[0] * boxM[j][0] + (*dirIter)[1]* boxM[j][1] + (*dirIter)[2] * boxM[j][2];
210 >    //print the replicate direction
211 >    sprintf(buffer, "repeatX = %d:\n", replicateOpt[0]);
212 >    result += buffer;
213  
214 <      data->addAtomInfo(newAtomInfo);
215 <    }
207 <  }// end for(dirIter)  
208 < }
214 >    sprintf(buffer, "repeatY = %d:\n", replicateOpt[1]);
215 >    result += buffer;
216  
217 < const string ReplicateVisitor::toString(){
218 <  char buffer[65535];
212 <  string result;
213 <  set<string>::iterator i;
214 <  
215 <  sprintf(buffer ,"------------------------------------------------------------------\n");
216 <  result += buffer;
217 >    sprintf(buffer, "repeatZ = %d:\n", replicateOpt[2]);
218 >    result += buffer;
219  
220 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
221 <  result += buffer;
220 >    sprintf(buffer,
221 >            "------------------------------------------------------------------\n");
222 >    result += buffer;
223  
224 <  sprintf(buffer ,"Visitor Description: replicate the atoms in different direction\n");
225 <  result += buffer;
223 <  
224 <  //print the replicate direction
225 <  sprintf(buffer , "repeatX = %d:\n", replicateOpt[0]);
226 <  result += buffer;
224 >    return result;
225 >  }
226  
227 <  sprintf(buffer , "repeatY = %d:\n", replicateOpt[1]);
229 <  result += buffer;
227 >  //------------------------------------------------------------------------//
228  
229 <  sprintf(buffer , "repeatZ = %d:\n", replicateOpt[2]);
230 <  result += buffer;
231 <
232 <
233 <  sprintf(buffer,"------------------------------------------------------------------\n");
234 <  result += buffer;
235 <
236 <  return result;
237 < }
238 <
239 < //----------------------------------------------------------------------------//
240 <
241 < XYZVisitor::XYZVisitor(SimInfo* info,  bool printDipole) : BaseVisitor(){
242 <  this->info = info;
245 <  visitorName = "XYZVisitor";
246 <  this->printDipole = printDipole;
247 < }
248 <
249 < void XYZVisitor::visit(Atom* atom){
250 <  if(!isIgnore(atom))
251 <    internalVisit(atom);
252 < }
253 <
254 < void XYZVisitor::visit(DirectionalAtom* datom){
255 <  if(!isIgnore(datom))
256 <    internalVisit(datom);
257 < }
258 <
259 < void XYZVisitor::visit(RigidBody* rb){
260 <  if(!isIgnore(rb))
261 <    internalVisit(rb);
262 <
263 < }
264 <
265 < void XYZVisitor::internalVisit(StuntDouble* sd){
266 <  GenericData* data;
267 <  AtomData* atomData;
268 <  AtomInfo* atomInfo;
269 <  vector<AtomInfo*>::iterator i;
270 <  char buffer[1024];
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 >  }
243    
244 <  //if there is not atom data, just skip it
245 <  data = sd->getProperty("ATOMDATA");
246 <  if(data != NULL){
247 <    atomData = dynamic_cast<AtomData*>(data);  
248 <    if(atomData == NULL)
249 <      return;
244 >  XYZVisitor::XYZVisitor(SimInfo *info, const std::string& script) :
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 <  else
259 <    return;
258 >    
259 >  void XYZVisitor::visit(Atom *atom) {
260 >    if (isSelected(atom))
261 >      internalVisit(atom);
262 >  }
263  
264 <  for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){
265 <
266 <    if(printDipole)
267 <      sprintf(buffer, "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
268 <                  atomInfo->AtomType.c_str(),
269 <                  atomInfo->pos[0],
270 <                  atomInfo->pos[1],
271 <                  atomInfo->pos[2],
272 <                  atomInfo->dipole[0],
273 <                  atomInfo->dipole[1],
274 <                  atomInfo->dipole[2]);
275 <    else
276 <      sprintf(buffer, "%s%15.8f%15.8f%15.8f",
277 <                  atomInfo->AtomType.c_str(),
278 <                  atomInfo->pos[0],
297 <                  atomInfo->pos[1],
298 <                  atomInfo->pos[2]);  
299 <
300 <    frame.push_back(buffer);
301 <              
264 >  void XYZVisitor::visit(DirectionalAtom *datom) {
265 >    if (isSelected(datom))
266 >      internalVisit(datom);
267 >  }
268 >  
269 >  void XYZVisitor::visit(RigidBody *rb) {
270 >    if (isSelected(rb))
271 >      internalVisit(rb);
272 >  }
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    }
303
304 }
305
306 bool XYZVisitor::isIgnore(StuntDouble* sd){
307  GenericData* data;
280    
281 <  data = sd->getProperty("IGNORE");
282 <  return data ==NULL ? false : true;
283 < }
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 >    
288 >    //if there is not atom data, just skip it
289 >    data = sd->getPropertyByName("ATOMDATA");
290 >    
291 >    if (data != NULL) {
292 >      atomData = dynamic_cast<AtomData *>(data);
293 >      
294 >      if (atomData == NULL)
295 >        return;
296 >    } else
297 >      return;
298  
299 < void XYZVisitor::writeFrame(ostream& outStream){
300 <  vector<string>::iterator i;
301 <  double box[3][3];
302 <  char buffer[1024];
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 >      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 >      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 <  if(frame.size() == 0)
335 <    cerr << "Current Frame does not contain any atoms" << endl;
334 >  bool XYZVisitor::isSelected(StuntDouble *sd) {
335 >    return seleMan.isSelected(sd);
336 >  }
337  
338 <  //total number of atoms  
339 <  outStream << frame.size() << endl;
340 <
341 <  //write comment line
342 <  info->getBoxM(box);
343 <  sprintf(buffer,"%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f",
344 <              info->getTime(),
345 <              box[0][0], box[0][1], box[0][2],
346 <              box[1][0], box[1][1], box[1][2],
347 <              box[2][0], box[2][1], box[2][2]);
348 <
349 <  outStream << buffer << endl;  
350 <
351 <  for(i = frame.begin(); i != frame.end(); ++i)
352 <    outStream << *i << endl;
353 < }
354 <
355 < const string XYZVisitor::toString(){
356 <  char buffer[65535];
357 <  string result;
338 >  void XYZVisitor::writeFrame(std::ostream &outStream) {
339 >    std::vector<std::string>::iterator i;
340 >    char buffer[1024];
341 >    
342 >    if (frame.size() == 0)
343 >      std::cerr << "Current Frame does not contain any atoms" << std::endl;
344 >    
345 >    //total number of atoms  
346 >    outStream << frame.size() << std::endl;
347 >    
348 >    //write comment line
349 >    Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
350 >    Mat3x3d box = currSnapshot->getHmat();
351 >    
352 >    sprintf(buffer,
353 >            "%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f",
354 >            currSnapshot->getTime(),
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 >    
359 >    outStream << buffer << std::endl;
360 >    
361 >    for( i = frame.begin(); i != frame.end(); ++i )
362 >      outStream << *i << std::endl;
363 >  }
364    
365 <  sprintf(buffer ,"------------------------------------------------------------------\n");
366 <  result += buffer;
344 <
345 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
346 <  result += buffer;
347 <
348 <  sprintf(buffer ,"Visitor Description: assemble the atom data and output xyz file\n");
349 <  result += buffer;
350 <
351 <  sprintf(buffer,"------------------------------------------------------------------\n");
352 <  result += buffer;
353 <
354 <  return result;
355 < }
356 <
357 < //----------------------------------------------------------------------------//
358 <
359 < void PrepareVisitor::internalVisit(Atom * atom){
360 <  GenericData* data;
361 <  AtomData* atomData;
362 <
363 <  //if visited property is  existed, remove it
364 <  data = atom->getProperty("VISITED");
365 <  if(data != NULL){
366 <    atom->removeProperty("VISITED");  
365 >  std::string XYZVisitor::trimmedName(const std::string&atomTypeName) {    
366 >    return atomTypeName.substr(0, atomTypeName.find('-'));
367    }
368 +  
369 +  const std::string XYZVisitor::toString() {
370 +    char        buffer[65535];
371 +    std::string result;
372 +    
373 +    sprintf(buffer,
374 +            "------------------------------------------------------------------\n");
375 +    result += buffer;
376 +    
377 +    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
378 +    result += buffer;
379 +    
380 +    sprintf(buffer,
381 +            "Visitor Description: assemble the atom data and output xyz file\n");
382 +    result += buffer;
383  
384 <  //remove atomdata
385 <  data = atom->getProperty("ATOMDATA");
386 <  if(data != NULL){
387 <    atomData = dynamic_cast<AtomData*>(data);  
388 <    if(atomData != NULL)
374 <      atom->removeProperty("ATOMDATA");
384 >    sprintf(buffer,
385 >            "------------------------------------------------------------------\n");
386 >    result += buffer;
387 >    
388 >    return result;
389    }
390    
391 < }
378 <
379 < void PrepareVisitor::internalVisit(RigidBody * rb){
380 <  GenericData* data;
381 <  AtomData* atomData;
382 <  vector<Atom*> myAtoms;
383 <  vector<Atom*>::iterator atomIter;
391 >  //----------------------------------------------------------------------------//
392    
393 <  //if visited property is  existed, remove it
394 <  data = rb->getProperty("VISITED");
395 <  if(data != NULL){
396 <    rb->removeProperty("VISITED");  
397 <  }
393 >  void PrepareVisitor::internalVisit(Atom *atom) {
394 >    GenericData *data;
395 >    AtomData *   atomData;
396 >    
397 >    //if visited property is  existed, remove it
398 >    data = atom->getPropertyByName("VISITED");
399 >    
400 >    if (data != NULL) {
401 >      atom->removeProperty("VISITED");
402 >    }
403 >    
404 >    //remove atomdata
405 >    data = atom->getPropertyByName("ATOMDATA");
406  
407 <  //remove atomdata
408 <  data = rb->getProperty("ATOMDATA");
409 <  if(data != NULL){
410 <    atomData = dynamic_cast<AtomData*>(data);  
411 <    if(atomData != NULL)
412 <      rb->removeProperty("ATOMDATA");
407 >    if (data != NULL) {
408 >      atomData = dynamic_cast<AtomData *>(data);
409 >
410 >      if (atomData != NULL)
411 >        atom->removeProperty("ATOMDATA");
412 >    }
413    }
414  
415 <  myAtoms = rb->getAtoms();
416 <    
417 <  for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter)
418 <   internalVisit (*atomIter);  
419 < }
415 >  void PrepareVisitor::internalVisit(RigidBody *rb) {
416 >    GenericData* data;
417 >    AtomData* atomData;
418 >    std::vector<Atom *> myAtoms;
419 >    std::vector<Atom *>::iterator atomIter;
420  
421 < const string PrepareVisitor::toString(){
422 <  char buffer[65535];
407 <  string result;
408 <  
409 <  sprintf(buffer ,"------------------------------------------------------------------\n");
410 <  result += buffer;
421 >    //if visited property is  existed, remove it
422 >    data = rb->getPropertyByName("VISITED");
423  
424 <  sprintf(buffer ,"Visitor name: %s", visitorName.c_str());
425 <  result += buffer;
424 >    if (data != NULL) {
425 >      rb->removeProperty("VISITED");
426 >    }
427  
428 <  sprintf(buffer ,"Visitor Description: prepare for operation of other vistors\n");
429 <  result += buffer;
428 >    //remove atomdata
429 >    data = rb->getPropertyByName("ATOMDATA");
430  
431 <  sprintf(buffer ,"------------------------------------------------------------------\n");
432 <  result += buffer;
431 >    if (data != NULL) {
432 >      atomData = dynamic_cast<AtomData *>(data);
433  
434 <  return result;
435 < }
434 >      if (atomData != NULL)
435 >        rb->removeProperty("ATOMDATA");
436 >    }
437  
438 < //----------------------------------------------------------------------------//
438 >    myAtoms = rb->getAtoms();
439  
440 < WaterTypeVisitor:: WaterTypeVisitor(){
441 <  visitorName = "WaterTypeVisitor";
442 <  waterTypeList.insert("TIP3P_RB_0");
429 <  waterTypeList.insert("TIP4P_RB_0");
430 <  waterTypeList.insert("TIP5P_RB_0");
431 <  waterTypeList.insert("SPCE_RB_0");  
432 < }
440 >    for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter )
441 >      internalVisit(*atomIter);
442 >  }
443  
444 +  const std::string PrepareVisitor::toString() {
445 +    char buffer[65535];
446 +    std::string result;
447 +
448 +    sprintf(buffer,
449 +            "------------------------------------------------------------------\n");
450 +    result += buffer;
451 +
452 +    sprintf(buffer, "Visitor name: %s", visitorName.c_str());
453 +    result += buffer;
454 +
455 +    sprintf(buffer,
456 +            "Visitor Description: prepare for operation of other vistors\n");
457 +    result += buffer;
458 +
459 +    sprintf(buffer,
460 +            "------------------------------------------------------------------\n");
461 +    result += buffer;
462 +
463 +    return result;
464 +  }
465  
466 < void WaterTypeVisitor:: visit(RigidBody* rb){
436 <  string rbName;
437 <  vector<Atom*> myAtoms;
438 <  vector<Atom*>::iterator atomIter;
439 <  GenericData* data;
440 <  AtomData* atomData;
441 <  AtomInfo* atomInfo;
442 <  vector<AtomInfo*>::iterator i;
443 <  
444 <  rbName = rb->getType();
466 >  //----------------------------------------------------------------------------//
467  
468 <  if(waterTypeList.find(rbName) != waterTypeList.end()){
468 >  WaterTypeVisitor::WaterTypeVisitor() {
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 >    waterTypeList.insert("POL3_RB_0");
478 >  }
479  
480 <    myAtoms = rb->getAtoms();    
481 <    for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter){
480 >  void WaterTypeVisitor::visit(RigidBody *rb) {
481 >    std::string rbName;
482 >    std::vector<Atom *> myAtoms;
483 >    std::vector<Atom *>::iterator atomIter;
484 >    GenericData* data;
485 >    AtomData* atomData;
486 >    AtomInfo* atomInfo;
487 >    std::vector<AtomInfo *>::iterator i;
488  
489 <      data = (*atomIter)->getProperty("ATOMDATA");
490 <      if(data != NULL){
491 <        atomData = dynamic_cast<AtomData*>(data);  
492 <        if(atomData == NULL)
455 <          continue;
456 <      }
457 <      else
458 <        continue;
459 <      
460 <      for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){
461 <        replaceType(atomInfo->AtomType);
462 <      }//end for(atomInfo)
489 >    rbName = rb->getType();
490 >    
491 >    if (waterTypeList.find(rbName) != waterTypeList.end()) {
492 >      myAtoms = rb->getAtoms();
493  
494 <    }//end for(atomIter)
495 <      
496 <  }//end if (waterTypeList.find(rbName) != waterTypeList.end())
497 <  
498 < }
494 >      for( atomIter = myAtoms.begin(); atomIter != myAtoms.end();
495 >           ++atomIter ) {
496 >        data = (*atomIter)->getPropertyByName("ATOMDATA");
497 >        
498 >        if (data != NULL) {
499 >          atomData = dynamic_cast<AtomData *>(data);
500 >          
501 >          if (atomData == NULL)
502 >            continue;
503 >        } else
504 >          continue;
505 >        
506 >        for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
507 >             atomInfo = atomData->nextAtomInfo(i) ) {
508 >          atomInfo->atomTypeName = trimmedName(atomInfo->atomTypeName);
509 >        } //end for(atomInfo)
510 >      }     //end for(atomIter)
511 >    }         //end if (waterTypeList.find(rbName) != waterTypeList.end())
512 >  }
513  
514 < void WaterTypeVisitor:: replaceType(string& atomType){
515 <  atomType = atomType.substr(0, atomType.find('_'));
516 < }
514 >  std::string WaterTypeVisitor::trimmedName(const std::string&atomTypeName) {
515 >    return atomTypeName.substr(0, atomTypeName.find('_'));
516 >  }
517  
518 < const string WaterTypeVisitor:: toString(){
519 <  char buffer[65535];
520 <  string result;
477 <  
478 <  sprintf(buffer ,"------------------------------------------------------------------\n");
479 <  result += buffer;
518 >  const std::string WaterTypeVisitor::toString() {
519 >    char buffer[65535];
520 >    std::string result;
521  
522 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
523 <  result += buffer;
522 >    sprintf(buffer,
523 >            "------------------------------------------------------------------\n");
524 >    result += buffer;
525  
526 <  sprintf(buffer ,"Visitor Description: Replace the atom type in water model\n");
527 <  result += buffer;
526 >    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
527 >    result += buffer;
528  
529 <  sprintf(buffer ,"------------------------------------------------------------------\n");
530 <  result += buffer;
529 >    sprintf(buffer,
530 >            "Visitor Description: Replace the atom type in water model\n");
531 >    result += buffer;
532  
533 <  return result;
534 < }
533 >    sprintf(buffer,
534 >            "------------------------------------------------------------------\n");
535 >    result += buffer;
536  
537 +    return result;
538 +  }
539 +
540 + } //namespace OpenMD

Comparing:
trunk/src/visitors/OtherVisitor.cpp (property svn:keywords), Revision 3 by tim, Fri Sep 24 16:27:58 2004 UTC vs.
branches/development/src/visitors/OtherVisitor.cpp (property svn:keywords), Revision 1701 by kstocke1, Thu Apr 5 19:37:58 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines