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

Comparing trunk/OOPSE-4/src/types/MoleculeStamp.cpp (file contents):
Revision 2484 by tim, Mon Dec 5 18:23:30 2005 UTC vs.
Revision 2485 by tim, Mon Dec 5 19:10:58 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  
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 64 | Line 83 | bool MoleculeStamp::addAtomStamp( AtomStamp* atom) {
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      
# Line 88 | Line 107 | bool MoleculeStamp::addRigidBodyStamp( RigidBodyStamp*
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   }
# Line 143 | Line 162 | void MoleculeStamp::checkAtoms() {
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) {
# Line 166 | Line 186 | void MoleculeStamp::checkBonds() {
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          }
# Line 176 | Line 196 | void MoleculeStamp::checkBonds() {
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      
# Line 196 | Line 216 | void MoleculeStamp::checkBends() {
216          std::vector<int> bendAtoms =  bendStamp->getMembers();
217          std::vector<int>::iterator j =std::find_if(bendAtoms.begin(), bendAtoms.end(), std::bind2nd(std::greater<int>(), getNAtoms()-1));
218          if (j != bendAtoms.end()) {
219 <            std::cout << "Error in Molecule " << getName();
219 >            std::cout << "Error in Molecule " << getName() << " : atoms of bend" << containerToString(bendAtoms) << "have invalid indices\n";
220          }
221  
222          if (bendAtoms.size() == 2 ) {
# Line 230 | Line 250 | void MoleculeStamp::checkBends() {
250              if (rigidbodyIndex >= 0) {
251                  ++rigidSet[rigidbodyIndex];
252                  if (rigidSet[rigidbodyIndex] > 1) {
253 <                    std::cout << "Error in Molecule " << getName() << ": ";
234 <                    //std::cout << "atoms of bend " <<  << "belong to same rigidbody " << rigidbodyIndex << "\n";                    
253 >                    std::cout << "Error in Molecule " << getName() << ": bend" << containerToString(bendAtoms) << " belong to same rigidbody " << rigidbodyIndex << "\n";                    
254                  }
255              }
256          }
# Line 341 | Line 360 | void MoleculeStamp::checkTorsions() {
360  
361  
362   void MoleculeStamp::checkTorsions() {
363 +    for(int i = 0; i < getNBends(); ++i) {
364 +        TorsionStamp* torsionStamp = getTorsionStamp(i);
365 +        std::vector<int> torsionAtoms =  torsionStamp ->getMembers();
366 +        std::vector<int>::iterator j =std::find_if(torsionAtoms.begin(), torsionAtoms.end(), std::bind2nd(std::greater<int>(), getNAtoms()-1));
367 +        if (j != torsionAtoms.end()) {
368 +            std::cout << "Error in Molecule " << getName() << ": atoms of torsion" << containerToString(torsionAtoms) << " have invalid indices\n";
369 +        }
370 +    }
371 +    
372      for(int i = 0; i < getNTorsions(); ++i) {
373          TorsionStamp* torsionStamp = getTorsionStamp(i);
374          std::vector<int> torsionAtoms =  torsionStamp->getMembers();
# Line 351 | Line 379 | void MoleculeStamp::checkTorsions() {
379              if (rigidbodyIndex >= 0) {
380                  ++rigidSet[rigidbodyIndex];
381                  if (rigidSet[rigidbodyIndex] > 1) {
382 <                    std::cout << "Error in Molecule " << getName() << ": ";
355 <                    //std::cout << "atoms of torsion " <<  << "belong to same rigidbody " << rigidbodyIndex << "\n";                    
382 >                    std::cout << "Error in Molecule " << getName() << ": torsion" << containerToString(torsionAtoms) << "is invalid\n";                  
383                  }
384              }
385          }
# Line 503 | Line 530 | bool MoleculeStamp::isAtomInRigidBody(int atomIndex){
530   // Function Name: isAtomInRigidBody
531   //return false if atom does not belong to a rigid body, otherwise return true
532   bool MoleculeStamp::isAtomInRigidBody(int atomIndex){
533 <  int whichRigidBody;
507 <  int consAtomIndex;
508 <
509 <  return isAtomInRigidBody(atomIndex, whichRigidBody, consAtomIndex);
533 >  return atom2Rigidbody[atomIndex] >=0 ;
534    
535   }
536  
# Line 517 | Line 541 | bool MoleculeStamp::isAtomInRigidBody(int atomIndex, i
541   //whichRigidBody: the index of rigidbody in component
542   //consAtomIndex:  the position of joint atom apears in  rigidbody's definition
543   bool MoleculeStamp::isAtomInRigidBody(int atomIndex, int& whichRigidBody, int& consAtomIndex){
520  RigidBodyStamp* rbStamp;
521  int numRb;
522  int numAtom;
544  
545 +  
546 +
547    whichRigidBody = -1;
548    consAtomIndex = -1;
549  
550 <  numRb = this->getNRigidBodies();
551 <  
552 <  for(int i = 0 ; i < numRb; i++){
553 <    rbStamp = this->getRigidBodyStamp(i);
554 <    numAtom = rbStamp->getNMembers();
532 <    for(int j = 0; j < numAtom; j++)
550 >  if (atom2Rigidbody[atomIndex] >=0) {
551 >    whichRigidBody = atom2Rigidbody[atomIndex];
552 >    RigidBodyStamp* rbStamp = getRigidBodyStamp(whichRigidBody);
553 >    int numAtom = rbStamp->getNMembers();
554 >    for(int j = 0; j < numAtom; j++) {
555        if (rbStamp->getMemberAt(j) == atomIndex){
534        whichRigidBody = i;
556          consAtomIndex = j;
557          return true;
558        }
559 +    }
560    }
561  
562    return false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines