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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines