ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/selection/NameFinder.cpp
(Generate patch)

Comparing:
trunk/src/selection/NameFinder.cpp (file contents), Revision 452 by tim, Tue Apr 5 23:09:48 2005 UTC vs.
branches/development/src/selection/NameFinder.cpp (file contents), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

# Line 6 | Line 6
6   * redistribute this software in source and binary code form, provided
7   * that the following conditions are met:
8   *
9 < * 1. Acknowledgement of the program authors must be made in any
10 < *    publication of scientific results based in part on use of the
11 < *    program.  An acceptable form of acknowledgement is citation of
12 < *    the article in which the program was described (Matthew
13 < *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 < *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 < *    Parallel Simulation Engine for Molecular Dynamics,"
16 < *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 < *
18 < * 2. Redistributions of source code must retain the above copyright
9 > * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12 < * 3. Redistributions in binary form must reproduce the above copyright
12 > * 2. Redistributions in binary form must reproduce the above copyright
13   *    notice, this list of conditions and the following disclaimer in the
14   *    documentation and/or other materials provided with the
15   *    distribution.
# Line 37 | Line 28
28   * arising out of the use of or inability to use software, even if the
29   * University of Notre Dame has been advised of the possibility of
30   * such damages.
31 + *
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 + *                                                                      
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 + * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42   #include "selection/NameFinder.hpp"
43   #include "utils/wildcards.hpp"
44   #include "utils/StringTokenizer.hpp"
45   #include "primitives/Molecule.hpp"
46   #include "utils/StringUtils.hpp"
47 < namespace oopse {
47 > namespace OpenMD {
48  
49 < TreeNode::~TreeNode(){
49 >  TreeNode::~TreeNode(){
50      std::map<std::string, TreeNode*>::iterator i;
51      for ( i = children.begin(); i != children.end(); ++i) {
52 <        i->second->~TreeNode();
52 >      i->second->~TreeNode();
53      }
54      children.clear();
55 < }
55 >  }
56  
57  
58 < NameFinder::NameFinder(SimInfo* info) : info_(info), root_(NULL){
58 >  NameFinder::NameFinder(SimInfo* info) : info_(info), root_(NULL){
59      nStuntDouble_ = info_->getNGlobalAtoms() + info_->getNGlobalRigidBodies();
60      loadNames();
61 < }
61 >  }
62  
63  
64 < NameFinder::~NameFinder(){
64 >  NameFinder::~NameFinder(){
65      delete root_;
66 < }
66 >  }
67  
68 < void NameFinder::loadNames() {
68 >  void NameFinder::loadNames() {
69  
70      std::map<std::string, TreeNode*>::iterator foundIter;
71      SimInfo::MoleculeIterator mi;
# Line 80 | Line 81 | void NameFinder::loadNames() {
81      
82      for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
83            
84 <        std::string molName = mol->getMoleculeName();
85 <         TreeNode* currentMolNode = createNode(root_, molName);
84 >      std::string molName = mol->getMoleculeName();
85 >      TreeNode* currentMolNode = createNode(root_, molName);
86          
87 <        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
88 <            std::string atomName = atom->getType();
89 <            TreeNode* currentAtomNode = createNode(currentMolNode, atomName);
87 >      for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
88 >        std::string atomName = atom->getType();
89 >        TreeNode* currentAtomNode = createNode(currentMolNode, atomName);
90              
91 <            currentMolNode->bs.setBitOn(atom->getGlobalIndex());
92 <            currentAtomNode->bs.setBitOn(atom->getGlobalIndex());
93 <        }
91 >        currentMolNode->bs.setBitOn(atom->getGlobalIndex());
92 >        currentAtomNode->bs.setBitOn(atom->getGlobalIndex());
93 >      }
94  
95 <        for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
96 <            std::string rbName = rb->getType();
97 <            TreeNode* currentRbNode = createNode(currentMolNode, rbName);
95 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
96 >        std::string rbName = rb->getType();
97 >        TreeNode* currentRbNode = createNode(currentMolNode, rbName);
98              
99 <            currentMolNode->bs.setBitOn(rb->getGlobalIndex());
100 <            currentRbNode->bs.setBitOn(rb->getGlobalIndex());
99 >        currentMolNode->bs.setBitOn(rb->getGlobalIndex());
100 >        currentRbNode->bs.setBitOn(rb->getGlobalIndex());
101  
102 <            //create nodes for atoms belong to this rigidbody
103 <            for(atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
104 <                std::string rbAtomName = atom->getType();
105 <                TreeNode* currentRbAtomNode = createNode(currentRbNode, rbName);;
102 >        //create nodes for atoms belong to this rigidbody
103 >        for(atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
104 >          std::string rbAtomName = atom->getType();
105 >          TreeNode* currentRbAtomNode = createNode(currentRbNode, rbName);;
106  
107 <                currentRbAtomNode->bs.setBitOn(atom->getGlobalIndex());
108 <            }
107 >          currentRbAtomNode->bs.setBitOn(atom->getGlobalIndex());
108 >        }
109  
110 <        }
110 >      }
111          
112      }    
113  
114 < }
114 >  }
115  
116 < TreeNode* NameFinder::createNode(TreeNode* parent, const std::string& name) {
116 >  TreeNode* NameFinder::createNode(TreeNode* parent, const std::string& name) {
117      TreeNode* node;    
118      std::map<std::string, TreeNode*>::iterator foundIter;
119      foundIter = parent->children.find(name);
120      if ( foundIter  == parent->children.end()) {
121 <        node = new TreeNode;
122 <        node->name = name;
123 <        node->bs.resize(nStuntDouble_);
124 <        parent->children.insert(std::make_pair(name, node));
121 >      node = new TreeNode;
122 >      node->name = name;
123 >      node->bs.resize(nStuntDouble_);
124 >      parent->children.insert(std::make_pair(name, node));
125      }else {
126 <        node = foundIter->second;
126 >      node = foundIter->second;
127      }
128      return node;
129 < }
129 >  }
130  
131 < BitSet NameFinder::match(const std::string& name){
132 <    BitSet bs(nStuntDouble_);
131 >  OpenMDBitSet NameFinder::match(const std::string& name){
132 >    OpenMDBitSet bs(nStuntDouble_);
133    
134      StringTokenizer tokenizer(name, ".");
135  
136      std::vector<std::string> names;
137      while(tokenizer.hasMoreTokens()) {
138 <        names.push_back(tokenizer.nextToken());
138 >      names.push_back(tokenizer.nextToken());
139      }
140  
141      int size = names.size();
142      switch(size) {
143 <        case 1 :
144 <            //could be molecule name, atom name and rigidbody name
145 <            matchMolecule(names[0], bs);
146 <            matchStuntDouble("*", names[0], bs);
143 >    case 1 :
144 >      //could be molecule name, atom name and rigidbody name
145 >      matchMolecule(names[0], bs);
146 >      matchStuntDouble("*", names[0], bs);
147              
148 <            break;
149 <        case 2:
150 <            //could be molecule.*(include atoms and rigidbodies) or rigidbody.*(atoms belong to rigidbody)
148 >      break;
149 >    case 2:
150 >      //could be molecule.*(include atoms and rigidbodies) or rigidbody.*(atoms belong to rigidbody)
151  
152 <            if (!isInteger(names[1])){
153 <                matchRigidAtoms("*", names[0], names[1], bs);
154 <                matchStuntDouble(names[0], names[1], bs);
155 <            } else {
156 <                int internalIndex = lexi_cast<int>(names[1]);
157 <                if (internalIndex < 0) {
158 <                    std::cerr << names[0] << ". " << names[1] << " is an invalid name" << std::endl;          
159 <                } else {
160 <                    matchInternalIndex(names[0], internalIndex, bs);
161 <                }
162 <            }
152 >      if (!isInteger(names[1])){
153 >        matchRigidAtoms("*", names[0], names[1], bs);
154 >        matchStuntDouble(names[0], names[1], bs);
155 >      } else {
156 >        int internalIndex = lexi_cast<int>(names[1]);
157 >        if (internalIndex < 0) {
158 >          std::cerr << names[0] << ". " << names[1] << " is an invalid name" << std::endl;          
159 >        } else {
160 >          matchInternalIndex(names[0], internalIndex, bs);
161 >        }
162 >      }
163              
164 <            break;
165 <        case 3:
166 <            //must be molecule.rigidbody.*
167 <            matchRigidAtoms(names[0], names[1], names[2], bs);
168 <            break;
169 <        default:      
170 <            std::cerr << "invalid name: " << name << std::endl;
171 <            break;          
164 >      break;
165 >    case 3:
166 >      //must be molecule.rigidbody.*
167 >      matchRigidAtoms(names[0], names[1], names[2], bs);
168 >      break;
169 >    default:      
170 >      std::cerr << "invalid name: " << name << std::endl;
171 >      break;          
172      }
173  
174      return bs;
175 < }
175 >  }
176  
177 < void NameFinder::matchMolecule(const std::string& molName, BitSet& bs) {
177 >  void NameFinder::matchMolecule(const std::string& molName, OpenMDBitSet& bs) {
178      std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
179      std::vector<TreeNode*>::iterator i;
180      for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
181 <        bs |= (*i)->bs;
181 >      bs |= (*i)->bs;
182      }    
183 < }
183 >  }
184  
185 < void NameFinder::matchStuntDouble(const std::string& molName, const std::string& sdName, BitSet& bs){
185 >  void NameFinder::matchStuntDouble(const std::string& molName, const std::string& sdName, OpenMDBitSet& bs){
186      std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
187      std::vector<TreeNode*>::iterator i;
188      for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
189 <        std::vector<TreeNode*> sdNodes = getMatchedChildren(*i, sdName);  
190 <        std::vector<TreeNode*>::iterator j;
191 <        for (j = sdNodes.begin(); j != sdNodes.end(); ++j) {
192 <            bs |= (*j)->bs;
193 <        }
189 >      std::vector<TreeNode*> sdNodes = getMatchedChildren(*i, sdName);  
190 >      std::vector<TreeNode*>::iterator j;
191 >      for (j = sdNodes.begin(); j != sdNodes.end(); ++j) {
192 >        bs |= (*j)->bs;
193 >      }
194      }
195  
196 < }
196 >  }
197  
198 < void NameFinder::matchRigidAtoms(const std::string& molName, const std::string& rbName, const std::string& rbAtomName, BitSet& bs){
198 >  void NameFinder::matchRigidAtoms(const std::string& molName, const std::string& rbName, const std::string& rbAtomName, OpenMDBitSet& bs){
199      std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
200      std::vector<TreeNode*>::iterator i;
201      for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
202 <        std::vector<TreeNode*> rbNodes = getMatchedChildren(*i, rbName);  
203 <        std::vector<TreeNode*>::iterator j;
204 <        for (j = rbNodes.begin(); j != rbNodes.end(); ++j) {
205 <            std::vector<TreeNode*> rbAtomNodes = getMatchedChildren(*j, rbAtomName);
206 <            std::vector<TreeNode*>::iterator k;
207 <            for(k = rbAtomNodes.begin(); k != rbAtomNodes.end(); ++k){
208 <                bs |= (*k)->bs;
209 <            }
210 <        }
202 >      std::vector<TreeNode*> rbNodes = getMatchedChildren(*i, rbName);  
203 >      std::vector<TreeNode*>::iterator j;
204 >      for (j = rbNodes.begin(); j != rbNodes.end(); ++j) {
205 >        std::vector<TreeNode*> rbAtomNodes = getMatchedChildren(*j, rbAtomName);
206 >        std::vector<TreeNode*>::iterator k;
207 >        for(k = rbAtomNodes.begin(); k != rbAtomNodes.end(); ++k){
208 >          bs |= (*k)->bs;
209 >        }
210 >      }
211      }
212  
213 < }
213 >  }
214  
215  
216 < std::vector<TreeNode*> NameFinder::getMatchedChildren(TreeNode* node, const std::string& name) {
216 >  std::vector<TreeNode*> NameFinder::getMatchedChildren(TreeNode* node, const std::string& name) {
217      std::vector<TreeNode*> matchedNodes;
218      std::map<std::string, TreeNode*>::iterator i;
219      for (i = node->children.begin(); i != node->children.end(); ++i) {
220 <        if (isMatched( i->first, name)) {
221 <            matchedNodes.push_back(i->second);
222 <        }
220 >      if (isMatched( i->first, name)) {
221 >        matchedNodes.push_back(i->second);
222 >      }
223      }
224  
225      return matchedNodes;
226 < }
226 >  }
227  
228 < bool NameFinder::isMatched(const std::string& str, const std::string& wildcard) {
228 >  bool NameFinder::isMatched(const std::string& str, const std::string& wildcard) {
229      return Wildcard::wildcardfit (wildcard.c_str(), str.c_str());
230 < }
230 >  }
231  
232  
233 < void NameFinder::matchInternalIndex(const std::string& name, int internalIndex, BitSet& bs){
233 >  void NameFinder::matchInternalIndex(const std::string& name, int internalIndex, OpenMDBitSet& bs){
234  
235      std::map<std::string, TreeNode*>::iterator foundIter;
236      SimInfo::MoleculeIterator mi;
# Line 237 | Line 238 | void NameFinder::matchInternalIndex(const std::string&
238  
239      for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
240            
241 <        if (isMatched(mol->getMoleculeName(), name) ) {
242 <            int natoms = mol->getNAtoms();
243 <            int nrigidbodies = mol->getNRigidBodies();
244 <            if (internalIndex >= natoms + nrigidbodies) {
245 <                continue;
246 <            } else if (internalIndex < natoms) {
247 <                bs.setBitOn(mol->getAtomAt(internalIndex)->getGlobalIndex());
248 <                continue;
249 <            } else if ( internalIndex < natoms + nrigidbodies) {
250 <                bs.setBitOn(mol->getRigidBodyAt(internalIndex - natoms)->getGlobalIndex());
251 <            }
252 <        }
241 >      if (isMatched(mol->getMoleculeName(), name) ) {
242 >        int natoms = mol->getNAtoms();
243 >        int nrigidbodies = mol->getNRigidBodies();
244 >        if (internalIndex >= natoms + nrigidbodies) {
245 >          continue;
246 >        } else if (internalIndex < natoms) {
247 >          bs.setBitOn(mol->getAtomAt(internalIndex)->getGlobalIndex());
248 >          continue;
249 >        } else if ( internalIndex < natoms + nrigidbodies) {
250 >          bs.setBitOn(mol->getRigidBodyAt(internalIndex - natoms)->getGlobalIndex());
251 >        }
252 >      }
253          
254      }    
255      
256 < }
256 >  }
257  
258 < bool NameFinder::isInteger(const std::string str) {
258 >  bool NameFinder::isInteger(const std::string str) {
259      for(int i =0; i < str.size(); ++i){
260 <        if (!std::isdigit(str[i])) {
261 <            return false;
262 <        }
260 >      if (!std::isdigit(str[i])) {
261 >        return false;
262 >      }
263      }
264  
265      return true;
266 < }
266 >  }
267  
268   }

Comparing:
trunk/src/selection/NameFinder.cpp (property svn:keywords), Revision 452 by tim, Tue Apr 5 23:09:48 2005 UTC vs.
branches/development/src/selection/NameFinder.cpp (property svn:keywords), Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines