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 x, y, z; |
125 |
int i; |
126 |
|
127 |
for(i=0; i<nAtoms; i++) { |
128 |
if(myAtoms[i] != NULL ) { |
129 |
|
130 |
x = myAtoms[i]->getX() + delta[0]; |
131 |
y = myAtoms[i]->getY() + delta[1]; |
132 |
z = myAtoms[i]->getZ() + delta[2]; |
133 |
|
134 |
myAtoms[i]->setX(x); |
135 |
myAtoms[i]->setY(y); |
136 |
myAtoms[i]->setZ(z); |
137 |
} |
138 |
} |
139 |
} |
140 |
|
141 |
void Molecule::getCOM( double COM[3] ) { |
142 |
|
143 |
double mass, mtot; |
144 |
int i; |
145 |
|
146 |
COM[0] = 0.0; |
147 |
COM[1] = 0.0; |
148 |
COM[2] = 0.0; |
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 |
COM[0] += myAtoms[i]->getX() * mass; |
157 |
COM[1] += myAtoms[i]->getY() * mass; |
158 |
COM[2] += myAtoms[i]->getZ() * mass; |
159 |
|
160 |
} |
161 |
} |
162 |
|
163 |
COM[0] /= mtot; |
164 |
COM[1] /= mtot; |
165 |
COM[2] /= mtot; |
166 |
|
167 |
} |
168 |
|
169 |
void Molecule::getCOMvel( double mtot, double COMvel[3] ) { |
170 |
|
171 |
double mass; |
172 |
int i; |
173 |
|
174 |
COMvel[0] = 0.0; |
175 |
COMvel[1] = 0.0; |
176 |
COMvel[2] = 0.0; |
177 |
mtot = 0.0; |
178 |
|
179 |
for (i=0; i < nAtoms; i++) { |
180 |
if (myAtoms[i] != NULL) { |
181 |
|
182 |
mass = myAtoms[i]->getMass(); |
183 |
mtot += mass; |
184 |
COMvel[0] += myAtoms[i]->get_vx() * mass; |
185 |
COMvel[1] += myAtoms[i]->get_vy() * mass; |
186 |
COMvel[2] += myAtoms[i]->get_vz() * mass; |
187 |
|
188 |
} |
189 |
} |
190 |
|
191 |
COMvel[0] /= mtot; |
192 |
COMvel[1] /= mtot; |
193 |
COMvel[2] /= mtot; |
194 |
|
195 |
} |