| 51 |
|
#include "io/DumpReader.hpp" |
| 52 |
|
#include "primitives/Molecule.hpp" |
| 53 |
|
#include "utils/NumericConstant.hpp" |
| 54 |
– |
#include "math/SphericalHarmonic.hpp" |
| 54 |
|
|
| 55 |
|
namespace oopse { |
| 56 |
|
|
| 57 |
|
BondOrderParameter::BondOrderParameter(SimInfo* info, |
| 58 |
|
const std::string& filename, |
| 59 |
|
const std::string& sele, |
| 60 |
< |
double rCut, int lNumber, int nbins) : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info){ |
| 60 |
> |
double rCut, int nbins) : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info){ |
| 61 |
|
|
| 62 |
|
setOutputName(getPrefix(filename) + ".bo"); |
| 63 |
|
|
| 68 |
|
|
| 69 |
|
// Set up cutoff radius and order of the Legendre Polynomial: |
| 70 |
|
|
| 72 |
– |
lNumber_ = lNumber; |
| 71 |
|
rCut_ = rCut; |
| 72 |
< |
mSize_ = 2*lNumber_+1; |
| 72 |
> |
nBins_ = nbins; |
| 73 |
> |
Qcount_.resize(lMax_+1); |
| 74 |
> |
Wcount_.resize(lMax_+1); |
| 75 |
> |
|
| 76 |
> |
// Q can take values from 0 to 1 |
| 77 |
> |
|
| 78 |
> |
MinQ_ = 0.0; |
| 79 |
> |
MaxQ_ = 1.1; |
| 80 |
> |
deltaQ_ = (MaxQ_ - MinQ_) / nbins; |
| 81 |
> |
|
| 82 |
> |
// W_6 for icosahedral clusters is 11 / sqrt(4199) = 0.169754, so we'll |
| 83 |
> |
// use values for MinW_ and MaxW_ that are slightly larger than this: |
| 84 |
> |
|
| 85 |
> |
MinW_ = -0.25; |
| 86 |
> |
MaxW_ = 0.25; |
| 87 |
> |
deltaW_ = (MaxW_ - MinW_) / nbins; |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
BondOrderParameter::~BondOrderParameter() { |
| 91 |
+ |
Q_histogram_.clear(); |
| 92 |
+ |
W_histogram_.clear(); |
| 93 |
|
} |
| 94 |
|
|
| 95 |
+ |
void BondOrderParameter::initalizeHistogram() { |
| 96 |
+ |
for (int bin = 0; bin < nBins_; bin++) { |
| 97 |
+ |
for (int l = 0; l <= lMax_; l++) { |
| 98 |
+ |
Q_histogram_[std::make_pair(bin,l)] = 0; |
| 99 |
+ |
W_histogram_[std::make_pair(bin,l)] = 0; |
| 100 |
+ |
} |
| 101 |
+ |
} |
| 102 |
+ |
} |
| 103 |
+ |
|
| 104 |
|
void BondOrderParameter::process() { |
| 105 |
|
Molecule* mol; |
| 106 |
|
Atom* atom; |
| 115 |
|
RealType phi; |
| 116 |
|
RealType r; |
| 117 |
|
RealType dist; |
| 118 |
< |
std::map<int,ComplexType> QBar_lm; |
| 119 |
< |
RealType QSq_l; |
| 120 |
< |
RealType Q_l; |
| 121 |
< |
ComplexType W_l; |
| 122 |
< |
ComplexType W_l_hat; |
| 123 |
< |
int nBonds; |
| 118 |
> |
std::map<std::pair<int,int>,ComplexType> q; |
| 119 |
> |
std::vector<RealType> q_l; |
| 120 |
> |
std::vector<RealType> q2; |
| 121 |
> |
std::vector<ComplexType> w; |
| 122 |
> |
std::vector<ComplexType> w_hat; |
| 123 |
> |
std::map<std::pair<int,int>,ComplexType> QBar; |
| 124 |
> |
std::vector<RealType> Q2; |
| 125 |
> |
std::vector<RealType> Q; |
| 126 |
> |
std::vector<ComplexType> W; |
| 127 |
> |
std::vector<ComplexType> W_hat; |
| 128 |
> |
int nBonds, Nbonds; |
| 129 |
|
SphericalHarmonic sphericalHarmonic; |
| 130 |
|
int i, j; |
| 131 |
|
// Make arrays for Wigner3jm |
| 132 |
< |
double* THRCOF = new double[mSize_]; |
| 132 |
> |
double* THRCOF = new double[2*lMax_+1]; |
| 133 |
|
// Variables for Wigner routine |
| 134 |
< |
double l_ = (double)lNumber_; |
| 135 |
< |
double m1Pass, m2Min, m2Max; |
| 136 |
< |
int error, m1, m2, m3; |
| 134 |
> |
double lPass, m1Pass, m2Min, m2Max; |
| 135 |
> |
int error, m1, m2, m3, mSize; |
| 136 |
> |
mSize = 2*lMax_+1; |
| 137 |
|
|
| 109 |
– |
// Set the l for the spherical harmonic, it doesn't change |
| 110 |
– |
sphericalHarmonic.setL(lNumber_); |
| 111 |
– |
|
| 138 |
|
DumpReader reader(info_, dumpFilename_); |
| 139 |
|
int nFrames = reader.getNFrames(); |
| 140 |
|
frameCounter_ = 0; |
| 141 |
|
|
| 142 |
+ |
q_l.resize(lMax_+1); |
| 143 |
+ |
q2.resize(lMax_+1); |
| 144 |
+ |
w.resize(lMax_+1); |
| 145 |
+ |
w_hat.resize(lMax_+1); |
| 146 |
+ |
|
| 147 |
+ |
Q2.resize(lMax_+1); |
| 148 |
+ |
Q.resize(lMax_+1); |
| 149 |
+ |
W.resize(lMax_+1); |
| 150 |
+ |
W_hat.resize(lMax_+1); |
| 151 |
+ |
|
| 152 |
|
for (int istep = 0; istep < nFrames; istep += step_) { |
| 153 |
|
reader.readFrame(istep); |
| 154 |
|
frameCounter_++; |
| 166 |
|
rb = mol->nextRigidBody(rbIter)) { |
| 167 |
|
rb->updateAtoms(); |
| 168 |
|
} |
| 169 |
< |
} |
| 170 |
< |
|
| 135 |
< |
nBonds = 0; |
| 136 |
< |
|
| 137 |
< |
for (int m = -lNumber_; m <= lNumber_; m++) { |
| 138 |
< |
QBar_lm[m] = 0.0; |
| 139 |
< |
} |
| 140 |
< |
|
| 169 |
> |
} |
| 170 |
> |
|
| 171 |
|
// outer loop is over the selected StuntDoubles: |
| 172 |
|
|
| 173 |
|
for (sd = seleMan_.beginSelected(i); sd != NULL; |
| 174 |
|
sd = seleMan_.nextSelected(i)) { |
| 175 |
|
|
| 176 |
|
myIndex = sd->getGlobalIndex(); |
| 177 |
+ |
nBonds = 0; |
| 178 |
|
|
| 179 |
+ |
for (int l = 0; l <= lMax_; l++) { |
| 180 |
+ |
for (int m = -l; m <= l; m++) { |
| 181 |
+ |
q[std::make_pair(l,m)] = 0.0; |
| 182 |
+ |
} |
| 183 |
+ |
} |
| 184 |
+ |
|
| 185 |
|
// inner loop is over all other atoms in the system: |
| 186 |
|
|
| 187 |
|
for (mol = info_->beginMolecule(mi); mol != NULL; |
| 206 |
|
if (r < rCut_) { |
| 207 |
|
costheta = vec.z() / r; |
| 208 |
|
phi = atan2(vec.y(), vec.x()); |
| 209 |
< |
|
| 210 |
< |
for(int m = -lNumber_; m <= lNumber_; m++){ |
| 211 |
< |
sphericalHarmonic.setM(m); |
| 212 |
< |
QBar_lm[m] += sphericalHarmonic.getValueAt(costheta, phi); |
| 209 |
> |
|
| 210 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 211 |
> |
sphericalHarmonic.setL(l); |
| 212 |
> |
for(int m = -l; m <= l; m++){ |
| 213 |
> |
sphericalHarmonic.setM(m); |
| 214 |
> |
q[std::make_pair(l,m)] += sphericalHarmonic.getValueAt(costheta, phi); |
| 215 |
> |
} |
| 216 |
|
} |
| 217 |
|
nBonds++; |
| 218 |
|
} |
| 219 |
|
} |
| 220 |
|
} |
| 221 |
|
} |
| 222 |
< |
} |
| 223 |
< |
} |
| 222 |
> |
|
| 223 |
> |
|
| 224 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 225 |
> |
q_l[l] = 0.0; |
| 226 |
> |
for(int m = -l; m <= l; m++) { |
| 227 |
> |
q_l[l] += norm(q[std::make_pair(l,m)]); |
| 228 |
> |
} |
| 229 |
> |
q_l[l] *= 4.0*NumericConstant::PI/(RealType)(2*l + 1); |
| 230 |
> |
q_l[l] = sqrt(q_l[l])/(RealType)nBonds; |
| 231 |
> |
} |
| 232 |
|
|
| 233 |
+ |
// Find second order invariant Q_l |
| 234 |
+ |
|
| 235 |
+ |
for (int l = 0; l <= lMax_; l++) { |
| 236 |
+ |
q2[l] = 0.0; |
| 237 |
+ |
for (int m = -l; m <= l; m++){ |
| 238 |
+ |
q2[l] += norm(q[std::make_pair(l,m)]); |
| 239 |
+ |
} |
| 240 |
+ |
q_l[l] = sqrt(q2[l] * 4.0 * NumericConstant::PI / |
| 241 |
+ |
(RealType)(2*l + 1))/(RealType)nBonds; |
| 242 |
+ |
} |
| 243 |
+ |
|
| 244 |
+ |
// Find Third Order Invariant W_l |
| 245 |
+ |
|
| 246 |
+ |
for (int l = 0; l <= lMax_; l++) { |
| 247 |
+ |
w[l] = 0.0; |
| 248 |
+ |
lPass = (double)l; |
| 249 |
+ |
for (int m1 = -l; m1 <= l; m1++) { |
| 250 |
+ |
// Zero work array |
| 251 |
+ |
for (int ii = 0; ii < 2*l + 1; ii++){ |
| 252 |
+ |
THRCOF[ii] = 0.0; |
| 253 |
+ |
} |
| 254 |
+ |
// Get Wigner coefficients |
| 255 |
+ |
m1Pass = (double)m1; |
| 256 |
+ |
|
| 257 |
+ |
Wigner3jm(&lPass, &lPass, &lPass, |
| 258 |
+ |
&m1Pass, &m2Min, &m2Max, |
| 259 |
+ |
THRCOF, &mSize, &error); |
| 260 |
+ |
|
| 261 |
+ |
for (int mmm = 0; mmm < (int)(m2Max - m2Min); mmm++) { |
| 262 |
+ |
m2 = (int)floor(m2Min) + mmm; |
| 263 |
+ |
m3 = -m1-m2; |
| 264 |
+ |
w[l] += THRCOF[mmm] * |
| 265 |
+ |
q[std::make_pair(l,m1)] * |
| 266 |
+ |
q[std::make_pair(l,m2)] * |
| 267 |
+ |
q[std::make_pair(l,m3)]; |
| 268 |
+ |
} |
| 269 |
+ |
} |
| 270 |
+ |
|
| 271 |
+ |
w_hat[l] = w[l] / pow(q2[l], 1.5); |
| 272 |
+ |
} |
| 273 |
+ |
|
| 274 |
+ |
collectHistogram(q_l, w_hat); |
| 275 |
+ |
|
| 276 |
+ |
Nbonds += nBonds; |
| 277 |
+ |
for (int l = 0; l <= lMax_; l++) { |
| 278 |
+ |
for (int m = -l; m <= l; m++) { |
| 279 |
+ |
QBar[std::make_pair(l,m)] += q[std::make_pair(l,m)]; |
| 280 |
+ |
} |
| 281 |
+ |
} |
| 282 |
+ |
} |
| 283 |
+ |
} |
| 284 |
+ |
|
| 285 |
|
// Normalize Qbar2 |
| 286 |
< |
for (int m = -lNumber_;m <= lNumber_; m++){ |
| 287 |
< |
QBar_lm[m] /= nBonds; |
| 286 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 287 |
> |
for (int m = -l; m <= l; m++){ |
| 288 |
> |
QBar[std::make_pair(l,m)] /= Nbonds; |
| 289 |
> |
} |
| 290 |
|
} |
| 291 |
|
|
| 292 |
|
// Find second order invariant Q_l |
| 293 |
|
|
| 294 |
< |
QSq_l = 0.0; |
| 295 |
< |
for (int m = -lNumber_; m <= lNumber_; m++){ |
| 296 |
< |
QSq_l += norm(QBar_lm[m]); |
| 294 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 295 |
> |
Q2[l] = 0.0; |
| 296 |
> |
for (int m = -l; m <= l; m++){ |
| 297 |
> |
Q2[l] += norm(QBar[std::make_pair(l,m)]); |
| 298 |
> |
} |
| 299 |
> |
Q[l] = sqrt(Q2[l] * 4.0 * NumericConstant::PI / (RealType)(2*l + 1)); |
| 300 |
|
} |
| 301 |
|
|
| 197 |
– |
std::cout << "qsl = " << QSq_l << "\n"; |
| 198 |
– |
Q_l = sqrt(QSq_l * 4.0 * NumericConstant::PI / (RealType)(2*lNumber_ + 1)); |
| 199 |
– |
|
| 302 |
|
// Find Third Order Invariant W_l |
| 303 |
|
|
| 304 |
< |
W_l = 0.0; |
| 305 |
< |
for (int m1 = -lNumber_; m1 <= lNumber_; m1++) { |
| 306 |
< |
// Zero work array |
| 307 |
< |
for (int ii = 0; ii < mSize_; ii++){ |
| 308 |
< |
THRCOF[ii] = 0.0; |
| 304 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 305 |
> |
W[l] = 0.0; |
| 306 |
> |
lPass = (double)l; |
| 307 |
> |
for (int m1 = -l; m1 <= l; m1++) { |
| 308 |
> |
// Zero work array |
| 309 |
> |
for (int ii = 0; ii < 2*l + 1; ii++){ |
| 310 |
> |
THRCOF[ii] = 0.0; |
| 311 |
> |
} |
| 312 |
> |
// Get Wigner coefficients |
| 313 |
> |
m1Pass = (double)m1; |
| 314 |
> |
|
| 315 |
> |
Wigner3jm(&lPass, &lPass, &lPass, |
| 316 |
> |
&m1Pass, &m2Min, &m2Max, |
| 317 |
> |
THRCOF, &mSize, &error); |
| 318 |
> |
|
| 319 |
> |
for (int mmm = 0; mmm < (int)(m2Max - m2Min); mmm++) { |
| 320 |
> |
m2 = (int)floor(m2Min) + mmm; |
| 321 |
> |
m3 = -m1-m2; |
| 322 |
> |
W[l] += THRCOF[mmm] * |
| 323 |
> |
QBar[std::make_pair(l,m1)] * |
| 324 |
> |
QBar[std::make_pair(l,m2)] * |
| 325 |
> |
QBar[std::make_pair(l,m3)]; |
| 326 |
> |
} |
| 327 |
|
} |
| 208 |
– |
// Get Wigner coefficients |
| 209 |
– |
m1Pass = (double)m1; |
| 328 |
|
|
| 329 |
< |
Wigner3jm(&l_, &l_, &l_, |
| 212 |
< |
&m1Pass, &m2Min, &m2Max, |
| 213 |
< |
THRCOF, &mSize_, &error); |
| 214 |
< |
|
| 215 |
< |
for (int mmm = 0; mmm < (int)(m2Max - m2Min); mmm++) { |
| 216 |
< |
m2 = (int)floor(m2Min) + mmm; |
| 217 |
< |
m3 = -m1-m2; |
| 218 |
< |
W_l += THRCOF[mmm] * QBar_lm[m1] * QBar_lm[m2] * QBar_lm[m3]; |
| 219 |
< |
} |
| 329 |
> |
W_hat[l] = W[l] / pow(Q2[l], 1.5); |
| 330 |
|
} |
| 331 |
|
|
| 332 |
< |
W_l_hat = W_l / pow(QSq_l, 1.5); |
| 223 |
< |
|
| 224 |
< |
writeOrderParameter(Q_l, real(W_l_hat)); |
| 332 |
> |
writeOrderParameter(Q, W_hat); |
| 333 |
|
} |
| 334 |
|
|
| 335 |
+ |
void BondOrderParameter::collectHistogram(std::vector<RealType> q, |
| 336 |
+ |
std::vector<ComplexType> what) { |
| 337 |
|
|
| 338 |
< |
void BondOrderParameter::writeOrderParameter(RealType ql, RealType Wlhat) { |
| 338 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 339 |
> |
if (q[l] >= MinQ_ && q[l] < MaxQ_) { |
| 340 |
> |
int qbin = (q[l] - MinQ_) / deltaQ_; |
| 341 |
> |
Q_histogram_[std::make_pair(qbin,l)] += 1; |
| 342 |
> |
Qcount_[l]++; |
| 343 |
> |
} else { |
| 344 |
> |
sprintf( painCave.errMsg, |
| 345 |
> |
"q_l value outside reasonable range\n"); |
| 346 |
> |
painCave.severity = OOPSE_ERROR; |
| 347 |
> |
painCave.isFatal = 1; |
| 348 |
> |
simError(); |
| 349 |
> |
} |
| 350 |
> |
} |
| 351 |
|
|
| 352 |
< |
std::ofstream os(getOutputFileName().c_str()); |
| 352 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 353 |
> |
if (real(what[l]) >= MinW_ && real(what[l]) < MaxW_) { |
| 354 |
> |
int wbin = (real(what[l]) - MinW_) / deltaW_; |
| 355 |
> |
W_histogram_[std::make_pair(wbin,l)] += 1; |
| 356 |
> |
Wcount_[l]++; |
| 357 |
> |
} else { |
| 358 |
> |
sprintf( painCave.errMsg, |
| 359 |
> |
"Re[w_hat] value outside reasonable range\n"); |
| 360 |
> |
painCave.severity = OOPSE_ERROR; |
| 361 |
> |
painCave.isFatal = 1; |
| 362 |
> |
simError(); |
| 363 |
> |
} |
| 364 |
> |
} |
| 365 |
|
|
| 366 |
< |
if (os.is_open()) { |
| 366 |
> |
} |
| 367 |
> |
|
| 368 |
> |
|
| 369 |
> |
void BondOrderParameter::writeOrderParameter(std::vector<RealType> Q, |
| 370 |
> |
std::vector<ComplexType> What) { |
| 371 |
> |
|
| 372 |
> |
std::ofstream osq((getOutputFileName() + "q").c_str()); |
| 373 |
> |
|
| 374 |
> |
if (osq.is_open()) { |
| 375 |
|
|
| 376 |
< |
os << "# Bond Order Parameters\n"; |
| 377 |
< |
os << "# selection: (" << selectionScript_ << ")\n"; |
| 378 |
< |
os << "# \n"; |
| 379 |
< |
os << "# <Q_" << lNumber_ << ">: " << ql << "\n"; |
| 380 |
< |
os << "# <W_" << lNumber_ << ">: " << Wlhat << "\n"; |
| 381 |
< |
os.close(); |
| 376 |
> |
osq << "# Bond Order Parameters\n"; |
| 377 |
> |
osq << "# selection: (" << selectionScript_ << ")\n"; |
| 378 |
> |
osq << "# \n"; |
| 379 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 380 |
> |
osq << "# <Q_" << l << ">: " << Q[l] << "\n"; |
| 381 |
> |
} |
| 382 |
> |
// Normalize by number of frames and write it out: |
| 383 |
> |
for (int i = 0; i < nBins_; ++i) { |
| 384 |
> |
RealType Qval = MinQ_ + (i + 0.5) * deltaQ_; |
| 385 |
> |
osq << Qval; |
| 386 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 387 |
> |
osq << "\t" << (RealType)Q_histogram_[std::make_pair(i,l)] / (RealType)Qcount_[l]; |
| 388 |
> |
} |
| 389 |
> |
osq << "\n"; |
| 390 |
> |
} |
| 391 |
|
|
| 392 |
+ |
osq.close(); |
| 393 |
+ |
|
| 394 |
|
} else { |
| 395 |
|
sprintf(painCave.errMsg, "BondOrderParameter: unable to open %s\n", |
| 396 |
< |
getOutputFileName().c_str()); |
| 396 |
> |
(getOutputFileName() + "q").c_str()); |
| 397 |
|
painCave.isFatal = 1; |
| 398 |
|
simError(); |
| 399 |
|
} |
| 400 |
+ |
|
| 401 |
+ |
std::ofstream osw((getOutputFileName() + "w").c_str()); |
| 402 |
+ |
|
| 403 |
+ |
if (osw.is_open()) { |
| 404 |
+ |
osw << "# Bond Order Parameters\n"; |
| 405 |
+ |
osw << "# selection: (" << selectionScript_ << ")\n"; |
| 406 |
+ |
osw << "# \n"; |
| 407 |
+ |
for (int l = 0; l <= lMax_; l++) { |
| 408 |
+ |
osw << "# <W_" << l << ">: " << real(What[l]) << "\n"; |
| 409 |
+ |
} |
| 410 |
+ |
// Normalize by number of frames and write it out: |
| 411 |
+ |
for (int i = 0; i < nBins_; ++i) { |
| 412 |
+ |
RealType Wval = MinW_ + (i + 0.5) * deltaW_; |
| 413 |
+ |
osw << Wval; |
| 414 |
+ |
for (int l = 0; l <= lMax_; l++) { |
| 415 |
+ |
osw << "\t" << (RealType)W_histogram_[std::make_pair(i,l)] / (RealType)Wcount_[l]; |
| 416 |
+ |
} |
| 417 |
+ |
osw << "\n"; |
| 418 |
+ |
} |
| 419 |
+ |
|
| 420 |
+ |
osw.close(); |
| 421 |
+ |
} else { |
| 422 |
+ |
sprintf(painCave.errMsg, "BondOrderParameter: unable to open %s\n", |
| 423 |
+ |
(getOutputFileName() + "w").c_str()); |
| 424 |
+ |
painCave.isFatal = 1; |
| 425 |
+ |
simError(); |
| 426 |
+ |
} |
| 427 |
+ |
|
| 428 |
|
} |
| 429 |
|
} |