| 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, 24107 (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.4 2006-03-07 16:43:52 gezelter Exp $ |
| 43 |
> |
* @version $Id$ |
| 44 |
|
* |
| 45 |
|
*/ |
| 46 |
|
|
| 52 |
|
#include "utils/simError.h" |
| 53 |
|
#include "io/DumpReader.hpp" |
| 54 |
|
#include "primitives/Molecule.hpp" |
| 55 |
< |
namespace oopse { |
| 55 |
> |
namespace OpenMD { |
| 56 |
|
|
| 57 |
< |
RhoZ::RhoZ(SimInfo* info, const std::string& filename, const std::string& sele, double len, int nrbins) |
| 58 |
< |
: StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info), 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 |
< |
} |
| 68 |
< |
|
| 63 |
> |
} |
| 64 |
|
|
| 65 |
< |
deltaR_ = len_ /(nRBins_); |
| 65 |
> |
// fixed number of bins |
| 66 |
> |
|
| 67 |
> |
sliceSDLists_.resize(nZBins_); |
| 68 |
> |
density_.resize(nZBins_); |
| 69 |
|
|
| 72 |
– |
sliceSDLists_.resize(nRBins_); |
| 73 |
– |
density_.resize(nRBins_); |
| 74 |
– |
|
| 70 |
|
setOutputName(getPrefix(filename) + ".RhoZ"); |
| 71 |
|
} |
| 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 < nRBins_; i++) { |
| 96 |
> |
for (i=0; i < nZBins_; i++) { |
| 97 |
|
sliceSDLists_[i].clear(); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
< |
StuntDouble* sd; |
| 101 |
< |
reader.readFrame(istep); |
| 102 |
< |
currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
| 100 |
> |
RealType sliceVolume = currentSnapshot_->getVolume() /nZBins_; |
| 101 |
> |
Mat3x3d hmat = currentSnapshot_->getHmat(); |
| 102 |
> |
zBox_.push_back(hmat(2,2)); |
| 103 |
|
|
| 104 |
< |
double sliceVolume = currentSnapshot_->getVolume() /nRBins_; |
| 95 |
< |
//assume simulation box will never change |
| 96 |
< |
//Mat3x3d hmat = currentSnapshot_->getHmat(); |
| 97 |
< |
double halfBoxZ_ = len_ / 2.0; |
| 98 |
< |
|
| 99 |
< |
if (evaluator_.isDynamic()) { |
| 100 |
< |
seleMan_.setSelectionSet(evaluator_.evaluate()); |
| 101 |
< |
} |
| 104 |
> |
RealType halfBoxZ_ = hmat(2,2) / 2.0; |
| 105 |
|
|
| 106 |
< |
//wrap the stuntdoubles into a cell |
| 107 |
< |
for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) { |
| 108 |
< |
Vector3d pos = sd->getPos(); |
| 109 |
< |
currentSnapshot_->wrapVector(pos); |
| 110 |
< |
sd->setPos(pos); |
| 111 |
< |
} |
| 106 |
> |
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 |
|
|
| 126 |
< |
//determine which atom belongs to which slice |
| 127 |
< |
for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) { |
| 128 |
< |
Vector3d pos = sd->getPos(); |
| 129 |
< |
//int binNo = (pos.z() /deltaR_) - 1; |
| 130 |
< |
int binNo = (pos.z() + halfBoxZ_) /deltaR_ ; |
| 115 |
< |
//std::cout << "pos.z = " << pos.z() << " halfBoxZ_ = " << halfBoxZ_ << " deltaR_ = " << deltaR_ << " binNo = " << binNo << "\n"; |
| 116 |
< |
sliceSDLists_[binNo].push_back(sd); |
| 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 |
< |
|
| 133 |
< |
//loop over the slices to calculate the densities |
| 120 |
< |
for (i = 0; i < nRBins_; i++) { |
| 121 |
< |
double totalMass = 0; |
| 122 |
< |
for (int k = 0; k < sliceSDLists_[i].size(); ++k) { |
| 123 |
< |
totalMass += sliceSDLists_[i][k]->getMass(); |
| 124 |
< |
} |
| 125 |
< |
density_[i] += totalMass/sliceVolume; |
| 126 |
< |
} |
| 132 |
> |
density_[i] += totalMass/sliceVolume; |
| 133 |
> |
} |
| 134 |
|
} |
| 135 |
< |
|
| 135 |
> |
|
| 136 |
|
writeDensity(); |
| 137 |
|
|
| 138 |
|
} |
| 139 |
< |
|
| 140 |
< |
|
| 141 |
< |
|
| 139 |
> |
|
| 140 |
> |
|
| 141 |
> |
|
| 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 << "#RhoZ\n"; |
| 155 |
|
rdfStream << "#nFrames:\t" << nProcessed_ << "\n"; |
| 156 |
|
rdfStream << "#selection: (" << selectionScript_ << ")\n"; |
| 157 |
|
rdfStream << "#z\tdensity\n"; |
| 158 |
< |
for (int i = 0; i < density_.size(); ++i) { |
| 159 |
< |
double r = deltaR_ * (i + 0.5); |
| 160 |
< |
rdfStream << r << "\t" << 1.660535*density_[i]/nProcessed_ << "\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 { |