ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-1.0/utils/sysbuilder/MoLocator.cpp
(Generate patch)

Comparing trunk/OOPSE-1.0/utils/sysbuilder/MoLocator.cpp (file contents):
Revision 1429 by tim, Wed Jul 28 20:29:49 2004 UTC vs.
Revision 1443 by tim, Fri Jul 30 14:44:10 2004 UTC

# Line 5 | Line 5
5  
6   #include "simError.h"
7   #include "MoLocator.hpp"
8 + #include "MatVec3.h"
9  
10   MoLocator::MoLocator( MoleculeStamp* theStamp, ForceFields* theFF){
11  
# Line 15 | Line 16 | void MoLocator::placeMol( const Vector3d& offset, cons
16   }
17  
18   void MoLocator::placeMol( const Vector3d& offset, const Vector3d& ort, Molecule* mol){
19 <  Vector3d newCoor;
20 <  Vector3d velocity(0.0, 0.0, 0.0);
21 <  Vector3d angMomentum(0.0, 0.0, 0.0);
21 <  double quaternion[4];
19 >  double newCoor[3];
20 >  double curRefCoor[3];
21 >  double zeroVector[3];
22    vector<StuntDouble*> myIntegrableObjects;
23 <
24 <  quaternion[0] = 1.0;
25 <  quaternion[1] = 0.0;
26 <  quaternion[2] = 0.0;
27 <  quaternion[3] = 0.0;
28 <
23 >  double rotMat[3][3];
24 >  
25 >  zeroVector[0] = 0.0;
26 >  zeroVector[1] = 0.0;
27 >  zeroVector[2] = 0.0;
28 >  
29 >  latVec2RotMat(ort, rotMat);
30 >  
31    myIntegrableObjects = mol->getIntegrableObjects();
32  
33    if(myIntegrableObjects.size() != nIntegrableObjects){
# Line 39 | Line 41 | void MoLocator::placeMol( const Vector3d& offset, cons
41      
42    for(int i=0; i<nIntegrableObjects; i++) {
43  
44 <      newCoor = refCoords[i] + offset;
45 <      myIntegrableObjects[i]->setPos( newCoor.vec);
46 <      myIntegrableObjects[i]->setVel(velocity.vec);
44 >    //calculate the reference coordinate for integrable objects after rotation
45 >    curRefCoor[0] = refCoords[i][0];
46 >    curRefCoor[1] = refCoords[i][1];
47 >    curRefCoor[2] = refCoords[i][2];
48 >    
49 >    matVecMul3(rotMat, curRefCoor, newCoor);    
50  
51 <      if(myIntegrableObjects[i]->isDirectional()){
52 <        myIntegrableObjects[i]->setQ(quaternion);
53 <        myIntegrableObjects[i]->setJ(angMomentum.vec);  
54 <      }
51 >    newCoor[0] +=  offset[0];
52 >    newCoor[1] +=  offset[1];
53 >    newCoor[2] +=  offset[2];
54 >
55 >    myIntegrableObjects[i]->setPos( newCoor);
56 >    myIntegrableObjects[i]->setVel(zeroVector);
57 >
58 >    if(myIntegrableObjects[i]->isDirectional()){
59 >      myIntegrableObjects[i]->setA(rotMat);
60 >      myIntegrableObjects[i]->setJ(zeroVector);  
61 >    }
62    }
63  
64   }
# Line 61 | Line 73 | void MoLocator::calcRefCoords( void ){
73    int nAtomsInRb;
74    double totMassInRb;
75    double currAtomMass;
76 <
65 <  double totMass;
76 >  double molMass;
77    
67  mass.resize(nIntegrableObjects);
68  
78    nAtoms= myStamp->getNAtoms();
79    nRigidBodies = myStamp->getNRigidBodies();
80  
72  //
81    for(size_t i=0; i<nAtoms; i++){
82  
83      currAtomStamp = myStamp->getAtom(i);
# Line 122 | Line 130 | void MoLocator::calcRefCoords( void ){
130      refCoords.push_back(coor);
131    }
132  
133 +
134    //calculate the reference center of mass
135 +  molMass = 0;
136 +  refMolCom.x = 0;
137 +  refMolCom.y = 0;
138 +  refMolCom.z = 0;
139 +  
140    for(int i = 0; i < nIntegrableObjects; i++){
141      refMolCom += refCoords[i] * mass[i];
142 <    totMass += mass[i];
142 >   molMass += mass[i];
143    }
144    
145 <  refMolCom /= totMass;
145 >  refMolCom /= molMass;
146  
147    //move the reference center of mass to (0,0,0) and adjust the reference coordinate
148    //of the integrabel objects
# Line 136 | Line 150 | void MoLocator::calcRefCoords( void ){
150      refCoords[i] -= refMolCom;
151   }
152  
153 +
154 + void latVec2RotMat(const Vector3d& lv, double rotMat[3][3]){
155 +
156 +  double theta, phi, psi;
157 +  
158 +  theta =acos(lv.z);
159 +  phi = atan2(lv.y, lv.x);
160 +  psi = 0;
161 +
162 +  rotMat[0][0] = (cos(phi) * cos(psi)) - (sin(phi) * cos(theta) * sin(psi));
163 +  rotMat[0][1] = (sin(phi) * cos(psi)) + (cos(phi) * cos(theta) * sin(psi));
164 +  rotMat[0][2] = sin(theta) * sin(psi);
165 +  
166 +  rotMat[1][0] = -(cos(phi) * sin(psi)) - (sin(phi) * cos(theta) * cos(psi));
167 +  rotMat[1][1] = -(sin(phi) * sin(psi)) + (cos(phi) * cos(theta) * cos(psi));
168 +  rotMat[1][2] = sin(theta) * cos(psi);
169 +  
170 +  rotMat[2][0] = sin(phi) * sin(theta);
171 +  rotMat[2][1] = -cos(phi) * sin(theta);
172 +  rotMat[2][2] = cos(theta);
173 + }
174 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines