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 2 by gezelter, Fri Sep 24 04:16:43 2004 UTC vs.
branches/development/src/visitors/OtherVisitor.cpp (file contents), Revision 1875 by gezelter, Fri May 17 14:41:42 2013 UTC

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

Comparing:
trunk/src/visitors/OtherVisitor.cpp (property svn:keywords), Revision 2 by gezelter, Fri Sep 24 04:16:43 2004 UTC vs.
branches/development/src/visitors/OtherVisitor.cpp (property svn:keywords), Revision 1875 by gezelter, Fri May 17 14:41:42 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines