| 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 |
1042 |
#include "math/SphericalHarmonic.hpp" |
| 55 |
gezelter |
1041 |
|
| 56 |
chuckv |
1038 |
namespace oopse { |
| 57 |
|
|
|
| 58 |
gezelter |
1039 |
BondOrderParameter::BondOrderParameter(SimInfo* info, |
| 59 |
|
|
const std::string& filename, |
| 60 |
|
|
const std::string& sele, |
| 61 |
gezelter |
1041 |
double rCut, int lNumber, int nbins) : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info){ |
| 62 |
gezelter |
1039 |
|
| 63 |
gezelter |
1041 |
setOutputName(getPrefix(filename) + ".bo"); |
| 64 |
chuckv |
1038 |
|
| 65 |
gezelter |
1039 |
evaluator_.loadScriptString(sele); |
| 66 |
|
|
if (!evaluator_.isDynamic()) { |
| 67 |
|
|
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 68 |
chuckv |
1038 |
} |
| 69 |
|
|
|
| 70 |
gezelter |
1039 |
// Set up cutoff radius and order of the Legendre Polynomial: |
| 71 |
|
|
|
| 72 |
chuckv |
1038 |
lNumber_ = lNumber; |
| 73 |
|
|
rCut_ = rCut; |
| 74 |
gezelter |
1039 |
mSize_ = 2*lNumber_+1; |
| 75 |
|
|
} |
| 76 |
chuckv |
1038 |
|
| 77 |
gezelter |
1041 |
BondOrderParameter::~BondOrderParameter() { |
| 78 |
|
|
} |
| 79 |
|
|
|
| 80 |
gezelter |
1039 |
void BondOrderParameter::process() { |
| 81 |
|
|
Molecule* mol; |
| 82 |
|
|
Atom* atom; |
| 83 |
|
|
RigidBody* rb; |
| 84 |
gezelter |
1043 |
int myIndex; |
| 85 |
gezelter |
1039 |
SimInfo::MoleculeIterator mi; |
| 86 |
|
|
Molecule::RigidBodyIterator rbIter; |
| 87 |
|
|
Molecule::AtomIterator ai; |
| 88 |
|
|
StuntDouble* sd; |
| 89 |
gezelter |
1043 |
Vector3d vec; |
| 90 |
gezelter |
1042 |
RealType costheta; |
| 91 |
gezelter |
1039 |
RealType phi; |
| 92 |
|
|
RealType r; |
| 93 |
|
|
RealType dist; |
| 94 |
gezelter |
1046 |
std::map<int,ComplexType> QBar_lm; |
| 95 |
gezelter |
1039 |
RealType QSq_l; |
| 96 |
|
|
RealType Q_l; |
| 97 |
gezelter |
1043 |
ComplexType W_l; |
| 98 |
|
|
ComplexType W_l_hat; |
| 99 |
gezelter |
1039 |
int nBonds; |
| 100 |
gezelter |
1042 |
SphericalHarmonic sphericalHarmonic; |
| 101 |
gezelter |
1039 |
int i, j; |
| 102 |
gezelter |
1043 |
// Make arrays for Wigner3jm |
| 103 |
|
|
double* THRCOF = new double[mSize_]; |
| 104 |
|
|
// Variables for Wigner routine |
| 105 |
|
|
double l_ = (double)lNumber_; |
| 106 |
|
|
double m1Pass, m2Min, m2Max; |
| 107 |
|
|
int error, m1, m2, m3; |
| 108 |
|
|
|
| 109 |
gezelter |
1040 |
// Set the l for the spherical harmonic, it doesn't change |
| 110 |
|
|
sphericalHarmonic.setL(lNumber_); |
| 111 |
|
|
|
| 112 |
gezelter |
1039 |
DumpReader reader(info_, dumpFilename_); |
| 113 |
|
|
int nFrames = reader.getNFrames(); |
| 114 |
gezelter |
1041 |
frameCounter_ = 0; |
| 115 |
chuckv |
1038 |
|
| 116 |
gezelter |
1039 |
for (int istep = 0; istep < nFrames; istep += step_) { |
| 117 |
|
|
reader.readFrame(istep); |
| 118 |
gezelter |
1041 |
frameCounter_++; |
| 119 |
gezelter |
1039 |
currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 120 |
|
|
|
| 121 |
|
|
if (evaluator_.isDynamic()) { |
| 122 |
|
|
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 123 |
|
|
} |
| 124 |
chuckv |
1038 |
|
| 125 |
gezelter |
1039 |
// update the positions of atoms which belong to the rigidbodies |
| 126 |
chuckv |
1038 |
|
| 127 |
gezelter |
1039 |
for (mol = info_->beginMolecule(mi); mol != NULL; |
| 128 |
|
|
mol = info_->nextMolecule(mi)) { |
| 129 |
|
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
| 130 |
|
|
rb = mol->nextRigidBody(rbIter)) { |
| 131 |
|
|
rb->updateAtoms(); |
| 132 |
|
|
} |
| 133 |
|
|
} |
| 134 |
|
|
|
| 135 |
gezelter |
1047 |
nBonds = 0; |
| 136 |
|
|
|
| 137 |
|
|
for (int m = -lNumber_; m <= lNumber_; m++) { |
| 138 |
|
|
QBar_lm[m] = 0.0; |
| 139 |
|
|
} |
| 140 |
|
|
|
| 141 |
gezelter |
1039 |
// outer loop is over the selected StuntDoubles: |
| 142 |
chuckv |
1038 |
|
| 143 |
gezelter |
1039 |
for (sd = seleMan_.beginSelected(i); sd != NULL; |
| 144 |
|
|
sd = seleMan_.nextSelected(i)) { |
| 145 |
chuckv |
1038 |
|
| 146 |
gezelter |
1043 |
myIndex = sd->getGlobalIndex(); |
| 147 |
gezelter |
1039 |
|
| 148 |
|
|
// inner loop is over all other atoms in the system: |
| 149 |
|
|
|
| 150 |
|
|
for (mol = info_->beginMolecule(mi); mol != NULL; |
| 151 |
|
|
mol = info_->nextMolecule(mi)) { |
| 152 |
|
|
for (atom = mol->beginAtom(ai); atom != NULL; |
| 153 |
|
|
atom = mol->nextAtom(ai)) { |
| 154 |
chuckv |
1038 |
|
| 155 |
gezelter |
1043 |
if (atom->getGlobalIndex() != myIndex) { |
| 156 |
chuckv |
1038 |
|
| 157 |
gezelter |
1043 |
vec = sd->getPos() - atom->getPos(); |
| 158 |
|
|
currentSnapshot_->wrapVector(vec); |
| 159 |
gezelter |
1042 |
|
| 160 |
gezelter |
1043 |
// Calculate "bonds" and build Q_lm(r) where |
| 161 |
|
|
// Q_lm = Y_lm(theta(r),phi(r)) |
| 162 |
|
|
// The spherical harmonics are wrt any arbitrary coordinate |
| 163 |
|
|
// system, we choose standard spherical coordinates |
| 164 |
|
|
|
| 165 |
|
|
r = vec.length(); |
| 166 |
|
|
|
| 167 |
|
|
// Check to see if neighbor is in bond cutoff |
| 168 |
|
|
|
| 169 |
|
|
if (r < rCut_) { |
| 170 |
|
|
costheta = vec.z() / r; |
| 171 |
|
|
phi = atan2(vec.y(), vec.x()); |
| 172 |
|
|
|
| 173 |
|
|
for(int m = -lNumber_; m <= lNumber_; m++){ |
| 174 |
|
|
sphericalHarmonic.setM(m); |
| 175 |
gezelter |
1047 |
QBar_lm[m] += sphericalHarmonic.getValueAt(costheta, phi); |
| 176 |
gezelter |
1043 |
} |
| 177 |
|
|
nBonds++; |
| 178 |
|
|
} |
| 179 |
|
|
} |
| 180 |
gezelter |
1039 |
} |
| 181 |
|
|
} |
| 182 |
gezelter |
1047 |
} |
| 183 |
|
|
} |
| 184 |
chuckv |
1038 |
|
| 185 |
gezelter |
1047 |
// Normalize Qbar2 |
| 186 |
|
|
for (int m = -lNumber_;m <= lNumber_; m++){ |
| 187 |
|
|
QBar_lm[m] /= nBonds; |
| 188 |
gezelter |
1039 |
} |
| 189 |
|
|
|
| 190 |
gezelter |
1047 |
// Find second order invariant Q_l |
| 191 |
gezelter |
1039 |
|
| 192 |
gezelter |
1047 |
QSq_l = 0.0; |
| 193 |
|
|
for (int m = -lNumber_; m <= lNumber_; m++){ |
| 194 |
|
|
QSq_l += norm(QBar_lm[m]); |
| 195 |
gezelter |
1039 |
} |
| 196 |
gezelter |
1047 |
|
| 197 |
|
|
std::cout << "qsl = " << QSq_l << "\n"; |
| 198 |
|
|
Q_l = sqrt(QSq_l * 4.0 * NumericConstant::PI / (RealType)(2*lNumber_ + 1)); |
| 199 |
|
|
|
| 200 |
|
|
// Find Third Order Invariant W_l |
| 201 |
|
|
|
| 202 |
|
|
W_l = 0.0; |
| 203 |
|
|
for (int m1 = -lNumber_; m1 <= lNumber_; m1++) { |
| 204 |
|
|
// Zero work array |
| 205 |
|
|
for (int ii = 0; ii < mSize_; ii++){ |
| 206 |
|
|
THRCOF[ii] = 0.0; |
| 207 |
|
|
} |
| 208 |
|
|
// Get Wigner coefficients |
| 209 |
|
|
m1Pass = (double)m1; |
| 210 |
gezelter |
1041 |
|
| 211 |
gezelter |
1047 |
Wigner3jm(&l_, &l_, &l_, |
| 212 |
|
|
&m1Pass, &m2Min, &m2Max, |
| 213 |
|
|
THRCOF, &mSize_, &error); |
| 214 |
gezelter |
1041 |
|
| 215 |
gezelter |
1047 |
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 |
gezelter |
1041 |
} |
| 220 |
gezelter |
1039 |
} |
| 221 |
gezelter |
1047 |
|
| 222 |
|
|
W_l_hat = W_l / pow(QSq_l, 1.5); |
| 223 |
|
|
|
| 224 |
|
|
writeOrderParameter(Q_l, real(W_l_hat)); |
| 225 |
|
|
} |
| 226 |
chuckv |
1038 |
|
| 227 |
|
|
|
| 228 |
gezelter |
1047 |
void BondOrderParameter::writeOrderParameter(RealType ql, RealType Wlhat) { |
| 229 |
chuckv |
1038 |
|
| 230 |
gezelter |
1047 |
std::ofstream os(getOutputFileName().c_str()); |
| 231 |
|
|
|
| 232 |
|
|
if (os.is_open()) { |
| 233 |
gezelter |
1041 |
|
| 234 |
gezelter |
1047 |
os << "# Bond Order Parameters\n"; |
| 235 |
|
|
os << "# selection: (" << selectionScript_ << ")\n"; |
| 236 |
|
|
os << "# \n"; |
| 237 |
|
|
os << "# <Q_" << lNumber_ << ">: " << ql << "\n"; |
| 238 |
|
|
os << "# <W_" << lNumber_ << ">: " << Wlhat << "\n"; |
| 239 |
|
|
os.close(); |
| 240 |
|
|
|
| 241 |
gezelter |
1041 |
} else { |
| 242 |
|
|
sprintf(painCave.errMsg, "BondOrderParameter: unable to open %s\n", |
| 243 |
gezelter |
1047 |
getOutputFileName().c_str()); |
| 244 |
gezelter |
1041 |
painCave.isFatal = 1; |
| 245 |
|
|
simError(); |
| 246 |
|
|
} |
| 247 |
|
|
} |
| 248 |
gezelter |
1039 |
} |