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 483 by gezelter, Wed Apr 9 04:06:43 2003 UTC vs.
Revision 1167 by tim, Wed May 12 16:38:45 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   }
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    }
# Line 80 | Line 104 | void Molecule::calcForces( void ){
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  
# Line 87 | Line 114 | 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();
# Line 118 | Line 149 | void Molecule::printMe( void ){
149    for(i=0; i<nTorsions; i++){
150      myTorsions[i]->printMe();
151    }
152 +
153   }
154  
155   void Molecule::moveCOM(double delta[3]){
156 <  double x, y, z;
157 <  int i;
156 >  double aPos[3];
157 >  int i, j;
158  
159 <  for(i=0; i<nAtoms; i++) {
160 <    if(myAtoms[i] != NULL ) {
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 <      x = myAtoms[i]->getX() + delta[0];
168 <      y = myAtoms[i]->getY() + delta[1];
169 <      z = myAtoms[i]->getZ() + delta[2];
167 >      myIntegrableObjects[i]->setPos( aPos );
168 >    }
169 >  }
170  
171 <      myAtoms[i]->setX(x);
172 <      myAtoms[i]->setY(y);
173 <      myAtoms[i]->setZ(z);
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 <  int i;
192 >  double aPos[3];
193 >  int i, j;
194  
195 <  COM[0] = 0.0;
196 <  COM[1] = 0.0;
197 <  COM[2] = 0.0;
195 >  for (j=0; j<3; j++)
196 >    COM[j] = 0.0;
197 >
198    mtot   = 0.0;
199  
200 <  for (i=0; i < nAtoms; i++) {
201 <    if (myAtoms[i] != NULL) {
200 >  for (i=0; i < myIntegrableObjects.size(); i++) {
201 >    if (myIntegrableObjects[i] != NULL) {
202  
203 <      mass = myAtoms[i]->getMass();
203 >      mass = myIntegrableObjects[i]->getMass();
204        mtot   += mass;
205 <      COM[0] += myAtoms[i]->getX() * mass;
206 <      COM[1] += myAtoms[i]->getY() * mass;
158 <      COM[2] += myAtoms[i]->getZ() * 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 <  COM[0] /= mtot;
215 <  COM[1] /= mtot;
165 <  COM[2] /= mtot;
166 <
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 <  int i;
221 >  double aVel[3];
222 >  int i, j;
223  
224 <  COMvel[0] = 0.0;
225 <  COMvel[1] = 0.0;
226 <  COMvel[2] = 0.0;
224 >
225 >  for (j=0; j<3; j++)
226 >    COMvel[j] = 0.0;
227 >
228    mtot   = 0.0;
229  
230 <  for (i=0; i < nAtoms; i++) {
231 <    if (myAtoms[i] != NULL) {
232 <      
233 <      mass = myAtoms[i]->getMass();
230 >  for (i=0; i < myIntegrableObjects.size(); i++) {
231 >    if (myIntegrableObjects[i] != NULL) {
232 >
233 >      mass = myIntegrableObjects[i]->getMass();
234        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;
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 <  COMvel[0] /= mtot;
245 <  COMvel[1] /= mtot;
193 <  COMvel[2] /= mtot;
244 >  for (j=0; j<3; j++)
245 >    COMvel[j] /= mtot;
246  
247    return mtot;
248  
249   }
250  
251 < void Molecule::atomicRollCall(int* molMembership) {
252 <  int i, which;
251 > double Molecule::getTotalMass()
252 > {
253  
254 <  for (i=0; i < nAtoms; i++) {
255 <    if (myAtoms[i] != NULL) {
256 <      which = myAtoms[i]->getIndex();
257 <      molMembership[which] = myIndex;
258 <    }
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   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines