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 3446 by cli2, Wed Sep 10 19:51:45 2008 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 + * 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"
6
46   namespace oopse {
47  
48 < //----------------------------------------------------------------------------//
10 < void IgnoreVisitor::visit(Atom* atom){
11 <  if(isIgnoreType(atom->getType()))
48 >  void WrappingVisitor::visit(Atom *atom) {
49      internalVisit(atom);
50 < }
50 >  }
51  
52 < void IgnoreVisitor::visit(DirectionalAtom* datom){
16 <  if(isIgnoreType(datom->getType()))
52 >  void WrappingVisitor::visit(DirectionalAtom *datom) {
53      internalVisit(datom);
54 < }
54 >  }
55  
56 < void IgnoreVisitor::visit(RigidBody* rb){
21 <  vector<Atom*> myAtoms;
22 <  vector<Atom*>::iterator atomIter;
23 <  AtomInfo* atomInfo;
24 <  
25 <  if(isIgnoreType(rb->getType())){
26 <    
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 <  }
35 <  
36 < }
66 >    data = sd->getPropertyByName("ATOMDATA");
67  
68 < bool IgnoreVisitor::isIgnoreType(const string& name){
69 <  return itList.find(name) != itList.end() ? true : false;
40 < }
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
47 <  if (data == NULL){
48 <    data = new GenericData;
49 <    data->setID("IGNORE");
50 <    sd->addProperty(data);
51 <  }
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    }
78  sprintf(buffer ,"\n");
79  result += buffer;
112  
113 <  sprintf(buffer ,"------------------------------------------------------------------\n");
82 <  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 < }
92 < void WrappingVisitor::visit(DirectionalAtom* datom){
93 <  internalVisit(datom);
94 < }
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;
147 <  AtomData* atomData;
103 <  AtomInfo* atomInfo;
104 <  vector<AtomInfo*>::iterator i;
145 >  void ReplicateVisitor::visit(RigidBody *rb) {
146 >    internalVisit(rb);
147 >  }
148  
149 <  data = sd->getProperty("ATOMDATA");
150 <  if(data != NULL){
151 <    atomData = dynamic_cast<AtomData*>(data);  
152 <    if(atomData == NULL)
149 >  void ReplicateVisitor::internalVisit(StuntDouble *sd) {
150 >    GenericData *          data;
151 >    AtomData *             atomData;
152 >
153 >    //if there is not atom data, just skip it
154 >    data = sd->getPropertyByName("ATOMDATA");
155 >
156 >    if (data != NULL) {
157 >      atomData = dynamic_cast<AtomData *>(data);
158 >
159 >      if (atomData == NULL) {
160 >        return;
161 >      }
162 >    } else {
163        return;
164 <  }
112 <  else
113 <    return;
164 >    }
165  
166 <  for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i))
167 <    info->wrapVector(atomInfo->pos);
166 >    Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
167 >    Mat3x3d box = currSnapshot->getHmat();
168  
169 <  
119 < }
169 >    std::vector<AtomInfo *> atomInfoList = atomData->getData();
170  
171 < const string WrappingVisitor::toString(){
172 <  char buffer[65535];
123 <  string result;
124 <  
125 <  sprintf(buffer ,"------------------------------------------------------------------\n");
126 <  result += buffer;
171 >    replicate(atomInfoList, atomData, box);
172 >  }
173  
174 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
175 <  result += buffer;
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 <  sprintf(buffer ,"Visitor Description: wrapping atoms back to periodic box\n");
180 <  result += buffer;
181 <
182 <  sprintf(buffer,"------------------------------------------------------------------\n");
135 <  result += buffer;
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 <  return result;
185 < }
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 < //----------------------------------------------------------------------------//
187 >        data->addAtomInfo(newAtomInfo);
188 >      }
189 >    } // end for(dirIter)  
190 >  }
191  
192 < ReplicateVisitor::ReplicateVisitor(SimInfo* info, IntVec3 opt) : BaseVisitor(){
193 <  this->info = info;
194 <  visitorName = "ReplicateVisitor";
195 <  this->replicateOpt = opt;
146 <  //generate the replicate directions
147 <  for(int i = 0; i <= replicateOpt[0]; i ++)
148 <    for(int j = 0; j <= replicateOpt[1]; j ++)
149 <      for(int k = 0; k <= replicateOpt[2]; k ++)
150 <        //skip original frame
151 <        if(i == 0 && j ==0 && k ==0)
152 <          continue;
153 <        else
154 <          dir.push_back(IntVec3(i, j, k));
155 <  
156 < }
157 < void ReplicateVisitor::visit(Atom* atom){
158 <  internalVisit(atom);
159 < }
160 < void ReplicateVisitor::visit(DirectionalAtom* datom){
161 <  internalVisit(datom);
162 < }
192 >  const std::string ReplicateVisitor::toString() {
193 >    char                            buffer[65535];
194 >    std::string                     result;
195 >    std::set<std::string>::iterator i;
196  
197 < void ReplicateVisitor::visit(RigidBody* rb){
198 <  internalVisit(rb);
199 < }
197 >    sprintf(buffer,
198 >            "------------------------------------------------------------------\n");
199 >    result += buffer;
200  
201 < void ReplicateVisitor::internalVisit(StuntDouble* sd){
202 <  GenericData* data;
170 <  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;
201 >    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
202 >    result += buffer;
203  
204 <  
205 <  info->getBoxM(box);
204 >    sprintf(buffer,
205 >            "Visitor Description: replicate the atoms in different direction\n");
206 >    result += buffer;
207  
208 <  atomInfoList = atomData->getData();
209 <  
210 <  replicate(atomInfoList, atomData, box);
208 >    //print the replicate direction
209 >    sprintf(buffer, "repeatX = %d:\n", replicateOpt[0]);
210 >    result += buffer;
211  
212 < }
212 >    sprintf(buffer, "repeatY = %d:\n", replicateOpt[1]);
213 >    result += buffer;
214  
215 < void ReplicateVisitor::replicate(vector<AtomInfo*>& infoList, AtomData* data, double boxM[3][3]){
216 <  AtomInfo * newAtomInfo;
197 <  vector<IntVec3>::iterator dirIter;
198 <  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);    
215 >    sprintf(buffer, "repeatZ = %d:\n", replicateOpt[2]);
216 >    result += buffer;
217  
218 <      for(int j = 0; j < 3; j++)
219 <        newAtomInfo->pos[j] +=   (*dirIter)[0] * boxM[j][0] + (*dirIter)[1]* boxM[j][1] + (*dirIter)[2] * boxM[j][2];
218 >    sprintf(buffer,
219 >            "------------------------------------------------------------------\n");
220 >    result += buffer;
221  
222 <      data->addAtomInfo(newAtomInfo);
223 <    }
210 <  }// end for(dirIter)  
211 < }
222 >    return result;
223 >  }
224  
225 < const string ReplicateVisitor::toString(){
214 <  char buffer[65535];
215 <  string result;
216 <  set<string>::iterator i;
217 <  
218 <  sprintf(buffer ,"------------------------------------------------------------------\n");
219 <  result += buffer;
225 >  //----------------------------------------------------------------------------//
226  
227 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
228 <  result += buffer;
227 >  XYZVisitor::XYZVisitor(SimInfo *info) :
228 >    BaseVisitor(), seleMan(info), evaluator(info){
229 >      this->info = info;
230 >      visitorName = "XYZVisitor";
231  
232 <  sprintf(buffer ,"Visitor Description: replicate the atoms in different direction\n");
225 <  result += buffer;
226 <  
227 <  //print the replicate direction
228 <  sprintf(buffer , "repeatX = %d:\n", replicateOpt[0]);
229 <  result += buffer;
232 >      evaluator.loadScriptString("select all");
233  
234 <  sprintf(buffer , "repeatY = %d:\n", replicateOpt[1]);
235 <  result += buffer;
234 >      if (!evaluator.isDynamic()) {
235 >        seleMan.setSelectionSet(evaluator.evaluate());
236 >      }
237 >      posOnly_ = false;
238 >    }
239  
240 <  sprintf(buffer , "repeatZ = %d:\n", replicateOpt[2]);
241 <  result += buffer;
240 >  XYZVisitor::XYZVisitor(SimInfo *info, const std::string& script) :
241 >    BaseVisitor(), seleMan(info), evaluator(info) {
242 >      this->info = info;
243 >      visitorName = "XYZVisitor";
244  
245 +      evaluator.loadScriptString(script);
246  
247 <  sprintf(buffer,"------------------------------------------------------------------\n");
248 <  result += buffer;
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 <  return result;
259 < }
258 >  void XYZVisitor::visit(DirectionalAtom *datom) {
259 >    if (isSelected(datom))
260 >      internalVisit(datom);
261 >  }
262  
263 < //----------------------------------------------------------------------------//
263 >  void XYZVisitor::visit(RigidBody *rb) {
264 >    if (isSelected(rb))
265 >      internalVisit(rb);
266 >  }
267  
268 < XYZVisitor::XYZVisitor(SimInfo* info,  bool printDipole) : BaseVisitor(){
269 <  this->info = info;
270 <  visitorName = "XYZVisitor";
271 <  this->printDipole = printDipole;
272 < }
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 < void XYZVisitor::visit(Atom* atom){
276 <  if(!isIgnore(atom))
277 <    internalVisit(atom);
278 < }
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 < void XYZVisitor::visit(DirectionalAtom* datom){
283 <  if(!isIgnore(datom))
259 <    internalVisit(datom);
260 < }
282 >    //if there is not atom data, just skip it
283 >    data = sd->getPropertyByName("ATOMDATA");
284  
285 < void XYZVisitor::visit(RigidBody* rb){
286 <  if(!isIgnore(rb))
264 <    internalVisit(rb);
285 >    if (data != NULL) {
286 >      atomData = dynamic_cast<AtomData *>(data);
287  
288 < }
289 <
290 < void XYZVisitor::internalVisit(StuntDouble* sd){
291 <  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;
284 <
285 <  for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){
286 <
287 <    if(printDipole)
288 <      sprintf(buffer, "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
289 <                  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]);  
288 >      if (atomData == NULL)
289 >        return;
290 >    } else
291 >      return;
292  
293 <    frame.push_back(buffer);
294 <              
293 >    AtomType* at = dynamic_cast<Atom *>(sd)->getAtomType();
294 >    std::string bn = baseTypeName(at);
295 >
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 < }
347 >  bool XYZVisitor::isSelected(StuntDouble *sd) {
348 >    return seleMan.isSelected(sd);
349 >  }
350  
351 < bool XYZVisitor::isIgnore(StuntDouble* sd){
352 <  GenericData* data;
353 <  
312 <  data = sd->getProperty("IGNORE");
313 <  return data ==NULL ? false : true;
314 < }
351 >  void XYZVisitor::writeFrame(std::ostream &outStream) {
352 >    std::vector<std::string>::iterator i;
353 >    char buffer[1024];
354  
355 < void XYZVisitor::writeFrame(ostream& outStream){
356 <  vector<string>::iterator i;
318 <  double box[3][3];
319 <  char buffer[1024];
355 >    if (frame.size() == 0)
356 >      std::cerr << "Current Frame does not contain any atoms" << std::endl;
357  
358 <  if(frame.size() == 0)
359 <    cerr << "Current Frame does not contain any atoms" << endl;
358 >    //total number of atoms  
359 >    outStream << frame.size() << std::endl;
360  
361 <  //total number of atoms  
362 <  outStream << frame.size() << endl;
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 <  //write comment line
328 <  info->getBoxM(box);
329 <  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]);
372 >    outStream << buffer << std::endl;
373  
374 <  outStream << buffer << endl;  
374 >    for( i = frame.begin(); i != frame.end(); ++i )
375 >      outStream << *i << std::endl;
376 >  }
377  
378 <  for(i = frame.begin(); i != frame.end(); ++i)
379 <    outStream << *i << endl;
380 < }
378 >  std::string XYZVisitor::trimmedName(const std::string&atomTypeName) {    
379 >    return atomTypeName.substr(0, atomTypeName.find('-'));
380 >  }
381  
382 < const string XYZVisitor::toString(){
383 <  char buffer[65535];
384 <  string result;
385 <  
345 <  sprintf(buffer ,"------------------------------------------------------------------\n");
346 <  result += buffer;
382 >  std::string XYZVisitor::baseTypeName(AtomType* at) {
383 >    std::vector<AtomType*> ayb = at->allYourBase();
384 >    return ayb[ayb.size()-1]->getName();
385 >  }
386  
387 <  sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
388 <  result += buffer;
387 >  const std::string XYZVisitor::toString() {
388 >    char        buffer[65535];
389 >    std::string result;
390  
391 <  sprintf(buffer ,"Visitor Description: assemble the atom data and output xyz file\n");
392 <  result += buffer;
393 <
354 <  sprintf(buffer,"------------------------------------------------------------------\n");
355 <  result += buffer;
391 >    sprintf(buffer,
392 >            "------------------------------------------------------------------\n");
393 >    result += buffer;
394  
395 <  return result;
396 < }
395 >    sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
396 >    result += buffer;
397  
398 < //----------------------------------------------------------------------------//
398 >    sprintf(buffer,
399 >            "Visitor Description: assemble the atom data and output xyz file\n");
400 >    result += buffer;
401  
402 < void PrepareVisitor::internalVisit(Atom * atom){
403 <  GenericData* data;
404 <  AtomData* atomData;
402 >    sprintf(buffer,
403 >            "------------------------------------------------------------------\n");
404 >    result += buffer;
405  
406 <  //if visited property is  existed, remove it
367 <  data = atom->getProperty("VISITED");
368 <  if(data != NULL){
369 <    atom->removeProperty("VISITED");  
406 >    return result;
407    }
408  
409 <  //remove atomdata
373 <  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 < }
409 >  //----------------------------------------------------------------------------//
410  
411 < void PrepareVisitor::internalVisit(RigidBody * rb){
412 <  GenericData* data;
413 <  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 <  }
411 >  void PrepareVisitor::internalVisit(Atom *atom) {
412 >    GenericData *data;
413 >    AtomData *   atomData;
414  
415 <  //remove atomdata
416 <  data = rb->getProperty("ATOMDATA");
417 <  if(data != NULL){
418 <    atomData = dynamic_cast<AtomData*>(data);  
419 <    if(atomData != NULL)
420 <      rb->removeProperty("ATOMDATA");
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];
410 <  string result;
411 <  
412 <  sprintf(buffer ,"------------------------------------------------------------------\n");
413 <  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");
432 <  waterTypeList.insert("TIP4P_RB_0");
433 <  waterTypeList.insert("TIP5P_RB_0");
434 <  waterTypeList.insert("SPCE_RB_0");  
435 < }
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){
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();
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");
455 <      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)
503 >    rbName = rb->getType();
504  
505 <    }//end for(atomIter)
506 <      
469 <  }//end if (waterTypeList.find(rbName) != waterTypeList.end())
470 <  
471 < }
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];
479 <  string result;
480 <  
481 <  sprintf(buffer ,"------------------------------------------------------------------\n");
482 <  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 < }//namespace oopse
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