--- trunk/OOPSE-4/src/visitors/OtherVisitor.cpp 2004/10/21 16:22:01 1625 +++ trunk/OOPSE-4/src/visitors/OtherVisitor.cpp 2005/01/12 22:41:40 1930 @@ -1,497 +1,559 @@ + /* + * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. + * + * The University of Notre Dame grants you ("Licensee") a + * non-exclusive, royalty free, license to use, modify and + * redistribute this software in source and binary code form, provided + * that the following conditions are met: + * + * 1. Acknowledgement of the program authors must be made in any + * publication of scientific results based in part on use of the + * program. An acceptable form of acknowledgement is citation of + * the article in which the program was described (Matthew + * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher + * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented + * Parallel Simulation Engine for Molecular Dynamics," + * J. Comput. Chem. 26, pp. 252-271 (2005)) + * + * 2. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 3. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * This software is provided "AS IS," without a warranty of any + * kind. All express or implied conditions, representations and + * warranties, including any implied warranty of merchantability, + * fitness for a particular purpose or non-infringement, are hereby + * excluded. The University of Notre Dame and its licensors shall not + * be liable for any damages suffered by licensee as a result of + * using, modifying or distributing the software or its + * derivatives. In no event will the University of Notre Dame or its + * licensors be liable for any lost revenue, profit or data, or for + * direct, indirect, special, consequential, incidental or punitive + * damages, however caused and regardless of the theory of liability, + * arising out of the use of or inability to use software, even if the + * University of Notre Dame has been advised of the possibility of + * such damages. + */ + #include "visitors/OtherVisitor.hpp" #include "primitives/DirectionalAtom.hpp" #include "primitives/RigidBody.hpp" #include "primitives/Molecule.hpp" #include "brains/SimInfo.hpp" - namespace oopse { //----------------------------------------------------------------------------// -void IgnoreVisitor::visit(Atom* atom){ - if(isIgnoreType(atom->getType())) - internalVisit(atom); +void IgnoreVisitor::visit(Atom *atom) { + if (isIgnoreType(atom->getType())) + internalVisit(atom); } -void IgnoreVisitor::visit(DirectionalAtom* datom){ - if(isIgnoreType(datom->getType())) - internalVisit(datom); +void IgnoreVisitor::visit(DirectionalAtom *datom) { + if (isIgnoreType(datom->getType())) + internalVisit(datom); } -void IgnoreVisitor::visit(RigidBody* rb){ - vector myAtoms; - vector::iterator atomIter; - AtomInfo* atomInfo; - - if(isIgnoreType(rb->getType())){ - - internalVisit(rb); +void IgnoreVisitor::visit(RigidBody *rb) { + std::vector myAtoms; + std::vector::iterator atomIter; + AtomInfo * atomInfo; - myAtoms = rb->getAtoms(); - - for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter) - internalVisit(*atomIter); + if (isIgnoreType(rb->getType())) { + internalVisit(rb); - } - + myAtoms = rb->getAtoms(); + + for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter ) + internalVisit(*atomIter); + } } -bool IgnoreVisitor::isIgnoreType(const string& name){ - return itList.find(name) != itList.end() ? true : false; +bool IgnoreVisitor::isIgnoreType(const std::string&name) { +return itList.find(name) != itList.end() ? true : false; } -void IgnoreVisitor::internalVisit(StuntDouble* sd){ - GenericData* data; - data = sd->getProperty("IGNORE"); +void IgnoreVisitor::internalVisit(StuntDouble *sd) { + GenericData *data; + data = sd->getPropertyByName("IGNORE"); - //if this stuntdoulbe is already marked as ignore just skip it - if (data == NULL){ - data = new GenericData; - data->setID("IGNORE"); - sd->addProperty(data); - } - + //if this stuntdoulbe is already marked as ignore just skip it + if (data == NULL) { + data = new GenericData; + data->setID("IGNORE"); + sd->addProperty(data); + } } -const string IgnoreVisitor::toString(){ - char buffer[65535]; - string result; - set::iterator i; - - sprintf(buffer ,"------------------------------------------------------------------\n"); - result += buffer; +const std::string IgnoreVisitor::toString() { + char buffer[65535]; + std::string result; + std::set::iterator i; - sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); - result += buffer; + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; - sprintf(buffer ,"Visitor Description: ignore stuntdoubles\n"); - result += buffer; + sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); + result += buffer; - //print the ignore type list - sprintf(buffer , "Ignore type list contains below types:\n"); - result += buffer; + sprintf(buffer, "Visitor Description: ignore stuntdoubles\n"); + result += buffer; - for(i = itList.begin(); i != itList.end(); ++i){ - sprintf(buffer ,"%s\t", i->c_str()); + //print the ignore type list + sprintf(buffer, "Ignore type list contains below types:\n"); result += buffer; - } - sprintf(buffer ,"\n"); - result += buffer; + for( i = itList.begin(); i != itList.end(); ++i ) { + sprintf(buffer, "%s\t", i->c_str()); + result += buffer; + } - sprintf(buffer ,"------------------------------------------------------------------\n"); - result += buffer; + sprintf(buffer, "\n"); + result += buffer; - return result; + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; + + return result; } //----------------------------------------------------------------------------// -void WrappingVisitor::visit(Atom* atom){ - internalVisit(atom); +void WrappingVisitor::visit(Atom *atom) { +internalVisit(atom); } -void WrappingVisitor::visit(DirectionalAtom* datom){ - internalVisit(datom); + +void WrappingVisitor::visit(DirectionalAtom *datom) { +internalVisit(datom); } -void WrappingVisitor::visit(RigidBody* rb){ - internalVisit(rb); +void WrappingVisitor::visit(RigidBody *rb) { +internalVisit(rb); } -void WrappingVisitor::internalVisit(StuntDouble* sd){ - GenericData* data; - AtomData* atomData; - AtomInfo* atomInfo; - vector::iterator i; +void WrappingVisitor::internalVisit(StuntDouble *sd) { + GenericData * data; + AtomData * atomData; + AtomInfo * atomInfo; + std::vector::iterator i; - data = sd->getProperty("ATOMDATA"); - if(data != NULL){ - atomData = dynamic_cast(data); - if(atomData == NULL) - return; - } - else - return; + data = sd->getPropertyByName("ATOMDATA"); - for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)) - info->wrapVector(atomInfo->pos); + if (data != NULL) { + atomData = dynamic_cast(data); - + if (atomData == NULL) + return; + } else + return; + + Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot(); + + for( atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i) ) { + currSnapshot->wrapVector(atomInfo->pos); + } } -const string WrappingVisitor::toString(){ - char buffer[65535]; - string result; - - sprintf(buffer ,"------------------------------------------------------------------\n"); - result += buffer; +const std::string WrappingVisitor::toString() { + char buffer[65535]; + std::string result; - sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); - result += buffer; + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; - sprintf(buffer ,"Visitor Description: wrapping atoms back to periodic box\n"); - result += buffer; - - sprintf(buffer,"------------------------------------------------------------------\n"); - result += buffer; + sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); + result += buffer; - return result; + sprintf(buffer, + "Visitor Description: wrapping atoms back to periodic box\n"); + result += buffer; + + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; + + return result; } //----------------------------------------------------------------------------// -ReplicateVisitor::ReplicateVisitor(SimInfo* info, IntVec3 opt) : BaseVisitor(){ - this->info = info; - visitorName = "ReplicateVisitor"; - this->replicateOpt = opt; - //generate the replicate directions - for(int i = 0; i <= replicateOpt[0]; i ++) - for(int j = 0; j <= replicateOpt[1]; j ++) - for(int k = 0; k <= replicateOpt[2]; k ++) - //skip original frame - if(i == 0 && j ==0 && k ==0) - continue; - else - dir.push_back(IntVec3(i, j, k)); - +ReplicateVisitor::ReplicateVisitor(SimInfo *info, Vector3i opt) : + BaseVisitor() { + this->info = info; + visitorName = "ReplicateVisitor"; + this->replicateOpt = opt; + + //generate the replicate directions + for( int i = 0; i <= replicateOpt[0]; i++ ) { + for( int j = 0; j <= replicateOpt[1]; j++ ) { + for( int k = 0; k <= replicateOpt[2]; k++ ) { + //skip original frame + if (i == 0 && j == 0 && k == 0) { + continue; + } else { + dir.push_back(Vector3i(i, j, k)); + } + } + } + } + } -void ReplicateVisitor::visit(Atom* atom){ - internalVisit(atom); + +void ReplicateVisitor::visit(Atom *atom) { +internalVisit(atom); } -void ReplicateVisitor::visit(DirectionalAtom* datom){ - internalVisit(datom); + +void ReplicateVisitor::visit(DirectionalAtom *datom) { +internalVisit(datom); } -void ReplicateVisitor::visit(RigidBody* rb){ - internalVisit(rb); +void ReplicateVisitor::visit(RigidBody *rb) { +internalVisit(rb); } -void ReplicateVisitor::internalVisit(StuntDouble* sd){ - GenericData* data; - AtomData* atomData; - AtomInfo* atomInfo; - double box[3][3]; - vector atomInfoList; - IntVec3 dir; - - //if there is not atom data, just skip it - data = sd->getProperty("ATOMDATA"); - if(data != NULL){ - atomData = dynamic_cast(data); - if(atomData == NULL) - return; - } - else - return; +void ReplicateVisitor::internalVisit(StuntDouble *sd) { + GenericData * data; + AtomData * atomData; - - info->getBoxM(box); + //if there is not atom data, just skip it + data = sd->getPropertyByName("ATOMDATA"); - atomInfoList = atomData->getData(); - - replicate(atomInfoList, atomData, box); + if (data != NULL) { + atomData = dynamic_cast(data); + if (atomData == NULL) { + return; + } + } else { + return; + } + + Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot(); + Mat3x3d box = currSnapshot->getHmat(); + + std::vector atomInfoList = atomData->getData(); + + replicate(atomInfoList, atomData, box); } -void ReplicateVisitor::replicate(vector& infoList, AtomData* data, double boxM[3][3]){ - AtomInfo * newAtomInfo; - vector::iterator dirIter; - vector::iterator i; - - for(dirIter = dir.begin(); dirIter != dir.end(); ++dirIter){ - for(i = infoList.begin(); i != infoList.end(); i++){ - newAtomInfo = new AtomInfo; - *newAtomInfo = *(*i); +void ReplicateVisitor::replicate(std::vector&infoList, AtomData *data, const Mat3x3d& box) { + AtomInfo* newAtomInfo; + std::vector::iterator dirIter; + std::vector::iterator i; - for(int j = 0; j < 3; j++) - newAtomInfo->pos[j] += (*dirIter)[0] * boxM[j][0] + (*dirIter)[1]* boxM[j][1] + (*dirIter)[2] * boxM[j][2]; + for( dirIter = dir.begin(); dirIter != dir.end(); ++dirIter ) { + for( i = infoList.begin(); i != infoList.end(); i++ ) { + newAtomInfo = new AtomInfo(); + *newAtomInfo = *(*i); - data->addAtomInfo(newAtomInfo); - } - }// end for(dirIter) + for( int j = 0; j < 3; j++ ) + newAtomInfo->pos[j] += (*dirIter)[0]*box(j, 0) + (*dirIter)[1]*box(j, 1) + (*dirIter)[2]*box(j, 2); + + data->addAtomInfo(newAtomInfo); + } + } // end for(dirIter) } -const string ReplicateVisitor::toString(){ - char buffer[65535]; - string result; - set::iterator i; - - sprintf(buffer ,"------------------------------------------------------------------\n"); - result += buffer; +const std::string ReplicateVisitor::toString() { + char buffer[65535]; + std::string result; + std::set::iterator i; - sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); - result += buffer; + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; - sprintf(buffer ,"Visitor Description: replicate the atoms in different direction\n"); - result += buffer; - - //print the replicate direction - sprintf(buffer , "repeatX = %d:\n", replicateOpt[0]); - result += buffer; + sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); + result += buffer; - sprintf(buffer , "repeatY = %d:\n", replicateOpt[1]); - result += buffer; + sprintf(buffer, + "Visitor Description: replicate the atoms in different direction\n"); + result += buffer; - sprintf(buffer , "repeatZ = %d:\n", replicateOpt[2]); - result += buffer; + //print the replicate direction + sprintf(buffer, "repeatX = %d:\n", replicateOpt[0]); + result += buffer; + sprintf(buffer, "repeatY = %d:\n", replicateOpt[1]); + result += buffer; - sprintf(buffer,"------------------------------------------------------------------\n"); - result += buffer; + sprintf(buffer, "repeatZ = %d:\n", replicateOpt[2]); + result += buffer; - return result; + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; + + return result; } //----------------------------------------------------------------------------// -XYZVisitor::XYZVisitor(SimInfo* info, bool printDipole) : BaseVisitor(){ - this->info = info; - visitorName = "XYZVisitor"; - this->printDipole = printDipole; +XYZVisitor::XYZVisitor(SimInfo *info, bool printDipole) : + BaseVisitor() { + this->info = info; + visitorName = "XYZVisitor"; + this->printDipole = printDipole; } -void XYZVisitor::visit(Atom* atom){ - if(!isIgnore(atom)) - internalVisit(atom); +void XYZVisitor::visit(Atom *atom) { + if (!isIgnore(atom)) + internalVisit(atom); } -void XYZVisitor::visit(DirectionalAtom* datom){ - if(!isIgnore(datom)) - internalVisit(datom); +void XYZVisitor::visit(DirectionalAtom *datom) { + if (!isIgnore(datom)) + internalVisit(datom); } -void XYZVisitor::visit(RigidBody* rb){ - if(!isIgnore(rb)) - internalVisit(rb); +void XYZVisitor::visit(RigidBody *rb) { + if (!isIgnore(rb)) + internalVisit(rb); +} + +void XYZVisitor::internalVisit(StuntDouble *sd) { + GenericData * data; + AtomData * atomData; + AtomInfo * atomInfo; + std::vector::iterator i; + char buffer[1024]; + + //if there is not atom data, just skip it + data = sd->getPropertyByName("ATOMDATA"); + + if (data != NULL) { + atomData = dynamic_cast(data); + if (atomData == NULL) + return; + } else + return; + + for( atomInfo = atomData->beginAtomInfo(i); atomInfo; + atomInfo = atomData->nextAtomInfo(i) ) { + if (printDipole) + sprintf(buffer, + "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f", + atomInfo->AtomType.c_str(), + atomInfo->pos[0], + atomInfo->pos[1], + atomInfo->pos[2], + atomInfo->dipole[0], + atomInfo->dipole[1], + atomInfo->dipole[2]); else + sprintf(buffer, "%s%15.8f%15.8f%15.8f", + atomInfo->AtomType.c_str(), atomInfo->pos[0], + atomInfo->pos[1], atomInfo->pos[2]); + + frame.push_back(buffer); + } } -void XYZVisitor::internalVisit(StuntDouble* sd){ - GenericData* data; - AtomData* atomData; - AtomInfo* atomInfo; - vector::iterator i; - char buffer[1024]; - - //if there is not atom data, just skip it - data = sd->getProperty("ATOMDATA"); - if(data != NULL){ - atomData = dynamic_cast(data); - if(atomData == NULL) - return; - } - else - return; +bool XYZVisitor::isIgnore(StuntDouble *sd) { + GenericData *data; - for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){ + data = sd->getPropertyByName("IGNORE"); + return data == NULL ? false : true; +} - if(printDipole) - sprintf(buffer, "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f", - atomInfo->AtomType.c_str(), - atomInfo->pos[0], - atomInfo->pos[1], - atomInfo->pos[2], - atomInfo->dipole[0], - atomInfo->dipole[1], - atomInfo->dipole[2]); - else - sprintf(buffer, "%s%15.8f%15.8f%15.8f", - atomInfo->AtomType.c_str(), - atomInfo->pos[0], - atomInfo->pos[1], - atomInfo->pos[2]); +void XYZVisitor::writeFrame(std::ostream &outStream) { + std::vector::iterator i; + char buffer[1024]; - frame.push_back(buffer); - - } + if (frame.size() == 0) + std::cerr << "Current Frame does not contain any atoms" << std::endl; -} + //total number of atoms + outStream << frame.size() << std::endl; -bool XYZVisitor::isIgnore(StuntDouble* sd){ - GenericData* data; - - data = sd->getProperty("IGNORE"); - return data ==NULL ? false : true; + //write comment line + Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot(); + Mat3x3d box = currSnapshot->getHmat(); + + sprintf(buffer, + "%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f", + currSnapshot->getTime(), + box(0, 0), box(0, 1), box(0, 2), + box(1, 0), box(1, 1), box(1, 2), + box(2, 0), box(2, 1), box(2, 2)); + + outStream << buffer << std::endl; + + for( i = frame.begin(); i != frame.end(); ++i ) + outStream << *i << std::endl; } -void XYZVisitor::writeFrame(ostream& outStream){ - vector::iterator i; - double box[3][3]; - char buffer[1024]; +const std::string XYZVisitor::toString() { + char buffer[65535]; + std::string result; - if(frame.size() == 0) - cerr << "Current Frame does not contain any atoms" << endl; + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; - //total number of atoms - outStream << frame.size() << endl; + sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); + result += buffer; - //write comment line - info->getBoxM(box); - sprintf(buffer,"%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f", - info->getTime(), - box[0][0], box[0][1], box[0][2], - box[1][0], box[1][1], box[1][2], - box[2][0], box[2][1], box[2][2]); + sprintf(buffer, + "Visitor Description: assemble the atom data and output xyz file\n"); + result += buffer; - outStream << buffer << endl; + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; - for(i = frame.begin(); i != frame.end(); ++i) - outStream << *i << endl; + return result; } -const string XYZVisitor::toString(){ - char buffer[65535]; - string result; - - sprintf(buffer ,"------------------------------------------------------------------\n"); - result += buffer; +//----------------------------------------------------------------------------// - sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); - result += buffer; +void PrepareVisitor::internalVisit(Atom *atom) { + GenericData *data; + AtomData * atomData; - sprintf(buffer ,"Visitor Description: assemble the atom data and output xyz file\n"); - result += buffer; - - sprintf(buffer,"------------------------------------------------------------------\n"); - result += buffer; + //if visited property is existed, remove it + data = atom->getPropertyByName("VISITED"); - return result; + if (data != NULL) { + atom->removeProperty("VISITED"); + } + + //remove atomdata + data = atom->getPropertyByName("ATOMDATA"); + + if (data != NULL) { + atomData = dynamic_cast(data); + + if (atomData != NULL) + atom->removeProperty("ATOMDATA"); + } } -//----------------------------------------------------------------------------// +void PrepareVisitor::internalVisit(RigidBody *rb) { + GenericData* data; + AtomData* atomData; + std::vector myAtoms; + std::vector::iterator atomIter; -void PrepareVisitor::internalVisit(Atom * atom){ - GenericData* data; - AtomData* atomData; + //if visited property is existed, remove it + data = rb->getPropertyByName("VISITED"); - //if visited property is existed, remove it - data = atom->getProperty("VISITED"); - if(data != NULL){ - atom->removeProperty("VISITED"); - } + if (data != NULL) { + rb->removeProperty("VISITED"); + } - //remove atomdata - data = atom->getProperty("ATOMDATA"); - if(data != NULL){ - atomData = dynamic_cast(data); - if(atomData != NULL) - atom->removeProperty("ATOMDATA"); - } - -} + //remove atomdata + data = rb->getPropertyByName("ATOMDATA"); -void PrepareVisitor::internalVisit(RigidBody * rb){ - GenericData* data; - AtomData* atomData; - vector myAtoms; - vector::iterator atomIter; - - //if visited property is existed, remove it - data = rb->getProperty("VISITED"); - if(data != NULL){ - rb->removeProperty("VISITED"); - } + if (data != NULL) { + atomData = dynamic_cast(data); - //remove atomdata - data = rb->getProperty("ATOMDATA"); - if(data != NULL){ - atomData = dynamic_cast(data); - if(atomData != NULL) - rb->removeProperty("ATOMDATA"); - } + if (atomData != NULL) + rb->removeProperty("ATOMDATA"); + } - myAtoms = rb->getAtoms(); - - for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter) - internalVisit (*atomIter); + myAtoms = rb->getAtoms(); + + for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter ) + internalVisit(*atomIter); } -const string PrepareVisitor::toString(){ - char buffer[65535]; - string result; - - sprintf(buffer ,"------------------------------------------------------------------\n"); - result += buffer; +const std::string PrepareVisitor::toString() { + char buffer[65535]; + std::string result; - sprintf(buffer ,"Visitor name: %s", visitorName.c_str()); - result += buffer; + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; - sprintf(buffer ,"Visitor Description: prepare for operation of other vistors\n"); - result += buffer; + sprintf(buffer, "Visitor name: %s", visitorName.c_str()); + result += buffer; - sprintf(buffer ,"------------------------------------------------------------------\n"); - result += buffer; + sprintf(buffer, + "Visitor Description: prepare for operation of other vistors\n"); + result += buffer; - return result; + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; + + return result; } //----------------------------------------------------------------------------// -WaterTypeVisitor:: WaterTypeVisitor(){ - visitorName = "WaterTypeVisitor"; - waterTypeList.insert("TIP3P_RB_0"); - waterTypeList.insert("TIP4P_RB_0"); - waterTypeList.insert("TIP5P_RB_0"); - waterTypeList.insert("SPCE_RB_0"); +WaterTypeVisitor::WaterTypeVisitor() { + visitorName = "WaterTypeVisitor"; + waterTypeList.insert("TIP3P_RB_0"); + waterTypeList.insert("TIP4P_RB_0"); + waterTypeList.insert("TIP5P_RB_0"); + waterTypeList.insert("SPCE_RB_0"); } +void WaterTypeVisitor::visit(RigidBody *rb) { + std::string rbName; + std::vector myAtoms; + std::vector::iterator atomIter; + GenericData* data; + AtomData* atomData; + AtomInfo* atomInfo; + std::vector::iterator i; -void WaterTypeVisitor:: visit(RigidBody* rb){ - string rbName; - vector myAtoms; - vector::iterator atomIter; - GenericData* data; - AtomData* atomData; - AtomInfo* atomInfo; - vector::iterator i; - - rbName = rb->getType(); + rbName = rb->getType(); - if(waterTypeList.find(rbName) != waterTypeList.end()){ + if (waterTypeList.find(rbName) != waterTypeList.end()) { + myAtoms = rb->getAtoms(); - myAtoms = rb->getAtoms(); - for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter){ + for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); + ++atomIter ) { + data = (*atomIter)->getPropertyByName("ATOMDATA"); - data = (*atomIter)->getProperty("ATOMDATA"); - if(data != NULL){ - atomData = dynamic_cast(data); - if(atomData == NULL) - continue; - } - else - continue; - - for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){ - replaceType(atomInfo->AtomType); - }//end for(atomInfo) + if (data != NULL) { + atomData = dynamic_cast(data); - }//end for(atomIter) - - }//end if (waterTypeList.find(rbName) != waterTypeList.end()) - + if (atomData == NULL) + continue; + } else + continue; + + for( atomInfo = atomData->beginAtomInfo(i); atomInfo; + atomInfo = atomData->nextAtomInfo(i) ) { + replaceType(atomInfo->AtomType); + } //end for(atomInfo) + } //end for(atomIter) + } //end if (waterTypeList.find(rbName) != waterTypeList.end()) } -void WaterTypeVisitor:: replaceType(string& atomType){ - atomType = atomType.substr(0, atomType.find('_')); +void WaterTypeVisitor::replaceType(std::string&atomType) { +atomType = atomType.substr(0, atomType.find('_')); } -const string WaterTypeVisitor:: toString(){ - char buffer[65535]; - string result; - - sprintf(buffer ,"------------------------------------------------------------------\n"); - result += buffer; +const std::string WaterTypeVisitor::toString() { + char buffer[65535]; + std::string result; - sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); - result += buffer; + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; - sprintf(buffer ,"Visitor Description: Replace the atom type in water model\n"); - result += buffer; + sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); + result += buffer; - sprintf(buffer ,"------------------------------------------------------------------\n"); - result += buffer; + sprintf(buffer, + "Visitor Description: Replace the atom type in water model\n"); + result += buffer; - return result; + sprintf(buffer, + "------------------------------------------------------------------\n"); + result += buffer; + + return result; } - -}//namespace oopse +} //namespace oopse