45#include "visitors/ReplacementVisitor.hpp"
55 void ReplacementVisitor::addReplacedAtomName(
const std::string& repName) {
56 myTypes_.insert(repName);
59 bool ReplacementVisitor::isReplacedAtom(
const std::string& atomType) {
60 std::set<std::string>::iterator strIter;
61 strIter = myTypes_.find(atomType);
62 return strIter != myTypes_.end() ? true :
false;
65 void ReplacementVisitor::addSite(
const std::string& name,
66 const Vector3d& refPos) {
67 std::shared_ptr<AtomInfo> atomInfo = std::make_shared<AtomInfo>();
68 atomInfo->atomTypeName = name;
69 atomInfo->pos = refPos;
70 sites_->addAtomInfo(atomInfo);
72 void ReplacementVisitor::addSite(
const std::string& name,
73 const Vector3d& refPos,
74 const Vector3d& refVec) {
75 std::shared_ptr<AtomInfo> atomInfo = std::make_shared<AtomInfo>();
76 atomInfo->atomTypeName = name;
77 atomInfo->pos = refPos;
78 atomInfo->vec = refVec;
79 atomInfo->hasVector =
true;
80 sites_->addAtomInfo(atomInfo);
83 void ReplacementVisitor::visit(DirectionalAtom* datom) {
95 std::shared_ptr<AtomInfo> atomInfo;
96 std::shared_ptr<AtomData> atomData;
97 std::shared_ptr<GenericData> data;
101 if (!isReplacedAtom(datom->getType()))
return;
103 data = datom->getPropertyByName(
"ATOMDATA");
105 if (data !=
nullptr) {
106 atomData = std::dynamic_pointer_cast<AtomData>(data);
108 if (atomData ==
nullptr) {
109 std::cerr <<
"can not get Atom Data from " << datom->getType()
111 atomData = std::make_shared<AtomData>();
112 haveAtomData =
false;
116 atomData = std::make_shared<AtomData>();
117 haveAtomData =
false;
120 pos = datom->getPos();
121 vel = datom->getVel();
128 skewMat(0, 1) = j[2] / I(2, 2);
129 skewMat(0, 2) = -j[1] / I(1, 1);
130 skewMat(1, 0) = -j[2] / I(2, 2);
132 skewMat(1, 2) = j[0] / I(0, 0);
133 skewMat(2, 0) = j[1] / I(1, 1);
134 skewMat(2, 1) = -j[0] / I(0, 0);
136 Mat3x3d mat = (A * skewMat).transpose();
139 Atrans = A.transpose();
141 std::shared_ptr<AtomInfo> siteInfo;
142 std::vector<std::shared_ptr<AtomInfo>>::iterator iter;
144 for (siteInfo = sites_->beginAtomInfo(iter); siteInfo;
145 siteInfo = sites_->nextAtomInfo(iter)) {
146 newVec = Atrans * siteInfo->pos;
148 atomInfo = std::make_shared<AtomInfo>();
149 atomInfo->atomTypeName = siteInfo->atomTypeName;
150 atomInfo->pos = pos + newVec;
152 if (siteInfo->hasVector) {
153 newVec = Atrans * siteInfo->vec;
154 atomInfo->vec = newVec;
156 atomInfo->vec = V3Zero;
159 atomInfo->vel = vel + mat * siteInfo->pos;
160 atomInfo->hasVelocity =
true;
162 atomData->addAtomInfo(atomInfo);
165 atomData->setID(
"ATOMDATA");
166 datom->addProperty(atomData);
172 const std::string ReplacementVisitor::toString() {
178 "------------------------------------------------------------------\n");
181 snprintf(buffer, 65535,
"Visitor name: %s\n", visitorName.c_str());
184 snprintf(buffer, 65535,
185 "Visitor Description: replace atom with other sites\n");
190 "------------------------------------------------------------------\n");
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.