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

File Contents

# User Rev Content
1 gezelter 1629 /*
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     * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 gezelter 1629 */
42    
43     /* Calculates Angle(R) for DirectionalAtoms*/
44     #include <algorithm>
45     #include <fstream>
46     #include "applications/staticProps/AngleR.hpp"
47     #include "utils/simError.h"
48     #include "utils/NumericConstant.hpp"
49     #include "io/DumpReader.hpp"
50     #include "primitives/Molecule.hpp"
51     #include <math.h>
52    
53     namespace OpenMD {
54    
55    
56     AngleR::AngleR(SimInfo* info, const std::string& filename, const std::string& sele, RealType len, int nrbins)
57     : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info), len_(len), nRBins_(nrbins){
58    
59    
60     evaluator_.loadScriptString(sele);
61     if (!evaluator_.isDynamic()) {
62     seleMan_.setSelectionSet(evaluator_.evaluate());
63     }
64    
65    
66     deltaR_ = len_ /nRBins_;
67    
68     histogram_.resize(nRBins_);
69     count_.resize(nRBins_);
70     avgAngleR_.resize(nRBins_);
71     setOutputName(getPrefix(filename) + ".AngleR");
72     }
73    
74    
75     void AngleR::process() {
76    
77     DumpReader reader(info_, dumpFilename_);
78     int nFrames = reader.getNFrames();
79     nProcessed_ = nFrames/step_;
80    
81     std::fill(avgAngleR_.begin(), avgAngleR_.end(), 0.0);
82     std::fill(histogram_.begin(), histogram_.end(), 0.0);
83     std::fill(count_.begin(), count_.end(), 0);
84    
85     for (int istep = 0; istep < nFrames; istep += step_) {
86    
87     int i;
88     StuntDouble* sd;
89     reader.readFrame(istep);
90     currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
91     Vector3d CenterOfMass = info_->getCom();
92    
93    
94     if (evaluator_.isDynamic()) {
95     seleMan_.setSelectionSet(evaluator_.evaluate());
96     }
97    
98     //determine which atom belongs to which slice
99     for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
100     Vector3d pos = sd->getPos();
101     Vector3d r1 = CenterOfMass - pos;
102     // only do this if the stunt double actually has a vector associated
103     // with it
104     if (sd->isDirectional()) {
105     Vector3d dipole = sd->getA().getColumn(2);
106     // std::cerr << "pos = " << pos << " dipole = " << dipole << "\n";
107     RealType distance = r1.length();
108    
109     dipole.normalize();
110     r1.normalize();
111     RealType cosangle = dot(r1, dipole);
112    
113     if (distance < len_) {
114     int whichBin = distance / deltaR_;
115     histogram_[whichBin] += cosangle;
116     count_[whichBin] += 1;
117     }
118     }
119    
120     }
121    
122     }
123    
124     processHistogram();
125     writeAngleR();
126     }
127    
128    
129    
130     void AngleR::processHistogram() {
131    
132     for(int i = 0 ; i < histogram_.size(); ++i){
133    
134     if (count_[i] > 0)
135     avgAngleR_[i] += histogram_[i] / count_[i];
136     else
137     avgAngleR_[i] = 0.0;
138    
139     std::cerr << " count = " << count_[i] << " avgAngle = " << avgAngleR_[i] << "\n";
140     }
141    
142     }
143    
144    
145    
146     void AngleR::writeAngleR() {
147     std::ofstream rdfStream(outputFilename_.c_str());
148     if (rdfStream.is_open()) {
149     rdfStream << "#radial density function Angle(r)\n";
150     rdfStream << "#r\tcorrValue\n";
151     for (int i = 0; i < avgAngleR_.size(); ++i) {
152     RealType r = deltaR_ * (i + 0.5);
153     rdfStream << r << "\t" << avgAngleR_[i] << "\n";
154     }
155    
156     } else {
157    
158     sprintf(painCave.errMsg, "AngleR: unable to open %s\n", outputFilename_.c_str());
159     painCave.isFatal = 1;
160     simError();
161     }
162    
163     rdfStream.close();
164     }
165    
166     }
167    

Properties

Name Value
svn:eol-style native