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 1874 by gezelter, Wed May 15 15:09:35 2013 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, 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"
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 > #include "brains/Thermo.hpp"
49 >
50 > namespace OpenMD {
51 >
52 >  void WrappingVisitor::visit(Atom *atom) {
53      internalVisit(atom);
54 < }
54 >  }
55  
56 < void IgnoreVisitor::visit(DirectionalAtom* datom){
13 <  if(isIgnoreType(datom->getType()))
56 >  void WrappingVisitor::visit(DirectionalAtom *datom) {
57      internalVisit(datom);
58 < }
58 >  }
59  
60 < void IgnoreVisitor::visit(RigidBody* rb){
18 <  vector<Atom*> myAtoms;
19 <  vector<Atom*>::iterator atomIter;
20 <  AtomInfo* atomInfo;
21 <  
22 <  if(isIgnoreType(rb->getType())){
23 <    
60 >  void WrappingVisitor::visit(RigidBody *rb) {
61      internalVisit(rb);
62 +  }
63  
64 <    myAtoms = rb->getAtoms();    
65 <    
66 <    for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter)
67 <      internalVisit(*atomIter);
64 >  void WrappingVisitor::internalVisit(StuntDouble *sd) {
65 >    GenericData *                     data;
66 >    AtomData *                        atomData;
67 >    AtomInfo *                        atomInfo;
68 >    std::vector<AtomInfo *>::iterator i;
69  
70 <  }
32 <  
33 < }
70 >    data = sd->getPropertyByName("ATOMDATA");
71  
72 < bool IgnoreVisitor::isIgnoreType(const string& name){
73 <  return itList.find(name) != itList.end() ? true : false;
37 < }
72 >    if (data != NULL) {
73 >      atomData = dynamic_cast<AtomData *>(data);
74  
75 < void IgnoreVisitor::internalVisit(StuntDouble* sd){
76 <  GenericData* data;
77 <  data = sd->getProperty("IGNORE");
75 >      if (atomData == NULL)
76 >        return;
77 >    } else
78 >      return;
79  
80 <  //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 <  }
80 >    Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
81      
82 < }
82 >    for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
83 >         atomInfo = atomData->nextAtomInfo(i) ) {
84  
85 < const string IgnoreVisitor::toString(){
86 <  char buffer[65535];
87 <  string result;
88 <  set<string>::iterator i;
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 >      Thermo thermo(info);
95 >      origin_ = thermo.getCom();
96 >    }
97 >  }
98    
99 <  sprintf(buffer ,"------------------------------------------------------------------\n");
100 <  result += buffer;
99 >  const std::string WrappingVisitor::toString() {
100 >    char        buffer[65535];
101 >    std::string result;
102  
103 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
104 <  result += buffer;
103 >    sprintf(buffer,
104 >            "------------------------------------------------------------------\n");
105 >    result += buffer;
106  
107 <  sprintf(buffer ,"Visitor Description: ignore  stuntdoubles\n");
108 <  result += buffer;
107 >    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
108 >    result += buffer;
109  
110 <  //print the ignore type list
111 <  sprintf(buffer , "Ignore type list contains below types:\n");
112 <  result += buffer;
110 >    sprintf(buffer,
111 >            "Visitor Description: wrapping atoms back to periodic box\n");
112 >    result += buffer;
113  
114 <  for(i = itList.begin(); i != itList.end(); ++i){
115 <    sprintf(buffer ,"%s\t", i->c_str());
114 >    sprintf(buffer,
115 >            "------------------------------------------------------------------\n");
116      result += buffer;
117  
118 +    return result;
119    }
75  sprintf(buffer ,"\n");
76  result += buffer;
120  
121 <  sprintf(buffer ,"------------------------------------------------------------------\n");
79 <  result += buffer;
121 >  //----------------------------------------------------------------------------//
122  
123 <  return result;
124 < }
123 >  ReplicateVisitor::ReplicateVisitor(SimInfo *info, Vector3i opt) :
124 >    BaseVisitor() {
125 >      this->info = info;
126 >      visitorName = "ReplicateVisitor";
127 >      this->replicateOpt = opt;
128  
129 < //----------------------------------------------------------------------------//
129 >      //generate the replicate directions
130 >      for( int i = 0; i <= replicateOpt[0]; i++ ) {
131 >        for( int j = 0; j <= replicateOpt[1]; j++ ) {
132 >          for( int k = 0; k <= replicateOpt[2]; k++ ) {
133 >            //skip original frame
134 >            if (i == 0 && j == 0 && k == 0) {
135 >              continue;
136 >            } else {
137 >              dir.push_back(Vector3i(i, j, k));
138 >            }
139 >          }
140 >        }
141 >      }
142 >    
143 >    }
144  
145 < void WrappingVisitor::visit(Atom* atom){
146 <  internalVisit(atom);
147 < }
89 < void WrappingVisitor::visit(DirectionalAtom* datom){
90 <  internalVisit(datom);
91 < }
145 >  void ReplicateVisitor::visit(Atom *atom) {
146 >    internalVisit(atom);
147 >  }
148  
149 < void WrappingVisitor::visit(RigidBody* rb){
150 <  internalVisit(rb);
151 < }
149 >  void ReplicateVisitor::visit(DirectionalAtom *datom) {
150 >    internalVisit(datom);
151 >  }
152  
153 < void WrappingVisitor::internalVisit(StuntDouble* sd){
154 <  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;
153 >  void ReplicateVisitor::visit(RigidBody *rb) {
154 >    internalVisit(rb);
155    }
109  else
110    return;
156  
157 <  for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i))
158 <    info->wrapVector(atomInfo->pos);
157 >  void ReplicateVisitor::internalVisit(StuntDouble *sd) {
158 >    GenericData *          data;
159 >    AtomData *             atomData;
160  
161 <  
162 < }
161 >    //if there is not atom data, just skip it
162 >    data = sd->getPropertyByName("ATOMDATA");
163  
164 < const string WrappingVisitor::toString(){
165 <  char buffer[65535];
120 <  string result;
121 <  
122 <  sprintf(buffer ,"------------------------------------------------------------------\n");
123 <  result += buffer;
164 >    if (data != NULL) {
165 >      atomData = dynamic_cast<AtomData *>(data);
166  
167 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
168 <  result += buffer;
167 >      if (atomData == NULL) {
168 >        return;
169 >      }
170 >    } else {
171 >      return;
172 >    }
173  
174 <  sprintf(buffer ,"Visitor Description: wrapping atoms back to periodic box\n");
175 <  result += buffer;
130 <
131 <  sprintf(buffer,"------------------------------------------------------------------\n");
132 <  result += buffer;
174 >    Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
175 >    Mat3x3d box = currSnapshot->getHmat();
176  
177 <  return result;
135 < }
177 >    std::vector<AtomInfo *> atomInfoList = atomData->getData();
178  
179 < //----------------------------------------------------------------------------//
179 >    replicate(atomInfoList, atomData, box);
180 >  }
181  
182 < ReplicateVisitor::ReplicateVisitor(SimInfo* info, IntVec3 opt) : BaseVisitor(){
183 <  this->info = info;
184 <  visitorName = "ReplicateVisitor";
185 <  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 < }
182 >  void ReplicateVisitor::replicate(std::vector<AtomInfo *>&infoList, AtomData *data, const Mat3x3d& box) {
183 >    AtomInfo* newAtomInfo;
184 >    std::vector<Vector3i>::iterator dirIter;
185 >    std::vector<AtomInfo *>::iterator i;
186  
187 < void ReplicateVisitor::visit(RigidBody* rb){
188 <  internalVisit(rb);
189 < }
187 >    for( dirIter = dir.begin(); dirIter != dir.end(); ++dirIter ) {
188 >      for( i = infoList.begin(); i != infoList.end(); ++i ) {
189 >        newAtomInfo = new AtomInfo();
190 >        *newAtomInfo = *(*i);
191  
192 < void ReplicateVisitor::internalVisit(StuntDouble* sd){
193 <  GenericData* data;
194 <  AtomData* atomData;
195 <  AtomInfo* atomInfo;
196 <  double box[3][3];
197 <  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;
192 >        for( int j = 0; j < 3; j++ )
193 >          newAtomInfo->pos[j] += (*dirIter)[0]*box(j, 0) + (*dirIter)[1]*box(j, 1) + (*dirIter)[2]*box(j, 2);
194 >
195 >        data->addAtomInfo(newAtomInfo);
196 >      }
197 >    } // end for(dirIter)  
198    }
180  else
181    return;
199  
200 <  
201 <  info->getBoxM(box);
200 >  const std::string ReplicateVisitor::toString() {
201 >    char                            buffer[65535];
202 >    std::string                     result;
203  
186  atomInfoList = atomData->getData();
187  
188  replicate(atomInfoList, atomData, box);
204  
205 < }
205 >    sprintf(buffer,
206 >            "--------------------------------------------------------------\n");
207 >    result += buffer;
208  
209 < void ReplicateVisitor::replicate(vector<AtomInfo*>& infoList, AtomData* data, double boxM[3][3]){
210 <  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);    
209 >    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
210 >    result += buffer;
211  
212 <      for(int j = 0; j < 3; j++)
213 <        newAtomInfo->pos[j] +=   (*dirIter)[0] * boxM[j][0] + (*dirIter)[1]* boxM[j][1] + (*dirIter)[2] * boxM[j][2];
212 >    sprintf(buffer,
213 >            "Visitor Description: replicate the atoms in different direction\n");
214 >    result += buffer;
215  
216 <      data->addAtomInfo(newAtomInfo);
217 <    }
218 <  }// end for(dirIter)  
208 < }
216 >    //print the replicate direction
217 >    sprintf(buffer, "repeatX = %d:\n", replicateOpt[0]);
218 >    result += buffer;
219  
220 < const string ReplicateVisitor::toString(){
221 <  char buffer[65535];
212 <  string result;
213 <  set<string>::iterator i;
214 <  
215 <  sprintf(buffer ,"------------------------------------------------------------------\n");
216 <  result += buffer;
220 >    sprintf(buffer, "repeatY = %d:\n", replicateOpt[1]);
221 >    result += buffer;
222  
223 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
224 <  result += buffer;
223 >    sprintf(buffer, "repeatZ = %d:\n", replicateOpt[2]);
224 >    result += buffer;
225  
226 <  sprintf(buffer ,"Visitor Description: replicate the atoms in different direction\n");
227 <  result += buffer;
228 <  
224 <  //print the replicate direction
225 <  sprintf(buffer , "repeatX = %d:\n", replicateOpt[0]);
226 <  result += buffer;
226 >    sprintf(buffer,
227 >            "--------------------------------------------------------------\n");
228 >    result += buffer;
229  
230 <  sprintf(buffer , "repeatY = %d:\n", replicateOpt[1]);
231 <  result += buffer;
230 >    return result;
231 >  }
232  
233 <  sprintf(buffer , "repeatZ = %d:\n", replicateOpt[2]);
232 <  result += buffer;
233 >  //------------------------------------------------------------------------//
234  
235 <
236 <  sprintf(buffer,"------------------------------------------------------------------\n");
237 <  result += buffer;
238 <
239 <  return result;
240 < }
241 <
242 < //----------------------------------------------------------------------------//
243 <
244 < XYZVisitor::XYZVisitor(SimInfo* info,  bool printDipole) : BaseVisitor(){
245 <  this->info = info;
246 <  visitorName = "XYZVisitor";
247 <  this->printDipole = printDipole;
248 < }
249 <
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];
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 >  }
250    
251 <  //if there is not atom data, just skip it
252 <  data = sd->getProperty("ATOMDATA");
253 <  if(data != NULL){
254 <    atomData = dynamic_cast<AtomData*>(data);  
255 <    if(atomData == NULL)
256 <      return;
251 >  XYZVisitor::XYZVisitor(SimInfo *info, const std::string& script) :
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 <  else
266 <    return;
265 >    
266 >  void XYZVisitor::visit(Atom *atom) {
267 >    if (isSelected(atom))
268 >      internalVisit(atom);
269 >  }
270  
271 <  for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){
272 <
273 <    if(printDipole)
274 <      sprintf(buffer, "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
275 <                  atomInfo->AtomType.c_str(),
276 <                  atomInfo->pos[0],
277 <                  atomInfo->pos[1],
278 <                  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]);  
299 <
300 <    frame.push_back(buffer);
301 <              
271 >  void XYZVisitor::visit(DirectionalAtom *datom) {
272 >    if (isSelected(datom))
273 >      internalVisit(datom);
274 >  }
275 >  
276 >  void XYZVisitor::visit(RigidBody *rb) {
277 >    if (isSelected(rb))
278 >      internalVisit(rb);
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 < }
284 <
285 < void XYZVisitor::writeFrame(ostream& outStream){
286 <  vector<string>::iterator i;
315 <  double box[3][3];
316 <  char buffer[1024];
317 <
318 <  if(frame.size() == 0)
319 <    cerr << "Current Frame does not contain any atoms" << endl;
320 <
321 <  //total number of atoms  
322 <  outStream << frame.size() << endl;
323 <
324 <  //write comment line
325 <  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]);
331 <
332 <  outStream << buffer << endl;  
333 <
334 <  for(i = frame.begin(); i != frame.end(); ++i)
335 <    outStream << *i << endl;
336 < }
337 <
338 < const string XYZVisitor::toString(){
339 <  char buffer[65535];
340 <  string result;
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    
288 <  sprintf(buffer ,"------------------------------------------------------------------\n");
289 <  result += buffer;
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 >    
295 >    //if there is not atom data, just skip it
296 >    data = sd->getPropertyByName("ATOMDATA");
297 >    
298 >    if (data != NULL) {
299 >      atomData = dynamic_cast<AtomData *>(data);
300 >      
301 >      if (atomData == NULL)
302 >        return;
303 >    } else
304 >      return;
305  
306 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
307 <  result += 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 >      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 >      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 <  sprintf(buffer ,"Visitor Description: assemble the atom data and output xyz file\n");
347 <  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");  
346 >  bool XYZVisitor::isSelected(StuntDouble *sd) {
347 >    return seleMan.isSelected(sd);
348    }
349  
350 <  //remove atomdata
351 <  data = atom->getProperty("ATOMDATA");
352 <  if(data != NULL){
353 <    atomData = dynamic_cast<AtomData*>(data);  
354 <    if(atomData != NULL)
355 <      atom->removeProperty("ATOMDATA");
350 >  void XYZVisitor::writeFrame(std::ostream &outStream) {
351 >    std::vector<std::string>::iterator i;
352 >    char buffer[1024];
353 >    
354 >    if (frame.empty())
355 >      std::cerr << "Current Frame does not contain any atoms" << std::endl;
356 >    
357 >    //total number of atoms  
358 >    outStream << frame.size() << std::endl;
359 >    
360 >    //write comment line
361 >    Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
362 >    Mat3x3d box = currSnapshot->getHmat();
363 >    
364 >    sprintf(buffer,
365 >            "%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f",
366 >            currSnapshot->getTime(),
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 >    
371 >    outStream << buffer << std::endl;
372 >    
373 >    for( i = frame.begin(); i != frame.end(); ++i )
374 >      outStream << *i << std::endl;
375    }
376    
377 < }
378 <
379 < void PrepareVisitor::internalVisit(RigidBody * rb){
380 <  GenericData* data;
381 <  AtomData* atomData;
382 <  vector<Atom*> myAtoms;
383 <  vector<Atom*>::iterator atomIter;
377 >  std::string XYZVisitor::trimmedName(const std::string&atomTypeName) {    
378 >    return atomTypeName.substr(0, atomTypeName.find('-'));
379 >  }
380    
381 <  //if visited property is  existed, remove it
382 <  data = rb->getProperty("VISITED");
383 <  if(data != NULL){
384 <    rb->removeProperty("VISITED");  
381 >  const std::string XYZVisitor::toString() {
382 >    char        buffer[65535];
383 >    std::string result;
384 >    
385 >    sprintf(buffer,
386 >            "------------------------------------------------------------------\n");
387 >    result += buffer;
388 >    
389 >    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
390 >    result += buffer;
391 >    
392 >    sprintf(buffer,
393 >            "Visitor Description: assemble the atom data and output xyz file\n");
394 >    result += buffer;
395 >
396 >    sprintf(buffer,
397 >            "------------------------------------------------------------------\n");
398 >    result += buffer;
399 >    
400 >    return result;
401    }
402 +  
403 +  //----------------------------------------------------------------------------//
404 +  
405 +  void PrepareVisitor::internalVisit(Atom *atom) {
406 +    GenericData *data;
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 <  //remove atomdata
419 <  data = rb->getProperty("ATOMDATA");
420 <  if(data != NULL){
421 <    atomData = dynamic_cast<AtomData*>(data);  
422 <    if(atomData != NULL)
423 <      rb->removeProperty("ATOMDATA");
418 >    if (data != NULL) {
419 >      AtomData* 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("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 <    myAtoms = rb->getAtoms();    
491 <    for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter){
490 >  void WaterTypeVisitor::visit(RigidBody *rb) {
491 >    std::string rbName;
492 >    std::vector<Atom *> myAtoms;
493 >    std::vector<Atom *>::iterator atomIter;
494 >    std::vector<AtomInfo *>::iterator i;
495 >    AtomData* atomData;
496  
497 <      data = (*atomIter)->getProperty("ATOMDATA");
498 <      if(data != NULL){
499 <        atomData = dynamic_cast<AtomData*>(data);  
500 <        if(atomData == NULL)
455 <          continue;
456 <      }
457 <      else
458 <        continue;
497 >    rbName = rb->getType();
498 >    
499 >    if (waterTypeList.find(rbName) != waterTypeList.end()) {
500 >      myAtoms = rb->getAtoms();
501        
502 <      for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){
503 <        replaceType(atomInfo->AtomType);
504 <      }//end for(atomInfo)
502 >      for( atomIter = myAtoms.begin(); atomIter != myAtoms.end();
503 >           ++atomIter ) {
504 >        GenericData* data = (*atomIter)->getPropertyByName("ATOMDATA");
505 >        
506 >        if (data != NULL) {
507 >          atomData = dynamic_cast<AtomData *>(data);
508 >          
509 >          if (atomData == NULL)
510 >            continue;
511 >        } else
512 >          continue;
513 >        
514 >        for( AtomInfo* atomInfo = atomData->beginAtomInfo(i); atomInfo;
515 >             atomInfo = atomData->nextAtomInfo(i) ) {
516 >          atomInfo->atomTypeName = trimmedName(atomInfo->atomTypeName);
517 >        }
518 >      }  
519 >    }
520 >  }
521  
522 <    }//end for(atomIter)
523 <      
524 <  }//end if (waterTypeList.find(rbName) != waterTypeList.end())
467 <  
468 < }
522 >  std::string WaterTypeVisitor::trimmedName(const std::string&atomTypeName) {
523 >    return atomTypeName.substr(0, atomTypeName.find('_'));
524 >  }
525  
526 < void WaterTypeVisitor:: replaceType(string& atomType){
527 <  atomType = atomType.substr(0, atomType.find('_'));
528 < }
526 >  const std::string WaterTypeVisitor::toString() {
527 >    char buffer[65535];
528 >    std::string result;
529  
530 < const string WaterTypeVisitor:: toString(){
531 <  char buffer[65535];
532 <  string result;
477 <  
478 <  sprintf(buffer ,"------------------------------------------------------------------\n");
479 <  result += buffer;
530 >    sprintf(buffer,
531 >            "------------------------------------------------------------------\n");
532 >    result += buffer;
533  
534 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
535 <  result += buffer;
534 >    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
535 >    result += buffer;
536  
537 <  sprintf(buffer ,"Visitor Description: Replace the atom type in water model\n");
538 <  result += buffer;
537 >    sprintf(buffer,
538 >            "Visitor Description: Replace the atom type in water model\n");
539 >    result += buffer;
540  
541 <  sprintf(buffer ,"------------------------------------------------------------------\n");
542 <  result += buffer;
541 >    sprintf(buffer,
542 >            "------------------------------------------------------------------\n");
543 >    result += buffer;
544  
545 <  return result;
546 < }
545 >    return result;
546 >  }
547  
548 + } //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 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