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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines