ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/selection/NameFinder.cpp
Revision: 1971
Committed: Fri Feb 4 05:42:49 2005 UTC (19 years, 5 months ago) by tim
File size: 9035 byte(s)
Log Message:
selection library get built

File Contents

# User Rev Content
1 tim 1967 /*
2     * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3     *
4     * The University of Notre Dame grants you ("Licensee") a
5     * non-exclusive, royalty free, license to use, modify and
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
19     * notice, this list of conditions and the following disclaimer.
20     *
21     * 3. Redistributions in binary form must reproduce the above copyright
22     * notice, this list of conditions and the following disclaimer in the
23     * documentation and/or other materials provided with the
24     * distribution.
25     *
26     * This software is provided "AS IS," without a warranty of any
27     * kind. All express or implied conditions, representations and
28     * warranties, including any implied warranty of merchantability,
29     * fitness for a particular purpose or non-infringement, are hereby
30     * excluded. The University of Notre Dame and its licensors shall not
31     * be liable for any damages suffered by licensee as a result of
32     * using, modifying or distributing the software or its
33     * derivatives. In no event will the University of Notre Dame or its
34     * licensors be liable for any lost revenue, profit or data, or for
35     * direct, indirect, special, consequential, incidental or punitive
36     * damages, however caused and regardless of the theory of liability,
37     * arising out of the use of or inability to use software, even if the
38     * University of Notre Dame has been advised of the possibility of
39     * such damages.
40     */
41     #include "selection/NameFinder.hpp"
42 tim 1968 #include "utils/wildcards.hpp"
43 tim 1971 #include "utils/StringTokenizer.hpp"
44     #include "primitives/Molecule.hpp"
45 tim 1967 namespace oopse {
46    
47 tim 1968 TreeNode::~TreeNode(){
48     std::map<std::string, TreeNode*>::iterator i;
49     for ( i = children.begin(); i != children.end(); ++i) {
50     i->second->~TreeNode();
51     }
52     children.clear();
53     }
54    
55    
56     NameFinder::NameFinder(SimInfo* info) : info_(info), root_(NULL){
57 tim 1971 nStuntDouble_ = info_->getNGlobalAtoms() + info_->getNGlobalRigidBodies();
58 tim 1967 loadNames();
59     }
60    
61    
62 tim 1968 NameFinder::~NameFinder(){
63     delete root_;
64     }
65 tim 1967
66     void NameFinder::loadNames() {
67    
68 tim 1968 std::map<std::string, TreeNode*>::iterator foundIter;
69 tim 1967 SimInfo::MoleculeIterator mi;
70     Molecule* mol;
71     Molecule::AtomIterator ai;
72     Atom* atom;
73     Molecule::RigidBodyIterator rbIter;
74     RigidBody* rb;
75 tim 1968
76     root_ = new TreeNode;
77 tim 1971 root_->bs.resize(nStuntDouble_);
78 tim 1968 root_->bs.setAll(); //
79    
80 tim 1967 for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
81 tim 1968 TreeNode* currentMolNode;
82     std::string molName = mol->getMoleculeName();
83    
84     foundIter = root_->children.find(molName);
85     if ( foundIter == root_->children.end()) {
86     currentMolNode = new TreeNode;
87     currentMolNode->name = molName;
88     currentMolNode->bs.resize(nStuntDouble_);
89     }else {
90 tim 1971 currentMolNode = foundIter->second;
91 tim 1968 }
92 tim 1967
93     for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
94 tim 1968 std::string atomName = atom->getType();
95     TreeNode* currentAtomNode;
96     foundIter = currentMolNode->children.find(molName);
97     if (foundIter == currentMolNode->children.end()) {
98     currentAtomNode = new TreeNode;
99     currentAtomNode->name = atomName;
100     currentAtomNode->bs.resize(nStuntDouble_);
101     } else {
102     currentAtomNode = foundIter->second;
103     }
104     currentMolNode->bs.setBitOn(atom->getGlobalIndex());
105     currentAtomNode->bs.setBitOn(atom->getGlobalIndex());
106 tim 1967 }
107 tim 1968
108     for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
109     std::string rbName = atom->getType();
110     TreeNode* currentRbNode;
111     foundIter = currentMolNode->children.find(molName);
112     if (foundIter == currentMolNode->children.end()) {
113     currentRbNode = new TreeNode;
114     currentRbNode->name = rbName;
115     currentRbNode->bs.resize(nStuntDouble_);
116     } else {
117     currentRbNode = foundIter->second;
118     }
119    
120     currentMolNode->bs.setBitOn(rb->getGlobalIndex());
121     currentRbNode->bs.setBitOn(rb->getGlobalIndex());
122    
123     //create nodes for atoms belong to this rigidbody
124     for(atom = rb->beginAtom(ai); rb != NULL; atom = rb->nextAtom(ai)) {
125     std::string rbAtomName = atom->getType();
126     TreeNode* currentRbAtomNode;
127     foundIter = currentRbNode->children.find(molName);
128     if (foundIter == currentRbNode->children.end()) {
129     currentRbAtomNode = new TreeNode;
130     currentRbAtomNode->name = rbAtomName;
131     currentRbAtomNode->bs.resize(nStuntDouble_);
132     } else {
133     currentRbAtomNode = foundIter->second;
134     }
135     currentRbAtomNode->bs.setBitOn(atom->getGlobalIndex());
136     }
137    
138     }
139 tim 1967
140     }
141 tim 1968
142 tim 1967 }
143    
144     bool NameFinder::match(const std::string& name, BitSet& bs){
145    
146 tim 1971 bool hasError = false;
147 tim 1967 StringTokenizer tokenizer(name, ".");
148    
149     std::vector<std::string> names;
150     while(tokenizer.hasMoreTokens()) {
151     names.push_back(tokenizer.nextToken());
152     }
153    
154     int size = names.size();
155     switch(size) {
156     case 1 :
157 tim 1968 //could be molecule name, atom name and rigidbody name
158     if (names[0] == "*"){
159     //if all molecules are selected, we don't need to do the matching, just set all of the bits
160     bs.setAll();
161     } else{
162 tim 1971 matchMolecule(names[0], bs);
163     matchStuntDouble("*", names[0], bs);
164 tim 1968 }
165    
166 tim 1967 break;
167     case 2:
168 tim 1968 //could be molecule.*(include atoms and rigidbodies) or rigidbody.*(atoms belong to rigidbody)
169     matchRigidAtoms("*", names[0], names[1], bs);
170 tim 1971 matchStuntDouble(names[0], names[1], bs);
171 tim 1968
172 tim 1967 break;
173     case 3:
174     //must be molecule.rigidbody.*
175 tim 1971 matchRigidAtoms(names[0], names[1], names[2], bs);
176 tim 1967 break;
177 tim 1971 default:
178     hasError = true;
179 tim 1967 break;
180     }
181    
182 tim 1971 return hasError;
183 tim 1967 }
184    
185 tim 1968 void NameFinder::matchMolecule(const std::string& molName, BitSet& 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 tim 1971 bs |= (*i)->bs;
190 tim 1968 }
191 tim 1967 }
192 tim 1968
193     void NameFinder::matchStuntDouble(const std::string& molName, const std::string& sdName, BitSet& bs){
194     std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);
195     std::vector<TreeNode*>::iterator i;
196     for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
197     std::vector<TreeNode*> sdNodes = getMatchedChildren(*i, sdName);
198     std::vector<TreeNode*>::iterator j;
199     for (j = sdNodes.begin(); j != sdNodes.end(); ++j) {
200 tim 1971 bs |= (*j)->bs;
201 tim 1968 }
202     }
203    
204     }
205    
206     void NameFinder::matchRigidAtoms(const std::string& molName, const std::string& rbName, const std::string& rbAtomName, BitSet& bs){
207     std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName);
208     std::vector<TreeNode*>::iterator i;
209     for( i = molNodes.begin(); i != molNodes.end(); ++i ) {
210     std::vector<TreeNode*> rbNodes = getMatchedChildren(*i, rbName);
211     std::vector<TreeNode*>::iterator j;
212     for (j = rbNodes.begin(); j != rbNodes.end(); ++j) {
213     std::vector<TreeNode*> rbAtomNodes = getMatchedChildren(*j, rbAtomName);
214     std::vector<TreeNode*>::iterator k;
215     for(k = rbAtomNodes.begin(); k != rbAtomNodes.end(); ++k){
216 tim 1971 bs |= (*k)->bs;
217 tim 1968 }
218     }
219     }
220    
221     }
222    
223    
224     std::vector<TreeNode*> NameFinder::getMatchedChildren(TreeNode* node, const std::string& name) {
225     std::vector<TreeNode*> matchedNodes;
226     std::map<std::string, TreeNode*>::iterator i;
227     for (i = node->children.begin(); i != node->children.end(); ++i) {
228     if (isMatched( i->first, name)) {
229     matchedNodes.push_back(i->second);
230     }
231     }
232    
233     return matchedNodes;
234     }
235    
236     bool NameFinder::isMatched(const std::string& str, const std::string& wildcard) {
237     return Wildcard::wildcardfit (wildcard.c_str(), str.c_str());
238     }
239    
240     }

Properties

Name Value
svn:executable *