ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/BondAngleDistribution.cpp
Revision: 1180
Committed: Mon Sep 17 20:05:51 2007 UTC (17 years, 7 months ago) by chuckv
File size: 7501 byte(s)
Log Message:
Added code to compute bond angle distributions.

File Contents

# Content
1 /*
2 * Copyright (c) 2007 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. Acknowledgement of the program authors must be made in any
10 * publication of scientific results based in part on use of the
11 * program. An acceptable form of acknowledgement is citation of
12 * the article in which the program was described (Matthew
13 * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 * Parallel Simulation Engine for Molecular Dynamics,"
16 * J. Comput. Chem. 26, pp. 252-271 (2005))
17 *
18 * 2. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * 3. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the
24 * distribution.
25 *
26 * This software is provided "AS IS," without a warranty of any
27 * kind. All express or implied conditions, representations and
28 * warranties, including any implied warranty of merchantability,
29 * fitness for a particular purpose or non-infringement, are hereby
30 * excluded. The University of Notre Dame and its licensors shall not
31 * be liable for any damages suffered by licensee as a result of
32 * using, modifying or distributing the software or its
33 * derivatives. In no event will the University of Notre Dame or its
34 * licensors be liable for any lost revenue, profit or data, or for
35 * direct, indirect, special, consequential, incidental or punitive
36 * damages, however caused and regardless of the theory of liability,
37 * arising out of the use of or inability to use software, even if the
38 * University of Notre Dame has been advised of the possibility of
39 * such damages.
40 *
41 * BondAngleDistribution.cpp
42 * OOPSE-4
43 *
44 * Created by J. Daniel Gezelter on 07/27/07.
45 * @author J. Daniel Gezelter
46 * @version $Id: BondAngleDistribution.cpp,v 1.1 2007-09-17 20:05:51 chuckv Exp $
47 *
48 */
49
50 #include "applications/staticProps/BondAngleDistribution.hpp"
51 #include "utils/simError.h"
52 #include "io/DumpReader.hpp"
53 #include "primitives/Molecule.hpp"
54 #include "utils/NumericConstant.hpp"
55
56 namespace oopse {
57
58 BondAngleDistribution::BondAngleDistribution(SimInfo* info,
59 const std::string& filename,
60 const std::string& sele,
61 double rCut, int nbins) : StaticAnalyser(info, filename),
62 selectionScript_(sele),
63 evaluator_(info), seleMan_(info){
64
65 setOutputName(getPrefix(filename) + ".bad");
66
67 evaluator_.loadScriptString(sele);
68 if (!evaluator_.isDynamic()) {
69 seleMan_.setSelectionSet(evaluator_.evaluate());
70 }
71
72 // Set up cutoff radius and order of the Legendre Polynomial:
73
74 rCut_ = rCut;
75 nBins_ = nbins;
76
77
78 // Theta can take values from 0 to 180
79 deltaTheta_ = (180.0) / nBins_;
80 histogram_.resize(nBins_);
81 }
82
83 BondAngleDistribution::~BondAngleDistribution() {
84 histogram_.clear();
85 }
86
87 void BondAngleDistribution::initalizeHistogram() {
88 for (int bin = 0; bin < nBins_; bin++) {
89 histogram_[bin] = 0;
90 }
91 }
92
93 void BondAngleDistribution::process() {
94 Molecule* mol;
95 Atom* atom;
96 RigidBody* rb;
97 int myIndex;
98 SimInfo::MoleculeIterator mi;
99 Molecule::RigidBodyIterator rbIter;
100 Molecule::AtomIterator ai;
101 StuntDouble* sd;
102 Vector3d vec;
103 std::vector<Vector3d> bondvec;
104 std::vector<RealType> bonddist;
105 RealType costheta;
106 RealType r;
107 RealType dist;
108
109 int nBonds;
110
111 int i, j;
112
113 DumpReader reader(info_, dumpFilename_);
114 int nFrames = reader.getNFrames();
115 frameCounter_ = 0;
116
117 nTotBonds_ = 0;
118
119 for (int istep = 0; istep < nFrames; istep += step_) {
120 reader.readFrame(istep);
121 frameCounter_++;
122 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
123
124 if (evaluator_.isDynamic()) {
125 seleMan_.setSelectionSet(evaluator_.evaluate());
126 }
127
128 // update the positions of atoms which belong to the rigidbodies
129
130 for (mol = info_->beginMolecule(mi); mol != NULL;
131 mol = info_->nextMolecule(mi)) {
132 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
133 rb = mol->nextRigidBody(rbIter)) {
134 rb->updateAtoms();
135 }
136 }
137
138 // outer loop is over the selected StuntDoubles:
139
140 for (sd = seleMan_.beginSelected(i); sd != NULL;
141 sd = seleMan_.nextSelected(i)) {
142
143 myIndex = sd->getGlobalIndex();
144 nBonds = 0;
145 bondvec.clear();
146
147 // inner loop is over all other atoms in the system:
148
149 for (mol = info_->beginMolecule(mi); mol != NULL;
150 mol = info_->nextMolecule(mi)) {
151 for (atom = mol->beginAtom(ai); atom != NULL;
152 atom = mol->nextAtom(ai)) {
153
154 if (atom->getGlobalIndex() != myIndex) {
155
156 vec = sd->getPos() - atom->getPos();
157
158 if (usePeriodicBoundaryConditions_)
159 currentSnapshot_->wrapVector(vec);
160
161 // Calculate "bonds" and make a pair list
162
163 r = vec.length();
164
165 // Check to see if neighbor is in bond cutoff
166
167 if (r < rCut_) {
168 // Add neighbor to bond list's
169 bondvec.push_back(vec);
170 nBonds++;
171 nTotBonds_++;
172 }
173 }
174 }
175
176
177 for (int i = 0; i < nBonds-1; i++ ){
178 Vector3d vec1 = bondvec[i];
179 vec1.normalize();
180 for(int j = i+1; j < nBonds; j++){
181 Vector3d vec2 = bondvec[j];
182
183 vec2.normalize();
184
185 RealType theta = acos(dot(vec1,vec2))*180.0/NumericConstant::PI;
186
187
188 if (theta > 180.0){
189 theta = 360.0 - theta;
190 }
191 int whichBin = theta/deltaTheta_;
192
193 histogram_[whichBin] += 2;
194 }
195 }
196 }
197 }
198 }
199
200
201 writeBondAngleDistribution();
202 }
203
204
205 void BondAngleDistribution::writeBondAngleDistribution() {
206
207 std::ofstream osbad(getOutputFileName().c_str());
208
209
210 RealType norm = (RealType)nTotBonds_*((RealType)nTotBonds_-1.0)/2.0;
211 if (osbad.is_open()) {
212
213 // Normalize by number of frames and write it out:
214 for (int i = 0; i < nBins_; ++i) {
215 RealType Thetaval = i * deltaTheta_;
216 osbad << Thetaval;
217 osbad << "\t" << (RealType)histogram_[i]/norm/frameCounter_;
218
219 osbad << "\n";
220 }
221
222 osbad.close();
223
224 } else {
225 sprintf(painCave.errMsg, "BondAngleDistribution: unable to open %s\n",
226 (getOutputFileName() + "q").c_str());
227 painCave.isFatal = 1;
228 simError();
229 }
230
231 }
232 }

Properties

Name Value
svn:executable *