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