1 |
#include <stdlib.h> |
2 |
|
3 |
|
4 |
#include "Molecule.hpp" |
5 |
#include "simError.h" |
6 |
|
7 |
|
8 |
|
9 |
Molecule::Molecule( void ){ |
10 |
|
11 |
myAtoms = NULL; |
12 |
myBonds = NULL; |
13 |
myBends = NULL; |
14 |
myTorsions = NULL; |
15 |
|
16 |
} |
17 |
|
18 |
Molecule::~Molecule( void ){ |
19 |
int i; |
20 |
|
21 |
if( myAtoms != NULL ){ |
22 |
for(i=0; i<nAtoms; i++) if(myAtoms[i] != NULL ) delete myAtoms[i]; |
23 |
delete[] myAtoms; |
24 |
} |
25 |
|
26 |
if( myBonds != NULL ){ |
27 |
for(i=0; i<nBonds; i++) if(myBonds[i] != NULL ) delete myBonds[i]; |
28 |
delete[] myBonds; |
29 |
} |
30 |
|
31 |
if( myBends != NULL ){ |
32 |
for(i=0; i<nBends; i++) if(myBends[i] != NULL ) delete myBends[i]; |
33 |
delete[] myBends; |
34 |
} |
35 |
|
36 |
if( myTorsions != NULL ){ |
37 |
for(i=0; i<nTorsions; i++) if(myTorsions[i] != NULL ) delete myTorsions[i]; |
38 |
delete[] myTorsions; |
39 |
} |
40 |
|
41 |
} |
42 |
|
43 |
|
44 |
void Molecule::initialize( molInit &theInit ){ |
45 |
|
46 |
nAtoms = theInit.nAtoms; |
47 |
nMembers = nAtoms; |
48 |
nBonds = theInit.nBonds; |
49 |
nBends = theInit.nBends; |
50 |
nTorsions = theInit.nTorsions; |
51 |
nRigidBodies = theInit.nRigidBodies; |
52 |
nOriented = theInit.nOriented; |
53 |
|
54 |
myAtoms = theInit.myAtoms; |
55 |
myBonds = theInit.myBonds; |
56 |
myBends = theInit.myBends; |
57 |
myTorsions = theInit.myTorsions; |
58 |
myRigidBodies = theInit.myRigidBodies; |
59 |
|
60 |
myIntegrableObjects = theInit.myIntegrableObjects; |
61 |
|
62 |
for (int i = 0; i < myRigidBodies.size(); i++) |
63 |
myRigidBodies[i]->calcRefCoords(); |
64 |
|
65 |
} |
66 |
|
67 |
void Molecule::calcForces( void ){ |
68 |
|
69 |
int i; |
70 |
|
71 |
for(i=0; i<myRigidBodies.size(); i++) { |
72 |
myRigidBodies[i]->updateAtoms(); |
73 |
} |
74 |
|
75 |
for(i=0; i<nBonds; i++){ |
76 |
myBonds[i]->calc_forces(); |
77 |
} |
78 |
|
79 |
for(i=0; i<nBends; i++){ |
80 |
myBends[i]->calc_forces(); |
81 |
} |
82 |
|
83 |
for(i=0; i<nTorsions; i++){ |
84 |
myTorsions[i]->calc_forces(); |
85 |
} |
86 |
|
87 |
// Rigid Body forces and torques are done after the fortran force loop |
88 |
|
89 |
} |
90 |
|
91 |
|
92 |
double Molecule::getPotential( void ){ |
93 |
|
94 |
int i; |
95 |
double myPot = 0.0; |
96 |
|
97 |
for(i=0; i<myRigidBodies.size(); i++) { |
98 |
myRigidBodies[i]->updateAtoms(); |
99 |
} |
100 |
|
101 |
for(i=0; i<nBonds; i++){ |
102 |
myPot += myBonds[i]->get_potential(); |
103 |
} |
104 |
|
105 |
for(i=0; i<nBends; i++){ |
106 |
myPot += myBends[i]->get_potential(); |
107 |
} |
108 |
|
109 |
for(i=0; i<nTorsions; i++){ |
110 |
myPot += myTorsions[i]->get_potential(); |
111 |
} |
112 |
|
113 |
return myPot; |
114 |
} |
115 |
|
116 |
void Molecule::printMe( void ){ |
117 |
|
118 |
int i; |
119 |
|
120 |
for(i=0; i<nBonds; i++){ |
121 |
myBonds[i]->printMe(); |
122 |
} |
123 |
|
124 |
for(i=0; i<nBends; i++){ |
125 |
myBends[i]->printMe(); |
126 |
} |
127 |
|
128 |
for(i=0; i<nTorsions; i++){ |
129 |
myTorsions[i]->printMe(); |
130 |
} |
131 |
|
132 |
} |
133 |
|
134 |
void Molecule::moveCOM(double delta[3]){ |
135 |
double aPos[3]; |
136 |
int i, j; |
137 |
|
138 |
for(i=0; i<myIntegrableObjects.size(); i++) { |
139 |
if(myIntegrableObjects[i] != NULL ) { |
140 |
|
141 |
myIntegrableObjects[i]->getPos( aPos ); |
142 |
|
143 |
for (j=0; j< 3; j++) |
144 |
aPos[j] += delta[j]; |
145 |
|
146 |
myIntegrableObjects[i]->setPos( aPos ); |
147 |
} |
148 |
} |
149 |
|
150 |
for(i=0; i<myRigidBodies.size(); i++) { |
151 |
|
152 |
myRigidBodies[i]->getPos( aPos ); |
153 |
|
154 |
for (j=0; j< 3; j++) |
155 |
aPos[j] += delta[j]; |
156 |
|
157 |
myRigidBodies[i]->setPos( aPos ); |
158 |
} |
159 |
} |
160 |
|
161 |
void Molecule::atoms2rigidBodies( void ) { |
162 |
int i; |
163 |
for (i = 0; i < myRigidBodies.size(); i++) { |
164 |
myRigidBodies[i]->calcForcesAndTorques(); |
165 |
} |
166 |
} |
167 |
|
168 |
void Molecule::getCOM( double COM[3] ) { |
169 |
|
170 |
double mass, mtot; |
171 |
double aPos[3]; |
172 |
int i, j; |
173 |
|
174 |
for (j=0; j<3; j++) |
175 |
COM[j] = 0.0; |
176 |
|
177 |
mtot = 0.0; |
178 |
|
179 |
for (i=0; i < myIntegrableObjects.size(); i++) { |
180 |
if (myIntegrableObjects[i] != NULL) { |
181 |
|
182 |
mass = myIntegrableObjects[i]->getMass(); |
183 |
mtot += mass; |
184 |
|
185 |
myIntegrableObjects[i]->getPos( aPos ); |
186 |
|
187 |
for( j = 0; j < 3; j++) |
188 |
COM[j] += aPos[j] * mass; |
189 |
|
190 |
} |
191 |
} |
192 |
|
193 |
for (j = 0; j < 3; j++) |
194 |
COM[j] /= mtot; |
195 |
} |
196 |
|
197 |
double Molecule::getCOMvel( double COMvel[3] ) { |
198 |
|
199 |
double mass, mtot; |
200 |
double aVel[3]; |
201 |
int i, j; |
202 |
|
203 |
|
204 |
for (j=0; j<3; j++) |
205 |
COMvel[j] = 0.0; |
206 |
|
207 |
mtot = 0.0; |
208 |
|
209 |
for (i=0; i < myIntegrableObjects.size(); i++) { |
210 |
if (myIntegrableObjects[i] != NULL) { |
211 |
|
212 |
mass = myIntegrableObjects[i]->getMass(); |
213 |
mtot += mass; |
214 |
|
215 |
myIntegrableObjects[i]->getVel(aVel); |
216 |
|
217 |
for (j=0; j<3; j++) |
218 |
COMvel[j] += aVel[j]*mass; |
219 |
|
220 |
} |
221 |
} |
222 |
|
223 |
for (j=0; j<3; j++) |
224 |
COMvel[j] /= mtot; |
225 |
|
226 |
return mtot; |
227 |
|
228 |
} |
229 |
|
230 |
double Molecule::getTotalMass() |
231 |
{ |
232 |
|
233 |
double totalMass; |
234 |
|
235 |
totalMass = 0; |
236 |
for(int i =0; i < myIntegrableObjects.size(); i++){ |
237 |
totalMass += myIntegrableObjects[i]->getMass(); |
238 |
} |
239 |
|
240 |
return totalMass; |
241 |
} |