| 1 | tim | 1159 | #ifndef _CUTOFFGROUP_H_ | 
| 2 |  |  | #define _CUTOFFGROUP_H_ | 
| 3 |  |  | #include "Atom.hpp" | 
| 4 |  |  |  | 
| 5 |  |  | class CutoffGroup{ | 
| 6 |  |  | public: | 
| 7 |  |  |  | 
| 8 |  |  | void addAtom(Atom* atom) {cutoffAtomList.push_back(atom);} | 
| 9 |  |  |  | 
| 10 |  |  | Atom* beginAtom(vector<Atom*>::iterator& i){ | 
| 11 |  |  | i = cutoffAtomList.begin(); | 
| 12 |  |  | return i != cutoffAtomList.end()? *i : NULL; | 
| 13 |  |  | } | 
| 14 |  |  |  | 
| 15 |  |  | Atom* nextAtom(vector<Atom*>::iterator& i){ | 
| 16 |  |  | i++; | 
| 17 |  |  | return i != cutoffAtomList.end()? *i : NULL; | 
| 18 |  |  | } | 
| 19 |  |  |  | 
| 20 |  |  | double getMass(){ | 
| 21 |  |  | vector<Atom*>::iterator i; | 
| 22 |  |  | Atom* atom; | 
| 23 |  |  | double totalMass; | 
| 24 |  |  | double mass; | 
| 25 |  |  |  | 
| 26 |  |  | totalMass = 0; | 
| 27 |  |  |  | 
| 28 |  |  | for(atom = beginAtom(i); atom != NULL; atom = nextAtom(i)){ | 
| 29 |  |  | mass = atom->getMass(); | 
| 30 |  |  | totalMass += mass; | 
| 31 |  |  | } | 
| 32 |  |  |  | 
| 33 |  |  | return totalMass; | 
| 34 |  |  | } | 
| 35 |  |  |  | 
| 36 |  |  | void getCOM(double com[3]){ | 
| 37 |  |  | vector<Atom*>::iterator i; | 
| 38 |  |  | Atom* atom; | 
| 39 |  |  | double pos[3]; | 
| 40 |  |  | double totalMass; | 
| 41 |  |  | double mass; | 
| 42 |  |  |  | 
| 43 |  |  | com[0] = 0; | 
| 44 |  |  | com[1] = 0; | 
| 45 |  |  | com[2] = 0; | 
| 46 |  |  | totalMass = 0; | 
| 47 |  |  |  | 
| 48 |  |  | for(atom = beginAtom(i); atom != NULL; atom = nextAtom(i)){ | 
| 49 |  |  | mass = atom->getMass(); | 
| 50 |  |  | totalMass += mass; | 
| 51 |  |  | atom->getPos(pos); | 
| 52 | tim | 1164 | com[0] += pos[0] * mass; | 
| 53 |  |  | com[1] += pos[1] * mass; | 
| 54 |  |  | com[2] += pos[2] * mass; | 
| 55 | tim | 1159 | } | 
| 56 |  |  |  | 
| 57 |  |  | com[0] /= totalMass; | 
| 58 |  |  | com[1] /= totalMass; | 
| 59 |  |  | com[2] /= totalMass; | 
| 60 |  |  |  | 
| 61 |  |  | } | 
| 62 |  |  |  | 
| 63 |  |  | int getNumAtom() {return cutoffAtomList.size();} | 
| 64 |  |  |  | 
| 65 |  |  | private: | 
| 66 |  |  | vector<Atom*> cutoffAtomList; | 
| 67 |  |  |  | 
| 68 |  |  | }; | 
| 69 |  |  |  | 
| 70 |  |  | #endif |