| 1 |
chuckv |
769 |
/* |
| 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 |
gezelter |
1390 |
* 1. Redistributions of source code must retain the above copyright |
| 10 |
chuckv |
769 |
* notice, this list of conditions and the following disclaimer. |
| 11 |
|
|
* |
| 12 |
gezelter |
1390 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
chuckv |
769 |
* 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 |
gezelter |
1390 |
* 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 |
|
|
* [4] , Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). * |
| 41 |
chuckv |
769 |
* Created by Charles F. Vardeman II on 11/26/05. |
| 42 |
|
|
* @author Charles F. Vardeman II |
| 43 |
gezelter |
1442 |
* @version $Id$ |
| 44 |
chuckv |
769 |
* |
| 45 |
|
|
*/ |
| 46 |
|
|
|
| 47 |
|
|
/* Calculates Rho(Z) for density profile of liquid slab. */ |
| 48 |
|
|
|
| 49 |
|
|
#include <algorithm> |
| 50 |
|
|
#include <fstream> |
| 51 |
|
|
#include "applications/staticProps/RhoZ.hpp" |
| 52 |
|
|
#include "utils/simError.h" |
| 53 |
tim |
840 |
#include "io/DumpReader.hpp" |
| 54 |
|
|
#include "primitives/Molecule.hpp" |
| 55 |
gezelter |
1390 |
namespace OpenMD { |
| 56 |
chuckv |
769 |
|
| 57 |
gpuliti |
1267 |
RhoZ::RhoZ(SimInfo* info, const std::string& filename, const std::string& sele, int nzbins) |
| 58 |
|
|
: StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info), nZBins_(nzbins){ |
| 59 |
tim |
840 |
|
| 60 |
|
|
evaluator_.loadScriptString(sele); |
| 61 |
|
|
if (!evaluator_.isDynamic()) { |
| 62 |
|
|
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 63 |
gpuliti |
1267 |
} |
| 64 |
chuckv |
769 |
|
| 65 |
gpuliti |
1267 |
// fixed number of bins |
| 66 |
|
|
|
| 67 |
|
|
sliceSDLists_.resize(nZBins_); |
| 68 |
|
|
density_.resize(nZBins_); |
| 69 |
chuckv |
769 |
|
| 70 |
|
|
setOutputName(getPrefix(filename) + ".RhoZ"); |
| 71 |
|
|
} |
| 72 |
tim |
840 |
|
| 73 |
|
|
void RhoZ::process() { |
| 74 |
gpuliti |
1267 |
Molecule* mol; |
| 75 |
|
|
RigidBody* rb; |
| 76 |
|
|
StuntDouble* sd; |
| 77 |
|
|
SimInfo::MoleculeIterator mi; |
| 78 |
|
|
Molecule::RigidBodyIterator rbIter; |
| 79 |
|
|
|
| 80 |
tim |
840 |
DumpReader reader(info_, dumpFilename_); |
| 81 |
|
|
int nFrames = reader.getNFrames(); |
| 82 |
gezelter |
894 |
nProcessed_ = nFrames/step_; |
| 83 |
tim |
840 |
|
| 84 |
|
|
for (int istep = 0; istep < nFrames; istep += step_) { |
| 85 |
gpuliti |
1267 |
reader.readFrame(istep); |
| 86 |
|
|
currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 87 |
tim |
840 |
|
| 88 |
gpuliti |
1267 |
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
| 89 |
|
|
//change the positions of atoms which belong to the rigidbodies |
| 90 |
|
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
| 91 |
|
|
rb->updateAtoms(); |
| 92 |
|
|
} |
| 93 |
|
|
} |
| 94 |
|
|
|
| 95 |
gezelter |
894 |
int i; |
| 96 |
gpuliti |
1267 |
for (i=0; i < nZBins_; i++) { |
| 97 |
gezelter |
894 |
sliceSDLists_[i].clear(); |
| 98 |
|
|
} |
| 99 |
tim |
840 |
|
| 100 |
gpuliti |
1267 |
RealType sliceVolume = currentSnapshot_->getVolume() /nZBins_; |
| 101 |
|
|
Mat3x3d hmat = currentSnapshot_->getHmat(); |
| 102 |
|
|
zBox_.push_back(hmat(2,2)); |
| 103 |
gezelter |
894 |
|
| 104 |
gpuliti |
1267 |
RealType halfBoxZ_ = hmat(2,2) / 2.0; |
| 105 |
tim |
840 |
|
| 106 |
gpuliti |
1267 |
if (evaluator_.isDynamic()) { |
| 107 |
|
|
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 108 |
|
|
} |
| 109 |
|
|
|
| 110 |
|
|
//wrap the stuntdoubles into a cell |
| 111 |
|
|
for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) { |
| 112 |
|
|
Vector3d pos = sd->getPos(); |
| 113 |
|
|
if (usePeriodicBoundaryConditions_) |
| 114 |
|
|
currentSnapshot_->wrapVector(pos); |
| 115 |
|
|
sd->setPos(pos); |
| 116 |
|
|
} |
| 117 |
|
|
|
| 118 |
|
|
//determine which atom belongs to which slice |
| 119 |
|
|
for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) { |
| 120 |
|
|
Vector3d pos = sd->getPos(); |
| 121 |
|
|
// shift molecules by half a box to have bins start at 0 |
| 122 |
|
|
int binNo = int(nZBins_ * (halfBoxZ_ + pos.z()) / hmat(2,2)); |
| 123 |
|
|
sliceSDLists_[binNo].push_back(sd); |
| 124 |
|
|
} |
| 125 |
tim |
840 |
|
| 126 |
gpuliti |
1267 |
//loop over the slices to calculate the densities |
| 127 |
|
|
for (i = 0; i < nZBins_; i++) { |
| 128 |
|
|
RealType totalMass = 0; |
| 129 |
gezelter |
1782 |
for (unsigned int k = 0; k < sliceSDLists_[i].size(); ++k) { |
| 130 |
gpuliti |
1267 |
totalMass += sliceSDLists_[i][k]->getMass(); |
| 131 |
tim |
840 |
} |
| 132 |
gpuliti |
1267 |
density_[i] += totalMass/sliceVolume; |
| 133 |
|
|
} |
| 134 |
chuckv |
769 |
} |
| 135 |
gpuliti |
1267 |
|
| 136 |
tim |
840 |
writeDensity(); |
| 137 |
|
|
|
| 138 |
chuckv |
769 |
} |
| 139 |
gpuliti |
1267 |
|
| 140 |
|
|
|
| 141 |
|
|
|
| 142 |
|
|
void RhoZ::writeDensity() { |
| 143 |
tim |
840 |
|
| 144 |
gpuliti |
1267 |
// compute average box length: |
| 145 |
|
|
std::vector<RealType>::iterator j; |
| 146 |
|
|
RealType zSum = 0.0; |
| 147 |
|
|
for (j = zBox_.begin(); j != zBox_.end(); ++j) { |
| 148 |
|
|
zSum += *j; |
| 149 |
|
|
} |
| 150 |
|
|
RealType zAve = zSum / zBox_.size(); |
| 151 |
|
|
|
| 152 |
chuckv |
769 |
std::ofstream rdfStream(outputFilename_.c_str()); |
| 153 |
|
|
if (rdfStream.is_open()) { |
| 154 |
tim |
840 |
rdfStream << "#RhoZ\n"; |
| 155 |
gezelter |
894 |
rdfStream << "#nFrames:\t" << nProcessed_ << "\n"; |
| 156 |
|
|
rdfStream << "#selection: (" << selectionScript_ << ")\n"; |
| 157 |
tim |
840 |
rdfStream << "#z\tdensity\n"; |
| 158 |
gezelter |
1782 |
for (unsigned int i = 0; i < density_.size(); ++i) { |
| 159 |
gpuliti |
1267 |
RealType z = zAve * (i+0.5)/density_.size(); |
| 160 |
|
|
rdfStream << z << "\t" << 1.660535*density_[i]/nProcessed_ << "\n"; |
| 161 |
chuckv |
769 |
} |
| 162 |
|
|
|
| 163 |
|
|
} else { |
| 164 |
|
|
|
| 165 |
|
|
sprintf(painCave.errMsg, "RhoZ: unable to open %s\n", outputFilename_.c_str()); |
| 166 |
|
|
painCave.isFatal = 1; |
| 167 |
|
|
simError(); |
| 168 |
|
|
} |
| 169 |
|
|
|
| 170 |
|
|
rdfStream.close(); |
| 171 |
|
|
} |
| 172 |
|
|
|
| 173 |
|
|
} |
| 174 |
|
|
|