| 1 | /* | 
| 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 |  | 
| 49 | #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 | #include "math/SphericalHarmonic.hpp" | 
| 55 |  | 
| 56 | namespace oopse { | 
| 57 |  | 
| 58 | BondOrderParameter::BondOrderParameter(SimInfo* info, | 
| 59 | const std::string& filename, | 
| 60 | const std::string& sele, | 
| 61 | double rCut, int lNumber, int nbins) : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info){ | 
| 62 |  | 
| 63 | setOutputName(getPrefix(filename) + ".bo"); | 
| 64 |  | 
| 65 | evaluator_.loadScriptString(sele); | 
| 66 | if (!evaluator_.isDynamic()) { | 
| 67 | seleMan_.setSelectionSet(evaluator_.evaluate()); | 
| 68 | } | 
| 69 |  | 
| 70 | // Set up cutoff radius and order of the Legendre Polynomial: | 
| 71 |  | 
| 72 | lNumber_ = lNumber; | 
| 73 | rCut_ = rCut; | 
| 74 | mSize_ = 2*lNumber_+1; | 
| 75 | } | 
| 76 |  | 
| 77 | BondOrderParameter::~BondOrderParameter() { | 
| 78 | } | 
| 79 |  | 
| 80 | void BondOrderParameter::process() { | 
| 81 | Molecule* mol; | 
| 82 | Atom* atom; | 
| 83 | RigidBody* rb; | 
| 84 | int myIndex; | 
| 85 | SimInfo::MoleculeIterator mi; | 
| 86 | Molecule::RigidBodyIterator rbIter; | 
| 87 | Molecule::AtomIterator ai; | 
| 88 | StuntDouble* sd; | 
| 89 | Vector3d vec; | 
| 90 | RealType costheta; | 
| 91 | RealType phi; | 
| 92 | RealType r; | 
| 93 | RealType dist; | 
| 94 | std::map<int,ComplexType> QBar_lm; | 
| 95 | RealType QSq_l; | 
| 96 | RealType Q_l; | 
| 97 | ComplexType W_l; | 
| 98 | ComplexType W_l_hat; | 
| 99 | int nBonds; | 
| 100 | SphericalHarmonic sphericalHarmonic; | 
| 101 | int i, j; | 
| 102 | // 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 | // Set the l for the spherical harmonic, it doesn't change | 
| 110 | sphericalHarmonic.setL(lNumber_); | 
| 111 |  | 
| 112 | DumpReader reader(info_, dumpFilename_); | 
| 113 | int nFrames = reader.getNFrames(); | 
| 114 | frameCounter_ = 0; | 
| 115 |  | 
| 116 | for (int istep = 0; istep < nFrames; istep += step_) { | 
| 117 | reader.readFrame(istep); | 
| 118 | frameCounter_++; | 
| 119 | currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); | 
| 120 |  | 
| 121 | if (evaluator_.isDynamic()) { | 
| 122 | seleMan_.setSelectionSet(evaluator_.evaluate()); | 
| 123 | } | 
| 124 |  | 
| 125 | // update the positions of atoms which belong to the rigidbodies | 
| 126 |  | 
| 127 | 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 | nBonds = 0; | 
| 136 |  | 
| 137 | for (int m = -lNumber_; m <= lNumber_; m++) { | 
| 138 | QBar_lm[m] = 0.0; | 
| 139 | } | 
| 140 |  | 
| 141 | // outer loop is over the selected StuntDoubles: | 
| 142 |  | 
| 143 | for (sd = seleMan_.beginSelected(i); sd != NULL; | 
| 144 | sd = seleMan_.nextSelected(i)) { | 
| 145 |  | 
| 146 | myIndex = sd->getGlobalIndex(); | 
| 147 |  | 
| 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 |  | 
| 155 | if (atom->getGlobalIndex() != myIndex) { | 
| 156 |  | 
| 157 | vec = sd->getPos() - atom->getPos(); | 
| 158 | currentSnapshot_->wrapVector(vec); | 
| 159 |  | 
| 160 | // 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 | QBar_lm[m] += sphericalHarmonic.getValueAt(costheta, phi); | 
| 176 | } | 
| 177 | nBonds++; | 
| 178 | } | 
| 179 | } | 
| 180 | } | 
| 181 | } | 
| 182 | } | 
| 183 | } | 
| 184 |  | 
| 185 | // Normalize Qbar2 | 
| 186 | for (int m = -lNumber_;m <= lNumber_; m++){ | 
| 187 | QBar_lm[m] /= nBonds; | 
| 188 | } | 
| 189 |  | 
| 190 | // Find second order invariant Q_l | 
| 191 |  | 
| 192 | QSq_l = 0.0; | 
| 193 | for (int m = -lNumber_; m <= lNumber_; m++){ | 
| 194 | QSq_l += norm(QBar_lm[m]); | 
| 195 | } | 
| 196 |  | 
| 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 |  | 
| 211 | 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 | } | 
| 220 | } | 
| 221 |  | 
| 222 | W_l_hat = W_l / pow(QSq_l, 1.5); | 
| 223 |  | 
| 224 | writeOrderParameter(Q_l, real(W_l_hat)); | 
| 225 | } | 
| 226 |  | 
| 227 |  | 
| 228 | void BondOrderParameter::writeOrderParameter(RealType ql, RealType Wlhat) { | 
| 229 |  | 
| 230 | std::ofstream os(getOutputFileName().c_str()); | 
| 231 |  | 
| 232 | if (os.is_open()) { | 
| 233 |  | 
| 234 | 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 | } else { | 
| 242 | sprintf(painCave.errMsg, "BondOrderParameter: unable to open %s\n", | 
| 243 | getOutputFileName().c_str()); | 
| 244 | painCave.isFatal = 1; | 
| 245 | simError(); | 
| 246 | } | 
| 247 | } | 
| 248 | } |