ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/pAngle.cpp
Revision: 1442
Committed: Mon May 10 17:28:26 2010 UTC (14 years, 11 months ago) by gezelter
File size: 5647 byte(s)
Log Message:
Adding property set to svn entries

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

Properties

Name Value
svn:keywords Author Id Revision Date