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

Comparing trunk/src/selection/NameFinder.cpp (file contents):
Revision 770 by tim, Fri Dec 2 15:38:03 2005 UTC vs.
Revision 2052 by gezelter, Fri Jan 9 19:06:35 2015 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, 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   */
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(){
50      std::map<std::string, TreeNode*>::iterator i;
# Line 53 | Line 54 | namespace oopse {
54      children.clear();
55    }
56  
56
57    NameFinder::NameFinder(SimInfo* info) : info_(info), root_(NULL){
58 <    nStuntDouble_ = info_->getNGlobalAtoms() + info_->getNGlobalRigidBodies();
58 >    nObjects_.push_back(info_->getNGlobalAtoms()+info_->getNGlobalRigidBodies());
59 >    nObjects_.push_back(info_->getNGlobalBonds());
60 >    nObjects_.push_back(info_->getNGlobalBends());
61 >    nObjects_.push_back(info_->getNGlobalTorsions());
62 >    nObjects_.push_back(info_->getNGlobalInversions());
63 >    nObjects_.push_back(info_->getNGlobalMolecules());
64 >    
65      loadNames();
66    }
67  
62
68    NameFinder::~NameFinder(){
69      delete root_;
70    }
71  
72    void NameFinder::loadNames() {
68
69    std::map<std::string, TreeNode*>::iterator foundIter;
73      SimInfo::MoleculeIterator mi;
71    Molecule* mol;
74      Molecule::AtomIterator ai;
73    Atom* atom;
75      Molecule::RigidBodyIterator rbIter;
76 +    Molecule::BondIterator bondIter;
77 +    Molecule::BendIterator bendIter;
78 +    Molecule::TorsionIterator torsionIter;
79 +    Molecule::InversionIterator inversionIter;
80 +
81 +    Molecule* mol;
82 +    Atom* atom;
83      RigidBody* rb;
84 +    Bond* bond;
85 +    Bend* bend;
86 +    Torsion* torsion;
87 +    Inversion* inversion;    
88  
89      root_ = new TreeNode;
90 <    root_->bs.resize(nStuntDouble_);
90 >    root_->bs.resize(nObjects_);
91      root_->bs.setAll(); //
92      
93 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
93 >    for (mol = info_->beginMolecule(mi); mol != NULL;
94 >         mol = info_->nextMolecule(mi)) {
95            
96        std::string molName = mol->getMoleculeName();
97 <      TreeNode* currentMolNode = createNode(root_, molName);
97 >      TreeNode* molNode = createNode(root_, molName);
98 >      molNode->bs.bitsets_[MOLECULE].setBitOn(mol->getGlobalIndex());
99          
100        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
101          std::string atomName = atom->getType();
102 <        TreeNode* currentAtomNode = createNode(currentMolNode, atomName);
102 >        TreeNode* atomNode = createNode(molNode, atomName);
103              
104 <        currentMolNode->bs.setBitOn(atom->getGlobalIndex());
105 <        currentAtomNode->bs.setBitOn(atom->getGlobalIndex());
104 >        molNode->bs.bitsets_[STUNTDOUBLE].setBitOn(atom->getGlobalIndex());
105 >        atomNode->bs.bitsets_[STUNTDOUBLE].setBitOn(atom->getGlobalIndex());
106        }
107  
108 <      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
108 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
109 >           rb = mol->nextRigidBody(rbIter)) {
110          std::string rbName = rb->getType();
111 <        TreeNode* currentRbNode = createNode(currentMolNode, rbName);
111 >        TreeNode* rbNode = createNode(molNode, rbName);
112              
113 <        currentMolNode->bs.setBitOn(rb->getGlobalIndex());
114 <        currentRbNode->bs.setBitOn(rb->getGlobalIndex());
113 >        molNode->bs.bitsets_[STUNTDOUBLE].setBitOn(rb->getGlobalIndex());
114 >        rbNode->bs.bitsets_[STUNTDOUBLE].setBitOn(rb->getGlobalIndex());
115  
116 <        //create nodes for atoms belong to this rigidbody
117 <        for(atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
118 <          std::string rbAtomName = atom->getType();
119 <          TreeNode* currentRbAtomNode = createNode(currentRbNode, rbName);;
116 >        // COMMENTED OUT because rigid bodies are IntegrableObjects
117 >        // (e.g. they are independently mobile, so selecting their
118 >        // member atoms will give some odd results if we are computing
119 >        // degrees of freedom elsewhere.
120  
121 <          currentRbAtomNode->bs.setBitOn(atom->getGlobalIndex());
122 <        }
121 >        // //create nodes for atoms belong to this rigidbody
122 >        // for(atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
123 >        //   std::string rbAtomName = atom->getType();
124 >        //   TreeNode* rbAtomNode = createNode(rbNode, rbAtomName);
125  
126 +        //   rbAtomNode->bs.bitsets_[STUNTDOUBLE].setBitOn(atom->getGlobalIndex());
127 +        // }
128        }
129 +
130 +      for (bond = mol->beginBond(bondIter); bond != NULL;
131 +           bond = mol->nextBond(bondIter)) {
132 +
133 +        std::string bondName = bond->getName();
134 +        TreeNode* bondNode = createNode(molNode, bondName);
135 +
136 +        molNode->bs.bitsets_[BOND].setBitOn(bond->getGlobalIndex());
137 +        bondNode->bs.bitsets_[BOND].setBitOn(bond->getGlobalIndex());
138 +
139 +        std::vector<Atom*> atoms = bond->getAtoms();
140 +        std::vector<Atom*>::iterator ai;
141          
142 <    }    
142 >        for (ai = atoms.begin(); ai != atoms.end(); ++ai) {
143 >          std::string atomName = (*ai)->getType();
144 >          TreeNode* atomNode = createNode(bondNode, atomName);
145 >          atomNode->bs.bitsets_[STUNTDOUBLE].setBitOn((*ai)->getGlobalIndex());
146 >        }
147 >      }
148 >      for (bend = mol->beginBend(bendIter); bend != NULL;
149 >           bend = mol->nextBend(bendIter)) {
150 >
151 >        std::string bendName = bend->getName();
152 >        TreeNode* bendNode = createNode(molNode, bendName);
153 >
154 >        molNode->bs.bitsets_[BEND].setBitOn(bend->getGlobalIndex());
155 >        bendNode->bs.bitsets_[BEND].setBitOn(bend->getGlobalIndex());
156 >
157 >        std::vector<Atom*> atoms = bend->getAtoms();
158 >        std::vector<Atom*>::iterator ai;
159 >        
160 >        for (ai = atoms.begin(); ai != atoms.end(); ++ai) {
161 >          std::string atomName = (*ai)->getType();
162 >          TreeNode* atomNode = createNode(bendNode, atomName);
163 >          atomNode->bs.bitsets_[STUNTDOUBLE].setBitOn((*ai)->getGlobalIndex());
164 >        }
165 >
166 >      }
167 >      for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
168 >           torsion = mol->nextTorsion(torsionIter)) {
169 >
170 >        std::string torsionName = torsion->getName();
171 >        TreeNode* torsionNode = createNode(molNode, torsionName);
172 >
173 >        molNode->bs.bitsets_[TORSION].setBitOn(torsion->getGlobalIndex());
174 >        torsionNode->bs.bitsets_[TORSION].setBitOn(torsion->getGlobalIndex());
175 >
176 >        std::vector<Atom*> atoms = torsion->getAtoms();
177 >        std::vector<Atom*>::iterator ai;
178 >        
179 >        for (ai = atoms.begin(); ai != atoms.end(); ++ai) {
180 >          std::string atomName = (*ai)->getType();
181 >          TreeNode* atomNode = createNode(torsionNode, atomName);
182 >          atomNode->bs.bitsets_[STUNTDOUBLE].setBitOn((*ai)->getGlobalIndex());
183 >        }
184  
185 +      }
186 +      for (inversion = mol->beginInversion(inversionIter); inversion != NULL;
187 +           inversion = mol->nextInversion(inversionIter)) {
188 +
189 +        std::string inversionName = inversion->getName();
190 +        TreeNode* inversionNode = createNode(molNode, inversionName);
191 +
192 +        molNode->bs.bitsets_[INVERSION].setBitOn(inversion->getGlobalIndex());
193 +        inversionNode->bs.bitsets_[INVERSION].setBitOn(inversion->getGlobalIndex());
194 +        std::vector<Atom*> atoms = inversion->getAtoms();
195 +        std::vector<Atom*>::iterator ai;
196 +        
197 +        for (ai = atoms.begin(); ai != atoms.end(); ++ai) {
198 +          std::string atomName = (*ai)->getType();
199 +          TreeNode* atomNode = createNode(inversionNode, atomName);
200 +          atomNode->bs.bitsets_[STUNTDOUBLE].setBitOn((*ai)->getGlobalIndex());
201 +        }
202 +      }
203 +    }
204    }
205  
206    TreeNode* NameFinder::createNode(TreeNode* parent, const std::string& name) {
# Line 119 | Line 210 | namespace oopse {
210      if ( foundIter  == parent->children.end()) {
211        node = new TreeNode;
212        node->name = name;
213 <      node->bs.resize(nStuntDouble_);
213 >      node->bs.resize(nObjects_);
214        parent->children.insert(std::make_pair(name, node));
215      }else {
216        node = foundIter->second;
# Line 127 | Line 218 | namespace oopse {
218      return node;
219    }
220  
221 <  OOPSEBitSet NameFinder::match(const std::string& name){
222 <    OOPSEBitSet bs(nStuntDouble_);
221 >  SelectionSet NameFinder::match(const std::string& name){
222 >    SelectionSet bs(nObjects_);
223    
224      StringTokenizer tokenizer(name, ".");
225  
# Line 138 | Line 229 | namespace oopse {
229      }
230  
231      int size = names.size();
232 +
233      switch(size) {
234      case 1 :
235        //could be molecule name, atom name and rigidbody name
236        matchMolecule(names[0], bs);
237        matchStuntDouble("*", names[0], bs);
238 +      matchBond("*", names[0], bs);
239 +      matchBend("*", names[0], bs);
240 +      matchTorsion("*", names[0], bs);
241 +      matchInversion("*", names[0], bs);
242              
243        break;
244      case 2:
# Line 173 | Line 269 | namespace oopse {
269      return bs;
270    }
271  
272 <  void NameFinder::matchMolecule(const std::string& molName, OOPSEBitSet& bs) {
272 >  void NameFinder::matchMolecule(const std::string& molName, SelectionSet& bs) {
273      std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
274      std::vector<TreeNode*>::iterator i;
275      for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
# Line 181 | Line 277 | namespace oopse {
277      }    
278    }
279  
280 <  void NameFinder::matchStuntDouble(const std::string& molName, const std::string& sdName, OOPSEBitSet& bs){
280 >  void NameFinder::matchStuntDouble(const std::string& molName, const std::string& sdName, SelectionSet& bs){
281      std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
282      std::vector<TreeNode*>::iterator i;
283      for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
# Line 194 | Line 290 | namespace oopse {
290  
291    }
292  
293 <  void NameFinder::matchRigidAtoms(const std::string& molName, const std::string& rbName, const std::string& rbAtomName, OOPSEBitSet& bs){
293 >  void NameFinder::matchBond(const std::string& molName,
294 >                             const std::string& bondName, SelectionSet& bs){
295      std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
296      std::vector<TreeNode*>::iterator i;
297      for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
298 +      std::vector<TreeNode*> bondNodes = getMatchedChildren(*i, bondName);  
299 +      std::vector<TreeNode*>::iterator j;
300 +      for (j = bondNodes.begin(); j != bondNodes.end(); ++j) {
301 +        bs |= (*j)->bs;
302 +        std::vector<TreeNode*> bondAtomNodes = getAllChildren(*j);
303 +        std::vector<TreeNode*>::iterator k;
304 +        for(k = bondAtomNodes.begin(); k != bondAtomNodes.end(); ++k){
305 +          bs |= (*k)->bs;
306 +        }
307 +      }
308 +    }
309 +  }
310 +
311 +  void NameFinder::matchBend(const std::string& molName, const std::string& bendName,  SelectionSet& bs){
312 +    std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
313 +    std::vector<TreeNode*>::iterator i;
314 +    for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
315 +      std::vector<TreeNode*> bendNodes = getMatchedChildren(*i, bendName);  
316 +      std::vector<TreeNode*>::iterator j;
317 +      for (j = bendNodes.begin(); j != bendNodes.end(); ++j) {
318 +        std::vector<TreeNode*> bendAtomNodes = getAllChildren(*j);
319 +        std::vector<TreeNode*>::iterator k;
320 +        for(k = bendAtomNodes.begin(); k != bendAtomNodes.end(); ++k){
321 +          bs |= (*k)->bs;
322 +        }
323 +      }
324 +    }
325 +  }
326 +  void NameFinder::matchTorsion(const std::string& molName, const std::string& torsionName, SelectionSet& bs){
327 +    std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
328 +    std::vector<TreeNode*>::iterator i;
329 +    for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
330 +      std::vector<TreeNode*> torsionNodes = getMatchedChildren(*i, torsionName);  
331 +      std::vector<TreeNode*>::iterator j;
332 +      for (j = torsionNodes.begin(); j != torsionNodes.end(); ++j) {
333 +        std::vector<TreeNode*> torsionAtomNodes = getAllChildren(*j);
334 +        std::vector<TreeNode*>::iterator k;
335 +        for(k = torsionAtomNodes.begin(); k != torsionAtomNodes.end(); ++k){
336 +          bs |= (*k)->bs;
337 +        }
338 +      }
339 +    }
340 +  }
341 +  void NameFinder::matchInversion(const std::string& molName, const std::string& inversionName, SelectionSet& bs){
342 +    std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
343 +    std::vector<TreeNode*>::iterator i;
344 +    for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
345 +      std::vector<TreeNode*> inversionNodes = getMatchedChildren(*i, inversionName);  
346 +      std::vector<TreeNode*>::iterator j;
347 +      for (j = inversionNodes.begin(); j != inversionNodes.end(); ++j) {
348 +        std::vector<TreeNode*> inversionAtomNodes = getAllChildren(*j);
349 +        std::vector<TreeNode*>::iterator k;
350 +        for(k = inversionAtomNodes.begin(); k != inversionAtomNodes.end(); ++k){
351 +          bs |= (*k)->bs;
352 +        }
353 +      }
354 +    }
355 +  }
356 +
357 +  void NameFinder::matchRigidAtoms(const std::string& molName, const std::string& rbName, const std::string& rbAtomName, SelectionSet& bs){
358 +    std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
359 +    std::vector<TreeNode*>::iterator i;
360 +    for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
361        std::vector<TreeNode*> rbNodes = getMatchedChildren(*i, rbName);  
362        std::vector<TreeNode*>::iterator j;
363        for (j = rbNodes.begin(); j != rbNodes.end(); ++j) {
# Line 211 | Line 371 | namespace oopse {
371  
372    }
373  
374 +  std::vector<TreeNode*> NameFinder::getAllChildren(TreeNode* node)  {
375 +    std::vector<TreeNode*> childNodes;
376 +    std::map<std::string, TreeNode*>::iterator i;
377 +    for (i = node->children.begin(); i != node->children.end(); ++i) {
378 +      childNodes.push_back(i->second);
379 +    }
380 +    return childNodes;
381 +  }
382  
383    std::vector<TreeNode*> NameFinder::getMatchedChildren(TreeNode* node, const std::string& name) {
384      std::vector<TreeNode*> matchedNodes;
# Line 225 | Line 393 | namespace oopse {
393    }
394  
395    bool NameFinder::isMatched(const std::string& str, const std::string& wildcard) {
396 <    return Wildcard::wildcardfit (wildcard.c_str(), str.c_str());
396 >    return Wildcard::wildcardfit(wildcard.c_str(), str.c_str()) > 0 ? true : false;
397    }
398  
399  
400 <  void NameFinder::matchInternalIndex(const std::string& name, int internalIndex, OOPSEBitSet& bs){
400 >  void NameFinder::matchInternalIndex(const std::string& name, int internalIndex, SelectionSet& bs){
401  
234    std::map<std::string, TreeNode*>::iterator foundIter;
402      SimInfo::MoleculeIterator mi;
403      Molecule* mol;
404  
405 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
405 >    for (mol = info_->beginMolecule(mi); mol != NULL;
406 >         mol = info_->nextMolecule(mi)) {
407            
408        if (isMatched(mol->getMoleculeName(), name) ) {
409          int natoms = mol->getNAtoms();
# Line 243 | Line 411 | namespace oopse {
411          if (internalIndex >= natoms + nrigidbodies) {
412            continue;
413          } else if (internalIndex < natoms) {
414 <          bs.setBitOn(mol->getAtomAt(internalIndex)->getGlobalIndex());
414 >          bs.bitsets_[STUNTDOUBLE].setBitOn(mol->getAtomAt(internalIndex)->getGlobalIndex());
415            continue;
416          } else if ( internalIndex < natoms + nrigidbodies) {
417 <          bs.setBitOn(mol->getRigidBodyAt(internalIndex - natoms)->getGlobalIndex());
417 >          bs.bitsets_[STUNTDOUBLE].setBitOn(mol->getRigidBodyAt(internalIndex - natoms)->getGlobalIndex());
418          }
419        }
420 <        
253 <    }    
254 <    
420 >    }
421    }
422  
423 <  bool NameFinder::isInteger(const std::string str) {
424 <    for(int i =0; i < str.size(); ++i){
423 >  bool NameFinder::isInteger(const std::string &str) {
424 >    for(unsigned int i = 0; i < str.size(); ++i){
425        if (!std::isdigit(str[i])) {
426          return false;
427        }
428      }
263
429      return true;
430    }
266
431   }

Comparing trunk/src/selection/NameFinder.cpp (property svn:keywords):
Revision 770 by tim, Fri Dec 2 15:38:03 2005 UTC vs.
Revision 2052 by gezelter, Fri Jan 9 19:06:35 2015 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines