ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/visitors/OtherVisitor.cpp
Revision: 1702
Committed: Thu Apr 5 19:49:59 2012 UTC (13 years ago) by kstocke1
File size: 16208 byte(s)
Log Message:
Un-did some changes that weren't ready to be committed.

File Contents

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

Properties

Name Value
svn:executable *
svn:keywords Author Id Revision Date