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 |
|
|
* 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 |
19 |
|
|
* notice, this list of conditions and the following disclaimer. |
20 |
|
|
* |
21 |
|
|
* 3. Redistributions in binary form must reproduce the above copyright |
22 |
|
|
* notice, this list of conditions and the following disclaimer in the |
23 |
|
|
* documentation and/or other materials provided with the |
24 |
|
|
* distribution. |
25 |
|
|
* |
26 |
|
|
* This software is provided "AS IS," without a warranty of any |
27 |
|
|
* kind. All express or implied conditions, representations and |
28 |
|
|
* warranties, including any implied warranty of merchantability, |
29 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
30 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
31 |
|
|
* be liable for any damages suffered by licensee as a result of |
32 |
|
|
* using, modifying or distributing the software or its |
33 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
34 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
35 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
36 |
|
|
* damages, however caused and regardless of the theory of liability, |
37 |
|
|
* arising out of the use of or inability to use software, even if the |
38 |
|
|
* University of Notre Dame has been advised of the possibility of |
39 |
|
|
* such damages. |
40 |
|
|
* |
41 |
|
|
* |
42 |
|
|
* RhoZ.cpp |
43 |
|
|
* OOPSE-2.0 |
44 |
|
|
* |
45 |
|
|
* Created by Charles F. Vardeman II on 11/26/05. |
46 |
|
|
* @author Charles F. Vardeman II |
47 |
tim |
840 |
* @version $Id: RhoZ.cpp,v 1.2 2006-01-09 22:14:32 tim Exp $ |
48 |
chuckv |
769 |
* |
49 |
|
|
*/ |
50 |
|
|
|
51 |
|
|
/* Calculates Rho(Z) for density profile of liquid slab. */ |
52 |
|
|
|
53 |
|
|
#include <algorithm> |
54 |
|
|
#include <fstream> |
55 |
|
|
#include "applications/staticProps/RhoZ.hpp" |
56 |
|
|
#include "utils/simError.h" |
57 |
tim |
840 |
#include "io/DumpReader.hpp" |
58 |
|
|
#include "primitives/Molecule.hpp" |
59 |
chuckv |
769 |
namespace oopse { |
60 |
|
|
|
61 |
tim |
840 |
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){ |
63 |
|
|
|
64 |
|
|
evaluator_.loadScriptString(sele); |
65 |
|
|
if (!evaluator_.isDynamic()) { |
66 |
|
|
seleMan_.setSelectionSet(evaluator_.evaluate()); |
67 |
|
|
} |
68 |
|
|
|
69 |
chuckv |
769 |
|
70 |
|
|
deltaR_ = len_ /nRBins_; |
71 |
|
|
|
72 |
tim |
840 |
sliceSDLists_.resize(nRBins_); |
73 |
|
|
density_.resize(nRBins_); |
74 |
chuckv |
769 |
|
75 |
|
|
setOutputName(getPrefix(filename) + ".RhoZ"); |
76 |
|
|
} |
77 |
tim |
840 |
|
78 |
|
|
void RhoZ::process() { |
79 |
|
|
DumpReader reader(info_, dumpFilename_); |
80 |
|
|
int nFrames = reader.getNFrames(); |
81 |
|
|
nProcessed_ = nFrames / step_; |
82 |
|
|
|
83 |
|
|
|
84 |
|
|
for (int istep = 0; istep < nFrames; istep += step_) { |
85 |
|
|
|
86 |
|
|
StuntDouble* sd; |
87 |
|
|
int i; |
88 |
|
|
reader.readFrame(istep); |
89 |
|
|
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()); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
//wrap the stuntdoubles into a cell |
101 |
|
|
for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) { |
102 |
|
|
Vector3d pos = sd->getPos(); |
103 |
|
|
currentSnapshot_->wrapVector(pos); |
104 |
|
|
sd->setPos(pos); |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
//determine which atom belong to which slice |
108 |
|
|
for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) { |
109 |
|
|
Vector3d pos = sd->getPos(); |
110 |
|
|
int binNo = (pos.z() + halfBoxZ) /deltaR_; |
111 |
|
|
sliceSDLists_[binNo].push_back(sd); |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
//loop over the slices to calculate the densities |
115 |
|
|
for (std::size_t j = 0; j < sliceSDLists_.size(); ++j) { |
116 |
|
|
double totalMass = 0; |
117 |
|
|
for (int k = 0; k < sliceSDLists_[j].size(); ++k) { |
118 |
|
|
totalMass += sliceSDLists_[j][k]->getMass(); |
119 |
|
|
} |
120 |
|
|
density_[j] += totalMass/sliceVolume; |
121 |
|
|
} |
122 |
chuckv |
769 |
} |
123 |
tim |
840 |
|
124 |
chuckv |
769 |
|
125 |
tim |
840 |
writeDensity(); |
126 |
|
|
|
127 |
chuckv |
769 |
} |
128 |
tim |
840 |
|
129 |
|
|
|
130 |
chuckv |
769 |
|
131 |
tim |
840 |
void RhoZ::writeDensity() { |
132 |
chuckv |
769 |
std::ofstream rdfStream(outputFilename_.c_str()); |
133 |
|
|
if (rdfStream.is_open()) { |
134 |
tim |
840 |
rdfStream << "#RhoZ\n"; |
135 |
|
|
rdfStream << "#selection: (" << selectionScript_ << ")\t"; |
136 |
|
|
rdfStream << "#z\tdensity\n"; |
137 |
|
|
for (int i = 0; i < density_.size(); ++i) { |
138 |
chuckv |
769 |
double r = deltaR_ * (i + 0.5); |
139 |
tim |
840 |
rdfStream << r << "\t" << density_[i]/nProcessed_ << "\n"; |
140 |
chuckv |
769 |
} |
141 |
|
|
|
142 |
|
|
} else { |
143 |
|
|
|
144 |
|
|
sprintf(painCave.errMsg, "RhoZ: unable to open %s\n", outputFilename_.c_str()); |
145 |
|
|
painCave.isFatal = 1; |
146 |
|
|
simError(); |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
rdfStream.close(); |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
} |
153 |
|
|
|