43 |
|
#include <fstream> |
44 |
|
#include "applications/staticProps/GofXyz.hpp" |
45 |
|
#include "utils/simError.h" |
46 |
< |
|
46 |
> |
#include "primitives/Molecule.hpp" |
47 |
|
namespace oopse { |
48 |
|
|
49 |
|
GofXyz::GofXyz(SimInfo* info, const std::string& filename, const std::string& sele1, const std::string& sele2, double len, int nrbins) |
50 |
< |
: RadialDistrFunc(info, filename, sele1, sele2), len_(len), nRBins_(nrbins) { |
50 |
> |
: RadialDistrFunc(info, filename, sele1, sele2), len_(len), halfLen_(len/2), nRBins_(nrbins) { |
51 |
|
setOutputName(getPrefix(filename) + ".gxyz"); |
52 |
|
|
53 |
< |
deltaR_ = len_ / nRBins_; |
53 |
> |
deltaR_ = len_ / nRBins_; |
54 |
|
|
55 |
|
histogram_.resize(nRBins_); |
56 |
|
for (int i = 0 ; i < nRBins_; ++i) { |
59 |
|
histogram_[i][j].resize(nRBins_); |
60 |
|
} |
61 |
|
} |
62 |
+ |
|
63 |
+ |
//create atom2Mol mapping (should be other class' responsibility) |
64 |
+ |
atom2Mol_.insert(atom2Mol_.begin(), info_->getNGlobalAtoms() + info_->getNGlobalRigidBodies(), static_cast<Molecule*>(NULL)); |
65 |
+ |
|
66 |
+ |
SimInfo::MoleculeIterator mi; |
67 |
+ |
Molecule* mol; |
68 |
+ |
Molecule::AtomIterator ai; |
69 |
+ |
Atom* atom; |
70 |
+ |
Molecule::RigidBodyIterator rbIter; |
71 |
+ |
RigidBody* rb; |
72 |
+ |
|
73 |
+ |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
74 |
+ |
|
75 |
+ |
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
76 |
+ |
atom2Mol_[atom->getGlobalIndex()] = mol; |
77 |
+ |
} |
78 |
+ |
|
79 |
+ |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
80 |
+ |
atom2Mol_[rb->getGlobalIndex()] = mol; |
81 |
+ |
} |
82 |
+ |
|
83 |
+ |
} |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
|
void GofXyz::preProcess() { |
88 |
< |
/* |
89 |
< |
for (int i = 0; i < avgGofr_.size(); ++i) { |
90 |
< |
std::fill(avgGofr_[i].begin(), avgGofr_[i].end(), 0); |
91 |
< |
} |
92 |
< |
*/ |
88 |
> |
for (int i = 0 ; i < nRBins_; ++i) { |
89 |
> |
histogram_[i].resize(nRBins_); |
90 |
> |
for(int j = 0; j < nRBins_; ++j) { |
91 |
> |
std::fill(histogram_[i][j].begin(), histogram_[i][j].end(), 0); |
92 |
> |
} |
93 |
> |
} |
94 |
|
} |
95 |
|
|
96 |
+ |
|
97 |
|
void GofXyz::initalizeHistogram() { |
98 |
< |
/* |
75 |
< |
npairs_ = 0; |
76 |
< |
for (int i = 0; i < histogram_.size(); ++i) |
77 |
< |
std::fill(histogram_[i].begin(), histogram_[i].end(), 0); |
78 |
< |
*/ |
79 |
< |
} |
98 |
> |
//calculate the center of mass of the molecule of selected stuntdouble in selection1 |
99 |
|
|
100 |
+ |
//determine the new coordinate set of selection1 |
101 |
+ |
//v1 = Rs1 -Rcom, |
102 |
+ |
//z = Rs1.dipole |
103 |
+ |
//x = v1 X z |
104 |
+ |
//y = z X x |
105 |
+ |
coorSets_.clear(); |
106 |
|
|
107 |
< |
void GofXyz::processHistogram() { |
108 |
< |
|
109 |
< |
/* |
110 |
< |
double volume = info_->getSnapshotManager()->getCurrentSnapshot()->getVolume(); |
111 |
< |
double pairDensity = npairs_ /volume; |
112 |
< |
double pairConstant = ( 4.0 * NumericConstant::PI * pairDensity ) / 3.0; |
113 |
< |
|
114 |
< |
for(int i = 0 ; i < histogram_.size(); ++i){ |
115 |
< |
|
116 |
< |
double rLower = i * deltaR_; |
117 |
< |
double rUpper = rLower + deltaR_; |
118 |
< |
double volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower ); |
119 |
< |
double nIdeal = volSlice * pairConstant; |
95 |
< |
|
96 |
< |
for (int j = 0; j < histogram_[i].size(); ++j){ |
97 |
< |
avgGofr_[i][j] += histogram_[i][j] / nIdeal; |
98 |
< |
} |
107 |
> |
int i; |
108 |
> |
StuntDouble* sd; |
109 |
> |
for (sd = seleMan1_.beginSelected(i); sd != NULL; sd = seleMan1_.nextSelected(i)) { |
110 |
> |
Vector3d rcom = getMolCom(sd); |
111 |
> |
Vector3d rs1 = sd->getPos(); |
112 |
> |
Vector3d v1 = rcom - rs1; |
113 |
> |
CoorSet currCoorSet; |
114 |
> |
currCoorSet.zaxis = sd->getElectroFrame().getColumn(2); |
115 |
> |
v1.normalize(); |
116 |
> |
currCoorSet.zaxis.normalize(); |
117 |
> |
currCoorSet.xaxis = cross(v1, currCoorSet.zaxis); |
118 |
> |
currCoorSet.yaxis = cross(currCoorSet.zaxis, currCoorSet.xaxis); |
119 |
> |
coorSets_.insert(std::map<int, CoorSet>::value_type(sd->getGlobalIndex(), currCoorSet)); |
120 |
|
} |
121 |
< |
*/ |
121 |
> |
|
122 |
|
} |
123 |
|
|
124 |
|
void GofXyz::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) { |
125 |
|
|
105 |
– |
/* |
106 |
– |
if (sd1 == sd2) { |
107 |
– |
return; |
108 |
– |
} |
109 |
– |
|
126 |
|
Vector3d pos1 = sd1->getPos(); |
127 |
|
Vector3d pos2 = sd2->getPos(); |
128 |
< |
Vector3d r12 = pos1 - pos2; |
128 |
> |
Vector3d r12 = pos2 - pos1; |
129 |
|
currentSnapshot_->wrapVector(r12); |
130 |
|
|
131 |
< |
double distance = r12.length(); |
132 |
< |
int whichRBin = distance / deltaR_; |
131 |
> |
std::map<int, CoorSet>::iterator i = coorSets_.find(sd1->getGlobalIndex()); |
132 |
> |
assert(i != coorSets_.end()); |
133 |
> |
|
134 |
> |
double x = dot(r12, i->second.xaxis); |
135 |
> |
double y = dot(r12, i->second.yaxis); |
136 |
> |
double z = dot(r12, i->second.zaxis); |
137 |
|
|
138 |
+ |
// x, y and z's possible values range -halfLen_ to halfLen_ |
139 |
+ |
int xbin = (x+ halfLen_) / deltaR_; |
140 |
+ |
int ybin = (y + halfLen_) / deltaR_; |
141 |
+ |
int zbin = (z + halfLen_) / deltaR_; |
142 |
+ |
|
143 |
+ |
if (xbin < nRBins_ && xbin >=0 && |
144 |
+ |
ybin < nRBins_ && ybin >= 0 && |
145 |
+ |
zbin < nRBins_ && zbin >=0 ) { |
146 |
+ |
++histogram_[xbin][ybin][zbin]; |
147 |
+ |
} |
148 |
|
|
119 |
– |
double cosAngle = evaluateAngle(sd1, sd2); |
120 |
– |
double halfBin = (nAngleBins_ - 1) * 0.5; |
121 |
– |
int whichThetaBin = halfBin * (cosAngle + 1.0) |
122 |
– |
++histogram_[whichRBin][whichThetaBin]; |
123 |
– |
|
124 |
– |
++npairs_; |
125 |
– |
*/ |
149 |
|
} |
150 |
|
|
151 |
|
void GofXyz::writeRdf() { |
152 |
< |
std::ofstream rdfStream(outputFilename_.c_str()); |
152 |
> |
std::ofstream rdfStream(outputFilename_.c_str(), std::ios::binary); |
153 |
|
if (rdfStream.is_open()) { |
154 |
< |
rdfStream << "#radial distribution function\n"; |
155 |
< |
rdfStream << "#selection1: (" << selectionScript1_ << ")\t"; |
156 |
< |
rdfStream << "selection2: (" << selectionScript2_ << ")\n"; |
157 |
< |
rdfStream << "#r\tcorrValue\n"; |
154 |
> |
//rdfStream << "#g(x, y, z)\n"; |
155 |
> |
//rdfStream << "#selection1: (" << selectionScript1_ << ")\t"; |
156 |
> |
//rdfStream << "selection2: (" << selectionScript2_ << ")\n"; |
157 |
> |
//rdfStream << "#nRBins = " << nRBins_ << "\t maxLen = " << len_ << "deltaR = " << deltaR_ <<"\n"; |
158 |
|
for (int i = 0; i < histogram_.size(); ++i) { |
159 |
< |
double x = deltaR_ * (i + 0.5); |
137 |
< |
|
159 |
> |
|
160 |
|
for(int j = 0; j < histogram_[i].size(); ++j) { |
161 |
< |
double y = deltaR_ * (j+ 0.5); |
140 |
< |
|
161 |
> |
|
162 |
|
for(int k = 0;k < histogram_[i].size(); ++k) { |
163 |
< |
double z = deltaR_ * (k + 0.5); |
143 |
< |
rdfStream << x << "\t" << y << "\t" << z << "\t" << histogram_[i][j][k]/nProcessed_ << "\n"; |
163 |
> |
rdfStream.write(reinterpret_cast<char *>(&histogram_[i][j][k] ), sizeof(histogram_[i][j][k] )); |
164 |
|
} |
165 |
|
} |
166 |
|
} |
175 |
|
rdfStream.close(); |
176 |
|
} |
177 |
|
|
178 |
+ |
Vector3d GofXyz::getMolCom(StuntDouble* sd){ |
179 |
+ |
Molecule* mol = atom2Mol_[sd->getGlobalIndex()]; |
180 |
+ |
assert(mol); |
181 |
+ |
return mol->getCom(); |
182 |
|
} |
183 |
|
|
184 |
< |
|
161 |
< |
|
184 |
> |
} |