ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/OtherVisitor.cpp
Revision: 1119
Committed: Mon Apr 19 17:44:48 2004 UTC (20 years, 2 months ago) by tim
File size: 8027 byte(s)
Log Message:
Dump2XYZ is almost working except atoms in rigidbody are double counted

File Contents

# Content
1 #include "OtherVisitor.hpp"
2 #include "DirectionalAtom.hpp"
3 #include "RigidBody.hpp"
4 #include "Molecule.hpp"
5 #include "SimInfo.hpp"
6 //----------------------------------------------------------------------------//
7 void IgnoreVisitor::visit(Atom* atom){
8 if(isIgnoreType(atom->getType()))
9 internalVisit(atom);
10 }
11
12 void IgnoreVisitor::visit(DirectionalAtom* datom){
13 if(isIgnoreType(datom->getType()))
14 internalVisit(datom);
15 }
16
17 void IgnoreVisitor::visit(RigidBody* rb){
18 if(isIgnoreType(rb->getType()))
19 internalVisit(rb);
20 }
21
22 bool IgnoreVisitor::isIgnoreType(const string& name){
23 return itList.find(name) != itList.end() ? true : false;
24 }
25
26 void IgnoreVisitor::internalVisit(StuntDouble* sd){
27 GenericData* data;
28 data = sd->getProperty("IGNORE");
29
30 //if this stuntdoulbe is already marked as ignore just skip it
31 if (data == NULL){
32 data = new GenericData;
33 data->setID("IGNORE");
34 sd->addProperty(data);
35 }
36
37 }
38
39 const string IgnoreVisitor::toString(){
40 char buffer[65535];
41 string result;
42 set<string>::iterator i;
43
44 sprintf(buffer ,"------------------------------------------------------------------\n");
45 result += buffer;
46
47 sprintf(buffer ,"Visitor name: %s", visitorName.c_str());
48 result += buffer;
49
50 //print the ignore type list
51 sprintf(buffer , "Ignore type list contains below types:\n");
52 result += buffer;
53
54 for(i = itList.begin(); i != itList.end(); ++i){
55 sprintf(buffer ,"%s,\t", i->c_str());
56 result += buffer;
57
58 }
59 sprintf(buffer ,"\n");
60 result += buffer;
61
62 sprintf(buffer ,"------------------------------------------------------------------\n");
63 result += buffer;
64
65 return buffer;
66 }
67
68 //----------------------------------------------------------------------------//
69
70 void WrappingVisitor::visit(Atom* atom){
71 internalVisit(atom);
72 }
73 void WrappingVisitor::visit(DirectionalAtom* datom){
74 internalVisit(datom);
75 }
76
77 void WrappingVisitor::visit(RigidBody* rb){
78 internalVisit(rb);
79 }
80
81 void WrappingVisitor::internalVisit(StuntDouble* sd){
82 GenericData* data;
83 AtomData* atomData;
84 AtomInfo* atomInfo;
85 double pos[3];
86 vector<AtomInfo*>::iterator i;
87
88 data = sd->getProperty("ATOMDATA");
89 if(data != NULL)
90 atomData = dynamic_cast<AtomData*>(data);
91 if(atomData == NULL)
92 return;
93 else
94 return;
95
96 for(atomInfo = atomData->beginAtomInfo(i); atomInfo != NULL; atomData->nextAtomInfo(i))
97 info->wrapVector(atomInfo->pos);
98
99 }
100
101 //----------------------------------------------------------------------------//
102
103 ReplicateVisitor::ReplicateVisitor(SimInfo* info, IntVec3 replicateOpt) : BaseVisitor(){
104 this->info = info;
105 visitorName = "ReplicateVisitor";
106 this->replicateOpt = replicateOpt;
107 //generate the replicate directions
108 for(int i = 0; i < replicateOpt[0]; i ++)
109 for(int j = 0; i < replicateOpt[1]; j ++)
110 for(int k = 0; i < replicateOpt[2]; k ++)
111 //skip original frame
112 if(i == 0 && j ==0 && k ==0)
113 continue;
114 else
115 dir.push_back(IntVec3(i, j, k));
116
117 }
118 void ReplicateVisitor::visit(Atom* atom){
119 internalVisit(atom);
120 }
121 void ReplicateVisitor::visit(DirectionalAtom* datom){
122 internalVisit(datom);
123 }
124
125 void ReplicateVisitor::visit(RigidBody* rb){
126 internalVisit(rb);
127 }
128
129 void ReplicateVisitor::internalVisit(StuntDouble* sd){
130 GenericData* data;
131 AtomData* atomData;
132 AtomInfo* atomInfo;
133 double box[3][3];
134 vector<AtomInfo*> atomInfoList;
135 IntVec3 dir;
136
137 //if there is not atom data, just skip it
138 data = sd->getProperty("ATOMDATA");
139 if(data != NULL)
140 atomData = dynamic_cast<AtomData*>(data);
141 if(atomData == NULL)
142 return;
143 else
144 return;
145
146
147 info->getBoxM(box);
148
149 atomInfoList = atomData->getData();
150
151 replicate(atomInfoList, atomData, box);
152
153 }
154
155 void ReplicateVisitor::replicate(vector<AtomInfo*>& infoList, AtomData* data, double boxM[3][3]){
156 AtomInfo * newAtomInfo;
157 vector<IntVec3>::iterator dirIter;
158 vector<AtomInfo*>::iterator i;
159
160 for(dirIter = dir.begin(); dirIter != dir.end(); ++dirIter){
161 for(i = infoList.begin(); i != infoList.end(); i++){
162 newAtomInfo = new AtomInfo;
163 *newAtomInfo = *(*i);
164
165 for(int j = 0; j < 3; j++)
166 newAtomInfo->pos[j] += (*dirIter)[0] * boxM[j][0] + (*dirIter)[1]* boxM[j][1] + (*dirIter)[2] * boxM[j][2];
167
168 data->addAtomInfo(newAtomInfo);
169 }
170 }// end for(dirIter)
171 }
172
173 const string ReplicateVisitor::toString(){
174 char buffer[65535];
175 string result;
176 set<string>::iterator i;
177
178 sprintf(buffer ,"------------------------------------------------------------------\n");
179 result += buffer;
180
181 sprintf(buffer ,"Visitor name: %s", visitorName.c_str());
182 result += buffer;
183
184 //print the replicate direction
185 sprintf(buffer , "repeatX = %d:\n", replicateOpt[0]);
186 result += buffer;
187
188 sprintf(buffer , "repeatY = %d:\n", replicateOpt[1]);
189 result += buffer;
190
191 sprintf(buffer , "repeatZ = %d:\n", replicateOpt[2]);
192 result += buffer;
193
194
195 sprintf(buffer,"------------------------------------------------------------------\n");
196 result += buffer;
197
198 return result;
199 }
200
201 //----------------------------------------------------------------------------//
202
203 XYZVisitor::XYZVisitor(SimInfo* info, bool printDipole) : BaseVisitor(){
204 this->info = info;
205 visitorName = "XYZVisitor";
206 this->printDipole = printDipole;
207 }
208
209 void XYZVisitor::visit(Atom* atom){
210 if(!isIgnore(atom))
211 internalVisit(atom);
212 }
213
214 void XYZVisitor::visit(DirectionalAtom* datom){
215 if(!isIgnore(datom))
216 internalVisit(datom);
217 }
218
219 void XYZVisitor::visit(RigidBody* rb){
220 if(!isIgnore(rb))
221 internalVisit(rb);
222
223 }
224
225 void XYZVisitor::internalVisit(StuntDouble* sd){
226 GenericData* data;
227 AtomData* atomData;
228 AtomInfo* atomInfo;
229 vector<AtomInfo*>::iterator i;
230 char buffer[1024];
231
232 //if there is not atom data, just skip it
233 data = sd->getProperty("ATOMDATA");
234 if(data != NULL){
235 atomData = dynamic_cast<AtomData*>(data);
236 if(atomData == NULL)
237 return;
238 }
239 else
240 return;
241
242 for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){
243
244 if(printDipole)
245 sprintf(buffer, "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f",
246 atomInfo->AtomType.c_str(),
247 atomInfo->pos[0],
248 atomInfo->pos[1],
249 atomInfo->pos[2],
250 atomInfo->dipole[0],
251 atomInfo->dipole[1],
252 atomInfo->dipole[2]);
253 else
254 sprintf(buffer, "%s%15.8f%15.8f%15.8f",
255 atomInfo->AtomType.c_str(),
256 atomInfo->pos[0],
257 atomInfo->pos[1],
258 atomInfo->pos[2]);
259 }
260
261 frame.push_back(buffer);
262
263 }
264
265 bool XYZVisitor::isIgnore(StuntDouble* sd){
266 GenericData* data;
267
268 data = sd->getProperty("IGNORE");
269 return data ==NULL ? false : true;
270 }
271
272 void XYZVisitor::writeFrame(ostream& outStream){
273 vector<string>::iterator i;
274 double box[3][3];
275 char buffer[1024];
276
277 if(frame.size() == 0)
278 cerr << "Current Frame does not contain any atoms" << endl;
279
280 //total number of atoms
281 outStream << frame.size() << endl;
282
283 //write comment line
284 info->getBoxM(box);
285 sprintf(buffer,"%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f",
286 info->getTime(),
287 box[0][0], box[0][1], box[0][2],
288 box[1][0], box[1][1], box[1][2],
289 box[2][0], box[2][1], box[2][2]);
290
291 outStream << buffer << endl;
292
293 for(i = frame.begin(); i != frame.end(); ++i)
294 outStream << *i << endl;
295 }
296
297 //----------------------------------------------------------------------------//
298
299 void PrepareVisitor::internalVisit(StuntDouble * sd){
300 GenericData* data;
301 AtomData* atomData;
302
303 //if visited property is existed, remove it
304 data = sd->getProperty("VISITED");
305 if(data != NULL){
306 sd->removeProperty("VISITED");
307 }
308
309 //remove atomdata
310 data = sd->getProperty("ATOMDATA");
311 if(data != NULL){
312 atomData = dynamic_cast<AtomData*>(data);
313 if(atomData != NULL)
314 sd->removeProperty("ATOMDATA");
315 }
316
317 }
318

Properties

Name Value
svn:executable *