| 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 |
| 9 |
> |
* 1. Redistributions of source code must retain the above copyright |
| 10 |
|
* notice, this list of conditions and the following disclaimer. |
| 11 |
|
* |
| 12 |
< |
* 3. Redistributions in binary form must reproduce the above copyright |
| 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. |
| 29 |
|
* University of Notre Dame has been advised of the possibility of |
| 30 |
|
* such damages. |
| 31 |
|
* |
| 32 |
< |
* |
| 33 |
< |
* RhoZ.cpp |
| 34 |
< |
* OOPSE-2.0 |
| 35 |
< |
* |
| 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, 234107 (2008). |
| 39 |
> |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
| 40 |
> |
* [4] , Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). * |
| 41 |
|
* Created by Charles F. Vardeman II on 11/26/05. |
| 42 |
|
* @author Charles F. Vardeman II |
| 43 |
< |
* @version $Id: RhoZ.cpp,v 1.1 2005-11-30 21:00:39 chuckv Exp $ |
| 43 |
> |
* @version $Id$ |
| 44 |
|
* |
| 45 |
|
*/ |
| 46 |
|
|
| 50 |
|
#include <fstream> |
| 51 |
|
#include "applications/staticProps/RhoZ.hpp" |
| 52 |
|
#include "utils/simError.h" |
| 53 |
< |
|
| 54 |
< |
namespace oopse { |
| 53 |
> |
#include "io/DumpReader.hpp" |
| 54 |
> |
#include "primitives/Molecule.hpp" |
| 55 |
> |
namespace OpenMD { |
| 56 |
|
|
| 57 |
< |
RhoZ::RhoZ(SimInfo* info, const std::string& filename, const std::string& sele1, const std::string& sele2, double len, int nrbins) |
| 58 |
< |
: RadialDistrFunc(info, filename, sele1, sele2), len_(len), nRBins_(nrbins){ |
| 57 |
> |
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 |
> |
|
| 60 |
> |
evaluator_.loadScriptString(sele); |
| 61 |
> |
if (!evaluator_.isDynamic()) { |
| 62 |
> |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 63 |
> |
} |
| 64 |
|
|
| 65 |
< |
deltaR_ = len_ /nRBins_; |
| 65 |
> |
// fixed number of bins |
| 66 |
> |
|
| 67 |
> |
sliceSDLists_.resize(nZBins_); |
| 68 |
> |
density_.resize(nZBins_); |
| 69 |
|
|
| 65 |
– |
histogram_.resize(nRBins_); |
| 66 |
– |
avgRhoZ_.resize(nRBins_); |
| 67 |
– |
|
| 70 |
|
setOutputName(getPrefix(filename) + ".RhoZ"); |
| 71 |
|
} |
| 72 |
< |
|
| 73 |
< |
|
| 74 |
< |
void RhoZ::preProcess() { |
| 75 |
< |
std::fill(avgRhoZ_.begin(), avgRhoZ_.end(), 0.0); |
| 76 |
< |
} |
| 77 |
< |
|
| 78 |
< |
void RhoZ::initalizeHistogram() { |
| 79 |
< |
std::fill(histogram_.begin(), histogram_.end(), 0); |
| 80 |
< |
} |
| 81 |
< |
|
| 82 |
< |
|
| 83 |
< |
void RhoZ::processHistogram() { |
| 84 |
< |
|
| 85 |
< |
int nPairs = getNPairs(); |
| 86 |
< |
double volume = info_->getSnapshotManager()->getCurrentSnapshot()->getVolume(); |
| 87 |
< |
double pairDensity = nPairs /volume * 2.0; |
| 88 |
< |
double pairConstant = ( 4.0 * NumericConstant::PI * pairDensity ) / 3.0; |
| 89 |
< |
|
| 90 |
< |
for(int i = 0 ; i < histogram_.size(); ++i){ |
| 72 |
> |
|
| 73 |
> |
void RhoZ::process() { |
| 74 |
> |
Molecule* mol; |
| 75 |
> |
RigidBody* rb; |
| 76 |
> |
StuntDouble* sd; |
| 77 |
> |
SimInfo::MoleculeIterator mi; |
| 78 |
> |
Molecule::RigidBodyIterator rbIter; |
| 79 |
> |
|
| 80 |
> |
DumpReader reader(info_, dumpFilename_); |
| 81 |
> |
int nFrames = reader.getNFrames(); |
| 82 |
> |
nProcessed_ = nFrames/step_; |
| 83 |
> |
|
| 84 |
> |
for (int istep = 0; istep < nFrames; istep += step_) { |
| 85 |
> |
reader.readFrame(istep); |
| 86 |
> |
currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 87 |
> |
|
| 88 |
> |
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 |
> |
int i; |
| 96 |
> |
for (i=0; i < nZBins_; i++) { |
| 97 |
> |
sliceSDLists_[i].clear(); |
| 98 |
> |
} |
| 99 |
> |
|
| 100 |
> |
RealType sliceVolume = currentSnapshot_->getVolume() /nZBins_; |
| 101 |
> |
Mat3x3d hmat = currentSnapshot_->getHmat(); |
| 102 |
> |
zBox_.push_back(hmat(2,2)); |
| 103 |
|
|
| 104 |
< |
double rLower = i * deltaR_; |
| 105 |
< |
double rUpper = rLower + deltaR_; |
| 106 |
< |
double volSlice = ( rUpper * rUpper * rUpper ) - ( rLower * rLower * rLower ); |
| 107 |
< |
double nIdeal = volSlice * pairConstant; |
| 104 |
> |
RealType halfBoxZ_ = hmat(2,2) / 2.0; |
| 105 |
> |
|
| 106 |
> |
if (evaluator_.isDynamic()) { |
| 107 |
> |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 108 |
> |
} |
| 109 |
|
|
| 110 |
< |
avgRhoZ_[i] += histogram_[i] / nIdeal; |
| 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 |
> |
|
| 126 |
> |
//loop over the slices to calculate the densities |
| 127 |
> |
for (i = 0; i < nZBins_; i++) { |
| 128 |
> |
RealType totalMass = 0; |
| 129 |
> |
for (unsigned int k = 0; k < sliceSDLists_[i].size(); ++k) { |
| 130 |
> |
totalMass += sliceSDLists_[i][k]->getMass(); |
| 131 |
> |
} |
| 132 |
> |
density_[i] += totalMass/sliceVolume; |
| 133 |
> |
} |
| 134 |
|
} |
| 135 |
|
|
| 136 |
+ |
writeDensity(); |
| 137 |
+ |
|
| 138 |
|
} |
| 139 |
|
|
| 100 |
– |
void RhoZ::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) { |
| 101 |
– |
|
| 102 |
– |
if (sd1 == sd2) { |
| 103 |
– |
return; |
| 104 |
– |
} |
| 105 |
– |
|
| 106 |
– |
Vector3d pos1 = sd1->getPosZ(); |
| 107 |
– |
Vector3d pos2 = sd2->getPosZ(); |
| 108 |
– |
Vector3d r12 = pos2 - pos1; |
| 109 |
– |
currentSnapshot_->wrapVector(r12); |
| 110 |
– |
|
| 111 |
– |
double distance = r12.length(); |
| 112 |
– |
|
| 113 |
– |
if (distance < len_) { |
| 114 |
– |
int whichBin = distance / deltaR_; |
| 115 |
– |
histogram_[whichBin] += 2; |
| 116 |
– |
} |
| 117 |
– |
} |
| 140 |
|
|
| 141 |
|
|
| 142 |
< |
void RhoZ::writeRdf() { |
| 142 |
> |
void RhoZ::writeDensity() { |
| 143 |
> |
|
| 144 |
> |
// 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 |
|
std::ofstream rdfStream(outputFilename_.c_str()); |
| 153 |
|
if (rdfStream.is_open()) { |
| 154 |
< |
rdfStream << "#radial distribution function\n"; |
| 155 |
< |
rdfStream << "#selection1: (" << selectionScript1_ << ")\t"; |
| 156 |
< |
rdfStream << "selection2: (" << selectionScript2_ << ")\n"; |
| 157 |
< |
rdfStream << "#r\tcorrValue\n"; |
| 158 |
< |
for (int i = 0; i < avgRhoZ_.size(); ++i) { |
| 159 |
< |
double r = deltaR_ * (i + 0.5); |
| 160 |
< |
rdfStream << r << "\t" << avgRhoZ_[i]/nProcessed_ << "\n"; |
| 154 |
> |
rdfStream << "#RhoZ\n"; |
| 155 |
> |
rdfStream << "#nFrames:\t" << nProcessed_ << "\n"; |
| 156 |
> |
rdfStream << "#selection: (" << selectionScript_ << ")\n"; |
| 157 |
> |
rdfStream << "#z\tdensity\n"; |
| 158 |
> |
for (unsigned int i = 0; i < density_.size(); ++i) { |
| 159 |
> |
RealType z = zAve * (i+0.5)/density_.size(); |
| 160 |
> |
rdfStream << z << "\t" << 1.660535*density_[i]/nProcessed_ << "\n"; |
| 161 |
|
} |
| 162 |
|
|
| 163 |
|
} else { |