ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-2.0/src/applications/simpleBuilder/MoLocator.cpp
Revision: 1904
Committed: Thu Jan 6 00:36:22 2005 UTC (19 years, 6 months ago) by tim
File size: 4467 byte(s)
Log Message:
simpleBuilder is working

File Contents

# Content
1 #include <iostream>
2
3 #include <cstdlib>
4 #include <cmath>
5
6 #include "utils/simError.h"
7 #include "applications/simpleBuilder/MoLocator.hpp"
8 #include "types/AtomType.hpp"
9 namespace oopse {
10 MoLocator::MoLocator( MoleculeStamp* theStamp, ForceField* theFF){
11
12 myStamp = theStamp;
13 myFF = theFF;
14 nIntegrableObjects = myStamp->getNIntegrable();
15 calcRef();
16 }
17
18 void MoLocator::placeMol( const Vector3d& offset, const Vector3d& ort, Molecule* mol){
19 Vector3d newCoor;
20 Vector3d curRefCoor;
21 RotMat3x3d rotMat = latVec2RotMat(ort);
22
23 if(mol->getNIntegrableObjects() != nIntegrableObjects){
24 sprintf( painCave.errMsg,
25 "MoLocator error.\n"
26 " The number of integrable objects of MoleculeStamp is not the same as that of Molecule\n");
27 painCave.isFatal = 1;
28 simError();
29 }
30
31 Molecule::IntegrableObjectIterator ii;
32 StuntDouble* integrableObject;
33 int i;
34 for (integrableObject = mol->beginIntegrableObject(ii), i = 0; integrableObject != NULL;
35 integrableObject = mol->nextIntegrableObject(ii), ++i) {
36
37 newCoor = rotMat * refCoords[i];
38 newCoor += offset;
39
40 integrableObject->setPos( newCoor);
41 integrableObject->setVel(V3Zero);
42
43 if(integrableObject->isDirectional()){
44 integrableObject->setA(rotMat * integrableObject->getA());
45 integrableObject->setJ(V3Zero);
46 }
47 }
48 }
49
50 void MoLocator::calcRef( void ){
51 AtomStamp* currAtomStamp;
52 int nAtoms;
53 int nRigidBodies;
54 std::vector<double> mass;
55 Vector3d coor;
56 Vector3d refMolCom;
57 int nAtomsInRb;
58 double totMassInRb;
59 double currAtomMass;
60 double molMass;
61
62 nAtoms= myStamp->getNAtoms();
63 nRigidBodies = myStamp->getNRigidBodies();
64
65 for(size_t i=0; i<nAtoms; i++){
66
67 currAtomStamp = myStamp->getAtom(i);
68
69 if( !currAtomStamp->havePosition() ){
70 sprintf( painCave.errMsg,
71 "MoLocator error.\n"
72 " Component %s, atom %s does not have a position specified.\n"
73 " This means MoLocator cannot initalize it's position.\n",
74 myStamp->getID(),
75 currAtomStamp->getType() );
76
77 painCave.isFatal = 1;
78 simError();
79 }
80
81 //if atom belongs to rigidbody, just skip it
82 if(myStamp->isAtomInRigidBody(i))
83 continue;
84 //get mass and the reference coordinate
85 else{
86
87 mass.push_back(currAtomMass);
88 coor.x() = currAtomStamp->getPosX();
89 coor.y() = currAtomStamp->getPosY();
90 coor.z() = currAtomStamp->getPosZ();
91 refCoords.push_back(coor);
92
93 }
94 }
95
96 for(int i = 0; i < nRigidBodies; i++){
97 coor.x() = 0;
98 coor.y() = 0;
99 coor.z() = 0;
100 totMassInRb = 0;
101
102 for(int j = 0; j < nAtomsInRb; j++){
103
104 currAtomMass = getAtomMass(currAtomStamp->getType(), myFF);
105 totMassInRb += currAtomMass;
106
107 coor.x() += currAtomStamp->getPosX() * currAtomMass;
108 coor.y() += currAtomStamp->getPosY() * currAtomMass;
109 coor.z() += currAtomStamp->getPosZ() * currAtomMass;
110 }
111
112 mass.push_back(totMassInRb);
113 coor /= totMassInRb;
114 refCoords.push_back(coor);
115 }
116
117
118 //calculate the reference center of mass
119 molMass = 0;
120 refMolCom.x() = 0;
121 refMolCom.y() = 0;
122 refMolCom.z() = 0;
123
124 for(int i = 0; i < nIntegrableObjects; i++){
125 refMolCom += refCoords[i] * mass[i];
126 molMass += mass[i];
127 }
128
129 refMolCom /= molMass;
130
131 //move the reference center of mass to (0,0,0) and adjust the reference coordinate
132 //of the integrabel objects
133 for(int i = 0; i < nIntegrableObjects; i++)
134 refCoords[i] -= refMolCom;
135 }
136
137
138
139 double getAtomMass(const std::string& at, ForceField* myFF) {
140 double mass;
141 AtomType* atomType= myFF->getAtomType(at);
142 if (atomType != NULL) {
143 mass = atomType->getMass();
144 } else {
145 mass = 0.0;
146 std::cerr << "Can not find AtomType: " << at << std::endl;
147 }
148 return mass;
149 }
150
151 double getMolMass(MoleculeStamp *molStamp, ForceField *myFF) {
152 int nAtoms;
153 double totMass = 0;
154 nAtoms = molStamp->getNAtoms();
155
156 for(size_t i = 0; i < nAtoms; i++) {
157 AtomStamp *currAtomStamp = molStamp->getAtom(i);
158 totMass += getAtomMass(currAtomStamp->getType(), myFF);
159 }
160 return totMass;
161 }
162 RotMat3x3d latVec2RotMat(const Vector3d& lv){
163
164 double theta =acos(lv[2]);
165 double phi = atan2(lv[1], lv[0]);
166 double psi = 0;
167
168 return RotMat3x3d(phi, theta, psi);
169
170 }
171 }
172