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, 4 months ago) by gezelter
File size: 8835 byte(s)
Log Message:
Reducing the number of warnings when using g++ to compile.

File Contents

# User Rev Content
1 plouden 1762 /*
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 gezelter 1843 *
36 plouden 1762 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
37     * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
38 gezelter 1879 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
39 gezelter 1843 * [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 plouden 1762 */
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 gezelter 1843 namespace OpenMD {
55     TetrahedralityParamZ::TetrahedralityParamZ(SimInfo* info,
56     const std::string& filename,
57 gezelter 1846 const std::string& sele1,
58     const std::string& sele2,
59 gezelter 1843 double rCut, int nzbins)
60 gezelter 2071 : StaticAnalyser(info, filename),
61     selectionScript1_(sele1), selectionScript2_(sele2),
62     seleMan1_(info), seleMan2_(info), evaluator1_(info), evaluator2_(info),
63     nZBins_(nzbins) {
64 plouden 1762
65 gezelter 1846 evaluator1_.loadScriptString(sele1);
66     if (!evaluator1_.isDynamic()) {
67     seleMan1_.setSelectionSet(evaluator1_.evaluate());
68 gezelter 1843 }
69 gezelter 1846 evaluator2_.loadScriptString(sele2);
70     if (!evaluator2_.isDynamic()) {
71     seleMan2_.setSelectionSet(evaluator2_.evaluate());
72     }
73 gezelter 1843
74     // Set up cutoff radius:
75 plouden 1762 rCut_ = rCut;
76    
77 gezelter 1843 // 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 plouden 1762 }
85    
86 gezelter 1843 TetrahedralityParamZ::~TetrahedralityParamZ() {
87     sliceQ_.clear();
88     sliceCount_.clear();
89     zBox_.clear();
90 plouden 1762 }
91 gezelter 1843
92     void TetrahedralityParamZ::process() {
93 plouden 1762 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 gezelter 1843 Vector3d ri, rj, rk, rik, rkj;
104 plouden 1762 RealType r;
105     RealType cospsi;
106     RealType Qk;
107 gezelter 1843 std::vector<std::pair<RealType,StuntDouble*> > myNeighbors;
108 gezelter 1846 int isd1;
109     int isd2;
110 gezelter 1767
111 plouden 1762 DumpReader reader(info_, dumpFilename_);
112     int nFrames = reader.getNFrames();
113    
114 gezelter 1796 for (int istep = 0; istep < nFrames; istep += step_) {
115     reader.readFrame(istep);
116     currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
117    
118 gezelter 1843 Mat3x3d hmat = currentSnapshot_->getHmat();
119     zBox_.push_back(hmat(2,2));
120    
121     RealType halfBoxZ_ = hmat(2,2) / 2.0;
122    
123 gezelter 1846 if (evaluator1_.isDynamic()) {
124     seleMan1_.setSelectionSet(evaluator1_.evaluate());
125 gezelter 1796 }
126 gezelter 1843
127 gezelter 1846 if (evaluator2_.isDynamic()) {
128     seleMan2_.setSelectionSet(evaluator2_.evaluate());
129     }
130    
131 plouden 1762 // update the positions of atoms which belong to the rigidbodies
132 gezelter 1796 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 gezelter 1843 }
138     }
139    
140 gezelter 1796 // outer loop is over the selected StuntDoubles:
141 gezelter 1846 for (sd = seleMan1_.beginSelected(isd1); sd != NULL;
142     sd = seleMan1_.nextSelected(isd1)) {
143 gezelter 1843
144 gezelter 1796 myIndex = sd->getGlobalIndex();
145 gezelter 1846
146 gezelter 1796 Qk = 1.0;
147 gezelter 1846 myNeighbors.clear();
148 gezelter 1843
149 gezelter 1846 for (sd2 = seleMan2_.beginSelected(isd2); sd2 != NULL;
150     sd2 = seleMan2_.nextSelected(isd2)) {
151    
152     if (sd2->getGlobalIndex() != myIndex) {
153 gezelter 1796
154 gezelter 1846 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 gezelter 1796 }
166     }
167     }
168    
169     // Sort the vector using predicate and std::sort
170 gezelter 1843 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 gezelter 1796 int nang = int (0.5 * (nbors * (nbors - 1)));
176 gezelter 1843
177 gezelter 1796 rk = sd->getPos();
178 gezelter 1846
179 gezelter 1843 for (int i = 0; i < nbors-1; i++) {
180 gezelter 1846
181 gezelter 1796 sdi = myNeighbors[i].second;
182     ri = sdi->getPos();
183     rik = rk - ri;
184     if (usePeriodicBoundaryConditions_)
185 gezelter 1843 currentSnapshot_->wrapVector(rik);
186    
187 gezelter 1796 rik.normalize();
188 gezelter 1846
189 gezelter 1843 for (int j = i+1; j < nbors; j++) {
190 gezelter 1846
191 gezelter 1796 sdj = myNeighbors[j].second;
192     rj = sdj->getPos();
193     rkj = rk - rj;
194     if (usePeriodicBoundaryConditions_)
195     currentSnapshot_->wrapVector(rkj);
196     rkj.normalize();
197    
198 gezelter 1843 cospsi = dot(rik,rkj);
199 gezelter 1846
200 gezelter 1796 // Calculates scaled Qk for each molecule using calculated
201     // angles from 4 or fewer nearest neighbors.
202 gezelter 1843 Qk -= (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);
203 gezelter 1796 }
204     }
205 gezelter 1846
206 gezelter 1796 if (nang > 0) {
207 gezelter 1843 if (usePeriodicBoundaryConditions_)
208     currentSnapshot_->wrapVector(rk);
209 gezelter 1796
210 gezelter 1843 int binNo = int(nZBins_ * (halfBoxZ_ + rk.z()) / hmat(2,2));
211     sliceQ_[binNo] += Qk;
212     sliceCount_[binNo] += 1;
213     }
214 plouden 1762 }
215 gezelter 1796 }
216 gezelter 1843 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 gezelter 1796 }
228 gezelter 1843 RealType zAve = zSum / zBox_.size();
229 plouden 1762
230 gezelter 1843 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 gezelter 1846 qZstream << "#selection 1: (" << selectionScript1_ << ")\n";
235     qZstream << "#selection 2: (" << selectionScript2_ << ")\n";
236 gezelter 1843 qZstream << "#z\tQk\n";
237     for (unsigned int i = 0; i < sliceQ_.size(); ++i) {
238     RealType z = zAve * (i+0.5) / sliceQ_.size();
239 gezelter 2025 if (sliceCount_[i] != 0) {
240     qZstream << z << "\t" << sliceQ_[i] / sliceCount_[i] << "\n";
241     }
242 gezelter 1843 }
243    
244     } else {
245 gezelter 1796 sprintf(painCave.errMsg, "TetrahedralityParamZ: unable to open %s\n",
246 gezelter 1843 outputFilename_.c_str());
247 gezelter 1796 painCave.isFatal = 1;
248     simError();
249 gezelter 1843 }
250     qZstream.close();
251 plouden 1762 }
252     }
253    
254    
255    

Properties

Name Value
svn:executable *