ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/TetrahedralityParam.cpp
Revision: 1524
Committed: Fri Nov 19 20:48:18 2010 UTC (14 years, 5 months ago) by kstocke1
File size: 10301 byte(s)
Log Message:
added missing files

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 * Created by J. Daniel Gezelter on 09/26/06.
42 * @author J. Daniel Gezelter
43 * @version $Id: BondOrderParameter.cpp 1442 2010-05-10 17:28:26Z gezelter $
44 *
45 */
46
47 #include "applications/staticProps/TetrahedralityParam.hpp"
48 #include "utils/simError.h"
49 #include "io/DumpReader.hpp"
50 #include "primitives/Molecule.hpp"
51 #include "utils/NumericConstant.hpp"
52 #include <vector>
53
54 namespace OpenMD {
55
56 TetrahedralityParam::TetrahedralityParam(SimInfo* info,
57 const std::string& filename,
58 const std::string& sele,
59 double rCut, int nbins) : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info){
60
61 setOutputName(getPrefix(filename) + ".q");
62
63 evaluator_.loadScriptString(sele);
64 if (!evaluator_.isDynamic()) {
65 seleMan_.setSelectionSet(evaluator_.evaluate());
66 }
67
68 // Set up cutoff radius:
69
70 rCut_ = rCut;
71 nBins_ = nbins;
72
73 Q_histogram_.resize(nBins_);
74
75 // Q can take values from 0 to 1
76
77 MinQ_ = 0.0;
78 MaxQ_ = 1.1;
79 deltaQ_ = (MaxQ_ - MinQ_) / nbins;
80
81 }
82
83 TetrahedralityParam::~TetrahedralityParam() {
84 Q_histogram_.clear();
85 }
86
87 void TetrahedralityParam::initalizeHistogram() {
88 std::fill(Q_histogram_.begin(), Q_histogram_.end(), 0);
89 }
90
91 void TetrahedralityParam::process() {
92 Molecule* mol;
93 StuntDouble* sd;
94 StuntDouble* sd2;
95 StuntDouble* sdi;
96 StuntDouble* sdj;
97 StuntDouble* sdk;
98 RigidBody* rb;
99 int myIndex;
100 SimInfo::MoleculeIterator mi;
101 Molecule::RigidBodyIterator rbIter;
102 Molecule::IntegrableObjectIterator ioi;
103 Vector3d vec;
104 Vector3d ri, rj, rk, rik, rkj, dposition, tposition;
105 RealType r;
106 RealType dist;
107 RealType cospsi;
108 RealType Qk;
109 std::vector<std::pair<RealType,StuntDouble*> > myNeighbors;
110 int isd;
111
112 DumpReader reader(info_, dumpFilename_);
113 int nFrames = reader.getNFrames();
114 frameCounter_ = 0;
115
116 Distorted_.clear();
117 Tetrahedral_.clear();
118
119 for (int istep = 0; istep < nFrames; istep += step_) {
120 reader.readFrame(istep);
121 frameCounter_++;
122 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
123
124 if (evaluator_.isDynamic()) {
125 seleMan_.setSelectionSet(evaluator_.evaluate());
126 }
127
128 // update the positions of atoms which belong to the rigidbodies
129
130 for (mol = info_->beginMolecule(mi); mol != NULL;
131 mol = info_->nextMolecule(mi)) {
132 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
133 rb = mol->nextRigidBody(rbIter)) {
134 rb->updateAtoms();
135 }
136 }
137
138
139 // outer loop is over the selected StuntDoubles:
140
141 for (sd = seleMan_.beginSelected(isd); sd != NULL;
142 sd = seleMan_.nextSelected(isd)) {
143
144 myIndex = sd->getGlobalIndex();
145 Qk = 1.0;
146
147 myNeighbors.clear();
148
149 // inner loop is over all StuntDoubles in the system:
150
151 for (mol = info_->beginMolecule(mi); mol != NULL;
152 mol = info_->nextMolecule(mi)) {
153
154 for (sd2 = mol->beginIntegrableObject(ioi); sd2 != NULL;
155 sd2 = mol->nextIntegrableObject(ioi)) {
156
157 if (sd2->getGlobalIndex() != myIndex) {
158
159 vec = sd->getPos() - sd2->getPos();
160
161 if (usePeriodicBoundaryConditions_)
162 currentSnapshot_->wrapVector(vec);
163
164 r = vec.length();
165
166 // Check to see if neighbor is in bond cutoff
167
168 if (r < rCut_) {
169
170 myNeighbors.push_back(std::make_pair(r,sd2));
171 }
172 }
173 }
174 }
175
176 // Sort the vector using predicate and std::sort
177 std::sort(myNeighbors.begin(), myNeighbors.end());
178
179 std::cerr << myNeighbors.size() << " neighbors within " << rCut_ << " A" << " \n";
180
181 // Use only the 4 closest neighbors to do the rest of the work:
182
183 int nbors = myNeighbors.size();
184 // > 4 ? 4 : myNeighbors.size();
185 int nang = int (0.5 * (nbors * (nbors - 1)));
186
187 rk = sd->getPos();
188
189 for (int i = 0; i < nbors-1; i++) {
190
191 sdi = myNeighbors[i].second;
192 ri = sdi->getPos();
193 rik = rk - ri;
194 if (usePeriodicBoundaryConditions_)
195 currentSnapshot_->wrapVector(rik);
196
197 rik.normalize();
198
199 for (int j = i+1; j < nbors; j++) {
200
201 sdj = myNeighbors[j].second;
202 rj = sdj->getPos();
203 rkj = rk - rj;
204 if (usePeriodicBoundaryConditions_)
205 currentSnapshot_->wrapVector(rkj);
206 rkj.normalize();
207
208 cospsi = dot(rik,rkj);
209
210 //std::cerr << "cos(psi) = " << cospsi << " \n";
211
212 // Calculates scaled Qk for each molecule using calculated angles from 4 or fewer nearest neighbors.
213 Qk = Qk - (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);
214
215 }
216 }
217
218 if (nang > 0) {
219 collectHistogram(Qk);
220
221 // Saves positions of StuntDoubles & neighbors with distorted coordination (low Qk value)
222 if ((Qk < 0.55) && (Qk > 0.45)) {
223
224 Distorted_.push_back(sd);
225
226 dposition = sd->getPos();
227 //std::cerr << "distorted position \t" << dposition << "\n";
228 }
229
230 // Saves positions of StuntDoubles & neighbors with tetrahedral coordination (high Qk value)
231 if (Qk > 0.95) {
232
233 Tetrahedral_.push_back(sd);
234
235 tposition = sd->getPos();
236 //std::cerr << "tetrahedral position \t" << tposition << "\n";
237 }
238
239 }
240
241 }
242 }
243
244 writeOrderParameter();
245 std::cerr << "number of distorted StuntDoubles = " << Distorted_.size() << "\n";
246 std::cerr << "number of tetrahedral StuntDoubles = " << Tetrahedral_.size() << "\n";
247 }
248
249 void TetrahedralityParam::collectHistogram(RealType Qk) {
250
251 if (Qk > MinQ_ && Qk < MaxQ_) {
252
253 int whichBin = int((Qk - MinQ_) / deltaQ_);
254 Q_histogram_[whichBin] += 1;
255 }
256 }
257
258
259 void TetrahedralityParam::writeOrderParameter() {
260
261 int nSelected = 0;
262
263 for (int i = 0; i < nBins_; ++i) {
264 nSelected = nSelected + Q_histogram_[i]*deltaQ_;
265 }
266
267 std::ofstream osq((getOutputFileName() + "Q").c_str());
268
269 if (osq.is_open()) {
270
271 osq << "# Tetrahedrality Parameters\n";
272 osq << "# selection: (" << selectionScript_ << ")\n";
273 osq << "# \n";
274 // Normalize by number of frames and write it out:
275 for (int i = 0; i < nBins_; ++i) {
276 RealType Qval = MinQ_ + (i + 0.5) * deltaQ_;
277 osq << Qval;
278 osq << "\t" << (RealType) (Q_histogram_[i]/deltaQ_)/nSelected;
279 osq << "\n";
280 }
281
282 osq.close();
283
284 }else {
285 sprintf(painCave.errMsg, "TetrahedralityParam: unable to open %s\n",
286 (getOutputFileName() + "q").c_str());
287 painCave.isFatal = 1;
288 simError();
289 }
290
291 DumpReader reader(info_, dumpFilename_);
292 int nFrames = reader.getNFrames();
293
294 if (nFrames == 1) {
295
296 std::vector<StuntDouble*>::iterator iter;
297 std::ofstream osd((getOutputFileName() + "dxyz").c_str());
298
299 if (osd.is_open()) {
300
301 osd << Distorted_.size() << "\n";
302
303 osd << "1000000.00000000; 34.52893134 0.00000000 0.00000000; 0.00000000 34.52893134 0.00000000; 0.00000000 0.00000000 34.52893134" << "\n";
304
305 for (iter = Distorted_.begin(); iter != Distorted_.end(); ++iter) {
306
307 Vector3d position;
308
309 position = (*iter)->getPos();
310
311 osd << "O " << "\t";
312
313 for (int z=0; z<position.size(); z++) {
314
315 osd << position[z] << " " << "\t";
316 }
317
318 osd << "\n";
319
320 }
321
322 osd.close();
323 }
324
325
326 std::ofstream ost((getOutputFileName() + "txyz").c_str());
327
328 if (ost.is_open()) {
329
330 ost << Tetrahedral_.size() << "\n";
331
332 ost << "1000000.00000000; 34.52893134 0.00000000 0.00000000; 0.00000000 34.52893134 0.00000000; 0.00000000 0.00000000 34.52893134" << "\n";
333
334 for (iter = Tetrahedral_.begin(); iter != Tetrahedral_.end(); ++iter) {
335
336 Vector3d position;
337
338 position = (*iter)->getPos();
339
340 ost << "O " << "\t";
341
342 for (int z=0; z<position.size(); z++) {
343
344 ost << position[z] << " " << "\t";
345 }
346
347 ost << "\n";
348
349 }
350
351 ost.close();
352 }
353
354 }
355 }
356 }
357
358
359

Properties

Name Value
svn:executable *