ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/staticProps/DensityPlot.cpp
Revision: 1665
Committed: Tue Nov 22 20:38:56 2011 UTC (13 years, 6 months ago) by gezelter
File size: 8483 byte(s)
Log Message:
updated copyright notices

File Contents

# User Rev Content
1 tim 545 /*
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 gezelter 1390 * 1. Redistributions of source code must retain the above copyright
10 tim 545 * notice, this list of conditions and the following disclaimer.
11     *
12 gezelter 1390 * 2. Redistributions in binary form must reproduce the above copyright
13 tim 545 * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the
15     * distribution.
16     *
17     * This software is provided "AS IS," without a warranty of any
18     * kind. All express or implied conditions, representations and
19     * warranties, including any implied warranty of merchantability,
20     * fitness for a particular purpose or non-infringement, are hereby
21     * excluded. The University of Notre Dame and its licensors shall not
22     * be liable for any damages suffered by licensee as a result of
23     * using, modifying or distributing the software or its
24     * derivatives. In no event will the University of Notre Dame or its
25     * licensors be liable for any lost revenue, profit or data, or for
26     * direct, indirect, special, consequential, incidental or punitive
27     * damages, however caused and regardless of the theory of liability,
28     * arising out of the use of or inability to use software, even if the
29     * University of Notre Dame has been advised of the possibility of
30     * such damages.
31 gezelter 1390 *
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 gezelter 1665 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40     * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 tim 545 */
42    
43     #include <algorithm>
44 tim 565 #include <functional>
45 tim 545 #include "applications/staticProps/DensityPlot.hpp"
46     #include "utils/simError.h"
47     #include "io/DumpReader.hpp"
48     #include "primitives/Molecule.hpp"
49     #include "utils/NumericConstant.hpp"
50 gezelter 1390 namespace OpenMD {
51 tim 545
52    
53 tim 963 DensityPlot::DensityPlot(SimInfo* info, const std::string& filename, const std::string& sele, const std::string& cmSele, RealType len, int nrbins)
54 tim 545 : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info),
55 tim 558 cmSelectionScript_(cmSele), cmEvaluator_(info), cmSeleMan_(info),
56 tim 545 len_(len), nRBins_(nrbins), halfLen_(len/2) {
57    
58     setOutputName(getPrefix(filename) + ".density");
59    
60     deltaR_ = len_ /nRBins_;
61     histogram_.resize(nRBins_);
62     density_.resize(nRBins_);
63    
64     std::fill(histogram_.begin(), histogram_.end(), 0);
65    
66     evaluator_.loadScriptString(sele);
67    
68     if (!evaluator_.isDynamic()) {
69     seleMan_.setSelectionSet(evaluator_.evaluate());
70     }
71 tim 558
72     cmEvaluator_.loadScriptString(cmSele);
73     if (!cmEvaluator_.isDynamic()) {
74     cmSeleMan_.setSelectionSet(cmEvaluator_.evaluate());
75     }
76 tim 545
77 tim 558
78 tim 545 }
79    
80     void DensityPlot::process() {
81     Molecule* mol;
82     RigidBody* rb;
83     SimInfo::MoleculeIterator mi;
84     Molecule::RigidBodyIterator rbIter;
85    
86     DumpReader reader(info_, dumpFilename_);
87     int nFrames = reader.getNFrames();
88 tim 565 for (int i = 0; i < nFrames; i += step_) {
89 tim 545 reader.readFrame(i);
90     currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
91    
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    
100     if (evaluator_.isDynamic()) {
101     seleMan_.setSelectionSet(evaluator_.evaluate());
102     }
103    
104 tim 558 if (cmEvaluator_.isDynamic()) {
105     cmSeleMan_.setSelectionSet(cmEvaluator_.evaluate());
106     }
107    
108     Vector3d origin = calcNewOrigin();
109    
110     Mat3x3d hmat = currentSnapshot_->getHmat();
111 tim 963 RealType slabVolume = deltaR_ * hmat(0, 0) * hmat(1, 1);
112 tim 565 int k;
113     for (StuntDouble* sd = seleMan_.beginSelected(k); sd != NULL; sd = seleMan_.nextSelected(k)) {
114 tim 545
115 tim 558
116     if (!sd->isAtom()) {
117     sprintf( painCave.errMsg, "Can not calculate electron density if it is not atom\n");
118 gezelter 1390 painCave.severity = OPENMD_ERROR;
119 tim 558 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 gezelter 1390 painCave.severity = OPENMD_ERROR;
128 tim 558 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 gezelter 1390 painCave.severity = OPENMD_ERROR;
137 tim 558 painCave.isFatal = 1;
138     simError();
139     }
140    
141 tim 963 RealType nelectron = doubleData->getData();
142 tim 558
143     data = atom->getAtomType()->getPropertyByName("LennardJones");
144     if (data == NULL) {
145     sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n");
146 gezelter 1390 painCave.severity = OPENMD_ERROR;
147 tim 558 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 gezelter 1390 painCave.severity = OPENMD_ERROR;
156 tim 558 painCave.isFatal = 1;
157     simError();
158     }
159    
160     LJParam ljParam = ljData->getData();
161 tim 963 RealType sigma = ljParam.sigma * 0.5;
162     RealType sigma2 = sigma * sigma;
163 tim 558
164     Vector3d pos = sd->getPos() - origin;
165     for (int j =0; j < nRBins_; ++j) {
166     Vector3d tmp(pos);
167 tim 963 RealType zdist =j * deltaR_ - halfLen_;
168 tim 558 tmp[2] += zdist;
169 gezelter 1078 if (usePeriodicBoundaryConditions_)
170     currentSnapshot_->wrapVector(tmp);
171 tim 558
172 tim 963 RealType wrappedZdist = tmp.z() + halfLen_;
173 tim 558 if (wrappedZdist < 0.0 || wrappedZdist > len_) {
174     continue;
175     }
176    
177     int which =wrappedZdist / deltaR_;
178     density_[which] += nelectron * exp(-zdist*zdist/(sigma2*2.0)) /(slabVolume* sqrt(2*NumericConstant::PI*sigma*sigma));
179    
180     }
181    
182    
183    
184 tim 545 }
185     }
186 tim 558
187     int nProcessed = nFrames /step_;
188 tim 963 std::transform(density_.begin(), density_.end(), density_.begin(), std::bind2nd(std::divides<RealType>(), nProcessed));
189 tim 558 writeDensity();
190 tim 545
191    
192    
193     }
194    
195 tim 558 Vector3d DensityPlot::calcNewOrigin() {
196    
197     int i;
198     Vector3d newOrigin(0.0);
199 tim 963 RealType totalMass = 0.0;
200 tim 558 for (StuntDouble* sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
201 tim 963 RealType mass = sd->getMass();
202 tim 558 totalMass += mass;
203     newOrigin += sd->getPos() * mass;
204     }
205     newOrigin /= totalMass;
206     return newOrigin;
207     }
208    
209 tim 545 void DensityPlot::writeDensity() {
210     std::ofstream ofs(outputFilename_.c_str(), std::ios::binary);
211     if (ofs.is_open()) {
212     ofs << "#g(x, y, z)\n";
213 tim 558 ofs << "#selection: (" << selectionScript_ << ")\n";
214     ofs << "#cmSelection:(" << cmSelectionScript_ << ")\n";
215     ofs << "#nRBins = " << nRBins_ << "\t maxLen = " << len_ << "\tdeltaR = " << deltaR_ <<"\n";
216 tim 545 for (int i = 0; i < histogram_.size(); ++i) {
217     ofs << i*deltaR_ - halfLen_ <<"\t" << density_[i]<< std::endl;
218     }
219     } else {
220    
221     sprintf(painCave.errMsg, "DensityPlot: unable to open %s\n", outputFilename_.c_str());
222     painCave.isFatal = 1;
223     simError();
224     }
225    
226     ofs.close();
227    
228    
229     }
230    
231     }
232    
233    

Properties

Name Value
svn:executable *
svn:keywords Author Id Revision Date