1 |
#include <cstdlib> |
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 |
|
19 |
|
20 |
Molecule::~Molecule( void ){ |
21 |
int i; |
22 |
|
23 |
if( myAtoms != NULL ){ |
24 |
for(i=0; i<nAtoms; i++) if(myAtoms[i] != NULL ) delete myAtoms[i]; |
25 |
delete[] myAtoms; |
26 |
} |
27 |
|
28 |
if( myBonds != NULL ){ |
29 |
for(i=0; i<nBonds; i++) if(myBonds[i] != NULL ) delete myBonds[i]; |
30 |
delete[] myBonds; |
31 |
} |
32 |
|
33 |
if( myBends != NULL ){ |
34 |
for(i=0; i<nBends; i++) if(myBends[i] != NULL ) delete myBends[i]; |
35 |
delete[] myBends; |
36 |
} |
37 |
|
38 |
if( myTorsions != NULL ){ |
39 |
for(i=0; i<nTorsions; i++) if(myTorsions[i] != NULL ) delete myTorsions[i]; |
40 |
delete[] myTorsions; |
41 |
} |
42 |
|
43 |
if( myExcludes != NULL ){ |
44 |
for(i=0; i<nExcludes; i++) if(myExcludes[i] != NULL ) delete myExcludes[i]; |
45 |
delete[] myExcludes; |
46 |
} |
47 |
} |
48 |
|
49 |
|
50 |
void Molecule::initialize( molInit &theInit ){ |
51 |
|
52 |
nAtoms = theInit.nAtoms; |
53 |
nMembers = nAtoms; |
54 |
nBonds = theInit.nBonds; |
55 |
nBends = theInit.nBends; |
56 |
nTorsions = theInit.nTorsions; |
57 |
nExcludes = theInit.nExcludes; |
58 |
nOriented = theInit.nOriented; |
59 |
|
60 |
myAtoms = theInit.myAtoms; |
61 |
myBonds = theInit.myBonds; |
62 |
myBends = theInit.myBends; |
63 |
myTorsions = theInit.myTorsions; |
64 |
myExcludes = theInit.myExcludes; |
65 |
|
66 |
} |
67 |
|
68 |
void Molecule::calcForces( void ){ |
69 |
|
70 |
int i; |
71 |
|
72 |
for(i=0; i<nBonds; i++){ |
73 |
myBonds[i]->calc_forces(); |
74 |
} |
75 |
|
76 |
for(i=0; i<nBends; i++){ |
77 |
myBends[i]->calc_forces(); |
78 |
} |
79 |
|
80 |
for(i=0; i<nTorsions; i++){ |
81 |
myTorsions[i]->calc_forces(); |
82 |
} |
83 |
} |
84 |
|
85 |
|
86 |
double Molecule::getPotential( void ){ |
87 |
|
88 |
int i; |
89 |
double myPot = 0.0; |
90 |
|
91 |
for(i=0; i<nBonds; i++){ |
92 |
myPot += myBonds[i]->get_potential(); |
93 |
} |
94 |
|
95 |
for(i=0; i<nBends; i++){ |
96 |
myPot += myBends[i]->get_potential(); |
97 |
} |
98 |
|
99 |
for(i=0; i<nTorsions; i++){ |
100 |
myPot += myTorsions[i]->get_potential(); |
101 |
} |
102 |
|
103 |
return myPot; |
104 |
} |
105 |
|
106 |
void Molecule::printMe( void ){ |
107 |
|
108 |
int i; |
109 |
|
110 |
for(i=0; i<nBonds; i++){ |
111 |
myBonds[i]->printMe(); |
112 |
} |
113 |
|
114 |
for(i=0; i<nBends; i++){ |
115 |
myBends[i]->printMe(); |
116 |
} |
117 |
|
118 |
for(i=0; i<nTorsions; i++){ |
119 |
myTorsions[i]->printMe(); |
120 |
} |
121 |
} |
122 |
|
123 |
void Molecule::moveCOM(double delta[3]){ |
124 |
double aPos[3]; |
125 |
int i, j; |
126 |
|
127 |
for(i=0; i<nAtoms; i++) { |
128 |
if(myAtoms[i] != NULL ) { |
129 |
|
130 |
myAtoms[i]->getPos( aPos ); |
131 |
|
132 |
for (j=0; j< 3; j++) |
133 |
aPos[j] += delta[j]; |
134 |
|
135 |
myAtoms[i]->setPos( aPos ); |
136 |
} |
137 |
} |
138 |
} |
139 |
|
140 |
void Molecule::getCOM( double COM[3] ) { |
141 |
|
142 |
double mass, mtot; |
143 |
double aPos[3]; |
144 |
int i, j; |
145 |
|
146 |
for (j=0; j<3; j++) |
147 |
COM[j] = 0.0; |
148 |
|
149 |
mtot = 0.0; |
150 |
|
151 |
for (i=0; i < nAtoms; i++) { |
152 |
if (myAtoms[i] != NULL) { |
153 |
|
154 |
mass = myAtoms[i]->getMass(); |
155 |
mtot += mass; |
156 |
|
157 |
myAtoms[i]->getPos( aPos ); |
158 |
|
159 |
for( j = 0; j < 3; j++) |
160 |
COM[j] += aPos[j] * mass; |
161 |
|
162 |
} |
163 |
} |
164 |
|
165 |
for (j = 0; j < 3; j++) |
166 |
COM[j] /= mtot; |
167 |
} |
168 |
|
169 |
double Molecule::getCOMvel( double COMvel[3] ) { |
170 |
|
171 |
double mass, mtot; |
172 |
double aVel[3]; |
173 |
int i, j; |
174 |
|
175 |
|
176 |
for (j=0; j<3; j++) |
177 |
COMvel[j] = 0.0; |
178 |
|
179 |
mtot = 0.0; |
180 |
|
181 |
for (i=0; i < nAtoms; i++) { |
182 |
if (myAtoms[i] != NULL) { |
183 |
|
184 |
mass = myAtoms[i]->getMass(); |
185 |
mtot += mass; |
186 |
|
187 |
myAtoms[i]->getVel(aVel); |
188 |
|
189 |
for (j=0; j<3; j++) |
190 |
COMvel[j] += aVel[j]*mass; |
191 |
|
192 |
} |
193 |
} |
194 |
|
195 |
for (j=0; j<3; j++) |
196 |
COMvel[j] /= mtot; |
197 |
|
198 |
return mtot; |
199 |
|
200 |
} |
201 |
|
202 |
double Molecule::getTotalMass() |
203 |
{ |
204 |
int natoms; |
205 |
Atom** atoms; |
206 |
double totalMass; |
207 |
|
208 |
natoms = getNAtoms(); |
209 |
atoms = getMyAtoms(); |
210 |
totalMass = 0; |
211 |
for(int i =0; i < natoms; i++){ |
212 |
totalMass += atoms[i]->getMass(); |
213 |
} |
214 |
|
215 |
return totalMass; |
216 |
} |