ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/staticProps/BOPofR.cpp
Revision: 1826
Committed: Wed Jan 9 19:41:48 2013 UTC (12 years, 3 months ago) by gezelter
File size: 11605 byte(s)
Log Message:
Cleaning more cruft and unused variables.

File Contents

# User Rev Content
1 chuckv 1128 /*
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 gezelter 1390 * 1. Redistributions of source code must retain the above copyright
10 chuckv 1128 * notice, this list of conditions and the following disclaimer.
11     *
12 gezelter 1390 * 2. Redistributions in binary form must reproduce the above copyright
13 chuckv 1128 * 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 gezelter 1390 * 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 chuckv 1128 * Created by J. Daniel Gezelter on 09/26/06.
42     * @author J. Daniel Gezelter
43 gezelter 1442 * @version $Id$
44 chuckv 1128 *
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 gezelter 1600 #include "math/Wigner3jm.hpp"
53 gezelter 1764 #include "brains/Thermo.hpp"
54 chuckv 1128
55 gezelter 1600 using namespace MATPACK;
56 gezelter 1390 namespace OpenMD {
57 chuckv 1128
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 chuckv 1137
79     for (int i = 0; i < nBins_; i++){
80     RCount_[i] = 0;
81     WofR_[i] = 0;
82     QofR_[i] = 0;
83     }
84 chuckv 1128
85     // Make arrays for Wigner3jm
86 gezelter 1600 RealType* THRCOF = new RealType[2*lMax_+1];
87 chuckv 1128 // Variables for Wigner routine
88 gezelter 1600 RealType lPass, m1Pass, m2m, m2M;
89 chuckv 1128 int error, mSize;
90     mSize = 2*lMax_+1;
91    
92     for (int l = 0; l <= lMax_; l++) {
93 gezelter 1600 lPass = (RealType)l;
94 chuckv 1128 for (int m1 = -l; m1 <= l; m1++) {
95 gezelter 1600 m1Pass = (RealType)m1;
96 chuckv 1128
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 gezelter 1600 Wigner3jm(lPass, lPass, lPass,
106     m1Pass, m2m, m2M,
107     THRCOF, mSize, error);
108 chuckv 1128
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 chuckv 1137 THRCOF = NULL;
120 chuckv 1128
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 gezelter 1794 void BOPofR::initializeHistogram() {
149 chuckv 1137 for (int i = 0; i < nBins_; i++){
150     RCount_[i] = 0;
151     WofR_[i] = 0;
152     QofR_[i] = 0;
153     }
154 chuckv 1128 }
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     Vector3d rCOM;
171     RealType distCOM;
172     Vector3d pos;
173     Vector3d CenterOfMass;
174     std::map<std::pair<int,int>,ComplexType> q;
175     std::vector<RealType> q_l;
176     std::vector<RealType> q2;
177     std::vector<ComplexType> w;
178     std::vector<ComplexType> w_hat;
179     std::map<std::pair<int,int>,ComplexType> QBar;
180     std::vector<RealType> Q2;
181     std::vector<RealType> Q;
182     std::vector<ComplexType> W;
183     std::vector<ComplexType> W_hat;
184 gezelter 1826 int nBonds;
185 chuckv 1128 SphericalHarmonic sphericalHarmonic;
186 gezelter 1767 int i;
187    
188 chuckv 1128 DumpReader reader(info_, dumpFilename_);
189     int nFrames = reader.getNFrames();
190     frameCounter_ = 0;
191    
192 gezelter 1764 Thermo thermo(info_);
193    
194 chuckv 1128 q_l.resize(lMax_+1);
195     q2.resize(lMax_+1);
196     w.resize(lMax_+1);
197     w_hat.resize(lMax_+1);
198    
199     Q2.resize(lMax_+1);
200     Q.resize(lMax_+1);
201     W.resize(lMax_+1);
202     W_hat.resize(lMax_+1);
203    
204     for (int istep = 0; istep < nFrames; istep += step_) {
205     reader.readFrame(istep);
206     frameCounter_++;
207     currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
208 gezelter 1764 CenterOfMass = thermo.getCom();
209 chuckv 1128 if (evaluator_.isDynamic()) {
210     seleMan_.setSelectionSet(evaluator_.evaluate());
211     }
212    
213     // update the positions of atoms which belong to the rigidbodies
214    
215     for (mol = info_->beginMolecule(mi); mol != NULL;
216     mol = info_->nextMolecule(mi)) {
217     for (rb = mol->beginRigidBody(rbIter); rb != NULL;
218     rb = mol->nextRigidBody(rbIter)) {
219     rb->updateAtoms();
220     }
221     }
222    
223     // outer loop is over the selected StuntDoubles:
224    
225     for (sd = seleMan_.beginSelected(i); sd != NULL;
226     sd = seleMan_.nextSelected(i)) {
227    
228     myIndex = sd->getGlobalIndex();
229    
230     nBonds = 0;
231    
232     for (int l = 0; l <= lMax_; l++) {
233     for (int m = -l; m <= l; m++) {
234     q[std::make_pair(l,m)] = 0.0;
235     }
236     }
237     pos = sd->getPos();
238     rCOM = CenterOfMass - pos;
239     if (usePeriodicBoundaryConditions_)
240     currentSnapshot_->wrapVector(rCOM);
241     distCOM = rCOM.length();
242    
243     // inner loop is over all other atoms in the system:
244    
245     for (mol = info_->beginMolecule(mi); mol != NULL;
246     mol = info_->nextMolecule(mi)) {
247     for (atom = mol->beginAtom(ai); atom != NULL;
248     atom = mol->nextAtom(ai)) {
249    
250     if (atom->getGlobalIndex() != myIndex) {
251     vec = pos - atom->getPos();
252    
253     if (usePeriodicBoundaryConditions_)
254     currentSnapshot_->wrapVector(vec);
255    
256     // Calculate "bonds" and build Q_lm(r) where
257     // Q_lm = Y_lm(theta(r),phi(r))
258     // The spherical harmonics are wrt any arbitrary coordinate
259     // system, we choose standard spherical coordinates
260    
261     r = vec.length();
262    
263     // Check to see if neighbor is in bond cutoff
264    
265     if (r < rCut_) {
266     costheta = vec.z() / r;
267     phi = atan2(vec.y(), vec.x());
268    
269     for (int l = 0; l <= lMax_; l++) {
270     sphericalHarmonic.setL(l);
271     for(int m = -l; m <= l; m++){
272     sphericalHarmonic.setM(m);
273     q[std::make_pair(l,m)] += sphericalHarmonic.getValueAt(costheta, phi);
274     }
275     }
276     nBonds++;
277     }
278     }
279     }
280     }
281    
282    
283     for (int l = 0; l <= lMax_; l++) {
284     q2[l] = 0.0;
285     for (int m = -l; m <= l; m++){
286     q[std::make_pair(l,m)] /= (RealType)nBonds;
287     q2[l] += norm(q[std::make_pair(l,m)]);
288     }
289     q_l[l] = sqrt(q2[l] * 4.0 * NumericConstant::PI / (RealType)(2*l + 1));
290     }
291    
292     // Find Third Order Invariant W_l
293    
294     for (int l = 0; l <= lMax_; l++) {
295     w[l] = 0.0;
296     for (int m1 = -l; m1 <= l; m1++) {
297     std::pair<int,int> lm = std::make_pair(l, m1);
298     for (int mmm = 0; mmm <= (m2Max[lm] - m2Min[lm]); mmm++) {
299     int m2 = m2Min[lm] + mmm;
300     int m3 = -m1-m2;
301     w[l] += w3j[lm][mmm] * q[lm] *
302     q[std::make_pair(l,m2)] * q[std::make_pair(l,m3)];
303     }
304     }
305    
306 gezelter 1668 w_hat[l] = w[l] / pow(q2[l], RealType(1.5));
307 chuckv 1128 }
308    
309     collectHistogram(q_l, w_hat, distCOM);
310 chuckv 1137
311 chuckv 1194 // 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]));
312 chuckv 1137
313 chuckv 1128 }
314     }
315    
316     writeOrderParameter();
317     }
318    
319     void BOPofR::collectHistogram(std::vector<RealType> q,
320     std::vector<ComplexType> what, RealType distCOM) {
321    
322     if ( distCOM < len_){
323     // Figure out where this distance goes...
324 gezelter 1794 int whichBin = int(distCOM / deltaR_);
325 chuckv 1137 RCount_[whichBin]++;
326    
327     if(real(what[6]) < -0.15){
328     WofR_[whichBin]++;
329 chuckv 1128 }
330 chuckv 1137 if(q[6] > 0.5){
331     QofR_[whichBin]++;
332     }
333 chuckv 1128 }
334    
335     }
336    
337     void BOPofR::writeOrderParameter() {
338    
339     std::ofstream osq((getOutputFileName() + "qr").c_str());
340    
341     if (osq.is_open()) {
342    
343     // Normalize by number of frames and write it out:
344    
345     for (int i = 0; i < nBins_; ++i) {
346     RealType Rval = (i + 0.5) * deltaR_;
347     osq << Rval;
348 chuckv 1137 if (RCount_[i] == 0){
349     osq << "\t" << 0;
350     osq << "\n";
351     }else{
352     osq << "\t" << (RealType)QofR_[i]/(RealType)RCount_[i];
353     osq << "\n";
354     }
355 chuckv 1128 }
356    
357     osq.close();
358    
359     } else {
360     sprintf(painCave.errMsg, "BOPofR: unable to open %s\n",
361     (getOutputFileName() + "q").c_str());
362     painCave.isFatal = 1;
363     simError();
364     }
365    
366     std::ofstream osw((getOutputFileName() + "wr").c_str());
367    
368     if (osw.is_open()) {
369     // Normalize by number of frames and write it out:
370     for (int i = 0; i < nBins_; ++i) {
371     RealType Rval = deltaR_ * (i + 0.5);
372     osw << Rval;
373 chuckv 1137 if (RCount_[i] == 0){
374     osw << "\t" << 0;
375     osw << "\n";
376     }else{
377     osw << "\t" << (RealType)WofR_[i]/(RealType)RCount_[i];
378     osw << "\n";
379     }
380 chuckv 1128 }
381    
382     osw.close();
383     } else {
384     sprintf(painCave.errMsg, "BOPofR: unable to open %s\n",
385     (getOutputFileName() + "w").c_str());
386     painCave.isFatal = 1;
387     simError();
388    
389     }
390    
391     }
392     }

Properties

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