ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/TetrahedralityParamZ.cpp
(Generate patch)

Comparing:
branches/development/src/applications/staticProps/TetrahedralityParamZ.cpp (file contents), Revision 1767 by gezelter, Fri Jul 6 22:01:58 2012 UTC vs.
trunk/src/applications/staticProps/TetrahedralityParamZ.cpp (file contents), Revision 1843 by gezelter, Tue Jan 29 20:58:08 2013 UTC

# Line 32 | Line 32
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 < *                                                                      
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: BondOrderParameter.cpp 1442 2010-05-10 17:28:26Z gezelter $
44 < *
39 > * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 > * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 > * [6]  Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
42   */
43  
44   #include "applications/staticProps/TetrahedralityParamZ.hpp"
# Line 54 | Line 51 | using namespace std;
51   #include <fstream>
52  
53   using namespace std;
54 <
55 < namespace OpenMD
56 < {
57 <  TetrahedralityParamZ::TetrahedralityParamZ(SimInfo* info,
58 <                                           const std::string& filename,
59 <                                           const std::string& sele,
60 <                                           double rCut, int nzbins) : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan1_(info),seleMan2_(info), nZBins_(nzbins)
64 <  {
65 <    //nZBins_ = 50;
66 <    //std ::cerrnZBins_:"<<nZBins_<<"\t"<<"nzbins:"<<nzbins<<endl;
67 <    // nZBins_ = 90;
68 <    //fixed numbe of bins
69 <    count_.resize(nZBins_);
70 <    sliceSDLists_.resize(nZBins_);
71 <    Qave_.resize(nZBins_);
72 <
73 <    setOutputName(getPrefix(filename) + ".q");
54 > namespace OpenMD {
55 >  TetrahedralityParamZ::TetrahedralityParamZ(SimInfo* info,  
56 >                                             const std::string& filename,
57 >                                             const std::string& sele,
58 >                                             double rCut, int nzbins)
59 >    : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info),
60 >      seleMan_(info), nZBins_(nzbins) {
61      
62      evaluator_.loadScriptString(sele);
63 <    if (!evaluator_.isDynamic())
64 <      {
65 <        seleMan1_.setSelectionSet(evaluator_.evaluate());
66 <        seleMan2_.setSelectionSet(evaluator_.evaluate());
67 <      }
81 <
82 <    // Set up cutoff radius:
63 >    if (!evaluator_.isDynamic()) {
64 >      seleMan_.setSelectionSet(evaluator_.evaluate());
65 >    }
66 >    
67 >    // Set up cutoff radius:    
68      rCut_ = rCut;
69  
70 <    // Q can take values from 0 to 1
71 <    MinQ_ = 0.0;
72 <    MaxQ_ = 1.1;
73 <    deltaQ_ = (MaxQ_ - MinQ_)/nzbins;
70 >    // fixed number of bins
71 >    sliceQ_.resize(nZBins_);
72 >    sliceCount_.resize(nZBins_);    
73 >    std::fill(sliceQ_.begin(), sliceQ_.end(), 0.0);
74 >    std::fill(sliceCount_.begin(), sliceCount_.end(), 0);
75 >    
76 >    setOutputName(getPrefix(filename) + ".Qz");
77    }
90
91  TetrahedralityParamZ::~TetrahedralityParamZ()
92  {
93    Q_histogram_.clear();
94  }
78    
79 <  void TetrahedralityParamZ::initalizeHistogram()
80 <  {
81 <    std::fill(Q_histogram_.begin(), Q_histogram_.end(), 0);
79 >  TetrahedralityParamZ::~TetrahedralityParamZ() {
80 >    sliceQ_.clear();
81 >    sliceCount_.clear();
82 >    zBox_.clear();
83    }
84 <  
85 <
102 <  
103 <
104 <  void TetrahedralityParamZ::process()
105 <  {
84 >    
85 >  void TetrahedralityParamZ::process() {
86      Molecule* mol;
87      StuntDouble* sd;
88      StuntDouble* sd2;
# Line 111 | Line 91 | namespace OpenMD
91      RigidBody* rb;
92      int myIndex;
93      SimInfo::MoleculeIterator mi;
114    Molecule::RigidBodyIterator rbIter;
94      Molecule::IntegrableObjectIterator ioi;
95 +    Molecule::RigidBodyIterator rbIter;
96      Vector3d vec;
97 <    Vector3d ri, rj, rk, rik, rkj, dposition, tposition;
97 >    Vector3d ri, rj, rk, rik, rkj;
98      RealType r;
99      RealType cospsi;
100      RealType Qk;
121
101      std::vector<std::pair<RealType,StuntDouble*> > myNeighbors;
102 <    int isd1, isd2;
103 <    cerr << "After Creation of variables in TP:process()\n";
102 >    int isd;
103 >
104      DumpReader reader(info_, dumpFilename_);    
126    cerr << "The DumpReader was created?\n";
127    cerr << "nZbins: " << nZBins_ << "\n";
105      int nFrames = reader.getNFrames();
129    frameCounter_ = 0;
130    nProcessed_=nFrames/step_;
131    reader.readFrame(0);
132    currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
133    Mat3x3d hmat = currentSnapshot_->getHmat();
134    zBox_.push_back(hmat(2,2));
135    
136    RealType halfBoxZ_ = hmat(2,2) / 2.0;
106  
107 <    Distorted_.clear();
108 <    Tetrahedral_.clear();
109 <    int i;
110 <    for(i=0;i<nZBins_;i++)
111 <      {
112 <        sliceSDLists_[i].clear();
113 <      }
107 >    for (int istep = 0; istep < nFrames; istep += step_) {
108 >      reader.readFrame(istep);
109 >      currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
110 >      
111 >      Mat3x3d hmat = currentSnapshot_->getHmat();
112 >      zBox_.push_back(hmat(2,2));
113 >      
114 >      RealType halfBoxZ_ = hmat(2,2) / 2.0;      
115  
116 <    //LOOP OVER ALL FRAMES
117 <    for (int istep = 0; istep < nFrames; istep += step_)
118 <      {
119 <        int i;
150 <        for(i=0;i<nZBins_;i++)
151 <          {
152 <            count_[i]=0;
153 <          }    
154 <        
155 <        reader.readFrame(istep);
156 <        frameCounter_++;
157 <        currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
158 <        
159 <        if (evaluator_.isDynamic())
160 <          {
161 <            seleMan1_.setSelectionSet(evaluator_.evaluate());
162 <            seleMan2_.setSelectionSet(evaluator_.evaluate());
163 <          }
164 <        
116 >      if (evaluator_.isDynamic()) {
117 >        seleMan_.setSelectionSet(evaluator_.evaluate());
118 >      }
119 >      
120        // update the positions of atoms which belong to the rigidbodies
121 <      for (mol = info_->beginMolecule(mi); mol != NULL;mol = info_->nextMolecule(mi))
122 <        {
123 <          for (rb = mol->beginRigidBody(rbIter); rb != NULL;rb = mol->nextRigidBody(rbIter))
124 <            {
125 <              rb->updateAtoms();
126 <            }        
127 <        }          
121 >      for (mol = info_->beginMolecule(mi); mol != NULL;
122 >           mol = info_->nextMolecule(mi)) {
123 >        for (rb = mol->beginRigidBody(rbIter); rb != NULL;
124 >             rb = mol->nextRigidBody(rbIter)) {
125 >          rb->updateAtoms();
126 >        }
127 >      }
128 >      
129 >      // outer loop is over the selected StuntDoubles:
130 >      for (sd = seleMan_.beginSelected(isd); sd != NULL;
131 >           sd = seleMan_.nextSelected(isd)) {
132 >        
133 >        myIndex = sd->getGlobalIndex();
134  
135 <       // outer loop is over the selected StuntDoubles:
136 <      int idk=0;
137 <      for (sd = seleMan1_.beginSelected(isd1); sd != NULL;sd = seleMan1_.nextSelected(isd1))
138 <        {
139 <          myIndex = sd->getGlobalIndex();
140 <          Qk = 1.0;      
141 <          myNeighbors.clear();
181 <          // inner loop is over all StuntDoubles in the system:
182 <          //for (mol = info_->beginMolecule(mi); mol != NULL;mol = info_->nextMolecule(mi))
183 <            //{
184 <              //for (sd2 = mol->beginIntegrableObject(ioi); sd2 != NULL; sd2 = mol->nextIntegrableObject(ioi))
185 <                //{
186 <                for(sd2 = seleMan2_.beginSelected(isd2); sd2 != NULL; sd2 = seleMan2_.nextSelected(isd2)){
187 <                        if(sd2->getGlobalIndex() != myIndex){
188 <                        vec = sd->getPos() - sd2->getPos();      
189 <                        if (usePeriodicBoundaryConditions_)
190 <                                        currentSnapshot_->wrapVector(vec);
191 <                        r = vec.length();            
192 <
193 <                        // Check to see if neighbor is in bond cutoff
194 <                        if (r < rCut_){
195 <                                        myNeighbors.push_back(std::make_pair(r,sd2));
196 <                                }
197 <                        }
198 <                }
199 <           // }
200 <          // Sort the vector using predicate and std::sort
201 <          std::sort(myNeighbors.begin(), myNeighbors.end());      
202 <          //std::cerr << myNeighbors.size() <<  " neighbors within " << rCut_  << " A" << " \n";
203 <          // Use only the 4 closest neighbors to do the rest of the work:        
204 <          int nbors =  myNeighbors.size()> 4 ? 4 : myNeighbors.size();
205 <          int nang = int (0.5 * (nbors * (nbors - 1)));
206 <          
207 <          rk = sd->getPos();
208 <          for (int i = 0; i < nbors-1; i++)
209 <            {                
210 <              sdi = myNeighbors[i].second;
211 <              ri = sdi->getPos();
212 <              rik = rk - ri;
213 <              if (usePeriodicBoundaryConditions_)
214 <                currentSnapshot_->wrapVector(rik);            
215 <              rik.normalize();
216 <              
217 <              for (int j = i+1; j < nbors; j++)
218 <                {                    
219 <                  sdj = myNeighbors[j].second;
220 <                  rj = sdj->getPos();
221 <                  rkj = rk - rj;
222 <                  if (usePeriodicBoundaryConditions_)
223 <                    currentSnapshot_->wrapVector(rkj);
224 <                  rkj.normalize();
225 <                  
226 <                  cospsi = dot(rik,rkj);
227 <                  
228 <                  // Calculates scaled Qk for each molecule using calculated angles from 4 or fewer nearest neighbors.
229 <                  Qk = Qk - (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);
230 <                }
231 <            }
232 <          
233 <          //std::cerr<<nbors<<endl;
234 <           if (nang > 0)
235 <           {
236 <             //collectHistogram(Qk);
237 <              
238 <              // Saves positions of StuntDoubles & neighbors with distorted coordination (low Qk value)
239 <            if ((Qk < 0.55) && (Qk > 0.45))
240 <                {
241 <                  Distorted_.push_back(sd);
242 <                  dposition = sd->getPos();
243 <                }
244 <            
245 <            // Saves positions of StuntDoubles & neighbors with tetrahedral coordination (high Qk value)
246 <            if (Qk > 0)
247 <              {
248 <                Tetrahedral_.push_back(sd);
249 <                tposition = sd->getPos();
250 <              }
135 >        Qk = 1.0;        
136 >        myNeighbors.clear();
137 >        
138 >        // inner loop is over all StuntDoubles in the system:
139 >        
140 >        for (mol = info_->beginMolecule(mi); mol != NULL;
141 >             mol = info_->nextMolecule(mi)) {
142  
143 <           }
144 <          
145 <           //wrap the stuntdoubles into a cell      
146 <           Vector3d pos = sd->getPos();
147 <           if (usePeriodicBoundaryConditions_)
148 <             currentSnapshot_->wrapVector(pos);
149 <           sd->setPos(pos);
150 <           // shift molecules by half a box to have bins start at 0
151 <           int binNo = int(nZBins_ * (halfBoxZ_ + pos.z()) / hmat(2,2));
152 <           //Patrick took out the "halfBoxZ_" part in the line above to below
153 <           //int binNo = int(nZBins_ * (pos.z()) / hmat(2,2));
263 <           sliceSDLists_[binNo].push_back(Qk);
264 <           idk++;
265 <        }//outer sd loop
266 <      }//istep loop
267 <
268 <    //Averaging the value of Qk in each bin
269 <    for(int i=0;i< nZBins_; i++)
270 <      {
271 <        RealType Qsum=0;
272 <        for (unsigned int k = 0; k < sliceSDLists_[i].size(); ++k)
273 <          {
274 <            Qsum=Qsum+sliceSDLists_[i][k];
275 <            count_[i]++;
276 <          }
277 <        //std::cerr<<"past averagin Qk"<<endl;
278 <        //std::cerr<<Qsum<<endl;
279 <        if(count_[i]!=0)
280 <          {
281 <            Qave_.push_back(Qsum/count_[i]);
282 <          }
283 <        //std::cerr<<count[i]<<endl;
284 <      }
285 <    //std::cerr<<"nZBins_ = "<< nZBins_<<endl;
286 <    //Writing bin#:<Qk> to a file
287 <    std::ofstream rdfStream(outputFilename_.c_str());
288 <    if (rdfStream.is_open())
289 <      {
290 <        //rdfStream << "#QkZ\n";
291 <        //rdfStream << "#nFrames:\t" << nProcessed_ << "\n";
292 <        //rdfStream << "#selection: (" << selectionScript_ << ")\n";
293 <        //rdfStream << "#z\tdensity\n";
294 <        for (int i = 0; i < nZBins_; ++i)
295 <          {
296 <            if(count_[i]!=0)
297 <              {
298 <                rdfStream << ((hmat(2,2)*i)/nZBins_)+(hmat(2,2)/(2*nZBins_)) << "\t" << Qave_[i] << "\n";
299 <              }
300 <          }
301 <      }
302 <    
143 >          for (sd2 = mol->beginIntegrableObject(ioi); sd2 != NULL;
144 >               sd2 = mol->nextIntegrableObject(ioi)) {
145 >            
146 >            if (sd2->getGlobalIndex() != myIndex) {
147 >              
148 >              vec = sd->getPos() - sd2->getPos();      
149 >              
150 >              if (usePeriodicBoundaryConditions_)
151 >                currentSnapshot_->wrapVector(vec);
152 >              
153 >              r = vec.length();            
154  
155 +              // Check to see if neighbor is in bond cutoff
156 +              
157 +              if (r < rCut_) {                
158 +                myNeighbors.push_back(std::make_pair(r,sd2));
159 +              }
160 +            }
161 +          }
162 +        }
163 +        
164 +        // Sort the vector using predicate and std::sort
165 +        std::sort(myNeighbors.begin(), myNeighbors.end());
166 +        
167 +        // Use only the 4 closest neighbors to do the rest of the work:
168 +        
169 +        int nbors =  myNeighbors.size()> 4 ? 4 : myNeighbors.size();
170 +        int nang = int (0.5 * (nbors * (nbors - 1)));
171 +        
172 +        rk = sd->getPos();
173  
174 +        for (int i = 0; i < nbors-1; i++) {      
175  
176 +          sdi = myNeighbors[i].second;
177 +          ri = sdi->getPos();
178 +          rik = rk - ri;
179 +          if (usePeriodicBoundaryConditions_)
180 +            currentSnapshot_->wrapVector(rik);
181 +          
182 +          rik.normalize();
183  
184 <  
308 <    writeOrderParameter();
309 <    std::cerr << "number of distorted StuntDoubles = " << Distorted_.size() << "\n";
310 <    std::cerr << "number of tetrahedral StuntDoubles = " << Tetrahedral_.size() << "\n";
311 <    collectHistogram(Qk);
184 >          for (int j = i+1; j < nbors; j++) {      
185  
186 <  }//void TetrahedralityParam::process() loop
186 >            sdj = myNeighbors[j].second;
187 >            rj = sdj->getPos();
188 >            rkj = rk - rj;
189 >            if (usePeriodicBoundaryConditions_)
190 >              currentSnapshot_->wrapVector(rkj);
191 >            rkj.normalize();
192 >            
193 >            cospsi = dot(rik,rkj);          
194 >
195 >            // Calculates scaled Qk for each molecule using calculated
196 >            // angles from 4 or fewer nearest neighbors.
197 >            Qk -=  (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);            
198 >          }
199 >        }
200 >
201 >        if (nang > 0) {
202 >          if (usePeriodicBoundaryConditions_)
203 >            currentSnapshot_->wrapVector(rk);
204 >          
205 >          int binNo = int(nZBins_ * (halfBoxZ_ + rk.z()) / hmat(2,2));
206 >          sliceQ_[binNo] += Qk;
207 >          sliceCount_[binNo] += 1;
208 >        }  
209 >      }
210 >    }
211 >    writeQz();
212 >  }
213    
214 <  void TetrahedralityParamZ::collectHistogram(RealType Qk)
316 <  {
317 <  //if (Qk > MinQ_ && Qk < MaxQ_)
318 <  //  {
319 <  //    int whichBin = int((Qk - MinQ_) / deltaQ_);
320 <  //    Q_histogram_[whichBin] += 1;
321 <  //  }
322 <  }    
214 >  void TetrahedralityParamZ::writeQz() {
215  
216 <  void TetrahedralityParamZ::writeOrderParameter()
217 <  {  
218 <   int nSelected = 0;
219 <  std::ofstream osq((getOutputFileName() + "Q").c_str());
220 <  if (osq.is_open())
221 <    {
330 <        osq << "# Tetrahedrality Parameters\n";
331 <        osq << "# selection: (" << selectionScript_ << ")\n";
332 <        osq << "# \n";
333 <        osq.close();
216 >    // compute average box length:
217 >    
218 >    RealType zSum = 0.0;
219 >    for (std::vector<RealType>::iterator j = zBox_.begin();
220 >         j != zBox_.end(); ++j) {
221 >      zSum += *j;      
222      }
223 <  else
224 <    {
225 <        sprintf(painCave.errMsg, "TetrahedralityParamZ: unable to open %s\n",
226 <                (getOutputFileName() + "q").c_str());
227 <        painCave.isFatal = 1;
228 <        simError();  
229 <    }
230 <  DumpReader reader(info_, dumpFilename_);    
231 <  int nFrames = reader.getNFrames();
232 <  if (nFrames == 1)
233 <    {
234 <        std::vector<StuntDouble*>::iterator iter;
235 <        std::ofstream osd((getOutputFileName() + "dxyz").c_str());
236 <        if (osd.is_open())
237 <          {
238 <            osd << Distorted_.size() << "\n";
239 <            osd << "1000000.00000000;    34.52893134     0.00000000     0.00000000;     0.00000000    34.52893134     0.00000000;     0.00000000     0.00000000    34.52893134" << "\n";
240 <            
241 <            for (iter = Distorted_.begin(); iter != Distorted_.end(); ++iter)
242 <              {
355 <                Vector3d position;
356 <                position = (*iter)->getPos();
357 <                osd << "O  " << "\t";
358 <                for (unsigned int z=0; z<position.size(); z++)
359 <                  {
360 <                    osd << position[z] << "  " << "\t";
361 <                  }
362 <                osd << "\n";
363 <              }
364 <            osd.close();
365 <          }
366 <        std::ofstream ost((getOutputFileName() + "txyz").c_str());
367 <        if (ost.is_open())
368 <          {
369 <            ost << Tetrahedral_.size() << "\n";
370 <            ost << "1000000.00000000;    34.52893134     0.00000000     0.00000000;     0.00000000    34.52893134     0.00000000;     0.00000000     0.00000000    34.52893134" << "\n";
371 <            
372 <            for (iter = Tetrahedral_.begin(); iter != Tetrahedral_.end(); ++iter)
373 <              {
374 <                Vector3d position;              
375 <                position = (*iter)->getPos();
376 <                ost << "O  " << "\t";
377 <                for (unsigned int z=0; z<position.size(); z++)
378 <                  {
379 <                    ost << position[z] << "  " << "\t";
380 <                  }
381 <                ost << "\n";
382 <              }
383 <            ost.close();
384 <          }
385 <    }
223 >    RealType zAve = zSum / zBox_.size();
224 >
225 >    std::ofstream qZstream(outputFilename_.c_str());
226 >    if (qZstream.is_open()) {
227 >      qZstream << "#Tetrahedrality Parameters (z)\n";
228 >      qZstream << "#nFrames:\t" << zBox_.size() << "\n";
229 >      qZstream << "#selection: (" << selectionScript_ << ")\n";
230 >      qZstream << "#z\tQk\n";
231 >      for (unsigned int i = 0; i < sliceQ_.size(); ++i) {
232 >        RealType z = zAve * (i+0.5) / sliceQ_.size();
233 >        qZstream << z << "\t" << sliceQ_[i] / sliceCount_[i] << "\n";
234 >      }
235 >      
236 >    } else {      
237 >      sprintf(painCave.errMsg, "TetrahedralityParamZ: unable to open %s\n",
238 >              outputFilename_.c_str());
239 >      painCave.isFatal = 1;
240 >      simError();  
241 >    }    
242 >    qZstream.close();
243    }
244   }
245  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines