ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/TetrahedralityParamZ.cpp
Revision: 2071
Committed: Sat Mar 7 21:41:51 2015 UTC (10 years, 1 month ago) by gezelter
File size: 8835 byte(s)
Log Message:
Reducing the number of warnings when using g++ to compile.

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, 234107 (2008).
39 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
42 */
43
44 #include "applications/staticProps/TetrahedralityParamZ.hpp"
45 #include "utils/simError.h"
46 #include "io/DumpReader.hpp"
47 #include "primitives/Molecule.hpp"
48 #include "utils/NumericConstant.hpp"
49 #include <vector>
50 #include <algorithm>
51 #include <fstream>
52
53 using namespace std;
54 namespace OpenMD {
55 TetrahedralityParamZ::TetrahedralityParamZ(SimInfo* info,
56 const std::string& filename,
57 const std::string& sele1,
58 const std::string& sele2,
59 double rCut, int nzbins)
60 : StaticAnalyser(info, filename),
61 selectionScript1_(sele1), selectionScript2_(sele2),
62 seleMan1_(info), seleMan2_(info), evaluator1_(info), evaluator2_(info),
63 nZBins_(nzbins) {
64
65 evaluator1_.loadScriptString(sele1);
66 if (!evaluator1_.isDynamic()) {
67 seleMan1_.setSelectionSet(evaluator1_.evaluate());
68 }
69 evaluator2_.loadScriptString(sele2);
70 if (!evaluator2_.isDynamic()) {
71 seleMan2_.setSelectionSet(evaluator2_.evaluate());
72 }
73
74 // Set up cutoff radius:
75 rCut_ = rCut;
76
77 // fixed number of bins
78 sliceQ_.resize(nZBins_);
79 sliceCount_.resize(nZBins_);
80 std::fill(sliceQ_.begin(), sliceQ_.end(), 0.0);
81 std::fill(sliceCount_.begin(), sliceCount_.end(), 0);
82
83 setOutputName(getPrefix(filename) + ".Qz");
84 }
85
86 TetrahedralityParamZ::~TetrahedralityParamZ() {
87 sliceQ_.clear();
88 sliceCount_.clear();
89 zBox_.clear();
90 }
91
92 void TetrahedralityParamZ::process() {
93 Molecule* mol;
94 StuntDouble* sd;
95 StuntDouble* sd2;
96 StuntDouble* sdi;
97 StuntDouble* sdj;
98 RigidBody* rb;
99 int myIndex;
100 SimInfo::MoleculeIterator mi;
101 Molecule::RigidBodyIterator rbIter;
102 Vector3d vec;
103 Vector3d ri, rj, rk, rik, rkj;
104 RealType r;
105 RealType cospsi;
106 RealType Qk;
107 std::vector<std::pair<RealType,StuntDouble*> > myNeighbors;
108 int isd1;
109 int isd2;
110
111 DumpReader reader(info_, dumpFilename_);
112 int nFrames = reader.getNFrames();
113
114 for (int istep = 0; istep < nFrames; istep += step_) {
115 reader.readFrame(istep);
116 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
117
118 Mat3x3d hmat = currentSnapshot_->getHmat();
119 zBox_.push_back(hmat(2,2));
120
121 RealType halfBoxZ_ = hmat(2,2) / 2.0;
122
123 if (evaluator1_.isDynamic()) {
124 seleMan1_.setSelectionSet(evaluator1_.evaluate());
125 }
126
127 if (evaluator2_.isDynamic()) {
128 seleMan2_.setSelectionSet(evaluator2_.evaluate());
129 }
130
131 // update the positions of atoms which belong to the rigidbodies
132 for (mol = info_->beginMolecule(mi); mol != NULL;
133 mol = info_->nextMolecule(mi)) {
134 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
135 rb = mol->nextRigidBody(rbIter)) {
136 rb->updateAtoms();
137 }
138 }
139
140 // outer loop is over the selected StuntDoubles:
141 for (sd = seleMan1_.beginSelected(isd1); sd != NULL;
142 sd = seleMan1_.nextSelected(isd1)) {
143
144 myIndex = sd->getGlobalIndex();
145
146 Qk = 1.0;
147 myNeighbors.clear();
148
149 for (sd2 = seleMan2_.beginSelected(isd2); sd2 != NULL;
150 sd2 = seleMan2_.nextSelected(isd2)) {
151
152 if (sd2->getGlobalIndex() != myIndex) {
153
154 vec = sd->getPos() - sd2->getPos();
155
156 if (usePeriodicBoundaryConditions_)
157 currentSnapshot_->wrapVector(vec);
158
159 r = vec.length();
160
161 // Check to see if neighbor is in bond cutoff
162
163 if (r < rCut_) {
164 myNeighbors.push_back(std::make_pair(r,sd2));
165 }
166 }
167 }
168
169 // Sort the vector using predicate and std::sort
170 std::sort(myNeighbors.begin(), myNeighbors.end());
171
172 // Use only the 4 closest neighbors to do the rest of the work:
173
174 int nbors = myNeighbors.size()> 4 ? 4 : myNeighbors.size();
175 int nang = int (0.5 * (nbors * (nbors - 1)));
176
177 rk = sd->getPos();
178
179 for (int i = 0; i < nbors-1; i++) {
180
181 sdi = myNeighbors[i].second;
182 ri = sdi->getPos();
183 rik = rk - ri;
184 if (usePeriodicBoundaryConditions_)
185 currentSnapshot_->wrapVector(rik);
186
187 rik.normalize();
188
189 for (int j = i+1; j < nbors; j++) {
190
191 sdj = myNeighbors[j].second;
192 rj = sdj->getPos();
193 rkj = rk - rj;
194 if (usePeriodicBoundaryConditions_)
195 currentSnapshot_->wrapVector(rkj);
196 rkj.normalize();
197
198 cospsi = dot(rik,rkj);
199
200 // Calculates scaled Qk for each molecule using calculated
201 // angles from 4 or fewer nearest neighbors.
202 Qk -= (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);
203 }
204 }
205
206 if (nang > 0) {
207 if (usePeriodicBoundaryConditions_)
208 currentSnapshot_->wrapVector(rk);
209
210 int binNo = int(nZBins_ * (halfBoxZ_ + rk.z()) / hmat(2,2));
211 sliceQ_[binNo] += Qk;
212 sliceCount_[binNo] += 1;
213 }
214 }
215 }
216 writeQz();
217 }
218
219 void TetrahedralityParamZ::writeQz() {
220
221 // compute average box length:
222
223 RealType zSum = 0.0;
224 for (std::vector<RealType>::iterator j = zBox_.begin();
225 j != zBox_.end(); ++j) {
226 zSum += *j;
227 }
228 RealType zAve = zSum / zBox_.size();
229
230 std::ofstream qZstream(outputFilename_.c_str());
231 if (qZstream.is_open()) {
232 qZstream << "#Tetrahedrality Parameters (z)\n";
233 qZstream << "#nFrames:\t" << zBox_.size() << "\n";
234 qZstream << "#selection 1: (" << selectionScript1_ << ")\n";
235 qZstream << "#selection 2: (" << selectionScript2_ << ")\n";
236 qZstream << "#z\tQk\n";
237 for (unsigned int i = 0; i < sliceQ_.size(); ++i) {
238 RealType z = zAve * (i+0.5) / sliceQ_.size();
239 if (sliceCount_[i] != 0) {
240 qZstream << z << "\t" << sliceQ_[i] / sliceCount_[i] << "\n";
241 }
242 }
243
244 } else {
245 sprintf(painCave.errMsg, "TetrahedralityParamZ: unable to open %s\n",
246 outputFilename_.c_str());
247 painCave.isFatal = 1;
248 simError();
249 }
250 qZstream.close();
251 }
252 }
253
254
255

Properties

Name Value
svn:executable *