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 1140 by tim, Wed Apr 28 22:34:02 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 >  hasMassRatio = false;
16   }
17  
18
19
18   Molecule::~Molecule( void ){
19    int i;
20    
# Line 40 | Line 38 | Molecule::~Molecule( void ){
38      delete[] myTorsions;
39    }
40  
43  if( myExcludes != NULL ){
44    for(i=0; i<nExcludes; i++) if(myExcludes[i] != NULL ) delete myExcludes[i];
45    delete[] myExcludes;
46  }
41   }
42  
43  
# Line 54 | Line 48 | void Molecule::initialize( molInit &theInit ){
48    nBonds = theInit.nBonds;
49    nBends = theInit.nBends;
50    nTorsions = theInit.nTorsions;
51 <  nExcludes = theInit.nExcludes;
51 >  nRigidBodies = theInit.nRigidBodies;
52    nOriented = theInit.nOriented;
53  
54    myAtoms = theInit.myAtoms;
55    myBonds = theInit.myBonds;
56    myBends = theInit.myBends;
57    myTorsions = theInit.myTorsions;
58 <  myExcludes = theInit.myExcludes;
59 <    
58 >  myRigidBodies = theInit.myRigidBodies;
59 >
60 >  myIntegrableObjects = theInit.myIntegrableObjects;
61 >
62 >  for (int i = 0; i < myRigidBodies.size(); i++)
63 >      myRigidBodies[i]->calcRefCoords();
64 >
65   }
66  
67   void Molecule::calcForces( void ){
68    
69    int i;
70 +  double com[3];
71  
72 +  for(i=0; i<myRigidBodies.size(); i++) {
73 +    myRigidBodies[i]->updateAtoms();
74 +  }
75 +
76 +  //the mass ratio will never change during the simulation. Thus, we could
77 +  //just calculate it at the begining of the simulation
78 +  if (!hasMassRatio){
79 +    double totMass = getTotalMass();
80 +    for(int i = 0; i < nAtoms; i ++)
81 +      myAtoms[i]->setMassRatio(myAtoms[i]->getMass()/totMass);  
82 +    hasMassRatio =  true;
83 +  }
84 +
85 +  //calculate the center of mass of the molecule
86 +  getCOM(com);  
87 +  for(int i = 0; i < nAtoms; i ++)
88 +    myAtoms[i]->setRc(com);  
89 +  
90 +
91    for(i=0; i<nBonds; i++){
92      myBonds[i]->calc_forces();
93    }
# Line 80 | Line 99 | void Molecule::calcForces( void ){
99    for(i=0; i<nTorsions; i++){
100      myTorsions[i]->calc_forces();
101    }
102 +
103 +  // Rigid Body forces and torques are done after the fortran force loop
104 +
105   }
106  
107  
# Line 87 | Line 109 | double Molecule::getPotential( void ){
109    
110    int i;
111    double myPot = 0.0;
112 +
113 +  for(i=0; i<myRigidBodies.size(); i++) {
114 +    myRigidBodies[i]->updateAtoms();
115 +  }
116    
117    for(i=0; i<nBonds; i++){
118      myPot += myBonds[i]->get_potential();
# Line 118 | Line 144 | void Molecule::printMe( void ){
144    for(i=0; i<nTorsions; i++){
145      myTorsions[i]->printMe();
146    }
147 +
148   }
149  
150   void Molecule::moveCOM(double delta[3]){
151 <  double x, y, z;
152 <  int i;
151 >  double aPos[3];
152 >  int i, j;
153  
154 <  for(i=0; i<nAtoms; i++) {
155 <    if(myAtoms[i] != NULL ) {
154 >  for(i=0; i<myIntegrableObjects.size(); i++) {
155 >    if(myIntegrableObjects[i] != NULL ) {
156 >      
157 >      myIntegrableObjects[i]->getPos( aPos );
158 >      
159 >      for (j=0; j< 3; j++)
160 >        aPos[j] += delta[j];
161  
162 <      x = myAtoms[i]->getX() + delta[0];
163 <      y = myAtoms[i]->getY() + delta[1];
164 <      z = myAtoms[i]->getZ() + delta[2];
162 >      myIntegrableObjects[i]->setPos( aPos );
163 >    }
164 >  }
165  
166 <      myAtoms[i]->setX(x);
167 <      myAtoms[i]->setY(y);
168 <      myAtoms[i]->setZ(z);
166 >  for(i=0; i<myRigidBodies.size(); i++) {
167 >
168 >      myRigidBodies[i]->getPos( aPos );
169 >
170 >      for (j=0; j< 3; j++)
171 >        aPos[j] += delta[j];
172 >      
173 >      myRigidBodies[i]->setPos( aPos );
174      }
175 + }
176 +
177 + void Molecule::atoms2rigidBodies( void ) {
178 +  int i;
179 +  for (i = 0; i < myRigidBodies.size(); i++) {
180 +    myRigidBodies[i]->calcForcesAndTorques();  
181    }
182   }
183  
184   void Molecule::getCOM( double COM[3] ) {
185  
186    double mass, mtot;
187 <  int i;
187 >  double aPos[3];
188 >  int i, j;
189  
190 <  COM[0] = 0.0;
191 <  COM[1] = 0.0;
192 <  COM[2] = 0.0;
190 >  for (j=0; j<3; j++)
191 >    COM[j] = 0.0;
192 >
193    mtot   = 0.0;
194  
195 <  for (i=0; i < nAtoms; i++) {
196 <    if (myAtoms[i] != NULL) {
195 >  for (i=0; i < myIntegrableObjects.size(); i++) {
196 >    if (myIntegrableObjects[i] != NULL) {
197  
198 <      mass = myAtoms[i]->getMass();
198 >      mass = myIntegrableObjects[i]->getMass();
199        mtot   += mass;
200 <      COM[0] += myAtoms[i]->getX() * mass;
201 <      COM[1] += myAtoms[i]->getY() * mass;
158 <      COM[2] += myAtoms[i]->getZ() * mass;
200 >      
201 >      myIntegrableObjects[i]->getPos( aPos );
202  
203 +      for( j = 0; j < 3; j++)
204 +        COM[j] += aPos[j] * mass;
205 +
206      }
207    }
208  
209 <  COM[0] /= mtot;
210 <  COM[1] /= mtot;
165 <  COM[2] /= mtot;
166 <
209 >  for (j = 0; j < 3; j++)
210 >    COM[j] /= mtot;
211   }
212  
213   double Molecule::getCOMvel( double COMvel[3] ) {
214  
215    double mass, mtot;
216 <  int i;
216 >  double aVel[3];
217 >  int i, j;
218  
219 <  COMvel[0] = 0.0;
220 <  COMvel[1] = 0.0;
221 <  COMvel[2] = 0.0;
219 >
220 >  for (j=0; j<3; j++)
221 >    COMvel[j] = 0.0;
222 >
223    mtot   = 0.0;
224  
225 <  for (i=0; i < nAtoms; i++) {
226 <    if (myAtoms[i] != NULL) {
227 <      
228 <      mass = myAtoms[i]->getMass();
225 >  for (i=0; i < myIntegrableObjects.size(); i++) {
226 >    if (myIntegrableObjects[i] != NULL) {
227 >
228 >      mass = myIntegrableObjects[i]->getMass();
229        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;
230  
231 +      myIntegrableObjects[i]->getVel(aVel);
232 +
233 +      for (j=0; j<3; j++)
234 +        COMvel[j] += aVel[j]*mass;
235 +
236      }
237    }
238  
239 <  COMvel[0] /= mtot;
240 <  COMvel[1] /= mtot;
193 <  COMvel[2] /= mtot;
239 >  for (j=0; j<3; j++)
240 >    COMvel[j] /= mtot;
241  
242    return mtot;
243  
244   }
245  
246 < void Molecule::atomicRollCall(int* molMembership) {
247 <  int i, which;
246 > double Molecule::getTotalMass()
247 > {
248  
249 <  for (i=0; i < nAtoms; i++) {
250 <    if (myAtoms[i] != NULL) {
251 <      which = myAtoms[i]->getIndex();
252 <      molMembership[which] = myIndex;
253 <    }
249 >  double totalMass;
250 >  
251 >  totalMass = 0;
252 >  for(int i =0; i < myIntegrableObjects.size(); i++){
253 >    totalMass += myIntegrableObjects[i]->getMass();
254    }
255 +
256 +  return totalMass;
257   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines