ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/staticProps/TetrahedralityParam.cpp
Revision: 1762
Committed: Thu Jun 28 20:17:33 2012 UTC (12 years, 10 months ago) by plouden
File size: 10557 byte(s)
Log Message:
Calculates the tetrahedrality parameter as a function of zbins. Abandon all hope ye who enter here.

File Contents

# User Rev Content
1 gezelter 1629 /*
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 gezelter 1665 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40     * [4] , Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). *
41 gezelter 1629 * 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 plouden 1762 int nbors = myNeighbors.size()> 4 ? 4 : myNeighbors.size();
184 gezelter 1629 int nang = int (0.5 * (nbors * (nbors - 1)));
185    
186     rk = sd->getPos();
187 plouden 1762 std::cerr<<nbors<<endl;
188 gezelter 1629 for (int i = 0; i < nbors-1; i++) {
189    
190     sdi = myNeighbors[i].second;
191     ri = sdi->getPos();
192     rik = rk - ri;
193     if (usePeriodicBoundaryConditions_)
194     currentSnapshot_->wrapVector(rik);
195    
196     rik.normalize();
197    
198     for (int j = i+1; j < nbors; j++) {
199    
200     sdj = myNeighbors[j].second;
201     rj = sdj->getPos();
202     rkj = rk - rj;
203     if (usePeriodicBoundaryConditions_)
204     currentSnapshot_->wrapVector(rkj);
205     rkj.normalize();
206    
207     cospsi = dot(rik,rkj);
208    
209     //std::cerr << "cos(psi) = " << cospsi << " \n";
210    
211     // Calculates scaled Qk for each molecule using calculated angles from 4 or fewer nearest neighbors.
212     Qk = Qk - (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);
213 plouden 1762 //std::cerr<<Qk<<"\t"<<nang<<endl;
214 gezelter 1629 }
215     }
216 plouden 1762 //std::cerr<<nang<<endl;
217 gezelter 1629 if (nang > 0) {
218     collectHistogram(Qk);
219    
220     // Saves positions of StuntDoubles & neighbors with distorted coordination (low Qk value)
221     if ((Qk < 0.55) && (Qk > 0.45)) {
222 plouden 1762 //std::cerr<<Distorted_.size()<<endl;
223 gezelter 1629 Distorted_.push_back(sd);
224 plouden 1762 //std::cerr<<Distorted_.size()<<endl;
225 gezelter 1629 dposition = sd->getPos();
226     //std::cerr << "distorted position \t" << dposition << "\n";
227     }
228    
229     // Saves positions of StuntDoubles & neighbors with tetrahedral coordination (high Qk value)
230 plouden 1762 if (Qk > 0.05) {
231 gezelter 1629
232     Tetrahedral_.push_back(sd);
233    
234     tposition = sd->getPos();
235     //std::cerr << "tetrahedral position \t" << tposition << "\n";
236     }
237    
238 plouden 1762 //std::cerr<<Tetrahedral_.size()<<endl;
239    
240    
241 gezelter 1629 }
242    
243     }
244     }
245    
246     writeOrderParameter();
247     std::cerr << "number of distorted StuntDoubles = " << Distorted_.size() << "\n";
248     std::cerr << "number of tetrahedral StuntDoubles = " << Tetrahedral_.size() << "\n";
249     }
250    
251     void TetrahedralityParam::collectHistogram(RealType Qk) {
252    
253     if (Qk > MinQ_ && Qk < MaxQ_) {
254    
255     int whichBin = int((Qk - MinQ_) / deltaQ_);
256     Q_histogram_[whichBin] += 1;
257     }
258     }
259    
260    
261     void TetrahedralityParam::writeOrderParameter() {
262    
263     int nSelected = 0;
264    
265     for (int i = 0; i < nBins_; ++i) {
266     nSelected = nSelected + Q_histogram_[i]*deltaQ_;
267     }
268    
269     std::ofstream osq((getOutputFileName() + "Q").c_str());
270    
271     if (osq.is_open()) {
272    
273     osq << "# Tetrahedrality Parameters\n";
274     osq << "# selection: (" << selectionScript_ << ")\n";
275     osq << "# \n";
276     // Normalize by number of frames and write it out:
277     for (int i = 0; i < nBins_; ++i) {
278     RealType Qval = MinQ_ + (i + 0.5) * deltaQ_;
279     osq << Qval;
280     osq << "\t" << (RealType) (Q_histogram_[i]/deltaQ_)/nSelected;
281     osq << "\n";
282     }
283    
284     osq.close();
285    
286     }else {
287     sprintf(painCave.errMsg, "TetrahedralityParam: unable to open %s\n",
288     (getOutputFileName() + "q").c_str());
289     painCave.isFatal = 1;
290     simError();
291     }
292    
293     DumpReader reader(info_, dumpFilename_);
294     int nFrames = reader.getNFrames();
295    
296     if (nFrames == 1) {
297    
298     std::vector<StuntDouble*>::iterator iter;
299     std::ofstream osd((getOutputFileName() + "dxyz").c_str());
300    
301     if (osd.is_open()) {
302    
303     osd << Distorted_.size() << "\n";
304    
305     osd << "1000000.00000000; 34.52893134 0.00000000 0.00000000; 0.00000000 34.52893134 0.00000000; 0.00000000 0.00000000 34.52893134" << "\n";
306    
307     for (iter = Distorted_.begin(); iter != Distorted_.end(); ++iter) {
308    
309     Vector3d position;
310    
311     position = (*iter)->getPos();
312    
313     osd << "O " << "\t";
314    
315     for (int z=0; z<position.size(); z++) {
316    
317     osd << position[z] << " " << "\t";
318     }
319    
320     osd << "\n";
321    
322     }
323    
324     osd.close();
325     }
326    
327    
328     std::ofstream ost((getOutputFileName() + "txyz").c_str());
329    
330     if (ost.is_open()) {
331    
332     ost << Tetrahedral_.size() << "\n";
333    
334     ost << "1000000.00000000; 34.52893134 0.00000000 0.00000000; 0.00000000 34.52893134 0.00000000; 0.00000000 0.00000000 34.52893134" << "\n";
335    
336     for (iter = Tetrahedral_.begin(); iter != Tetrahedral_.end(); ++iter) {
337    
338     Vector3d position;
339    
340     position = (*iter)->getPos();
341    
342     ost << "O " << "\t";
343    
344     for (int z=0; z<position.size(); z++) {
345    
346     ost << position[z] << " " << "\t";
347     }
348    
349     ost << "\n";
350    
351     }
352    
353     ost.close();
354     }
355    
356     }
357     }
358     }
359    
360    
361    

Properties

Name Value
svn:eol-style native
svn:executable *