ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/visitors/OtherVisitor.cpp
(Generate patch)

Comparing trunk/OOPSE-4/src/visitors/OtherVisitor.cpp (file contents):
Revision 1490 by gezelter, Fri Sep 24 04:16:43 2004 UTC vs.
Revision 2204 by gezelter, Fri Apr 15 22:04:00 2005 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. Acknowledgement of the program authors must be made in any
10 > *    publication of scientific results based in part on use of the
11 > *    program.  An acceptable form of acknowledgement is citation of
12 > *    the article in which the program was described (Matthew
13 > *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 > *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 > *    Parallel Simulation Engine for Molecular Dynamics,"
16 > *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 > *
18 > * 2. Redistributions of source code must retain the above copyright
19 > *    notice, this list of conditions and the following disclaimer.
20 > *
21 > * 3. Redistributions in binary form must reproduce the above copyright
22 > *    notice, this list of conditions and the following disclaimer in the
23 > *    documentation and/or other materials provided with the
24 > *    distribution.
25 > *
26 > * This software is provided "AS IS," without a warranty of any
27 > * kind. All express or implied conditions, representations and
28 > * warranties, including any implied warranty of merchantability,
29 > * fitness for a particular purpose or non-infringement, are hereby
30 > * excluded.  The University of Notre Dame and its licensors shall not
31 > * be liable for any damages suffered by licensee as a result of
32 > * using, modifying or distributing the software or its
33 > * derivatives. In no event will the University of Notre Dame or its
34 > * licensors be liable for any lost revenue, profit or data, or for
35 > * direct, indirect, special, consequential, incidental or punitive
36 > * damages, however caused and regardless of the theory of liability,
37 > * arising out of the use of or inability to use software, even if the
38 > * University of Notre Dame has been advised of the possibility of
39 > * such damages.
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 > namespace oopse {
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 >      currSnapshot->wrapVector(atomInfo->pos);
81 >    }
82 >  }
83  
84 < const string IgnoreVisitor::toString(){
85 <  char buffer[65535];
86 <  string result;
55 <  set<string>::iterator i;
56 <  
57 <  sprintf(buffer ,"------------------------------------------------------------------\n");
58 <  result += buffer;
84 >  const std::string WrappingVisitor::toString() {
85 >    char        buffer[65535];
86 >    std::string result;
87  
88 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
89 <  result += buffer;
88 >    sprintf(buffer,
89 >            "------------------------------------------------------------------\n");
90 >    result += buffer;
91  
92 <  sprintf(buffer ,"Visitor Description: ignore  stuntdoubles\n");
93 <  result += buffer;
92 >    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
93 >    result += buffer;
94  
95 <  //print the ignore type list
96 <  sprintf(buffer , "Ignore type list contains below types:\n");
97 <  result += buffer;
95 >    sprintf(buffer,
96 >            "Visitor Description: wrapping atoms back to periodic box\n");
97 >    result += buffer;
98  
99 <  for(i = itList.begin(); i != itList.end(); ++i){
100 <    sprintf(buffer ,"%s\t", i->c_str());
99 >    sprintf(buffer,
100 >            "------------------------------------------------------------------\n");
101      result += buffer;
102  
103 +    return result;
104    }
75  sprintf(buffer ,"\n");
76  result += buffer;
105  
106 <  sprintf(buffer ,"------------------------------------------------------------------\n");
79 <  result += buffer;
106 >  //----------------------------------------------------------------------------//
107  
108 <  return result;
109 < }
108 >  ReplicateVisitor::ReplicateVisitor(SimInfo *info, Vector3i opt) :
109 >    BaseVisitor() {
110 >      this->info = info;
111 >      visitorName = "ReplicateVisitor";
112 >      this->replicateOpt = opt;
113  
114 < //----------------------------------------------------------------------------//
114 >      //generate the replicate directions
115 >      for( int i = 0; i <= replicateOpt[0]; i++ ) {
116 >        for( int j = 0; j <= replicateOpt[1]; j++ ) {
117 >          for( int k = 0; k <= replicateOpt[2]; k++ ) {
118 >            //skip original frame
119 >            if (i == 0 && j == 0 && k == 0) {
120 >              continue;
121 >            } else {
122 >              dir.push_back(Vector3i(i, j, k));
123 >            }
124 >          }
125 >        }
126 >      }
127 >    
128 >    }
129  
130 < void WrappingVisitor::visit(Atom* atom){
131 <  internalVisit(atom);
132 < }
89 < void WrappingVisitor::visit(DirectionalAtom* datom){
90 <  internalVisit(datom);
91 < }
130 >  void ReplicateVisitor::visit(Atom *atom) {
131 >    internalVisit(atom);
132 >  }
133  
134 < void WrappingVisitor::visit(RigidBody* rb){
135 <  internalVisit(rb);
136 < }
134 >  void ReplicateVisitor::visit(DirectionalAtom *datom) {
135 >    internalVisit(datom);
136 >  }
137  
138 < void WrappingVisitor::internalVisit(StuntDouble* sd){
139 <  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;
138 >  void ReplicateVisitor::visit(RigidBody *rb) {
139 >    internalVisit(rb);
140    }
109  else
110    return;
141  
142 <  for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i))
143 <    info->wrapVector(atomInfo->pos);
142 >  void ReplicateVisitor::internalVisit(StuntDouble *sd) {
143 >    GenericData *          data;
144 >    AtomData *             atomData;
145  
146 <  
147 < }
146 >    //if there is not atom data, just skip it
147 >    data = sd->getPropertyByName("ATOMDATA");
148  
149 < const string WrappingVisitor::toString(){
150 <  char buffer[65535];
120 <  string result;
121 <  
122 <  sprintf(buffer ,"------------------------------------------------------------------\n");
123 <  result += buffer;
149 >    if (data != NULL) {
150 >      atomData = dynamic_cast<AtomData *>(data);
151  
152 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
153 <  result += buffer;
152 >      if (atomData == NULL) {
153 >        return;
154 >      }
155 >    } else {
156 >      return;
157 >    }
158  
159 <  sprintf(buffer ,"Visitor Description: wrapping atoms back to periodic box\n");
160 <  result += buffer;
130 <
131 <  sprintf(buffer,"------------------------------------------------------------------\n");
132 <  result += buffer;
159 >    Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
160 >    Mat3x3d box = currSnapshot->getHmat();
161  
162 <  return result;
135 < }
162 >    std::vector<AtomInfo *> atomInfoList = atomData->getData();
163  
164 < //----------------------------------------------------------------------------//
164 >    replicate(atomInfoList, atomData, box);
165 >  }
166  
167 < ReplicateVisitor::ReplicateVisitor(SimInfo* info, IntVec3 opt) : BaseVisitor(){
168 <  this->info = info;
169 <  visitorName = "ReplicateVisitor";
170 <  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 < }
167 >  void ReplicateVisitor::replicate(std::vector<AtomInfo *>&infoList, AtomData *data, const Mat3x3d& box) {
168 >    AtomInfo* newAtomInfo;
169 >    std::vector<Vector3i>::iterator dirIter;
170 >    std::vector<AtomInfo *>::iterator i;
171  
172 < void ReplicateVisitor::visit(RigidBody* rb){
173 <  internalVisit(rb);
174 < }
172 >    for( dirIter = dir.begin(); dirIter != dir.end(); ++dirIter ) {
173 >      for( i = infoList.begin(); i != infoList.end(); i++ ) {
174 >        newAtomInfo = new AtomInfo();
175 >        *newAtomInfo = *(*i);
176  
177 < void ReplicateVisitor::internalVisit(StuntDouble* sd){
178 <  GenericData* data;
179 <  AtomData* atomData;
180 <  AtomInfo* atomInfo;
181 <  double box[3][3];
182 <  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;
177 >        for( int j = 0; j < 3; j++ )
178 >          newAtomInfo->pos[j] += (*dirIter)[0]*box(j, 0) + (*dirIter)[1]*box(j, 1) + (*dirIter)[2]*box(j, 2);
179 >
180 >        data->addAtomInfo(newAtomInfo);
181 >      }
182 >    } // end for(dirIter)  
183    }
180  else
181    return;
184  
185 <  
186 <  info->getBoxM(box);
185 >  const std::string ReplicateVisitor::toString() {
186 >    char                            buffer[65535];
187 >    std::string                     result;
188 >    std::set<std::string>::iterator i;
189  
190 <  atomInfoList = atomData->getData();
191 <  
192 <  replicate(atomInfoList, atomData, box);
190 >    sprintf(buffer,
191 >            "------------------------------------------------------------------\n");
192 >    result += buffer;
193  
194 < }
194 >    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
195 >    result += buffer;
196  
197 < void ReplicateVisitor::replicate(vector<AtomInfo*>& infoList, AtomData* data, double boxM[3][3]){
198 <  AtomInfo * newAtomInfo;
199 <  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);    
197 >    sprintf(buffer,
198 >            "Visitor Description: replicate the atoms in different direction\n");
199 >    result += buffer;
200  
201 <      for(int j = 0; j < 3; j++)
202 <        newAtomInfo->pos[j] +=   (*dirIter)[0] * boxM[j][0] + (*dirIter)[1]* boxM[j][1] + (*dirIter)[2] * boxM[j][2];
201 >    //print the replicate direction
202 >    sprintf(buffer, "repeatX = %d:\n", replicateOpt[0]);
203 >    result += buffer;
204  
205 <      data->addAtomInfo(newAtomInfo);
206 <    }
207 <  }// end for(dirIter)  
208 < }
205 >    sprintf(buffer, "repeatY = %d:\n", replicateOpt[1]);
206 >    result += buffer;
207  
208 < const string ReplicateVisitor::toString(){
209 <  char buffer[65535];
212 <  string result;
213 <  set<string>::iterator i;
214 <  
215 <  sprintf(buffer ,"------------------------------------------------------------------\n");
216 <  result += buffer;
208 >    sprintf(buffer, "repeatZ = %d:\n", replicateOpt[2]);
209 >    result += buffer;
210  
211 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
212 <  result += buffer;
211 >    sprintf(buffer,
212 >            "------------------------------------------------------------------\n");
213 >    result += buffer;
214  
215 <  sprintf(buffer ,"Visitor Description: replicate the atoms in different direction\n");
216 <  result += buffer;
223 <  
224 <  //print the replicate direction
225 <  sprintf(buffer , "repeatX = %d:\n", replicateOpt[0]);
226 <  result += buffer;
215 >    return result;
216 >  }
217  
218 <  sprintf(buffer , "repeatY = %d:\n", replicateOpt[1]);
229 <  result += buffer;
218 >  //----------------------------------------------------------------------------//
219  
220 <  sprintf(buffer , "repeatZ = %d:\n", replicateOpt[2]);
221 <  result += buffer;
220 >  XYZVisitor::XYZVisitor(SimInfo *info) :
221 >    BaseVisitor(), seleMan(info), evaluator(info){
222 >      this->info = info;
223 >      visitorName = "XYZVisitor";
224  
225 +      evaluator.loadScriptString("select all");
226  
227 <  sprintf(buffer,"------------------------------------------------------------------\n");
228 <  result += buffer;
227 >      if (!evaluator.isDynamic()) {
228 >        seleMan.setSelectionSet(evaluator.evaluate());
229 >      }
230  
231 <  return result;
239 < }
231 >    }
232  
233 < //----------------------------------------------------------------------------//
233 >  XYZVisitor::XYZVisitor(SimInfo *info, const std::string& script) :
234 >    BaseVisitor(), seleMan(info), evaluator(info) {
235 >      this->info = info;
236 >      visitorName = "XYZVisitor";
237  
238 < XYZVisitor::XYZVisitor(SimInfo* info,  bool printDipole) : BaseVisitor(){
244 <  this->info = info;
245 <  visitorName = "XYZVisitor";
246 <  this->printDipole = printDipole;
247 < }
238 >      evaluator.loadScriptString(script);
239  
240 < void XYZVisitor::visit(Atom* atom){
241 <  if(!isIgnore(atom))
242 <    internalVisit(atom);
243 < }
244 <
245 < void XYZVisitor::visit(DirectionalAtom* datom){
246 <  if(!isIgnore(datom))
247 <    internalVisit(datom);
248 < }
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;
240 >      if (!evaluator.isDynamic()) {
241 >        seleMan.setSelectionSet(evaluator.evaluate());
242 >      }
243 >          
244 >    }
245 >    
246 >  void XYZVisitor::visit(Atom *atom) {
247 >    if (isSelected(atom))
248 >      internalVisit(atom);
249    }
279  else
280    return;
250  
251 <  for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){
252 <
253 <    if(printDipole)
254 <      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]);  
251 >  void XYZVisitor::visit(DirectionalAtom *datom) {
252 >    if (isSelected(datom))
253 >      internalVisit(datom);
254 >  }
255  
256 <    frame.push_back(buffer);
257 <              
256 >  void XYZVisitor::visit(RigidBody *rb) {
257 >    if (isSelected(rb))
258 >      internalVisit(rb);
259    }
260  
261 < }
261 >  void XYZVisitor::update() {
262 >    //if dynamic, we need to re-evaluate the selection
263 >    if (evaluator.isDynamic()) {
264 >      seleMan.setSelectionSet(evaluator.evaluate());
265 >    }
266 >  }
267  
268 < bool XYZVisitor::isIgnore(StuntDouble* sd){
269 <  GenericData* data;
270 <  
271 <  data = sd->getProperty("IGNORE");
272 <  return data ==NULL ? false : true;
273 < }
268 >  void XYZVisitor::internalVisit(StuntDouble *sd) {
269 >    GenericData *                     data;
270 >    AtomData *                        atomData;
271 >    AtomInfo *                        atomInfo;
272 >    std::vector<AtomInfo *>::iterator i;
273 >    char                              buffer[1024];
274  
275 < void XYZVisitor::writeFrame(ostream& outStream){
276 <  vector<string>::iterator i;
315 <  double box[3][3];
316 <  char buffer[1024];
275 >    //if there is not atom data, just skip it
276 >    data = sd->getPropertyByName("ATOMDATA");
277  
278 <  if(frame.size() == 0)
279 <    cerr << "Current Frame does not contain any atoms" << endl;
278 >    if (data != NULL) {
279 >      atomData = dynamic_cast<AtomData *>(data);
280  
281 <  //total number of atoms  
282 <  outStream << frame.size() << endl;
281 >      if (atomData == NULL)
282 >        return;
283 >    } else
284 >      return;
285  
286 <  //write comment line
287 <  info->getBoxM(box);
288 <  sprintf(buffer,"%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f",
289 <              info->getTime(),
290 <              box[0][0], box[0][1], box[0][2],
291 <              box[1][0], box[1][1], box[1][2],
292 <              box[2][0], box[2][1], box[2][2]);
286 >    for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
287 >         atomInfo = atomData->nextAtomInfo(i) ) {
288 >      sprintf(buffer,
289 >              "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
290 >              atomInfo->atomTypeName.c_str(),
291 >              atomInfo->pos[0],
292 >              atomInfo->pos[1],
293 >              atomInfo->pos[2],
294 >              atomInfo->dipole[0],
295 >              atomInfo->dipole[1],
296 >              atomInfo->dipole[2]);
297 >      frame.push_back(buffer);
298 >    }
299 >  }
300  
301 <  outStream << buffer << endl;  
301 >  bool XYZVisitor::isSelected(StuntDouble *sd) {
302 >    return seleMan.isSelected(sd);
303 >  }
304  
305 <  for(i = frame.begin(); i != frame.end(); ++i)
306 <    outStream << *i << endl;
307 < }
305 >  void XYZVisitor::writeFrame(std::ostream &outStream) {
306 >    std::vector<std::string>::iterator i;
307 >    char buffer[1024];
308  
309 < const string XYZVisitor::toString(){
310 <  char buffer[65535];
340 <  string result;
341 <  
342 <  sprintf(buffer ,"------------------------------------------------------------------\n");
343 <  result += buffer;
309 >    if (frame.size() == 0)
310 >      std::cerr << "Current Frame does not contain any atoms" << std::endl;
311  
312 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
313 <  result += buffer;
312 >    //total number of atoms  
313 >    outStream << frame.size() << std::endl;
314  
315 <  sprintf(buffer ,"Visitor Description: assemble the atom data and output xyz file\n");
316 <  result += buffer;
317 <
318 <  sprintf(buffer,"------------------------------------------------------------------\n");
319 <  result += buffer;
315 >    //write comment line
316 >    Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
317 >    Mat3x3d box = currSnapshot->getHmat();
318 >    
319 >    sprintf(buffer,
320 >            "%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f",
321 >            currSnapshot->getTime(),
322 >            box(0, 0), box(0, 1), box(0, 2),
323 >            box(1, 0), box(1, 1), box(1, 2),
324 >            box(2, 0), box(2, 1), box(2, 2));
325  
326 <  return result;
355 < }
326 >    outStream << buffer << std::endl;
327  
328 < //----------------------------------------------------------------------------//
328 >    for( i = frame.begin(); i != frame.end(); ++i )
329 >      outStream << *i << std::endl;
330 >  }
331  
332 < void PrepareVisitor::internalVisit(Atom * atom){
333 <  GenericData* data;
334 <  AtomData* atomData;
332 >  const std::string XYZVisitor::toString() {
333 >    char        buffer[65535];
334 >    std::string result;
335  
336 <  //if visited property is  existed, remove it
337 <  data = atom->getProperty("VISITED");
338 <  if(data != NULL){
366 <    atom->removeProperty("VISITED");  
367 <  }
336 >    sprintf(buffer,
337 >            "------------------------------------------------------------------\n");
338 >    result += buffer;
339  
340 <  //remove atomdata
341 <  data = atom->getProperty("ATOMDATA");
371 <  if(data != NULL){
372 <    atomData = dynamic_cast<AtomData*>(data);  
373 <    if(atomData != NULL)
374 <      atom->removeProperty("ATOMDATA");
375 <  }
376 <  
377 < }
340 >    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
341 >    result += buffer;
342  
343 < void PrepareVisitor::internalVisit(RigidBody * rb){
344 <  GenericData* data;
345 <  AtomData* atomData;
346 <  vector<Atom*> myAtoms;
347 <  vector<Atom*>::iterator atomIter;
348 <  
349 <  //if visited property is  existed, remove it
350 <  data = rb->getProperty("VISITED");
351 <  if(data != NULL){
388 <    rb->removeProperty("VISITED");  
343 >    sprintf(buffer,
344 >            "Visitor Description: assemble the atom data and output xyz file\n");
345 >    result += buffer;
346 >
347 >    sprintf(buffer,
348 >            "------------------------------------------------------------------\n");
349 >    result += buffer;
350 >
351 >    return result;
352    }
353  
354 <  //remove atomdata
355 <  data = rb->getProperty("ATOMDATA");
356 <  if(data != NULL){
357 <    atomData = dynamic_cast<AtomData*>(data);  
358 <    if(atomData != NULL)
359 <      rb->removeProperty("ATOMDATA");
354 >  //----------------------------------------------------------------------------//
355 >
356 >  void PrepareVisitor::internalVisit(Atom *atom) {
357 >    GenericData *data;
358 >    AtomData *   atomData;
359 >
360 >    //if visited property is  existed, remove it
361 >    data = atom->getPropertyByName("VISITED");
362 >
363 >    if (data != NULL) {
364 >      atom->removeProperty("VISITED");
365 >    }
366 >
367 >    //remove atomdata
368 >    data = atom->getPropertyByName("ATOMDATA");
369 >
370 >    if (data != NULL) {
371 >      atomData = dynamic_cast<AtomData *>(data);
372 >
373 >      if (atomData != NULL)
374 >        atom->removeProperty("ATOMDATA");
375 >    }
376    }
377  
378 <  myAtoms = rb->getAtoms();
379 <    
380 <  for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter)
381 <   internalVisit (*atomIter);  
382 < }
378 >  void PrepareVisitor::internalVisit(RigidBody *rb) {
379 >    GenericData* data;
380 >    AtomData* atomData;
381 >    std::vector<Atom *> myAtoms;
382 >    std::vector<Atom *>::iterator atomIter;
383  
384 < const string PrepareVisitor::toString(){
385 <  char buffer[65535];
407 <  string result;
408 <  
409 <  sprintf(buffer ,"------------------------------------------------------------------\n");
410 <  result += buffer;
384 >    //if visited property is  existed, remove it
385 >    data = rb->getPropertyByName("VISITED");
386  
387 <  sprintf(buffer ,"Visitor name: %s", visitorName.c_str());
388 <  result += buffer;
387 >    if (data != NULL) {
388 >      rb->removeProperty("VISITED");
389 >    }
390  
391 <  sprintf(buffer ,"Visitor Description: prepare for operation of other vistors\n");
392 <  result += buffer;
391 >    //remove atomdata
392 >    data = rb->getPropertyByName("ATOMDATA");
393  
394 <  sprintf(buffer ,"------------------------------------------------------------------\n");
395 <  result += buffer;
394 >    if (data != NULL) {
395 >      atomData = dynamic_cast<AtomData *>(data);
396  
397 <  return result;
398 < }
397 >      if (atomData != NULL)
398 >        rb->removeProperty("ATOMDATA");
399 >    }
400  
401 < //----------------------------------------------------------------------------//
401 >    myAtoms = rb->getAtoms();
402  
403 < WaterTypeVisitor:: WaterTypeVisitor(){
404 <  visitorName = "WaterTypeVisitor";
405 <  waterTypeList.insert("TIP3P_RB_0");
429 <  waterTypeList.insert("TIP4P_RB_0");
430 <  waterTypeList.insert("TIP5P_RB_0");
431 <  waterTypeList.insert("SPCE_RB_0");  
432 < }
403 >    for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter )
404 >      internalVisit(*atomIter);
405 >  }
406  
407 +  const std::string PrepareVisitor::toString() {
408 +    char buffer[65535];
409 +    std::string result;
410 +
411 +    sprintf(buffer,
412 +            "------------------------------------------------------------------\n");
413 +    result += buffer;
414 +
415 +    sprintf(buffer, "Visitor name: %s", visitorName.c_str());
416 +    result += buffer;
417 +
418 +    sprintf(buffer,
419 +            "Visitor Description: prepare for operation of other vistors\n");
420 +    result += buffer;
421 +
422 +    sprintf(buffer,
423 +            "------------------------------------------------------------------\n");
424 +    result += buffer;
425 +
426 +    return result;
427 +  }
428  
429 < 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();
429 >  //----------------------------------------------------------------------------//
430  
431 <  if(waterTypeList.find(rbName) != waterTypeList.end()){
431 >  WaterTypeVisitor::WaterTypeVisitor() {
432 >    visitorName = "WaterTypeVisitor";
433 >    waterTypeList.insert("TIP3P_RB_0");
434 >    waterTypeList.insert("TIP4P_RB_0");
435 >    waterTypeList.insert("TIP5P_RB_0");
436 >    waterTypeList.insert("SPCE_RB_0");
437 >  }
438  
439 <    myAtoms = rb->getAtoms();    
440 <    for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter){
439 >  void WaterTypeVisitor::visit(RigidBody *rb) {
440 >    std::string rbName;
441 >    std::vector<Atom *> myAtoms;
442 >    std::vector<Atom *>::iterator atomIter;
443 >    GenericData* data;
444 >    AtomData* atomData;
445 >    AtomInfo* atomInfo;
446 >    std::vector<AtomInfo *>::iterator i;
447  
448 <      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)
448 >    rbName = rb->getType();
449  
450 <    }//end for(atomIter)
451 <      
466 <  }//end if (waterTypeList.find(rbName) != waterTypeList.end())
467 <  
468 < }
450 >    if (waterTypeList.find(rbName) != waterTypeList.end()) {
451 >      myAtoms = rb->getAtoms();
452  
453 < void WaterTypeVisitor:: replaceType(string& atomType){
454 <  atomType = atomType.substr(0, atomType.find('_'));
455 < }
453 >      for( atomIter = myAtoms.begin(); atomIter != myAtoms.end();
454 >           ++atomIter ) {
455 >        data = (*atomIter)->getPropertyByName("ATOMDATA");
456  
457 < const string WaterTypeVisitor:: toString(){
458 <  char buffer[65535];
476 <  string result;
477 <  
478 <  sprintf(buffer ,"------------------------------------------------------------------\n");
479 <  result += buffer;
457 >        if (data != NULL) {
458 >          atomData = dynamic_cast<AtomData *>(data);
459  
460 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
461 <  result += buffer;
460 >          if (atomData == NULL)
461 >            continue;
462 >        } else
463 >          continue;
464  
465 <  sprintf(buffer ,"Visitor Description: Replace the atom type in water model\n");
466 <  result += buffer;
465 >        for( atomInfo = atomData->beginAtomInfo(i); atomInfo;
466 >             atomInfo = atomData->nextAtomInfo(i) ) {
467 >          atomInfo->atomTypeName = trimmedName(atomInfo->atomTypeName);
468 >        } //end for(atomInfo)
469 >      }     //end for(atomIter)
470 >    }         //end if (waterTypeList.find(rbName) != waterTypeList.end())
471 >  }
472  
473 <  sprintf(buffer ,"------------------------------------------------------------------\n");
474 <  result += buffer;
473 >  std::string WaterTypeVisitor::trimmedName(const std::string&atomTypeName) {
474 >    return atomTypeName.substr(0, atomTypeName.find('_'));
475 >  }
476  
477 <  return result;
478 < }
477 >  const std::string WaterTypeVisitor::toString() {
478 >    char buffer[65535];
479 >    std::string result;
480  
481 +    sprintf(buffer,
482 +            "------------------------------------------------------------------\n");
483 +    result += buffer;
484 +
485 +    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
486 +    result += buffer;
487 +
488 +    sprintf(buffer,
489 +            "Visitor Description: Replace the atom type in water model\n");
490 +    result += buffer;
491 +
492 +    sprintf(buffer,
493 +            "------------------------------------------------------------------\n");
494 +    result += buffer;
495 +
496 +    return result;
497 +  }
498 +
499 + } //namespace oopse

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines