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 1796 by gezelter, Mon Sep 10 18:38:44 2012 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 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;
63 <    //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),
61 >      selectionScript1_(sele1), selectionScript2_(sele2),
62 >      seleMan1_(info), seleMan2_(info), evaluator1_(info), evaluator2_(info),
63 >      nZBins_(nzbins) {
64      
65 <    evaluator_.loadScriptString(sele);
66 <    if (!evaluator_.isDynamic())
67 <      {
68 <        seleMan1_.setSelectionSet(evaluator_.evaluate());
69 <        seleMan2_.setSelectionSet(evaluator_.evaluate());
70 <      }
71 <
72 <    // Set up cutoff radius:
65 >    evaluator1_.loadScriptString(sele1);
66 >    if (!evaluator1_.isDynamic()) {
67 >      seleMan1_.setSelectionSet(evaluator1_.evaluate());
68 >    }
69 >    evaluator2_.loadScriptString(sele2);
70 >    if (!evaluator2_.isDynamic()) {
71 >      seleMan2_.setSelectionSet(evaluator2_.evaluate());
72 >    }
73 >    
74 >    // Set up cutoff radius:    
75      rCut_ = rCut;
76  
77 <    // Q can take values from 0 to 1
78 <    MinQ_ = 0.0;
79 <    MaxQ_ = 1.1;
80 <    deltaQ_ = (MaxQ_ - MinQ_)/nzbins;
77 >    // fixed number of bins
78 >    sliceQ_.resize(nZBins_);
79 >    sliceCount_.resize(nZBins_);    
80 >    std::fill(sliceQ_.begin(), sliceQ_.end(), 0.0);
81 >    std::fill(sliceCount_.begin(), sliceCount_.end(), 0);
82 >    
83 >    setOutputName(getPrefix(filename) + ".Qz");
84    }
90
91  TetrahedralityParamZ::~TetrahedralityParamZ()
92  {
93    Q_histogram_.clear();
94  }
85    
86 <  void TetrahedralityParamZ::initalizeHistogram()
87 <  {
88 <    std::fill(Q_histogram_.begin(), Q_histogram_.end(), 0);
86 >  TetrahedralityParamZ::~TetrahedralityParamZ() {
87 >    sliceQ_.clear();
88 >    sliceCount_.clear();
89 >    zBox_.clear();
90    }
91 <  
92 <
102 <  
103 <
104 <  void TetrahedralityParamZ::process()
105 <  {
91 >    
92 >  void TetrahedralityParamZ::process() {
93      Molecule* mol;
94      StuntDouble* sd;
95      StuntDouble* sd2;
# Line 113 | Line 100 | namespace OpenMD
100      SimInfo::MoleculeIterator mi;
101      Molecule::RigidBodyIterator rbIter;
102      Vector3d vec;
103 <    Vector3d ri, rj, rk, rik, rkj, dposition, tposition;
103 >    Vector3d ri, rj, rk, rik, rkj;
104      RealType r;
105      RealType cospsi;
106      RealType Qk;
120
107      std::vector<std::pair<RealType,StuntDouble*> > myNeighbors;
108 <    int isd1, isd2;
109 <    cerr << "After Creation of variables in TP:process()\n";
108 >    int isd1;
109 >    int isd2;
110 >
111      DumpReader reader(info_, dumpFilename_);    
125    cerr << "The DumpReader was created?\n";
126    cerr << "nZbins: " << nZBins_ << "\n";
112      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;
113  
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
114      for (int istep = 0; istep < nFrames; istep += step_) {
146      int i;
147      for(i=0;i<nZBins_;i++) {
148        count_[i]=0;
149      }
150        
115        reader.readFrame(istep);
152      frameCounter_++;
116        currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
117        
118 <      if (evaluator_.isDynamic()) {
119 <        seleMan1_.setSelectionSet(evaluator_.evaluate());
120 <        seleMan2_.setSelectionSet(evaluator_.evaluate());
118 >      Mat3x3d hmat = currentSnapshot_->getHmat();
119 >      zBox_.push_back(hmat(2,2));
120 >      
121 >      RealType halfBoxZ_ = hmat(2,2) / 2.0;      
122 >
123 >      if (evaluator1_.isDynamic()) {
124 >        seleMan1_.setSelectionSet(evaluator1_.evaluate());
125        }
126 <        
126 >      
127 >      if (evaluator2_.isDynamic()) {
128 >        seleMan2_.setSelectionSet(evaluator2_.evaluate());
129 >      }
130 >      
131        // update the positions of atoms which belong to the rigidbodies
132        for (mol = info_->beginMolecule(mi); mol != NULL;
133             mol = info_->nextMolecule(mi)) {
134          for (rb = mol->beginRigidBody(rbIter); rb != NULL;
135               rb = mol->nextRigidBody(rbIter)) {
136            rb->updateAtoms();
137 <        }        
138 <      }          
139 <
137 >        }
138 >      }
139 >      
140        // outer loop is over the selected StuntDoubles:
170      int idk=0;
141        for (sd = seleMan1_.beginSelected(isd1); sd != NULL;
142             sd = seleMan1_.nextSelected(isd1)) {
143 +        
144          myIndex = sd->getGlobalIndex();
145 +        
146          Qk = 1.0;        
147 <        myNeighbors.clear();
148 <        for(sd2 = seleMan2_.beginSelected(isd2); sd2 != NULL;
149 <            sd2 = seleMan2_.nextSelected(isd2)){
150 <          if(sd2->getGlobalIndex() != myIndex){
147 >        myNeighbors.clear();      
148 >
149 >        for (sd2 = seleMan2_.beginSelected(isd2); sd2 != NULL;
150 >             sd2 = seleMan2_.nextSelected(isd2)) {
151 >          
152 >          if (sd2->getGlobalIndex() != myIndex) {
153 >            
154              vec = sd->getPos() - sd2->getPos();      
155 +            
156              if (usePeriodicBoundaryConditions_)
157                currentSnapshot_->wrapVector(vec);
158 +            
159              r = vec.length();            
160              
161              // Check to see if neighbor is in bond cutoff
162 <            if (r < rCut_) {
162 >            
163 >            if (r < rCut_) {                
164                myNeighbors.push_back(std::make_pair(r,sd2));
165              }
166            }
167          }
168          
169          // Sort the vector using predicate and std::sort
170 <        std::sort(myNeighbors.begin(), myNeighbors.end());        
171 <        //std::cerr << myNeighbors.size() <<  " neighbors within " << rCut_  << " A" << " \n";
172 <        // Use only the 4 closest neighbors to do the rest of the work:  
173 <        int nbors =  myNeighbors.size() > 4 ? 4 : myNeighbors.size();
170 >        std::sort(myNeighbors.begin(), myNeighbors.end());
171 >        
172 >        // Use only the 4 closest neighbors to do the rest of the work:
173 >        
174 >        int nbors =  myNeighbors.size()> 4 ? 4 : myNeighbors.size();
175          int nang = int (0.5 * (nbors * (nbors - 1)));
176 <        
176 >        
177          rk = sd->getPos();
178 <        for (int i = 0; i < nbors-1; i++) {
178 >        
179 >        for (int i = 0; i < nbors-1; i++) {      
180 >          
181            sdi = myNeighbors[i].second;
182            ri = sdi->getPos();
183            rik = rk - ri;
184            if (usePeriodicBoundaryConditions_)
185 <            currentSnapshot_->wrapVector(rik);        
185 >            currentSnapshot_->wrapVector(rik);
186 >          
187            rik.normalize();
188            
189 <          for (int j = i+1; j < nbors; j++) {
189 >          for (int j = i+1; j < nbors; j++) {      
190 >            
191              sdj = myNeighbors[j].second;
192              rj = sdj->getPos();
193              rkj = rk - rj;
# Line 212 | Line 195 | namespace OpenMD
195                currentSnapshot_->wrapVector(rkj);
196              rkj.normalize();
197              
198 <            cospsi = dot(rik,rkj);
198 >            cospsi = dot(rik,rkj);          
199              
200              // Calculates scaled Qk for each molecule using calculated
201              // angles from 4 or fewer nearest neighbors.
202 <            Qk = Qk - (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);
202 >            Qk -=  (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);            
203            }
204          }
205 <        
223 <        //std::cerr<<nbors<<endl;
205 >        
206          if (nang > 0) {
207 <          //collectHistogram(Qk);
207 >          if (usePeriodicBoundaryConditions_)
208 >            currentSnapshot_->wrapVector(rk);
209            
210 <          // Saves positions of StuntDoubles & neighbors with
211 <          // distorted coordination (low Qk value)
212 <          if ((Qk < 0.55) && (Qk > 0.45)) {
213 <            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]++;
210 >          int binNo = int(nZBins_ * (halfBoxZ_ + rk.z()) / hmat(2,2));
211 >          sliceQ_[binNo] += Qk;
212 >          sliceCount_[binNo] += 1;
213 >        }  
214        }
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;
215      }
216 <    //std::cerr<<"nZBins_ = "<< nZBins_<<endl;
217 <    //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
216 >    writeQz();
217 >  }
218    
219 <  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 <  }    
219 >  void TetrahedralityParamZ::writeQz() {
220  
221 <  void TetrahedralityParamZ::writeOrderParameter() {
222 <    int nSelected = 0;
223 <    std::ofstream osq((getOutputFileName() + "Q").c_str());
224 <    if (osq.is_open()) {
225 <      osq << "# Tetrahedrality Parameters\n";
226 <      osq << "# selection: (" << selectionScript_ << ")\n";
310 <      osq << "# \n";
311 <      osq.close();
312 <    } else {
313 <      sprintf(painCave.errMsg, "TetrahedralityParamZ: unable to open %s\n",
314 <              (getOutputFileName() + "q").c_str());
315 <      painCave.isFatal = 1;
316 <      simError();  
221 >    // compute average box length:
222 >    
223 >    RealType zSum = 0.0;
224 >    for (std::vector<RealType>::iterator j = zBox_.begin();
225 >         j != zBox_.end(); ++j) {
226 >      zSum += *j;      
227      }
228 <    DumpReader reader(info_, dumpFilename_);    
229 <    int nFrames = reader.getNFrames();
230 <    if (nFrames == 1) {
231 <      std::vector<StuntDouble*>::iterator iter;
232 <      std::ofstream osd((getOutputFileName() + "dxyz").c_str());
233 <      if (osd.is_open()) {
234 <        osd << Distorted_.size() << "\n\n";
235 <        
236 <        for (iter = Distorted_.begin(); iter != Distorted_.end(); ++iter) {
237 <          Vector3d position;
238 <          position = (*iter)->getPos();
239 <          osd << "O  " << "\t";
240 <          for (unsigned int z=0; z<position.size(); z++) {
331 <            osd << position[z] << "  " << "\t";
332 <          }
333 <          osd << "\n";
228 >    RealType zAve = zSum / zBox_.size();
229 >
230 >    std::ofstream qZstream(outputFilename_.c_str());
231 >    if (qZstream.is_open()) {
232 >      qZstream << "#Tetrahedrality Parameters (z)\n";
233 >      qZstream << "#nFrames:\t" << zBox_.size() << "\n";
234 >      qZstream << "#selection 1: (" << selectionScript1_ << ")\n";
235 >      qZstream << "#selection 2: (" << selectionScript2_ << ")\n";
236 >      qZstream << "#z\tQk\n";
237 >      for (unsigned int i = 0; i < sliceQ_.size(); ++i) {
238 >        RealType z = zAve * (i+0.5) / sliceQ_.size();
239 >        if (sliceCount_[i] != 0) {
240 >          qZstream << z << "\t" << sliceQ_[i] / sliceCount_[i] << "\n";
241          }
335        osd.close();
242        }
243 <      std::ofstream ost((getOutputFileName() + "txyz").c_str());
244 <      if (ost.is_open()) {
245 <        ost << Tetrahedral_.size() << "\n\n";      
246 <        for (iter = Tetrahedral_.begin(); iter != Tetrahedral_.end(); ++iter) {
247 <          Vector3d position;            
248 <          position = (*iter)->getPos();
249 <          ost << "O  " << "\t";
250 <          for (unsigned int z=0; z<position.size(); z++) {
345 <            ost << position[z] << "  " << "\t";
346 <          }
347 <          ost << "\n";
348 <        }
349 <        ost.close();
350 <      }
351 <    }
243 >      
244 >    } else {      
245 >      sprintf(painCave.errMsg, "TetrahedralityParamZ: unable to open %s\n",
246 >              outputFilename_.c_str());
247 >      painCave.isFatal = 1;
248 >      simError();  
249 >    }    
250 >    qZstream.close();
251    }
252   }
253  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines