55 |
|
} |
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 |
|
|
68 |
|
} |
69 |
|
|
70 |
|
void NameFinder::loadNames() { |
67 |
– |
|
71 |
|
SimInfo::MoleculeIterator mi; |
69 |
– |
Molecule* mol; |
72 |
|
Molecule::AtomIterator ai; |
71 |
– |
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; |
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; |
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 |
+ |
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 |
|
|
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; |
210 |
|
return node; |
211 |
|
} |
212 |
|
|
213 |
< |
OpenMDBitSet NameFinder::match(const std::string& name){ |
214 |
< |
OpenMDBitSet bs(nStuntDouble_); |
213 |
> |
SelectionSet NameFinder::match(const std::string& name){ |
214 |
> |
SelectionSet bs(nObjects_); |
215 |
|
|
216 |
|
StringTokenizer tokenizer(name, "."); |
217 |
|
|
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: |
261 |
|
return bs; |
262 |
|
} |
263 |
|
|
264 |
< |
void NameFinder::matchMolecule(const std::string& molName, OpenMDBitSet& 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 ) { |
269 |
|
} |
270 |
|
} |
271 |
|
|
272 |
< |
void NameFinder::matchStuntDouble(const std::string& molName, const std::string& sdName, OpenMDBitSet& 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 ) { |
282 |
|
|
283 |
|
} |
284 |
|
|
285 |
< |
void NameFinder::matchRigidAtoms(const std::string& molName, const std::string& rbName, const std::string& rbAtomName, OpenMDBitSet& 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) { |
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; |
389 |
|
} |
390 |
|
|
391 |
|
|
392 |
< |
void NameFinder::matchInternalIndex(const std::string& name, int internalIndex, OpenMDBitSet& bs){ |
392 |
> |
void NameFinder::matchInternalIndex(const std::string& name, int internalIndex, SelectionSet& bs){ |
393 |
|
|
394 |
|
SimInfo::MoleculeIterator mi; |
395 |
|
Molecule* mol; |
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 |
|
} |