ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/BOPofR.cpp
Revision: 1128
Committed: Wed Apr 11 23:27:20 2007 UTC (18 years ago) by chuckv
File size: 11826 byte(s)
Log Message:
Added Bond Order Parameter as a function of radius.

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. Acknowledgement of the program authors must be made in any
10 * publication of scientific results based in part on use of the
11 * program. An acceptable form of acknowledgement is citation of
12 * the article in which the program was described (Matthew
13 * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 * Parallel Simulation Engine for Molecular Dynamics,"
16 * J. Comput. Chem. 26, pp. 252-271 (2005))
17 *
18 * 2. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * 3. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the
24 * distribution.
25 *
26 * This software is provided "AS IS," without a warranty of any
27 * kind. All express or implied conditions, representations and
28 * warranties, including any implied warranty of merchantability,
29 * fitness for a particular purpose or non-infringement, are hereby
30 * excluded. The University of Notre Dame and its licensors shall not
31 * be liable for any damages suffered by licensee as a result of
32 * using, modifying or distributing the software or its
33 * derivatives. In no event will the University of Notre Dame or its
34 * licensors be liable for any lost revenue, profit or data, or for
35 * direct, indirect, special, consequential, incidental or punitive
36 * damages, however caused and regardless of the theory of liability,
37 * arising out of the use of or inability to use software, even if the
38 * University of Notre Dame has been advised of the possibility of
39 * such damages.
40 *
41 * BondOrderParameter.cpp
42 * OOPSE-4
43 *
44 * Created by J. Daniel Gezelter on 09/26/06.
45 * @author J. Daniel Gezelter
46 * @version $Id: BOPofR.cpp,v 1.1 2007-04-11 23:27:20 chuckv Exp $
47 *
48 */
49
50 #include "applications/staticProps/BOPofR.hpp"
51 #include "utils/simError.h"
52 #include "io/DumpReader.hpp"
53 #include "primitives/Molecule.hpp"
54 #include "utils/NumericConstant.hpp"
55
56
57 namespace oopse {
58
59 BOPofR::BOPofR(SimInfo* info, const std::string& filename, const std::string& sele, double rCut,
60 int nbins, RealType len) : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info){
61
62 setOutputName(getPrefix(filename) + ".bo");
63
64 evaluator_.loadScriptString(sele);
65 if (!evaluator_.isDynamic()) {
66 seleMan_.setSelectionSet(evaluator_.evaluate());
67 }
68
69 // Set up cutoff radius and order of the Legendre Polynomial:
70
71 rCut_ = rCut;
72 nBins_ = nbins;
73 len_ = len;
74
75 deltaR_ = len_/nBins_;
76 RCount_.resize(nBins_);
77 WofR_.resize(nBins_);
78 QofR_.resize(nBins_);
79
80 // Make arrays for Wigner3jm
81 double* THRCOF = new double[2*lMax_+1];
82 // Variables for Wigner routine
83 double lPass, m1Pass, m2m, m2M;
84 int error, mSize;
85 mSize = 2*lMax_+1;
86
87 for (int l = 0; l <= lMax_; l++) {
88 lPass = (double)l;
89 for (int m1 = -l; m1 <= l; m1++) {
90 m1Pass = (double)m1;
91
92 std::pair<int,int> lm = std::make_pair(l, m1);
93
94 // Zero work array
95 for (int ii = 0; ii < 2*l + 1; ii++){
96 THRCOF[ii] = 0.0;
97 }
98
99 // Get Wigner coefficients
100 Wigner3jm(&lPass, &lPass, &lPass,
101 &m1Pass, &m2m, &m2M,
102 THRCOF, &mSize, &error);
103
104 m2Min[lm] = (int)floor(m2m);
105 m2Max[lm] = (int)floor(m2M);
106
107 for (int mmm = 0; mmm <= (int)(m2M - m2m); mmm++) {
108 w3j[lm].push_back(THRCOF[mmm]);
109 }
110 }
111 }
112
113 delete [] THRCOF;
114 THRCOF = NULL;
115
116
117 for (int bin = 0; bin < nBins_; bin++) {
118 QofR_[bin].resize(lMax_ + 1);
119 WofR_[bin].resize(lMax_ + 1 );
120 RCount_[bin].resize(lMax_ + 1);
121
122 for (int l = 0; l <= lMax_; l++) {
123 QofR_[bin][l] = 0.0;
124 WofR_[bin][l] = 0.0;
125 RCount_[bin][l] = 1;
126 }
127
128 }
129
130 }
131
132 BOPofR::~BOPofR() {
133 /*
134 std::cerr << "Freeing stuff" << std::endl;
135 for (int l = 0; l <= lMax_; l++) {
136 for (int m = -l; m <= l; m++) {
137 w3j[std::make_pair(l,m)].clear();
138 }
139 }
140 std::cerr << "w3j made free...." << std::endl;
141 for (int bin = 0; bin < nBins_; bin++) {
142 QofR_[bin].clear();
143 WofR_[bin].clear();
144 RCount_[bin].clear();
145 }
146 std::cout << "R arrays made free...." << std::endl;
147 w3j.clear();
148 m2Min.clear();
149 m2Max.clear();
150 RCount_.clear();
151 WofR_.clear();
152 QofR_.clear();
153 */
154 }
155
156
157 void BOPofR::initalizeHistogram() {
158 for (int bin = 0; bin < nBins_; bin++) {
159 QofR_[bin].resize(lMax_);
160 WofR_[bin].resize(lMax_);
161 RCount_[bin].resize(lMax_);
162 for (int l = 0; l <= lMax_; l++) {
163 QofR_[bin][l] = 0;
164 WofR_[bin][l] = 0;
165 RCount_[bin][l] = 0;
166 }
167 }
168 }
169
170
171 void BOPofR::process() {
172 Molecule* mol;
173 Atom* atom;
174 RigidBody* rb;
175 int myIndex;
176 SimInfo::MoleculeIterator mi;
177 Molecule::RigidBodyIterator rbIter;
178 Molecule::AtomIterator ai;
179 StuntDouble* sd;
180 Vector3d vec;
181 RealType costheta;
182 RealType phi;
183 RealType r;
184 RealType dist;
185 Vector3d rCOM;
186 RealType distCOM;
187 Vector3d pos;
188 Vector3d CenterOfMass;
189 std::map<std::pair<int,int>,ComplexType> q;
190 std::vector<RealType> q_l;
191 std::vector<RealType> q2;
192 std::vector<ComplexType> w;
193 std::vector<ComplexType> w_hat;
194 std::map<std::pair<int,int>,ComplexType> QBar;
195 std::vector<RealType> Q2;
196 std::vector<RealType> Q;
197 std::vector<ComplexType> W;
198 std::vector<ComplexType> W_hat;
199 int nBonds, Nbonds;
200 SphericalHarmonic sphericalHarmonic;
201 int i, j;
202
203 DumpReader reader(info_, dumpFilename_);
204 int nFrames = reader.getNFrames();
205 frameCounter_ = 0;
206
207 q_l.resize(lMax_+1);
208 q2.resize(lMax_+1);
209 w.resize(lMax_+1);
210 w_hat.resize(lMax_+1);
211
212 Q2.resize(lMax_+1);
213 Q.resize(lMax_+1);
214 W.resize(lMax_+1);
215 W_hat.resize(lMax_+1);
216 Nbonds = 0;
217
218 for (int istep = 0; istep < nFrames; istep += step_) {
219 reader.readFrame(istep);
220 frameCounter_++;
221 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
222 CenterOfMass = info_->getCom();
223 if (evaluator_.isDynamic()) {
224 seleMan_.setSelectionSet(evaluator_.evaluate());
225 }
226
227 // update the positions of atoms which belong to the rigidbodies
228
229 for (mol = info_->beginMolecule(mi); mol != NULL;
230 mol = info_->nextMolecule(mi)) {
231 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
232 rb = mol->nextRigidBody(rbIter)) {
233 rb->updateAtoms();
234 }
235 }
236
237 // outer loop is over the selected StuntDoubles:
238
239 for (sd = seleMan_.beginSelected(i); sd != NULL;
240 sd = seleMan_.nextSelected(i)) {
241
242 myIndex = sd->getGlobalIndex();
243
244 nBonds = 0;
245
246 for (int l = 0; l <= lMax_; l++) {
247 for (int m = -l; m <= l; m++) {
248 q[std::make_pair(l,m)] = 0.0;
249 }
250 }
251 pos = sd->getPos();
252 rCOM = CenterOfMass - pos;
253 if (usePeriodicBoundaryConditions_)
254 currentSnapshot_->wrapVector(rCOM);
255 distCOM = rCOM.length();
256
257 // inner loop is over all other atoms in the system:
258
259 for (mol = info_->beginMolecule(mi); mol != NULL;
260 mol = info_->nextMolecule(mi)) {
261 for (atom = mol->beginAtom(ai); atom != NULL;
262 atom = mol->nextAtom(ai)) {
263
264 if (atom->getGlobalIndex() != myIndex) {
265 vec = pos - atom->getPos();
266
267 if (usePeriodicBoundaryConditions_)
268 currentSnapshot_->wrapVector(vec);
269
270 // Calculate "bonds" and build Q_lm(r) where
271 // Q_lm = Y_lm(theta(r),phi(r))
272 // The spherical harmonics are wrt any arbitrary coordinate
273 // system, we choose standard spherical coordinates
274
275 r = vec.length();
276
277 // Check to see if neighbor is in bond cutoff
278
279 if (r < rCut_) {
280 costheta = vec.z() / r;
281 phi = atan2(vec.y(), vec.x());
282
283 for (int l = 0; l <= lMax_; l++) {
284 sphericalHarmonic.setL(l);
285 for(int m = -l; m <= l; m++){
286 sphericalHarmonic.setM(m);
287 q[std::make_pair(l,m)] += sphericalHarmonic.getValueAt(costheta, phi);
288 }
289 }
290 nBonds++;
291 }
292 }
293 }
294 }
295
296
297 for (int l = 0; l <= lMax_; l++) {
298 q2[l] = 0.0;
299 for (int m = -l; m <= l; m++){
300 q[std::make_pair(l,m)] /= (RealType)nBonds;
301 q2[l] += norm(q[std::make_pair(l,m)]);
302 }
303 q_l[l] = sqrt(q2[l] * 4.0 * NumericConstant::PI / (RealType)(2*l + 1));
304 }
305
306 // Find Third Order Invariant W_l
307
308 for (int l = 0; l <= lMax_; l++) {
309 w[l] = 0.0;
310 for (int m1 = -l; m1 <= l; m1++) {
311 std::pair<int,int> lm = std::make_pair(l, m1);
312 for (int mmm = 0; mmm <= (m2Max[lm] - m2Min[lm]); mmm++) {
313 int m2 = m2Min[lm] + mmm;
314 int m3 = -m1-m2;
315 w[l] += w3j[lm][mmm] * q[lm] *
316 q[std::make_pair(l,m2)] * q[std::make_pair(l,m3)];
317 }
318 }
319
320 w_hat[l] = w[l] / pow(q2[l], 1.5);
321 }
322
323 collectHistogram(q_l, w_hat, distCOM);
324 if(real(w_hat[6]) < -0.1){
325 std::cout << real(w_hat[6]) << pos << std::endl;
326 }
327 }
328 }
329
330 writeOrderParameter();
331 }
332
333 void BOPofR::collectHistogram(std::vector<RealType> q,
334 std::vector<ComplexType> what, RealType distCOM) {
335
336 if ( distCOM < len_){
337 // Figure out where this distance goes...
338 int whichBin = distCOM / deltaR_;
339
340
341 for (int l = 0; l <= lMax_; l++) {
342 RCount_[whichBin][l]++;
343 QofR_[whichBin][l]=q[l];
344 WofR_[whichBin][l]=real(what[l]);
345 }
346
347 }
348
349 }
350
351 void BOPofR::writeOrderParameter() {
352
353 std::ofstream osq((getOutputFileName() + "qr").c_str());
354
355 if (osq.is_open()) {
356
357 // Normalize by number of frames and write it out:
358
359 for (int i = 0; i < nBins_; ++i) {
360 RealType Rval = (i + 0.5) * deltaR_;
361 osq << Rval;
362 for (int l = 0; l <= lMax_; l++) {
363
364 osq << "\t" << (RealType)QofR_[i][l]/(RealType)RCount_[i][l];
365 }
366 osq << "\n";
367 }
368
369 osq.close();
370
371 } else {
372 sprintf(painCave.errMsg, "BOPofR: unable to open %s\n",
373 (getOutputFileName() + "q").c_str());
374 painCave.isFatal = 1;
375 simError();
376 }
377
378 std::ofstream osw((getOutputFileName() + "wr").c_str());
379
380 if (osw.is_open()) {
381 // Normalize by number of frames and write it out:
382 for (int i = 0; i < nBins_; ++i) {
383 RealType Rval = deltaR_ * (i + 0.5);
384 osw << Rval;
385 for (int l = 0; l <= lMax_; l++) {
386
387 osw << "\t" << (RealType)WofR_[i][l]/(RealType)RCount_[i][l];
388 }
389 osw << "\n";
390 }
391
392 osw.close();
393 } else {
394 sprintf(painCave.errMsg, "BOPofR: unable to open %s\n",
395 (getOutputFileName() + "w").c_str());
396 painCave.isFatal = 1;
397 simError();
398
399 }
400
401 }
402 }

Properties

Name Value
svn:executable *