ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/staticProps/BOPofR.cpp
Revision: 1764
Committed: Tue Jul 3 18:32:27 2012 UTC (12 years, 9 months ago) by gezelter
File size: 11641 byte(s)
Log Message:
Refactored Snapshot and Stats to use the Accumulator classes.  Collected
a number of methods into Thermo that belonged there.

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

Properties

Name Value
svn:executable *
svn:keywords Author Id Revision Date