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 1953 by gezelter, Thu Dec 5 18:19:26 2013 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      loadNames();
64    }
65  
62
66    NameFinder::~NameFinder(){
67      delete root_;
68    }
69  
70    void NameFinder::loadNames() {
68
69    std::map<std::string, TreeNode*>::iterator foundIter;
71      SimInfo::MoleculeIterator mi;
71    Molecule* mol;
72      Molecule::AtomIterator ai;
73    Atom* atom;
73      Molecule::RigidBodyIterator rbIter;
74 +    Molecule::BondIterator bondIter;
75 +    Molecule::BendIterator bendIter;
76 +    Molecule::TorsionIterator torsionIter;
77 +    Molecule::InversionIterator inversionIter;
78 +
79 +    Molecule* mol;
80 +    Atom* atom;
81      RigidBody* rb;
82 +    Bond* bond;
83 +    Bend* bend;
84 +    Torsion* torsion;
85 +    Inversion* inversion;    
86  
87      root_ = new TreeNode;
88 <    root_->bs.resize(nStuntDouble_);
88 >    root_->bs.resize(nObjects_);
89      root_->bs.setAll(); //
90      
91 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
91 >    for (mol = info_->beginMolecule(mi); mol != NULL;
92 >         mol = info_->nextMolecule(mi)) {
93            
94        std::string molName = mol->getMoleculeName();
95 <      TreeNode* currentMolNode = createNode(root_, molName);
95 >      TreeNode* molNode = createNode(root_, molName);
96          
97        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
98          std::string atomName = atom->getType();
99 <        TreeNode* currentAtomNode = createNode(currentMolNode, atomName);
99 >        TreeNode* atomNode = createNode(molNode, atomName);
100              
101 <        currentMolNode->bs.setBitOn(atom->getGlobalIndex());
102 <        currentAtomNode->bs.setBitOn(atom->getGlobalIndex());
101 >        molNode->bs.bitsets_[STUNTDOUBLE].setBitOn(atom->getGlobalIndex());
102 >        atomNode->bs.bitsets_[STUNTDOUBLE].setBitOn(atom->getGlobalIndex());
103        }
104  
105 <      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
105 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
106 >           rb = mol->nextRigidBody(rbIter)) {
107          std::string rbName = rb->getType();
108 <        TreeNode* currentRbNode = createNode(currentMolNode, rbName);
108 >        TreeNode* rbNode = createNode(molNode, rbName);
109              
110 <        currentMolNode->bs.setBitOn(rb->getGlobalIndex());
111 <        currentRbNode->bs.setBitOn(rb->getGlobalIndex());
110 >        molNode->bs.bitsets_[STUNTDOUBLE].setBitOn(rb->getGlobalIndex());
111 >        rbNode->bs.bitsets_[STUNTDOUBLE].setBitOn(rb->getGlobalIndex());
112  
113          //create nodes for atoms belong to this rigidbody
114          for(atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) {
115            std::string rbAtomName = atom->getType();
116 <          TreeNode* currentRbAtomNode = createNode(currentRbNode, rbName);;
116 >          TreeNode* rbAtomNode = createNode(rbNode, rbAtomName);
117  
118 <          currentRbAtomNode->bs.setBitOn(atom->getGlobalIndex());
118 >          rbAtomNode->bs.bitsets_[STUNTDOUBLE].setBitOn(atom->getGlobalIndex());
119          }
120 +      }
121  
122 +      for (bond = mol->beginBond(bondIter); bond != NULL;
123 +           bond = mol->nextBond(bondIter)) {
124 +
125 +        std::string bondName = bond->getName();
126 +        TreeNode* bondNode = createNode(molNode, bondName);
127 +
128 +        molNode->bs.bitsets_[BOND].setBitOn(bond->getGlobalIndex());
129 +        bondNode->bs.bitsets_[BOND].setBitOn(bond->getGlobalIndex());
130 +
131 +        std::vector<Atom*> atoms = bond->getAtoms();
132 +        std::vector<Atom*>::iterator ai;
133 +        
134 +        for (ai = atoms.begin(); ai != atoms.end(); ++ai) {
135 +          std::string atomName = (*ai)->getType();
136 +          TreeNode* atomNode = createNode(bondNode, atomName);
137 +          atomNode->bs.bitsets_[STUNTDOUBLE].setBitOn((*ai)->getGlobalIndex());
138 +        }
139        }
140 +      for (bend = mol->beginBend(bendIter); bend != NULL;
141 +           bend = mol->nextBend(bendIter)) {
142 +
143 +        std::string bendName = bend->getName();
144 +        TreeNode* bendNode = createNode(molNode, bendName);
145 +
146 +        molNode->bs.bitsets_[BEND].setBitOn(bend->getGlobalIndex());
147 +        bendNode->bs.bitsets_[BEND].setBitOn(bend->getGlobalIndex());
148 +
149 +        std::vector<Atom*> atoms = bend->getAtoms();
150 +        std::vector<Atom*>::iterator ai;
151          
152 <    }    
152 >        for (ai = atoms.begin(); ai != atoms.end(); ++ai) {
153 >          std::string atomName = (*ai)->getType();
154 >          TreeNode* atomNode = createNode(bendNode, atomName);
155 >          atomNode->bs.bitsets_[STUNTDOUBLE].setBitOn((*ai)->getGlobalIndex());
156 >        }
157 >
158 >      }
159 >      for (torsion = mol->beginTorsion(torsionIter); torsion != NULL;
160 >           torsion = mol->nextTorsion(torsionIter)) {
161 >
162 >        std::string torsionName = torsion->getName();
163 >        TreeNode* torsionNode = createNode(molNode, torsionName);
164 >
165 >        molNode->bs.bitsets_[TORSION].setBitOn(torsion->getGlobalIndex());
166 >        torsionNode->bs.bitsets_[TORSION].setBitOn(torsion->getGlobalIndex());
167 >
168 >        std::vector<Atom*> atoms = torsion->getAtoms();
169 >        std::vector<Atom*>::iterator ai;
170 >        
171 >        for (ai = atoms.begin(); ai != atoms.end(); ++ai) {
172 >          std::string atomName = (*ai)->getType();
173 >          TreeNode* atomNode = createNode(torsionNode, atomName);
174 >          atomNode->bs.bitsets_[STUNTDOUBLE].setBitOn((*ai)->getGlobalIndex());
175 >        }
176 >
177 >      }
178 >      for (inversion = mol->beginInversion(inversionIter); inversion != NULL;
179 >           inversion = mol->nextInversion(inversionIter)) {
180  
181 +        std::string inversionName = inversion->getName();
182 +        TreeNode* inversionNode = createNode(molNode, inversionName);
183 +
184 +        molNode->bs.bitsets_[INVERSION].setBitOn(inversion->getGlobalIndex());
185 +        inversionNode->bs.bitsets_[INVERSION].setBitOn(inversion->getGlobalIndex());
186 +        std::vector<Atom*> atoms = inversion->getAtoms();
187 +        std::vector<Atom*>::iterator ai;
188 +        
189 +        for (ai = atoms.begin(); ai != atoms.end(); ++ai) {
190 +          std::string atomName = (*ai)->getType();
191 +          TreeNode* atomNode = createNode(inversionNode, atomName);
192 +          atomNode->bs.bitsets_[STUNTDOUBLE].setBitOn((*ai)->getGlobalIndex());
193 +        }
194 +      }
195 +    }
196    }
197  
198    TreeNode* NameFinder::createNode(TreeNode* parent, const std::string& name) {
# Line 119 | Line 202 | namespace oopse {
202      if ( foundIter  == parent->children.end()) {
203        node = new TreeNode;
204        node->name = name;
205 <      node->bs.resize(nStuntDouble_);
205 >      node->bs.resize(nObjects_);
206        parent->children.insert(std::make_pair(name, node));
207      }else {
208        node = foundIter->second;
# Line 127 | Line 210 | namespace oopse {
210      return node;
211    }
212  
213 <  OOPSEBitSet NameFinder::match(const std::string& name){
214 <    OOPSEBitSet bs(nStuntDouble_);
213 >  SelectionSet NameFinder::match(const std::string& name){
214 >    SelectionSet bs(nObjects_);
215    
216      StringTokenizer tokenizer(name, ".");
217  
# Line 138 | Line 221 | namespace oopse {
221      }
222  
223      int size = names.size();
224 +
225      switch(size) {
226      case 1 :
227        //could be molecule name, atom name and rigidbody name
228        matchMolecule(names[0], bs);
229        matchStuntDouble("*", names[0], bs);
230 +      matchBond("*", names[0], bs);
231 +      matchBend("*", names[0], bs);
232 +      matchTorsion("*", names[0], bs);
233 +      matchInversion("*", names[0], bs);
234              
235        break;
236      case 2:
# Line 173 | Line 261 | namespace oopse {
261      return bs;
262    }
263  
264 <  void NameFinder::matchMolecule(const std::string& molName, OOPSEBitSet& bs) {
264 >  void NameFinder::matchMolecule(const std::string& molName, SelectionSet& bs) {
265      std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
266      std::vector<TreeNode*>::iterator i;
267      for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
# Line 181 | Line 269 | namespace oopse {
269      }    
270    }
271  
272 <  void NameFinder::matchStuntDouble(const std::string& molName, const std::string& sdName, OOPSEBitSet& bs){
272 >  void NameFinder::matchStuntDouble(const std::string& molName, const std::string& sdName, 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 194 | Line 282 | namespace oopse {
282  
283    }
284  
285 <  void NameFinder::matchRigidAtoms(const std::string& molName, const std::string& rbName, const std::string& rbAtomName, OOPSEBitSet& bs){
285 >  void NameFinder::matchBond(const std::string& molName,
286 >                             const std::string& bondName, SelectionSet& bs){
287      std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
288      std::vector<TreeNode*>::iterator i;
289      for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
290 +      std::vector<TreeNode*> bondNodes = getMatchedChildren(*i, bondName);  
291 +      std::vector<TreeNode*>::iterator j;
292 +      for (j = bondNodes.begin(); j != bondNodes.end(); ++j) {
293 +        bs |= (*j)->bs;
294 +        std::vector<TreeNode*> bondAtomNodes = getAllChildren(*j);
295 +        std::vector<TreeNode*>::iterator k;
296 +        for(k = bondAtomNodes.begin(); k != bondAtomNodes.end(); ++k){
297 +          bs |= (*k)->bs;
298 +        }
299 +      }
300 +    }
301 +  }
302 +
303 +  void NameFinder::matchBend(const std::string& molName, const std::string& bendName,  SelectionSet& bs){
304 +    std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
305 +    std::vector<TreeNode*>::iterator i;
306 +    for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
307 +      std::vector<TreeNode*> bendNodes = getMatchedChildren(*i, bendName);  
308 +      std::vector<TreeNode*>::iterator j;
309 +      for (j = bendNodes.begin(); j != bendNodes.end(); ++j) {
310 +        std::vector<TreeNode*> bendAtomNodes = getAllChildren(*j);
311 +        std::vector<TreeNode*>::iterator k;
312 +        for(k = bendAtomNodes.begin(); k != bendAtomNodes.end(); ++k){
313 +          bs |= (*k)->bs;
314 +        }
315 +      }
316 +    }
317 +  }
318 +  void NameFinder::matchTorsion(const std::string& molName, const std::string& torsionName, SelectionSet& bs){
319 +    std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
320 +    std::vector<TreeNode*>::iterator i;
321 +    for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
322 +      std::vector<TreeNode*> torsionNodes = getMatchedChildren(*i, torsionName);  
323 +      std::vector<TreeNode*>::iterator j;
324 +      for (j = torsionNodes.begin(); j != torsionNodes.end(); ++j) {
325 +        std::vector<TreeNode*> torsionAtomNodes = getAllChildren(*j);
326 +        std::vector<TreeNode*>::iterator k;
327 +        for(k = torsionAtomNodes.begin(); k != torsionAtomNodes.end(); ++k){
328 +          bs |= (*k)->bs;
329 +        }
330 +      }
331 +    }
332 +  }
333 +  void NameFinder::matchInversion(const std::string& molName, const std::string& inversionName, SelectionSet& bs){
334 +    std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
335 +    std::vector<TreeNode*>::iterator i;
336 +    for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
337 +      std::vector<TreeNode*> inversionNodes = getMatchedChildren(*i, inversionName);  
338 +      std::vector<TreeNode*>::iterator j;
339 +      for (j = inversionNodes.begin(); j != inversionNodes.end(); ++j) {
340 +        std::vector<TreeNode*> inversionAtomNodes = getAllChildren(*j);
341 +        std::vector<TreeNode*>::iterator k;
342 +        for(k = inversionAtomNodes.begin(); k != inversionAtomNodes.end(); ++k){
343 +          bs |= (*k)->bs;
344 +        }
345 +      }
346 +    }
347 +  }
348 +
349 +  void NameFinder::matchRigidAtoms(const std::string& molName, const std::string& rbName, const std::string& rbAtomName, SelectionSet& bs){
350 +    std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);            
351 +    std::vector<TreeNode*>::iterator i;
352 +    for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
353        std::vector<TreeNode*> rbNodes = getMatchedChildren(*i, rbName);  
354        std::vector<TreeNode*>::iterator j;
355        for (j = rbNodes.begin(); j != rbNodes.end(); ++j) {
# Line 211 | Line 363 | namespace oopse {
363  
364    }
365  
366 +  std::vector<TreeNode*> NameFinder::getAllChildren(TreeNode* node)  {
367 +    std::vector<TreeNode*> childNodes;
368 +    std::map<std::string, TreeNode*>::iterator i;
369 +    for (i = node->children.begin(); i != node->children.end(); ++i) {
370 +      childNodes.push_back(i->second);
371 +    }
372 +    return childNodes;
373 +  }
374  
375    std::vector<TreeNode*> NameFinder::getMatchedChildren(TreeNode* node, const std::string& name) {
376      std::vector<TreeNode*> matchedNodes;
# Line 225 | Line 385 | namespace oopse {
385    }
386  
387    bool NameFinder::isMatched(const std::string& str, const std::string& wildcard) {
388 <    return Wildcard::wildcardfit (wildcard.c_str(), str.c_str());
388 >    return Wildcard::wildcardfit(wildcard.c_str(), str.c_str()) > 0 ? true : false;
389    }
390  
391  
392 <  void NameFinder::matchInternalIndex(const std::string& name, int internalIndex, OOPSEBitSet& bs){
392 >  void NameFinder::matchInternalIndex(const std::string& name, int internalIndex, SelectionSet& bs){
393  
234    std::map<std::string, TreeNode*>::iterator foundIter;
394      SimInfo::MoleculeIterator mi;
395      Molecule* mol;
396  
397 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
397 >    for (mol = info_->beginMolecule(mi); mol != NULL;
398 >         mol = info_->nextMolecule(mi)) {
399            
400        if (isMatched(mol->getMoleculeName(), name) ) {
401          int natoms = mol->getNAtoms();
# Line 243 | Line 403 | namespace oopse {
403          if (internalIndex >= natoms + nrigidbodies) {
404            continue;
405          } else if (internalIndex < natoms) {
406 <          bs.setBitOn(mol->getAtomAt(internalIndex)->getGlobalIndex());
406 >          bs.bitsets_[STUNTDOUBLE].setBitOn(mol->getAtomAt(internalIndex)->getGlobalIndex());
407            continue;
408          } else if ( internalIndex < natoms + nrigidbodies) {
409 <          bs.setBitOn(mol->getRigidBodyAt(internalIndex - natoms)->getGlobalIndex());
409 >          bs.bitsets_[STUNTDOUBLE].setBitOn(mol->getRigidBodyAt(internalIndex - natoms)->getGlobalIndex());
410          }
411        }
412 <        
253 <    }    
254 <    
412 >    }
413    }
414  
415 <  bool NameFinder::isInteger(const std::string str) {
416 <    for(int i =0; i < str.size(); ++i){
415 >  bool NameFinder::isInteger(const std::string &str) {
416 >    for(unsigned int i = 0; i < str.size(); ++i){
417        if (!std::isdigit(str[i])) {
418          return false;
419        }
420      }
263
421      return true;
422    }
266
423   }

Comparing trunk/src/selection/NameFinder.cpp (property svn:keywords):
Revision 770 by tim, Fri Dec 2 15:38:03 2005 UTC vs.
Revision 1953 by gezelter, Thu Dec 5 18:19:26 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines