ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-1.0/utils/sysbuilder/MoLocator.cpp
Revision: 1429
Committed: Wed Jul 28 20:29:49 2004 UTC (19 years, 11 months ago) by tim
File size: 3531 byte(s)
Log Message:
simpleBuilder in progress

File Contents

# Content
1 #include <iostream>
2
3 #include <cstdlib>
4 #include <cmath>
5
6 #include "simError.h"
7 #include "MoLocator.hpp"
8
9 MoLocator::MoLocator( MoleculeStamp* theStamp, ForceFields* theFF){
10
11 myStamp = theStamp;
12 myFF = theFF;
13 nIntegrableObjects = myStamp->getNIntegrable();
14 calcRefCoords();
15 }
16
17 void MoLocator::placeMol( const Vector3d& offset, const Vector3d& ort, Molecule* mol){
18 Vector3d newCoor;
19 Vector3d velocity(0.0, 0.0, 0.0);
20 Vector3d angMomentum(0.0, 0.0, 0.0);
21 double quaternion[4];
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
29 myIntegrableObjects = mol->getIntegrableObjects();
30
31 if(myIntegrableObjects.size() != nIntegrableObjects){
32 sprintf( painCave.errMsg,
33 "MoLocator error.\n"
34 " The number of integrable objects of MoleculeStamp is not the same as that of Molecule\n");
35 painCave.isFatal = 1;
36 simError();
37
38 }
39
40 for(int i=0; i<nIntegrableObjects; i++) {
41
42 newCoor = refCoords[i] + offset;
43 myIntegrableObjects[i]->setPos( newCoor.vec);
44 myIntegrableObjects[i]->setVel(velocity.vec);
45
46 if(myIntegrableObjects[i]->isDirectional()){
47 myIntegrableObjects[i]->setQ(quaternion);
48 myIntegrableObjects[i]->setJ(angMomentum.vec);
49 }
50 }
51
52 }
53
54 void MoLocator::calcRefCoords( void ){
55 AtomStamp* currAtomStamp;
56 int nAtoms;
57 int nRigidBodies;
58 vector<double> mass;
59 Vector3d coor;
60 Vector3d refMolCom;
61 int nAtomsInRb;
62 double totMassInRb;
63 double currAtomMass;
64
65 double totMass;
66
67 mass.resize(nIntegrableObjects);
68
69 nAtoms= myStamp->getNAtoms();
70 nRigidBodies = myStamp->getNRigidBodies();
71
72 //
73 for(size_t i=0; i<nAtoms; i++){
74
75 currAtomStamp = myStamp->getAtom(i);
76
77 if( !currAtomStamp->havePosition() ){
78 sprintf( painCave.errMsg,
79 "MoLocator error.\n"
80 " Component %s, atom %s does not have a position specified.\n"
81 " This means MoLocator cannot initalize it's position.\n",
82 myStamp->getID(),
83 currAtomStamp->getType() );
84
85 painCave.isFatal = 1;
86 simError();
87 }
88
89 //if atom belongs to rigidbody, just skip it
90 if(myStamp->isAtomInRigidBody(i))
91 continue;
92 //get mass and the reference coordinate
93 else{
94 currAtomMass = myFF->getAtomTypeMass(currAtomStamp->getType());
95 mass.push_back(currAtomMass);
96 coor.x = currAtomStamp->getPosX();
97 coor.y = currAtomStamp->getPosY();
98 coor.z = currAtomStamp->getPosZ();
99 refCoords.push_back(coor);
100
101 }
102 }
103
104 for(int i = 0; i < nRigidBodies; i++){
105 coor.x = 0;
106 coor.y = 0;
107 coor.z = 0;
108 totMassInRb = 0;
109
110 for(int j = 0; j < nAtomsInRb; j++){
111
112 currAtomMass = myFF->getAtomTypeMass(currAtomStamp->getType());
113 totMassInRb += currAtomMass;
114
115 coor.x += currAtomStamp->getPosX() * currAtomMass;
116 coor.y += currAtomStamp->getPosY() * currAtomMass;
117 coor.z += currAtomStamp->getPosZ() * currAtomMass;
118 }
119
120 mass.push_back(totMassInRb);
121 coor /= totMassInRb;
122 refCoords.push_back(coor);
123 }
124
125 //calculate the reference center of mass
126 for(int i = 0; i < nIntegrableObjects; i++){
127 refMolCom += refCoords[i] * mass[i];
128 totMass += mass[i];
129 }
130
131 refMolCom /= totMass;
132
133 //move the reference center of mass to (0,0,0) and adjust the reference coordinate
134 //of the integrabel objects
135 for(int i = 0; i < nIntegrableObjects; i++)
136 refCoords[i] -= refMolCom;
137 }
138