45#include "visitors/OtherVisitor.hpp"
50#include "brains/Thermo.hpp"
54#include "selection/SelectionManager.hpp"
58 void WrappingVisitor::visit(Atom* atom) { internalVisit(atom); }
60 void WrappingVisitor::visit(DirectionalAtom* datom) { internalVisit(datom); }
62 void WrappingVisitor::visit(RigidBody* rb) { internalVisit(rb); }
64 void WrappingVisitor::internalVisit(StuntDouble* sd) {
65 std::shared_ptr<GenericData> data;
66 std::shared_ptr<AtomData> atomData;
67 std::shared_ptr<AtomInfo> atomInfo;
68 std::vector<std::shared_ptr<AtomInfo>>::iterator i;
70 data = sd->getPropertyByName(
"ATOMDATA");
72 if (data !=
nullptr) {
73 atomData = std::dynamic_pointer_cast<AtomData>(data);
75 if (atomData ==
nullptr)
return;
81 for (atomInfo = atomData->beginAtomInfo(i); atomInfo;
82 atomInfo = atomData->nextAtomInfo(i)) {
83 Vector3d newPos = atomInfo->pos - origin_;
84 currSnapshot->wrapVector(newPos);
85 atomInfo->pos = newPos;
89 void WrappingVisitor::update() {
92 origin_ = thermo.getCom();
96 const std::string WrappingVisitor::toString() {
102 "------------------------------------------------------------------\n");
105 snprintf(buffer, 65535,
"Visitor name: %s\n", visitorName.c_str());
108 snprintf(buffer, 65535,
109 "Visitor Description: wrapping atoms back to periodic box\n");
114 "------------------------------------------------------------------\n");
122 ReplicateVisitor::ReplicateVisitor(SimInfo* info, Vector3i opt) :
123 BaseVisitor(), replicateOpt(opt) {
125 visitorName =
"ReplicateVisitor";
128 for (
int i = 0; i <= replicateOpt[0]; i++) {
129 for (
int j = 0; j <= replicateOpt[1]; j++) {
130 for (
int k = 0; k <= replicateOpt[2]; k++) {
132 if (i == 0 && j == 0 && k == 0) {
135 dir.push_back(Vector3d((RealType)i, (RealType)j, (RealType)k));
142 void ReplicateVisitor::visit(Atom* atom) { internalVisit(atom); }
144 void ReplicateVisitor::visit(DirectionalAtom* datom) { internalVisit(datom); }
146 void ReplicateVisitor::visit(RigidBody* rb) { internalVisit(rb); }
148 void ReplicateVisitor::internalVisit(StuntDouble* sd) {
149 std::shared_ptr<GenericData> data;
150 std::shared_ptr<AtomData> atomData;
153 data = sd->getPropertyByName(
"ATOMDATA");
155 if (data !=
nullptr) {
156 atomData = std::dynamic_pointer_cast<AtomData>(data);
158 if (atomData ==
nullptr) {
return; }
163 Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
164 Mat3x3d box = currSnapshot->getHmat();
166 std::vector<std::shared_ptr<AtomInfo>> atomInfoList = atomData->getData();
168 replicate(atomInfoList, atomData, box);
171 void ReplicateVisitor::replicate(
172 std::vector<std::shared_ptr<AtomInfo>>& infoList,
173 std::shared_ptr<AtomData> data,
const Mat3x3d& box) {
174 std::shared_ptr<AtomInfo> newAtomInfo;
175 std::vector<Vector3d>::iterator dirIter;
176 std::vector<std::shared_ptr<AtomInfo>>::iterator i;
178 for (dirIter = dir.begin(); dirIter != dir.end(); ++dirIter) {
179 for (i = infoList.begin(); i != infoList.end(); ++i) {
180 newAtomInfo = std::make_shared<AtomInfo>();
181 *newAtomInfo = *(*i);
182 newAtomInfo->pos += box * (*dirIter);
183 data->addAtomInfo(newAtomInfo);
188 const std::string ReplicateVisitor::toString() {
194 "--------------------------------------------------------------\n");
197 snprintf(buffer, 65535,
"Visitor name: %s\n", visitorName.c_str());
202 "Visitor Description: replicate the atoms in different direction\n");
206 snprintf(buffer, 65535,
"repeatX = %d:\n", replicateOpt[0]);
209 snprintf(buffer, 65535,
"repeatY = %d:\n", replicateOpt[1]);
212 snprintf(buffer, 65535,
"repeatZ = %d:\n", replicateOpt[2]);
217 "--------------------------------------------------------------\n");
225 XYZVisitor::XYZVisitor(SimInfo* info) :
226 BaseVisitor(), seleMan(info), evaluator(info), doPositions_(true),
227 doVelocities_(false), doForces_(false), doVectors_(false),
228 doCharges_(false), doElectricFields_(false), doGlobalIDs_(false) {
230 visitorName =
"XYZVisitor";
232 evaluator.loadScriptString(
"select all");
234 if (!evaluator.isDynamic()) {
235 seleMan.setSelectionSet(evaluator.evaluate());
239 XYZVisitor::XYZVisitor(SimInfo* info,
const std::string& script) :
240 BaseVisitor(), seleMan(info), evaluator(info), doPositions_(true),
241 doVelocities_(false), doForces_(false), doVectors_(false),
242 doCharges_(false), doElectricFields_(false), doGlobalIDs_(false) {
244 visitorName =
"XYZVisitor";
246 evaluator.loadScriptString(script);
248 if (!evaluator.isDynamic()) {
249 seleMan.setSelectionSet(evaluator.evaluate());
253 void XYZVisitor::visit(Atom* atom) {
254 if (isSelected(atom)) internalVisit(atom);
257 void XYZVisitor::visit(DirectionalAtom* datom) {
258 if (isSelected(datom)) internalVisit(datom);
261 void XYZVisitor::visit(RigidBody* rb) {
262 if (isSelected(rb)) internalVisit(rb);
265 void XYZVisitor::update() {
267 if (evaluator.isDynamic()) {
268 seleMan.setSelectionSet(evaluator.evaluate());
272 void XYZVisitor::internalVisit(StuntDouble* sd) {
273 std::shared_ptr<GenericData> data;
274 std::shared_ptr<AtomData> atomData;
275 std::shared_ptr<AtomInfo> atomInfo;
276 std::vector<std::shared_ptr<AtomInfo>>::iterator i;
280 data = sd->getPropertyByName(
"ATOMDATA");
282 if (data !=
nullptr) {
283 atomData = std::dynamic_pointer_cast<AtomData>(data);
285 if (atomData ==
nullptr)
return;
289 for (atomInfo = atomData->beginAtomInfo(i); atomInfo;
290 atomInfo = atomData->nextAtomInfo(i)) {
292 snprintf(buffer, 1024,
"%s", atomInfo->atomTypeName.c_str());
296 snprintf(buffer, 1024,
"%15.8f%15.8f%15.8f", atomInfo->pos[0],
297 atomInfo->pos[1], atomInfo->pos[2]);
300 if (doCharges_ && atomInfo->hasCharge) {
301 snprintf(buffer, 1024,
"%15.8f", atomInfo->charge);
304 if (doVectors_ && atomInfo->hasVector) {
305 snprintf(buffer, 1024,
"%15.8f%15.8f%15.8f", atomInfo->vec[0],
306 atomInfo->vec[1], atomInfo->vec[2]);
309 if (doVelocities_ && atomInfo->hasVelocity) {
310 snprintf(buffer, 1024,
"%15.8f%15.8f%15.8f", atomInfo->vel[0],
311 atomInfo->vel[1], atomInfo->vel[2]);
314 if (doForces_ && atomInfo->hasForce) {
315 snprintf(buffer, 1024,
"%15.8f%15.8f%15.8f", atomInfo->frc[0],
316 atomInfo->frc[1], atomInfo->frc[2]);
319 if (doElectricFields_ && atomInfo->hasElectricField) {
320 snprintf(buffer, 1024,
"%15.8f%15.8f%15.8f", atomInfo->eField[0],
321 atomInfo->eField[1], atomInfo->eField[2]);
325 snprintf(buffer, 1024,
"%10d", atomInfo->globalID);
329 frame.push_back(line);
333 bool XYZVisitor::isSelected(StuntDouble* sd) {
334 return seleMan.isSelected(sd);
337 void XYZVisitor::writeFrame(std::ostream& outStream) {
338 std::vector<std::string>::iterator i;
342 std::cerr <<
"Current Frame does not contain any atoms" << std::endl;
345 outStream << frame.size() << std::endl;
348 Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
349 Mat3x3d box = currSnapshot->getHmat();
351 snprintf(buffer, 1024,
352 "%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f",
353 currSnapshot->getTime(), box(0, 0), box(0, 1), box(0, 2),
354 box(1, 0), box(1, 1), box(1, 2), box(2, 0), box(2, 1), box(2, 2));
356 outStream << buffer << std::endl;
358 for (i = frame.begin(); i != frame.end(); ++i)
359 outStream << *i << std::endl;
362 std::string XYZVisitor::trimmedName(
const std::string& atomTypeName) {
363 return atomTypeName.substr(0, atomTypeName.find(
'-'));
366 const std::string XYZVisitor::toString() {
372 "------------------------------------------------------------------\n");
375 snprintf(buffer, 65535,
"Visitor name: %s\n", visitorName.c_str());
380 "Visitor Description: assemble the atom data and output xyz file\n");
385 "------------------------------------------------------------------\n");
393 void PrepareVisitor::internalVisit(Atom* atom) {
394 std::shared_ptr<GenericData> data;
397 data = atom->getPropertyByName(
"VISITED");
399 if (data !=
nullptr) { atom->removeProperty(
"VISITED"); }
402 data = atom->getPropertyByName(
"ATOMDATA");
404 if (data !=
nullptr) {
405 std::shared_ptr<AtomData> atomData =
406 std::dynamic_pointer_cast<AtomData>(data);
408 if (atomData != NULL) atom->removeProperty(
"ATOMDATA");
412 void PrepareVisitor::internalVisit(RigidBody* rb) {
413 std::shared_ptr<GenericData> data;
414 std::shared_ptr<AtomData> atomData;
415 std::vector<Atom*> myAtoms;
416 std::vector<Atom*>::iterator atomIter;
419 data = rb->getPropertyByName(
"VISITED");
421 if (data !=
nullptr) { rb->removeProperty(
"VISITED"); }
424 data = rb->getPropertyByName(
"ATOMDATA");
426 if (data !=
nullptr) {
427 atomData = std::dynamic_pointer_cast<AtomData>(data);
429 if (atomData != NULL) rb->removeProperty(
"ATOMDATA");
432 myAtoms = rb->getAtoms();
434 for (atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter)
435 internalVisit(*atomIter);
438 const std::string PrepareVisitor::toString() {
444 "------------------------------------------------------------------\n");
447 snprintf(buffer, 65535,
"Visitor name: %s", visitorName.c_str());
450 snprintf(buffer, 65535,
451 "Visitor Description: prepare for operation of other vistors\n");
456 "------------------------------------------------------------------\n");
464 WaterTypeVisitor::WaterTypeVisitor() {
465 visitorName =
"WaterTypeVisitor";
466 waterTypeList.insert(
"TIP3P_RB_0");
467 waterTypeList.insert(
"TIP3P-FB_RB_0");
468 waterTypeList.insert(
"TIP4P_RB_0");
469 waterTypeList.insert(
"TIP4P-Ice_RB_0");
470 waterTypeList.insert(
"TIP4P-Ew_RB_0");
471 waterTypeList.insert(
"TIP4P-2005_RB_0");
472 waterTypeList.insert(
"TIP4P-FB_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 waterTypeList.insert(
"SPC-HW_RB_0");
478 waterTypeList.insert(
"NE6_RB_0");
479 waterTypeList.insert(
"OPC_RB_0");
480 waterTypeList.insert(
"OPC3_RB_0");
483 void WaterTypeVisitor::visit(RigidBody* rb) {
485 std::vector<Atom*> myAtoms;
486 std::vector<Atom*>::iterator atomIter;
487 std::vector<std::shared_ptr<AtomInfo>>::iterator i;
488 std::shared_ptr<AtomData> atomData;
490 rbName = rb->getType();
492 if (waterTypeList.find(rbName) != waterTypeList.end()) {
493 myAtoms = rb->getAtoms();
495 for (atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter) {
496 std::shared_ptr<GenericData> data =
497 (*atomIter)->getPropertyByName(
"ATOMDATA");
499 if (data !=
nullptr) {
500 atomData = std::dynamic_pointer_cast<AtomData>(data);
502 if (atomData ==
nullptr)
continue;
506 for (std::shared_ptr<AtomInfo> atomInfo = atomData->beginAtomInfo(i);
507 atomInfo; atomInfo = atomData->nextAtomInfo(i)) {
508 atomInfo->atomTypeName = trimmedName(atomInfo->atomTypeName);
514 std::string WaterTypeVisitor::trimmedName(
const std::string& atomTypeName) {
515 return atomTypeName.substr(0, atomTypeName.find(
'_'));
518 const std::string WaterTypeVisitor::toString() {
524 "------------------------------------------------------------------\n");
527 snprintf(buffer, 65535,
"Visitor name: %s\n", visitorName.c_str());
530 snprintf(buffer, 65535,
531 "Visitor Description: Replace the atom type in water model\n");
536 "------------------------------------------------------------------\n");
SnapshotManager * getSnapshotManager()
Returns the snapshot manager.
Snapshot * getCurrentSnapshot()
Returns the pointer of current snapshot.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.