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.
Revision 1455 by gezelter, Thu Jun 24 20:44:18 2010 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]  Vardeman & Gezelter, in progress (2009).                        
40 + */
41 + #include "selection/SelectionManager.hpp"
42   #include "visitors/OtherVisitor.hpp"
43   #include "primitives/DirectionalAtom.hpp"
44   #include "primitives/RigidBody.hpp"
45   #include "primitives/Molecule.hpp"
46   #include "brains/SimInfo.hpp"
47 < //----------------------------------------------------------------------------//
48 < void IgnoreVisitor::visit(Atom* atom){
49 <  if(isIgnoreType(atom->getType()))
47 > namespace OpenMD {
48 >
49 >  void WrappingVisitor::visit(Atom *atom) {
50      internalVisit(atom);
51 < }
51 >  }
52  
53 < void IgnoreVisitor::visit(DirectionalAtom* datom){
13 <  if(isIgnoreType(datom->getType()))
53 >  void WrappingVisitor::visit(DirectionalAtom *datom) {
54      internalVisit(datom);
55 < }
55 >  }
56  
57 < void IgnoreVisitor::visit(RigidBody* rb){
18 <  vector<Atom*> myAtoms;
19 <  vector<Atom*>::iterator atomIter;
20 <  AtomInfo* atomInfo;
21 <  
22 <  if(isIgnoreType(rb->getType())){
23 <    
57 >  void WrappingVisitor::visit(RigidBody *rb) {
58      internalVisit(rb);
59 +  }
60  
61 <    myAtoms = rb->getAtoms();    
62 <    
63 <    for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter)
64 <      internalVisit(*atomIter);
61 >  void WrappingVisitor::internalVisit(StuntDouble *sd) {
62 >    GenericData *                     data;
63 >    AtomData *                        atomData;
64 >    AtomInfo *                        atomInfo;
65 >    std::vector<AtomInfo *>::iterator i;
66  
67 <  }
32 <  
33 < }
67 >    data = sd->getPropertyByName("ATOMDATA");
68  
69 < bool IgnoreVisitor::isIgnoreType(const string& name){
70 <  return itList.find(name) != itList.end() ? true : false;
37 < }
69 >    if (data != NULL) {
70 >      atomData = dynamic_cast<AtomData *>(data);
71  
72 < void IgnoreVisitor::internalVisit(StuntDouble* sd){
73 <  GenericData* data;
74 <  data = sd->getProperty("IGNORE");
72 >      if (atomData == NULL)
73 >        return;
74 >    } else
75 >      return;
76  
77 <  //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 <  }
77 >    Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
78      
79 < }
79 >    for( atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i) ) {
80 >      Vector3d newPos = atomInfo->pos - origin_;
81 >      currSnapshot->wrapVector(newPos);
82 >      atomInfo->pos = newPos;
83 >    }
84 >  }
85  
86 < const string IgnoreVisitor::toString(){
87 <  char buffer[65535];
88 <  string result;
89 <  set<string>::iterator i;
86 >  void WrappingVisitor::update() {
87 >    if (useCom_){
88 >      origin_ = info->getCom();
89 >    }
90 >  }
91    
92 <  sprintf(buffer ,"------------------------------------------------------------------\n");
93 <  result += buffer;
92 >  const std::string WrappingVisitor::toString() {
93 >    char        buffer[65535];
94 >    std::string result;
95  
96 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
97 <  result += buffer;
96 >    sprintf(buffer,
97 >            "------------------------------------------------------------------\n");
98 >    result += buffer;
99  
100 <  sprintf(buffer ,"Visitor Description: ignore  stuntdoubles\n");
101 <  result += buffer;
100 >    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
101 >    result += buffer;
102  
103 <  //print the ignore type list
104 <  sprintf(buffer , "Ignore type list contains below types:\n");
105 <  result += buffer;
103 >    sprintf(buffer,
104 >            "Visitor Description: wrapping atoms back to periodic box\n");
105 >    result += buffer;
106  
107 <  for(i = itList.begin(); i != itList.end(); ++i){
108 <    sprintf(buffer ,"%s\t", i->c_str());
107 >    sprintf(buffer,
108 >            "------------------------------------------------------------------\n");
109      result += buffer;
110  
111 +    return result;
112    }
75  sprintf(buffer ,"\n");
76  result += buffer;
113  
114 <  sprintf(buffer ,"------------------------------------------------------------------\n");
79 <  result += buffer;
114 >  //----------------------------------------------------------------------------//
115  
116 <  return result;
117 < }
116 >  ReplicateVisitor::ReplicateVisitor(SimInfo *info, Vector3i opt) :
117 >    BaseVisitor() {
118 >      this->info = info;
119 >      visitorName = "ReplicateVisitor";
120 >      this->replicateOpt = opt;
121  
122 < //----------------------------------------------------------------------------//
122 >      //generate the replicate directions
123 >      for( int i = 0; i <= replicateOpt[0]; i++ ) {
124 >        for( int j = 0; j <= replicateOpt[1]; j++ ) {
125 >          for( int k = 0; k <= replicateOpt[2]; k++ ) {
126 >            //skip original frame
127 >            if (i == 0 && j == 0 && k == 0) {
128 >              continue;
129 >            } else {
130 >              dir.push_back(Vector3i(i, j, k));
131 >            }
132 >          }
133 >        }
134 >      }
135 >    
136 >    }
137  
138 < void WrappingVisitor::visit(Atom* atom){
139 <  internalVisit(atom);
140 < }
89 < void WrappingVisitor::visit(DirectionalAtom* datom){
90 <  internalVisit(datom);
91 < }
138 >  void ReplicateVisitor::visit(Atom *atom) {
139 >    internalVisit(atom);
140 >  }
141  
142 < void WrappingVisitor::visit(RigidBody* rb){
143 <  internalVisit(rb);
144 < }
142 >  void ReplicateVisitor::visit(DirectionalAtom *datom) {
143 >    internalVisit(datom);
144 >  }
145  
146 < void WrappingVisitor::internalVisit(StuntDouble* sd){
147 <  GenericData* data;
148 <  AtomData* atomData;
100 <  AtomInfo* atomInfo;
101 <  vector<AtomInfo*>::iterator i;
146 >  void ReplicateVisitor::visit(RigidBody *rb) {
147 >    internalVisit(rb);
148 >  }
149  
150 <  data = sd->getProperty("ATOMDATA");
151 <  if(data != NULL){
152 <    atomData = dynamic_cast<AtomData*>(data);  
153 <    if(atomData == NULL)
150 >  void ReplicateVisitor::internalVisit(StuntDouble *sd) {
151 >    GenericData *          data;
152 >    AtomData *             atomData;
153 >
154 >    //if there is not atom data, just skip it
155 >    data = sd->getPropertyByName("ATOMDATA");
156 >
157 >    if (data != NULL) {
158 >      atomData = dynamic_cast<AtomData *>(data);
159 >
160 >      if (atomData == NULL) {
161 >        return;
162 >      }
163 >    } else {
164        return;
165 <  }
109 <  else
110 <    return;
165 >    }
166  
167 <  for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i))
168 <    info->wrapVector(atomInfo->pos);
167 >    Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
168 >    Mat3x3d box = currSnapshot->getHmat();
169  
170 <  
116 < }
170 >    std::vector<AtomInfo *> atomInfoList = atomData->getData();
171  
172 < const string WrappingVisitor::toString(){
173 <  char buffer[65535];
120 <  string result;
121 <  
122 <  sprintf(buffer ,"------------------------------------------------------------------\n");
123 <  result += buffer;
172 >    replicate(atomInfoList, atomData, box);
173 >  }
174  
175 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
176 <  result += buffer;
175 >  void ReplicateVisitor::replicate(std::vector<AtomInfo *>&infoList, AtomData *data, const Mat3x3d& box) {
176 >    AtomInfo* newAtomInfo;
177 >    std::vector<Vector3i>::iterator dirIter;
178 >    std::vector<AtomInfo *>::iterator i;
179  
180 <  sprintf(buffer ,"Visitor Description: wrapping atoms back to periodic box\n");
181 <  result += buffer;
182 <
183 <  sprintf(buffer,"------------------------------------------------------------------\n");
132 <  result += buffer;
180 >    for( dirIter = dir.begin(); dirIter != dir.end(); ++dirIter ) {
181 >      for( i = infoList.begin(); i != infoList.end(); i++ ) {
182 >        newAtomInfo = new AtomInfo();
183 >        *newAtomInfo = *(*i);
184  
185 <  return result;
186 < }
185 >        for( int j = 0; j < 3; j++ )
186 >          newAtomInfo->pos[j] += (*dirIter)[0]*box(j, 0) + (*dirIter)[1]*box(j, 1) + (*dirIter)[2]*box(j, 2);
187  
188 < //----------------------------------------------------------------------------//
188 >        data->addAtomInfo(newAtomInfo);
189 >      }
190 >    } // end for(dirIter)  
191 >  }
192  
193 < ReplicateVisitor::ReplicateVisitor(SimInfo* info, IntVec3 opt) : BaseVisitor(){
194 <  this->info = info;
195 <  visitorName = "ReplicateVisitor";
196 <  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 < }
193 >  const std::string ReplicateVisitor::toString() {
194 >    char                            buffer[65535];
195 >    std::string                     result;
196 >    std::set<std::string>::iterator i;
197  
198 < void ReplicateVisitor::visit(RigidBody* rb){
199 <  internalVisit(rb);
200 < }
198 >    sprintf(buffer,
199 >            "------------------------------------------------------------------\n");
200 >    result += buffer;
201  
202 < void ReplicateVisitor::internalVisit(StuntDouble* sd){
203 <  GenericData* data;
167 <  AtomData* atomData;
168 <  AtomInfo* atomInfo;
169 <  double box[3][3];
170 <  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;
179 <  }
180 <  else
181 <    return;
202 >    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
203 >    result += buffer;
204  
205 <  
206 <  info->getBoxM(box);
205 >    sprintf(buffer,
206 >            "Visitor Description: replicate the atoms in different direction\n");
207 >    result += buffer;
208  
209 <  atomInfoList = atomData->getData();
210 <  
211 <  replicate(atomInfoList, atomData, box);
209 >    //print the replicate direction
210 >    sprintf(buffer, "repeatX = %d:\n", replicateOpt[0]);
211 >    result += buffer;
212  
213 < }
213 >    sprintf(buffer, "repeatY = %d:\n", replicateOpt[1]);
214 >    result += buffer;
215  
216 < void ReplicateVisitor::replicate(vector<AtomInfo*>& infoList, AtomData* data, double boxM[3][3]){
217 <  AtomInfo * newAtomInfo;
194 <  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);    
216 >    sprintf(buffer, "repeatZ = %d:\n", replicateOpt[2]);
217 >    result += buffer;
218  
219 <      for(int j = 0; j < 3; j++)
220 <        newAtomInfo->pos[j] +=   (*dirIter)[0] * boxM[j][0] + (*dirIter)[1]* boxM[j][1] + (*dirIter)[2] * boxM[j][2];
219 >    sprintf(buffer,
220 >            "------------------------------------------------------------------\n");
221 >    result += buffer;
222  
223 <      data->addAtomInfo(newAtomInfo);
224 <    }
207 <  }// end for(dirIter)  
208 < }
223 >    return result;
224 >  }
225  
226 < const string ReplicateVisitor::toString(){
211 <  char buffer[65535];
212 <  string result;
213 <  set<string>::iterator i;
214 <  
215 <  sprintf(buffer ,"------------------------------------------------------------------\n");
216 <  result += buffer;
226 >  //----------------------------------------------------------------------------//
227  
228 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
229 <  result += buffer;
228 >  XYZVisitor::XYZVisitor(SimInfo *info) :
229 >    BaseVisitor(), seleMan(info), evaluator(info){
230 >      this->info = info;
231 >      visitorName = "XYZVisitor";
232  
233 <  sprintf(buffer ,"Visitor Description: replicate the atoms in different direction\n");
222 <  result += buffer;
223 <  
224 <  //print the replicate direction
225 <  sprintf(buffer , "repeatX = %d:\n", replicateOpt[0]);
226 <  result += buffer;
233 >      evaluator.loadScriptString("select all");
234  
235 <  sprintf(buffer , "repeatY = %d:\n", replicateOpt[1]);
236 <  result += buffer;
235 >      if (!evaluator.isDynamic()) {
236 >        seleMan.setSelectionSet(evaluator.evaluate());
237 >      }
238 >      posOnly_ = false;
239 >    }
240  
241 <  sprintf(buffer , "repeatZ = %d:\n", replicateOpt[2]);
242 <  result += buffer;
241 >  XYZVisitor::XYZVisitor(SimInfo *info, const std::string& script) :
242 >    BaseVisitor(), seleMan(info), evaluator(info) {
243 >      this->info = info;
244 >      visitorName = "XYZVisitor";
245  
246 +      evaluator.loadScriptString(script);
247  
248 <  sprintf(buffer,"------------------------------------------------------------------\n");
249 <  result += buffer;
248 >      if (!evaluator.isDynamic()) {
249 >        seleMan.setSelectionSet(evaluator.evaluate());
250 >      }
251 >      posOnly_ = false;
252 >    }
253 >    
254 >  void XYZVisitor::visit(Atom *atom) {
255 >    if (isSelected(atom))
256 >      internalVisit(atom);
257 >  }
258  
259 <  return result;
260 < }
259 >  void XYZVisitor::visit(DirectionalAtom *datom) {
260 >    if (isSelected(datom))
261 >      internalVisit(datom);
262 >  }
263  
264 < //----------------------------------------------------------------------------//
264 >  void XYZVisitor::visit(RigidBody *rb) {
265 >    if (isSelected(rb))
266 >      internalVisit(rb);
267 >  }
268  
269 < XYZVisitor::XYZVisitor(SimInfo* info,  bool printDipole) : BaseVisitor(){
270 <  this->info = info;
271 <  visitorName = "XYZVisitor";
272 <  this->printDipole = printDipole;
273 < }
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];
271 <  
272 <  //if there is not atom data, just skip it
273 <  data = sd->getProperty("ATOMDATA");
274 <  if(data != NULL){
275 <    atomData = dynamic_cast<AtomData*>(data);  
276 <    if(atomData == NULL)
277 <      return;
269 >  void XYZVisitor::update() {
270 >    //if dynamic, we need to re-evaluate the selection
271 >    if (evaluator.isDynamic()) {
272 >      seleMan.setSelectionSet(evaluator.evaluate());
273 >    }
274    }
279  else
280    return;
275  
276 <  for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){
276 >  void XYZVisitor::internalVisit(StuntDouble *sd) {
277 >    GenericData *                     data;
278 >    AtomData *                        atomData;
279 >    AtomInfo *                        atomInfo;
280 >    std::vector<AtomInfo *>::iterator i;
281 >    char                              buffer[1024];
282  
283 <    if(printDipole)
284 <      sprintf(buffer, "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
286 <                  atomInfo->AtomType.c_str(),
287 <                  atomInfo->pos[0],
288 <                  atomInfo->pos[1],
289 <                  atomInfo->pos[2],
290 <                  atomInfo->dipole[0],
291 <                  atomInfo->dipole[1],
292 <                  atomInfo->dipole[2]);
293 <    else
294 <      sprintf(buffer, "%s%15.8f%15.8f%15.8f",
295 <                  atomInfo->AtomType.c_str(),
296 <                  atomInfo->pos[0],
297 <                  atomInfo->pos[1],
298 <                  atomInfo->pos[2]);  
283 >    //if there is not atom data, just skip it
284 >    data = sd->getPropertyByName("ATOMDATA");
285  
286 <    frame.push_back(buffer);
287 <              
302 <  }
286 >    if (data != NULL) {
287 >      atomData = dynamic_cast<AtomData *>(data);
288  
289 < }
289 >      if (atomData == NULL)
290 >        return;
291 >    } else
292 >      return;
293  
294 < bool XYZVisitor::isIgnore(StuntDouble* sd){
295 <  GenericData* data;
296 <  
297 <  data = sd->getProperty("IGNORE");
298 <  return data ==NULL ? false : true;
299 < }
294 >    if (posOnly_){
295 >      for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
296 >           atomInfo = atomData->nextAtomInfo(i) ) {
297 >        if (atomInfo->hasCharge) {
298 >          sprintf(buffer,
299 >                  "%s%15.8f%15.8f%15.8f%15.8f",
300 >                  atomInfo->atomTypeName.c_str(),
301 >                  atomInfo->pos[0],
302 >                  atomInfo->pos[1],
303 >                  atomInfo->pos[2],
304 >                  atomInfo->charge);
305 >        } else {
306 >          sprintf(buffer,
307 >                "%s%15.8f%15.8f%15.8f",
308 >                  atomInfo->atomTypeName.c_str(),
309 >                  atomInfo->pos[0],
310 >                  atomInfo->pos[1],
311 >                  atomInfo->pos[2]);
312 >        }
313 >        frame.push_back(buffer);
314 >      }
315 >    }else{
316 >      for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
317 >           atomInfo = atomData->nextAtomInfo(i) ) {
318 >        if (atomInfo->hasCharge) {
319 >        sprintf(buffer,
320 >                "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
321 >                atomInfo->atomTypeName.c_str(),
322 >                atomInfo->pos[0],
323 >                atomInfo->pos[1],
324 >                atomInfo->pos[2],
325 >                atomInfo->charge,
326 >                atomInfo->dipole[0],
327 >                atomInfo->dipole[1],
328 >                atomInfo->dipole[2]);
329 >        } else {
330 >        sprintf(buffer,
331 >                "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
332 >                atomInfo->atomTypeName.c_str(),
333 >                atomInfo->pos[0],
334 >                atomInfo->pos[1],
335 >                atomInfo->pos[2],
336 >                atomInfo->dipole[0],
337 >                atomInfo->dipole[1],
338 >                atomInfo->dipole[2]);
339 >        }
340 >        frame.push_back(buffer);
341 >      }
342 >    }
343 >  }
344  
345 < void XYZVisitor::writeFrame(ostream& outStream){
346 <  vector<string>::iterator i;
347 <  double box[3][3];
316 <  char buffer[1024];
345 >  bool XYZVisitor::isSelected(StuntDouble *sd) {
346 >    return seleMan.isSelected(sd);
347 >  }
348  
349 <  if(frame.size() == 0)
350 <    cerr << "Current Frame does not contain any atoms" << endl;
349 >  void XYZVisitor::writeFrame(std::ostream &outStream) {
350 >    std::vector<std::string>::iterator i;
351 >    char buffer[1024];
352  
353 <  //total number of atoms  
354 <  outStream << frame.size() << endl;
353 >    if (frame.size() == 0)
354 >      std::cerr << "Current Frame does not contain any atoms" << std::endl;
355  
356 <  //write comment line
357 <  info->getBoxM(box);
326 <  sprintf(buffer,"%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f",
327 <              info->getTime(),
328 <              box[0][0], box[0][1], box[0][2],
329 <              box[1][0], box[1][1], box[1][2],
330 <              box[2][0], box[2][1], box[2][2]);
356 >    //total number of atoms  
357 >    outStream << frame.size() << std::endl;
358  
359 <  outStream << buffer << endl;  
359 >    //write comment line
360 >    Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
361 >    Mat3x3d box = currSnapshot->getHmat();
362 >    
363 >    sprintf(buffer,
364 >            "%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f",
365 >            currSnapshot->getTime(),
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  
370 <  for(i = frame.begin(); i != frame.end(); ++i)
335 <    outStream << *i << endl;
336 < }
370 >    outStream << buffer << std::endl;
371  
372 < const string XYZVisitor::toString(){
373 <  char buffer[65535];
374 <  string result;
341 <  
342 <  sprintf(buffer ,"------------------------------------------------------------------\n");
343 <  result += buffer;
372 >    for( i = frame.begin(); i != frame.end(); ++i )
373 >      outStream << *i << std::endl;
374 >  }
375  
376 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
377 <  result += buffer;
376 >  std::string XYZVisitor::trimmedName(const std::string&atomTypeName) {    
377 >    return atomTypeName.substr(0, atomTypeName.find('-'));
378 >  }
379  
380 <  sprintf(buffer ,"Visitor Description: assemble the atom data and output xyz file\n");
381 <  result += buffer;
382 <
351 <  sprintf(buffer,"------------------------------------------------------------------\n");
352 <  result += buffer;
380 >  const std::string XYZVisitor::toString() {
381 >    char        buffer[65535];
382 >    std::string result;
383  
384 <  return result;
385 < }
384 >    sprintf(buffer,
385 >            "------------------------------------------------------------------\n");
386 >    result += buffer;
387  
388 < //----------------------------------------------------------------------------//
388 >    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
389 >    result += buffer;
390  
391 < void PrepareVisitor::internalVisit(Atom * atom){
392 <  GenericData* data;
393 <  AtomData* atomData;
391 >    sprintf(buffer,
392 >            "Visitor Description: assemble the atom data and output xyz file\n");
393 >    result += buffer;
394  
395 <  //if visited property is  existed, remove it
396 <  data = atom->getProperty("VISITED");
397 <  if(data != NULL){
366 <    atom->removeProperty("VISITED");  
367 <  }
395 >    sprintf(buffer,
396 >            "------------------------------------------------------------------\n");
397 >    result += buffer;
398  
399 <  //remove atomdata
370 <  data = atom->getProperty("ATOMDATA");
371 <  if(data != NULL){
372 <    atomData = dynamic_cast<AtomData*>(data);  
373 <    if(atomData != NULL)
374 <      atom->removeProperty("ATOMDATA");
399 >    return result;
400    }
376  
377 }
401  
402 < void PrepareVisitor::internalVisit(RigidBody * rb){
380 <  GenericData* data;
381 <  AtomData* atomData;
382 <  vector<Atom*> myAtoms;
383 <  vector<Atom*>::iterator atomIter;
384 <  
385 <  //if visited property is  existed, remove it
386 <  data = rb->getProperty("VISITED");
387 <  if(data != NULL){
388 <    rb->removeProperty("VISITED");  
389 <  }
402 >  //----------------------------------------------------------------------------//
403  
404 <  //remove atomdata
405 <  data = rb->getProperty("ATOMDATA");
406 <  if(data != NULL){
407 <    atomData = dynamic_cast<AtomData*>(data);  
408 <    if(atomData != NULL)
409 <      rb->removeProperty("ATOMDATA");
404 >  void PrepareVisitor::internalVisit(Atom *atom) {
405 >    GenericData *data;
406 >    AtomData *   atomData;
407 >
408 >    //if visited property is  existed, remove it
409 >    data = atom->getPropertyByName("VISITED");
410 >
411 >    if (data != NULL) {
412 >      atom->removeProperty("VISITED");
413 >    }
414 >
415 >    //remove atomdata
416 >    data = atom->getPropertyByName("ATOMDATA");
417 >
418 >    if (data != NULL) {
419 >      atomData = dynamic_cast<AtomData *>(data);
420 >
421 >      if (atomData != NULL)
422 >        atom->removeProperty("ATOMDATA");
423 >    }
424    }
425  
426 <  myAtoms = rb->getAtoms();
427 <    
428 <  for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter)
429 <   internalVisit (*atomIter);  
430 < }
426 >  void PrepareVisitor::internalVisit(RigidBody *rb) {
427 >    GenericData* data;
428 >    AtomData* atomData;
429 >    std::vector<Atom *> myAtoms;
430 >    std::vector<Atom *>::iterator atomIter;
431  
432 < const string PrepareVisitor::toString(){
433 <  char buffer[65535];
407 <  string result;
408 <  
409 <  sprintf(buffer ,"------------------------------------------------------------------\n");
410 <  result += buffer;
432 >    //if visited property is  existed, remove it
433 >    data = rb->getPropertyByName("VISITED");
434  
435 <  sprintf(buffer ,"Visitor name: %s", visitorName.c_str());
436 <  result += buffer;
435 >    if (data != NULL) {
436 >      rb->removeProperty("VISITED");
437 >    }
438  
439 <  sprintf(buffer ,"Visitor Description: prepare for operation of other vistors\n");
440 <  result += buffer;
439 >    //remove atomdata
440 >    data = rb->getPropertyByName("ATOMDATA");
441  
442 <  sprintf(buffer ,"------------------------------------------------------------------\n");
443 <  result += buffer;
442 >    if (data != NULL) {
443 >      atomData = dynamic_cast<AtomData *>(data);
444  
445 <  return result;
446 < }
445 >      if (atomData != NULL)
446 >        rb->removeProperty("ATOMDATA");
447 >    }
448  
449 < //----------------------------------------------------------------------------//
449 >    myAtoms = rb->getAtoms();
450  
451 < WaterTypeVisitor:: WaterTypeVisitor(){
452 <  visitorName = "WaterTypeVisitor";
453 <  waterTypeList.insert("TIP3P_RB_0");
429 <  waterTypeList.insert("TIP4P_RB_0");
430 <  waterTypeList.insert("TIP5P_RB_0");
431 <  waterTypeList.insert("SPCE_RB_0");  
432 < }
451 >    for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter )
452 >      internalVisit(*atomIter);
453 >  }
454  
455 +  const std::string PrepareVisitor::toString() {
456 +    char buffer[65535];
457 +    std::string result;
458 +
459 +    sprintf(buffer,
460 +            "------------------------------------------------------------------\n");
461 +    result += buffer;
462 +
463 +    sprintf(buffer, "Visitor name: %s", visitorName.c_str());
464 +    result += buffer;
465 +
466 +    sprintf(buffer,
467 +            "Visitor Description: prepare for operation of other vistors\n");
468 +    result += buffer;
469 +
470 +    sprintf(buffer,
471 +            "------------------------------------------------------------------\n");
472 +    result += buffer;
473 +
474 +    return result;
475 +  }
476  
477 < 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();
477 >  //----------------------------------------------------------------------------//
478  
479 <  if(waterTypeList.find(rbName) != waterTypeList.end()){
479 >  WaterTypeVisitor::WaterTypeVisitor() {
480 >    visitorName = "WaterTypeVisitor";
481 >    waterTypeList.insert("TIP3P_RB_0");
482 >    waterTypeList.insert("TIP4P_RB_0");
483 >    waterTypeList.insert("TIP5P_RB_0");
484 >    waterTypeList.insert("SPCE_RB_0");
485 >  }
486  
487 <    myAtoms = rb->getAtoms();    
488 <    for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter){
487 >  void WaterTypeVisitor::visit(RigidBody *rb) {
488 >    std::string rbName;
489 >    std::vector<Atom *> myAtoms;
490 >    std::vector<Atom *>::iterator atomIter;
491 >    GenericData* data;
492 >    AtomData* atomData;
493 >    AtomInfo* atomInfo;
494 >    std::vector<AtomInfo *>::iterator i;
495  
496 <      data = (*atomIter)->getProperty("ATOMDATA");
452 <      if(data != NULL){
453 <        atomData = dynamic_cast<AtomData*>(data);  
454 <        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)
496 >    rbName = rb->getType();
497  
498 <    }//end for(atomIter)
499 <      
466 <  }//end if (waterTypeList.find(rbName) != waterTypeList.end())
467 <  
468 < }
498 >    if (waterTypeList.find(rbName) != waterTypeList.end()) {
499 >      myAtoms = rb->getAtoms();
500  
501 < void WaterTypeVisitor:: replaceType(string& atomType){
502 <  atomType = atomType.substr(0, atomType.find('_'));
503 < }
501 >      for( atomIter = myAtoms.begin(); atomIter != myAtoms.end();
502 >           ++atomIter ) {
503 >        data = (*atomIter)->getPropertyByName("ATOMDATA");
504  
505 < const string WaterTypeVisitor:: toString(){
506 <  char buffer[65535];
476 <  string result;
477 <  
478 <  sprintf(buffer ,"------------------------------------------------------------------\n");
479 <  result += buffer;
505 >        if (data != NULL) {
506 >          atomData = dynamic_cast<AtomData *>(data);
507  
508 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
509 <  result += buffer;
508 >          if (atomData == NULL)
509 >            continue;
510 >        } else
511 >          continue;
512  
513 <  sprintf(buffer ,"Visitor Description: Replace the atom type in water model\n");
514 <  result += buffer;
513 >        for( 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())
519 >  }
520  
521 <  sprintf(buffer ,"------------------------------------------------------------------\n");
522 <  result += buffer;
521 >  std::string WaterTypeVisitor::trimmedName(const std::string&atomTypeName) {
522 >    return atomTypeName.substr(0, atomTypeName.find('_'));
523 >  }
524  
525 <  return result;
526 < }
525 >  const std::string WaterTypeVisitor::toString() {
526 >    char buffer[65535];
527 >    std::string result;
528  
529 +    sprintf(buffer,
530 +            "------------------------------------------------------------------\n");
531 +    result += buffer;
532 +
533 +    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
534 +    result += buffer;
535 +
536 +    sprintf(buffer,
537 +            "Visitor Description: Replace the atom type in water model\n");
538 +    result += buffer;
539 +
540 +    sprintf(buffer,
541 +            "------------------------------------------------------------------\n");
542 +    result += buffer;
543 +
544 +    return result;
545 +  }
546 +
547 + } //namespace OpenMD

Comparing trunk/src/visitors/OtherVisitor.cpp (property svn:keywords):
Revision 3 by tim, Fri Sep 24 16:27:58 2004 UTC vs.
Revision 1455 by gezelter, Thu Jun 24 20:44:18 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines