ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/staticProps/BondOrderParameter.cpp
(Generate patch)

Comparing trunk/OOPSE-4/src/applications/staticProps/BondOrderParameter.cpp (file contents):
Revision 2902 by chuckv, Tue Jun 27 16:36:25 2006 UTC vs.
Revision 3022 by gezelter, Tue Sep 26 01:30:32 2006 UTC

# Line 1 | Line 1
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. 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 < #include "applications/staticProps/BondOrderParameter.hpp"
43 < #include "utils/simError.h"
44 < #include "io/DumpReader.hpp"
45 < #include "primitives/Molecule.hpp"
46 < #include "utils/NumericConstant.hpp"
47 < namespace oopse {
48 <
49 <
50 < BondOrderParameter::BondOrderParameter(SimInfo* info, const std::string& filename, const std::string& sele1,
51 < const std::string& sele2, double rCut, int lNumber)
52 <  : StaticAnalyser(info, filename),
53 <    selectionScript1_(sele1), evaluator1_(info),
54 <    seleMan1_(info){
55 <
56 <    setOutputName(getPrefix(filename) + ".p2");
57 <        
58 <    evaluator1_.loadScriptString(sele1);
59 <    evaluator2_.loadScriptString(sele2);
60 <
61 <    if (!evaluator1_.isDynamic()) {
62 <      seleMan1_.setSelectionSet(evaluator1_.evaluate());
63 <    }else {
64 <        sprintf( painCave.errMsg,
65 <                 "--sele1 must be static selection\n");
66 <        painCave.severity = OOPSE_ERROR;
67 <        painCave.isFatal = 1;
68 <        simError();  
69 <    }
70 <
71 <
72 <  int i;
73 <  int j;
74 <  StuntDouble* sd1;
75 <  StuntDouble* sd2;
76 <  for (sd1 = seleMan1_.beginSelected(i), sd2 = seleMan1_.beginSelected(j);
77 <     sd1 != NULL && sd2 != NULL;
78 <     sd1 = seleMan1_.nextSelected(i), sd2 = seleMan2_.nextSelected(j)) {
79 <
80 <     sdPairs_.push_back(std::make_pair(sd1, sd2));
81 <  }
82 <
83 <    
84 <  }
85 <
86 < void BondOrderParameter::process() {
87 <  Molecule* mol;
88 <  RigidBody* rb;
89 <  SimInfo::MoleculeIterator mi;
90 <  Molecule::RigidBodyIterator rbIter;
91 <  
92 <  DumpReader reader(info_, dumpFilename_);    
93 <  int nFrames = reader.getNFrames();
94 <
95 <  for (int i = 0; i < nFrames; i += step_) {
96 <    reader.readFrame(i);
97 <    currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
98 <
99 <    
100 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
101 <        //change the positions of atoms which belong to the rigidbodies
102 <        for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
103 <            rb->updateAtoms();
104 <        }
105 <        
106 <    }      
107 <
108 <      Mat3x3d orderTensor(0.0);
109 <      for (std::vector<std::pair<StuntDouble*, StuntDouble*> >::iterator j = sdPairs_.begin(); j != sdPairs_.end(); ++j) {
110 <          Vector3d vec = j->first->getPos() - j->second->getPos();
111 <          currentSnapshot_->wrapVector(vec);
112 <          vec.normalize();
113 <          orderTensor +=outProduct(vec, vec);
114 <      }
115 <      
116 <      orderTensor /= sdPairs_.size();
117 <      orderTensor -= (RealType)(1.0/3.0) * Mat3x3d::identity();  
118 <      
119 <      Vector3d eigenvalues;
120 <      Mat3x3d eigenvectors;    
121 <      Mat3x3d::diagonalize(orderTensor, eigenvalues, eigenvectors);
122 <      
123 <      int which;
124 <      RealType maxEval = 0.0;
125 <      for(int k = 0; k< 3; k++){
126 <        if(fabs(eigenvalues[k]) > maxEval){
127 <          which = k;
128 <          maxEval = fabs(eigenvalues[k]);
129 <        }
130 <      }
131 <      RealType p2 = 1.5 * maxEval;
132 <      
133 <      //the eigen vector is already normalized in SquareMatrix3::diagonalize
134 <      Vector3d director = eigenvectors.getColumn(which);
135 <      if (director[0] < 0) {
136 <          director.negate();
137 <      }  
138 <
139 <      RealType angle = 0.0;
140 <      for (std::vector<std::pair<StuntDouble*, StuntDouble*> >::iterator j = sdPairs_.begin(); j != sdPairs_.end(); ++j) {
141 <          Vector3d vec = j->first->getPos() - j->second->getPos();
142 <          currentSnapshot_->wrapVector(vec);
143 <          vec.normalize();
144 <
145 <          angle += acos(dot(vec, director)) ;
146 <      }
147 <      angle = angle / (sdPairs_.size() * NumericConstant::PI) * 180.0;
148 <
149 <       OrderParam param;
150 <       param.p2 = p2;
151 <       param.director = director;
152 <       param.angle = angle;
153 <
154 <        orderParams_.push_back(param);      
155 <    
156 <  }
157 <
158 <  writeP2();
159 <  
160 < }
161 <
162 < void BondOrderParameter::writeOrderParameter() {
163 <
164 <    std::ofstream os(getOutputFileName().c_str());
165 <    os << "#radial distribution function\n";
166 <    os<< "#selection1: (" << selectionScript1_ << ")\t";
167 <    os << "selection2: (" << selectionScript2_ << ")\n";
168 <    os << "#p2\tdirector_x\tdirector_y\tdiretor_z\tangle(degree)\n";    
169 <
170 <    for (std::size_t i = 0; i < orderParams_.size(); ++i) {
171 <        os <<  orderParams_[i].p2 << "\t"
172 <            <<  orderParams_[i].director[0] << "\t"
173 <            <<  orderParams_[i].director[1] << "\t"
174 <            <<  orderParams_[i].director[2] << "\t"
175 <            <<  orderParams_[i].angle << "\n";
176 <
177 <    }
178 <
179 < }
180 <
181 < }
182 <
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. 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 >
49 > #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 >
55 > namespace oopse {
56 >
57 >  BondOrderParameter::BondOrderParameter(SimInfo* info,
58 >                                         const std::string& filename,
59 >                                         const std::string& sele,
60 >                                         double rCut, int nbins) : 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 >    Qcount_.resize(lMax_+1);
74 >    Wcount_.resize(lMax_+1);
75 >
76 >    // Q can take values from 0 to 1
77 >
78 >    MinQ_ = 0.0;
79 >    MaxQ_ = 1.1;
80 >    deltaQ_ = (MaxQ_ - MinQ_) / nbins;
81 >
82 >    // W_6 for icosahedral clusters is 11 / sqrt(4199) = 0.169754, so we'll
83 >    // use values for MinW_ and MaxW_ that are slightly larger than this:
84 >
85 >    MinW_ = -0.25;
86 >    MaxW_ = 0.25;
87 >    deltaW_ = (MaxW_ - MinW_) / nbins;
88 >  }
89 >
90 >  BondOrderParameter::~BondOrderParameter() {
91 >    Q_histogram_.clear();
92 >    W_histogram_.clear();
93 >  }
94 >
95 >  void BondOrderParameter::initalizeHistogram() {
96 >    for (int bin = 0; bin < nBins_; bin++) {
97 >      for (int l = 0; l <= lMax_; l++) {
98 >        Q_histogram_[std::make_pair(bin,l)] = 0;
99 >        W_histogram_[std::make_pair(bin,l)] = 0;
100 >      }
101 >    }
102 >  }
103 >
104 >  void BondOrderParameter::process() {
105 >    Molecule* mol;
106 >    Atom* atom;
107 >    RigidBody* rb;
108 >    int myIndex;
109 >    SimInfo::MoleculeIterator mi;
110 >    Molecule::RigidBodyIterator rbIter;
111 >    Molecule::AtomIterator ai;
112 >    StuntDouble* sd;
113 >    Vector3d vec;
114 >    RealType costheta;
115 >    RealType phi;
116 >    RealType r;
117 >    RealType dist;
118 >    std::map<std::pair<int,int>,ComplexType> q;
119 >    std::vector<RealType> q_l;
120 >    std::vector<RealType> q2;
121 >    std::vector<ComplexType> w;
122 >    std::vector<ComplexType> w_hat;
123 >    std::map<std::pair<int,int>,ComplexType> QBar;
124 >    std::vector<RealType> Q2;
125 >    std::vector<RealType> Q;
126 >    std::vector<ComplexType> W;
127 >    std::vector<ComplexType> W_hat;
128 >    int nBonds, Nbonds;
129 >    SphericalHarmonic sphericalHarmonic;
130 >    int i, j;
131 >    // Make arrays for Wigner3jm
132 >    double* THRCOF = new double[2*lMax_+1];
133 >    // Variables for Wigner routine
134 >    double lPass, m1Pass, m2Min, m2Max;
135 >    int error, m1, m2, m3, mSize;
136 >    mSize = 2*lMax_+1;
137 >
138 >    DumpReader reader(info_, dumpFilename_);    
139 >    int nFrames = reader.getNFrames();
140 >    frameCounter_ = 0;
141 >
142 >    q_l.resize(lMax_+1);
143 >    q2.resize(lMax_+1);
144 >    w.resize(lMax_+1);
145 >    w_hat.resize(lMax_+1);
146 >
147 >    Q2.resize(lMax_+1);
148 >    Q.resize(lMax_+1);
149 >    W.resize(lMax_+1);
150 >    W_hat.resize(lMax_+1);
151 >
152 >    for (int istep = 0; istep < nFrames; istep += step_) {
153 >      reader.readFrame(istep);
154 >      frameCounter_++;
155 >      currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
156 >      
157 >      if (evaluator_.isDynamic()) {
158 >        seleMan_.setSelectionSet(evaluator_.evaluate());
159 >      }
160 >
161 >      // update the positions of atoms which belong to the rigidbodies
162 >
163 >      for (mol = info_->beginMolecule(mi); mol != NULL;
164 >           mol = info_->nextMolecule(mi)) {
165 >        for (rb = mol->beginRigidBody(rbIter); rb != NULL;
166 >             rb = mol->nextRigidBody(rbIter)) {
167 >          rb->updateAtoms();
168 >        }        
169 >      }          
170 >            
171 >      // outer loop is over the selected StuntDoubles:
172 >
173 >      for (sd = seleMan_.beginSelected(i); sd != NULL;
174 >           sd = seleMan_.nextSelected(i)) {
175 >
176 >        myIndex = sd->getGlobalIndex();
177 >        nBonds = 0;
178 >        
179 >        for (int l = 0; l <= lMax_; l++) {
180 >          for (int m = -l; m <= l; m++) {
181 >            q[std::make_pair(l,m)] = 0.0;
182 >          }
183 >        }
184 >        
185 >        // inner loop is over all other atoms in the system:
186 >        
187 >        for (mol = info_->beginMolecule(mi); mol != NULL;
188 >             mol = info_->nextMolecule(mi)) {
189 >          for (atom = mol->beginAtom(ai); atom != NULL;
190 >               atom = mol->nextAtom(ai)) {
191 >
192 >            if (atom->getGlobalIndex() != myIndex) {
193 >
194 >              vec = sd->getPos() - atom->getPos();      
195 >              currentSnapshot_->wrapVector(vec);
196 >              
197 >              // Calculate "bonds" and build Q_lm(r) where
198 >              //      Q_lm = Y_lm(theta(r),phi(r))                
199 >              // The spherical harmonics are wrt any arbitrary coordinate
200 >              // system, we choose standard spherical coordinates
201 >              
202 >              r = vec.length();
203 >              
204 >              // Check to see if neighbor is in bond cutoff
205 >              
206 >              if (r < rCut_) {
207 >                costheta = vec.z() / r;
208 >                phi = atan2(vec.y(), vec.x());
209 >
210 >                for (int l = 0; l <= lMax_; l++) {
211 >                  sphericalHarmonic.setL(l);
212 >                  for(int m = -l; m <= l; m++){
213 >                    sphericalHarmonic.setM(m);
214 >                    q[std::make_pair(l,m)] += sphericalHarmonic.getValueAt(costheta, phi);
215 >                  }
216 >                }
217 >                nBonds++;
218 >              }  
219 >            }
220 >          }
221 >        }
222 >        
223 >        
224 >        for (int l = 0; l <= lMax_; l++) {        
225 >          q_l[l] = 0.0;
226 >          for(int m = -l; m <= l; m++) {
227 >            q_l[l] += norm(q[std::make_pair(l,m)]);
228 >          }    
229 >          q_l[l] *= 4.0*NumericConstant::PI/(RealType)(2*l + 1);
230 >          q_l[l] = sqrt(q_l[l])/(RealType)nBonds;
231 >        }
232 >
233 >        // Find second order invariant Q_l
234 >        
235 >        for (int l = 0; l <= lMax_; l++) {
236 >          q2[l] = 0.0;
237 >          for (int m = -l; m <= l; m++){
238 >            q2[l] += norm(q[std::make_pair(l,m)]);
239 >          }
240 >          q_l[l] = sqrt(q2[l] * 4.0 * NumericConstant::PI /
241 >                        (RealType)(2*l + 1))/(RealType)nBonds;
242 >        }
243 >
244 >        // Find Third Order Invariant W_l
245 >    
246 >        for (int l = 0; l <= lMax_; l++) {
247 >          w[l] = 0.0;
248 >          lPass = (double)l;
249 >          for (int m1 = -l; m1 <= l; m1++) {
250 >            // Zero work array
251 >            for (int ii = 0; ii < 2*l + 1; ii++){
252 >              THRCOF[ii] = 0.0;
253 >            }
254 >            // Get Wigner coefficients
255 >            m1Pass = (double)m1;
256 >            
257 >            Wigner3jm(&lPass, &lPass, &lPass,
258 >                      &m1Pass, &m2Min, &m2Max,
259 >                      THRCOF, &mSize, &error);
260 >            
261 >            for (int mmm = 0; mmm < (int)(m2Max - m2Min); mmm++) {
262 >              m2 = (int)floor(m2Min) + mmm;
263 >              m3 = -m1-m2;
264 >              w[l] += THRCOF[mmm] *
265 >                q[std::make_pair(l,m1)] *
266 >                q[std::make_pair(l,m2)] *
267 >                q[std::make_pair(l,m3)];
268 >            }
269 >          }
270 >          
271 >          w_hat[l] = w[l] / pow(q2[l], 1.5);
272 >        }
273 >
274 >        collectHistogram(q_l, w_hat);
275 >        
276 >        Nbonds += nBonds;
277 >        for (int l = 0; l <= lMax_;  l++) {
278 >          for (int m = -l; m <= l; m++) {
279 >            QBar[std::make_pair(l,m)] += q[std::make_pair(l,m)];
280 >          }
281 >        }
282 >      }
283 >    }
284 >      
285 >    // Normalize Qbar2
286 >    for (int l = 0; l <= lMax_; l++) {
287 >      for (int m = -l; m <= l; m++){
288 >        QBar[std::make_pair(l,m)] /= Nbonds;
289 >      }
290 >    }
291 >    
292 >    // Find second order invariant Q_l
293 >    
294 >    for (int l = 0; l <= lMax_; l++) {
295 >      Q2[l] = 0.0;
296 >      for (int m = -l; m <= l; m++){
297 >        Q2[l] += norm(QBar[std::make_pair(l,m)]);
298 >      }
299 >      Q[l] = sqrt(Q2[l] * 4.0 * NumericConstant::PI / (RealType)(2*l + 1));
300 >    }
301 >    
302 >    // Find Third Order Invariant W_l
303 >    
304 >    for (int l = 0; l <= lMax_; l++) {
305 >      W[l] = 0.0;
306 >      lPass = (double)l;
307 >      for (int m1 = -l; m1 <= l; m1++) {
308 >        // Zero work array
309 >        for (int ii = 0; ii < 2*l + 1; ii++){
310 >          THRCOF[ii] = 0.0;
311 >        }
312 >        // Get Wigner coefficients
313 >        m1Pass = (double)m1;
314 >        
315 >        Wigner3jm(&lPass, &lPass, &lPass,
316 >                  &m1Pass, &m2Min, &m2Max,
317 >                  THRCOF, &mSize, &error);
318 >        
319 >        for (int mmm = 0; mmm < (int)(m2Max - m2Min); mmm++) {
320 >          m2 = (int)floor(m2Min) + mmm;
321 >          m3 = -m1-m2;
322 >          W[l] += THRCOF[mmm] *
323 >            QBar[std::make_pair(l,m1)] *
324 >            QBar[std::make_pair(l,m2)] *
325 >            QBar[std::make_pair(l,m3)];
326 >        }
327 >      }
328 >      
329 >      W_hat[l] = W[l] / pow(Q2[l], 1.5);
330 >    }
331 >    
332 >    writeOrderParameter(Q, W_hat);    
333 >  }
334 >
335 >  void BondOrderParameter::collectHistogram(std::vector<RealType> q,
336 >                                            std::vector<ComplexType> what) {
337 >
338 >    for (int l = 0; l <= lMax_; l++) {
339 >      if (q[l] >= MinQ_ && q[l] < MaxQ_) {
340 >        int qbin = (q[l] - MinQ_) / deltaQ_;
341 >        Q_histogram_[std::make_pair(qbin,l)] += 1;
342 >        Qcount_[l]++;      
343 >      } else {
344 >        sprintf( painCave.errMsg,
345 >                 "q_l value outside reasonable range\n");
346 >        painCave.severity = OOPSE_ERROR;
347 >        painCave.isFatal = 1;
348 >        simError();  
349 >      }
350 >    }
351 >
352 >    for (int l = 0; l <= lMax_; l++) {
353 >      if (real(what[l]) >= MinW_ && real(what[l]) < MaxW_) {
354 >        int wbin = (real(what[l]) - MinW_) / deltaW_;
355 >        W_histogram_[std::make_pair(wbin,l)] += 1;
356 >        Wcount_[l]++;      
357 >      } else {
358 >        sprintf( painCave.errMsg,
359 >                 "Re[w_hat] value outside reasonable range\n");
360 >        painCave.severity = OOPSE_ERROR;
361 >        painCave.isFatal = 1;
362 >        simError();  
363 >      }
364 >    }
365 >
366 >  }  
367 >
368 >
369 >  void BondOrderParameter::writeOrderParameter(std::vector<RealType> Q,
370 >                                               std::vector<ComplexType> What) {
371 >    
372 >    std::ofstream osq((getOutputFileName() + "q").c_str());
373 >
374 >    if (osq.is_open()) {
375 >      
376 >      osq << "# Bond Order Parameters\n";
377 >      osq << "# selection: (" << selectionScript_ << ")\n";
378 >      osq << "# \n";
379 >      for (int l = 0; l <= lMax_; l++) {
380 >        osq << "# <Q_" << l << ">: " << Q[l] << "\n";
381 >      }
382 >      // Normalize by number of frames and write it out:
383 >      for (int i = 0; i < nBins_; ++i) {
384 >        RealType Qval = MinQ_ + (i + 0.5) * deltaQ_;              
385 >        osq << Qval;
386 >        for (int l = 0; l <= lMax_; l++) {
387 >          osq << "\t" << (RealType)Q_histogram_[std::make_pair(i,l)] / (RealType)Qcount_[l];
388 >        }
389 >        osq << "\n";
390 >      }
391 >
392 >      osq.close();
393 >
394 >    } else {
395 >      sprintf(painCave.errMsg, "BondOrderParameter: unable to open %s\n",
396 >              (getOutputFileName() + "q").c_str());
397 >      painCave.isFatal = 1;
398 >      simError();  
399 >    }
400 >
401 >    std::ofstream osw((getOutputFileName() + "w").c_str());
402 >
403 >    if (osw.is_open()) {
404 >      osw << "# Bond Order Parameters\n";
405 >      osw << "# selection: (" << selectionScript_ << ")\n";
406 >      osw << "# \n";
407 >      for (int l = 0; l <= lMax_; l++) {
408 >        osw << "# <W_" << l << ">: " << real(What[l]) << "\n";
409 >      }
410 >      // Normalize by number of frames and write it out:
411 >      for (int i = 0; i < nBins_; ++i) {
412 >        RealType Wval = MinW_ + (i + 0.5) * deltaW_;              
413 >        osw << Wval;
414 >        for (int l = 0; l <= lMax_; l++) {
415 >          osw << "\t" << (RealType)W_histogram_[std::make_pair(i,l)] / (RealType)Wcount_[l];
416 >        }
417 >        osw << "\n";
418 >      }
419 >
420 >      osw.close();
421 >    } else {
422 >      sprintf(painCave.errMsg, "BondOrderParameter: unable to open %s\n",
423 >              (getOutputFileName() + "w").c_str());
424 >      painCave.isFatal = 1;
425 >      simError();  
426 >    }
427 >      
428 >  }
429 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines