ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/staticProps/BOPofR.cpp
Revision: 3137
Committed: Tue May 29 22:50:14 2007 UTC (17 years, 3 months ago) by chuckv
File size: 11512 byte(s)
Log Message:
Removed CGAL from OOPSE and replaced it with qhull.

File Contents

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

Properties

Name Value
svn:executable *