| 51 |
|
#include "io/DumpReader.hpp" |
| 52 |
|
#include "primitives/Molecule.hpp" |
| 53 |
|
#include "utils/NumericConstant.hpp" |
| 54 |
< |
#include "math/RealSphericalHarmonic.hpp" |
| 54 |
> |
#include "math/SphericalHarmonic.hpp" |
| 55 |
> |
|
| 56 |
|
namespace oopse { |
| 57 |
|
|
| 57 |
– |
|
| 58 |
|
BondOrderParameter::BondOrderParameter(SimInfo* info, |
| 59 |
|
const std::string& filename, |
| 60 |
|
const std::string& sele, |
| 61 |
< |
double rCut, int lNumber, int nbins) |
| 62 |
< |
: StaticAnalyser(info, filename), selectionScript_(sele), |
| 63 |
< |
evaluator_(info), seleMan_(info){ |
| 61 |
> |
double rCut, int lNumber, int nbins) : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info){ |
| 62 |
|
|
| 63 |
< |
setOutputName(getPrefix(filename) + ".obo"); |
| 63 |
> |
setOutputName(getPrefix(filename) + ".bo"); |
| 64 |
|
|
| 65 |
|
evaluator_.loadScriptString(sele); |
| 66 |
|
if (!evaluator_.isDynamic()) { |
| 73 |
|
rCut_ = rCut; |
| 74 |
|
mSize_ = 2*lNumber_+1; |
| 75 |
|
|
| 76 |
< |
deltaQ_ = 1.0 / nbins; |
| 79 |
< |
deltaW_ = 2.0 / nbins; |
| 76 |
> |
// Q can take values from 0 to 1 |
| 77 |
|
|
| 78 |
+ |
MinQ_ = 0.0; |
| 79 |
+ |
MaxQ_ = 1.0; |
| 80 |
+ |
deltaQ_ = (MaxQ_ - MinQ_) / nbins; |
| 81 |
|
Q_histogram_.resize(nbins); |
| 82 |
+ |
|
| 83 |
+ |
// W_6 for icosahedral clusters is 11 / sqrt(4199) = 0.169754, so we'll |
| 84 |
+ |
// use values for MinW_ and MaxW_ that are slightly larger than this: |
| 85 |
+ |
|
| 86 |
+ |
MinW_ = -0.18; |
| 87 |
+ |
MaxW_ = 0.18; |
| 88 |
+ |
deltaW_ = (MaxW_ - MinW_) / nbins; |
| 89 |
|
W_histogram_.resize(nbins); |
| 90 |
|
|
| 91 |
|
} |
| 92 |
|
|
| 93 |
+ |
BondOrderParameter::~BondOrderParameter() { |
| 94 |
+ |
Q_histogram_.clear(); |
| 95 |
+ |
W_histogram_.clear(); |
| 96 |
+ |
} |
| 97 |
+ |
|
| 98 |
|
void BondOrderParameter::initalizeHistogram() { |
| 99 |
|
std::fill(Q_histogram_.begin(), Q_histogram_.end(), 0); |
| 100 |
|
std::fill(W_histogram_.begin(), W_histogram_.end(), 0); |
| 108 |
|
Molecule::RigidBodyIterator rbIter; |
| 109 |
|
Molecule::AtomIterator ai; |
| 110 |
|
StuntDouble* sd; |
| 111 |
< |
RealType theta; |
| 111 |
> |
RealType costheta; |
| 112 |
|
RealType phi; |
| 113 |
|
RealType r; |
| 114 |
|
RealType dist; |
| 115 |
< |
std::map<int, RealType> QBar_lm; |
| 115 |
> |
std::map<int, ComplexType> QBar_lm; |
| 116 |
|
RealType QSq_l; |
| 117 |
|
RealType Q_l; |
| 118 |
|
int nBonds; |
| 119 |
< |
RealSphericalHarmonic sphericalHarmonic; |
| 119 |
> |
SphericalHarmonic sphericalHarmonic; |
| 120 |
|
int i, j; |
| 121 |
|
|
| 122 |
|
// Set the l for the spherical harmonic, it doesn't change |
| 125 |
|
|
| 126 |
|
DumpReader reader(info_, dumpFilename_); |
| 127 |
|
int nFrames = reader.getNFrames(); |
| 128 |
+ |
frameCounter_ = 0; |
| 129 |
|
|
| 117 |
– |
|
| 130 |
|
for (int istep = 0; istep < nFrames; istep += step_) { |
| 131 |
|
reader.readFrame(istep); |
| 132 |
+ |
frameCounter_++; |
| 133 |
|
currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 134 |
|
|
| 135 |
|
if (evaluator_.isDynamic()) { |
| 180 |
|
// Check to see if neighbor is in bond cutoff |
| 181 |
|
|
| 182 |
|
if (r < rCut_) { |
| 183 |
< |
theta = atan2(vec.y(), vec.x()); |
| 184 |
< |
phi = acos(vec.z()/r); |
| 183 |
> |
costheta = vec.z() / r; |
| 184 |
> |
phi = atan2(vec.y(), vec.x()); |
| 185 |
> |
|
| 186 |
|
for(int m = -lNumber_; m <= lNumber_; m++){ |
| 187 |
|
sphericalHarmonic.setM(m); |
| 188 |
< |
QBar_lm[m] += sphericalHarmonic.getValueAt(theta,phi); |
| 188 |
> |
QBar_lm[m] += sphericalHarmonic.getValueAt(costheta,phi); |
| 189 |
|
} |
| 190 |
|
nBonds++; |
| 191 |
|
} |
| 192 |
|
} |
| 193 |
|
} |
| 194 |
|
|
| 195 |
< |
// Normalize Qbar |
| 195 |
> |
// Normalize Qbar2 |
| 196 |
|
for (int m = -lNumber_;m <= lNumber_; m++){ |
| 197 |
|
QBar_lm[m] /= nBonds; |
| 198 |
|
} |
| 201 |
|
|
| 202 |
|
QSq_l = 0.0; |
| 203 |
|
for (int m = -lNumber_; m <= lNumber_; m++){ |
| 204 |
< |
QSq_l += pow(QBar_lm[m], 2); |
| 204 |
> |
QSq_l += norm(QBar_lm[m]); |
| 205 |
|
} |
| 206 |
|
Q_l = sqrt(QSq_l*(4.0 * NumericConstant::PI / (2.0*(RealType)lNumber_ + 1))); |
| 207 |
|
|
| 211 |
|
double* THRCOF = new double[mSize_]; |
| 212 |
|
// Variables for Wigner routine |
| 213 |
|
double l_ = (double)lNumber_; |
| 214 |
< |
double m2Min, m2Max; |
| 214 |
> |
double m1Pass, m2Min, m2Max; |
| 215 |
|
int error, m1, m2, m3; |
| 216 |
|
|
| 217 |
< |
RealType W_l; |
| 218 |
< |
RealType W_l_hat; |
| 217 |
> |
ComplexType W_l; |
| 218 |
> |
ComplexType W_l_hat; |
| 219 |
|
W_l = 0.0; |
| 220 |
|
for (int m1 = -lNumber_; m1 <= lNumber_; m1++) { |
| 221 |
|
// Zero work array |
| 223 |
|
THRCOF[i] = 0.0; |
| 224 |
|
} |
| 225 |
|
// Get Wigner coefficients |
| 226 |
< |
Wigner3jm(&l_, &l_, &l_, &(double)m1, &m2Min, &m2Max, THRCOF, &mSize_, &error); |
| 226 |
> |
m1Pass = (double)m1; |
| 227 |
> |
Wigner3jm(&l_, &l_, &l_, &m1Pass, &m2Min, &m2Max, THRCOF, &mSize_, &error); |
| 228 |
|
for (int m_index = 1; i < (int)(m2Max - m2Min-1.0); m_index++) { |
| 229 |
|
m2 = floor(m2Min) + m_index - 1; |
| 230 |
|
m3 = -m1-m2; |
| 236 |
|
|
| 237 |
|
// accumulate histogram data for Q_l and W_l_hat: |
| 238 |
|
|
| 239 |
< |
collectHistogram(Q_l, W_l_hat); |
| 239 |
> |
collectHistogram(Q_l, real(W_l_hat)); |
| 240 |
|
|
| 241 |
|
} |
| 242 |
|
} |
| 243 |
|
|
| 229 |
– |
// Normalize by number of frames |
| 230 |
– |
for (int m = -lNumber_; m <= lNumber_; m++){ |
| 231 |
– |
QBar_lm[m] /= nFrames; |
| 232 |
– |
} |
| 233 |
– |
|
| 234 |
– |
|
| 235 |
– |
|
| 236 |
– |
|
| 237 |
– |
|
| 244 |
|
writeOrderParameter(); |
| 245 |
|
|
| 246 |
|
} |
| 247 |
|
|
| 242 |
– |
|
| 243 |
– |
void BondOrderParameter::processHistogram() { |
| 244 |
– |
|
| 245 |
– |
int nPairs = getNPairs(); |
| 246 |
– |
RealType volume = info_->getSnapshotManager()->getCurrentSnapshot()->getVolume(); |
| 247 |
– |
RealType pairDensity = nPairs /volume * 2.0; |
| 248 |
– |
RealType pairConstant = ( 4.0 * NumericConstant::PI * pairDensity ) / 3.0; |
| 248 |
|
|
| 250 |
– |
for(int i = 0 ; i < histogram_.size(); ++i){ |
| 251 |
– |
|
| 252 |
– |
RealType rLower = i * deltaR_; |
| 253 |
– |
RealType rUpper = rLower + deltaR_; |
| 254 |
– |
RealType volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower ); |
| 255 |
– |
RealType nIdeal = volSlice * pairConstant; |
| 256 |
– |
|
| 257 |
– |
avgGofr_[i] += histogram_[i] / nIdeal; |
| 258 |
– |
} |
| 259 |
– |
|
| 260 |
– |
} |
| 261 |
– |
|
| 249 |
|
void BondOrderParameter::collectHistogram(RealType Q_l, RealType W_l_hat) { |
| 250 |
|
|
| 251 |
< |
if (Q_l < MaxQ_) { |
| 252 |
< |
int whichBin = Q_l / deltaQ_; |
| 253 |
< |
Q_histogram_[whichBin] += 1; |
| 254 |
< |
} |
| 255 |
< |
if (W_l_hat < MaxW_) { |
| 256 |
< |
int whichBin = W_l_hat / deltaW_; |
| 257 |
< |
W_histogram_[whichBin] += 1; |
| 251 |
> |
if (Q_l >= MinQ_ && Q_l < MaxQ_) { |
| 252 |
> |
int qbin = (Q_l - MinQ_) / deltaQ_; |
| 253 |
> |
Q_histogram_[qbin] += 1; |
| 254 |
> |
Qcount_++; |
| 255 |
> |
sumQ_ += Q_l; |
| 256 |
> |
sumQ2_ += Q_l * Q_l; |
| 257 |
> |
} else { |
| 258 |
> |
sprintf( painCave.errMsg, |
| 259 |
> |
"Q_l value outside reasonable range\n"); |
| 260 |
> |
painCave.severity = OOPSE_ERROR; |
| 261 |
> |
painCave.isFatal = 1; |
| 262 |
> |
simError(); |
| 263 |
|
} |
| 272 |
– |
} |
| 273 |
– |
|
| 264 |
|
|
| 265 |
+ |
if (W_l_hat >= MinW_ && W_l_hat < MaxW_) { |
| 266 |
+ |
int wbin = (W_l_hat - MinW_) / deltaW_; |
| 267 |
+ |
W_histogram_[wbin] += 1; |
| 268 |
+ |
Wcount_++; |
| 269 |
+ |
sumW_ += W_l_hat; |
| 270 |
+ |
sumW2_ += W_l_hat*W_l_hat; |
| 271 |
+ |
} else { |
| 272 |
+ |
sprintf( painCave.errMsg, |
| 273 |
+ |
"W_l_hat value outside reasonable range\n"); |
| 274 |
+ |
painCave.severity = OOPSE_ERROR; |
| 275 |
+ |
painCave.isFatal = 1; |
| 276 |
+ |
simError(); |
| 277 |
+ |
} |
| 278 |
+ |
} |
| 279 |
+ |
|
| 280 |
|
void BondOrderParameter::writeOrderParameter() { |
| 281 |
|
|
| 282 |
< |
std::ofstream os(getOutputFileName().c_str()); |
| 278 |
< |
os << "#Bond Order Parameter\n"; |
| 279 |
< |
os << "#selection: (" << selectionScript_ << ")\n"; |
| 282 |
> |
std::ofstream osq((getOutputFileName() + "q").c_str()); |
| 283 |
|
|
| 284 |
< |
for (std::size_t i = 0; i < orderParams_.size(); ++i) { |
| 282 |
< |
os << orderParams_[i].p2 << "\t" |
| 283 |
< |
<< orderParams_[i].director[0] << "\t" |
| 284 |
< |
<< orderParams_[i].director[1] << "\t" |
| 285 |
< |
<< orderParams_[i].director[2] << "\t" |
| 286 |
< |
<< orderParams_[i].angle << "\n"; |
| 284 |
> |
if (osq.is_open()) { |
| 285 |
|
|
| 286 |
+ |
RealType qAvg = sumQ_ / (RealType) Qcount_; |
| 287 |
+ |
RealType qStdDev = sumQ2_ / (RealType) Qcount_ - qAvg*qAvg; |
| 288 |
+ |
|
| 289 |
+ |
osq << "# Bond Order Parameter Q_" << lNumber_ << "\n"; |
| 290 |
+ |
osq << "# selection: (" << selectionScript_ << ")\n"; |
| 291 |
+ |
osq << "# <Q_" << lNumber_ << ">: " << qAvg << "\n"; |
| 292 |
+ |
osq << "# std. dev.: " << qStdDev << "\n"; |
| 293 |
+ |
|
| 294 |
+ |
// Normalize by number of frames and write it out: |
| 295 |
+ |
for (int i = 0; i < Q_histogram_.size(); ++i) { |
| 296 |
+ |
RealType Qval = MinQ_ + (i + 0.5) * deltaQ_; |
| 297 |
+ |
osq << Qval << "\t" << Q_histogram_[i] / frameCounter_ << "\n"; |
| 298 |
+ |
} |
| 299 |
+ |
|
| 300 |
+ |
osq.close(); |
| 301 |
+ |
} else { |
| 302 |
+ |
sprintf(painCave.errMsg, "BondOrderParameter: unable to open %s\n", |
| 303 |
+ |
(getOutputFileName() + "q").c_str()); |
| 304 |
+ |
painCave.isFatal = 1; |
| 305 |
+ |
simError(); |
| 306 |
|
} |
| 289 |
– |
} |
| 307 |
|
|
| 308 |
+ |
std::ofstream osw((getOutputFileName() + "w").c_str()); |
| 309 |
|
|
| 310 |
+ |
if (osw.is_open()) { |
| 311 |
|
|
| 312 |
+ |
RealType wAvg = sumW_ / (RealType) Wcount_; |
| 313 |
+ |
RealType wStdDev = sumW2_ / (RealType) Wcount_ - wAvg*wAvg; |
| 314 |
+ |
|
| 315 |
+ |
osw << "# Bond Order Parameter W_" << lNumber_ << "\n"; |
| 316 |
+ |
osw << "# selection: (" << selectionScript_ << ")\n"; |
| 317 |
+ |
osw << "# <W_" << lNumber_ << ">: " << wAvg << "\n"; |
| 318 |
+ |
osw << "# std. dev.: " << wStdDev << "\n"; |
| 319 |
+ |
|
| 320 |
+ |
// Normalize by number of frames and write it out: |
| 321 |
+ |
for (int i = 0; i < W_histogram_.size(); ++i) { |
| 322 |
+ |
RealType Wval = MinW_ + (i + 0.5) * deltaW_; |
| 323 |
+ |
osw << Wval << "\t" << W_histogram_[i] / frameCounter_ << "\n"; |
| 324 |
+ |
} |
| 325 |
+ |
|
| 326 |
+ |
osw.close(); |
| 327 |
+ |
} else { |
| 328 |
+ |
sprintf(painCave.errMsg, "BondOrderParameter: unable to open %s\n", |
| 329 |
+ |
(getOutputFileName() + "w").c_str()); |
| 330 |
+ |
painCave.isFatal = 1; |
| 331 |
+ |
simError(); |
| 332 |
+ |
} |
| 333 |
+ |
} |
| 334 |
|
} |