1 |
tim |
1734 |
#ifndef PRIMITIVES_CUTOFFGROUP_HPP |
2 |
|
|
|
3 |
|
|
#define PRIMITIVES_CUTOFFGROUP_HPP |
4 |
|
|
|
5 |
|
|
#include "primitives/Atom.hpp" |
6 |
|
|
#include "math/Vector3.hpp" |
7 |
|
|
|
8 |
|
|
namespace oopse { |
9 |
|
|
class CutoffGroup { |
10 |
|
|
public: |
11 |
|
|
|
12 |
|
|
CutoffGroup() { |
13 |
|
|
haveTotalMass = false; |
14 |
|
|
totalMass = 0.0; |
15 |
|
|
} |
16 |
|
|
|
17 |
|
|
void addAtom(Atom *atom) { |
18 |
|
|
cutoffAtomList.push_back(atom); |
19 |
|
|
} |
20 |
|
|
|
21 |
|
|
Atom *beginAtom(std::vector<Atom *>::iterator & i) { |
22 |
|
|
i = cutoffAtomList.begin(); |
23 |
|
|
return i != cutoffAtomList.end() ? *i : NULL; |
24 |
|
|
} |
25 |
|
|
|
26 |
|
|
Atom *nextAtom(std::vector<Atom *>::iterator & i) { |
27 |
|
|
i++; |
28 |
|
|
return i != cutoffAtomList.end() ? *i : NULL; |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
double getMass() { |
32 |
|
|
std::vector<Atom *>::iterator i; |
33 |
|
|
Atom * atom; |
34 |
|
|
double mass; |
35 |
|
|
|
36 |
|
|
if (!haveTotalMass) { |
37 |
|
|
totalMass = 0; |
38 |
|
|
|
39 |
|
|
for(atom = beginAtom(i); atom != NULL; atom = nextAtom(i)) { |
40 |
|
|
mass = atom->getMass(); |
41 |
|
|
totalMass += mass; |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
haveTotalMass = true; |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
return totalMass; |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
void getCOM(Vector3d & com) { |
51 |
|
|
std::vector<Atom *>::iterator i; |
52 |
|
|
Atom * atom; |
53 |
|
|
Vector3d pos; |
54 |
|
|
double mass; |
55 |
|
|
|
56 |
|
|
com[0] = 0; |
57 |
|
|
com[1] = 0; |
58 |
|
|
com[2] = 0; |
59 |
|
|
totalMass = getMass(); |
60 |
|
|
|
61 |
|
|
if (cutoffAtomList.size() == 1) { |
62 |
|
|
com = beginAtom(i)->getPos(); |
63 |
|
|
} else { |
64 |
|
|
for(atom = beginAtom(i); atom != NULL; atom = nextAtom(i)) { |
65 |
|
|
mass = atom->getMass(); |
66 |
|
|
pos = atom->getPos(); |
67 |
|
|
com += pos * mass; |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
com /= totalMass; |
71 |
|
|
} |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
int getNumAtom() { |
75 |
|
|
return cutoffAtomList.size(); |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
int getGlobalIndex() { |
79 |
|
|
return globalIndex; |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
void setGlobalIndex(int id) { |
83 |
|
|
this->globalIndex = id; |
84 |
|
|
} |
85 |
|
|
|
86 |
|
|
private: |
87 |
|
|
|
88 |
|
|
std::vector<Atom *>cutoffAtomList; |
89 |
|
|
bool haveTotalMass; |
90 |
|
|
double totalMass; |
91 |
|
|
int globalIndex; |
92 |
|
|
}; |
93 |
|
|
|
94 |
|
|
} //end namespace oopse |
95 |
|
|
|
96 |
|
|
#endif //PRIMITIVES_CUTOFFGROUP_HPP |