ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/staticProps/pAngle.cpp
Revision: 1764
Committed: Tue Jul 3 18:32:27 2012 UTC (12 years, 9 months ago) by gezelter
File size: 5854 byte(s)
Log Message:
Refactored Snapshot and Stats to use the Accumulator classes.  Collected
a number of methods into Thermo that belonged there.

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     * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).
39 gezelter 1665 * [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 1764 #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 1764 #include "brains/Thermo.hpp"
52    
53 gezelter 1413 namespace OpenMD {
54    
55     pAngle::pAngle(SimInfo* info, const std::string& filename,
56     const std::string& sele, int nthetabins)
57     : StaticAnalyser(info, filename), selectionScript_(sele),
58     evaluator_(info), seleMan_(info), nThetaBins_(nthetabins){
59    
60     evaluator_.loadScriptString(sele);
61     if (!evaluator_.isDynamic()) {
62     seleMan_.setSelectionSet(evaluator_.evaluate());
63     }
64    
65     count_.resize(nThetaBins_);
66     histogram_.resize(nThetaBins_);
67    
68     setOutputName(getPrefix(filename) + ".pAngle");
69     }
70    
71     void pAngle::process() {
72     Molecule* mol;
73     RigidBody* rb;
74     StuntDouble* sd;
75     SimInfo::MoleculeIterator mi;
76     Molecule::RigidBodyIterator rbIter;
77     int i;
78    
79 gezelter 1764 Thermo thermo(info_);
80 gezelter 1413 DumpReader reader(info_, dumpFilename_);
81     int nFrames = reader.getNFrames();
82     nProcessed_ = nFrames/step_;
83    
84     std::fill(histogram_.begin(), histogram_.end(), 0.0);
85     std::fill(count_.begin(), count_.end(), 0);
86    
87     for (int istep = 0; istep < nFrames; istep += step_) {
88     reader.readFrame(istep);
89     currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
90    
91     for (mol = info_->beginMolecule(mi); mol != NULL;
92     mol = info_->nextMolecule(mi)) {
93     //change the positions of atoms which belong to the rigidbodies
94     for (rb = mol->beginRigidBody(rbIter); rb != NULL;
95     rb = mol->nextRigidBody(rbIter)) {
96     rb->updateAtoms();
97     }
98     }
99    
100 gezelter 1764 Vector3d CenterOfMass = thermo.getCom();
101 gezelter 1413
102     if (evaluator_.isDynamic()) {
103     seleMan_.setSelectionSet(evaluator_.evaluate());
104     }
105    
106 gezelter 1629 int runningTot = 0;
107 gezelter 1413 for (sd = seleMan_.beginSelected(i); sd != NULL;
108     sd = seleMan_.nextSelected(i)) {
109    
110     Vector3d pos = sd->getPos();
111    
112     Vector3d r1 = CenterOfMass - pos;
113     // only do this if the stunt double actually has a vector associated
114     // with it
115     if (sd->isDirectional()) {
116     Vector3d dipole = sd->getA().getColumn(2);
117     RealType distance = r1.length();
118    
119     dipole.normalize();
120     r1.normalize();
121     RealType cosangle = dot(r1, dipole);
122    
123     int binNo = int(nThetaBins_ * (1.0 + cosangle) / 2.0);
124     count_[binNo]++;
125     }
126    
127     }
128     }
129     processHistogram();
130     writeProbs();
131    
132     }
133    
134     void pAngle::processHistogram() {
135    
136     int atot = 0;
137     for(int i = 0; i < count_.size(); ++i)
138     atot += count_[i];
139    
140     for(int i = 0; i < count_.size(); ++i) {
141 gezelter 1629 histogram_[i] = double(count_[i] / double(atot));
142 gezelter 1413 }
143     }
144    
145    
146     void pAngle::writeProbs() {
147    
148     std::ofstream rdfStream(outputFilename_.c_str());
149     if (rdfStream.is_open()) {
150     rdfStream << "#pAngle\n";
151     rdfStream << "#nFrames:\t" << nProcessed_ << "\n";
152     rdfStream << "#selection: (" << selectionScript_ << ")\n";
153     rdfStream << "#cos(theta)\tp(cos(theta))\n";
154 gezelter 1629 RealType dct = 2.0 / histogram_.size();
155 gezelter 1413 for (int i = 0; i < histogram_.size(); ++i) {
156 gezelter 1629 RealType ct = -1.0 + (2.0 * i + 1) / (histogram_.size());
157     rdfStream << ct << "\t" << histogram_[i]/dct << "\n";
158 gezelter 1413 }
159    
160     } else {
161    
162     sprintf(painCave.errMsg, "pAngle: unable to open %s\n", outputFilename_.c_str());
163     painCave.isFatal = 1;
164     simError();
165     }
166    
167     rdfStream.close();
168     }
169    
170     }
171    

Properties

Name Value
svn:keywords Author Id Revision Date