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);; |
113 |
> |
// COMMENTED OUT because rigid bodies are IntegrableObjects |
114 |
> |
// (e.g. they are independently mobile, so selecting their |
115 |
> |
// member atoms will give some odd results if we are computing |
116 |
> |
// degrees of freedom elsewhere. |
117 |
|
|
118 |
< |
currentRbAtomNode->bs.setBitOn(atom->getGlobalIndex()); |
119 |
< |
} |
118 |
> |
// //create nodes for atoms belong to this rigidbody |
119 |
> |
// for(atom = rb->beginAtom(ai); atom != NULL; atom = rb->nextAtom(ai)) { |
120 |
> |
// std::string rbAtomName = atom->getType(); |
121 |
> |
// TreeNode* rbAtomNode = createNode(rbNode, rbAtomName); |
122 |
> |
|
123 |
> |
// rbAtomNode->bs.bitsets_[STUNTDOUBLE].setBitOn(atom->getGlobalIndex()); |
124 |
> |
// } |
125 |
> |
} |
126 |
> |
|
127 |
> |
for (bond = mol->beginBond(bondIter); bond != NULL; |
128 |
> |
bond = mol->nextBond(bondIter)) { |
129 |
> |
|
130 |
> |
std::string bondName = bond->getName(); |
131 |
> |
TreeNode* bondNode = createNode(molNode, bondName); |
132 |
> |
|
133 |
> |
molNode->bs.bitsets_[BOND].setBitOn(bond->getGlobalIndex()); |
134 |
> |
bondNode->bs.bitsets_[BOND].setBitOn(bond->getGlobalIndex()); |
135 |
> |
|
136 |
> |
std::vector<Atom*> atoms = bond->getAtoms(); |
137 |
> |
std::vector<Atom*>::iterator ai; |
138 |
> |
|
139 |
> |
for (ai = atoms.begin(); ai != atoms.end(); ++ai) { |
140 |
> |
std::string atomName = (*ai)->getType(); |
141 |
> |
TreeNode* atomNode = createNode(bondNode, atomName); |
142 |
> |
atomNode->bs.bitsets_[STUNTDOUBLE].setBitOn((*ai)->getGlobalIndex()); |
143 |
> |
} |
144 |
> |
} |
145 |
> |
for (bend = mol->beginBend(bendIter); bend != NULL; |
146 |
> |
bend = mol->nextBend(bendIter)) { |
147 |
> |
|
148 |
> |
std::string bendName = bend->getName(); |
149 |
> |
TreeNode* bendNode = createNode(molNode, bendName); |
150 |
> |
|
151 |
> |
molNode->bs.bitsets_[BEND].setBitOn(bend->getGlobalIndex()); |
152 |
> |
bendNode->bs.bitsets_[BEND].setBitOn(bend->getGlobalIndex()); |
153 |
> |
|
154 |
> |
std::vector<Atom*> atoms = bend->getAtoms(); |
155 |
> |
std::vector<Atom*>::iterator ai; |
156 |
> |
|
157 |
> |
for (ai = atoms.begin(); ai != atoms.end(); ++ai) { |
158 |
> |
std::string atomName = (*ai)->getType(); |
159 |
> |
TreeNode* atomNode = createNode(bendNode, atomName); |
160 |
> |
atomNode->bs.bitsets_[STUNTDOUBLE].setBitOn((*ai)->getGlobalIndex()); |
161 |
> |
} |
162 |
> |
|
163 |
> |
} |
164 |
> |
for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; |
165 |
> |
torsion = mol->nextTorsion(torsionIter)) { |
166 |
> |
|
167 |
> |
std::string torsionName = torsion->getName(); |
168 |
> |
TreeNode* torsionNode = createNode(molNode, torsionName); |
169 |
> |
|
170 |
> |
molNode->bs.bitsets_[TORSION].setBitOn(torsion->getGlobalIndex()); |
171 |
> |
torsionNode->bs.bitsets_[TORSION].setBitOn(torsion->getGlobalIndex()); |
172 |
> |
|
173 |
> |
std::vector<Atom*> atoms = torsion->getAtoms(); |
174 |
> |
std::vector<Atom*>::iterator ai; |
175 |
> |
|
176 |
> |
for (ai = atoms.begin(); ai != atoms.end(); ++ai) { |
177 |
> |
std::string atomName = (*ai)->getType(); |
178 |
> |
TreeNode* atomNode = createNode(torsionNode, atomName); |
179 |
> |
atomNode->bs.bitsets_[STUNTDOUBLE].setBitOn((*ai)->getGlobalIndex()); |
180 |
> |
} |
181 |
> |
|
182 |
> |
} |
183 |
> |
for (inversion = mol->beginInversion(inversionIter); inversion != NULL; |
184 |
> |
inversion = mol->nextInversion(inversionIter)) { |
185 |
> |
|
186 |
> |
std::string inversionName = inversion->getName(); |
187 |
> |
TreeNode* inversionNode = createNode(molNode, inversionName); |
188 |
> |
|
189 |
> |
molNode->bs.bitsets_[INVERSION].setBitOn(inversion->getGlobalIndex()); |
190 |
> |
inversionNode->bs.bitsets_[INVERSION].setBitOn(inversion->getGlobalIndex()); |
191 |
> |
std::vector<Atom*> atoms = inversion->getAtoms(); |
192 |
> |
std::vector<Atom*>::iterator ai; |
193 |
> |
|
194 |
> |
for (ai = atoms.begin(); ai != atoms.end(); ++ai) { |
195 |
> |
std::string atomName = (*ai)->getType(); |
196 |
> |
TreeNode* atomNode = createNode(inversionNode, atomName); |
197 |
> |
atomNode->bs.bitsets_[STUNTDOUBLE].setBitOn((*ai)->getGlobalIndex()); |
198 |
> |
} |
199 |
|
} |
200 |
|
} |
201 |
|
} |
207 |
|
if ( foundIter == parent->children.end()) { |
208 |
|
node = new TreeNode; |
209 |
|
node->name = name; |
210 |
< |
node->bs.resize(nStuntDouble_); |
210 |
> |
node->bs.resize(nObjects_); |
211 |
|
parent->children.insert(std::make_pair(name, node)); |
212 |
|
}else { |
213 |
|
node = foundIter->second; |
215 |
|
return node; |
216 |
|
} |
217 |
|
|
218 |
< |
OpenMDBitSet NameFinder::match(const std::string& name){ |
219 |
< |
OpenMDBitSet bs(nStuntDouble_); |
218 |
> |
SelectionSet NameFinder::match(const std::string& name){ |
219 |
> |
SelectionSet bs(nObjects_); |
220 |
|
|
221 |
|
StringTokenizer tokenizer(name, "."); |
222 |
|
|
226 |
|
} |
227 |
|
|
228 |
|
int size = names.size(); |
229 |
+ |
|
230 |
|
switch(size) { |
231 |
|
case 1 : |
232 |
|
//could be molecule name, atom name and rigidbody name |
233 |
|
matchMolecule(names[0], bs); |
234 |
|
matchStuntDouble("*", names[0], bs); |
235 |
+ |
matchBond("*", names[0], bs); |
236 |
+ |
matchBend("*", names[0], bs); |
237 |
+ |
matchTorsion("*", names[0], bs); |
238 |
+ |
matchInversion("*", names[0], bs); |
239 |
|
|
240 |
|
break; |
241 |
|
case 2: |
266 |
|
return bs; |
267 |
|
} |
268 |
|
|
269 |
< |
void NameFinder::matchMolecule(const std::string& molName, OpenMDBitSet& bs) { |
269 |
> |
void NameFinder::matchMolecule(const std::string& molName, SelectionSet& bs) { |
270 |
|
std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName); |
271 |
|
std::vector<TreeNode*>::iterator i; |
272 |
|
for( i = molNodes.begin(); i != molNodes.end(); ++i ) { |
274 |
|
} |
275 |
|
} |
276 |
|
|
277 |
< |
void NameFinder::matchStuntDouble(const std::string& molName, const std::string& sdName, OpenMDBitSet& bs){ |
277 |
> |
void NameFinder::matchStuntDouble(const std::string& molName, const std::string& sdName, SelectionSet& bs){ |
278 |
|
std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName); |
279 |
|
std::vector<TreeNode*>::iterator i; |
280 |
|
for( i = molNodes.begin(); i != molNodes.end(); ++i ) { |
287 |
|
|
288 |
|
} |
289 |
|
|
290 |
< |
void NameFinder::matchRigidAtoms(const std::string& molName, const std::string& rbName, const std::string& rbAtomName, OpenMDBitSet& bs){ |
290 |
> |
void NameFinder::matchBond(const std::string& molName, |
291 |
> |
const std::string& bondName, SelectionSet& bs){ |
292 |
|
std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName); |
293 |
|
std::vector<TreeNode*>::iterator i; |
294 |
|
for( i = molNodes.begin(); i != molNodes.end(); ++i ) { |
295 |
+ |
std::vector<TreeNode*> bondNodes = getMatchedChildren(*i, bondName); |
296 |
+ |
std::vector<TreeNode*>::iterator j; |
297 |
+ |
for (j = bondNodes.begin(); j != bondNodes.end(); ++j) { |
298 |
+ |
bs |= (*j)->bs; |
299 |
+ |
std::vector<TreeNode*> bondAtomNodes = getAllChildren(*j); |
300 |
+ |
std::vector<TreeNode*>::iterator k; |
301 |
+ |
for(k = bondAtomNodes.begin(); k != bondAtomNodes.end(); ++k){ |
302 |
+ |
bs |= (*k)->bs; |
303 |
+ |
} |
304 |
+ |
} |
305 |
+ |
} |
306 |
+ |
} |
307 |
+ |
|
308 |
+ |
void NameFinder::matchBend(const std::string& molName, const std::string& bendName, SelectionSet& bs){ |
309 |
+ |
std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName); |
310 |
+ |
std::vector<TreeNode*>::iterator i; |
311 |
+ |
for( i = molNodes.begin(); i != molNodes.end(); ++i ) { |
312 |
+ |
std::vector<TreeNode*> bendNodes = getMatchedChildren(*i, bendName); |
313 |
+ |
std::vector<TreeNode*>::iterator j; |
314 |
+ |
for (j = bendNodes.begin(); j != bendNodes.end(); ++j) { |
315 |
+ |
std::vector<TreeNode*> bendAtomNodes = getAllChildren(*j); |
316 |
+ |
std::vector<TreeNode*>::iterator k; |
317 |
+ |
for(k = bendAtomNodes.begin(); k != bendAtomNodes.end(); ++k){ |
318 |
+ |
bs |= (*k)->bs; |
319 |
+ |
} |
320 |
+ |
} |
321 |
+ |
} |
322 |
+ |
} |
323 |
+ |
void NameFinder::matchTorsion(const std::string& molName, const std::string& torsionName, SelectionSet& bs){ |
324 |
+ |
std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName); |
325 |
+ |
std::vector<TreeNode*>::iterator i; |
326 |
+ |
for( i = molNodes.begin(); i != molNodes.end(); ++i ) { |
327 |
+ |
std::vector<TreeNode*> torsionNodes = getMatchedChildren(*i, torsionName); |
328 |
+ |
std::vector<TreeNode*>::iterator j; |
329 |
+ |
for (j = torsionNodes.begin(); j != torsionNodes.end(); ++j) { |
330 |
+ |
std::vector<TreeNode*> torsionAtomNodes = getAllChildren(*j); |
331 |
+ |
std::vector<TreeNode*>::iterator k; |
332 |
+ |
for(k = torsionAtomNodes.begin(); k != torsionAtomNodes.end(); ++k){ |
333 |
+ |
bs |= (*k)->bs; |
334 |
+ |
} |
335 |
+ |
} |
336 |
+ |
} |
337 |
+ |
} |
338 |
+ |
void NameFinder::matchInversion(const std::string& molName, const std::string& inversionName, SelectionSet& bs){ |
339 |
+ |
std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName); |
340 |
+ |
std::vector<TreeNode*>::iterator i; |
341 |
+ |
for( i = molNodes.begin(); i != molNodes.end(); ++i ) { |
342 |
+ |
std::vector<TreeNode*> inversionNodes = getMatchedChildren(*i, inversionName); |
343 |
+ |
std::vector<TreeNode*>::iterator j; |
344 |
+ |
for (j = inversionNodes.begin(); j != inversionNodes.end(); ++j) { |
345 |
+ |
std::vector<TreeNode*> inversionAtomNodes = getAllChildren(*j); |
346 |
+ |
std::vector<TreeNode*>::iterator k; |
347 |
+ |
for(k = inversionAtomNodes.begin(); k != inversionAtomNodes.end(); ++k){ |
348 |
+ |
bs |= (*k)->bs; |
349 |
+ |
} |
350 |
+ |
} |
351 |
+ |
} |
352 |
+ |
} |
353 |
+ |
|
354 |
+ |
void NameFinder::matchRigidAtoms(const std::string& molName, const std::string& rbName, const std::string& rbAtomName, SelectionSet& bs){ |
355 |
+ |
std::vector<TreeNode*> molNodes = getMatchedChildren(root_, molName); |
356 |
+ |
std::vector<TreeNode*>::iterator i; |
357 |
+ |
for( i = molNodes.begin(); i != molNodes.end(); ++i ) { |
358 |
|
std::vector<TreeNode*> rbNodes = getMatchedChildren(*i, rbName); |
359 |
|
std::vector<TreeNode*>::iterator j; |
360 |
|
for (j = rbNodes.begin(); j != rbNodes.end(); ++j) { |
368 |
|
|
369 |
|
} |
370 |
|
|
371 |
+ |
std::vector<TreeNode*> NameFinder::getAllChildren(TreeNode* node) { |
372 |
+ |
std::vector<TreeNode*> childNodes; |
373 |
+ |
std::map<std::string, TreeNode*>::iterator i; |
374 |
+ |
for (i = node->children.begin(); i != node->children.end(); ++i) { |
375 |
+ |
childNodes.push_back(i->second); |
376 |
+ |
} |
377 |
+ |
return childNodes; |
378 |
+ |
} |
379 |
|
|
380 |
|
std::vector<TreeNode*> NameFinder::getMatchedChildren(TreeNode* node, const std::string& name) { |
381 |
|
std::vector<TreeNode*> matchedNodes; |
394 |
|
} |
395 |
|
|
396 |
|
|
397 |
< |
void NameFinder::matchInternalIndex(const std::string& name, int internalIndex, OpenMDBitSet& bs){ |
397 |
> |
void NameFinder::matchInternalIndex(const std::string& name, int internalIndex, SelectionSet& bs){ |
398 |
|
|
399 |
|
SimInfo::MoleculeIterator mi; |
400 |
|
Molecule* mol; |
408 |
|
if (internalIndex >= natoms + nrigidbodies) { |
409 |
|
continue; |
410 |
|
} else if (internalIndex < natoms) { |
411 |
< |
bs.setBitOn(mol->getAtomAt(internalIndex)->getGlobalIndex()); |
411 |
> |
bs.bitsets_[STUNTDOUBLE].setBitOn(mol->getAtomAt(internalIndex)->getGlobalIndex()); |
412 |
|
continue; |
413 |
|
} else if ( internalIndex < natoms + nrigidbodies) { |
414 |
< |
bs.setBitOn(mol->getRigidBodyAt(internalIndex - natoms)->getGlobalIndex()); |
414 |
> |
bs.bitsets_[STUNTDOUBLE].setBitOn(mol->getRigidBodyAt(internalIndex - natoms)->getGlobalIndex()); |
415 |
|
} |
416 |
|
} |
417 |
|
} |