45#include "visitors/LipidTransVisitor.hpp"
49#include "types/MultipoleAdapter.hpp"
50#include "utils/simError.h"
53 LipidTransVisitor::LipidTransVisitor(SimInfo* info,
54 const std::string& originSeleScript,
55 const std::string& refSeleScript) :
57 info_(info), originEvaluator_(info), originSeleMan_(info),
58 refEvaluator_(info), refSeleMan_(info), refSd_(NULL) {
59 visitorName =
"LipidTransVisitor";
61 originEvaluator_.loadScriptString(originSeleScript);
62 if (!originEvaluator_.isDynamic()) {
63 originSeleMan_.setSelectionSet(originEvaluator_.evaluate());
64 if (originSeleMan_.getSelectionCount() == 1) {
67 dynamic_cast<DirectionalAtom*
>(originSeleMan_.beginSelected(i));
68 if (originDatom_ == NULL) {
69 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
70 "LipidTransVisitor: origin selection must select an "
77 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
78 "LipidTransVisitor: origin selection must select an directional "
85 refEvaluator_.loadScriptString(refSeleScript);
86 if (!refEvaluator_.isDynamic()) {
87 refSeleMan_.setSelectionSet(refEvaluator_.evaluate());
88 if (refSeleMan_.getSelectionCount() == 1) {
90 refSd_ = refSeleMan_.beginSelected(i);
98 void LipidTransVisitor::update() {
99 Vector3d ref = refSd_->getPos();
100 origin_ = originDatom_->getPos();
101 Vector3d v1 = ref - origin_;
102 info_->getSnapshotManager()->getCurrentSnapshot()->wrapVector(v1);
104 MultipoleAdapter ma = MultipoleAdapter(originDatom_->getAtomType());
107 zaxis = originDatom_->getDipole();
109 zaxis = originDatom_->getA().transpose() * V3Z;
112 Vector3d xaxis =
cross(v1, zaxis);
113 Vector3d yaxis =
cross(zaxis, xaxis);
119 rotMat_.setRow(0, xaxis);
120 rotMat_.setRow(1, yaxis);
121 rotMat_.setRow(2, zaxis);
124 void LipidTransVisitor::internalVisit(StuntDouble* sd) {
125 std::shared_ptr<GenericData> data;
126 std::shared_ptr<AtomData> atomData;
127 std::shared_ptr<AtomInfo> atomInfo;
128 std::vector<std::shared_ptr<AtomInfo>>::iterator i;
130 data = sd->getPropertyByName(
"ATOMDATA");
132 if (data !=
nullptr) {
133 atomData = std::dynamic_pointer_cast<AtomData>(data);
135 if (atomData ==
nullptr)
return;
139 Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
141 for (atomInfo = atomData->beginAtomInfo(i); atomInfo;
142 atomInfo = atomData->nextAtomInfo(i)) {
143 Vector3d tmp = atomInfo->pos - origin_;
144 currSnapshot->wrapVector(tmp);
145 atomInfo->pos = rotMat_ * tmp;
147 atomInfo->vec = rotMat_ * atomInfo->vec;
151 const std::string LipidTransVisitor::toString() {
157 "------------------------------------------------------------------\n");
160 snprintf(buffer, 65535,
"Visitor name: %s\n", visitorName.c_str());
163 snprintf(buffer, 65535,
"Visitor Description: rotate the whole system\n");
168 "------------------------------------------------------------------\n");
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Vector3< Real > cross(const Vector3< Real > &v1, const Vector3< Real > &v2)
Returns the cross product of two Vectors.