ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/RhoAngleR.cpp
Revision: 1524
Committed: Fri Nov 19 20:48:18 2010 UTC (14 years, 5 months ago) by kstocke1
File size: 5334 byte(s)
Log Message:
added missing files

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