ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Molecule.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/Molecule.cpp (file contents):
Revision 449 by mmeineke, Thu Apr 3 20:57:56 2003 UTC vs.
Revision 1234 by tim, Fri Jun 4 03:15:31 2004 UTC

# Line 1 | Line 1
1 < #include <cstdlib>
1 > #include <stdlib.h>
2  
3  
4   #include "Molecule.hpp"
# Line 12 | Line 12 | Molecule::Molecule( void ){
12    myBonds = NULL;
13    myBends = NULL;
14    myTorsions = NULL;
15
15   }
16  
18
19
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];
# Line 40 | Line 39 | Molecule::~Molecule( void ){
39      delete[] myTorsions;
40    }
41  
42 <  if( myExcludes != NULL ){
43 <    for(i=0; i<nExcludes; i++) if(myExcludes[i] != NULL ) delete myExcludes[i];
44 <    delete[] myExcludes;
45 <  }
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 <  nExcludes = theInit.nExcludes;
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 <  myExcludes = theInit.myExcludes;
70 <    
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 >  myConstraintPairs = theInit.myConstraintPairs;
80 >  
81   }
82  
83   void Molecule::calcForces( void ){
84    
85    int i;
86 +  double com[3];
87  
88 +  for(i=0; i<myRigidBodies.size(); i++) {
89 +    myRigidBodies[i]->updateAtoms();
90 +  }
91 +
92 +  //calculate the center of mass of the molecule
93 +  //getCOM(com);  
94 +  //for(int i = 0; i < nAtoms; i ++)
95 +  //  myAtoms[i]->setRc(com);  
96 +  
97 +
98    for(i=0; i<nBonds; i++){
99      myBonds[i]->calc_forces();
100    }
# Line 80 | Line 106 | void Molecule::calcForces( void ){
106    for(i=0; i<nTorsions; i++){
107      myTorsions[i]->calc_forces();
108    }
109 +
110 +  // Rigid Body forces and torques are done after the fortran force loop
111 +
112   }
113  
114  
# Line 87 | Line 116 | double Molecule::getPotential( void ){
116    
117    int i;
118    double myPot = 0.0;
119 +
120 +  for(i=0; i<myRigidBodies.size(); i++) {
121 +    myRigidBodies[i]->updateAtoms();
122 +  }
123    
124    for(i=0; i<nBonds; i++){
125      myPot += myBonds[i]->get_potential();
# Line 118 | Line 151 | void Molecule::printMe( void ){
151    for(i=0; i<nTorsions; i++){
152      myTorsions[i]->printMe();
153    }
154 +
155   }
156  
157   void Molecule::moveCOM(double delta[3]){
158 <  double x, y, z;
159 <  int i;
158 >  double aPos[3];
159 >  int i, j;
160  
161 <  for(i=0; i<nAtoms; i++) {
162 <    if(myAtoms[i] != NULL ) {
161 >  for(i=0; i<myIntegrableObjects.size(); i++) {
162 >    if(myIntegrableObjects[i] != NULL ) {
163 >      
164 >      myIntegrableObjects[i]->getPos( aPos );
165 >      
166 >      for (j=0; j< 3; j++)
167 >        aPos[j] += delta[j];
168  
169 <      x = myAtoms[i]->getX() + delta[0];
170 <      y = myAtoms[i]->getY() + delta[1];
171 <      z = myAtoms[i]->getZ() + delta[2];
169 >      myIntegrableObjects[i]->setPos( aPos );
170 >    }
171 >  }
172  
173 <      myAtoms[i]->setX(x);
174 <      myAtoms[i]->setY(y);
175 <      myAtoms[i]->setZ(z);
173 >  for(i=0; i<myRigidBodies.size(); i++) {
174 >
175 >      myRigidBodies[i]->getPos( aPos );
176 >
177 >      for (j=0; j< 3; j++)
178 >        aPos[j] += delta[j];
179 >      
180 >      myRigidBodies[i]->setPos( aPos );
181      }
182 + }
183 +
184 + void Molecule::atoms2rigidBodies( void ) {
185 +  int i;
186 +  for (i = 0; i < myRigidBodies.size(); i++) {
187 +    myRigidBodies[i]->calcForcesAndTorques();  
188    }
189   }
190  
191   void Molecule::getCOM( double COM[3] ) {
192  
193    double mass, mtot;
194 <  int i;
194 >  double aPos[3];
195 >  int i, j;
196  
197 <  COM[0] = 0.0;
198 <  COM[1] = 0.0;
199 <  COM[2] = 0.0;
197 >  for (j=0; j<3; j++)
198 >    COM[j] = 0.0;
199 >
200    mtot   = 0.0;
201  
202 <  for (i=0; i < nAtoms; i++) {
203 <    if (myAtoms[i] != NULL) {
202 >  for (i=0; i < myIntegrableObjects.size(); i++) {
203 >    if (myIntegrableObjects[i] != NULL) {
204  
205 <      mass = myAtoms[i]->getMass();
205 >      mass = myIntegrableObjects[i]->getMass();
206        mtot   += mass;
207 <      COM[0] += myAtoms[i]->getX() * mass;
208 <      COM[1] += myAtoms[i]->getY() * mass;
158 <      COM[2] += myAtoms[i]->getZ() * mass;
207 >      
208 >      myIntegrableObjects[i]->getPos( aPos );
209  
210 +      for( j = 0; j < 3; j++)
211 +        COM[j] += aPos[j] * mass;
212 +
213      }
214    }
215  
216 <  COM[0] /= mtot;
217 <  COM[1] /= mtot;
218 <  COM[2] /= mtot;
216 >  for (j = 0; j < 3; j++)
217 >    COM[j] /= mtot;
218 > }
219 >
220 > double Molecule::getCOMvel( double COMvel[3] ) {
221 >
222 >  double mass, mtot;
223 >  double aVel[3];
224 >  int i, j;
225 >
226 >
227 >  for (j=0; j<3; j++)
228 >    COMvel[j] = 0.0;
229 >
230 >  mtot   = 0.0;
231 >
232 >  for (i=0; i < myIntegrableObjects.size(); i++) {
233 >    if (myIntegrableObjects[i] != NULL) {
234 >
235 >      mass = myIntegrableObjects[i]->getMass();
236 >      mtot   += mass;
237 >
238 >      myIntegrableObjects[i]->getVel(aVel);
239 >
240 >      for (j=0; j<3; j++)
241 >        COMvel[j] += aVel[j]*mass;
242 >
243 >    }
244 >  }
245 >
246 >  for (j=0; j<3; j++)
247 >    COMvel[j] /= mtot;
248  
249 <  return COM;
249 >  return mtot;
250 >
251   }
252 +
253 + double Molecule::getTotalMass()
254 + {
255 +
256 +  double totalMass;
257 +  
258 +  totalMass = 0;
259 +  for(int i =0; i < myIntegrableObjects.size(); i++){
260 +    totalMass += myIntegrableObjects[i]->getMass();
261 +  }
262 +
263 +  return totalMass;
264 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines