30 |
|
* @version 1.0 |
31 |
|
*/ |
32 |
|
|
33 |
– |
#include "primitives/Molecule.hpp" |
33 |
|
#include <algorithm> |
34 |
+ |
#include <set> |
35 |
|
|
36 |
+ |
#include "primitives/Molecule.hpp" |
37 |
+ |
#include "utils/MemoryUtils.hpp" |
38 |
+ |
|
39 |
|
namespace oopse { |
40 |
+ |
Molecule::Molecule(int stampId, int globalIndex, const std::string& molName) |
41 |
+ |
: stampId_(stampId), globalIndex_(globalIndex), moleculeName_(molName) { |
42 |
|
|
43 |
+ |
} |
44 |
+ |
|
45 |
|
Molecule::~Molecule() { |
46 |
|
|
47 |
< |
deleteVectorOfPointer(atoms_); |
48 |
< |
deleteVectorOfPointer(bonds_); |
49 |
< |
deleteVectorOfPointer(bends_); |
50 |
< |
deleteVectorOfPointer(torsions_); |
51 |
< |
deleteVectorOfPointer(rigidbodies_); |
52 |
< |
deleteVectorOfPointer(cutoffGroups_); |
47 |
> |
MemoryUtils::deleteVectorOfPointer(atoms_); |
48 |
> |
MemoryUtils::deleteVectorOfPointer(bonds_); |
49 |
> |
MemoryUtils::deleteVectorOfPointer(bends_); |
50 |
> |
MemoryUtils::deleteVectorOfPointer(torsions_); |
51 |
> |
MemoryUtils::deleteVectorOfPointer(rigidBodies_); |
52 |
> |
MemoryUtils::deleteVectorOfPointer(cutoffGroups_); |
53 |
|
|
54 |
+ |
//integrableObjects_ don't own the objects |
55 |
|
integrableObjects_.clear(); |
56 |
|
|
57 |
|
} |
58 |
|
|
59 |
|
void Molecule::addAtom(Atom* atom) { |
60 |
< |
if (atoms_.find(atom) == atoms_.end()) { |
60 |
> |
if (std::find(atoms_.begin(), atoms_.end(), atom) == atoms_.end()) { |
61 |
|
atoms_.push_back(atom); |
62 |
|
} |
63 |
|
} |
64 |
|
|
65 |
|
void Molecule::addBond(Bond* bond) { |
66 |
< |
if (bonds_.find(bond) == bonds_.end()) { |
66 |
> |
if (std::find(bonds_.begin(), bonds_.end(), bond) == bonds_.end()) { |
67 |
|
bonds_.push_back(bond); |
68 |
|
} |
69 |
|
} |
70 |
|
|
71 |
|
void Molecule::addBend(Bend* bend) { |
72 |
< |
if (bends_.find(bend) == bends_.end()) { |
72 |
> |
if (std::find(bends_.begin(), bends_.end(), bend) == bends_.end()) { |
73 |
|
bends_.push_back(bend); |
74 |
|
} |
75 |
|
} |
76 |
|
|
77 |
|
void Molecule::addTorsion(Torsion* torsion) { |
78 |
< |
if (torsions_.find(torsion) == torsions_.end()) { |
78 |
> |
if (std::find(torsions_.begin(), torsions_.end(), torsion) == torsions_.end()) { |
79 |
|
torsions_.push_back(torsion); |
80 |
|
} |
81 |
|
} |
82 |
|
|
83 |
|
void Molecule::addRigidBody(RigidBody *rb) { |
84 |
< |
if (rigidBodies_.find(bond) == bonds_.end()) { |
84 |
> |
if (std::find(rigidBodies_.begin(), rigidBodies_.end(), rb) == rigidBodies_.end()) { |
85 |
|
rigidBodies_.push_back(rb); |
86 |
|
} |
87 |
|
} |
88 |
|
|
89 |
|
void Molecule::addCutoffGroup(CutoffGroup* cp) { |
90 |
< |
if (cutoffGroups_.find(bond) == bonds_.end()) { |
90 |
> |
if (std::find(cutoffGroups_.begin(), cutoffGroups_.end(), cp) == cutoffGroups_.end()) { |
91 |
|
cutoffGroups_.push_back(cp); |
92 |
|
} |
93 |
|
|
100 |
|
|
101 |
|
std::set<Atom*> rigidAtoms; |
102 |
|
RigidBody* rb; |
103 |
< |
std::vector<RigidBody*> rbIter; |
103 |
> |
std::vector<RigidBody*>::iterator rbIter; |
104 |
|
|
105 |
|
|
106 |
|
for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) { |
107 |
< |
rigidAtoms.insert(rb->beginAtomIter(), rb->endAtomIter()); |
107 |
> |
rigidAtoms.insert(rb->getBeginAtomIter(), rb->getEndAtomIter()); |
108 |
|
} |
109 |
|
|
110 |
|
//find all free atoms (which do not belong to rigid bodies) |
112 |
|
//element that is contained in [allAtoms.begin(), allAtoms.end()) and not contained in |
113 |
|
//[rigidAtoms.begin(), rigidAtoms.end()). |
114 |
|
std::set_difference(allAtoms.begin(), allAtoms.end(), rigidAtoms.begin(), rigidAtoms.end(), |
115 |
< |
std::back_inserter(integrableObjects_)); |
115 |
> |
std::back_inserter(integrableObjects_.end())); |
116 |
|
|
117 |
|
if (integrableObjects_.size() != allAtoms.size() - rigidAtoms.size()) { |
118 |
|
//Some atoms in rigidAtoms are not in allAtoms, something must be wrong |
119 |
+ |
sprintf(painCave.errMsg, "Atoms in rigidbody are not in the atom list of the same molecule"); |
120 |
+ |
|
121 |
+ |
painCave.isFatal = 1; |
122 |
+ |
simError(); |
123 |
|
} |
124 |
|
|
125 |
|
integrableObjects_.insert(integrableObjects_.end(), rigidBodies_.begin(), rigidBodies_.end()); |
196 |
|
++i; |
197 |
|
return (i == cutoffGroups_.end()) ? NULL : *i; |
198 |
|
} |
187 |
– |
|
188 |
– |
void Molecule::calcForces() { |
189 |
– |
RigidBody* rb; |
190 |
– |
Bond* bond; |
191 |
– |
Bend* bend; |
192 |
– |
Torsion* torsion; |
193 |
– |
std::vector<RigidBody*> rbIter; |
194 |
– |
std::vector<Bond*> bondIter;; |
195 |
– |
std::vector<Bend*> bendIter; |
196 |
– |
std::vector<Torsion*> torsionIter; |
197 |
– |
|
198 |
– |
for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) { |
199 |
– |
rb->updateAtoms(); |
200 |
– |
} |
199 |
|
|
202 |
– |
for (bond = beginBond(bondIter); bond != NULL; bond = nextBond(bondIter)) { |
203 |
– |
bond->calcForce(); |
204 |
– |
} |
200 |
|
|
206 |
– |
for (bend = beginBend(bendIter); bend != NULL; bend = nextBend(bendIter)) { |
207 |
– |
bend->calcForce(); |
208 |
– |
} |
209 |
– |
|
210 |
– |
for (torsion = beginTorsion(torsionIter); torsion != NULL; torsion = nextTorsion(torsionIter)) { |
211 |
– |
torsion->calcForce(); |
212 |
– |
} |
213 |
– |
|
214 |
– |
} |
215 |
– |
|
216 |
– |
double Molecule::getPotential() { |
217 |
– |
//RigidBody* rb; |
218 |
– |
Bond* bond; |
219 |
– |
Bend* bend; |
220 |
– |
Torsion* torsion; |
221 |
– |
//std::vector<RigidBody*> rbIter; |
222 |
– |
std::vector<Bond*> bondIter;; |
223 |
– |
std::vector<Bend*> bendIter; |
224 |
– |
std::vector<Torsion*> torsionIter; |
225 |
– |
|
226 |
– |
double potential = 0; |
227 |
– |
|
228 |
– |
//for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) { |
229 |
– |
// rb->updateAtoms(); |
230 |
– |
//} |
231 |
– |
|
232 |
– |
for (bond = beginBond(bondIter); bond != NULL; bond = nextBond(bondIter)) { |
233 |
– |
potential += bond->getPotential(); |
234 |
– |
} |
235 |
– |
|
236 |
– |
for (bend = beginBend(bendIter); bend != NULL; bend = nextBend(bendIter)) { |
237 |
– |
potential += bend->getPotential(); |
238 |
– |
} |
239 |
– |
|
240 |
– |
for (torsion = beginTorsion(torsionIter); torsion != NULL; torsion = nextTorsion(torsionIter)) { |
241 |
– |
potential += torsion->getPotential(); |
242 |
– |
} |
243 |
– |
|
244 |
– |
return potential; |
245 |
– |
} |
246 |
– |
|
201 |
|
Vector3d Molecule::getCom() { |
202 |
|
StuntDouble* sd; |
203 |
|
std::vector<StuntDouble*>::iterator i; |
216 |
|
return com; |
217 |
|
} |
218 |
|
|
219 |
< |
void Molecule::moveCom(const Vetor3d& delta) { |
219 |
> |
void Molecule::moveCom(const Vector3d& delta) { |
220 |
|
StuntDouble* sd; |
221 |
|
std::vector<StuntDouble*>::iterator i; |
222 |
|
|
223 |
|
for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){ |
224 |
< |
s->setPos(sd->getPos() + delta); |
224 |
> |
sd->setPos(sd->getPos() + delta); |
225 |
|
} |
226 |
|
|
227 |
|
} |
244 |
|
return velCom; |
245 |
|
} |
246 |
|
|
247 |
< |
std::ostream& operator <<(std::ostream& o, const Molecule& mol) { |
247 |
> |
std::ostream& operator <<(std::ostream& o, Molecule& mol) { |
248 |
|
o << std::endl; |
249 |
|
o << "Molecule " << mol.getGlobalIndex() << "has: " << std::endl; |
250 |
|
o << mol.getNAtoms() << " atoms" << std::endl; |