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 1782 by gezelter, Wed Aug 22 02:28:28 2012 UTC vs.
Revision 2025 by gezelter, Tue Oct 21 00:38:44 2014 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 112 | Line 98 | namespace OpenMD
98      int myIndex;
99      SimInfo::MoleculeIterator mi;
100      Molecule::RigidBodyIterator rbIter;
115    Molecule::IntegrableObjectIterator ioi;
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;
121
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_);    
126    cerr << "The DumpReader was created?\n";
127    cerr << "nZbins: " << nZBins_ << "\n";
111      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;
112  
113 <    Distorted_.clear();
114 <    Tetrahedral_.clear();
115 <    int i;
116 <    for(i=0;i<nZBins_;i++)
117 <      {
118 <        sliceSDLists_[i].clear();
119 <      }
113 >    for (int istep = 0; istep < nFrames; istep += step_) {
114 >      reader.readFrame(istep);
115 >      currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
116 >      
117 >      Mat3x3d hmat = currentSnapshot_->getHmat();
118 >      zBox_.push_back(hmat(2,2));
119 >      
120 >      RealType halfBoxZ_ = hmat(2,2) / 2.0;      
121  
122 <    //LOOP OVER ALL FRAMES
123 <    for (int istep = 0; istep < nFrames; istep += step_)
124 <      {
125 <        int i;
126 <        for(i=0;i<nZBins_;i++)
127 <          {
128 <            count_[i]=0;
129 <          }    
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 <        
122 >      if (evaluator1_.isDynamic()) {
123 >        seleMan1_.setSelectionSet(evaluator1_.evaluate());
124 >      }
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;mol = info_->nextMolecule(mi))
132 <        {
133 <          for (rb = mol->beginRigidBody(rbIter); rb != NULL;rb = mol->nextRigidBody(rbIter))
134 <            {
135 <              rb->updateAtoms();
136 <            }        
137 <        }          
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 >      
139 >      // outer loop is over the selected StuntDoubles:
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  
148 <       // outer loop is over the selected StuntDoubles:
149 <      int idk=0;
150 <      for (sd = seleMan1_.beginSelected(isd1); sd != NULL;sd = seleMan1_.nextSelected(isd1))
151 <        {
152 <          myIndex = sd->getGlobalIndex();
153 <          Qk = 1.0;      
154 <          myNeighbors.clear();
155 <          // inner loop is over all StuntDoubles in the system:
156 <          //for (mol = info_->beginMolecule(mi); mol != NULL;mol = info_->nextMolecule(mi))
157 <            //{
158 <              //for (sd2 = mol->beginIntegrableObject(ioi); sd2 != NULL; sd2 = mol->nextIntegrableObject(ioi))
159 <                //{
160 <                for(sd2 = seleMan2_.beginSelected(isd2); sd2 != NULL; sd2 = seleMan2_.nextSelected(isd2)){
161 <                        if(sd2->getGlobalIndex() != myIndex){
162 <                        vec = sd->getPos() - sd2->getPos();      
163 <                        if (usePeriodicBoundaryConditions_)
164 <                                        currentSnapshot_->wrapVector(vec);
165 <                        r = vec.length();            
166 <
167 <                        // Check to see if neighbor is in bond cutoff
168 <                        if (r < rCut_){
169 <                                        myNeighbors.push_back(std::make_pair(r,sd2));
170 <                                }
171 <                        }
172 <                }
173 <           // }
174 <          // Sort the vector using predicate and std::sort
175 <          std::sort(myNeighbors.begin(), myNeighbors.end());      
176 <          //std::cerr << myNeighbors.size() <<  " neighbors within " << rCut_  << " A" << " \n";
177 <          // Use only the 4 closest neighbors to do the rest of the work:        
178 <          int nbors =  myNeighbors.size()> 4 ? 4 : myNeighbors.size();
179 <          int nang = int (0.5 * (nbors * (nbors - 1)));
180 <          
181 <          rk = sd->getPos();
182 <          for (int i = 0; i < nbors-1; i++)
183 <            {                
184 <              sdi = myNeighbors[i].second;
185 <              ri = sdi->getPos();
186 <              rik = rk - ri;
187 <              if (usePeriodicBoundaryConditions_)
188 <                currentSnapshot_->wrapVector(rik);            
189 <              rik.normalize();
190 <              
191 <              for (int j = i+1; j < nbors; j++)
192 <                {                    
193 <                  sdj = myNeighbors[j].second;
194 <                  rj = sdj->getPos();
195 <                  rkj = rk - rj;
196 <                  if (usePeriodicBoundaryConditions_)
197 <                    currentSnapshot_->wrapVector(rkj);
198 <                  rkj.normalize();
199 <                  
200 <                  cospsi = dot(rik,rkj);
201 <                  
202 <                  // Calculates scaled Qk for each molecule using calculated angles from 4 or fewer nearest neighbors.
203 <                  Qk = Qk - (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);
204 <                }
205 <            }
206 <          
207 <          //std::cerr<<nbors<<endl;
208 <           if (nang > 0)
209 <           {
210 <             //collectHistogram(Qk);
211 <              
212 <              // 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 <              }
251 <
252 <           }
253 <          
254 <           //wrap the stuntdoubles into a cell      
255 <           Vector3d pos = sd->getPos();
256 <           if (usePeriodicBoundaryConditions_)
257 <             currentSnapshot_->wrapVector(pos);
258 <           sd->setPos(pos);
259 <           // shift molecules by half a box to have bins start at 0
260 <           int binNo = int(nZBins_ * (halfBoxZ_ + pos.z()) / hmat(2,2));
261 <           //Patrick took out the "halfBoxZ_" part in the line above to below
262 <           //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;
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 >            
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 >        
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 >        
176 >        rk = sd->getPos();
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);
185 >          
186 >          rik.normalize();
187 >          
188 >          for (int j = i+1; j < nbors; j++) {      
189 >            
190 >            sdj = myNeighbors[j].second;
191 >            rj = sdj->getPos();
192 >            rkj = rk - rj;
193 >            if (usePeriodicBoundaryConditions_)
194 >              currentSnapshot_->wrapVector(rkj);
195 >            rkj.normalize();
196 >            
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 -=  (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang);            
202 >          }
203 >        }
204 >        
205 >        if (nang > 0) {
206 >          if (usePeriodicBoundaryConditions_)
207 >            currentSnapshot_->wrapVector(rk);
208 >          
209 >          int binNo = int(nZBins_ * (halfBoxZ_ + rk.z()) / hmat(2,2));
210 >          sliceQ_[binNo] += Qk;
211 >          sliceCount_[binNo] += 1;
212 >        }  
213        }
214 <    //std::cerr<<"nZBins_ = "<< nZBins_<<endl;
215 <    //Writing bin#:<Qk> to a file
216 <    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 <    
303 <
304 <
305 <
306 <
307 <  
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);
312 <
313 <  }//void TetrahedralityParam::process() loop
214 >    }
215 >    writeQz();
216 >  }
217    
218 <  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 <  }    
218 >  void TetrahedralityParamZ::writeQz() {
219  
220 <  void TetrahedralityParamZ::writeOrderParameter()
221 <  {  
222 <   int nSelected = 0;
223 <  std::ofstream osq((getOutputFileName() + "Q").c_str());
224 <  if (osq.is_open())
225 <    {
330 <        osq << "# Tetrahedrality Parameters\n";
331 <        osq << "# selection: (" << selectionScript_ << ")\n";
332 <        osq << "# \n";
333 <        osq.close();
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 <  else
228 <    {
229 <        sprintf(painCave.errMsg, "TetrahedralityParamZ: unable to open %s\n",
230 <                (getOutputFileName() + "q").c_str());
231 <        painCave.isFatal = 1;
232 <        simError();  
233 <    }
234 <  DumpReader reader(info_, dumpFilename_);    
235 <  int nFrames = reader.getNFrames();
236 <  if (nFrames == 1)
237 <    {
238 <        std::vector<StuntDouble*>::iterator iter;
239 <        std::ofstream osd((getOutputFileName() + "dxyz").c_str());
240 <        if (osd.is_open())
241 <          {
242 <            osd << Distorted_.size() << "\n";
243 <            osd << "1000000.00000000;    34.52893134     0.00000000     0.00000000;     0.00000000    34.52893134     0.00000000;     0.00000000     0.00000000    34.52893134" << "\n";
244 <            
245 <            for (iter = Distorted_.begin(); iter != Distorted_.end(); ++iter)
246 <              {
247 <                Vector3d position;
248 <                position = (*iter)->getPos();
249 <                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 <    }
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 >        if (sliceCount_[i] != 0) {
239 >          qZstream << z << "\t" << sliceQ_[i] / sliceCount_[i] << "\n";
240 >        }
241 >      }
242 >      
243 >    } else {      
244 >      sprintf(painCave.errMsg, "TetrahedralityParamZ: unable to open %s\n",
245 >              outputFilename_.c_str());
246 >      painCave.isFatal = 1;
247 >      simError();  
248 >    }    
249 >    qZstream.close();
250    }
251   }
252  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines