ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/applications/staticProps/DensityPlot.cpp
Revision: 2257
Committed: Mon Jun 13 18:25:30 2005 UTC (19 years ago) by tim
File size: 8640 byte(s)
Log Message:
working version of DensityPlot

File Contents

# Content
1 /*
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 #include <algorithm>
43 #include "applications/staticProps/DensityPlot.hpp"
44 #include "utils/simError.h"
45 #include "io/DumpReader.hpp"
46 #include "primitives/Molecule.hpp"
47 #include "utils/NumericConstant.hpp"
48 namespace oopse {
49
50
51 DensityPlot::DensityPlot(SimInfo* info, const std::string& filename, const std::string& sele, const std::string& cmSele, double len, int nrbins)
52 : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info),
53 cmSelectionScript_(cmSele), cmEvaluator_(info), cmSeleMan_(info),
54 len_(len), nRBins_(nrbins), halfLen_(len/2) {
55
56 setOutputName(getPrefix(filename) + ".density");
57
58 deltaR_ = len_ /nRBins_;
59 histogram_.resize(nRBins_);
60 density_.resize(nRBins_);
61
62 std::fill(histogram_.begin(), histogram_.end(), 0);
63
64 evaluator_.loadScriptString(sele);
65
66 if (!evaluator_.isDynamic()) {
67 seleMan_.setSelectionSet(evaluator_.evaluate());
68 }
69
70 cmEvaluator_.loadScriptString(cmSele);
71 if (!cmEvaluator_.isDynamic()) {
72 cmSeleMan_.setSelectionSet(cmEvaluator_.evaluate());
73 }
74
75
76 }
77
78 void DensityPlot::process() {
79 Molecule* mol;
80 RigidBody* rb;
81 SimInfo::MoleculeIterator mi;
82 Molecule::RigidBodyIterator rbIter;
83
84 DumpReader reader(info_, dumpFilename_);
85 int nFrames = reader.getNFrames();
86
87 for (int i = 0; i < nFrames; i += step_) {
88 reader.readFrame(i);
89 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
90
91 for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
92 //change the positions of atoms which belong to the rigidbodies
93 for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
94 rb->updateAtoms();
95 }
96
97 }
98
99 if (evaluator_.isDynamic()) {
100 seleMan_.setSelectionSet(evaluator_.evaluate());
101 }
102
103 if (cmEvaluator_.isDynamic()) {
104 cmSeleMan_.setSelectionSet(cmEvaluator_.evaluate());
105 }
106
107 Vector3d origin = calcNewOrigin();
108
109 Mat3x3d hmat = currentSnapshot_->getHmat();
110 double slabVolume = deltaR_ * hmat(0, 0) * hmat(1, 1);
111
112 int i;
113 for (StuntDouble* sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
114
115
116 if (!sd->isAtom()) {
117 sprintf( painCave.errMsg, "Can not calculate electron density if it is not atom\n");
118 painCave.severity = OOPSE_ERROR;
119 painCave.isFatal = 1;
120 simError();
121 }
122
123 Atom* atom = static_cast<Atom*>(sd);
124 GenericData* data = atom->getAtomType()->getPropertyByName("nelectron");
125 if (data == NULL) {
126 sprintf( painCave.errMsg, "Can not find Parameters for nelectron\n");
127 painCave.severity = OOPSE_ERROR;
128 painCave.isFatal = 1;
129 simError();
130 }
131
132 DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
133 if (doubleData == NULL) {
134 sprintf( painCave.errMsg,
135 "Can not cast GenericData to DoubleGenericData\n");
136 painCave.severity = OOPSE_ERROR;
137 painCave.isFatal = 1;
138 simError();
139 }
140
141 double nelectron = doubleData->getData();
142
143 data = atom->getAtomType()->getPropertyByName("LennardJones");
144 if (data == NULL) {
145 sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n");
146 painCave.severity = OOPSE_ERROR;
147 painCave.isFatal = 1;
148 simError();
149 }
150
151 LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
152 if (ljData == NULL) {
153 sprintf( painCave.errMsg,
154 "Can not cast GenericData to LJParam\n");
155 painCave.severity = OOPSE_ERROR;
156 painCave.isFatal = 1;
157 simError();
158 }
159
160 LJParam ljParam = ljData->getData();
161 double sigma = ljParam.sigma * 0.5;
162 double sigma2 = sigma * sigma;
163
164 Vector3d pos = sd->getPos() - origin;
165 /*
166 currentSnapshot_->wrapVector(pos);
167 double wrappedZdist = pos.z() + halfLen_;
168 if (wrappedZdist < 0.0 || wrappedZdist > len_) {
169 continue;
170 }
171
172 int which =wrappedZdist / deltaR_;
173 density_[which] += nelectron;
174 */
175 for (int j =0; j < nRBins_; ++j) {
176 Vector3d tmp(pos);
177 double zdist =j * deltaR_ - halfLen_;
178 tmp[2] += zdist;
179 currentSnapshot_->wrapVector(tmp);
180
181 double wrappedZdist = tmp.z() + halfLen_;
182 if (wrappedZdist < 0.0 || wrappedZdist > len_) {
183 continue;
184 }
185
186 int which =wrappedZdist / deltaR_;
187 density_[which] += nelectron * exp(-zdist*zdist/(sigma2*2.0)) /(slabVolume* sqrt(2*NumericConstant::PI*sigma*sigma));
188
189 }
190
191
192
193 }
194 }
195
196 int nProcessed = nFrames /step_;
197 std::transform(density_.begin(), density_.end(), density_.begin(), std::bind2nd(std::divides<double>(), nProcessed));
198 writeDensity();
199
200
201
202 }
203
204 Vector3d DensityPlot::calcNewOrigin() {
205
206 int i;
207 Vector3d newOrigin(0.0);
208 double totalMass = 0.0;
209 for (StuntDouble* sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
210 double mass = sd->getMass();
211 totalMass += mass;
212 newOrigin += sd->getPos() * mass;
213 }
214 newOrigin /= totalMass;
215 return newOrigin;
216 }
217
218 void DensityPlot::writeDensity() {
219 std::ofstream ofs(outputFilename_.c_str(), std::ios::binary);
220 if (ofs.is_open()) {
221 ofs << "#g(x, y, z)\n";
222 ofs << "#selection: (" << selectionScript_ << ")\n";
223 ofs << "#cmSelection:(" << cmSelectionScript_ << ")\n";
224 ofs << "#nRBins = " << nRBins_ << "\t maxLen = " << len_ << "\tdeltaR = " << deltaR_ <<"\n";
225 for (int i = 0; i < histogram_.size(); ++i) {
226 ofs << i*deltaR_ - halfLen_ <<"\t" << density_[i]<< std::endl;
227 }
228 } else {
229
230 sprintf(painCave.errMsg, "DensityPlot: unable to open %s\n", outputFilename_.c_str());
231 painCave.isFatal = 1;
232 simError();
233 }
234
235 ofs.close();
236
237
238 }
239
240 }
241
242

Properties

Name Value
svn:executable *