| 51 |
|
#include "io/DumpReader.hpp" |
| 52 |
|
#include "primitives/Molecule.hpp" |
| 53 |
|
#include "utils/NumericConstant.hpp" |
| 54 |
< |
#include "math/RealSphericalHarmonic.hpp" |
| 54 |
> |
|
| 55 |
|
namespace oopse { |
| 56 |
|
|
| 57 |
– |
|
| 57 |
|
BondOrderParameter::BondOrderParameter(SimInfo* info, |
| 58 |
|
const std::string& filename, |
| 59 |
|
const std::string& sele, |
| 60 |
< |
double rCut, int lNumber, int nbins) |
| 62 |
< |
: StaticAnalyser(info, filename), selectionScript_(sele), |
| 63 |
< |
evaluator_(info), seleMan_(info){ |
| 60 |
> |
double rCut, int lMax, int nbins) : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info){ |
| 61 |
|
|
| 62 |
< |
setOutputName(getPrefix(filename) + ".obo"); |
| 62 |
> |
setOutputName(getPrefix(filename) + ".bo"); |
| 63 |
|
|
| 64 |
|
evaluator_.loadScriptString(sele); |
| 65 |
|
if (!evaluator_.isDynamic()) { |
| 68 |
|
|
| 69 |
|
// Set up cutoff radius and order of the Legendre Polynomial: |
| 70 |
|
|
| 71 |
< |
lNumber_ = lNumber; |
| 71 |
> |
lMax_ = lMax; |
| 72 |
|
rCut_ = rCut; |
| 73 |
< |
mSize_ = 2*lNumber_+1; |
| 73 |
> |
nBins_ = nbins; |
| 74 |
> |
Qcount_.resize(lMax_+1); |
| 75 |
> |
Wcount_.resize(lMax_+1); |
| 76 |
|
|
| 77 |
< |
deltaQ_ = 1.0 / nbins; |
| 79 |
< |
deltaW_ = 2.0 / nbins; |
| 77 |
> |
// Q can take values from 0 to 1 |
| 78 |
|
|
| 79 |
< |
Q_histogram_.resize(nbins); |
| 80 |
< |
W_histogram_.resize(nbins); |
| 79 |
> |
MinQ_ = 0.0; |
| 80 |
> |
MaxQ_ = 1.1; |
| 81 |
> |
deltaQ_ = (MaxQ_ - MinQ_) / 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 |
|
} |
| 90 |
|
|
| 91 |
+ |
BondOrderParameter::~BondOrderParameter() { |
| 92 |
+ |
Q_histogram_.clear(); |
| 93 |
+ |
W_histogram_.clear(); |
| 94 |
+ |
} |
| 95 |
+ |
|
| 96 |
|
void BondOrderParameter::initalizeHistogram() { |
| 97 |
< |
std::fill(Q_histogram_.begin(), Q_histogram_.end(), 0); |
| 98 |
< |
std::fill(W_histogram_.begin(), W_histogram_.end(), 0); |
| 97 |
> |
for (int bin = 0; bin < nBins_; bin++) { |
| 98 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 99 |
> |
Q_histogram_[std::make_pair(bin,l)] = 0; |
| 100 |
> |
W_histogram_[std::make_pair(bin,l)] = 0; |
| 101 |
> |
} |
| 102 |
> |
} |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
void BondOrderParameter::process() { |
| 106 |
|
Molecule* mol; |
| 107 |
|
Atom* atom; |
| 108 |
|
RigidBody* rb; |
| 109 |
+ |
int myIndex; |
| 110 |
|
SimInfo::MoleculeIterator mi; |
| 111 |
|
Molecule::RigidBodyIterator rbIter; |
| 112 |
|
Molecule::AtomIterator ai; |
| 113 |
|
StuntDouble* sd; |
| 114 |
< |
RealType theta; |
| 114 |
> |
Vector3d vec; |
| 115 |
> |
RealType costheta; |
| 116 |
|
RealType phi; |
| 117 |
|
RealType r; |
| 118 |
|
RealType dist; |
| 119 |
< |
std::map<int, RealType> QBar_lm; |
| 120 |
< |
RealType QSq_l; |
| 121 |
< |
RealType Q_l; |
| 122 |
< |
int nBonds; |
| 123 |
< |
RealSphericalHarmonic sphericalHarmonic; |
| 119 |
> |
std::map<std::pair<int,int>,ComplexType> q; |
| 120 |
> |
std::vector<RealType> q_l; |
| 121 |
> |
std::map<std::pair<int,int>,ComplexType> QBar; |
| 122 |
> |
std::vector<RealType> Q2; |
| 123 |
> |
std::vector<RealType> Q; |
| 124 |
> |
std::vector<ComplexType> W; |
| 125 |
> |
std::vector<ComplexType> W_hat; |
| 126 |
> |
int nBonds, Nbonds; |
| 127 |
> |
SphericalHarmonic sphericalHarmonic; |
| 128 |
|
int i, j; |
| 129 |
< |
|
| 130 |
< |
// Set the l for the spherical harmonic, it doesn't change |
| 131 |
< |
sphericalHarmonic.setL(lNumber_); |
| 129 |
> |
// Make arrays for Wigner3jm |
| 130 |
> |
double* THRCOF = new double[2*lMax_+1]; |
| 131 |
> |
// Variables for Wigner routine |
| 132 |
> |
double lPass, m1Pass, m2Min, m2Max; |
| 133 |
> |
int error, m1, m2, m3, mSize; |
| 134 |
> |
mSize = 2*lMax_+1; |
| 135 |
|
|
| 113 |
– |
|
| 136 |
|
DumpReader reader(info_, dumpFilename_); |
| 137 |
|
int nFrames = reader.getNFrames(); |
| 138 |
+ |
frameCounter_ = 0; |
| 139 |
|
|
| 140 |
+ |
q_l.resize(lMax_+1); |
| 141 |
+ |
Q2.resize(lMax_+1); |
| 142 |
+ |
Q.resize(lMax_+1); |
| 143 |
+ |
W.resize(lMax_+1); |
| 144 |
+ |
W_hat.resize(lMax_+1); |
| 145 |
|
|
| 146 |
|
for (int istep = 0; istep < nFrames; istep += step_) { |
| 147 |
|
reader.readFrame(istep); |
| 148 |
+ |
frameCounter_++; |
| 149 |
|
currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 150 |
|
|
| 151 |
|
if (evaluator_.isDynamic()) { |
| 160 |
|
rb = mol->nextRigidBody(rbIter)) { |
| 161 |
|
rb->updateAtoms(); |
| 162 |
|
} |
| 163 |
< |
} |
| 164 |
< |
|
| 163 |
> |
} |
| 164 |
> |
|
| 165 |
|
// outer loop is over the selected StuntDoubles: |
| 166 |
|
|
| 167 |
|
for (sd = seleMan_.beginSelected(i); sd != NULL; |
| 168 |
|
sd = seleMan_.nextSelected(i)) { |
| 169 |
|
|
| 170 |
< |
// For this central atom, zero out nBonds and QBar_lm |
| 142 |
< |
|
| 170 |
> |
myIndex = sd->getGlobalIndex(); |
| 171 |
|
nBonds = 0; |
| 172 |
< |
|
| 173 |
< |
for (int m = -lNumber_; m <= lNumber_; m++) { |
| 174 |
< |
QBar_lm[m] = 0.0; |
| 172 |
> |
|
| 173 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 174 |
> |
for (int m = -l; m <= l; m++) { |
| 175 |
> |
q[std::make_pair(l,m)] = 0.0; |
| 176 |
> |
} |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
// inner loop is over all other atoms in the system: |
| 183 |
|
for (atom = mol->beginAtom(ai); atom != NULL; |
| 184 |
|
atom = mol->nextAtom(ai)) { |
| 185 |
|
|
| 186 |
+ |
if (atom->getGlobalIndex() != myIndex) { |
| 187 |
|
|
| 188 |
< |
Vector3d vec = sd->getPos() - atom->getPos(); |
| 189 |
< |
currentSnapshot_->wrapVector(vec); |
| 190 |
< |
|
| 191 |
< |
// Calculate "bonds" and build Q_lm(r) where |
| 192 |
< |
// Q_lm = Y_lm(theta(r),phi(r)) |
| 193 |
< |
// The spherical harmonics are wrt any arbitrary coordinate |
| 194 |
< |
// system, we choose standard spherical coordinates |
| 195 |
< |
|
| 196 |
< |
r = sqrt(pow(vec.x(),2)+pow(vec.y(),2)+pow(vec.z(),2)); |
| 197 |
< |
|
| 198 |
< |
// Check to see if neighbor is in bond cutoff |
| 199 |
< |
|
| 200 |
< |
if (r < rCut_) { |
| 201 |
< |
theta = atan2(vec.y(), vec.x()); |
| 202 |
< |
phi = acos(vec.z()/r); |
| 203 |
< |
for(int m = -lNumber_; m <= lNumber_; m++){ |
| 204 |
< |
sphericalHarmonic.setM(m); |
| 205 |
< |
QBar_lm[m] += sphericalHarmonic.getValueAt(theta,phi); |
| 206 |
< |
} |
| 207 |
< |
nBonds++; |
| 208 |
< |
} |
| 188 |
> |
vec = sd->getPos() - atom->getPos(); |
| 189 |
> |
currentSnapshot_->wrapVector(vec); |
| 190 |
> |
|
| 191 |
> |
// Calculate "bonds" and build Q_lm(r) where |
| 192 |
> |
// Q_lm = Y_lm(theta(r),phi(r)) |
| 193 |
> |
// The spherical harmonics are wrt any arbitrary coordinate |
| 194 |
> |
// system, we choose standard spherical coordinates |
| 195 |
> |
|
| 196 |
> |
r = vec.length(); |
| 197 |
> |
|
| 198 |
> |
// Check to see if neighbor is in bond cutoff |
| 199 |
> |
|
| 200 |
> |
if (r < rCut_) { |
| 201 |
> |
costheta = vec.z() / r; |
| 202 |
> |
phi = atan2(vec.y(), vec.x()); |
| 203 |
> |
|
| 204 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 205 |
> |
sphericalHarmonic.setL(l); |
| 206 |
> |
for(int m = -l; m <= l; m++){ |
| 207 |
> |
sphericalHarmonic.setM(m); |
| 208 |
> |
q[std::make_pair(l,m)] += sphericalHarmonic.getValueAt(costheta, phi); |
| 209 |
> |
} |
| 210 |
> |
} |
| 211 |
> |
nBonds++; |
| 212 |
> |
} |
| 213 |
> |
} |
| 214 |
|
} |
| 215 |
|
} |
| 216 |
|
|
| 217 |
< |
// Normalize Qbar |
| 218 |
< |
for (int m = -lNumber_;m <= lNumber_; m++){ |
| 219 |
< |
QBar_lm[m] /= nBonds; |
| 217 |
> |
|
| 218 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 219 |
> |
q_l[l] = 0.0; |
| 220 |
> |
for(int m = -l; m <= l; m++) { |
| 221 |
> |
q_l[l] += norm(q[std::make_pair(l,m)]); |
| 222 |
> |
} |
| 223 |
> |
q_l[l] *= 4.0*NumericConstant::PI/(RealType)(2*l + 1); |
| 224 |
> |
q_l[l] = sqrt(q_l[l])/(RealType)nBonds; |
| 225 |
|
} |
| 226 |
< |
|
| 227 |
< |
// Find second order invariant Q_l |
| 228 |
< |
|
| 229 |
< |
QSq_l = 0.0; |
| 230 |
< |
for (int m = -lNumber_; m <= lNumber_; m++){ |
| 231 |
< |
QSq_l += pow(QBar_lm[m], 2); |
| 226 |
> |
collectHistogram(q_l); |
| 227 |
> |
|
| 228 |
> |
Nbonds += nBonds; |
| 229 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 230 |
> |
for (int m = -l; m <= l; m++) { |
| 231 |
> |
QBar[std::make_pair(l,m)] += q[std::make_pair(l,m)]; |
| 232 |
> |
} |
| 233 |
|
} |
| 234 |
< |
Q_l = sqrt(QSq_l*(4.0 * NumericConstant::PI / (2.0*(RealType)lNumber_ + 1))); |
| 235 |
< |
|
| 236 |
< |
// Find Third Order Invariant W_l |
| 237 |
< |
|
| 238 |
< |
// Make arrays for Wigner3jm |
| 239 |
< |
double* THRCOF = new double[mSize_]; |
| 240 |
< |
// Variables for Wigner routine |
| 199 |
< |
double l_ = (double)lNumber_; |
| 200 |
< |
double m2Min, m2Max; |
| 201 |
< |
int error, m1, m2, m3; |
| 202 |
< |
|
| 203 |
< |
RealType W_l; |
| 204 |
< |
RealType W_l_hat; |
| 205 |
< |
W_l = 0.0; |
| 206 |
< |
for (int m1 = -lNumber_; m1 <= lNumber_; m1++) { |
| 207 |
< |
// Zero work array |
| 208 |
< |
for (int ii = 0; ii < mSize_; ii++){ |
| 209 |
< |
THRCOF[i] = 0.0; |
| 210 |
< |
} |
| 211 |
< |
// Get Wigner coefficients |
| 212 |
< |
Wigner3jm(&l_, &l_, &l_, &(double)m1, &m2Min, &m2Max, THRCOF, &mSize_, &error); |
| 213 |
< |
for (int m_index = 1; i < (int)(m2Max - m2Min-1.0); m_index++) { |
| 214 |
< |
m2 = floor(m2Min) + m_index - 1; |
| 215 |
< |
m3 = -m1-m2; |
| 216 |
< |
W_l += THRCOF[m_index]*QBar_lm[m1+lNumber_]*QBar_lm[m2+lNumber_]*QBar_lm[m3+lNumber_]; |
| 217 |
< |
} |
| 218 |
< |
} |
| 219 |
< |
|
| 220 |
< |
W_l_hat = W_l / pow(QSq_l, 1.5); |
| 221 |
< |
|
| 222 |
< |
// accumulate histogram data for Q_l and W_l_hat: |
| 223 |
< |
|
| 224 |
< |
collectHistogram(Q_l, W_l_hat); |
| 225 |
< |
|
| 234 |
> |
} |
| 235 |
> |
} |
| 236 |
> |
|
| 237 |
> |
// Normalize Qbar2 |
| 238 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 239 |
> |
for (int m = -l; m <= l; m++){ |
| 240 |
> |
QBar[std::make_pair(l,m)] /= Nbonds; |
| 241 |
|
} |
| 242 |
|
} |
| 243 |
|
|
| 244 |
< |
// Normalize by number of frames |
| 245 |
< |
for (int m = -lNumber_; m <= lNumber_; m++){ |
| 246 |
< |
QBar_lm[m] /= nFrames; |
| 244 |
> |
// Find second order invariant Q_l |
| 245 |
> |
|
| 246 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 247 |
> |
Q2[l] = 0.0; |
| 248 |
> |
for (int m = -l; m <= l; m++){ |
| 249 |
> |
Q2[l] += norm(QBar[std::make_pair(l,m)]); |
| 250 |
> |
} |
| 251 |
> |
Q[l] = sqrt(Q2[l] * 4.0 * NumericConstant::PI / (RealType)(2*l + 1)); |
| 252 |
|
} |
| 253 |
|
|
| 234 |
– |
|
| 235 |
– |
|
| 236 |
– |
|
| 237 |
– |
|
| 238 |
– |
writeOrderParameter(); |
| 239 |
– |
|
| 240 |
– |
} |
| 254 |
|
|
| 242 |
– |
|
| 243 |
– |
void BondOrderParameter::processHistogram() { |
| 255 |
|
|
| 256 |
< |
int nPairs = getNPairs(); |
| 257 |
< |
RealType volume = info_->getSnapshotManager()->getCurrentSnapshot()->getVolume(); |
| 258 |
< |
RealType pairDensity = nPairs /volume * 2.0; |
| 259 |
< |
RealType pairConstant = ( 4.0 * NumericConstant::PI * pairDensity ) / 3.0; |
| 260 |
< |
|
| 261 |
< |
for(int i = 0 ; i < histogram_.size(); ++i){ |
| 262 |
< |
|
| 263 |
< |
RealType rLower = i * deltaR_; |
| 264 |
< |
RealType rUpper = rLower + deltaR_; |
| 265 |
< |
RealType volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower ); |
| 266 |
< |
RealType nIdeal = volSlice * pairConstant; |
| 267 |
< |
|
| 268 |
< |
avgGofr_[i] += histogram_[i] / nIdeal; |
| 256 |
> |
// Find Third Order Invariant W_l |
| 257 |
> |
|
| 258 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 259 |
> |
W[l] = 0.0; |
| 260 |
> |
lPass = (double)l; |
| 261 |
> |
for (int m1 = -l; m1 <= l; m1++) { |
| 262 |
> |
// Zero work array |
| 263 |
> |
for (int ii = 0; ii < 2*l + 1; ii++){ |
| 264 |
> |
THRCOF[ii] = 0.0; |
| 265 |
> |
} |
| 266 |
> |
// Get Wigner coefficients |
| 267 |
> |
m1Pass = (double)m1; |
| 268 |
> |
|
| 269 |
> |
Wigner3jm(&lPass, &lPass, &lPass, |
| 270 |
> |
&m1Pass, &m2Min, &m2Max, |
| 271 |
> |
THRCOF, &mSize, &error); |
| 272 |
> |
|
| 273 |
> |
for (int mmm = 0; mmm < (int)(m2Max - m2Min); mmm++) { |
| 274 |
> |
m2 = (int)floor(m2Min) + mmm; |
| 275 |
> |
m3 = -m1-m2; |
| 276 |
> |
W[l] += THRCOF[mmm] * |
| 277 |
> |
QBar[std::make_pair(l,m1)] * |
| 278 |
> |
QBar[std::make_pair(l,m2)] * |
| 279 |
> |
QBar[std::make_pair(l,m3)]; |
| 280 |
> |
} |
| 281 |
> |
} |
| 282 |
> |
|
| 283 |
> |
W_hat[l] = W[l] / pow(Q2[l], 1.5); |
| 284 |
|
} |
| 285 |
< |
|
| 285 |
> |
|
| 286 |
> |
writeOrderParameter(Q, W_hat); |
| 287 |
|
} |
| 288 |
|
|
| 289 |
< |
void BondOrderParameter::collectHistogram(RealType Q_l, RealType W_l_hat) { |
| 289 |
> |
void BondOrderParameter::collectHistogram(std::vector<RealType> q) { |
| 290 |
|
|
| 291 |
< |
if (Q_l < MaxQ_) { |
| 292 |
< |
int whichBin = Q_l / deltaQ_; |
| 293 |
< |
Q_histogram_[whichBin] += 1; |
| 291 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 292 |
> |
if (q[l] >= MinQ_ && q[l] < MaxQ_) { |
| 293 |
> |
int qbin = (q[l] - MinQ_) / deltaQ_; |
| 294 |
> |
Q_histogram_[std::make_pair(qbin,l)] += 1; |
| 295 |
> |
Qcount_[l]++; |
| 296 |
> |
} else { |
| 297 |
> |
sprintf( painCave.errMsg, |
| 298 |
> |
"q_l value outside reasonable range\n"); |
| 299 |
> |
painCave.severity = OOPSE_ERROR; |
| 300 |
> |
painCave.isFatal = 1; |
| 301 |
> |
simError(); |
| 302 |
> |
} |
| 303 |
|
} |
| 268 |
– |
if (W_l_hat < MaxW_) { |
| 269 |
– |
int whichBin = W_l_hat / deltaW_; |
| 270 |
– |
W_histogram_[whichBin] += 1; |
| 271 |
– |
} |
| 272 |
– |
} |
| 273 |
– |
|
| 304 |
|
|
| 305 |
< |
void BondOrderParameter::writeOrderParameter() { |
| 305 |
> |
} |
| 306 |
|
|
| 307 |
+ |
|
| 308 |
+ |
void BondOrderParameter::writeOrderParameter(std::vector<RealType> Q, std::vector<ComplexType> What) { |
| 309 |
+ |
|
| 310 |
|
std::ofstream os(getOutputFileName().c_str()); |
| 311 |
< |
os << "#Bond Order Parameter\n"; |
| 312 |
< |
os << "#selection: (" << selectionScript_ << ")\n"; |
| 311 |
> |
|
| 312 |
> |
if (os.is_open()) { |
| 313 |
> |
|
| 314 |
> |
os << "# Bond Order Parameters\n"; |
| 315 |
> |
os << "# selection: (" << selectionScript_ << ")\n"; |
| 316 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 317 |
> |
os << "# \n"; |
| 318 |
> |
os << "# <Q_" << l << ">: " << Q[l] << "\n"; |
| 319 |
> |
os << "# <W_" << l << ">: " << real(What[l]) << "\n"; |
| 320 |
> |
} |
| 321 |
> |
// Normalize by number of frames and write it out: |
| 322 |
> |
for (int i = 0; i < nBins_; ++i) { |
| 323 |
> |
RealType Qval = MinQ_ + (i + 0.5) * deltaQ_; |
| 324 |
> |
os << Qval; |
| 325 |
> |
for (int l = 0; l <= lMax_; l++) { |
| 326 |
> |
os << "\t" << (RealType)Q_histogram_[std::make_pair(i,l)] / (RealType)Qcount_[l]; |
| 327 |
> |
} |
| 328 |
> |
os << "\n"; |
| 329 |
> |
} |
| 330 |
|
|
| 331 |
< |
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"; |
| 331 |
> |
os.close(); |
| 332 |
|
|
| 333 |
+ |
} else { |
| 334 |
+ |
sprintf(painCave.errMsg, "BondOrderParameter: unable to open %s\n", |
| 335 |
+ |
getOutputFileName().c_str()); |
| 336 |
+ |
painCave.isFatal = 1; |
| 337 |
+ |
simError(); |
| 338 |
|
} |
| 339 |
|
} |
| 290 |
– |
|
| 291 |
– |
|
| 292 |
– |
|
| 340 |
|
} |