| 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) |
| 50 |
< |
: RadialDistrFunc(info, filename, sele1, sele2){ |
| 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) { |
| 51 |
|
setOutputName(getPrefix(filename) + ".gxyz"); |
| 52 |
|
|
| 53 |
+ |
deltaR_ = len_ / nRBins_; |
| 54 |
+ |
|
| 55 |
+ |
histogram_.resize(nRBins_); |
| 56 |
+ |
for (int i = 0 ; i < nRBins_; ++i) { |
| 57 |
+ |
histogram_[i].resize(nRBins_); |
| 58 |
+ |
for(int j = 0; j < nRBins_; ++j) { |
| 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 |
< |
/* |
| 66 |
< |
npairs_ = 0; |
| 67 |
< |
for (int i = 0; i < histogram_.size(); ++i) |
| 68 |
< |
std::fill(histogram_[i].begin(), histogram_[i].end(), 0); |
| 69 |
< |
*/ |
| 70 |
< |
} |
| 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; |
| 86 |
< |
|
| 87 |
< |
for (int j = 0; j < histogram_[i].size(); ++j){ |
| 88 |
< |
avgGofr_[i][j] += histogram_[i][j] / nIdeal; |
| 89 |
< |
} |
| 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 |
|
|
| 96 |
– |
/* |
| 97 |
– |
if (sd1 == sd2) { |
| 98 |
– |
return; |
| 99 |
– |
} |
| 100 |
– |
|
| 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 |
+ |
int xbin = x / deltaR_; |
| 139 |
+ |
int ybin = y / deltaR_; |
| 140 |
+ |
int zbin = z / deltaR_; |
| 141 |
+ |
|
| 142 |
+ |
if (xbin < nRBins_ && ybin < nRBins_ && zbin < nRBins_) { |
| 143 |
+ |
++histogram_[x][y][z]; |
| 144 |
+ |
} |
| 145 |
|
|
| 110 |
– |
double cosAngle = evaluateAngle(sd1, sd2); |
| 111 |
– |
double halfBin = (nAngleBins_ - 1) * 0.5; |
| 112 |
– |
int whichThetaBin = halfBin * (cosAngle + 1.0) |
| 113 |
– |
++histogram_[whichRBin][whichThetaBin]; |
| 114 |
– |
|
| 115 |
– |
++npairs_; |
| 116 |
– |
*/ |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
void GofXyz::writeRdf() { |
| 149 |
|
std::ofstream rdfStream(outputFilename_.c_str()); |
| 150 |
|
if (rdfStream.is_open()) { |
| 151 |
< |
rdfStream << "#radial distribution function\n"; |
| 151 |
> |
rdfStream << "#g(x, y, z)\n"; |
| 152 |
|
rdfStream << "#selection1: (" << selectionScript1_ << ")\t"; |
| 153 |
|
rdfStream << "selection2: (" << selectionScript2_ << ")\n"; |
| 154 |
< |
rdfStream << "#r\tcorrValue\n"; |
| 154 |
> |
rdfStream << "#nRBins = " << nRBins_ << "\t maxLen = " << len_ << "deltaR = " << deltaR_ <<"\n"; |
| 155 |
|
for (int i = 0; i < histogram_.size(); ++i) { |
| 156 |
< |
double x = deltaR_ * (i + 0.5); |
| 128 |
< |
|
| 156 |
> |
|
| 157 |
|
for(int j = 0; j < histogram_[i].size(); ++j) { |
| 158 |
< |
double y = deltaR_ * (j+ 0.5); |
| 131 |
< |
|
| 158 |
> |
|
| 159 |
|
for(int k = 0;k < histogram_[i].size(); ++k) { |
| 160 |
< |
double z = deltaR_ * (k + 0.5); |
| 161 |
< |
rdfStream << x << "\t" << y << "\t" << z << "\t" << histogram_[i][j][k]/nProcessed_ << "\n"; |
| 160 |
> |
|
| 161 |
> |
rdfStream << histogram_[i][j][k]/nProcessed_ << "\t"; |
| 162 |
|
} |
| 163 |
+ |
rdfStream << "\n"; |
| 164 |
|
} |
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
} else { |
| 168 |
|
|
| 169 |
< |
|
| 169 |
> |
sprintf(painCave.errMsg, "GofXyz: unable to open %s\n", outputFilename_.c_str()); |
| 170 |
> |
painCave.isFatal = 1; |
| 171 |
> |
simError(); |
| 172 |
|
} |
| 173 |
|
|
| 174 |
|
rdfStream.close(); |
| 175 |
|
} |
| 176 |
|
|
| 177 |
+ |
Vector3d GofXyz::getMolCom(StuntDouble* sd){ |
| 178 |
+ |
Molecule* mol = atom2Mol_[sd->getGlobalIndex()]; |
| 179 |
+ |
assert(mol); |
| 180 |
+ |
return mol->getCom(); |
| 181 |
|
} |
| 182 |
|
|
| 183 |
< |
|
| 150 |
< |
|
| 183 |
> |
} |