ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/AtomVisitor.cpp
Revision: 1252
Committed: Mon Jun 7 14:26:33 2004 UTC (20 years, 1 month ago) by gezelter
File size: 5925 byte(s)
Log Message:
Fixes from gcc -Wall

File Contents

# Content
1 #include <cstring>
2 #include "AtomVisitor.hpp"
3 #include "DirectionalAtom.hpp"
4 #include "MatVec3.h"
5 #include "RigidBody.hpp"
6
7 void BaseAtomVisitor::visit(RigidBody* rb){
8 //vector<Atom*> myAtoms;
9 //vector<Atom*>::iterator atomIter;
10
11 //myAtoms = rb->getAtoms();
12
13 //for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter)
14 // (*atomIter)->accept(this);
15 }
16
17 void BaseAtomVisitor::setVisited(Atom* atom){
18 GenericData* data;
19 data = atom->getProperty("VISITED");
20
21 //if visited property is not existed, add it as new property
22 if(data == NULL){
23 data = new GenericData();
24 data->setID("VISITED");
25 atom->addProperty(data);
26 }
27 }
28
29 bool BaseAtomVisitor::isVisited(Atom* atom){
30 GenericData* data;
31 data = atom->getProperty("VISITED");
32 return data == NULL ? false : true;
33 }
34
35 void SSDAtomVisitor::visit(DirectionalAtom* datom){
36
37 vector<AtomInfo*> atoms;
38
39 //we need to convert SSD into 4 differnet atoms
40 //one oxygen atom, two hydrogen atoms and one pseudo atom which is the center of the mass
41 //of the water with a dipole moment
42 double h1[3] = {0.0, -0.75695, 0.5206};
43 double h2[3] = {0.0, 0.75695, 0.5206};
44 double ox[3] = {0.0, 0.0, -0.0654};
45 double u[3] = {0, 0, 1};
46 double rotMatrix[3][3];
47 double rotTrans[3][3];
48 AtomInfo* atomInfo;
49 double pos[3];
50 double newVec[3];
51 double q[4];
52 AtomData* atomData;
53 GenericData* data;
54 bool haveAtomData;
55
56 //if atom is not SSD atom, just skip it
57 if(strcmp(datom->getType(), "SSD"))
58 return;
59
60 data = datom->getProperty("ATOMDATA");
61 if(data != NULL){
62
63 atomData = dynamic_cast<AtomData*>(data);
64 if(atomData == NULL){
65 cerr << "can not get Atom Data from " << datom->getType() << endl;
66 atomData = new AtomData;
67 haveAtomData = false;
68 }
69 else
70 haveAtomData = true;
71 }
72 else{
73 atomData = new AtomData;
74 haveAtomData = false;
75 }
76
77
78 datom->getPos(pos);
79 datom->getQ(q);
80 datom->getA(rotMatrix);
81
82 // We need A^T to convert from body-fixed to space-fixed:
83 transposeMat3(rotMatrix, rotTrans);
84
85 //center of mass of the water molecule
86 matVecMul3(rotTrans, u, newVec);
87 atomInfo = new AtomInfo;
88 atomInfo->AtomType = "X";
89 atomInfo->pos[0] = pos[0];
90 atomInfo->pos[1] = pos[1];
91 atomInfo->pos[2] = pos[2];
92 atomInfo->dipole[0] = newVec[0];
93 atomInfo->dipole[1] = newVec[1];
94 atomInfo->dipole[2] = newVec[2];
95
96 atomData->addAtomInfo(atomInfo);
97
98 //oxygen
99 matVecMul3(rotTrans, ox, newVec);
100 atomInfo = new AtomInfo;
101 atomInfo->AtomType = "O";
102 atomInfo->pos[0] = pos[0] + newVec[0];
103 atomInfo->pos[1] = pos[1] + newVec[1];
104 atomInfo->pos[2] = pos[2] + newVec[2];
105 atomInfo->dipole[0] = 0.0;
106 atomInfo->dipole[1] = 0.0;
107 atomInfo->dipole[2] = 0.0;
108 atomData->addAtomInfo(atomInfo);
109
110
111 //hydrogen1
112 matVecMul3(rotTrans, h1, newVec);
113 atomInfo = new AtomInfo;
114 atomInfo->AtomType = "H";
115 atomInfo->pos[0] = pos[0] + newVec[0];
116 atomInfo->pos[1] = pos[1] + newVec[1];
117 atomInfo->pos[2] = pos[2] + newVec[2];
118 atomInfo->dipole[0] = 0.0;
119 atomInfo->dipole[1] = 0.0;
120 atomInfo->dipole[2] = 0.0;
121 atomData->addAtomInfo(atomInfo);
122
123 //hydrogen2
124 matVecMul3(rotTrans, h2, newVec);
125 atomInfo = new AtomInfo;
126 atomInfo->AtomType = "H";
127 atomInfo->pos[0] = pos[0] + newVec[0];
128 atomInfo->pos[1] = pos[1] + newVec[1];
129 atomInfo->pos[2] = pos[2] + newVec[2];
130 atomInfo->dipole[0] = 0.0;
131 atomInfo->dipole[1] = 0.0;
132 atomInfo->dipole[2] = 0.0;
133 atomData->addAtomInfo(atomInfo);
134
135 //add atom data into atom's property
136
137 if(!haveAtomData){
138 atomData->setID("ATOMDATA");
139 datom->addProperty(atomData);
140 }
141
142 setVisited(datom);
143
144 }
145
146 const string SSDAtomVisitor::toString(){
147 char buffer[65535];
148 string result;
149
150 sprintf(buffer ,"------------------------------------------------------------------\n");
151 result += buffer;
152
153 sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
154 result += buffer;
155
156 sprintf(buffer , "Visitor Description: Convert SSD into 4 different atoms\n");
157 result += buffer;
158
159 sprintf(buffer ,"------------------------------------------------------------------\n");
160 result += buffer;
161
162 return result;
163 }
164
165 //----------------------------------------------------------------------------//
166
167 void DefaultAtomVisitor::visit(Atom* atom){
168 AtomData* atomData;
169 AtomInfo* atomInfo;
170 double pos[3];
171
172 if(isVisited(atom))
173 return;
174
175 atomInfo =new AtomInfo;
176
177 atomData = new AtomData;
178 atomData->setID("ATOMDATA");
179
180 atom->getPos(pos);
181 atomInfo->AtomType = atom->getType();
182 atomInfo->pos[0] = pos[0];
183 atomInfo->pos[1] = pos[1];
184 atomInfo->pos[2] = pos[2];
185 atomInfo->dipole[0] = 0.0;
186 atomInfo->dipole[1] = 0.0;
187 atomInfo->dipole[2] = 0.0;
188
189
190 atomData->addAtomInfo(atomInfo);
191
192 atom->addProperty(atomData);
193
194 setVisited(atom);
195 }
196 void DefaultAtomVisitor::visit(DirectionalAtom* datom){
197 AtomData* atomData;
198 AtomInfo* atomInfo;
199 double pos[3];
200 double u[3];
201
202 if(isVisited(datom))
203 return;
204
205 datom->getPos(pos);
206 datom->getU(u);
207
208 atomData = new AtomData;
209 atomData->setID("ATOMDATA");
210 atomInfo =new AtomInfo;
211
212 atomInfo->AtomType = datom->getType();
213 atomInfo->pos[0] = pos[0];
214 atomInfo->pos[1] = pos[1];
215 atomInfo->pos[2] = pos[2];
216 atomInfo->dipole[0] = u[0];
217 atomInfo->dipole[1] = u[1];
218 atomInfo->dipole[2] = u[2];
219
220 atomData->addAtomInfo(atomInfo);
221
222 datom->addProperty(atomData);
223
224 setVisited(datom);
225 }
226
227
228 const string DefaultAtomVisitor::toString(){
229 char buffer[65535];
230 string result;
231
232 sprintf(buffer ,"------------------------------------------------------------------\n");
233 result += buffer;
234
235 sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str());
236 result += buffer;
237
238 sprintf(buffer , "Visitor Description: copy atom infomation into atom data\n");
239 result += buffer;
240
241 sprintf(buffer ,"------------------------------------------------------------------\n");
242 result += buffer;
243
244 return result;
245 }

Properties

Name Value
svn:executable *