ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/staticProps/BondAngleDistribution.cpp
Revision: 1390
Committed: Wed Nov 25 20:02:06 2009 UTC (15 years, 5 months ago) by gezelter
Original Path: trunk/src/applications/staticProps/BondAngleDistribution.cpp
File size: 7500 byte(s)
Log Message:
Almost all of the changes necessary to create OpenMD out of our old
project (OOPSE-4)

File Contents

# User Rev Content
1 chuckv 1180 /*
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 gezelter 1390 * 1. Redistributions of source code must retain the above copyright
10 chuckv 1180 * notice, this list of conditions and the following disclaimer.
11     *
12 gezelter 1390 * 2. Redistributions in binary form must reproduce the above copyright
13 chuckv 1180 * 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 gezelter 1390 * 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 chuckv 1180 *
41     * Created by J. Daniel Gezelter on 07/27/07.
42     * @author J. Daniel Gezelter
43 gezelter 1390 * @version $Id: BondAngleDistribution.cpp,v 1.2 2009-11-25 20:01:59 gezelter Exp $
44 chuckv 1180 *
45     */
46    
47     #include "applications/staticProps/BondAngleDistribution.hpp"
48     #include "utils/simError.h"
49     #include "io/DumpReader.hpp"
50     #include "primitives/Molecule.hpp"
51     #include "utils/NumericConstant.hpp"
52    
53 gezelter 1390 namespace OpenMD {
54 chuckv 1180
55     BondAngleDistribution::BondAngleDistribution(SimInfo* info,
56     const std::string& filename,
57     const std::string& sele,
58     double rCut, int nbins) : StaticAnalyser(info, filename),
59     selectionScript_(sele),
60     evaluator_(info), seleMan_(info){
61    
62     setOutputName(getPrefix(filename) + ".bad");
63    
64     evaluator_.loadScriptString(sele);
65     if (!evaluator_.isDynamic()) {
66     seleMan_.setSelectionSet(evaluator_.evaluate());
67     }
68    
69     // Set up cutoff radius and order of the Legendre Polynomial:
70    
71     rCut_ = rCut;
72     nBins_ = nbins;
73    
74    
75     // Theta can take values from 0 to 180
76     deltaTheta_ = (180.0) / nBins_;
77     histogram_.resize(nBins_);
78     }
79    
80     BondAngleDistribution::~BondAngleDistribution() {
81     histogram_.clear();
82     }
83    
84     void BondAngleDistribution::initalizeHistogram() {
85     for (int bin = 0; bin < nBins_; bin++) {
86     histogram_[bin] = 0;
87     }
88     }
89    
90     void BondAngleDistribution::process() {
91     Molecule* mol;
92     Atom* atom;
93     RigidBody* rb;
94     int myIndex;
95     SimInfo::MoleculeIterator mi;
96     Molecule::RigidBodyIterator rbIter;
97     Molecule::AtomIterator ai;
98     StuntDouble* sd;
99     Vector3d vec;
100     std::vector<Vector3d> bondvec;
101     std::vector<RealType> bonddist;
102     RealType costheta;
103     RealType r;
104     RealType dist;
105    
106     int nBonds;
107    
108     int i, j;
109    
110     DumpReader reader(info_, dumpFilename_);
111     int nFrames = reader.getNFrames();
112     frameCounter_ = 0;
113    
114     nTotBonds_ = 0;
115    
116     for (int istep = 0; istep < nFrames; istep += step_) {
117     reader.readFrame(istep);
118     frameCounter_++;
119     currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
120    
121     if (evaluator_.isDynamic()) {
122     seleMan_.setSelectionSet(evaluator_.evaluate());
123     }
124    
125     // update the positions of atoms which belong to the rigidbodies
126    
127     for (mol = info_->beginMolecule(mi); mol != NULL;
128     mol = info_->nextMolecule(mi)) {
129     for (rb = mol->beginRigidBody(rbIter); rb != NULL;
130     rb = mol->nextRigidBody(rbIter)) {
131     rb->updateAtoms();
132     }
133     }
134    
135     // outer loop is over the selected StuntDoubles:
136    
137     for (sd = seleMan_.beginSelected(i); sd != NULL;
138     sd = seleMan_.nextSelected(i)) {
139    
140     myIndex = sd->getGlobalIndex();
141     nBonds = 0;
142     bondvec.clear();
143    
144     // inner loop is over all other atoms in the system:
145    
146     for (mol = info_->beginMolecule(mi); mol != NULL;
147     mol = info_->nextMolecule(mi)) {
148     for (atom = mol->beginAtom(ai); atom != NULL;
149     atom = mol->nextAtom(ai)) {
150    
151     if (atom->getGlobalIndex() != myIndex) {
152    
153     vec = sd->getPos() - atom->getPos();
154    
155     if (usePeriodicBoundaryConditions_)
156     currentSnapshot_->wrapVector(vec);
157    
158     // Calculate "bonds" and make a pair list
159    
160     r = vec.length();
161    
162     // Check to see if neighbor is in bond cutoff
163    
164     if (r < rCut_) {
165     // Add neighbor to bond list's
166     bondvec.push_back(vec);
167     nBonds++;
168     nTotBonds_++;
169     }
170     }
171     }
172    
173    
174     for (int i = 0; i < nBonds-1; i++ ){
175     Vector3d vec1 = bondvec[i];
176     vec1.normalize();
177     for(int j = i+1; j < nBonds; j++){
178     Vector3d vec2 = bondvec[j];
179    
180     vec2.normalize();
181    
182     RealType theta = acos(dot(vec1,vec2))*180.0/NumericConstant::PI;
183    
184    
185     if (theta > 180.0){
186     theta = 360.0 - theta;
187     }
188     int whichBin = theta/deltaTheta_;
189    
190     histogram_[whichBin] += 2;
191     }
192     }
193     }
194     }
195     }
196    
197    
198     writeBondAngleDistribution();
199     }
200    
201    
202     void BondAngleDistribution::writeBondAngleDistribution() {
203    
204     std::ofstream osbad(getOutputFileName().c_str());
205    
206    
207     RealType norm = (RealType)nTotBonds_*((RealType)nTotBonds_-1.0)/2.0;
208     if (osbad.is_open()) {
209    
210     // Normalize by number of frames and write it out:
211     for (int i = 0; i < nBins_; ++i) {
212     RealType Thetaval = i * deltaTheta_;
213     osbad << Thetaval;
214     osbad << "\t" << (RealType)histogram_[i]/norm/frameCounter_;
215    
216     osbad << "\n";
217     }
218    
219     osbad.close();
220    
221     } else {
222     sprintf(painCave.errMsg, "BondAngleDistribution: unable to open %s\n",
223     (getOutputFileName() + "q").c_str());
224     painCave.isFatal = 1;
225     simError();
226     }
227    
228     }
229     }

Properties

Name Value
svn:executable *