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

Comparing trunk/src/applications/staticProps/TetrahedralityParamZ.cpp (file contents):
Revision 1797 by gezelter, Mon Sep 10 20:58:00 2012 UTC vs.
Revision 1879 by gezelter, Sun Jun 16 15:15:42 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 < *
38 > * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).          
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)
61 <  {
62 <    //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& sele1,
58 >                                             const std::string& sele2,
59 >                                             double rCut, int nzbins)
60 >    : StaticAnalyser(info, filename), selectionScript1_(sele1),
61 >      evaluator1_(info), seleMan1_(info), selectionScript2_(sele2),
62 >      evaluator2_(info), seleMan2_(info), nZBins_(nzbins) {
63      
64 <    evaluator_.loadScriptString(sele);
65 <    if (!evaluator_.isDynamic())
66 <      {
67 <        seleMan1_.setSelectionSet(evaluator_.evaluate());
68 <        seleMan2_.setSelectionSet(evaluator_.evaluate());
69 <      }
70 <
71 <    // Set up cutoff radius:
64 >    evaluator1_.loadScriptString(sele1);
65 >    if (!evaluator1_.isDynamic()) {
66 >      seleMan1_.setSelectionSet(evaluator1_.evaluate());
67 >    }
68 >    evaluator2_.loadScriptString(sele2);
69 >    if (!evaluator2_.isDynamic()) {
70 >      seleMan2_.setSelectionSet(evaluator2_.evaluate());
71 >    }
72 >    
73 >    // Set up cutoff radius:    
74      rCut_ = rCut;
75  
76 <    // Q can take values from 0 to 1
77 <    MinQ_ = 0.0;
78 <    MaxQ_ = 1.1;
79 <    deltaQ_ = (MaxQ_ - MinQ_)/nzbins;
76 >    // fixed number of bins
77 >    sliceQ_.resize(nZBins_);
78 >    sliceCount_.resize(nZBins_);    
79 >    std::fill(sliceQ_.begin(), sliceQ_.end(), 0.0);
80 >    std::fill(sliceCount_.begin(), sliceCount_.end(), 0);
81 >    
82 >    setOutputName(getPrefix(filename) + ".Qz");
83    }
90
91  TetrahedralityParamZ::~TetrahedralityParamZ()
92  {
93    Q_histogram_.clear();
94  }
84    
85 <  void TetrahedralityParamZ::initalizeHistogram()
86 <  {
87 <    std::fill(Q_histogram_.begin(), Q_histogram_.end(), 0);
85 >  TetrahedralityParamZ::~TetrahedralityParamZ() {
86 >    sliceQ_.clear();
87 >    sliceCount_.clear();
88 >    zBox_.clear();
89    }
90 <  
91 <
102 <  
103 <
104 <  void TetrahedralityParamZ::process()
105 <  {
90 >    
91 >  void TetrahedralityParamZ::process() {
92      Molecule* mol;
93      StuntDouble* sd;
94      StuntDouble* sd2;
# Line 113 | Line 99 | namespace OpenMD
99      SimInfo::MoleculeIterator mi;
100      Molecule::RigidBodyIterator rbIter;
101      Vector3d vec;
102 <    Vector3d ri, rj, rk, rik, rkj, dposition, tposition;
102 >    Vector3d ri, rj, rk, rik, rkj;
103      RealType r;
104      RealType cospsi;
105      RealType Qk;
120
106      std::vector<std::pair<RealType,StuntDouble*> > myNeighbors;
107 <    int isd1, isd2;
108 <    cerr << "After Creation of variables in TP:process()\n";
107 >    int isd1;
108 >    int isd2;
109 >
110      DumpReader reader(info_, dumpFilename_);    
125    cerr << "The DumpReader was created?\n";
126    cerr << "nZbins: " << nZBins_ << "\n";
111      int nFrames = reader.getNFrames();
128    frameCounter_ = 0;
129    nProcessed_=nFrames/step_;
130    reader.readFrame(0);
131    currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
132    Mat3x3d hmat = currentSnapshot_->getHmat();
133    zBox_.push_back(hmat(2,2));
134    
135    RealType halfBoxZ_ = hmat(2,2) / 2.0;
112  
137    Distorted_.clear();
138    Tetrahedral_.clear();
139    int i;
140    for(i=0;i<nZBins_;i++) {
141      sliceSDLists_[i].clear();
142    }
143
144    //LOOP OVER ALL FRAMES
113      for (int istep = 0; istep < nFrames; istep += step_) {
146      int i;
147      for(i=0;i<nZBins_;i++) {
148        count_[i]=0;
149      }
150        
114        reader.readFrame(istep);
152      frameCounter_++;
115        currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
116        
117 <      if (evaluator_.isDynamic()) {
118 <        seleMan1_.setSelectionSet(evaluator_.evaluate());
119 <        seleMan2_.setSelectionSet(evaluator_.evaluate());
117 >      Mat3x3d hmat = currentSnapshot_->getHmat();
118 >      zBox_.push_back(hmat(2,2));
119 >      
120 >      RealType halfBoxZ_ = hmat(2,2) / 2.0;      
121 >
122 >      if (evaluator1_.isDynamic()) {
123 >        seleMan1_.setSelectionSet(evaluator1_.evaluate());
124        }
125 <        
125 >      
126 >      if (evaluator2_.isDynamic()) {
127 >        seleMan2_.setSelectionSet(evaluator2_.evaluate());
128 >      }
129 >      
130        // update the positions of atoms which belong to the rigidbodies
131        for (mol = info_->beginMolecule(mi); mol != NULL;
132             mol = info_->nextMolecule(mi)) {
133          for (rb = mol->beginRigidBody(rbIter); rb != NULL;
134               rb = mol->nextRigidBody(rbIter)) {
135            rb->updateAtoms();
136 <        }        
137 <      }          
138 <
136 >        }
137 >      }
138 >      
139        // outer loop is over the selected StuntDoubles:
170      int idk=0;
140        for (sd = seleMan1_.beginSelected(isd1); sd != NULL;
141             sd = seleMan1_.nextSelected(isd1)) {
142 +        
143          myIndex = sd->getGlobalIndex();
144 +        
145          Qk = 1.0;        
146 <        myNeighbors.clear();
147 <        for(sd2 = seleMan2_.beginSelected(isd2); sd2 != NULL;
148 <            sd2 = seleMan2_.nextSelected(isd2)){
149 <          if(sd2->getGlobalIndex() != myIndex){
146 >        myNeighbors.clear();      
147 >
148 >        for (sd2 = seleMan2_.beginSelected(isd2); sd2 != NULL;
149 >             sd2 = seleMan2_.nextSelected(isd2)) {
150 >          
151 >          if (sd2->getGlobalIndex() != myIndex) {
152 >            
153              vec = sd->getPos() - sd2->getPos();      
154 +            
155              if (usePeriodicBoundaryConditions_)
156                currentSnapshot_->wrapVector(vec);
157 +            
158              r = vec.length();            
159              
160              // Check to see if neighbor is in bond cutoff
161 <            if (r < rCut_) {
161 >            
162 >            if (r < rCut_) {                
163                myNeighbors.push_back(std::make_pair(r,sd2));
164              }
165            }
166          }
167          
168          // Sort the vector using predicate and std::sort
169 <        std::sort(myNeighbors.begin(), myNeighbors.end());        
170 <        //std::cerr << myNeighbors.size() <<  " neighbors within " << rCut_  << " A" << " \n";
171 <        // Use only the 4 closest neighbors to do the rest of the work:  
172 <        int nbors =  myNeighbors.size() > 4 ? 4 : myNeighbors.size();
169 >        std::sort(myNeighbors.begin(), myNeighbors.end());
170 >        
171 >        // Use only the 4 closest neighbors to do the rest of the work:
172 >        
173 >        int nbors =  myNeighbors.size()> 4 ? 4 : myNeighbors.size();
174          int nang = int (0.5 * (nbors * (nbors - 1)));
175 <        
175 >        
176          rk = sd->getPos();
177 <        for (int i = 0; i < nbors-1; i++) {
177 >        
178 >        for (int i = 0; i < nbors-1; i++) {      
179 >          
180            sdi = myNeighbors[i].second;
181            ri = sdi->getPos();
182            rik = rk - ri;
183            if (usePeriodicBoundaryConditions_)
184 <            currentSnapshot_->wrapVector(rik);        
184 >            currentSnapshot_->wrapVector(rik);
185 >          
186            rik.normalize();
187            
188 <          for (int j = i+1; j < nbors; j++) {
188 >          for (int j = i+1; j < nbors; j++) {      
189 >            
190              sdj = myNeighbors[j].second;
191              rj = sdj->getPos();
192              rkj = rk - rj;
# Line 212 | Line 194 | namespace OpenMD
194                currentSnapshot_->wrapVector(rkj);
195              rkj.normalize();
196              
197 <            cospsi = dot(rik,rkj);
197 >            cospsi = dot(rik,rkj);          
198              
199              // Calculates scaled Qk for each molecule using calculated
200              // angles from 4 or fewer nearest neighbors.
201 <            Qk = Qk - (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);
201 >            Qk -=  (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);            
202            }
203          }
204 <        
223 <        //std::cerr<<nbors<<endl;
204 >        
205          if (nang > 0) {
206 <          //collectHistogram(Qk);
206 >          if (usePeriodicBoundaryConditions_)
207 >            currentSnapshot_->wrapVector(rk);
208            
209 <          // Saves positions of StuntDoubles & neighbors with
210 <          // distorted coordination (low Qk value)
211 <          if ((Qk < 0.55) && (Qk > 0.45)) {
212 <            Distorted_.push_back(sd);
231 <            dposition = sd->getPos();
232 <          }
233 <          
234 <          // Saves positions of StuntDoubles & neighbors with
235 <          // tetrahedral coordination (high Qk value)
236 <          if (Qk > 0) {
237 <            Tetrahedral_.push_back(sd);
238 <            tposition = sd->getPos();
239 <          }
240 <          
241 <        }
242 <        
243 <        //wrap the stuntdoubles into a cell      
244 <        Vector3d pos = sd->getPos();
245 <        if (usePeriodicBoundaryConditions_)
246 <          currentSnapshot_->wrapVector(pos);
247 <        sd->setPos(pos);
248 <        // shift molecules by half a box to have bins start at 0
249 <        int binNo = int(nZBins_ * (halfBoxZ_ + pos.z()) / hmat(2,2));
250 <        // Patrick took out the "halfBoxZ_" part in the line above to below
251 <        // int binNo = int(nZBins_ * (pos.z()) / hmat(2,2));
252 <        sliceSDLists_[binNo].push_back(Qk);
253 <        idk++;
254 <      }//outer sd loop
255 <    }//istep loop
256 <
257 <    //Averaging the value of Qk in each bin
258 <    for(int i=0; i< nZBins_; i++) {
259 <      RealType Qsum=0;
260 <      for (unsigned int k = 0; k < sliceSDLists_[i].size(); ++k) {        
261 <        Qsum=Qsum+sliceSDLists_[i][k];
262 <        count_[i]++;
209 >          int binNo = int(nZBins_ * (halfBoxZ_ + rk.z()) / hmat(2,2));
210 >          sliceQ_[binNo] += Qk;
211 >          sliceCount_[binNo] += 1;
212 >        }  
213        }
264      //std::cerr<<"past averagin Qk"<<endl;
265      //std::cerr<<Qsum<<endl;
266      if(count_[i]!=0) {
267        Qave_.push_back(Qsum/count_[i]);
268      }
269      //std::cerr<<count[i]<<endl;
214      }
215 <    //std::cerr<<"nZBins_ = "<< nZBins_<<endl;
216 <    //Writing bin#:<Qk> to a file
273 <    std::ofstream rdfStream(outputFilename_.c_str());
274 <    if (rdfStream.is_open()) {
275 <      //rdfStream << "#QkZ\n";
276 <      //rdfStream << "#nFrames:\t" << nProcessed_ << "\n";
277 <      //rdfStream << "#selection: (" << selectionScript_ << ")\n";
278 <      //rdfStream << "#z\tdensity\n";
279 <      for (int i = 0; i < nZBins_; ++i) {
280 <        if(count_[i]!=0) {
281 <          rdfStream << ((hmat(2,2)*i)/nZBins_)+(hmat(2,2)/(2*nZBins_))
282 <                    << "\t" << Qave_[i] << "\n";
283 <        }
284 <      }
285 <    }
286 <    
287 <    writeOrderParameter();
288 <    std::cerr << "number of distorted StuntDoubles = "
289 <              << Distorted_.size() << "\n";
290 <    std::cerr << "number of tetrahedral StuntDoubles = "
291 <              << Tetrahedral_.size() << "\n";
292 <    collectHistogram(Qk);
293 <
294 <  }//void TetrahedralityParam::process() loop
215 >    writeQz();
216 >  }
217    
218 <  void TetrahedralityParamZ::collectHistogram(RealType Qk) {
297 <    //if (Qk > MinQ_ && Qk < MaxQ_)
298 <    //  {
299 <    //  int whichBin = int((Qk - MinQ_) / deltaQ_);
300 <    //  Q_histogram_[whichBin] += 1;
301 <    //  }
302 <  }    
218 >  void TetrahedralityParamZ::writeQz() {
219  
220 <  void TetrahedralityParamZ::writeOrderParameter() {
221 <    std::ofstream osq((getOutputFileName() + "Q").c_str());
222 <    if (osq.is_open()) {
223 <      osq << "# Tetrahedrality Parameters\n";
224 <      osq << "# selection: (" << selectionScript_ << ")\n";
225 <      osq << "# \n";
226 <      osq.close();
227 <    } else {
220 >    // compute average box length:
221 >    
222 >    RealType zSum = 0.0;
223 >    for (std::vector<RealType>::iterator j = zBox_.begin();
224 >         j != zBox_.end(); ++j) {
225 >      zSum += *j;      
226 >    }
227 >    RealType zAve = zSum / zBox_.size();
228 >
229 >    std::ofstream qZstream(outputFilename_.c_str());
230 >    if (qZstream.is_open()) {
231 >      qZstream << "#Tetrahedrality Parameters (z)\n";
232 >      qZstream << "#nFrames:\t" << zBox_.size() << "\n";
233 >      qZstream << "#selection 1: (" << selectionScript1_ << ")\n";
234 >      qZstream << "#selection 2: (" << selectionScript2_ << ")\n";
235 >      qZstream << "#z\tQk\n";
236 >      for (unsigned int i = 0; i < sliceQ_.size(); ++i) {
237 >        RealType z = zAve * (i+0.5) / sliceQ_.size();
238 >        qZstream << z << "\t" << sliceQ_[i] / sliceCount_[i] << "\n";
239 >      }
240 >      
241 >    } else {      
242        sprintf(painCave.errMsg, "TetrahedralityParamZ: unable to open %s\n",
243 <              (getOutputFileName() + "q").c_str());
243 >              outputFilename_.c_str());
244        painCave.isFatal = 1;
245        simError();  
246 <    }
247 <    DumpReader reader(info_, dumpFilename_);    
318 <    int nFrames = reader.getNFrames();
319 <    if (nFrames == 1) {
320 <      std::vector<StuntDouble*>::iterator iter;
321 <      std::ofstream osd((getOutputFileName() + "dxyz").c_str());
322 <      if (osd.is_open()) {
323 <        osd << Distorted_.size() << "\n\n";
324 <        
325 <        for (iter = Distorted_.begin(); iter != Distorted_.end(); ++iter) {
326 <          Vector3d position;
327 <          position = (*iter)->getPos();
328 <          osd << "O  " << "\t";
329 <          for (unsigned int z=0; z<position.size(); z++) {
330 <            osd << position[z] << "  " << "\t";
331 <          }
332 <          osd << "\n";
333 <        }
334 <        osd.close();
335 <      }
336 <      std::ofstream ost((getOutputFileName() + "txyz").c_str());
337 <      if (ost.is_open()) {
338 <        ost << Tetrahedral_.size() << "\n\n";      
339 <        for (iter = Tetrahedral_.begin(); iter != Tetrahedral_.end(); ++iter) {
340 <          Vector3d position;            
341 <          position = (*iter)->getPos();
342 <          ost << "O  " << "\t";
343 <          for (unsigned int z=0; z<position.size(); z++) {
344 <            ost << position[z] << "  " << "\t";
345 <          }
346 <          ost << "\n";
347 <        }
348 <        ost.close();
349 <      }
350 <    }
246 >    }    
247 >    qZstream.close();
248    }
249   }
250  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines