38 |
|
* University of Notre Dame has been advised of the possibility of |
39 |
|
* such damages. |
40 |
|
*/ |
41 |
< |
|
41 |
> |
|
42 |
> |
#include <functional> |
43 |
|
#include <iostream> |
44 |
< |
#include <functional> |
44 |
> |
#include <sstream> |
45 |
|
#include "types/MoleculeStamp.hpp" |
46 |
|
#include "utils/Tuple.hpp" |
47 |
|
|
48 |
|
namespace oopse { |
49 |
+ |
|
50 |
+ |
template<class ContainerType> |
51 |
+ |
std::string containerToString(ContainerType& cont) { |
52 |
+ |
std::ostringstream oss; |
53 |
+ |
oss << "("; |
54 |
+ |
typename ContainerType::iterator i = cont.begin(); |
55 |
+ |
if (i != cont.end()) { |
56 |
+ |
oss << *i; |
57 |
+ |
++i; |
58 |
+ |
} |
59 |
+ |
for (; i != cont.end();++i) { |
60 |
+ |
oss << ", "; |
61 |
+ |
oss << *i; |
62 |
+ |
} |
63 |
+ |
oss << ")"; |
64 |
+ |
return oss.str(); |
65 |
+ |
} |
66 |
+ |
|
67 |
|
MoleculeStamp::MoleculeStamp() { |
68 |
|
DefineParameter(Name, "name"); |
69 |
|
|
83 |
|
bool MoleculeStamp::addAtomStamp( AtomStamp* atom) { |
84 |
|
bool ret = addIndexSensitiveStamp(atomStamps_, atom); |
85 |
|
if (!ret) { |
86 |
< |
std::cout << "multiple atoms have the same index: " << atom->getIndex() <<" in " << getName() << " Molecule\n"; |
86 |
> |
std::cout<< "Error in Molecule " << getName() << ": multiple atoms have the same indices"<< atom->getIndex() <<"\n"; |
87 |
|
} |
88 |
|
return ret; |
89 |
|
|
107 |
|
bool MoleculeStamp::addRigidBodyStamp( RigidBodyStamp* rigidbody) { |
108 |
|
bool ret = addIndexSensitiveStamp(rigidBodyStamps_, rigidbody); |
109 |
|
if (!ret) { |
110 |
< |
std::cout << "multiple rigidbodies have the same index: " << rigidbody->getIndex() <<" in " << getName() << " Molecule\n"; |
110 |
> |
std::cout<< "Error in Molecule " << getName() << ": multiple rigidbodies have the same indices: " << rigidbody->getIndex() <<"\n"; |
111 |
|
} |
112 |
|
return ret; |
113 |
|
} |
162 |
|
std::cout << "Error in Molecule " << getName() << ": atom[" << ai - atomStamps_.begin()<< "] is missing\n"; |
163 |
|
} |
164 |
|
|
165 |
+ |
} |
166 |
+ |
|
167 |
+ |
void MoleculeStamp::checkBonds() { |
168 |
|
//make sure index is not out of range |
169 |
|
int natoms = getNAtoms(); |
170 |
|
for(int i = 0; i < getNBonds(); ++i) { |
171 |
|
BondStamp* bondStamp = getBondStamp(i); |
172 |
|
if (bondStamp->getA() >= natoms && bondStamp->getB() >= natoms) { |
173 |
< |
std::cout << "Error in Molecule " << getName() << ": bond between " << bondStamp->getA() << " and " << bondStamp->getB() << " is invalid\n"; |
173 |
> |
std::cout << "Error in Molecule " << getName() << ": bond(" << bondStamp->getA() << ", " << bondStamp->getB() << ") is invalid\n"; |
174 |
|
} |
175 |
|
} |
176 |
< |
} |
155 |
< |
|
156 |
< |
void MoleculeStamp::checkBonds() { |
176 |
> |
|
177 |
|
//make sure bonds are unique |
178 |
|
std::set<std::pair<int, int> > allBonds; |
179 |
|
for(int i = 0; i < getNBonds(); ++i) { |
186 |
|
|
187 |
|
std::set<std::pair<int, int> >::iterator iter = allBonds.find(bondPair); |
188 |
|
if ( iter != allBonds.end()) { |
189 |
< |
std::cout << "Error in Molecule " << getName() << ": " << "Bond appears multiple times\n"; |
189 |
> |
std::cout << "Error in Molecule " << getName() << ": " << "bond(" <<iter->first << ", "<< iter->second << ")appears multiple times\n"; |
190 |
|
} else { |
191 |
|
allBonds.insert(bondPair); |
192 |
|
} |
196 |
|
for(int i = 0; i < getNBonds(); ++i) { |
197 |
|
BondStamp* bondStamp = getBondStamp(i); |
198 |
|
if (atom2Rigidbody[bondStamp->getA()] == atom2Rigidbody[bondStamp->getB()]) { |
199 |
< |
std::cout << "Error in Molecule " << getName() << ": "<<"bond between " << bondStamp->getA() << " and " << bondStamp->getB() << " belong to same rigidbody " << atom2Rigidbody[bondStamp->getA()] << "\n"; |
199 |
> |
std::cout << "Error in Molecule " << getName() << ": "<<"bond(" << bondStamp->getA() << ", " << bondStamp->getB() << ") belong to same rigidbody " << atom2Rigidbody[bondStamp->getA()] << "\n"; |
200 |
|
} |
201 |
|
} |
202 |
|
|
203 |
|
} |
204 |
|
|
185 |
– |
struct BendLessThan : public std::binary_function<IntTuple4, IntTuple4, bool> { |
186 |
– |
bool operator()(IntTuple3 b1, IntTuple3 b2) { |
187 |
– |
return b1.first < b2.first |
188 |
– |
|| (!(b2.first < b1.first) && b1.second < b2.second) |
189 |
– |
|| (!(b2.first < b1.first) && !(b2.second < b2.second) && b1.third < b2.third); |
190 |
– |
} |
191 |
– |
}; |
192 |
– |
|
205 |
|
void MoleculeStamp::checkBends() { |
206 |
|
for(int i = 0; i < getNBends(); ++i) { |
207 |
|
BendStamp* bendStamp = getBendStamp(i); |
208 |
|
std::vector<int> bendAtoms = bendStamp->getMembers(); |
209 |
|
std::vector<int>::iterator j =std::find_if(bendAtoms.begin(), bendAtoms.end(), std::bind2nd(std::greater<int>(), getNAtoms()-1)); |
210 |
|
if (j != bendAtoms.end()) { |
211 |
< |
std::cout << "Error in Molecule " << getName(); |
211 |
> |
std::cout << "Error in Molecule " << getName() << " : atoms of bend" << containerToString(bendAtoms) << "have invalid indices\n"; |
212 |
|
} |
213 |
|
|
214 |
|
if (bendAtoms.size() == 2 ) { |
242 |
|
if (rigidbodyIndex >= 0) { |
243 |
|
++rigidSet[rigidbodyIndex]; |
244 |
|
if (rigidSet[rigidbodyIndex] > 1) { |
245 |
< |
std::cout << "Error in Molecule " << getName() << ": "; |
234 |
< |
//std::cout << "atoms of bend " << << "belong to same rigidbody " << rigidbodyIndex << "\n"; |
245 |
> |
std::cout << "Error in Molecule " << getName() << ": bend" << containerToString(bendAtoms) << " belong to same rigidbody " << rigidbodyIndex << "\n"; |
246 |
|
} |
247 |
|
} |
248 |
|
} |
249 |
|
} |
250 |
|
|
251 |
|
|
252 |
< |
std::set<IntTuple3, BendLessThan> allBends; |
253 |
< |
std::set<IntTuple3, BendLessThan>::iterator iter; |
252 |
> |
std::set<IntTuple3> allBends; |
253 |
> |
std::set<IntTuple3>::iterator iter; |
254 |
|
for(int i = 0; i < getNBends(); ++i) { |
255 |
|
BendStamp* bendStamp= getBendStamp(i); |
256 |
|
std::vector<int> bend = bendStamp->getMembers(); |
337 |
|
|
338 |
|
} |
339 |
|
|
329 |
– |
struct TorsionLessThan : public std::binary_function<IntTuple4, IntTuple4, bool> { |
330 |
– |
bool operator()(IntTuple4 t1, IntTuple4 t2) { |
331 |
– |
|
332 |
– |
return t1.first < t2.first |
333 |
– |
|| (!(t2.first < t1.first) && t1.second < t2.second) |
334 |
– |
|| (!(t2.first < t1.first) && !(t2.second < t2.second) && t1.third < t2.third) |
335 |
– |
||(!(t2.first < t1.first) && !(t2.second < t2.second) && !(t2.third < t1.third) && t1.fourth < t2.fourth); |
336 |
– |
} |
337 |
– |
|
338 |
– |
|
339 |
– |
|
340 |
– |
}; |
341 |
– |
|
342 |
– |
|
340 |
|
void MoleculeStamp::checkTorsions() { |
341 |
|
for(int i = 0; i < getNTorsions(); ++i) { |
342 |
|
TorsionStamp* torsionStamp = getTorsionStamp(i); |
343 |
+ |
std::vector<int> torsionAtoms = torsionStamp ->getMembers(); |
344 |
+ |
std::vector<int>::iterator j =std::find_if(torsionAtoms.begin(), torsionAtoms.end(), std::bind2nd(std::greater<int>(), getNAtoms()-1)); |
345 |
+ |
if (j != torsionAtoms.end()) { |
346 |
+ |
std::cout << "Error in Molecule " << getName() << ": atoms of torsion" << containerToString(torsionAtoms) << " have invalid indices\n"; |
347 |
+ |
} |
348 |
+ |
} |
349 |
+ |
|
350 |
+ |
for(int i = 0; i < getNTorsions(); ++i) { |
351 |
+ |
TorsionStamp* torsionStamp = getTorsionStamp(i); |
352 |
|
std::vector<int> torsionAtoms = torsionStamp->getMembers(); |
353 |
|
std::vector<int> rigidSet(getNRigidBodies(), 0); |
354 |
|
std::vector<int>::iterator j; |
357 |
|
if (rigidbodyIndex >= 0) { |
358 |
|
++rigidSet[rigidbodyIndex]; |
359 |
|
if (rigidSet[rigidbodyIndex] > 1) { |
360 |
< |
std::cout << "Error in Molecule " << getName() << ": "; |
355 |
< |
//std::cout << "atoms of torsion " << << "belong to same rigidbody " << rigidbodyIndex << "\n"; |
360 |
> |
std::cout << "Error in Molecule " << getName() << ": torsion" << containerToString(torsionAtoms) << "is invalid\n"; |
361 |
|
} |
362 |
|
} |
363 |
|
} |
364 |
|
} |
365 |
|
|
366 |
< |
std::set<IntTuple4, TorsionLessThan> allTorsions; |
367 |
< |
std::set<IntTuple4, TorsionLessThan>::iterator iter; |
366 |
> |
std::set<IntTuple4> allTorsions; |
367 |
> |
std::set<IntTuple4>::iterator iter; |
368 |
|
for(int i = 0; i < getNTorsions(); ++i) { |
369 |
|
TorsionStamp* torsionStamp= getTorsionStamp(i); |
370 |
|
std::vector<int> torsion = torsionStamp->getMembers(); |
508 |
|
// Function Name: isAtomInRigidBody |
509 |
|
//return false if atom does not belong to a rigid body, otherwise return true |
510 |
|
bool MoleculeStamp::isAtomInRigidBody(int atomIndex){ |
511 |
< |
int whichRigidBody; |
507 |
< |
int consAtomIndex; |
508 |
< |
|
509 |
< |
return isAtomInRigidBody(atomIndex, whichRigidBody, consAtomIndex); |
511 |
> |
return atom2Rigidbody[atomIndex] >=0 ; |
512 |
|
|
513 |
|
} |
514 |
|
|
519 |
|
//whichRigidBody: the index of rigidbody in component |
520 |
|
//consAtomIndex: the position of joint atom apears in rigidbody's definition |
521 |
|
bool MoleculeStamp::isAtomInRigidBody(int atomIndex, int& whichRigidBody, int& consAtomIndex){ |
520 |
– |
RigidBodyStamp* rbStamp; |
521 |
– |
int numRb; |
522 |
– |
int numAtom; |
522 |
|
|
523 |
+ |
|
524 |
+ |
|
525 |
|
whichRigidBody = -1; |
526 |
|
consAtomIndex = -1; |
527 |
|
|
528 |
< |
numRb = this->getNRigidBodies(); |
529 |
< |
|
530 |
< |
for(int i = 0 ; i < numRb; i++){ |
531 |
< |
rbStamp = this->getRigidBodyStamp(i); |
532 |
< |
numAtom = rbStamp->getNMembers(); |
532 |
< |
for(int j = 0; j < numAtom; j++) |
528 |
> |
if (atom2Rigidbody[atomIndex] >=0) { |
529 |
> |
whichRigidBody = atom2Rigidbody[atomIndex]; |
530 |
> |
RigidBodyStamp* rbStamp = getRigidBodyStamp(whichRigidBody); |
531 |
> |
int numAtom = rbStamp->getNMembers(); |
532 |
> |
for(int j = 0; j < numAtom; j++) { |
533 |
|
if (rbStamp->getMemberAt(j) == atomIndex){ |
534 |
– |
whichRigidBody = i; |
534 |
|
consAtomIndex = j; |
535 |
|
return true; |
536 |
|
} |
537 |
+ |
} |
538 |
|
} |
539 |
|
|
540 |
|
return false; |