ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/staticProps/pAngle.cpp
Revision: 1629
Committed: Wed Sep 14 21:15:17 2011 UTC (13 years, 7 months ago) by gezelter
File size: 5745 byte(s)
Log Message:
Merging changes from old branch into development branch

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

Properties

Name Value
svn:keywords Author Id Revision Date