ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/visitors/OtherVisitor.cpp
Revision: 2097
Committed: Wed Mar 9 17:30:29 2005 UTC (19 years, 4 months ago) by tim
File size: 14762 byte(s)
Log Message:
adding IndexFinder which is used to select the molecules; Seperate ElectrostaticAtomTypesSectionParser into
ChargeAtomTypesSectionParser and MultipoleAtomTypesSectionParser;remove print dipole option from Dump2XYZ;

File Contents

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

Properties

Name Value
svn:executable *