45#include "visitors/ZconsVisitor.hpp"
51#include "types/ZconsStamp.hpp"
58 visitorName =
"ZConsVisitor";
60 Globals* simParam = info_->getSimParams();
62 if (simParam->haveZconsTime()) {
63 zconsTime_ = simParam->getZconsTime();
65 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
66 "ZConstraint error: If you use a ZConstraint,\n"
67 "\tyou must set zconsTime.\n");
72 if (simParam->haveZconsTol()) {
73 zconsTol_ = simParam->getZconsTol();
76 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
77 "ZConstraint Warning: Tolerance for z-constraint method is not "
79 "\tOpenMD will use a default value of %f.\n"
80 "\tTo set the tolerance, use the zconsTol variable.\n",
86 int nZconstraints = simParam->getNZconsStamps();
87 std::vector<ZConsStamp*> stamp = simParam->getZconsStamps();
88 for (
int i = 0; i < nZconstraints; i++) {
89 int zmolIndex = stamp[i]->getMolIndex();
90 zmolStates_.insert(std::make_pair(zmolIndex, zsMoving));
95 std::map<int, ZConsState>::iterator j;
96 for (j = zmolStates_.begin(); j != zmolStates_.end(); ++j) {
99 Molecule::AtomIterator ai;
101 for (at = mol->beginAtom(ai); at != NULL; at = mol->nextAtom(ai)) {
107 zconsFilename_ =
getPrefix(info_->getFinalConfigFileName()) +
".fz";
111 if (zconsReader_->hasNextFrame()) zconsReader_->readNextFrame();
114 ZConsVisitor::~ZConsVisitor() {
delete zconsReader_; }
116 void ZConsVisitor::visit(Atom* atom) {
118 if (isZconstraint(atom->getGlobalIndex(), prefix))
119 internalVisit(atom, prefix);
122 void ZConsVisitor::visit(DirectionalAtom* datom) {
125 if (isZconstraint(datom->getGlobalIndex(), prefix))
126 internalVisit(datom, prefix);
129 void ZConsVisitor::visit(RigidBody* rb) {
131 std::vector<Atom*> atoms;
133 atoms = rb->getAtoms();
135 if (isZconstraint(atoms[0]->getGlobalIndex(), prefix))
136 internalVisit(rb, prefix);
139 void ZConsVisitor::update() {
141 std::map<int, ZConsState>::iterator i;
142 for (i = zmolStates_.begin(); i != zmolStates_.end(); ++i) {
143 i->second = zsMoving;
146 readZconsFile(currSnapshot_->getTime());
148 const std::vector<ZconsData>& fixedZmolData =
149 zconsReader_->getFixedZMolData();
150 std::vector<ZconsData>::const_iterator j;
151 for (j = fixedZmolData.begin(); j != fixedZmolData.end(); ++j) {
152 std::map<int, ZConsState>::iterator k = zmolStates_.find(j->zmolIndex);
153 assert(k != zmolStates_.end());
158 void ZConsVisitor::readZconsFile(RealType time) {
160 while (zconsReader_->hasNextFrame()) {
161 tempTime = zconsReader_->getCurTime();
162 if (tempTime >= time) {
return; }
164 zconsReader_->readNextFrame();
168 void ZConsVisitor::internalVisit(StuntDouble* sd,
const std::string& prefix) {
169 std::shared_ptr<GenericData> data;
170 std::shared_ptr<AtomData> atomData;
171 std::shared_ptr<AtomInfo> atomInfo;
172 std::vector<std::shared_ptr<AtomInfo>>::iterator iter;
175 data = sd->getPropertyByName(
"ATOMDATA");
176 if (data !=
nullptr) {
177 atomData = std::dynamic_pointer_cast<AtomData>(data);
178 if (atomData ==
nullptr)
return;
182 for (atomInfo = atomData->beginAtomInfo(iter); atomInfo;
183 atomInfo = atomData->nextAtomInfo(iter))
184 (atomInfo->atomTypeName).insert(0, prefix);
187 bool ZConsVisitor::isZconstraint(
int atomIndex, std::string& prefix) {
188 std::string prefixString[] = {
"ZF",
"ZM"};
189 std::map<int, int>::iterator i = zatomToZmol_.find(atomIndex);
190 if (i == zatomToZmol_.end()) {
194 std::map<int, ZConsState>::iterator j = zmolStates_.find(i->second);
195 assert(j != zmolStates_.end());
196 prefix = prefixString[j->second];
201 const std::string ZConsVisitor::toString() {
207 "------------------------------------------------------------------\n");
210 snprintf(buffer, 65535,
"Visitor name: %s\n", visitorName.c_str());
213 snprintf(buffer, 65535,
"number of zconstraint molecule: %d\n",
214 (
int)zmolStates_.size());
217 snprintf(buffer, 65535,
"zconstraint tolerance = %lf\n", zconsTol_);
220 snprintf(buffer, 65535,
"zconstraint sample time = %lf\n", zconsTime_);
223 snprintf(buffer, 65535,
"zconstraint output filename = %s\n",
224 zconsFilename_.c_str());
227 std::map<int, ZConsState>::iterator i;
229 for (i = zmolStates_.begin(); i != zmolStates_.end(); ++i) {
230 snprintf(buffer, 65535,
"zconstraint molecule[%d] = %d\n", j++, i->first);
236 "------------------------------------------------------------------\n");
int getGlobalIndex()
Returns the global index of this molecule.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Molecule * getMoleculeByGlobalIndex(int index)
Finds a molecule with a specified global index.
SnapshotManager * getSnapshotManager()
Returns the snapshot manager.
Snapshot * getCurrentSnapshot()
Returns the pointer of current snapshot.
int getGlobalIndex()
Returns the global index of this stuntDouble.
ZConsVisitor(SimInfo *info)
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
std::string getPrefix(const std::string &str)