48#include "visitors/OtherVisitor.hpp"
53#include "brains/Thermo.hpp"
57#include "selection/SelectionManager.hpp"
61 void WrappingVisitor::visit(
Atom* atom) { internalVisit(atom); }
63 void WrappingVisitor::visit(
DirectionalAtom* datom) { internalVisit(datom); }
65 void WrappingVisitor::visit(
RigidBody* rb) { internalVisit(rb); }
67 void WrappingVisitor::internalVisit(
StuntDouble* sd) {
68 std::shared_ptr<GenericData> data;
69 std::shared_ptr<AtomData> atomData;
70 std::shared_ptr<AtomInfo> atomInfo;
71 std::vector<std::shared_ptr<AtomInfo>>::iterator i;
73 data = sd->getPropertyByName(
"ATOMDATA");
75 if (data !=
nullptr) {
76 atomData = std::dynamic_pointer_cast<AtomData>(data);
78 if (atomData ==
nullptr)
return;
82 Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
84 for (atomInfo = atomData->beginAtomInfo(i); atomInfo;
85 atomInfo = atomData->nextAtomInfo(i)) {
86 Vector3d newPos = atomInfo->pos - origin_;
87 currSnapshot->wrapVector(newPos);
88 atomInfo->pos = newPos;
92 void WrappingVisitor::update() {
95 origin_ = thermo.getCom();
99 const std::string WrappingVisitor::toString() {
105 "------------------------------------------------------------------\n");
108 snprintf(buffer, 65535,
"Visitor name: %s\n", visitorName.c_str());
111 snprintf(buffer, 65535,
112 "Visitor Description: wrapping atoms back to periodic box\n");
117 "------------------------------------------------------------------\n");
125 ReplicateVisitor::ReplicateVisitor(
SimInfo* info, Vector3i opt) :
128 visitorName =
"ReplicateVisitor";
131 for (
int i = 0; i <= replicateOpt[0]; i++) {
132 for (
int j = 0; j <= replicateOpt[1]; j++) {
133 for (
int k = 0; k <= replicateOpt[2]; k++) {
135 if (i == 0 && j == 0 && k == 0) {
138 dir.push_back(Vector3d((RealType)i, (RealType)j, (RealType)k));
145 void ReplicateVisitor::visit(Atom* atom) { internalVisit(atom); }
147 void ReplicateVisitor::visit(DirectionalAtom* datom) { internalVisit(datom); }
149 void ReplicateVisitor::visit(RigidBody* rb) { internalVisit(rb); }
151 void ReplicateVisitor::internalVisit(StuntDouble* sd) {
152 std::shared_ptr<GenericData> data;
153 std::shared_ptr<AtomData> atomData;
156 data = sd->getPropertyByName(
"ATOMDATA");
158 if (data !=
nullptr) {
159 atomData = std::dynamic_pointer_cast<AtomData>(data);
161 if (atomData ==
nullptr) {
return; }
166 Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
167 Mat3x3d box = currSnapshot->getHmat();
169 std::vector<std::shared_ptr<AtomInfo>> atomInfoList = atomData->getData();
171 replicate(atomInfoList, atomData, box);
174 void ReplicateVisitor::replicate(
175 std::vector<std::shared_ptr<AtomInfo>>& infoList,
176 std::shared_ptr<AtomData> data,
const Mat3x3d& box) {
177 std::shared_ptr<AtomInfo> newAtomInfo;
178 std::vector<Vector3d>::iterator dirIter;
179 std::vector<std::shared_ptr<AtomInfo>>::iterator i;
181 for (dirIter = dir.begin(); dirIter != dir.end(); ++dirIter) {
182 for (i = infoList.begin(); i != infoList.end(); ++i) {
183 newAtomInfo = std::make_shared<AtomInfo>();
184 *newAtomInfo = *(*i);
185 newAtomInfo->pos += box * (*dirIter);
186 data->addAtomInfo(newAtomInfo);
191 const std::string ReplicateVisitor::toString() {
197 "--------------------------------------------------------------\n");
200 snprintf(buffer, 65535,
"Visitor name: %s\n", visitorName.c_str());
205 "Visitor Description: replicate the atoms in different direction\n");
209 snprintf(buffer, 65535,
"repeatX = %d:\n", replicateOpt[0]);
212 snprintf(buffer, 65535,
"repeatY = %d:\n", replicateOpt[1]);
215 snprintf(buffer, 65535,
"repeatZ = %d:\n", replicateOpt[2]);
220 "--------------------------------------------------------------\n");
228 XYZVisitor::XYZVisitor(SimInfo* info) :
229 BaseVisitor(), seleMan(info), evaluator(info), doPositions_(true),
230 doVelocities_(false), doForces_(false), doVectors_(false),
231 doCharges_(false), doElectricFields_(false), doGlobalIDs_(false) {
233 visitorName =
"XYZVisitor";
235 evaluator.loadScriptString(
"select all");
237 if (!evaluator.isDynamic()) {
238 seleMan.setSelectionSet(evaluator.evaluate());
242 XYZVisitor::XYZVisitor(SimInfo* info,
const std::string& script) :
243 BaseVisitor(), seleMan(info), evaluator(info), doPositions_(true),
244 doVelocities_(false), doForces_(false), doVectors_(false),
245 doCharges_(false), doElectricFields_(false), doGlobalIDs_(false) {
247 visitorName =
"XYZVisitor";
249 evaluator.loadScriptString(script);
251 if (!evaluator.isDynamic()) {
252 seleMan.setSelectionSet(evaluator.evaluate());
256 void XYZVisitor::visit(Atom* atom) {
257 if (isSelected(atom)) internalVisit(atom);
260 void XYZVisitor::visit(DirectionalAtom* datom) {
261 if (isSelected(datom)) internalVisit(datom);
264 void XYZVisitor::visit(RigidBody* rb) {
265 if (isSelected(rb)) internalVisit(rb);
268 void XYZVisitor::update() {
270 if (evaluator.isDynamic()) {
271 seleMan.setSelectionSet(evaluator.evaluate());
275 void XYZVisitor::internalVisit(StuntDouble* sd) {
276 std::shared_ptr<GenericData> data;
277 std::shared_ptr<AtomData> atomData;
278 std::shared_ptr<AtomInfo> atomInfo;
279 std::vector<std::shared_ptr<AtomInfo>>::iterator i;
283 data = sd->getPropertyByName(
"ATOMDATA");
285 if (data !=
nullptr) {
286 atomData = std::dynamic_pointer_cast<AtomData>(data);
288 if (atomData ==
nullptr)
return;
292 for (atomInfo = atomData->beginAtomInfo(i); atomInfo;
293 atomInfo = atomData->nextAtomInfo(i)) {
295 snprintf(buffer, 1024,
"%s", atomInfo->atomTypeName.c_str());
299 snprintf(buffer, 1024,
"%15.8f%15.8f%15.8f", atomInfo->pos[0],
300 atomInfo->pos[1], atomInfo->pos[2]);
303 if (doCharges_ && atomInfo->hasCharge) {
304 snprintf(buffer, 1024,
"%15.8f", atomInfo->charge);
307 if (doVectors_ && atomInfo->hasVector) {
308 snprintf(buffer, 1024,
"%15.8f%15.8f%15.8f", atomInfo->vec[0],
309 atomInfo->vec[1], atomInfo->vec[2]);
312 if (doVelocities_ && atomInfo->hasVelocity) {
313 snprintf(buffer, 1024,
"%15.8f%15.8f%15.8f", atomInfo->vel[0],
314 atomInfo->vel[1], atomInfo->vel[2]);
317 if (doForces_ && atomInfo->hasForce) {
318 snprintf(buffer, 1024,
"%15.8f%15.8f%15.8f", atomInfo->frc[0],
319 atomInfo->frc[1], atomInfo->frc[2]);
322 if (doElectricFields_ && atomInfo->hasElectricField) {
323 snprintf(buffer, 1024,
"%15.8f%15.8f%15.8f", atomInfo->eField[0],
324 atomInfo->eField[1], atomInfo->eField[2]);
328 snprintf(buffer, 1024,
"%10d", atomInfo->globalID);
332 frame.push_back(line);
336 bool XYZVisitor::isSelected(StuntDouble* sd) {
337 return seleMan.isSelected(sd);
340 void XYZVisitor::writeFrame(std::ostream& outStream) {
341 std::vector<std::string>::iterator i;
345 std::cerr <<
"Current Frame does not contain any atoms" << std::endl;
348 outStream << frame.size() << std::endl;
351 Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
352 Mat3x3d box = currSnapshot->getHmat();
354 snprintf(buffer, 1024,
355 "%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f",
356 currSnapshot->getTime(), box(0, 0), box(0, 1), box(0, 2),
357 box(1, 0), box(1, 1), box(1, 2), box(2, 0), box(2, 1), box(2, 2));
359 outStream << buffer << std::endl;
361 for (i = frame.begin(); i != frame.end(); ++i)
362 outStream << *i << std::endl;
365 std::string XYZVisitor::trimmedName(
const std::string& atomTypeName) {
366 return atomTypeName.substr(0, atomTypeName.find(
'-'));
369 const std::string XYZVisitor::toString() {
375 "------------------------------------------------------------------\n");
378 snprintf(buffer, 65535,
"Visitor name: %s\n", visitorName.c_str());
383 "Visitor Description: assemble the atom data and output xyz file\n");
388 "------------------------------------------------------------------\n");
396 void PrepareVisitor::internalVisit(Atom* atom) {
397 std::shared_ptr<GenericData> data;
400 data = atom->getPropertyByName(
"VISITED");
402 if (data !=
nullptr) { atom->removeProperty(
"VISITED"); }
405 data = atom->getPropertyByName(
"ATOMDATA");
407 if (data !=
nullptr) {
408 std::shared_ptr<AtomData> atomData =
409 std::dynamic_pointer_cast<AtomData>(data);
411 if (atomData != NULL) atom->removeProperty(
"ATOMDATA");
415 void PrepareVisitor::internalVisit(RigidBody* rb) {
416 std::shared_ptr<GenericData> data;
417 std::shared_ptr<AtomData> atomData;
418 std::vector<Atom*> myAtoms;
419 std::vector<Atom*>::iterator atomIter;
422 data = rb->getPropertyByName(
"VISITED");
424 if (data !=
nullptr) { rb->removeProperty(
"VISITED"); }
427 data = rb->getPropertyByName(
"ATOMDATA");
429 if (data !=
nullptr) {
430 atomData = std::dynamic_pointer_cast<AtomData>(data);
432 if (atomData != NULL) rb->removeProperty(
"ATOMDATA");
435 myAtoms = rb->getAtoms();
437 for (atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter)
438 internalVisit(*atomIter);
441 const std::string PrepareVisitor::toString() {
447 "------------------------------------------------------------------\n");
450 snprintf(buffer, 65535,
"Visitor name: %s", visitorName.c_str());
453 snprintf(buffer, 65535,
454 "Visitor Description: prepare for operation of other vistors\n");
459 "------------------------------------------------------------------\n");
467 WaterTypeVisitor::WaterTypeVisitor() {
468 visitorName =
"WaterTypeVisitor";
469 waterTypeList.insert(
"TIP3P_RB_0");
470 waterTypeList.insert(
"TIP3P-FB_RB_0");
471 waterTypeList.insert(
"TIP4P_RB_0");
472 waterTypeList.insert(
"TIP4P-Ice_RB_0");
473 waterTypeList.insert(
"TIP4P-Ew_RB_0");
474 waterTypeList.insert(
"TIP4P-2005_RB_0");
475 waterTypeList.insert(
"TIP4P-FB_RB_0");
476 waterTypeList.insert(
"TIP5P_RB_0");
477 waterTypeList.insert(
"TIP5P-E_RB_0");
478 waterTypeList.insert(
"SPCE_RB_0");
479 waterTypeList.insert(
"SPC_RB_0");
480 waterTypeList.insert(
"SPC-HW_RB_0");
481 waterTypeList.insert(
"NE6_RB_0");
482 waterTypeList.insert(
"OPC_RB_0");
483 waterTypeList.insert(
"OPC3_RB_0");
486 void WaterTypeVisitor::visit(RigidBody* rb) {
488 std::vector<Atom*> myAtoms;
489 std::vector<Atom*>::iterator atomIter;
490 std::vector<std::shared_ptr<AtomInfo>>::iterator i;
491 std::shared_ptr<AtomData> atomData;
493 rbName = rb->getType();
495 if (waterTypeList.find(rbName) != waterTypeList.end()) {
496 myAtoms = rb->getAtoms();
498 for (atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter) {
499 std::shared_ptr<GenericData> data =
500 (*atomIter)->getPropertyByName(
"ATOMDATA");
502 if (data !=
nullptr) {
503 atomData = std::dynamic_pointer_cast<AtomData>(data);
505 if (atomData ==
nullptr)
continue;
509 for (std::shared_ptr<AtomInfo> atomInfo = atomData->beginAtomInfo(i);
510 atomInfo; atomInfo = atomData->nextAtomInfo(i)) {
511 atomInfo->atomTypeName = trimmedName(atomInfo->atomTypeName);
517 std::string WaterTypeVisitor::trimmedName(
const std::string& atomTypeName) {
518 return atomTypeName.substr(0, atomTypeName.find(
'_'));
521 const std::string WaterTypeVisitor::toString() {
527 "------------------------------------------------------------------\n");
530 snprintf(buffer, 65535,
"Visitor name: %s\n", visitorName.c_str());
533 snprintf(buffer, 65535,
534 "Visitor Description: Replace the atom type in water model\n");
539 "------------------------------------------------------------------\n");
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
"Don't move, or you're dead! Stand up! Captain, we've got them!"
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.