| 44 |  | * | 
| 45 |  | *  Created by Charles F. Vardeman II on 11/26/05. | 
| 46 |  | *  @author  Charles F. Vardeman II | 
| 47 | < | *  @version $Id: RhoZ.cpp,v 1.2 2006-01-09 22:14:32 tim Exp $ | 
| 47 | > | *  @version $Id: RhoZ.cpp,v 1.7 2008-06-30 17:53:42 gpuliti Exp $ | 
| 48 |  | * | 
| 49 |  | */ | 
| 50 |  |  | 
| 58 |  | #include "primitives/Molecule.hpp" | 
| 59 |  | namespace oopse { | 
| 60 |  |  | 
| 61 | < | RhoZ::RhoZ(SimInfo* info, const std::string& filename, const std::string& sele, int len, int nrbins) | 
| 62 | < | : StaticAnalyser(info, filename), selectionScript_(sele),  evaluator_(info), seleMan_(info), len_(len), nRBins_(nrbins){ | 
| 61 | > | RhoZ::RhoZ(SimInfo* info, const std::string& filename, const std::string& sele, int nzbins) | 
| 62 | > | : StaticAnalyser(info, filename), selectionScript_(sele),  evaluator_(info), seleMan_(info), nZBins_(nzbins){ | 
| 63 |  |  | 
| 64 |  | evaluator_.loadScriptString(sele); | 
| 65 |  | if (!evaluator_.isDynamic()) { | 
| 66 |  | seleMan_.setSelectionSet(evaluator_.evaluate()); | 
| 67 | < | } | 
| 68 | < |  | 
| 67 | > | } | 
| 68 |  |  | 
| 69 | < | deltaR_ = len_ /nRBins_; | 
| 69 | > | // fixed number of bins | 
| 70 | > |  | 
| 71 | > | sliceSDLists_.resize(nZBins_); | 
| 72 | > | density_.resize(nZBins_); | 
| 73 |  |  | 
| 72 | – | sliceSDLists_.resize(nRBins_); | 
| 73 | – | density_.resize(nRBins_); | 
| 74 | – |  | 
| 74 |  | setOutputName(getPrefix(filename) + ".RhoZ"); | 
| 75 |  | } | 
| 76 |  |  | 
| 77 |  | void RhoZ::process() { | 
| 78 | + | Molecule* mol; | 
| 79 | + | RigidBody* rb; | 
| 80 | + | StuntDouble* sd; | 
| 81 | + | SimInfo::MoleculeIterator mi; | 
| 82 | + | Molecule::RigidBodyIterator rbIter; | 
| 83 | + |  | 
| 84 |  | DumpReader reader(info_, dumpFilename_); | 
| 85 |  | int nFrames = reader.getNFrames(); | 
| 86 | < | nProcessed_ = nFrames / step_; | 
| 86 | > | nProcessed_ = nFrames/step_; | 
| 87 |  |  | 
| 83 | – |  | 
| 88 |  | for (int istep = 0; istep < nFrames; istep += step_) { | 
| 89 | + | reader.readFrame(istep); | 
| 90 | + | currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); | 
| 91 |  |  | 
| 92 | < | StuntDouble* sd; | 
| 93 | < | int i; | 
| 94 | < | reader.readFrame(istep); | 
| 95 | < | currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); | 
| 90 | < |  | 
| 91 | < | double sliceVolume = currentSnapshot_->getVolume() /nRBins_; | 
| 92 | < | //assume simulation box will never change | 
| 93 | < | //Mat3x3d hmat = currentSnapshot_->getHmat(); | 
| 94 | < | double halfBoxZ = len_ /2; | 
| 95 | < |  | 
| 96 | < | if (evaluator_.isDynamic()) { | 
| 97 | < | seleMan_.setSelectionSet(evaluator_.evaluate()); | 
| 92 | > | for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 93 | > | //change the positions of atoms which belong to the rigidbodies | 
| 94 | > | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 95 | > | rb->updateAtoms(); | 
| 96 |  | } | 
| 97 | + | } | 
| 98 |  |  | 
| 99 | < | //wrap the stuntdoubles into a cell | 
| 100 | < | for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) { | 
| 101 | < | Vector3d pos = sd->getPos(); | 
| 102 | < | currentSnapshot_->wrapVector(pos); | 
| 104 | < | sd->setPos(pos); | 
| 105 | < | } | 
| 99 | > | int i; | 
| 100 | > | for (i=0; i < nZBins_; i++) { | 
| 101 | > | sliceSDLists_[i].clear(); | 
| 102 | > | } | 
| 103 |  |  | 
| 104 | < | //determine which atom belong to which slice | 
| 105 | < | for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) { | 
| 106 | < | Vector3d pos = sd->getPos(); | 
| 107 | < | int binNo = (pos.z() + halfBoxZ) /deltaR_; | 
| 108 | < | sliceSDLists_[binNo].push_back(sd); | 
| 112 | < | } | 
| 104 | > | RealType sliceVolume = currentSnapshot_->getVolume() /nZBins_; | 
| 105 | > | Mat3x3d hmat = currentSnapshot_->getHmat(); | 
| 106 | > | zBox_.push_back(hmat(2,2)); | 
| 107 | > |  | 
| 108 | > | RealType halfBoxZ_ = hmat(2,2) / 2.0; | 
| 109 |  |  | 
| 110 | < | //loop over the slices to calculate the densities | 
| 111 | < | for (std::size_t j = 0; j < sliceSDLists_.size(); ++j) { | 
| 112 | < | double totalMass = 0; | 
| 113 | < | for (int k = 0; k < sliceSDLists_[j].size(); ++k) { | 
| 114 | < | totalMass += sliceSDLists_[j][k]->getMass(); | 
| 115 | < | } | 
| 116 | < | density_[j] += totalMass/sliceVolume; | 
| 110 | > | if (evaluator_.isDynamic()) { | 
| 111 | > | seleMan_.setSelectionSet(evaluator_.evaluate()); | 
| 112 | > | } | 
| 113 | > |  | 
| 114 | > | //wrap the stuntdoubles into a cell | 
| 115 | > | for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) { | 
| 116 | > | Vector3d pos = sd->getPos(); | 
| 117 | > | if (usePeriodicBoundaryConditions_) | 
| 118 | > | currentSnapshot_->wrapVector(pos); | 
| 119 | > | sd->setPos(pos); | 
| 120 | > | } | 
| 121 | > |  | 
| 122 | > | //determine which atom belongs to which slice | 
| 123 | > | for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) { | 
| 124 | > | Vector3d pos = sd->getPos(); | 
| 125 | > | // shift molecules by half a box to have bins start at 0 | 
| 126 | > | int binNo = int(nZBins_ * (halfBoxZ_ + pos.z()) / hmat(2,2)); | 
| 127 | > | sliceSDLists_[binNo].push_back(sd); | 
| 128 | > | } | 
| 129 | > |  | 
| 130 | > | //loop over the slices to calculate the densities | 
| 131 | > | for (i = 0; i < nZBins_; i++) { | 
| 132 | > | RealType totalMass = 0; | 
| 133 | > | for (int k = 0; k < sliceSDLists_[i].size(); ++k) { | 
| 134 | > | totalMass += sliceSDLists_[i][k]->getMass(); | 
| 135 |  | } | 
| 136 | + | density_[i] += totalMass/sliceVolume; | 
| 137 | + | } | 
| 138 |  | } | 
| 123 | – |  | 
| 139 |  |  | 
| 140 |  | writeDensity(); | 
| 141 |  |  | 
| 142 |  | } | 
| 143 | < |  | 
| 144 | < |  | 
| 145 | < |  | 
| 143 | > |  | 
| 144 | > |  | 
| 145 | > |  | 
| 146 |  | void RhoZ::writeDensity() { | 
| 147 | + |  | 
| 148 | + | // compute average box length: | 
| 149 | + | std::vector<RealType>::iterator j; | 
| 150 | + | RealType zSum = 0.0; | 
| 151 | + | for (j = zBox_.begin(); j != zBox_.end(); ++j) { | 
| 152 | + | zSum += *j; | 
| 153 | + | } | 
| 154 | + | RealType zAve = zSum / zBox_.size(); | 
| 155 | + |  | 
| 156 |  | std::ofstream rdfStream(outputFilename_.c_str()); | 
| 157 |  | if (rdfStream.is_open()) { | 
| 158 |  | rdfStream << "#RhoZ\n"; | 
| 159 | < | rdfStream << "#selection: (" << selectionScript_ << ")\t"; | 
| 159 | > | rdfStream << "#nFrames:\t" << nProcessed_ << "\n"; | 
| 160 | > | rdfStream << "#selection: (" << selectionScript_ << ")\n"; | 
| 161 |  | rdfStream << "#z\tdensity\n"; | 
| 162 |  | for (int i = 0; i < density_.size(); ++i) { | 
| 163 | < | double r = deltaR_ * (i + 0.5); | 
| 164 | < | rdfStream << r << "\t" << density_[i]/nProcessed_ << "\n"; | 
| 163 | > | RealType z = zAve * (i+0.5)/density_.size(); | 
| 164 | > | rdfStream << z << "\t" << 1.660535*density_[i]/nProcessed_ << "\n"; | 
| 165 |  | } | 
| 166 |  |  | 
| 167 |  | } else { |