48#include "applications/staticProps/GofXyz.hpp"
54#include "types/MultipoleAdapter.hpp"
55#include "utils/simError.h"
59 GofXyz::GofXyz(
SimInfo* info,
const std::string& filename,
60 const std::string& sele1,
const std::string& sele2,
61 const std::string& sele3, RealType len,
int nrbins) :
63 len_(len), halfLen_(len / 2), evaluator3_(info), seleMan3_(info) {
64 setOutputName(
getPrefix(filename) +
".gxyz");
66 evaluator3_.loadScriptString(sele3);
67 if (!evaluator3_.isDynamic()) {
68 seleMan3_.setSelectionSet(evaluator3_.evaluate());
71 deltaR_ = len_ / nBins_;
73 histogram_.resize(nBins_);
74 for (
unsigned int i = 0; i < nBins_; ++i) {
75 histogram_[i].resize(nBins_);
76 for (
unsigned int j = 0; j < nBins_; ++j) {
77 histogram_[i][j].resize(nBins_);
82 void GofXyz::preProcess() {
83 for (
unsigned int i = 0; i < nBins_; ++i) {
84 histogram_[i].resize(nBins_);
85 for (
unsigned int j = 0; j < nBins_; ++j) {
86 std::fill(histogram_[i][j].begin(), histogram_[i][j].end(), 0);
91 void GofXyz::initializeHistogram() {
95 if (!evaluator3_.isDynamic()) {
96 seleMan3_.setSelectionSet(evaluator3_.evaluate());
99 assert(seleMan1_.getSelectionCount() == seleMan3_.getSelectionCount());
100 bool usePeriodicBoundaryConditions_ =
101 info_->getSimParams()->getUsePeriodicBoundaryConditions();
116 for (sd1 = seleMan1_.beginSelected(i), sd3 = seleMan3_.beginSelected(j);
117 sd1 != NULL || sd3 != NULL;
118 sd1 = seleMan1_.nextSelected(i), sd3 = seleMan3_.nextSelected(j)) {
119 Vector3d r3 = sd3->getPos();
120 Vector3d r1 = sd1->getPos();
121 Vector3d v1 = r3 - r1;
122 if (usePeriodicBoundaryConditions_)
123 info_->getSnapshotManager()->getCurrentSnapshot()->wrapVector(v1);
125 AtomType* atype1 =
static_cast<Atom*
>(sd1)->getAtomType();
126 MultipoleAdapter ma1 = MultipoleAdapter(atype1);
130 zaxis = sd1->getDipole();
132 zaxis = sd1->getA().transpose() * V3Z;
134 Vector3d xaxis =
cross(v1, zaxis);
135 Vector3d yaxis =
cross(zaxis, xaxis);
143 rotMat.setRow(1, yaxis);
144 rotMat.setRow(2, zaxis);
147 std::map<int, RotMat3x3d>::value_type(sd1->getGlobalIndex(), rotMat));
151 void GofXyz::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) {
152 bool usePeriodicBoundaryConditions_ =
153 info_->getSimParams()->getUsePeriodicBoundaryConditions();
155 Vector3d pos1 = sd1->getPos();
156 Vector3d pos2 = sd2->getPos();
157 Vector3d r12 = pos2 - pos1;
158 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(r12);
160 std::map<int, RotMat3x3d>::iterator i =
161 rotMats_.find(sd1->getGlobalIndex());
162 assert(i != rotMats_.end());
164 Vector3d newR12 = i->second * r12;
166 int xbin = int((newR12.x() + halfLen_) / deltaR_);
167 int ybin = int((newR12.y() + halfLen_) / deltaR_);
168 int zbin = int((newR12.z() + halfLen_) / deltaR_);
170 if (xbin <
int(nBins_) && xbin >= 0 && ybin <
int(nBins_) && ybin >= 0 &&
171 zbin <
int(nBins_) && zbin >= 0) {
172 ++histogram_[xbin][ybin][zbin];
176 void GofXyz::writeRdf() {
177 std::ofstream rdfStream(outputFilename_.c_str(), std::ios::binary);
178 if (rdfStream.is_open()) {
184 for (
unsigned int i = 0; i < histogram_.size(); ++i) {
185 for (
unsigned int j = 0; j < histogram_[i].size(); ++j) {
186 for (
unsigned int k = 0; k < histogram_[i][j].size(); ++k) {
187 rdfStream.write(
reinterpret_cast<char*
>(&histogram_[i][j][k]),
188 sizeof(histogram_[i][j][k]));
194 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
195 "GofXyz: unable to open %s\n", outputFilename_.c_str());
196 painCave.isFatal = 1;
Radial Distribution Function.
void setRow(unsigned int row, const Vector< Real, Row > &v)
Sets a row of this matrix.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
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)