| 1 | gezelter | 1413 | /* | 
| 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. Redistributions of source code must retain the above copyright | 
| 10 |  |  | *    notice, this list of conditions and the following disclaimer. | 
| 11 |  |  | * | 
| 12 |  |  | * 2. Redistributions in binary form must reproduce the above copyright | 
| 13 |  |  | *    notice, this list of conditions and the following disclaimer in the | 
| 14 |  |  | *    documentation and/or other materials provided with the | 
| 15 |  |  | *    distribution. | 
| 16 |  |  | * | 
| 17 |  |  | * This software is provided "AS IS," without a warranty of any | 
| 18 |  |  | * kind. All express or implied conditions, representations and | 
| 19 |  |  | * warranties, including any implied warranty of merchantability, | 
| 20 |  |  | * fitness for a particular purpose or non-infringement, are hereby | 
| 21 |  |  | * excluded.  The University of Notre Dame and its licensors shall not | 
| 22 |  |  | * be liable for any damages suffered by licensee as a result of | 
| 23 |  |  | * using, modifying or distributing the software or its | 
| 24 |  |  | * derivatives. In no event will the University of Notre Dame or its | 
| 25 |  |  | * licensors be liable for any lost revenue, profit or data, or for | 
| 26 |  |  | * direct, indirect, special, consequential, incidental or punitive | 
| 27 |  |  | * damages, however caused and regardless of the theory of liability, | 
| 28 |  |  | * arising out of the use of or inability to use software, even if the | 
| 29 |  |  | * University of Notre Dame has been advised of the possibility of | 
| 30 |  |  | * such damages. | 
| 31 |  |  | * | 
| 32 |  |  | * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your | 
| 33 |  |  | * research, please cite the appropriate papers when you publish your | 
| 34 |  |  | * work.  Good starting points are: | 
| 35 |  |  | * | 
| 36 |  |  | * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). | 
| 37 |  |  | * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). | 
| 38 | gezelter | 1879 | * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). | 
| 39 | gezelter | 1782 | * [4] Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 40 |  |  | * [4] , Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). * | 
| 41 | gezelter | 1413 | */ | 
| 42 |  |  |  | 
| 43 |  |  | /* Calculates Rho(theta) */ | 
| 44 |  |  |  | 
| 45 |  |  | #include <algorithm> | 
| 46 | gezelter | 1782 | #include <fstream> | 
| 47 | gezelter | 1413 | #include "applications/staticProps/pAngle.hpp" | 
| 48 |  |  | #include "utils/simError.h" | 
| 49 |  |  | #include "io/DumpReader.hpp" | 
| 50 |  |  | #include "primitives/Molecule.hpp" | 
| 51 | gezelter | 1782 | #include "brains/Thermo.hpp" | 
| 52 |  |  |  | 
| 53 | gezelter | 1413 | namespace OpenMD { | 
| 54 |  |  |  | 
| 55 |  |  | pAngle::pAngle(SimInfo* info, const std::string& filename, | 
| 56 |  |  | const std::string& sele, int nthetabins) | 
| 57 |  |  | : StaticAnalyser(info, filename), selectionScript_(sele), | 
| 58 |  |  | evaluator_(info), seleMan_(info), nThetaBins_(nthetabins){ | 
| 59 |  |  |  | 
| 60 |  |  | evaluator_.loadScriptString(sele); | 
| 61 |  |  | if (!evaluator_.isDynamic()) { | 
| 62 |  |  | seleMan_.setSelectionSet(evaluator_.evaluate()); | 
| 63 |  |  | } | 
| 64 |  |  |  | 
| 65 |  |  | count_.resize(nThetaBins_); | 
| 66 |  |  | histogram_.resize(nThetaBins_); | 
| 67 |  |  |  | 
| 68 |  |  | setOutputName(getPrefix(filename) + ".pAngle"); | 
| 69 |  |  | } | 
| 70 |  |  |  | 
| 71 |  |  | void pAngle::process() { | 
| 72 |  |  | Molecule* mol; | 
| 73 |  |  | RigidBody* rb; | 
| 74 |  |  | StuntDouble* sd; | 
| 75 |  |  | SimInfo::MoleculeIterator mi; | 
| 76 |  |  | Molecule::RigidBodyIterator rbIter; | 
| 77 |  |  | int i; | 
| 78 |  |  |  | 
| 79 | gezelter | 1782 | Thermo thermo(info_); | 
| 80 | gezelter | 1413 | DumpReader reader(info_, dumpFilename_); | 
| 81 |  |  | int nFrames = reader.getNFrames(); | 
| 82 |  |  | nProcessed_ = nFrames/step_; | 
| 83 |  |  |  | 
| 84 |  |  | std::fill(histogram_.begin(), histogram_.end(), 0.0); | 
| 85 |  |  | std::fill(count_.begin(), count_.end(), 0); | 
| 86 |  |  |  | 
| 87 |  |  | for (int istep = 0; istep < nFrames; istep += step_) { | 
| 88 |  |  | reader.readFrame(istep); | 
| 89 |  |  | currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); | 
| 90 |  |  |  | 
| 91 |  |  | for (mol = info_->beginMolecule(mi); mol != NULL; | 
| 92 |  |  | mol = info_->nextMolecule(mi)) { | 
| 93 |  |  | //change the positions of atoms which belong to the rigidbodies | 
| 94 |  |  | for (rb = mol->beginRigidBody(rbIter); rb != NULL; | 
| 95 |  |  | rb = mol->nextRigidBody(rbIter)) { | 
| 96 |  |  | rb->updateAtoms(); | 
| 97 |  |  | } | 
| 98 |  |  | } | 
| 99 |  |  |  | 
| 100 | gezelter | 1782 | Vector3d CenterOfMass = thermo.getCom(); | 
| 101 | gezelter | 1413 |  | 
| 102 |  |  | if  (evaluator_.isDynamic()) { | 
| 103 |  |  | seleMan_.setSelectionSet(evaluator_.evaluate()); | 
| 104 |  |  | } | 
| 105 |  |  |  | 
| 106 |  |  | for (sd = seleMan_.beginSelected(i); sd != NULL; | 
| 107 |  |  | sd = seleMan_.nextSelected(i)) { | 
| 108 | gezelter | 1782 |  | 
| 109 | gezelter | 1413 | Vector3d pos = sd->getPos(); | 
| 110 |  |  |  | 
| 111 |  |  | Vector3d r1 = CenterOfMass - pos; | 
| 112 |  |  | // only do this if the stunt double actually has a vector associated | 
| 113 |  |  | // with it | 
| 114 |  |  | if (sd->isDirectional()) { | 
| 115 |  |  | Vector3d dipole = sd->getA().getColumn(2); | 
| 116 |  |  | RealType distance = r1.length(); | 
| 117 |  |  |  | 
| 118 |  |  | dipole.normalize(); | 
| 119 |  |  | r1.normalize(); | 
| 120 |  |  | RealType cosangle = dot(r1, dipole); | 
| 121 |  |  |  | 
| 122 |  |  | int binNo = int(nThetaBins_ * (1.0 + cosangle) / 2.0); | 
| 123 |  |  | count_[binNo]++; | 
| 124 |  |  | } | 
| 125 |  |  |  | 
| 126 |  |  | } | 
| 127 |  |  | } | 
| 128 |  |  | processHistogram(); | 
| 129 |  |  | writeProbs(); | 
| 130 |  |  |  | 
| 131 |  |  | } | 
| 132 |  |  |  | 
| 133 |  |  | void pAngle::processHistogram() { | 
| 134 |  |  |  | 
| 135 |  |  | int atot = 0; | 
| 136 | gezelter | 1782 | for(unsigned int i = 0; i < count_.size(); ++i) | 
| 137 | gezelter | 1413 | atot += count_[i]; | 
| 138 |  |  |  | 
| 139 | gezelter | 1782 | for(unsigned int i = 0; i < count_.size(); ++i) { | 
| 140 |  |  | histogram_[i] = double(count_[i] / double(atot)); | 
| 141 | gezelter | 1413 | } | 
| 142 |  |  | } | 
| 143 |  |  |  | 
| 144 |  |  |  | 
| 145 |  |  | void pAngle::writeProbs() { | 
| 146 |  |  |  | 
| 147 |  |  | std::ofstream rdfStream(outputFilename_.c_str()); | 
| 148 |  |  | if (rdfStream.is_open()) { | 
| 149 |  |  | rdfStream << "#pAngle\n"; | 
| 150 |  |  | rdfStream << "#nFrames:\t" << nProcessed_ << "\n"; | 
| 151 |  |  | rdfStream << "#selection: (" << selectionScript_ << ")\n"; | 
| 152 |  |  | rdfStream << "#cos(theta)\tp(cos(theta))\n"; | 
| 153 | kstocke1 | 1522 | RealType dct = 2.0 / histogram_.size(); | 
| 154 | gezelter | 1782 | for (unsigned int i = 0; i < histogram_.size(); ++i) { | 
| 155 | kstocke1 | 1522 | RealType ct = -1.0 + (2.0 * i + 1) / (histogram_.size()); | 
| 156 |  |  | rdfStream << ct << "\t" << histogram_[i]/dct << "\n"; | 
| 157 | gezelter | 1413 | } | 
| 158 |  |  |  | 
| 159 |  |  | } else { | 
| 160 |  |  |  | 
| 161 |  |  | sprintf(painCave.errMsg, "pAngle: unable to open %s\n", outputFilename_.c_str()); | 
| 162 |  |  | painCave.isFatal = 1; | 
| 163 |  |  | simError(); | 
| 164 |  |  | } | 
| 165 |  |  |  | 
| 166 |  |  | rdfStream.close(); | 
| 167 |  |  | } | 
| 168 |  |  |  | 
| 169 |  |  | } | 
| 170 |  |  |  |