ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/staticProps/BondOrderParameter.cpp
Revision: 3015
Committed: Thu Sep 21 21:47:17 2006 UTC (17 years, 10 months ago) by gezelter
File size: 8192 byte(s)
Log Message:
more bug fixes

File Contents

# User Rev Content
1 chuckv 3005 /*
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    
42    
43     /* Creates orientational bond order parameters as outlined by
44     * Bond-orientaional order in liquids and glasses, Steinhart,Nelson,Ronchetti
45     * Phys Rev B, 28,784,1983
46     *
47     */
48 gezelter 3007
49 chuckv 3005 #include "applications/staticProps/BondOrderParameter.hpp"
50     #include "utils/simError.h"
51     #include "io/DumpReader.hpp"
52     #include "primitives/Molecule.hpp"
53     #include "utils/NumericConstant.hpp"
54 gezelter 3010 #include "math/SphericalHarmonic.hpp"
55 gezelter 3009
56 chuckv 3005 namespace oopse {
57    
58 gezelter 3007 BondOrderParameter::BondOrderParameter(SimInfo* info,
59     const std::string& filename,
60     const std::string& sele,
61 gezelter 3009 double rCut, int lNumber, int nbins) : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info){
62 gezelter 3007
63 gezelter 3009 setOutputName(getPrefix(filename) + ".bo");
64 chuckv 3005
65 gezelter 3007 evaluator_.loadScriptString(sele);
66     if (!evaluator_.isDynamic()) {
67     seleMan_.setSelectionSet(evaluator_.evaluate());
68 chuckv 3005 }
69    
70 gezelter 3007 // Set up cutoff radius and order of the Legendre Polynomial:
71    
72 chuckv 3005 lNumber_ = lNumber;
73     rCut_ = rCut;
74 gezelter 3007 mSize_ = 2*lNumber_+1;
75     }
76 chuckv 3005
77 gezelter 3009 BondOrderParameter::~BondOrderParameter() {
78     }
79    
80 gezelter 3007 void BondOrderParameter::process() {
81     Molecule* mol;
82     Atom* atom;
83     RigidBody* rb;
84 gezelter 3011 int myIndex;
85 gezelter 3007 SimInfo::MoleculeIterator mi;
86     Molecule::RigidBodyIterator rbIter;
87     Molecule::AtomIterator ai;
88     StuntDouble* sd;
89 gezelter 3011 Vector3d vec;
90 gezelter 3010 RealType costheta;
91 gezelter 3007 RealType phi;
92     RealType r;
93     RealType dist;
94 gezelter 3014 std::map<int,ComplexType> QBar_lm;
95 gezelter 3007 RealType QSq_l;
96     RealType Q_l;
97 gezelter 3011 ComplexType W_l;
98     ComplexType W_l_hat;
99 gezelter 3007 int nBonds;
100 gezelter 3010 SphericalHarmonic sphericalHarmonic;
101 gezelter 3007 int i, j;
102 gezelter 3011 // Make arrays for Wigner3jm
103     double* THRCOF = new double[mSize_];
104     // Variables for Wigner routine
105     double l_ = (double)lNumber_;
106     double m1Pass, m2Min, m2Max;
107     int error, m1, m2, m3;
108    
109 gezelter 3008 // Set the l for the spherical harmonic, it doesn't change
110     sphericalHarmonic.setL(lNumber_);
111    
112 gezelter 3007 DumpReader reader(info_, dumpFilename_);
113     int nFrames = reader.getNFrames();
114 gezelter 3009 frameCounter_ = 0;
115 chuckv 3005
116 gezelter 3007 for (int istep = 0; istep < nFrames; istep += step_) {
117     reader.readFrame(istep);
118 gezelter 3009 frameCounter_++;
119 gezelter 3007 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
120    
121     if (evaluator_.isDynamic()) {
122     seleMan_.setSelectionSet(evaluator_.evaluate());
123     }
124 chuckv 3005
125 gezelter 3007 // update the positions of atoms which belong to the rigidbodies
126 chuckv 3005
127 gezelter 3007 for (mol = info_->beginMolecule(mi); mol != NULL;
128     mol = info_->nextMolecule(mi)) {
129     for (rb = mol->beginRigidBody(rbIter); rb != NULL;
130     rb = mol->nextRigidBody(rbIter)) {
131     rb->updateAtoms();
132     }
133     }
134    
135 gezelter 3015 nBonds = 0;
136    
137     for (int m = -lNumber_; m <= lNumber_; m++) {
138     QBar_lm[m] = 0.0;
139     }
140    
141 gezelter 3007 // outer loop is over the selected StuntDoubles:
142 chuckv 3005
143 gezelter 3007 for (sd = seleMan_.beginSelected(i); sd != NULL;
144     sd = seleMan_.nextSelected(i)) {
145 chuckv 3005
146 gezelter 3011 myIndex = sd->getGlobalIndex();
147 gezelter 3007
148     // inner loop is over all other atoms in the system:
149    
150     for (mol = info_->beginMolecule(mi); mol != NULL;
151     mol = info_->nextMolecule(mi)) {
152     for (atom = mol->beginAtom(ai); atom != NULL;
153     atom = mol->nextAtom(ai)) {
154 chuckv 3005
155 gezelter 3011 if (atom->getGlobalIndex() != myIndex) {
156 chuckv 3005
157 gezelter 3011 vec = sd->getPos() - atom->getPos();
158     currentSnapshot_->wrapVector(vec);
159 gezelter 3010
160 gezelter 3011 // Calculate "bonds" and build Q_lm(r) where
161     // Q_lm = Y_lm(theta(r),phi(r))
162     // The spherical harmonics are wrt any arbitrary coordinate
163     // system, we choose standard spherical coordinates
164    
165     r = vec.length();
166    
167     // Check to see if neighbor is in bond cutoff
168    
169     if (r < rCut_) {
170     costheta = vec.z() / r;
171     phi = atan2(vec.y(), vec.x());
172    
173     for(int m = -lNumber_; m <= lNumber_; m++){
174     sphericalHarmonic.setM(m);
175 gezelter 3015 QBar_lm[m] += sphericalHarmonic.getValueAt(costheta, phi);
176 gezelter 3011 }
177     nBonds++;
178     }
179     }
180 gezelter 3007 }
181     }
182 gezelter 3015 }
183     }
184 chuckv 3005
185 gezelter 3015 // Normalize Qbar2
186     for (int m = -lNumber_;m <= lNumber_; m++){
187     QBar_lm[m] /= nBonds;
188 gezelter 3007 }
189    
190 gezelter 3015 // Find second order invariant Q_l
191 gezelter 3007
192 gezelter 3015 QSq_l = 0.0;
193     for (int m = -lNumber_; m <= lNumber_; m++){
194     QSq_l += norm(QBar_lm[m]);
195 gezelter 3007 }
196 gezelter 3015
197     std::cout << "qsl = " << QSq_l << "\n";
198     Q_l = sqrt(QSq_l * 4.0 * NumericConstant::PI / (RealType)(2*lNumber_ + 1));
199    
200     // Find Third Order Invariant W_l
201    
202     W_l = 0.0;
203     for (int m1 = -lNumber_; m1 <= lNumber_; m1++) {
204     // Zero work array
205     for (int ii = 0; ii < mSize_; ii++){
206     THRCOF[ii] = 0.0;
207     }
208     // Get Wigner coefficients
209     m1Pass = (double)m1;
210 gezelter 3009
211 gezelter 3015 Wigner3jm(&l_, &l_, &l_,
212     &m1Pass, &m2Min, &m2Max,
213     THRCOF, &mSize_, &error);
214 gezelter 3009
215 gezelter 3015 for (int mmm = 0; mmm < (int)(m2Max - m2Min); mmm++) {
216     m2 = (int)floor(m2Min) + mmm;
217     m3 = -m1-m2;
218     W_l += THRCOF[mmm] * QBar_lm[m1] * QBar_lm[m2] * QBar_lm[m3];
219 gezelter 3009 }
220 gezelter 3007 }
221 gezelter 3015
222     W_l_hat = W_l / pow(QSq_l, 1.5);
223    
224     writeOrderParameter(Q_l, real(W_l_hat));
225     }
226 chuckv 3005
227    
228 gezelter 3015 void BondOrderParameter::writeOrderParameter(RealType ql, RealType Wlhat) {
229 chuckv 3005
230 gezelter 3015 std::ofstream os(getOutputFileName().c_str());
231    
232     if (os.is_open()) {
233 gezelter 3009
234 gezelter 3015 os << "# Bond Order Parameters\n";
235     os << "# selection: (" << selectionScript_ << ")\n";
236     os << "# \n";
237     os << "# <Q_" << lNumber_ << ">: " << ql << "\n";
238     os << "# <W_" << lNumber_ << ">: " << Wlhat << "\n";
239     os.close();
240    
241 gezelter 3009 } else {
242     sprintf(painCave.errMsg, "BondOrderParameter: unable to open %s\n",
243 gezelter 3015 getOutputFileName().c_str());
244 gezelter 3009 painCave.isFatal = 1;
245     simError();
246     }
247     }
248 gezelter 3007 }

Properties

Name Value
svn:executable *