ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/visitors/OtherVisitor.cpp
Revision: 3446
Committed: Wed Sep 10 19:51:45 2008 UTC (15 years, 9 months ago) by cli2
File size: 15804 byte(s)
Log Message:
Inversion fixes and amber mostly working

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 * 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"
46 namespace oopse {
47
48 void WrappingVisitor::visit(Atom *atom) {
49 internalVisit(atom);
50 }
51
52 void WrappingVisitor::visit(DirectionalAtom *datom) {
53 internalVisit(datom);
54 }
55
56 void WrappingVisitor::visit(RigidBody *rb) {
57 internalVisit(rb);
58 }
59
60 void WrappingVisitor::internalVisit(StuntDouble *sd) {
61 GenericData * data;
62 AtomData * atomData;
63 AtomInfo * atomInfo;
64 std::vector<AtomInfo *>::iterator i;
65
66 data = sd->getPropertyByName("ATOMDATA");
67
68 if (data != NULL) {
69 atomData = dynamic_cast<AtomData *>(data);
70
71 if (atomData == NULL)
72 return;
73 } else
74 return;
75
76 Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
77
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 void WrappingVisitor::update() {
86 if (useCom_){
87 origin_ = info->getCom();
88 }
89 }
90
91 const std::string WrappingVisitor::toString() {
92 char buffer[65535];
93 std::string result;
94
95 sprintf(buffer,
96 "------------------------------------------------------------------\n");
97 result += buffer;
98
99 sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
100 result += buffer;
101
102 sprintf(buffer,
103 "Visitor Description: wrapping atoms back to periodic box\n");
104 result += buffer;
105
106 sprintf(buffer,
107 "------------------------------------------------------------------\n");
108 result += buffer;
109
110 return result;
111 }
112
113 //----------------------------------------------------------------------------//
114
115 ReplicateVisitor::ReplicateVisitor(SimInfo *info, Vector3i opt) :
116 BaseVisitor() {
117 this->info = info;
118 visitorName = "ReplicateVisitor";
119 this->replicateOpt = opt;
120
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 ReplicateVisitor::visit(Atom *atom) {
138 internalVisit(atom);
139 }
140
141 void ReplicateVisitor::visit(DirectionalAtom *datom) {
142 internalVisit(datom);
143 }
144
145 void ReplicateVisitor::visit(RigidBody *rb) {
146 internalVisit(rb);
147 }
148
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 }
165
166 Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
167 Mat3x3d box = currSnapshot->getHmat();
168
169 std::vector<AtomInfo *> atomInfoList = atomData->getData();
170
171 replicate(atomInfoList, atomData, box);
172 }
173
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 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 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 data->addAtomInfo(newAtomInfo);
188 }
189 } // end for(dirIter)
190 }
191
192 const std::string ReplicateVisitor::toString() {
193 char buffer[65535];
194 std::string result;
195 std::set<std::string>::iterator i;
196
197 sprintf(buffer,
198 "------------------------------------------------------------------\n");
199 result += buffer;
200
201 sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
202 result += buffer;
203
204 sprintf(buffer,
205 "Visitor Description: replicate the atoms in different direction\n");
206 result += buffer;
207
208 //print the replicate direction
209 sprintf(buffer, "repeatX = %d:\n", replicateOpt[0]);
210 result += buffer;
211
212 sprintf(buffer, "repeatY = %d:\n", replicateOpt[1]);
213 result += buffer;
214
215 sprintf(buffer, "repeatZ = %d:\n", replicateOpt[2]);
216 result += buffer;
217
218 sprintf(buffer,
219 "------------------------------------------------------------------\n");
220 result += buffer;
221
222 return result;
223 }
224
225 //----------------------------------------------------------------------------//
226
227 XYZVisitor::XYZVisitor(SimInfo *info) :
228 BaseVisitor(), seleMan(info), evaluator(info){
229 this->info = info;
230 visitorName = "XYZVisitor";
231
232 evaluator.loadScriptString("select all");
233
234 if (!evaluator.isDynamic()) {
235 seleMan.setSelectionSet(evaluator.evaluate());
236 }
237 posOnly_ = false;
238 }
239
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 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 void XYZVisitor::visit(DirectionalAtom *datom) {
259 if (isSelected(datom))
260 internalVisit(datom);
261 }
262
263 void XYZVisitor::visit(RigidBody *rb) {
264 if (isSelected(rb))
265 internalVisit(rb);
266 }
267
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::internalVisit(StuntDouble *sd) {
276 GenericData * data;
277 AtomData * atomData;
278 AtomInfo * atomInfo;
279 std::vector<AtomInfo *>::iterator i;
280 char buffer[1024];
281
282 //if there is not atom data, just skip it
283 data = sd->getPropertyByName("ATOMDATA");
284
285 if (data != NULL) {
286 atomData = dynamic_cast<AtomData *>(data);
287
288 if (atomData == NULL)
289 return;
290 } else
291 return;
292
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 bool XYZVisitor::isSelected(StuntDouble *sd) {
348 return seleMan.isSelected(sd);
349 }
350
351 void XYZVisitor::writeFrame(std::ostream &outStream) {
352 std::vector<std::string>::iterator i;
353 char buffer[1024];
354
355 if (frame.size() == 0)
356 std::cerr << "Current Frame does not contain any atoms" << std::endl;
357
358 //total number of atoms
359 outStream << frame.size() << std::endl;
360
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 outStream << buffer << std::endl;
373
374 for( i = frame.begin(); i != frame.end(); ++i )
375 outStream << *i << std::endl;
376 }
377
378 std::string XYZVisitor::trimmedName(const std::string&atomTypeName) {
379 return atomTypeName.substr(0, atomTypeName.find('-'));
380 }
381
382 std::string XYZVisitor::baseTypeName(AtomType* at) {
383 std::vector<AtomType*> ayb = at->allYourBase();
384 return ayb[ayb.size()-1]->getName();
385 }
386
387 const std::string XYZVisitor::toString() {
388 char buffer[65535];
389 std::string result;
390
391 sprintf(buffer,
392 "------------------------------------------------------------------\n");
393 result += buffer;
394
395 sprintf(buffer, "Visitor name: %s\n", visitorName.c_str());
396 result += buffer;
397
398 sprintf(buffer,
399 "Visitor Description: assemble the atom data and output xyz file\n");
400 result += buffer;
401
402 sprintf(buffer,
403 "------------------------------------------------------------------\n");
404 result += buffer;
405
406 return result;
407 }
408
409 //----------------------------------------------------------------------------//
410
411 void PrepareVisitor::internalVisit(Atom *atom) {
412 GenericData *data;
413 AtomData * atomData;
414
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 void PrepareVisitor::internalVisit(RigidBody *rb) {
434 GenericData* data;
435 AtomData* atomData;
436 std::vector<Atom *> myAtoms;
437 std::vector<Atom *>::iterator atomIter;
438
439 //if visited property is existed, remove it
440 data = rb->getPropertyByName("VISITED");
441
442 if (data != NULL) {
443 rb->removeProperty("VISITED");
444 }
445
446 //remove atomdata
447 data = rb->getPropertyByName("ATOMDATA");
448
449 if (data != NULL) {
450 atomData = dynamic_cast<AtomData *>(data);
451
452 if (atomData != NULL)
453 rb->removeProperty("ATOMDATA");
454 }
455
456 myAtoms = rb->getAtoms();
457
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 //----------------------------------------------------------------------------//
485
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 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 rbName = rb->getType();
504
505 if (waterTypeList.find(rbName) != waterTypeList.end()) {
506 myAtoms = rb->getAtoms();
507
508 for( atomIter = myAtoms.begin(); atomIter != myAtoms.end();
509 ++atomIter ) {
510 data = (*atomIter)->getPropertyByName("ATOMDATA");
511
512 if (data != NULL) {
513 atomData = dynamic_cast<AtomData *>(data);
514
515 if (atomData == NULL)
516 continue;
517 } else
518 continue;
519
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 std::string WaterTypeVisitor::trimmedName(const std::string&atomTypeName) {
529 return atomTypeName.substr(0, atomTypeName.find('_'));
530 }
531
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 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

Properties

Name Value
svn:executable *