45#include "applications/staticProps/GofXyz.hpp"
51#include "types/MultipoleAdapter.hpp"
52#include "utils/simError.h"
56 GofXyz::GofXyz(SimInfo* info,
const std::string& filename,
57 const std::string& sele1,
const std::string& sele2,
58 const std::string& sele3, RealType len,
int nrbins) :
59 RadialDistrFunc(info, filename, sele1, sele2, nrbins),
60 len_(len), halfLen_(len / 2), evaluator3_(info), seleMan3_(info) {
61 setOutputName(
getPrefix(filename) +
".gxyz");
63 evaluator3_.loadScriptString(sele3);
64 if (!evaluator3_.isDynamic()) {
65 seleMan3_.setSelectionSet(evaluator3_.evaluate());
68 deltaR_ = len_ / nBins_;
70 histogram_.resize(nBins_);
71 for (
unsigned int i = 0; i < nBins_; ++i) {
72 histogram_[i].resize(nBins_);
73 for (
unsigned int j = 0; j < nBins_; ++j) {
74 histogram_[i][j].resize(nBins_);
79 void GofXyz::preProcess() {
80 for (
unsigned int i = 0; i < nBins_; ++i) {
81 histogram_[i].resize(nBins_);
82 for (
unsigned int j = 0; j < nBins_; ++j) {
83 std::fill(histogram_[i][j].begin(), histogram_[i][j].end(), 0);
88 void GofXyz::initializeHistogram() {
92 if (!evaluator3_.isDynamic()) {
93 seleMan3_.setSelectionSet(evaluator3_.evaluate());
96 assert(seleMan1_.getSelectionCount() == seleMan3_.getSelectionCount());
97 bool usePeriodicBoundaryConditions_ =
98 info_->getSimParams()->getUsePeriodicBoundaryConditions();
113 for (sd1 = seleMan1_.beginSelected(i), sd3 = seleMan3_.beginSelected(j);
114 sd1 != NULL || sd3 != NULL;
115 sd1 = seleMan1_.nextSelected(i), sd3 = seleMan3_.nextSelected(j)) {
116 Vector3d r3 = sd3->getPos();
117 Vector3d r1 = sd1->getPos();
118 Vector3d v1 = r3 - r1;
119 if (usePeriodicBoundaryConditions_)
120 info_->getSnapshotManager()->getCurrentSnapshot()->wrapVector(v1);
122 AtomType* atype1 =
static_cast<Atom*
>(sd1)->getAtomType();
123 MultipoleAdapter ma1 = MultipoleAdapter(atype1);
127 zaxis = sd1->getDipole();
129 zaxis = sd1->getA().transpose() * V3Z;
131 Vector3d xaxis =
cross(v1, zaxis);
132 Vector3d yaxis =
cross(zaxis, xaxis);
140 rotMat.setRow(1, yaxis);
141 rotMat.setRow(2, zaxis);
144 std::map<int, RotMat3x3d>::value_type(sd1->getGlobalIndex(), rotMat));
148 void GofXyz::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) {
149 bool usePeriodicBoundaryConditions_ =
150 info_->getSimParams()->getUsePeriodicBoundaryConditions();
152 Vector3d pos1 = sd1->getPos();
153 Vector3d pos2 = sd2->getPos();
154 Vector3d r12 = pos2 - pos1;
155 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(r12);
157 std::map<int, RotMat3x3d>::iterator i =
158 rotMats_.find(sd1->getGlobalIndex());
159 assert(i != rotMats_.end());
161 Vector3d newR12 = i->second * r12;
163 int xbin = int((newR12.x() + halfLen_) / deltaR_);
164 int ybin = int((newR12.y() + halfLen_) / deltaR_);
165 int zbin = int((newR12.z() + halfLen_) / deltaR_);
167 if (xbin <
int(nBins_) && xbin >= 0 && ybin <
int(nBins_) && ybin >= 0 &&
168 zbin <
int(nBins_) && zbin >= 0) {
169 ++histogram_[xbin][ybin][zbin];
173 void GofXyz::writeRdf() {
174 std::ofstream rdfStream(outputFilename_.c_str(), std::ios::binary);
175 if (rdfStream.is_open()) {
181 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
182 for (
unsigned int j = 0; j < histogram_[i].size(); ++j) {
183 for (
unsigned int k = 0; k < histogram_[i][j].size(); ++k) {
184 rdfStream.write(
reinterpret_cast<char*
>(&histogram_[i][j][k]),
185 sizeof(histogram_[i][j][k]));
191 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
192 "GofXyz: unable to open %s\n", outputFilename_.c_str());
193 painCave.isFatal = 1;
void setRow(unsigned int row, const Vector< Real, Row > &v)
Sets a row of this matrix.
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.
std::string getPrefix(const std::string &str)