ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/types/MoleculeStamp.cpp
(Generate patch)

Comparing trunk/OOPSE-3.0/src/types/MoleculeStamp.cpp (file contents):
Revision 2483 by tim, Mon Dec 5 18:23:30 2005 UTC vs.
Revision 2515 by tim, Fri Dec 16 18:26:41 2005 UTC

# Line 38 | Line 38
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 <
47 > #include "utils/MemoryUtils.hpp"
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      
# Line 58 | Line 77 | MoleculeStamp::~MoleculeStamp() {
77   }
78  
79   MoleculeStamp::~MoleculeStamp() {
80 <
80 >    MemoryUtils::deletePointers(atomStamps_);
81 >    MemoryUtils::deletePointers(bondStamps_);
82 >    MemoryUtils::deletePointers(bendStamps_);
83 >    MemoryUtils::deletePointers(torsionStamps_);
84 >    MemoryUtils::deletePointers(rigidBodyStamps_);
85 >    MemoryUtils::deletePointers(cutoffGroupStamps_);
86 >    MemoryUtils::deletePointers(fragmentStamps_);    
87   }
88  
89   bool MoleculeStamp::addAtomStamp( AtomStamp* atom) {
90      bool ret = addIndexSensitiveStamp(atomStamps_, atom);
91      if (!ret) {
92 <        std::cout << "multiple atoms have the same index: " << atom->getIndex() <<" in " << getName()  << " Molecule\n";
92 >         std::cout<< "Error in Molecule " << getName()  << ": multiple atoms have the same indices"<< atom->getIndex() <<"\n";
93      }
94      return ret;
95      
# Line 88 | Line 113 | bool MoleculeStamp::addRigidBodyStamp( RigidBodyStamp*
113   bool MoleculeStamp::addRigidBodyStamp( RigidBodyStamp* rigidbody) {
114      bool ret = addIndexSensitiveStamp(rigidBodyStamps_, rigidbody);
115      if (!ret) {
116 <        std::cout << "multiple rigidbodies have the same index: " << rigidbody->getIndex() <<" in " << getName()  << " Molecule\n";
116 >        std::cout<< "Error in Molecule " << getName()  << ": multiple rigidbodies have the same indices: " << rigidbody->getIndex() <<"\n";
117      }
118      return ret;
119   }
# Line 143 | Line 168 | void MoleculeStamp::checkAtoms() {
168          std::cout << "Error in Molecule " << getName() << ": atom[" << ai - atomStamps_.begin()<< "] is missing\n";
169      }
170  
171 + }
172 +
173 + void MoleculeStamp::checkBonds() {
174      //make sure index is not out of range
175      int natoms = getNAtoms();
176      for(int i = 0; i < getNBonds(); ++i) {
177          BondStamp* bondStamp = getBondStamp(i);
178          if (bondStamp->getA() >=  natoms && bondStamp->getB() >= natoms) {
179 <            std::cout << "Error in Molecule " << getName() <<  ": bond between " << bondStamp->getA() << " and " << bondStamp->getB() << " is invalid\n";
179 >            std::cout << "Error in Molecule " << getName() <<  ": bond(" << bondStamp->getA() << ", " << bondStamp->getB() << ") is invalid\n";
180          }
181      }
182 < }
155 <
156 < void MoleculeStamp::checkBonds() {
182 >    
183      //make sure bonds are unique
184      std::set<std::pair<int, int> > allBonds;
185      for(int i = 0; i < getNBonds(); ++i) {
# Line 166 | Line 192 | void MoleculeStamp::checkBonds() {
192          
193          std::set<std::pair<int, int> >::iterator iter = allBonds.find(bondPair);
194          if ( iter != allBonds.end()) {
195 <            std::cout << "Error in Molecule " << getName() << ": " << "Bond appears multiple times\n";
195 >            std::cout << "Error in Molecule " << getName() << ": " << "bond(" <<iter->first << ", "<< iter->second << ")appears multiple times\n";
196          } else {
197              allBonds.insert(bondPair);
198          }
# Line 176 | Line 202 | void MoleculeStamp::checkBonds() {
202      for(int i = 0; i < getNBonds(); ++i) {
203          BondStamp* bondStamp = getBondStamp(i);
204          if (atom2Rigidbody[bondStamp->getA()] == atom2Rigidbody[bondStamp->getB()]) {
205 <            std::cout << "Error in Molecule " << getName() << ": "<<"bond between " << bondStamp->getA() << " and " << bondStamp->getB() << " belong to same rigidbody " << atom2Rigidbody[bondStamp->getA()] << "\n";
205 >            std::cout << "Error in Molecule " << getName() << ": "<<"bond(" << bondStamp->getA() << ", " << bondStamp->getB() << ") belong to same rigidbody " << atom2Rigidbody[bondStamp->getA()] << "\n";
206          }
207      }
208      
209   }
210  
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
211   void MoleculeStamp::checkBends() {
212      for(int i = 0; i < getNBends(); ++i) {
213          BendStamp* bendStamp = getBendStamp(i);
214          std::vector<int> bendAtoms =  bendStamp->getMembers();
215          std::vector<int>::iterator j =std::find_if(bendAtoms.begin(), bendAtoms.end(), std::bind2nd(std::greater<int>(), getNAtoms()-1));
216          if (j != bendAtoms.end()) {
217 <            std::cout << "Error in Molecule " << getName();
217 >            std::cout << "Error in Molecule " << getName() << " : atoms of bend" << containerToString(bendAtoms) << "have invalid indices\n";
218          }
219  
220          if (bendAtoms.size() == 2 ) {
# Line 230 | Line 248 | void MoleculeStamp::checkBends() {
248              if (rigidbodyIndex >= 0) {
249                  ++rigidSet[rigidbodyIndex];
250                  if (rigidSet[rigidbodyIndex] > 1) {
251 <                    std::cout << "Error in Molecule " << getName() << ": ";
234 <                    //std::cout << "atoms of bend " <<  << "belong to same rigidbody " << rigidbodyIndex << "\n";                    
251 >                    std::cout << "Error in Molecule " << getName() << ": bend" << containerToString(bendAtoms) << " belong to same rigidbody " << rigidbodyIndex << "\n";                    
252                  }
253              }
254          }
255      }
256      
257      
258 <    std::set<IntTuple3, BendLessThan> allBends;
259 <    std::set<IntTuple3, BendLessThan>::iterator iter;
258 >    std::set<IntTuple3> allBends;
259 >    std::set<IntTuple3>::iterator iter;
260      for(int i = 0; i < getNBends(); ++i) {
261          BendStamp* bendStamp= getBendStamp(i);
262          std::vector<int> bend = bendStamp->getMembers();
# Line 326 | Line 343 | struct TorsionLessThan : public std::binary_function<I
343  
344   }
345  
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
346   void MoleculeStamp::checkTorsions() {
347      for(int i = 0; i < getNTorsions(); ++i) {
348          TorsionStamp* torsionStamp = getTorsionStamp(i);
349 +        std::vector<int> torsionAtoms =  torsionStamp ->getMembers();
350 +        std::vector<int>::iterator j =std::find_if(torsionAtoms.begin(), torsionAtoms.end(), std::bind2nd(std::greater<int>(), getNAtoms()-1));
351 +        if (j != torsionAtoms.end()) {
352 +            std::cout << "Error in Molecule " << getName() << ": atoms of torsion" << containerToString(torsionAtoms) << " have invalid indices\n";
353 +        }
354 +    }
355 +    
356 +    for(int i = 0; i < getNTorsions(); ++i) {
357 +        TorsionStamp* torsionStamp = getTorsionStamp(i);
358          std::vector<int> torsionAtoms =  torsionStamp->getMembers();
359          std::vector<int> rigidSet(getNRigidBodies(), 0);
360          std::vector<int>::iterator j;
# Line 351 | Line 363 | void MoleculeStamp::checkTorsions() {
363              if (rigidbodyIndex >= 0) {
364                  ++rigidSet[rigidbodyIndex];
365                  if (rigidSet[rigidbodyIndex] > 1) {
366 <                    std::cout << "Error in Molecule " << getName() << ": ";
355 <                    //std::cout << "atoms of torsion " <<  << "belong to same rigidbody " << rigidbodyIndex << "\n";                    
366 >                    std::cout << "Error in Molecule " << getName() << ": torsion" << containerToString(torsionAtoms) << "is invalid\n";                  
367                  }
368              }
369          }
370      }    
371  
372 <    std::set<IntTuple4, TorsionLessThan> allTorsions;
373 <    std::set<IntTuple4, TorsionLessThan>::iterator iter;
372 >    std::set<IntTuple4> allTorsions;
373 >    std::set<IntTuple4>::iterator iter;
374       for(int i = 0; i < getNTorsions(); ++i) {
375           TorsionStamp* torsionStamp= getTorsionStamp(i);
376           std::vector<int> torsion = torsionStamp->getMembers();
# Line 503 | Line 514 | bool MoleculeStamp::isAtomInRigidBody(int atomIndex){
514   // Function Name: isAtomInRigidBody
515   //return false if atom does not belong to a rigid body, otherwise return true
516   bool MoleculeStamp::isAtomInRigidBody(int atomIndex){
517 <  int whichRigidBody;
507 <  int consAtomIndex;
508 <
509 <  return isAtomInRigidBody(atomIndex, whichRigidBody, consAtomIndex);
517 >  return atom2Rigidbody[atomIndex] >=0 ;
518    
519   }
520  
# Line 517 | Line 525 | bool MoleculeStamp::isAtomInRigidBody(int atomIndex, i
525   //whichRigidBody: the index of rigidbody in component
526   //consAtomIndex:  the position of joint atom apears in  rigidbody's definition
527   bool MoleculeStamp::isAtomInRigidBody(int atomIndex, int& whichRigidBody, int& consAtomIndex){
520  RigidBodyStamp* rbStamp;
521  int numRb;
522  int numAtom;
528  
529 +  
530 +
531    whichRigidBody = -1;
532    consAtomIndex = -1;
533  
534 <  numRb = this->getNRigidBodies();
535 <  
536 <  for(int i = 0 ; i < numRb; i++){
537 <    rbStamp = this->getRigidBodyStamp(i);
538 <    numAtom = rbStamp->getNMembers();
532 <    for(int j = 0; j < numAtom; j++)
534 >  if (atom2Rigidbody[atomIndex] >=0) {
535 >    whichRigidBody = atom2Rigidbody[atomIndex];
536 >    RigidBodyStamp* rbStamp = getRigidBodyStamp(whichRigidBody);
537 >    int numAtom = rbStamp->getNMembers();
538 >    for(int j = 0; j < numAtom; j++) {
539        if (rbStamp->getMemberAt(j) == atomIndex){
534        whichRigidBody = i;
540          consAtomIndex = j;
541          return true;
542        }
543 +    }
544    }
545  
546    return false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines