| 1 |
kstocke1 |
1524 |
/* |
| 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 |
|
|
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
| 39 |
gezelter |
1782 |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
| 40 |
|
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
| 41 |
kstocke1 |
1524 |
*/ |
| 42 |
|
|
|
| 43 |
|
|
/* Calculates Angle(R) for DirectionalAtoms*/ |
| 44 |
|
|
#include <algorithm> |
| 45 |
|
|
#include <fstream> |
| 46 |
|
|
#include "applications/staticProps/AngleR.hpp" |
| 47 |
|
|
#include "utils/simError.h" |
| 48 |
|
|
#include "utils/NumericConstant.hpp" |
| 49 |
|
|
#include "io/DumpReader.hpp" |
| 50 |
|
|
#include "primitives/Molecule.hpp" |
| 51 |
gezelter |
1782 |
#include "brains/Thermo.hpp" |
| 52 |
kstocke1 |
1524 |
#include <math.h> |
| 53 |
|
|
|
| 54 |
|
|
namespace OpenMD { |
| 55 |
|
|
|
| 56 |
|
|
|
| 57 |
|
|
AngleR::AngleR(SimInfo* info, const std::string& filename, const std::string& sele, RealType len, int nrbins) |
| 58 |
|
|
: StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info), len_(len), nRBins_(nrbins){ |
| 59 |
|
|
|
| 60 |
|
|
|
| 61 |
|
|
evaluator_.loadScriptString(sele); |
| 62 |
|
|
if (!evaluator_.isDynamic()) { |
| 63 |
|
|
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 64 |
|
|
} |
| 65 |
|
|
|
| 66 |
|
|
|
| 67 |
|
|
deltaR_ = len_ /nRBins_; |
| 68 |
|
|
|
| 69 |
|
|
histogram_.resize(nRBins_); |
| 70 |
|
|
count_.resize(nRBins_); |
| 71 |
|
|
avgAngleR_.resize(nRBins_); |
| 72 |
|
|
setOutputName(getPrefix(filename) + ".AngleR"); |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
|
|
|
| 76 |
|
|
void AngleR::process() { |
| 77 |
|
|
|
| 78 |
|
|
DumpReader reader(info_, dumpFilename_); |
| 79 |
|
|
int nFrames = reader.getNFrames(); |
| 80 |
|
|
nProcessed_ = nFrames/step_; |
| 81 |
|
|
|
| 82 |
|
|
std::fill(avgAngleR_.begin(), avgAngleR_.end(), 0.0); |
| 83 |
|
|
std::fill(histogram_.begin(), histogram_.end(), 0.0); |
| 84 |
|
|
std::fill(count_.begin(), count_.end(), 0); |
| 85 |
|
|
|
| 86 |
|
|
for (int istep = 0; istep < nFrames; istep += step_) { |
| 87 |
|
|
|
| 88 |
|
|
int i; |
| 89 |
|
|
StuntDouble* sd; |
| 90 |
|
|
reader.readFrame(istep); |
| 91 |
|
|
currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 92 |
gezelter |
1782 |
Thermo thermo(info_); |
| 93 |
|
|
Vector3d CenterOfMass = thermo.getCom(); |
| 94 |
kstocke1 |
1524 |
|
| 95 |
|
|
|
| 96 |
|
|
if (evaluator_.isDynamic()) { |
| 97 |
|
|
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 98 |
|
|
} |
| 99 |
|
|
|
| 100 |
|
|
//determine which atom belongs to which slice |
| 101 |
|
|
for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) { |
| 102 |
|
|
Vector3d pos = sd->getPos(); |
| 103 |
|
|
Vector3d r1 = CenterOfMass - pos; |
| 104 |
|
|
// only do this if the stunt double actually has a vector associated |
| 105 |
|
|
// with it |
| 106 |
|
|
if (sd->isDirectional()) { |
| 107 |
|
|
Vector3d dipole = sd->getA().getColumn(2); |
| 108 |
|
|
// std::cerr << "pos = " << pos << " dipole = " << dipole << "\n"; |
| 109 |
|
|
RealType distance = r1.length(); |
| 110 |
|
|
|
| 111 |
|
|
dipole.normalize(); |
| 112 |
|
|
r1.normalize(); |
| 113 |
|
|
RealType cosangle = dot(r1, dipole); |
| 114 |
|
|
|
| 115 |
|
|
if (distance < len_) { |
| 116 |
gezelter |
1790 |
int whichBin = int(distance / deltaR_); |
| 117 |
kstocke1 |
1524 |
histogram_[whichBin] += cosangle; |
| 118 |
|
|
count_[whichBin] += 1; |
| 119 |
|
|
} |
| 120 |
|
|
} |
| 121 |
|
|
|
| 122 |
|
|
} |
| 123 |
|
|
|
| 124 |
|
|
} |
| 125 |
|
|
|
| 126 |
|
|
processHistogram(); |
| 127 |
|
|
writeAngleR(); |
| 128 |
|
|
} |
| 129 |
|
|
|
| 130 |
|
|
|
| 131 |
|
|
|
| 132 |
|
|
void AngleR::processHistogram() { |
| 133 |
|
|
|
| 134 |
gezelter |
1782 |
for(unsigned int i = 0 ; i < histogram_.size(); ++i){ |
| 135 |
kstocke1 |
1524 |
|
| 136 |
|
|
if (count_[i] > 0) |
| 137 |
|
|
avgAngleR_[i] += histogram_[i] / count_[i]; |
| 138 |
|
|
else |
| 139 |
|
|
avgAngleR_[i] = 0.0; |
| 140 |
|
|
|
| 141 |
|
|
std::cerr << " count = " << count_[i] << " avgAngle = " << avgAngleR_[i] << "\n"; |
| 142 |
|
|
} |
| 143 |
|
|
|
| 144 |
|
|
} |
| 145 |
|
|
|
| 146 |
|
|
|
| 147 |
|
|
|
| 148 |
|
|
void AngleR::writeAngleR() { |
| 149 |
|
|
std::ofstream rdfStream(outputFilename_.c_str()); |
| 150 |
|
|
if (rdfStream.is_open()) { |
| 151 |
|
|
rdfStream << "#radial density function Angle(r)\n"; |
| 152 |
|
|
rdfStream << "#r\tcorrValue\n"; |
| 153 |
gezelter |
1782 |
for (unsigned int i = 0; i < avgAngleR_.size(); ++i) { |
| 154 |
kstocke1 |
1524 |
RealType r = deltaR_ * (i + 0.5); |
| 155 |
|
|
rdfStream << r << "\t" << avgAngleR_[i] << "\n"; |
| 156 |
|
|
} |
| 157 |
|
|
|
| 158 |
|
|
} else { |
| 159 |
|
|
|
| 160 |
|
|
sprintf(painCave.errMsg, "AngleR: unable to open %s\n", outputFilename_.c_str()); |
| 161 |
|
|
painCave.isFatal = 1; |
| 162 |
|
|
simError(); |
| 163 |
|
|
} |
| 164 |
|
|
|
| 165 |
|
|
rdfStream.close(); |
| 166 |
|
|
} |
| 167 |
|
|
|
| 168 |
|
|
} |
| 169 |
|
|
|