| 1 |
chuckv |
1038 |
/* |
| 2 |
|
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
| 3 |
|
|
* |
| 4 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
| 5 |
|
|
* non-exclusive, royalty free, license to use, modify and |
| 6 |
|
|
* redistribute this software in source and binary code form, provided |
| 7 |
|
|
* that the following conditions are met: |
| 8 |
|
|
* |
| 9 |
|
|
* 1. Acknowledgement of the program authors must be made in any |
| 10 |
|
|
* publication of scientific results based in part on use of the |
| 11 |
|
|
* program. An acceptable form of acknowledgement is citation of |
| 12 |
|
|
* the article in which the program was described (Matthew |
| 13 |
|
|
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
| 14 |
|
|
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
| 15 |
|
|
* Parallel Simulation Engine for Molecular Dynamics," |
| 16 |
|
|
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
| 17 |
|
|
* |
| 18 |
|
|
* 2. Redistributions of source code must retain the above copyright |
| 19 |
|
|
* notice, this list of conditions and the following disclaimer. |
| 20 |
|
|
* |
| 21 |
|
|
* 3. Redistributions in binary form must reproduce the above copyright |
| 22 |
|
|
* notice, this list of conditions and the following disclaimer in the |
| 23 |
|
|
* documentation and/or other materials provided with the |
| 24 |
|
|
* distribution. |
| 25 |
|
|
* |
| 26 |
|
|
* This software is provided "AS IS," without a warranty of any |
| 27 |
|
|
* kind. All express or implied conditions, representations and |
| 28 |
|
|
* warranties, including any implied warranty of merchantability, |
| 29 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
| 30 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
| 31 |
|
|
* be liable for any damages suffered by licensee as a result of |
| 32 |
|
|
* using, modifying or distributing the software or its |
| 33 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
| 34 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
| 35 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
| 36 |
|
|
* damages, however caused and regardless of the theory of liability, |
| 37 |
|
|
* arising out of the use of or inability to use software, even if the |
| 38 |
|
|
* University of Notre Dame has been advised of the possibility of |
| 39 |
|
|
* such damages. |
| 40 |
|
|
*/ |
| 41 |
|
|
|
| 42 |
|
|
|
| 43 |
|
|
/* Creates orientational bond order parameters as outlined by |
| 44 |
|
|
* Bond-orientaional order in liquids and glasses, Steinhart,Nelson,Ronchetti |
| 45 |
|
|
* Phys Rev B, 28,784,1983 |
| 46 |
|
|
* |
| 47 |
|
|
*/ |
| 48 |
gezelter |
1039 |
|
| 49 |
chuckv |
1038 |
#include "applications/staticProps/BondOrderParameter.hpp" |
| 50 |
|
|
#include "utils/simError.h" |
| 51 |
|
|
#include "io/DumpReader.hpp" |
| 52 |
|
|
#include "primitives/Molecule.hpp" |
| 53 |
|
|
#include "utils/NumericConstant.hpp" |
| 54 |
gezelter |
1041 |
|
| 55 |
chuckv |
1038 |
namespace oopse { |
| 56 |
|
|
|
| 57 |
gezelter |
1039 |
BondOrderParameter::BondOrderParameter(SimInfo* info, |
| 58 |
|
|
const std::string& filename, |
| 59 |
|
|
const std::string& sele, |
| 60 |
gezelter |
1051 |
double rCut, int lMax, int nbins) : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info){ |
| 61 |
gezelter |
1039 |
|
| 62 |
gezelter |
1041 |
setOutputName(getPrefix(filename) + ".bo"); |
| 63 |
chuckv |
1038 |
|
| 64 |
gezelter |
1039 |
evaluator_.loadScriptString(sele); |
| 65 |
|
|
if (!evaluator_.isDynamic()) { |
| 66 |
|
|
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 67 |
chuckv |
1038 |
} |
| 68 |
|
|
|
| 69 |
gezelter |
1039 |
// Set up cutoff radius and order of the Legendre Polynomial: |
| 70 |
|
|
|
| 71 |
gezelter |
1051 |
lMax_ = lMax; |
| 72 |
chuckv |
1038 |
rCut_ = rCut; |
| 73 |
gezelter |
1051 |
nBins_ = nbins; |
| 74 |
|
|
Qcount_.resize(lMax_+1); |
| 75 |
|
|
Wcount_.resize(lMax_+1); |
| 76 |
gezelter |
1048 |
|
| 77 |
|
|
// Q can take values from 0 to 1 |
| 78 |
|
|
|
| 79 |
|
|
MinQ_ = 0.0; |
| 80 |
gezelter |
1051 |
MaxQ_ = 1.1; |
| 81 |
gezelter |
1048 |
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 |
gezelter |
1039 |
} |
| 90 |
chuckv |
1038 |
|
| 91 |
gezelter |
1041 |
BondOrderParameter::~BondOrderParameter() { |
| 92 |
gezelter |
1048 |
Q_histogram_.clear(); |
| 93 |
|
|
W_histogram_.clear(); |
| 94 |
gezelter |
1041 |
} |
| 95 |
|
|
|
| 96 |
gezelter |
1048 |
void BondOrderParameter::initalizeHistogram() { |
| 97 |
gezelter |
1051 |
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 |
gezelter |
1048 |
} |
| 104 |
|
|
|
| 105 |
gezelter |
1039 |
void BondOrderParameter::process() { |
| 106 |
|
|
Molecule* mol; |
| 107 |
|
|
Atom* atom; |
| 108 |
|
|
RigidBody* rb; |
| 109 |
gezelter |
1043 |
int myIndex; |
| 110 |
gezelter |
1039 |
SimInfo::MoleculeIterator mi; |
| 111 |
|
|
Molecule::RigidBodyIterator rbIter; |
| 112 |
|
|
Molecule::AtomIterator ai; |
| 113 |
|
|
StuntDouble* sd; |
| 114 |
gezelter |
1043 |
Vector3d vec; |
| 115 |
gezelter |
1042 |
RealType costheta; |
| 116 |
gezelter |
1039 |
RealType phi; |
| 117 |
|
|
RealType r; |
| 118 |
|
|
RealType dist; |
| 119 |
gezelter |
1051 |
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 |
gezelter |
1048 |
int nBonds, Nbonds; |
| 127 |
gezelter |
1042 |
SphericalHarmonic sphericalHarmonic; |
| 128 |
gezelter |
1039 |
int i, j; |
| 129 |
gezelter |
1043 |
// Make arrays for Wigner3jm |
| 130 |
gezelter |
1051 |
double* THRCOF = new double[2*lMax_+1]; |
| 131 |
gezelter |
1043 |
// Variables for Wigner routine |
| 132 |
gezelter |
1051 |
double lPass, m1Pass, m2Min, m2Max; |
| 133 |
|
|
int error, m1, m2, m3, mSize; |
| 134 |
|
|
mSize = 2*lMax_+1; |
| 135 |
gezelter |
1043 |
|
| 136 |
gezelter |
1039 |
DumpReader reader(info_, dumpFilename_); |
| 137 |
|
|
int nFrames = reader.getNFrames(); |
| 138 |
gezelter |
1041 |
frameCounter_ = 0; |
| 139 |
chuckv |
1038 |
|
| 140 |
gezelter |
1051 |
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 |
gezelter |
1039 |
for (int istep = 0; istep < nFrames; istep += step_) { |
| 147 |
|
|
reader.readFrame(istep); |
| 148 |
gezelter |
1041 |
frameCounter_++; |
| 149 |
gezelter |
1039 |
currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 150 |
|
|
|
| 151 |
|
|
if (evaluator_.isDynamic()) { |
| 152 |
|
|
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 153 |
|
|
} |
| 154 |
chuckv |
1038 |
|
| 155 |
gezelter |
1039 |
// update the positions of atoms which belong to the rigidbodies |
| 156 |
chuckv |
1038 |
|
| 157 |
gezelter |
1039 |
for (mol = info_->beginMolecule(mi); mol != NULL; |
| 158 |
|
|
mol = info_->nextMolecule(mi)) { |
| 159 |
|
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
| 160 |
|
|
rb = mol->nextRigidBody(rbIter)) { |
| 161 |
|
|
rb->updateAtoms(); |
| 162 |
|
|
} |
| 163 |
gezelter |
1048 |
} |
| 164 |
|
|
|
| 165 |
gezelter |
1039 |
// outer loop is over the selected StuntDoubles: |
| 166 |
chuckv |
1038 |
|
| 167 |
gezelter |
1039 |
for (sd = seleMan_.beginSelected(i); sd != NULL; |
| 168 |
|
|
sd = seleMan_.nextSelected(i)) { |
| 169 |
chuckv |
1038 |
|
| 170 |
gezelter |
1043 |
myIndex = sd->getGlobalIndex(); |
| 171 |
gezelter |
1048 |
nBonds = 0; |
| 172 |
gezelter |
1051 |
|
| 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 |
gezelter |
1048 |
} |
| 178 |
gezelter |
1039 |
|
| 179 |
|
|
// inner loop is over all other atoms in the system: |
| 180 |
|
|
|
| 181 |
|
|
for (mol = info_->beginMolecule(mi); mol != NULL; |
| 182 |
|
|
mol = info_->nextMolecule(mi)) { |
| 183 |
|
|
for (atom = mol->beginAtom(ai); atom != NULL; |
| 184 |
|
|
atom = mol->nextAtom(ai)) { |
| 185 |
chuckv |
1038 |
|
| 186 |
gezelter |
1043 |
if (atom->getGlobalIndex() != myIndex) { |
| 187 |
chuckv |
1038 |
|
| 188 |
gezelter |
1043 |
vec = sd->getPos() - atom->getPos(); |
| 189 |
|
|
currentSnapshot_->wrapVector(vec); |
| 190 |
gezelter |
1042 |
|
| 191 |
gezelter |
1043 |
// 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 |
gezelter |
1051 |
|
| 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 |
gezelter |
1043 |
} |
| 211 |
|
|
nBonds++; |
| 212 |
|
|
} |
| 213 |
|
|
} |
| 214 |
gezelter |
1039 |
} |
| 215 |
|
|
} |
| 216 |
gezelter |
1051 |
|
| 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 |
|
|
collectHistogram(q_l); |
| 227 |
|
|
|
| 228 |
gezelter |
1048 |
Nbonds += nBonds; |
| 229 |
gezelter |
1051 |
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 |
gezelter |
1048 |
} |
| 234 |
|
|
} |
| 235 |
gezelter |
1047 |
} |
| 236 |
gezelter |
1051 |
|
| 237 |
gezelter |
1047 |
// Normalize Qbar2 |
| 238 |
gezelter |
1051 |
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 |
gezelter |
1039 |
} |
| 243 |
|
|
|
| 244 |
gezelter |
1047 |
// Find second order invariant Q_l |
| 245 |
gezelter |
1039 |
|
| 246 |
gezelter |
1051 |
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 |
gezelter |
1039 |
} |
| 253 |
gezelter |
1047 |
|
| 254 |
gezelter |
1051 |
|
| 255 |
gezelter |
1047 |
|
| 256 |
|
|
// Find Third Order Invariant W_l |
| 257 |
|
|
|
| 258 |
gezelter |
1051 |
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 |
gezelter |
1047 |
} |
| 282 |
gezelter |
1041 |
|
| 283 |
gezelter |
1051 |
W_hat[l] = W[l] / pow(Q2[l], 1.5); |
| 284 |
gezelter |
1039 |
} |
| 285 |
gezelter |
1047 |
|
| 286 |
gezelter |
1051 |
writeOrderParameter(Q, W_hat); |
| 287 |
gezelter |
1047 |
} |
| 288 |
chuckv |
1038 |
|
| 289 |
gezelter |
1051 |
void BondOrderParameter::collectHistogram(std::vector<RealType> q) { |
| 290 |
chuckv |
1038 |
|
| 291 |
gezelter |
1051 |
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 |
gezelter |
1048 |
} |
| 304 |
|
|
|
| 305 |
|
|
} |
| 306 |
|
|
|
| 307 |
|
|
|
| 308 |
gezelter |
1051 |
void BondOrderParameter::writeOrderParameter(std::vector<RealType> Q, std::vector<ComplexType> What) { |
| 309 |
|
|
|
| 310 |
gezelter |
1047 |
std::ofstream os(getOutputFileName().c_str()); |
| 311 |
gezelter |
1051 |
|
| 312 |
gezelter |
1047 |
if (os.is_open()) { |
| 313 |
gezelter |
1041 |
|
| 314 |
gezelter |
1047 |
os << "# Bond Order Parameters\n"; |
| 315 |
|
|
os << "# selection: (" << selectionScript_ << ")\n"; |
| 316 |
gezelter |
1051 |
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 |
gezelter |
1048 |
// Normalize by number of frames and write it out: |
| 322 |
gezelter |
1051 |
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 |
gezelter |
1048 |
} |
| 330 |
|
|
|
| 331 |
gezelter |
1047 |
os.close(); |
| 332 |
|
|
|
| 333 |
gezelter |
1041 |
} else { |
| 334 |
|
|
sprintf(painCave.errMsg, "BondOrderParameter: unable to open %s\n", |
| 335 |
gezelter |
1047 |
getOutputFileName().c_str()); |
| 336 |
gezelter |
1041 |
painCave.isFatal = 1; |
| 337 |
|
|
simError(); |
| 338 |
|
|
} |
| 339 |
|
|
} |
| 340 |
gezelter |
1039 |
} |