ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/pAngle.cpp
Revision: 2071
Committed: Sat Mar 7 21:41:51 2015 UTC (10 years, 1 month ago) by gezelter
File size: 11747 byte(s)
Log Message:
Reducing the number of warnings when using g++ to compile.

File Contents

# User Rev Content
1 gezelter 1413 /*
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. Redistributions of source code must retain the above copyright
10     * notice, this list of conditions and the following disclaimer.
11     *
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.
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     *
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 gezelter 1879 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
39 gezelter 1782 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40     * [4] , Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). *
41 gezelter 1413 */
42    
43     /* Calculates Rho(theta) */
44    
45     #include <algorithm>
46 gezelter 1782 #include <fstream>
47 gezelter 1413 #include "applications/staticProps/pAngle.hpp"
48     #include "utils/simError.h"
49     #include "io/DumpReader.hpp"
50     #include "primitives/Molecule.hpp"
51 gezelter 1782 #include "brains/Thermo.hpp"
52    
53 gezelter 1413 namespace OpenMD {
54    
55     pAngle::pAngle(SimInfo* info, const std::string& filename,
56 gezelter 1979 const std::string& sele1, int nthetabins)
57 gezelter 2071 : StaticAnalyser(info, filename), doVect_(true), doOffset_(false),
58     selectionScript1_(sele1), seleMan1_(info), seleMan2_(info),
59     evaluator1_(info), evaluator2_(info),
60     nThetaBins_(nthetabins) {
61 gezelter 1413
62 gezelter 1979 setOutputName(getPrefix(filename) + ".pAngle");
63    
64     evaluator1_.loadScriptString(sele1);
65     if (!evaluator1_.isDynamic()) {
66     seleMan1_.setSelectionSet(evaluator1_.evaluate());
67 gezelter 1413 }
68    
69     count_.resize(nThetaBins_);
70 gezelter 1979 histogram_.resize(nThetaBins_);
71     }
72    
73     pAngle::pAngle(SimInfo* info, const std::string& filename,
74     const std::string& sele1, const std::string& sele2,
75     int nthetabins)
76 gezelter 2071 : StaticAnalyser(info, filename), doVect_(false), doOffset_(false),
77     selectionScript1_(sele1), selectionScript2_(sele2),
78     seleMan1_(info), seleMan2_(info), evaluator1_(info), evaluator2_(info),
79     nThetaBins_(nthetabins) {
80 gezelter 1413
81     setOutputName(getPrefix(filename) + ".pAngle");
82 gezelter 1979
83     evaluator1_.loadScriptString(sele1);
84     if (!evaluator1_.isDynamic()) {
85     seleMan1_.setSelectionSet(evaluator1_.evaluate());
86     }
87    
88     evaluator2_.loadScriptString(sele2);
89     if (!evaluator2_.isDynamic()) {
90     seleMan2_.setSelectionSet(evaluator2_.evaluate());
91     }
92    
93     count_.resize(nThetaBins_);
94     histogram_.resize(nThetaBins_);
95 gezelter 1413 }
96 gezelter 1979
97     pAngle::pAngle(SimInfo* info, const std::string& filename,
98     const std::string& sele1, int seleOffset, int nthetabins)
99 gezelter 2071 : StaticAnalyser(info, filename), doVect_(false), doOffset_(true),
100     doOffset2_(false), selectionScript1_(sele1),
101     seleMan1_(info), seleMan2_(info), evaluator1_(info), evaluator2_(info),
102     seleOffset_(seleOffset), nThetaBins_(nthetabins) {
103 gezelter 1979
104     setOutputName(getPrefix(filename) + ".pAngle");
105    
106     evaluator1_.loadScriptString(sele1);
107     if (!evaluator1_.isDynamic()) {
108     seleMan1_.setSelectionSet(evaluator1_.evaluate());
109     }
110    
111     count_.resize(nThetaBins_);
112     histogram_.resize(nThetaBins_);
113     }
114 gezelter 1991
115     pAngle::pAngle(SimInfo* info, const std::string& filename,
116     const std::string& sele1, int seleOffset, int seleOffset2,
117     int nthetabins)
118 gezelter 2071 : StaticAnalyser(info, filename), doVect_(false), doOffset_(true),
119     doOffset2_(true), selectionScript1_(sele1),
120     seleMan1_(info), seleMan2_(info), evaluator1_(info), evaluator2_(info),
121     seleOffset_(seleOffset), seleOffset2_(seleOffset2),
122     nThetaBins_(nthetabins) {
123 gezelter 1991
124     setOutputName(getPrefix(filename) + ".pAngle");
125    
126     evaluator1_.loadScriptString(sele1);
127     if (!evaluator1_.isDynamic()) {
128     seleMan1_.setSelectionSet(evaluator1_.evaluate());
129     }
130    
131     count_.resize(nThetaBins_);
132     histogram_.resize(nThetaBins_);
133     }
134 gezelter 1413
135     void pAngle::process() {
136     Molecule* mol;
137     RigidBody* rb;
138     SimInfo::MoleculeIterator mi;
139     Molecule::RigidBodyIterator rbIter;
140 gezelter 1979 StuntDouble* sd1;
141     StuntDouble* sd2;
142     int ii;
143     int jj;
144 gezelter 1413
145 gezelter 1782 Thermo thermo(info_);
146 gezelter 1413 DumpReader reader(info_, dumpFilename_);
147     int nFrames = reader.getNFrames();
148 gezelter 1979
149 gezelter 1413 nProcessed_ = nFrames/step_;
150    
151     std::fill(histogram_.begin(), histogram_.end(), 0.0);
152     std::fill(count_.begin(), count_.end(), 0);
153    
154     for (int istep = 0; istep < nFrames; istep += step_) {
155     reader.readFrame(istep);
156     currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
157    
158     for (mol = info_->beginMolecule(mi); mol != NULL;
159     mol = info_->nextMolecule(mi)) {
160     //change the positions of atoms which belong to the rigidbodies
161     for (rb = mol->beginRigidBody(rbIter); rb != NULL;
162     rb = mol->nextRigidBody(rbIter)) {
163     rb->updateAtoms();
164     }
165     }
166    
167 gezelter 1782 Vector3d CenterOfMass = thermo.getCom();
168 gezelter 1413
169 gezelter 1979 if (evaluator1_.isDynamic()) {
170     seleMan1_.setSelectionSet(evaluator1_.evaluate());
171 gezelter 1413 }
172    
173 gezelter 1979 if (doVect_) {
174 gezelter 1988
175 gezelter 1782
176 gezelter 1979 for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL;
177     sd1 = seleMan1_.nextSelected(ii)) {
178 gezelter 1413
179 gezelter 1979 Vector3d pos = sd1->getPos();
180    
181     Vector3d r1 = CenterOfMass - pos;
182     // only do this if the stunt double actually has a vector associated
183     // with it
184     if (sd1->isDirectional()) {
185 gezelter 2071 Vector3d vec = sd1->getA().getColumn(2);
186 gezelter 1979 vec.normalize();
187     r1.normalize();
188     RealType cosangle = dot(r1, vec);
189    
190     int binNo = int(nThetaBins_ * (1.0 + cosangle) / 2.0);
191     count_[binNo]++;
192     }
193 gezelter 1413 }
194 gezelter 1979 } else {
195     if (doOffset_) {
196    
197     for (sd1 = seleMan1_.beginSelected(ii); sd1 != NULL;
198     sd1 = seleMan1_.nextSelected(ii)) {
199    
200     // This will require careful rewriting if StaticProps is
201     // ever parallelized. For an example, see
202     // Thermo::getTaggedAtomPairDistance
203 gezelter 1991 Vector3d r1;
204 gezelter 1979
205 gezelter 1991 if (doOffset2_) {
206     int sd1Aind = sd1->getGlobalIndex() + seleOffset2_;
207     StuntDouble* sd1A = info_->getIOIndexToIntegrableObject(sd1Aind);
208     r1 = CenterOfMass - sd1A->getPos();
209     } else {
210     r1 = CenterOfMass - sd1->getPos();
211     }
212    
213     if (usePeriodicBoundaryConditions_)
214     currentSnapshot_->wrapVector(r1);
215    
216    
217 gezelter 1979 int sd2Index = sd1->getGlobalIndex() + seleOffset_;
218     sd2 = info_->getIOIndexToIntegrableObject(sd2Index);
219 gezelter 1991
220 gezelter 1979 Vector3d r2 = CenterOfMass - sd2->getPos();
221     if (usePeriodicBoundaryConditions_)
222     currentSnapshot_->wrapVector(r1);
223    
224     Vector3d rc = 0.5*(r1 + r2);
225     if (usePeriodicBoundaryConditions_)
226     currentSnapshot_->wrapVector(rc);
227    
228     Vector3d vec = r1-r2;
229     if (usePeriodicBoundaryConditions_)
230     currentSnapshot_->wrapVector(vec);
231    
232     rc.normalize();
233     vec.normalize();
234     RealType cosangle = dot(rc, vec);
235     int binNo = int(nThetaBins_ * (1.0 + cosangle) / 2.0);
236     count_[binNo]++;
237     }
238     } else {
239    
240     if (evaluator2_.isDynamic()) {
241     seleMan2_.setSelectionSet(evaluator2_.evaluate());
242     }
243    
244     if (seleMan1_.getSelectionCount() != seleMan2_.getSelectionCount() ) {
245     sprintf( painCave.errMsg,
246     "In frame %d, the number of selected StuntDoubles are\n"
247     "\tnot the same in --sele1 and sele2\n", istep);
248     painCave.severity = OPENMD_INFO;
249     painCave.isFatal = 0;
250     simError();
251     }
252    
253     for (sd1 = seleMan1_.beginSelected(ii),
254     sd2 = seleMan2_.beginSelected(jj);
255     sd1 != NULL && sd2 != NULL;
256     sd1 = seleMan1_.nextSelected(ii),
257     sd2 = seleMan2_.nextSelected(jj)) {
258    
259     Vector3d r1 = CenterOfMass - sd1->getPos();
260     if (usePeriodicBoundaryConditions_)
261     currentSnapshot_->wrapVector(r1);
262    
263     Vector3d r2 = CenterOfMass - sd2->getPos();
264     if (usePeriodicBoundaryConditions_)
265     currentSnapshot_->wrapVector(r1);
266    
267     Vector3d rc = 0.5*(r1 + r2);
268     if (usePeriodicBoundaryConditions_)
269     currentSnapshot_->wrapVector(rc);
270    
271     Vector3d vec = r1-r2;
272     if (usePeriodicBoundaryConditions_)
273     currentSnapshot_->wrapVector(vec);
274    
275     rc.normalize();
276     vec.normalize();
277     RealType cosangle = dot(rc, vec);
278     int binNo = int(nThetaBins_ * (1.0 + cosangle) / 2.0);
279     count_[binNo]++;
280    
281     }
282     }
283 gezelter 1413 }
284     }
285 gezelter 1979
286 gezelter 1413 processHistogram();
287     writeProbs();
288    
289     }
290    
291     void pAngle::processHistogram() {
292    
293     int atot = 0;
294 gezelter 1782 for(unsigned int i = 0; i < count_.size(); ++i)
295 gezelter 1413 atot += count_[i];
296    
297 gezelter 1782 for(unsigned int i = 0; i < count_.size(); ++i) {
298     histogram_[i] = double(count_[i] / double(atot));
299 gezelter 1413 }
300     }
301    
302    
303     void pAngle::writeProbs() {
304    
305     std::ofstream rdfStream(outputFilename_.c_str());
306     if (rdfStream.is_open()) {
307     rdfStream << "#pAngle\n";
308     rdfStream << "#nFrames:\t" << nProcessed_ << "\n";
309 gezelter 1979 rdfStream << "#selection1: (" << selectionScript1_ << ")";
310     if (!doVect_) {
311     rdfStream << "\tselection2: (" << selectionScript2_ << ")";
312     }
313     rdfStream << "\n";
314 gezelter 1413 rdfStream << "#cos(theta)\tp(cos(theta))\n";
315 kstocke1 1522 RealType dct = 2.0 / histogram_.size();
316 gezelter 1782 for (unsigned int i = 0; i < histogram_.size(); ++i) {
317 kstocke1 1522 RealType ct = -1.0 + (2.0 * i + 1) / (histogram_.size());
318     rdfStream << ct << "\t" << histogram_[i]/dct << "\n";
319 gezelter 1413 }
320    
321     } else {
322    
323 gezelter 1979 sprintf(painCave.errMsg, "pAngle: unable to open %s\n",
324     outputFilename_.c_str());
325 gezelter 1413 painCave.isFatal = 1;
326     simError();
327     }
328    
329     rdfStream.close();
330     }
331    
332     }
333    

Properties

Name Value
svn:keywords Author Id Revision Date