void RCorrFuncZ::computeFrame(int istep) { hmat_ = currentSnapshot_->getHmat(); halfBoxZ_ = hmat_(2,2) / 2.0; StuntDouble* sd; int isd1, isd2; unsigned int index; if (evaluator1_.isDynamic()) { seleMan1_.setSelectionSet(evaluator1_.evaluate()); } if (uniqueSelections_ && evaluator2_.isDynamic()) { seleMan2_.setSelectionSet(evaluator2_.evaluate()); } for (sd = seleMan1_.beginSelected(isd1); sd != NULL; sd = seleMan1_.nextSelected(isd1)) { index = computeProperty1(istep, sd); if (index == sele1ToIndex_[istep].size()) { sele1ToIndex_[istep].push_back(sd->getGlobalIndex()); } else { sele1ToIndex_[istep].resize(index+1); sele1ToIndex_[istep][index] = sd->getGlobalIndex(); } } if (uniqueSelections_) { for (sd = seleMan2_.beginSelected(isd2); sd != NULL; sd = seleMan2_.nextSelected(isd2)) { index = computeProperty1(istep, sd); if (index == sele2ToIndex_[istep].size()) { sele2ToIndex_[istep].push_back(sd->getGlobalIndex()); } else { sele2ToIndex_[istep].resize(index+1); sele2ToIndex_[istep][index] = sd->getGlobalIndex(); } } } }
void BondAngleDistribution::process() { Molecule* mol; Atom* atom; RigidBody* rb; int myIndex; SimInfo::MoleculeIterator mi; Molecule::RigidBodyIterator rbIter; Molecule::AtomIterator ai; StuntDouble* sd; Vector3d vec; std::vector<Vector3d> bondvec; RealType r; int nBonds; int i; bool usePeriodicBoundaryConditions_ = info_->getSimParams()->getUsePeriodicBoundaryConditions(); DumpReader reader(info_, dumpFilename_); int nFrames = reader.getNFrames(); frameCounter_ = 0; nTotBonds_ = 0; for (int istep = 0; istep < nFrames; istep += step_) { reader.readFrame(istep); frameCounter_++; currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); if (evaluator_.isDynamic()) { seleMan_.setSelectionSet(evaluator_.evaluate()); } // update the positions of atoms which belong to the rigidbodies for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { rb->updateAtoms(); } } // outer loop is over the selected StuntDoubles: for (sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) { myIndex = sd->getGlobalIndex(); nBonds = 0; bondvec.clear(); // inner loop is over all other atoms in the system: for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { if (atom->getGlobalIndex() != myIndex) { vec = sd->getPos() - atom->getPos(); if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(vec); // Calculate "bonds" and make a pair list r = vec.length(); // Check to see if neighbor is in bond cutoff if (r < rCut_) { // Add neighbor to bond list's bondvec.push_back(vec); nBonds++; nTotBonds_++; } } } for (int i = 0; i < nBonds-1; i++ ){ Vector3d vec1 = bondvec[i]; vec1.normalize(); for(int j = i+1; j < nBonds; j++){ Vector3d vec2 = bondvec[j]; vec2.normalize(); RealType theta = acos(dot(vec1,vec2))*180.0/NumericConstant::PI; if (theta > 180.0){ theta = 360.0 - theta; } int whichBin = int(theta/deltaTheta_); histogram_[whichBin] += 2; } } } } } writeBondAngleDistribution(); }
void TetrahedralityParam::process() { Molecule* mol; StuntDouble* sd; StuntDouble* sd2; StuntDouble* sdi; StuntDouble* sdj; RigidBody* rb; int myIndex; SimInfo::MoleculeIterator mi; Molecule::RigidBodyIterator rbIter; Molecule::IntegrableObjectIterator ioi; Vector3d vec; Vector3d ri, rj, rk, rik, rkj, dposition, tposition; RealType r; RealType cospsi; RealType Qk; std::vector<std::pair<RealType,StuntDouble*> > myNeighbors; int isd; bool usePeriodicBoundaryConditions_ = info_->getSimParams()->getUsePeriodicBoundaryConditions(); DumpReader reader(info_, dumpFilename_); int nFrames = reader.getNFrames(); frameCounter_ = 0; Distorted_.clear(); Tetrahedral_.clear(); for (int istep = 0; istep < nFrames; istep += step_) { reader.readFrame(istep); frameCounter_++; currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); if (evaluator_.isDynamic()) { seleMan_.setSelectionSet(evaluator_.evaluate()); } // update the positions of atoms which belong to the rigidbodies for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { rb->updateAtoms(); } } // outer loop is over the selected StuntDoubles: for (sd = seleMan_.beginSelected(isd); sd != NULL; sd = seleMan_.nextSelected(isd)) { myIndex = sd->getGlobalIndex(); Qk = 1.0; myNeighbors.clear(); // inner loop is over all StuntDoubles in the system: for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { for (sd2 = mol->beginIntegrableObject(ioi); sd2 != NULL; sd2 = mol->nextIntegrableObject(ioi)) { if (sd2->getGlobalIndex() != myIndex) { vec = sd->getPos() - sd2->getPos(); if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(vec); r = vec.length(); // Check to see if neighbor is in bond cutoff if (r < rCut_) { myNeighbors.push_back(std::make_pair(r,sd2)); } } } } // Sort the vector using predicate and std::sort std::sort(myNeighbors.begin(), myNeighbors.end()); //std::cerr << myNeighbors.size() << " neighbors within " // << rCut_ << " A" << " \n"; // Use only the 4 closest neighbors to do the rest of the work: int nbors = myNeighbors.size()> 4 ? 4 : myNeighbors.size(); int nang = int (0.5 * (nbors * (nbors - 1))); rk = sd->getPos(); //std::cerr<<nbors<<endl; for (int i = 0; i < nbors-1; i++) { sdi = myNeighbors[i].second; ri = sdi->getPos(); rik = rk - ri; if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(rik); rik.normalize(); for (int j = i+1; j < nbors; j++) { sdj = myNeighbors[j].second; rj = sdj->getPos(); rkj = rk - rj; if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(rkj); rkj.normalize(); cospsi = dot(rik,rkj); //std::cerr << "cos(psi) = " << cospsi << " \n"; // Calculates scaled Qk for each molecule using calculated // angles from 4 or fewer nearest neighbors. Qk = Qk - (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang); //std::cerr<<Qk<<"\t"<<nang<<endl; } } //std::cerr<<nang<<endl; if (nang > 0) { collectHistogram(Qk); // Saves positions of StuntDoubles & neighbors with distorted // coordination (low Qk value) if ((Qk < 0.55) && (Qk > 0.45)) { //std::cerr<<Distorted_.size()<<endl; Distorted_.push_back(sd); //std::cerr<<Distorted_.size()<<endl; dposition = sd->getPos(); //std::cerr << "distorted position \t" << dposition << "\n"; } // Saves positions of StuntDoubles & neighbors with // tetrahedral coordination (high Qk value) if (Qk > 0.05) { Tetrahedral_.push_back(sd); tposition = sd->getPos(); //std::cerr << "tetrahedral position \t" << tposition << "\n"; } //std::cerr<<Tetrahedral_.size()<<endl; } } } writeOrderParameter(); std::cerr << "number of distorted StuntDoubles = " << Distorted_.size() << "\n"; std::cerr << "number of tetrahedral StuntDoubles = " << Tetrahedral_.size() << "\n"; }
void TetrahedralityParamXYZ::process() { Molecule* mol; StuntDouble* sd; StuntDouble* sd2; StuntDouble* sdi; StuntDouble* sdj; RigidBody* rb; int myIndex; SimInfo::MoleculeIterator mi; Molecule::RigidBodyIterator rbIter; Vector3d vec; Vector3d ri, rj, rk, rik, rkj; RealType r; RealType cospsi; RealType Qk; std::vector<std::pair<RealType,StuntDouble*> > myNeighbors; //std::vector<std::pair<Vector3d, RealType> > qvals; //std::vector<std::pair<Vector3d, RealType> >::iterator qiter; int isd1; int isd2; int kMax = int(5.0 * gaussWidth_ / voxelSize_); int kSqLim = kMax*kMax; cerr << "gw = " << gaussWidth_ << " vS = " << voxelSize_ << " kMax = " << kMax << " kSqLim = " << kSqLim << "\n"; DumpReader reader(info_, dumpFilename_); int nFrames = reader.getNFrames(); for (int istep = 0; istep < nFrames; istep += step_) { reader.readFrame(istep); currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); Mat3x3d hmat = currentSnapshot_->getHmat(); Vector3d halfBox = Vector3d(hmat(0,0), hmat(1,1), hmat(2,2)) / 2.0; if (evaluator1_.isDynamic()) { seleMan1_.setSelectionSet(evaluator1_.evaluate()); } if (evaluator2_.isDynamic()) { seleMan2_.setSelectionSet(evaluator2_.evaluate()); } // update the positions of atoms which belong to the rigidbodies for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { rb->updateAtoms(); } } //qvals.clear(); // outer loop is over the selected StuntDoubles: for (sd = seleMan1_.beginSelected(isd1); sd != NULL; sd = seleMan1_.nextSelected(isd1)) { myIndex = sd->getGlobalIndex(); Qk = 1.0; myNeighbors.clear(); for (sd2 = seleMan2_.beginSelected(isd2); sd2 != NULL; sd2 = seleMan2_.nextSelected(isd2)) { if (sd2->getGlobalIndex() != myIndex) { vec = sd->getPos() - sd2->getPos(); if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(vec); r = vec.length(); // Check to see if neighbor is in bond cutoff if (r < rCut_) { myNeighbors.push_back(std::make_pair(r,sd2)); } } } // Sort the vector using predicate and std::sort std::sort(myNeighbors.begin(), myNeighbors.end()); // Use only the 4 closest neighbors to do the rest of the work: int nbors = myNeighbors.size()> 4 ? 4 : myNeighbors.size(); int nang = int (0.5 * (nbors * (nbors - 1))); rk = sd->getPos(); for (int i = 0; i < nbors-1; i++) { sdi = myNeighbors[i].second; ri = sdi->getPos(); rik = rk - ri; if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(rik); rik.normalize(); for (int j = i+1; j < nbors; j++) { sdj = myNeighbors[j].second; rj = sdj->getPos(); rkj = rk - rj; if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(rkj); rkj.normalize(); cospsi = dot(rik,rkj); // Calculates scaled Qk for each molecule using calculated // angles from 4 or fewer nearest neighbors. Qk -= (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang); } } if (nang > 0) { if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(rk); //qvals.push_back(std::make_pair(rk, Qk)); Vector3d pos = rk + halfBox; Vector3i whichVoxel(int(pos[0] / voxelSize_), int(pos[1] / voxelSize_), int(pos[2] / voxelSize_)); for (int l = -kMax; l <= kMax; l++) { for (int m = -kMax; m <= kMax; m++) { for (int n = -kMax; n <= kMax; n++) { int kk = l*l + m*m + n*n; if(kk <= kSqLim) { int ll = (whichVoxel[0] + l) % nBins_(0); ll = ll < 0 ? nBins_(0) + ll : ll; int mm = (whichVoxel[1] + m) % nBins_(1); mm = mm < 0 ? nBins_(1) + mm : mm; int nn = (whichVoxel[2] + n) % nBins_(2); nn = nn < 0 ? nBins_(2) + nn : nn; Vector3d bPos = Vector3d(ll,mm,nn) * voxelSize_ - halfBox; Vector3d d = bPos - rk; currentSnapshot_->wrapVector(d); RealType denom = pow(2.0 * sqrt(M_PI) * gaussWidth_, 3); RealType exponent = -dot(d,d) / pow(2.0*gaussWidth_, 2); RealType weight = exp(exponent) / denom; count_[ll][mm][nn] += weight; hist_[ll][mm][nn] += weight * Qk; } } } } } } // for (int i = 0; i < nBins_(0); ++i) { // for(int j = 0; j < nBins_(1); ++j) { // for(int k = 0; k < nBins_(2); ++k) { // Vector3d pos = Vector3d(i, j, k) * voxelSize_ - halfBox; // for(qiter = qvals.begin(); qiter != qvals.end(); ++qiter) { // Vector3d d = pos - (*qiter).first; // currentSnapshot_->wrapVector(d); // RealType denom = pow(2.0 * sqrt(M_PI) * gaussWidth_, 3); // RealType exponent = -dot(d,d) / pow(2.0*gaussWidth_, 2); // RealType weight = exp(exponent) / denom; // count_[i][j][k] += weight; // hist_[i][j][k] += weight * (*qiter).second; // } // } // } // } } writeQxyz(); }
void TetrahedralityParamZ::process() { Molecule* mol; StuntDouble* sd; StuntDouble* sd2; StuntDouble* sdi; StuntDouble* sdj; RigidBody* rb; int myIndex; SimInfo::MoleculeIterator mi; Molecule::RigidBodyIterator rbIter; Vector3d vec; Vector3d ri, rj, rk, rik, rkj; RealType r; RealType cospsi; RealType Qk; std::vector<std::pair<RealType,StuntDouble*> > myNeighbors; int isd1; int isd2; DumpReader reader(info_, dumpFilename_); int nFrames = reader.getNFrames(); for (int istep = 0; istep < nFrames; istep += step_) { reader.readFrame(istep); currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); Mat3x3d hmat = currentSnapshot_->getHmat(); zBox_.push_back(hmat(2,2)); RealType halfBoxZ_ = hmat(2,2) / 2.0; if (evaluator1_.isDynamic()) { seleMan1_.setSelectionSet(evaluator1_.evaluate()); } if (evaluator2_.isDynamic()) { seleMan2_.setSelectionSet(evaluator2_.evaluate()); } // update the positions of atoms which belong to the rigidbodies for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { rb->updateAtoms(); } } // outer loop is over the selected StuntDoubles: for (sd = seleMan1_.beginSelected(isd1); sd != NULL; sd = seleMan1_.nextSelected(isd1)) { myIndex = sd->getGlobalIndex(); Qk = 1.0; myNeighbors.clear(); for (sd2 = seleMan2_.beginSelected(isd2); sd2 != NULL; sd2 = seleMan2_.nextSelected(isd2)) { if (sd2->getGlobalIndex() != myIndex) { vec = sd->getPos() - sd2->getPos(); if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(vec); r = vec.length(); // Check to see if neighbor is in bond cutoff if (r < rCut_) { myNeighbors.push_back(std::make_pair(r,sd2)); } } } // Sort the vector using predicate and std::sort std::sort(myNeighbors.begin(), myNeighbors.end()); // Use only the 4 closest neighbors to do the rest of the work: int nbors = myNeighbors.size()> 4 ? 4 : myNeighbors.size(); int nang = int (0.5 * (nbors * (nbors - 1))); rk = sd->getPos(); for (int i = 0; i < nbors-1; i++) { sdi = myNeighbors[i].second; ri = sdi->getPos(); rik = rk - ri; if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(rik); rik.normalize(); for (int j = i+1; j < nbors; j++) { sdj = myNeighbors[j].second; rj = sdj->getPos(); rkj = rk - rj; if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(rkj); rkj.normalize(); cospsi = dot(rik,rkj); // Calculates scaled Qk for each molecule using calculated // angles from 4 or fewer nearest neighbors. Qk -= (pow(cospsi + 1.0 / 3.0, 2) * 2.25 / nang); } } if (nang > 0) { if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(rk); int binNo = int(nZBins_ * (halfBoxZ_ + rk.z()) / hmat(2,2)); sliceQ_[binNo] += Qk; sliceCount_[binNo] += 1; } } } writeQz(); }