ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/BOPofR.cpp
Revision: 1390
Committed: Wed Nov 25 20:02:06 2009 UTC (15 years, 5 months ago) by gezelter
File size: 11516 byte(s)
Log Message:
Almost all of the changes necessary to create OpenMD out of our old
project (OOPSE-4)

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: BOPofR.cpp,v 1.4 2009-11-25 20:01:58 gezelter Exp $
44 *
45 */
46
47 #include "applications/staticProps/BOPofR.hpp"
48 #include "utils/simError.h"
49 #include "io/DumpReader.hpp"
50 #include "primitives/Molecule.hpp"
51 #include "utils/NumericConstant.hpp"
52
53
54 namespace OpenMD {
55
56 BOPofR::BOPofR(SimInfo* info, const std::string& filename, const std::string& sele, double rCut,
57 int nbins, RealType len) : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info){
58
59 setOutputName(getPrefix(filename) + ".bo");
60
61 evaluator_.loadScriptString(sele);
62 if (!evaluator_.isDynamic()) {
63 seleMan_.setSelectionSet(evaluator_.evaluate());
64 }
65
66 // Set up cutoff radius and order of the Legendre Polynomial:
67
68 rCut_ = rCut;
69 nBins_ = nbins;
70 len_ = len;
71
72 deltaR_ = len_/nBins_;
73 RCount_.resize(nBins_);
74 WofR_.resize(nBins_);
75 QofR_.resize(nBins_);
76
77 for (int i = 0; i < nBins_; i++){
78 RCount_[i] = 0;
79 WofR_[i] = 0;
80 QofR_[i] = 0;
81 }
82
83 // Make arrays for Wigner3jm
84 double* THRCOF = new double[2*lMax_+1];
85 // Variables for Wigner routine
86 double lPass, m1Pass, m2m, m2M;
87 int error, mSize;
88 mSize = 2*lMax_+1;
89
90 for (int l = 0; l <= lMax_; l++) {
91 lPass = (double)l;
92 for (int m1 = -l; m1 <= l; m1++) {
93 m1Pass = (double)m1;
94
95 std::pair<int,int> lm = std::make_pair(l, m1);
96
97 // Zero work array
98 for (int ii = 0; ii < 2*l + 1; ii++){
99 THRCOF[ii] = 0.0;
100 }
101
102 // Get Wigner coefficients
103 Wigner3jm(&lPass, &lPass, &lPass,
104 &m1Pass, &m2m, &m2M,
105 THRCOF, &mSize, &error);
106
107 m2Min[lm] = (int)floor(m2m);
108 m2Max[lm] = (int)floor(m2M);
109
110 for (int mmm = 0; mmm <= (int)(m2M - m2m); mmm++) {
111 w3j[lm].push_back(THRCOF[mmm]);
112 }
113 }
114 }
115
116 delete [] THRCOF;
117 THRCOF = NULL;
118
119 }
120
121 BOPofR::~BOPofR() {
122 /*
123 std::cerr << "Freeing stuff" << std::endl;
124 for (int l = 0; l <= lMax_; l++) {
125 for (int m = -l; m <= l; m++) {
126 w3j[std::make_pair(l,m)].clear();
127 }
128 }
129 std::cerr << "w3j made free...." << std::endl;
130 for (int bin = 0; bin < nBins_; bin++) {
131 QofR_[bin].clear();
132 WofR_[bin].clear();
133 RCount_[bin].clear();
134 }
135 std::cout << "R arrays made free...." << std::endl;
136 w3j.clear();
137 m2Min.clear();
138 m2Max.clear();
139 RCount_.clear();
140 WofR_.clear();
141 QofR_.clear();
142 */
143 }
144
145
146 void BOPofR::initalizeHistogram() {
147 for (int i = 0; i < nBins_; i++){
148 RCount_[i] = 0;
149 WofR_[i] = 0;
150 QofR_[i] = 0;
151 }
152 }
153
154
155 void BOPofR::process() {
156 Molecule* mol;
157 Atom* atom;
158 RigidBody* rb;
159 int myIndex;
160 SimInfo::MoleculeIterator mi;
161 Molecule::RigidBodyIterator rbIter;
162 Molecule::AtomIterator ai;
163 StuntDouble* sd;
164 Vector3d vec;
165 RealType costheta;
166 RealType phi;
167 RealType r;
168 RealType dist;
169 Vector3d rCOM;
170 RealType distCOM;
171 Vector3d pos;
172 Vector3d CenterOfMass;
173 std::map<std::pair<int,int>,ComplexType> q;
174 std::vector<RealType> q_l;
175 std::vector<RealType> q2;
176 std::vector<ComplexType> w;
177 std::vector<ComplexType> w_hat;
178 std::map<std::pair<int,int>,ComplexType> QBar;
179 std::vector<RealType> Q2;
180 std::vector<RealType> Q;
181 std::vector<ComplexType> W;
182 std::vector<ComplexType> W_hat;
183 int nBonds, Nbonds;
184 SphericalHarmonic sphericalHarmonic;
185 int i, j;
186
187 DumpReader reader(info_, dumpFilename_);
188 int nFrames = reader.getNFrames();
189 frameCounter_ = 0;
190
191 q_l.resize(lMax_+1);
192 q2.resize(lMax_+1);
193 w.resize(lMax_+1);
194 w_hat.resize(lMax_+1);
195
196 Q2.resize(lMax_+1);
197 Q.resize(lMax_+1);
198 W.resize(lMax_+1);
199 W_hat.resize(lMax_+1);
200 Nbonds = 0;
201
202 for (int istep = 0; istep < nFrames; istep += step_) {
203 reader.readFrame(istep);
204 frameCounter_++;
205 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
206 CenterOfMass = info_->getCom();
207 if (evaluator_.isDynamic()) {
208 seleMan_.setSelectionSet(evaluator_.evaluate());
209 }
210
211 // update the positions of atoms which belong to the rigidbodies
212
213 for (mol = info_->beginMolecule(mi); mol != NULL;
214 mol = info_->nextMolecule(mi)) {
215 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
216 rb = mol->nextRigidBody(rbIter)) {
217 rb->updateAtoms();
218 }
219 }
220
221 // outer loop is over the selected StuntDoubles:
222
223 for (sd = seleMan_.beginSelected(i); sd != NULL;
224 sd = seleMan_.nextSelected(i)) {
225
226 myIndex = sd->getGlobalIndex();
227
228 nBonds = 0;
229
230 for (int l = 0; l <= lMax_; l++) {
231 for (int m = -l; m <= l; m++) {
232 q[std::make_pair(l,m)] = 0.0;
233 }
234 }
235 pos = sd->getPos();
236 rCOM = CenterOfMass - pos;
237 if (usePeriodicBoundaryConditions_)
238 currentSnapshot_->wrapVector(rCOM);
239 distCOM = rCOM.length();
240
241 // inner loop is over all other atoms in the system:
242
243 for (mol = info_->beginMolecule(mi); mol != NULL;
244 mol = info_->nextMolecule(mi)) {
245 for (atom = mol->beginAtom(ai); atom != NULL;
246 atom = mol->nextAtom(ai)) {
247
248 if (atom->getGlobalIndex() != myIndex) {
249 vec = pos - atom->getPos();
250
251 if (usePeriodicBoundaryConditions_)
252 currentSnapshot_->wrapVector(vec);
253
254 // Calculate "bonds" and build Q_lm(r) where
255 // Q_lm = Y_lm(theta(r),phi(r))
256 // The spherical harmonics are wrt any arbitrary coordinate
257 // system, we choose standard spherical coordinates
258
259 r = vec.length();
260
261 // Check to see if neighbor is in bond cutoff
262
263 if (r < rCut_) {
264 costheta = vec.z() / r;
265 phi = atan2(vec.y(), vec.x());
266
267 for (int l = 0; l <= lMax_; l++) {
268 sphericalHarmonic.setL(l);
269 for(int m = -l; m <= l; m++){
270 sphericalHarmonic.setM(m);
271 q[std::make_pair(l,m)] += sphericalHarmonic.getValueAt(costheta, phi);
272 }
273 }
274 nBonds++;
275 }
276 }
277 }
278 }
279
280
281 for (int l = 0; l <= lMax_; l++) {
282 q2[l] = 0.0;
283 for (int m = -l; m <= l; m++){
284 q[std::make_pair(l,m)] /= (RealType)nBonds;
285 q2[l] += norm(q[std::make_pair(l,m)]);
286 }
287 q_l[l] = sqrt(q2[l] * 4.0 * NumericConstant::PI / (RealType)(2*l + 1));
288 }
289
290 // Find Third Order Invariant W_l
291
292 for (int l = 0; l <= lMax_; l++) {
293 w[l] = 0.0;
294 for (int m1 = -l; m1 <= l; m1++) {
295 std::pair<int,int> lm = std::make_pair(l, m1);
296 for (int mmm = 0; mmm <= (m2Max[lm] - m2Min[lm]); mmm++) {
297 int m2 = m2Min[lm] + mmm;
298 int m3 = -m1-m2;
299 w[l] += w3j[lm][mmm] * q[lm] *
300 q[std::make_pair(l,m2)] * q[std::make_pair(l,m3)];
301 }
302 }
303
304 w_hat[l] = w[l] / pow(q2[l], 1.5);
305 }
306
307 collectHistogram(q_l, w_hat, distCOM);
308
309 // printf( "%s %18.10g %18.10g %18.10g %18.10g \n", sd->getType().c_str(),pos[0],pos[1],pos[2],real(w_hat[6]));
310
311 }
312 }
313
314 writeOrderParameter();
315 }
316
317 void BOPofR::collectHistogram(std::vector<RealType> q,
318 std::vector<ComplexType> what, RealType distCOM) {
319
320 if ( distCOM < len_){
321 // Figure out where this distance goes...
322 int whichBin = distCOM / deltaR_;
323 RCount_[whichBin]++;
324
325 if(real(what[6]) < -0.15){
326 WofR_[whichBin]++;
327 }
328 if(q[6] > 0.5){
329 QofR_[whichBin]++;
330 }
331 }
332
333 }
334
335 void BOPofR::writeOrderParameter() {
336
337 std::ofstream osq((getOutputFileName() + "qr").c_str());
338
339 if (osq.is_open()) {
340
341 // Normalize by number of frames and write it out:
342
343 for (int i = 0; i < nBins_; ++i) {
344 RealType Rval = (i + 0.5) * deltaR_;
345 osq << Rval;
346 if (RCount_[i] == 0){
347 osq << "\t" << 0;
348 osq << "\n";
349 }else{
350 osq << "\t" << (RealType)QofR_[i]/(RealType)RCount_[i];
351 osq << "\n";
352 }
353 }
354
355 osq.close();
356
357 } else {
358 sprintf(painCave.errMsg, "BOPofR: unable to open %s\n",
359 (getOutputFileName() + "q").c_str());
360 painCave.isFatal = 1;
361 simError();
362 }
363
364 std::ofstream osw((getOutputFileName() + "wr").c_str());
365
366 if (osw.is_open()) {
367 // Normalize by number of frames and write it out:
368 for (int i = 0; i < nBins_; ++i) {
369 RealType Rval = deltaR_ * (i + 0.5);
370 osw << Rval;
371 if (RCount_[i] == 0){
372 osw << "\t" << 0;
373 osw << "\n";
374 }else{
375 osw << "\t" << (RealType)WofR_[i]/(RealType)RCount_[i];
376 osw << "\n";
377 }
378 }
379
380 osw.close();
381 } else {
382 sprintf(painCave.errMsg, "BOPofR: unable to open %s\n",
383 (getOutputFileName() + "w").c_str());
384 painCave.isFatal = 1;
385 simError();
386
387 }
388
389 }
390 }

Properties

Name Value
svn:executable *