ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Molecule.cpp
Revision: 1167
Committed: Wed May 12 16:38:45 2004 UTC (20 years, 2 months ago) by tim
File size: 4830 byte(s)
Log Message:
get rid of rc and massratio from simState, creat cutoff group forevery atom
which does not belong to
cutoff group defined at mdl file

File Contents

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