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