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 1452 by tim, Mon Aug 23 15:11:36 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 +  GenericData* gdata;
57 +  ConsRbData* rbData;
58 +  RigidBody* oldRb;
59 +  
60    nAtoms = theInit.nAtoms;
61    nMembers = nAtoms;
62    nBonds = theInit.nBonds;
63    nBends = theInit.nBends;
64    nTorsions = theInit.nTorsions;
65 <  nExcludes = theInit.nExcludes;
65 >  nRigidBodies = theInit.nRigidBodies;
66    nOriented = theInit.nOriented;
67  
68    myAtoms = theInit.myAtoms;
69    myBonds = theInit.myBonds;
70    myBends = theInit.myBends;
71    myTorsions = theInit.myTorsions;
72 <  myExcludes = theInit.myExcludes;
72 >  myRigidBodies = theInit.myRigidBodies;
73 >
74 >  myIntegrableObjects = theInit.myIntegrableObjects;
75 >
76 >  for (int i = 0; i < myRigidBodies.size(); i++){
77 >      myRigidBodies[i]->calcRefCoords();
78 >    //just a quick hack
79      
80 +    gdata = myRigidBodies[i]->getProperty("OldState");
81 +    if(gdata != NULL){
82 +      rbData = dynamic_cast<ConsRbData*>(gdata);
83 +      if(rbData ==NULL)
84 +        cerr << "dynamic_cast to ConsRbData Error in Molecule::initialize()" << endl;
85 +      else{
86 +        oldRb = rbData->getData();
87 +        oldRb->calcRefCoords();
88 +      }
89 +    }//end if(gata != NULL)
90 +    
91 +  }//end for(int i = 0; i < myRigidBodies.size(); i++)
92 +
93 +  myCutoffGroups = theInit.myCutoffGroups;
94 +  nCutoffGroups = myCutoffGroups.size();
95 +
96 +  myConstraintPairs = theInit.myConstraintPairs;
97 +  
98   }
99  
100   void Molecule::calcForces( void ){
101    
102    int i;
103 +  double com[3];
104  
105 +  for(i=0; i<myRigidBodies.size(); i++) {
106 +    myRigidBodies[i]->updateAtoms();
107 +  }
108 +
109 +  //calculate the center of mass of the molecule
110 +  //getCOM(com);  
111 +  //for(int i = 0; i < nAtoms; i ++)
112 +  //  myAtoms[i]->setRc(com);  
113 +  
114 +
115    for(i=0; i<nBonds; i++){
116      myBonds[i]->calc_forces();
117    }
# Line 80 | Line 123 | void Molecule::calcForces( void ){
123    for(i=0; i<nTorsions; i++){
124      myTorsions[i]->calc_forces();
125    }
126 +
127 +  // Rigid Body forces and torques are done after the fortran force loop
128 +
129   }
130  
131  
# Line 87 | Line 133 | double Molecule::getPotential( void ){
133    
134    int i;
135    double myPot = 0.0;
136 +
137 +  for(i=0; i<myRigidBodies.size(); i++) {
138 +    myRigidBodies[i]->updateAtoms();
139 +  }
140    
141    for(i=0; i<nBonds; i++){
142      myPot += myBonds[i]->get_potential();
# Line 118 | Line 168 | void Molecule::printMe( void ){
168    for(i=0; i<nTorsions; i++){
169      myTorsions[i]->printMe();
170    }
171 +
172   }
173  
174   void Molecule::moveCOM(double delta[3]){
175 <  double x, y, z;
176 <  int i;
175 >  double aPos[3];
176 >  int i, j;
177  
178 <  for(i=0; i<nAtoms; i++) {
179 <    if(myAtoms[i] != NULL ) {
178 >  for(i=0; i<myIntegrableObjects.size(); i++) {
179 >    if(myIntegrableObjects[i] != NULL ) {
180 >      
181 >      myIntegrableObjects[i]->getPos( aPos );
182 >      
183 >      for (j=0; j< 3; j++)
184 >        aPos[j] += delta[j];
185  
186 <      x = myAtoms[i]->getX() + delta[0];
187 <      y = myAtoms[i]->getY() + delta[1];
188 <      z = myAtoms[i]->getZ() + delta[2];
186 >      myIntegrableObjects[i]->setPos( aPos );
187 >    }
188 >  }
189  
190 <      myAtoms[i]->setX(x);
191 <      myAtoms[i]->setY(y);
192 <      myAtoms[i]->setZ(z);
190 >  for(i=0; i<myRigidBodies.size(); i++) {
191 >
192 >      myRigidBodies[i]->getPos( aPos );
193 >
194 >      for (j=0; j< 3; j++)
195 >        aPos[j] += delta[j];
196 >      
197 >      myRigidBodies[i]->setPos( aPos );
198      }
199 + }
200 +
201 + void Molecule::atoms2rigidBodies( void ) {
202 +  int i;
203 +  for (i = 0; i < myRigidBodies.size(); i++) {
204 +    myRigidBodies[i]->calcForcesAndTorques();  
205    }
206   }
207  
208   void Molecule::getCOM( double COM[3] ) {
209  
210    double mass, mtot;
211 <  int i;
211 >  double aPos[3];
212 >  int i, j;
213  
214 <  COM[0] = 0.0;
215 <  COM[1] = 0.0;
216 <  COM[2] = 0.0;
214 >  for (j=0; j<3; j++)
215 >    COM[j] = 0.0;
216 >
217    mtot   = 0.0;
218  
219 <  for (i=0; i < nAtoms; i++) {
220 <    if (myAtoms[i] != NULL) {
219 >  for (i=0; i < myIntegrableObjects.size(); i++) {
220 >    if (myIntegrableObjects[i] != NULL) {
221  
222 <      mass = myAtoms[i]->getMass();
222 >      mass = myIntegrableObjects[i]->getMass();
223        mtot   += mass;
224 <      COM[0] += myAtoms[i]->getX() * mass;
225 <      COM[1] += myAtoms[i]->getY() * mass;
158 <      COM[2] += myAtoms[i]->getZ() * mass;
224 >      
225 >      myIntegrableObjects[i]->getPos( aPos );
226  
227 +      for( j = 0; j < 3; j++)
228 +        COM[j] += aPos[j] * mass;
229 +
230      }
231    }
232  
233 <  COM[0] /= mtot;
234 <  COM[1] /= mtot;
165 <  COM[2] /= mtot;
166 <
233 >  for (j = 0; j < 3; j++)
234 >    COM[j] /= mtot;
235   }
236  
237   double Molecule::getCOMvel( double COMvel[3] ) {
238  
239    double mass, mtot;
240 <  int i;
240 >  double aVel[3];
241 >  int i, j;
242  
243 <  COMvel[0] = 0.0;
244 <  COMvel[1] = 0.0;
245 <  COMvel[2] = 0.0;
243 >
244 >  for (j=0; j<3; j++)
245 >    COMvel[j] = 0.0;
246 >
247    mtot   = 0.0;
248  
249 <  for (i=0; i < nAtoms; i++) {
250 <    if (myAtoms[i] != NULL) {
251 <      
252 <      mass = myAtoms[i]->getMass();
249 >  for (i=0; i < myIntegrableObjects.size(); i++) {
250 >    if (myIntegrableObjects[i] != NULL) {
251 >
252 >      mass = myIntegrableObjects[i]->getMass();
253        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;
254  
255 +      myIntegrableObjects[i]->getVel(aVel);
256 +
257 +      for (j=0; j<3; j++)
258 +        COMvel[j] += aVel[j]*mass;
259 +
260      }
261    }
262  
263 <  COMvel[0] /= mtot;
264 <  COMvel[1] /= mtot;
193 <  COMvel[2] /= mtot;
263 >  for (j=0; j<3; j++)
264 >    COMvel[j] /= mtot;
265  
266    return mtot;
267  
268   }
269  
270 < void Molecule::atomicRollCall(int* molMembership) {
271 <  int i, which;
270 > double Molecule::getTotalMass()
271 > {
272  
273 <  for (i=0; i < nAtoms; i++) {
274 <    if (myAtoms[i] != NULL) {
275 <      which = myAtoms[i]->getIndex();
276 <      molMembership[which] = myIndex;
277 <    }
273 >  double totalMass;
274 >  
275 >  totalMass = 0;
276 >  for(int i =0; i < myIntegrableObjects.size(); i++){
277 >    totalMass += myIntegrableObjects[i]->getMass();
278    }
279 +
280 +  return totalMass;
281   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines