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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines