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 829 by gezelter, Tue Oct 28 16:03:37 2003 UTC vs.
Revision 1452 by tim, Mon Aug 23 15:11:36 2004 UTC

# 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 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 <      myAtoms[i]->getPos( aPos );
181 >      myIntegrableObjects[i]->getPos( aPos );
182        
183        for (j=0; j< 3; j++)
184          aPos[j] += delta[j];
185  
186 <      myAtoms[i]->setPos( aPos );
186 >      myIntegrableObjects[i]->setPos( aPos );
187      }
188    }
189 +
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;
# Line 148 | Line 216 | void Molecule::getCOM( double COM[3] ) {
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        
225 <      myAtoms[i]->getPos( aPos );
225 >      myIntegrableObjects[i]->getPos( aPos );
226  
227        for( j = 0; j < 3; j++)
228          COM[j] += aPos[j] * mass;
# Line 178 | Line 246 | double Molecule::getCOMvel( double COMvel[3] ) {
246  
247    mtot   = 0.0;
248  
249 <  for (i=0; i < nAtoms; i++) {
250 <    if (myAtoms[i] != NULL) {
249 >  for (i=0; i < myIntegrableObjects.size(); i++) {
250 >    if (myIntegrableObjects[i] != NULL) {
251  
252 <      mass = myAtoms[i]->getMass();
252 >      mass = myIntegrableObjects[i]->getMass();
253        mtot   += mass;
254  
255 <      myAtoms[i]->getVel(aVel);
255 >      myIntegrableObjects[i]->getVel(aVel);
256  
257        for (j=0; j<3; j++)
258          COMvel[j] += aVel[j]*mass;
# Line 201 | Line 269 | double Molecule::getTotalMass()
269  
270   double Molecule::getTotalMass()
271   {
272 <  int natoms;
205 <  Atom** atoms;
272 >
273    double totalMass;
274    
208  natoms = getNAtoms();
209  atoms = getMyAtoms();
275    totalMass = 0;
276 <  for(int i =0; i < natoms; i++){
277 <    totalMass += atoms[i]->getMass();
276 >  for(int i =0; i < myIntegrableObjects.size(); i++){
277 >    totalMass += myIntegrableObjects[i]->getMass();
278    }
279  
280    return totalMass;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines