ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/pAngle.cpp
Revision: 1522
Committed: Fri Nov 19 20:26:36 2010 UTC (14 years, 5 months ago) by kstocke1
File size: 5745 byte(s)
Log Message:
new hotness

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 kstocke1 1522
104     int runningTot = 0;
105 gezelter 1413 for (sd = seleMan_.beginSelected(i); sd != NULL;
106     sd = seleMan_.nextSelected(i)) {
107 kstocke1 1522
108 gezelter 1413 Vector3d pos = sd->getPos();
109    
110     Vector3d r1 = CenterOfMass - pos;
111     // only do this if the stunt double actually has a vector associated
112     // with it
113     if (sd->isDirectional()) {
114     Vector3d dipole = sd->getA().getColumn(2);
115     RealType distance = r1.length();
116    
117     dipole.normalize();
118     r1.normalize();
119     RealType cosangle = dot(r1, dipole);
120    
121     int binNo = int(nThetaBins_ * (1.0 + cosangle) / 2.0);
122     count_[binNo]++;
123     }
124    
125     }
126     }
127     processHistogram();
128     writeProbs();
129    
130     }
131    
132     void pAngle::processHistogram() {
133    
134     int atot = 0;
135     for(int i = 0; i < count_.size(); ++i)
136     atot += count_[i];
137    
138     for(int i = 0; i < count_.size(); ++i) {
139 kstocke1 1522 histogram_[i] = double(count_[i]) / double(atot);
140 gezelter 1413 }
141     }
142    
143    
144     void pAngle::writeProbs() {
145    
146     std::ofstream rdfStream(outputFilename_.c_str());
147     if (rdfStream.is_open()) {
148     rdfStream << "#pAngle\n";
149     rdfStream << "#nFrames:\t" << nProcessed_ << "\n";
150     rdfStream << "#selection: (" << selectionScript_ << ")\n";
151     rdfStream << "#cos(theta)\tp(cos(theta))\n";
152 kstocke1 1522 RealType dct = 2.0 / histogram_.size();
153 gezelter 1413 for (int i = 0; i < histogram_.size(); ++i) {
154 kstocke1 1522 RealType ct = -1.0 + (2.0 * i + 1) / (histogram_.size());
155     rdfStream << ct << "\t" << histogram_[i]/dct << "\n";
156 gezelter 1413 }
157    
158     } else {
159    
160     sprintf(painCave.errMsg, "pAngle: unable to open %s\n", outputFilename_.c_str());
161     painCave.isFatal = 1;
162     simError();
163     }
164    
165     rdfStream.close();
166     }
167    
168     }
169    

Properties

Name Value
svn:keywords Author Id Revision Date