ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/visitors/OtherVisitor.cpp
Revision: 1930
Committed: Wed Jan 12 22:41:40 2005 UTC (19 years, 5 months ago) by gezelter
File size: 16529 byte(s)
Log Message:
merging new_design branch into OOPSE-2.0

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

Properties

Name Value
svn:executable *