3 |
|
#include "primitives/RigidBody.hpp" |
4 |
|
#include "primitives/Molecule.hpp" |
5 |
|
#include "brains/SimInfo.hpp" |
6 |
– |
|
6 |
|
namespace oopse { |
7 |
|
|
8 |
|
//----------------------------------------------------------------------------// |
9 |
< |
void IgnoreVisitor::visit(Atom* atom){ |
10 |
< |
if(isIgnoreType(atom->getType())) |
11 |
< |
internalVisit(atom); |
9 |
> |
void IgnoreVisitor::visit(Atom *atom) { |
10 |
> |
if (isIgnoreType(atom->getType())) |
11 |
> |
internalVisit(atom); |
12 |
|
} |
13 |
|
|
14 |
< |
void IgnoreVisitor::visit(DirectionalAtom* datom){ |
15 |
< |
if(isIgnoreType(datom->getType())) |
16 |
< |
internalVisit(datom); |
14 |
> |
void IgnoreVisitor::visit(DirectionalAtom *datom) { |
15 |
> |
if (isIgnoreType(datom->getType())) |
16 |
> |
internalVisit(datom); |
17 |
|
} |
18 |
|
|
19 |
< |
void IgnoreVisitor::visit(RigidBody* rb){ |
20 |
< |
vector<Atom*> myAtoms; |
21 |
< |
vector<Atom*>::iterator atomIter; |
22 |
< |
AtomInfo* atomInfo; |
24 |
< |
|
25 |
< |
if(isIgnoreType(rb->getType())){ |
26 |
< |
|
27 |
< |
internalVisit(rb); |
19 |
> |
void IgnoreVisitor::visit(RigidBody *rb) { |
20 |
> |
std::vector<Atom *> myAtoms; |
21 |
> |
std::vector<Atom *>::iterator atomIter; |
22 |
> |
AtomInfo * atomInfo; |
23 |
|
|
24 |
< |
myAtoms = rb->getAtoms(); |
25 |
< |
|
31 |
< |
for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter) |
32 |
< |
internalVisit(*atomIter); |
24 |
> |
if (isIgnoreType(rb->getType())) { |
25 |
> |
internalVisit(rb); |
26 |
|
|
27 |
< |
} |
28 |
< |
|
27 |
> |
myAtoms = rb->getAtoms(); |
28 |
> |
|
29 |
> |
for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter ) |
30 |
> |
internalVisit(*atomIter); |
31 |
> |
} |
32 |
|
} |
33 |
|
|
34 |
< |
bool IgnoreVisitor::isIgnoreType(const string& name){ |
35 |
< |
return itList.find(name) != itList.end() ? true : false; |
34 |
> |
bool IgnoreVisitor::isIgnoreType(const std::string&name) { |
35 |
> |
return itList.find(name) != itList.end() ? true : false; |
36 |
|
} |
37 |
|
|
38 |
< |
void IgnoreVisitor::internalVisit(StuntDouble* sd){ |
39 |
< |
GenericData* data; |
40 |
< |
data = sd->getPropertyByName("IGNORE"); |
38 |
> |
void IgnoreVisitor::internalVisit(StuntDouble *sd) { |
39 |
> |
GenericData *data; |
40 |
> |
data = sd->getPropertyByName("IGNORE"); |
41 |
|
|
42 |
< |
//if this stuntdoulbe is already marked as ignore just skip it |
43 |
< |
if (data == NULL){ |
44 |
< |
data = new GenericData; |
45 |
< |
data->setID("IGNORE"); |
46 |
< |
sd->addProperty(data); |
47 |
< |
} |
52 |
< |
|
42 |
> |
//if this stuntdoulbe is already marked as ignore just skip it |
43 |
> |
if (data == NULL) { |
44 |
> |
data = new GenericData; |
45 |
> |
data->setID("IGNORE"); |
46 |
> |
sd->addProperty(data); |
47 |
> |
} |
48 |
|
} |
49 |
|
|
50 |
< |
const string IgnoreVisitor::toString(){ |
51 |
< |
char buffer[65535]; |
52 |
< |
string result; |
53 |
< |
set<string>::iterator i; |
59 |
< |
|
60 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
61 |
< |
result += buffer; |
50 |
> |
const std::string IgnoreVisitor::toString() { |
51 |
> |
char buffer[65535]; |
52 |
> |
std::string result; |
53 |
> |
std::set<std::string>::iterator i; |
54 |
|
|
55 |
< |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
56 |
< |
result += buffer; |
55 |
> |
sprintf(buffer, |
56 |
> |
"------------------------------------------------------------------\n"); |
57 |
> |
result += buffer; |
58 |
|
|
59 |
< |
sprintf(buffer ,"Visitor Description: ignore stuntdoubles\n"); |
60 |
< |
result += buffer; |
59 |
> |
sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); |
60 |
> |
result += buffer; |
61 |
|
|
62 |
< |
//print the ignore type list |
63 |
< |
sprintf(buffer , "Ignore type list contains below types:\n"); |
71 |
< |
result += buffer; |
62 |
> |
sprintf(buffer, "Visitor Description: ignore stuntdoubles\n"); |
63 |
> |
result += buffer; |
64 |
|
|
65 |
< |
for(i = itList.begin(); i != itList.end(); ++i){ |
66 |
< |
sprintf(buffer ,"%s\t", i->c_str()); |
65 |
> |
//print the ignore type list |
66 |
> |
sprintf(buffer, "Ignore type list contains below types:\n"); |
67 |
|
result += buffer; |
68 |
|
|
69 |
< |
} |
70 |
< |
sprintf(buffer ,"\n"); |
71 |
< |
result += buffer; |
69 |
> |
for( i = itList.begin(); i != itList.end(); ++i ) { |
70 |
> |
sprintf(buffer, "%s\t", i->c_str()); |
71 |
> |
result += buffer; |
72 |
> |
} |
73 |
|
|
74 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
75 |
< |
result += buffer; |
74 |
> |
sprintf(buffer, "\n"); |
75 |
> |
result += buffer; |
76 |
|
|
77 |
< |
return result; |
77 |
> |
sprintf(buffer, |
78 |
> |
"------------------------------------------------------------------\n"); |
79 |
> |
result += buffer; |
80 |
> |
|
81 |
> |
return result; |
82 |
|
} |
83 |
|
|
84 |
|
//----------------------------------------------------------------------------// |
85 |
|
|
86 |
< |
void WrappingVisitor::visit(Atom* atom){ |
87 |
< |
internalVisit(atom); |
86 |
> |
void WrappingVisitor::visit(Atom *atom) { |
87 |
> |
internalVisit(atom); |
88 |
|
} |
89 |
< |
void WrappingVisitor::visit(DirectionalAtom* datom){ |
90 |
< |
internalVisit(datom); |
89 |
> |
|
90 |
> |
void WrappingVisitor::visit(DirectionalAtom *datom) { |
91 |
> |
internalVisit(datom); |
92 |
|
} |
93 |
|
|
94 |
< |
void WrappingVisitor::visit(RigidBody* rb){ |
95 |
< |
internalVisit(rb); |
94 |
> |
void WrappingVisitor::visit(RigidBody *rb) { |
95 |
> |
internalVisit(rb); |
96 |
|
} |
97 |
|
|
98 |
< |
void WrappingVisitor::internalVisit(StuntDouble* sd){ |
99 |
< |
GenericData* data; |
100 |
< |
AtomData* atomData; |
101 |
< |
AtomInfo* atomInfo; |
102 |
< |
vector<AtomInfo*>::iterator i; |
98 |
> |
void WrappingVisitor::internalVisit(StuntDouble *sd) { |
99 |
> |
GenericData * data; |
100 |
> |
AtomData * atomData; |
101 |
> |
AtomInfo * atomInfo; |
102 |
> |
std::vector<AtomInfo *>::iterator i; |
103 |
|
|
104 |
< |
data = sd->getPropertyByName("ATOMDATA"); |
107 |
< |
if(data != NULL){ |
108 |
< |
atomData = dynamic_cast<AtomData*>(data); |
109 |
< |
if(atomData == NULL) |
110 |
< |
return; |
111 |
< |
} |
112 |
< |
else |
113 |
< |
return; |
104 |
> |
data = sd->getPropertyByName("ATOMDATA"); |
105 |
|
|
106 |
< |
for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)) |
107 |
< |
info->wrapVector(atomInfo->pos); |
106 |
> |
if (data != NULL) { |
107 |
> |
atomData = dynamic_cast<AtomData *>(data); |
108 |
|
|
109 |
< |
|
109 |
> |
if (atomData == NULL) |
110 |
> |
return; |
111 |
> |
} else |
112 |
> |
return; |
113 |
> |
|
114 |
> |
Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot(); |
115 |
> |
|
116 |
> |
for( atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i) ) { |
117 |
> |
currSnapshot->wrapVector(atomInfo->pos); |
118 |
> |
} |
119 |
|
} |
120 |
|
|
121 |
< |
const string WrappingVisitor::toString(){ |
122 |
< |
char buffer[65535]; |
123 |
< |
string result; |
124 |
< |
|
125 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
126 |
< |
result += buffer; |
121 |
> |
const std::string WrappingVisitor::toString() { |
122 |
> |
char buffer[65535]; |
123 |
> |
std::string result; |
124 |
|
|
125 |
< |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
126 |
< |
result += buffer; |
125 |
> |
sprintf(buffer, |
126 |
> |
"------------------------------------------------------------------\n"); |
127 |
> |
result += buffer; |
128 |
|
|
129 |
< |
sprintf(buffer ,"Visitor Description: wrapping atoms back to periodic box\n"); |
130 |
< |
result += buffer; |
133 |
< |
|
134 |
< |
sprintf(buffer,"------------------------------------------------------------------\n"); |
135 |
< |
result += buffer; |
129 |
> |
sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); |
130 |
> |
result += buffer; |
131 |
|
|
132 |
< |
return result; |
132 |
> |
sprintf(buffer, |
133 |
> |
"Visitor Description: wrapping atoms back to periodic box\n"); |
134 |
> |
result += buffer; |
135 |
> |
|
136 |
> |
sprintf(buffer, |
137 |
> |
"------------------------------------------------------------------\n"); |
138 |
> |
result += buffer; |
139 |
> |
|
140 |
> |
return result; |
141 |
|
} |
142 |
|
|
143 |
|
//----------------------------------------------------------------------------// |
144 |
|
|
145 |
< |
ReplicateVisitor::ReplicateVisitor(SimInfo* info, IntVec3 opt) : BaseVisitor(){ |
146 |
< |
this->info = info; |
147 |
< |
visitorName = "ReplicateVisitor"; |
148 |
< |
this->replicateOpt = opt; |
149 |
< |
//generate the replicate directions |
150 |
< |
for(int i = 0; i <= replicateOpt[0]; i ++) |
151 |
< |
for(int j = 0; j <= replicateOpt[1]; j ++) |
152 |
< |
for(int k = 0; k <= replicateOpt[2]; k ++) |
153 |
< |
//skip original frame |
154 |
< |
if(i == 0 && j ==0 && k ==0) |
155 |
< |
continue; |
156 |
< |
else |
157 |
< |
dir.push_back(IntVec3(i, j, k)); |
158 |
< |
|
145 |
> |
ReplicateVisitor::ReplicateVisitor(SimInfo *info, Vector3i opt) : |
146 |
> |
BaseVisitor() { |
147 |
> |
this->info = info; |
148 |
> |
visitorName = "ReplicateVisitor"; |
149 |
> |
this->replicateOpt = opt; |
150 |
> |
|
151 |
> |
//generate the replicate directions |
152 |
> |
for( int i = 0; i <= replicateOpt[0]; i++ ) { |
153 |
> |
for( int j = 0; j <= replicateOpt[1]; j++ ) { |
154 |
> |
for( int k = 0; k <= replicateOpt[2]; k++ ) { |
155 |
> |
//skip original frame |
156 |
> |
if (i == 0 && j == 0 && k == 0) { |
157 |
> |
continue; |
158 |
> |
} else { |
159 |
> |
dir.push_back(Vector3i(i, j, k)); |
160 |
> |
} |
161 |
> |
} |
162 |
> |
} |
163 |
> |
} |
164 |
> |
|
165 |
|
} |
166 |
< |
void ReplicateVisitor::visit(Atom* atom){ |
167 |
< |
internalVisit(atom); |
166 |
> |
|
167 |
> |
void ReplicateVisitor::visit(Atom *atom) { |
168 |
> |
internalVisit(atom); |
169 |
|
} |
170 |
< |
void ReplicateVisitor::visit(DirectionalAtom* datom){ |
171 |
< |
internalVisit(datom); |
170 |
> |
|
171 |
> |
void ReplicateVisitor::visit(DirectionalAtom *datom) { |
172 |
> |
internalVisit(datom); |
173 |
|
} |
174 |
|
|
175 |
< |
void ReplicateVisitor::visit(RigidBody* rb){ |
176 |
< |
internalVisit(rb); |
175 |
> |
void ReplicateVisitor::visit(RigidBody *rb) { |
176 |
> |
internalVisit(rb); |
177 |
|
} |
178 |
|
|
179 |
< |
void ReplicateVisitor::internalVisit(StuntDouble* sd){ |
180 |
< |
GenericData* data; |
181 |
< |
AtomData* atomData; |
171 |
< |
AtomInfo* atomInfo; |
172 |
< |
double box[3][3]; |
173 |
< |
vector<AtomInfo*> atomInfoList; |
174 |
< |
IntVec3 dir; |
175 |
< |
|
176 |
< |
//if there is not atom data, just skip it |
177 |
< |
data = sd->getPropertyByName("ATOMDATA"); |
178 |
< |
if(data != NULL){ |
179 |
< |
atomData = dynamic_cast<AtomData*>(data); |
180 |
< |
if(atomData == NULL) |
181 |
< |
return; |
182 |
< |
} |
183 |
< |
else |
184 |
< |
return; |
179 |
> |
void ReplicateVisitor::internalVisit(StuntDouble *sd) { |
180 |
> |
GenericData * data; |
181 |
> |
AtomData * atomData; |
182 |
|
|
183 |
< |
|
184 |
< |
info->getBoxM(box); |
183 |
> |
//if there is not atom data, just skip it |
184 |
> |
data = sd->getPropertyByName("ATOMDATA"); |
185 |
|
|
186 |
< |
atomInfoList = atomData->getData(); |
187 |
< |
|
191 |
< |
replicate(atomInfoList, atomData, box); |
186 |
> |
if (data != NULL) { |
187 |
> |
atomData = dynamic_cast<AtomData *>(data); |
188 |
|
|
189 |
+ |
if (atomData == NULL) { |
190 |
+ |
return; |
191 |
+ |
} |
192 |
+ |
} else { |
193 |
+ |
return; |
194 |
+ |
} |
195 |
+ |
|
196 |
+ |
Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot(); |
197 |
+ |
Mat3x3d box = currSnapshot->getHmat(); |
198 |
+ |
|
199 |
+ |
std::vector<AtomInfo *> atomInfoList = atomData->getData(); |
200 |
+ |
|
201 |
+ |
replicate(atomInfoList, atomData, box); |
202 |
|
} |
203 |
|
|
204 |
< |
void ReplicateVisitor::replicate(vector<AtomInfo*>& infoList, AtomData* data, double boxM[3][3]){ |
205 |
< |
AtomInfo * newAtomInfo; |
206 |
< |
vector<IntVec3>::iterator dirIter; |
207 |
< |
vector<AtomInfo*>::iterator i; |
199 |
< |
|
200 |
< |
for(dirIter = dir.begin(); dirIter != dir.end(); ++dirIter){ |
201 |
< |
for(i = infoList.begin(); i != infoList.end(); i++){ |
202 |
< |
newAtomInfo = new AtomInfo; |
203 |
< |
*newAtomInfo = *(*i); |
204 |
> |
void ReplicateVisitor::replicate(std::vector<AtomInfo *>&infoList, AtomData *data, const Mat3x3d& box) { |
205 |
> |
AtomInfo* newAtomInfo; |
206 |
> |
std::vector<Vector3i>::iterator dirIter; |
207 |
> |
std::vector<AtomInfo *>::iterator i; |
208 |
|
|
209 |
< |
for(int j = 0; j < 3; j++) |
210 |
< |
newAtomInfo->pos[j] += (*dirIter)[0] * boxM[j][0] + (*dirIter)[1]* boxM[j][1] + (*dirIter)[2] * boxM[j][2]; |
209 |
> |
for( dirIter = dir.begin(); dirIter != dir.end(); ++dirIter ) { |
210 |
> |
for( i = infoList.begin(); i != infoList.end(); i++ ) { |
211 |
> |
newAtomInfo = new AtomInfo(); |
212 |
> |
*newAtomInfo = *(*i); |
213 |
|
|
214 |
< |
data->addAtomInfo(newAtomInfo); |
215 |
< |
} |
216 |
< |
}// end for(dirIter) |
214 |
> |
for( int j = 0; j < 3; j++ ) |
215 |
> |
newAtomInfo->pos[j] += (*dirIter)[0]*box(j, 0) + (*dirIter)[1]*box(j, 1) + (*dirIter)[2]*box(j, 2); |
216 |
> |
|
217 |
> |
data->addAtomInfo(newAtomInfo); |
218 |
> |
} |
219 |
> |
} // end for(dirIter) |
220 |
|
} |
221 |
|
|
222 |
< |
const string ReplicateVisitor::toString(){ |
223 |
< |
char buffer[65535]; |
224 |
< |
string result; |
225 |
< |
set<string>::iterator i; |
217 |
< |
|
218 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
219 |
< |
result += buffer; |
222 |
> |
const std::string ReplicateVisitor::toString() { |
223 |
> |
char buffer[65535]; |
224 |
> |
std::string result; |
225 |
> |
std::set<std::string>::iterator i; |
226 |
|
|
227 |
< |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
228 |
< |
result += buffer; |
227 |
> |
sprintf(buffer, |
228 |
> |
"------------------------------------------------------------------\n"); |
229 |
> |
result += buffer; |
230 |
|
|
231 |
< |
sprintf(buffer ,"Visitor Description: replicate the atoms in different direction\n"); |
232 |
< |
result += buffer; |
226 |
< |
|
227 |
< |
//print the replicate direction |
228 |
< |
sprintf(buffer , "repeatX = %d:\n", replicateOpt[0]); |
229 |
< |
result += buffer; |
231 |
> |
sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); |
232 |
> |
result += buffer; |
233 |
|
|
234 |
< |
sprintf(buffer , "repeatY = %d:\n", replicateOpt[1]); |
235 |
< |
result += buffer; |
234 |
> |
sprintf(buffer, |
235 |
> |
"Visitor Description: replicate the atoms in different direction\n"); |
236 |
> |
result += buffer; |
237 |
|
|
238 |
< |
sprintf(buffer , "repeatZ = %d:\n", replicateOpt[2]); |
239 |
< |
result += buffer; |
238 |
> |
//print the replicate direction |
239 |
> |
sprintf(buffer, "repeatX = %d:\n", replicateOpt[0]); |
240 |
> |
result += buffer; |
241 |
|
|
242 |
+ |
sprintf(buffer, "repeatY = %d:\n", replicateOpt[1]); |
243 |
+ |
result += buffer; |
244 |
|
|
245 |
< |
sprintf(buffer,"------------------------------------------------------------------\n"); |
246 |
< |
result += buffer; |
245 |
> |
sprintf(buffer, "repeatZ = %d:\n", replicateOpt[2]); |
246 |
> |
result += buffer; |
247 |
|
|
248 |
< |
return result; |
248 |
> |
sprintf(buffer, |
249 |
> |
"------------------------------------------------------------------\n"); |
250 |
> |
result += buffer; |
251 |
> |
|
252 |
> |
return result; |
253 |
|
} |
254 |
|
|
255 |
|
//----------------------------------------------------------------------------// |
256 |
|
|
257 |
< |
XYZVisitor::XYZVisitor(SimInfo* info, bool printDipole) : BaseVisitor(){ |
258 |
< |
this->info = info; |
259 |
< |
visitorName = "XYZVisitor"; |
260 |
< |
this->printDipole = printDipole; |
257 |
> |
XYZVisitor::XYZVisitor(SimInfo *info, bool printDipole) : |
258 |
> |
BaseVisitor() { |
259 |
> |
this->info = info; |
260 |
> |
visitorName = "XYZVisitor"; |
261 |
> |
this->printDipole = printDipole; |
262 |
|
} |
263 |
|
|
264 |
< |
void XYZVisitor::visit(Atom* atom){ |
265 |
< |
if(!isIgnore(atom)) |
266 |
< |
internalVisit(atom); |
264 |
> |
void XYZVisitor::visit(Atom *atom) { |
265 |
> |
if (!isIgnore(atom)) |
266 |
> |
internalVisit(atom); |
267 |
|
} |
268 |
|
|
269 |
< |
void XYZVisitor::visit(DirectionalAtom* datom){ |
270 |
< |
if(!isIgnore(datom)) |
271 |
< |
internalVisit(datom); |
269 |
> |
void XYZVisitor::visit(DirectionalAtom *datom) { |
270 |
> |
if (!isIgnore(datom)) |
271 |
> |
internalVisit(datom); |
272 |
|
} |
273 |
|
|
274 |
< |
void XYZVisitor::visit(RigidBody* rb){ |
275 |
< |
if(!isIgnore(rb)) |
276 |
< |
internalVisit(rb); |
265 |
< |
|
274 |
> |
void XYZVisitor::visit(RigidBody *rb) { |
275 |
> |
if (!isIgnore(rb)) |
276 |
> |
internalVisit(rb); |
277 |
|
} |
278 |
|
|
279 |
< |
void XYZVisitor::internalVisit(StuntDouble* sd){ |
280 |
< |
GenericData* data; |
281 |
< |
AtomData* atomData; |
282 |
< |
AtomInfo* atomInfo; |
283 |
< |
vector<AtomInfo*>::iterator i; |
284 |
< |
char buffer[1024]; |
274 |
< |
|
275 |
< |
//if there is not atom data, just skip it |
276 |
< |
data = sd->getPropertyByName("ATOMDATA"); |
277 |
< |
if(data != NULL){ |
278 |
< |
atomData = dynamic_cast<AtomData*>(data); |
279 |
< |
if(atomData == NULL) |
280 |
< |
return; |
281 |
< |
} |
282 |
< |
else |
283 |
< |
return; |
279 |
> |
void XYZVisitor::internalVisit(StuntDouble *sd) { |
280 |
> |
GenericData * data; |
281 |
> |
AtomData * atomData; |
282 |
> |
AtomInfo * atomInfo; |
283 |
> |
std::vector<AtomInfo *>::iterator i; |
284 |
> |
char buffer[1024]; |
285 |
|
|
286 |
< |
for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){ |
286 |
> |
//if there is not atom data, just skip it |
287 |
> |
data = sd->getPropertyByName("ATOMDATA"); |
288 |
|
|
289 |
< |
if(printDipole) |
290 |
< |
sprintf(buffer, "%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f", |
289 |
< |
atomInfo->AtomType.c_str(), |
290 |
< |
atomInfo->pos[0], |
291 |
< |
atomInfo->pos[1], |
292 |
< |
atomInfo->pos[2], |
293 |
< |
atomInfo->dipole[0], |
294 |
< |
atomInfo->dipole[1], |
295 |
< |
atomInfo->dipole[2]); |
296 |
< |
else |
297 |
< |
sprintf(buffer, "%s%15.8f%15.8f%15.8f", |
298 |
< |
atomInfo->AtomType.c_str(), |
299 |
< |
atomInfo->pos[0], |
300 |
< |
atomInfo->pos[1], |
301 |
< |
atomInfo->pos[2]); |
289 |
> |
if (data != NULL) { |
290 |
> |
atomData = dynamic_cast<AtomData *>(data); |
291 |
|
|
292 |
< |
frame.push_back(buffer); |
293 |
< |
|
294 |
< |
} |
292 |
> |
if (atomData == NULL) |
293 |
> |
return; |
294 |
> |
} else |
295 |
> |
return; |
296 |
|
|
297 |
+ |
for( atomInfo = atomData->beginAtomInfo(i); atomInfo; |
298 |
+ |
atomInfo = atomData->nextAtomInfo(i) ) { |
299 |
+ |
if (printDipole) |
300 |
+ |
sprintf(buffer, |
301 |
+ |
"%s%15.8f%15.8f%15.8f%15.8f%15.8f%15.8f", |
302 |
+ |
atomInfo->AtomType.c_str(), |
303 |
+ |
atomInfo->pos[0], |
304 |
+ |
atomInfo->pos[1], |
305 |
+ |
atomInfo->pos[2], |
306 |
+ |
atomInfo->dipole[0], |
307 |
+ |
atomInfo->dipole[1], |
308 |
+ |
atomInfo->dipole[2]); else |
309 |
+ |
sprintf(buffer, "%s%15.8f%15.8f%15.8f", |
310 |
+ |
atomInfo->AtomType.c_str(), atomInfo->pos[0], |
311 |
+ |
atomInfo->pos[1], atomInfo->pos[2]); |
312 |
+ |
|
313 |
+ |
frame.push_back(buffer); |
314 |
+ |
} |
315 |
|
} |
316 |
|
|
317 |
< |
bool XYZVisitor::isIgnore(StuntDouble* sd){ |
318 |
< |
GenericData* data; |
319 |
< |
|
320 |
< |
data = sd->getPropertyByName("IGNORE"); |
321 |
< |
return data ==NULL ? false : true; |
317 |
> |
bool XYZVisitor::isIgnore(StuntDouble *sd) { |
318 |
> |
GenericData *data; |
319 |
> |
|
320 |
> |
data = sd->getPropertyByName("IGNORE"); |
321 |
> |
return data == NULL ? false : true; |
322 |
|
} |
323 |
|
|
324 |
< |
void XYZVisitor::writeFrame(ostream& outStream){ |
325 |
< |
vector<string>::iterator i; |
326 |
< |
double box[3][3]; |
319 |
< |
char buffer[1024]; |
324 |
> |
void XYZVisitor::writeFrame(ostream &outStream) { |
325 |
> |
std::vector<std::string>::iterator i; |
326 |
> |
char buffer[1024]; |
327 |
|
|
328 |
< |
if(frame.size() == 0) |
329 |
< |
cerr << "Current Frame does not contain any atoms" << endl; |
328 |
> |
if (frame.size() == 0) |
329 |
> |
cerr << "Current Frame does not contain any atoms" << endl; |
330 |
|
|
331 |
< |
//total number of atoms |
332 |
< |
outStream << frame.size() << endl; |
331 |
> |
//total number of atoms |
332 |
> |
outStream << frame.size() << endl; |
333 |
|
|
334 |
< |
//write comment line |
335 |
< |
info->getBoxM(box); |
336 |
< |
sprintf(buffer,"%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f", |
337 |
< |
info->getTime(), |
338 |
< |
box[0][0], box[0][1], box[0][2], |
339 |
< |
box[1][0], box[1][1], box[1][2], |
340 |
< |
box[2][0], box[2][1], box[2][2]); |
334 |
> |
//write comment line |
335 |
> |
Snapshot* currSnapshot = info->getSnapshotManager()->getCurrentSnapshot(); |
336 |
> |
Mat3x3d box = currSnapshot->getHmat(); |
337 |
> |
|
338 |
> |
sprintf(buffer, |
339 |
> |
"%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f;%15.8f%15.8f%15.8f", |
340 |
> |
currSnapshot->getTime(), |
341 |
> |
box(0, 0), box(0, 1), box(0, 2), |
342 |
> |
box(1, 0), box(1, 1), box(1, 2), |
343 |
> |
box(2, 0), box(2, 1), box(2, 2)); |
344 |
|
|
345 |
< |
outStream << buffer << endl; |
345 |
> |
outStream << buffer << endl; |
346 |
|
|
347 |
< |
for(i = frame.begin(); i != frame.end(); ++i) |
348 |
< |
outStream << *i << endl; |
347 |
> |
for( i = frame.begin(); i != frame.end(); ++i ) |
348 |
> |
outStream << *i << endl; |
349 |
|
} |
350 |
|
|
351 |
< |
const string XYZVisitor::toString(){ |
352 |
< |
char buffer[65535]; |
353 |
< |
string result; |
344 |
< |
|
345 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
346 |
< |
result += buffer; |
351 |
> |
const std::string XYZVisitor::toString() { |
352 |
> |
char buffer[65535]; |
353 |
> |
std::string result; |
354 |
|
|
355 |
< |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
356 |
< |
result += buffer; |
355 |
> |
sprintf(buffer, |
356 |
> |
"------------------------------------------------------------------\n"); |
357 |
> |
result += buffer; |
358 |
|
|
359 |
< |
sprintf(buffer ,"Visitor Description: assemble the atom data and output xyz file\n"); |
360 |
< |
result += buffer; |
353 |
< |
|
354 |
< |
sprintf(buffer,"------------------------------------------------------------------\n"); |
355 |
< |
result += buffer; |
359 |
> |
sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); |
360 |
> |
result += buffer; |
361 |
|
|
362 |
< |
return result; |
362 |
> |
sprintf(buffer, |
363 |
> |
"Visitor Description: assemble the atom data and output xyz file\n"); |
364 |
> |
result += buffer; |
365 |
> |
|
366 |
> |
sprintf(buffer, |
367 |
> |
"------------------------------------------------------------------\n"); |
368 |
> |
result += buffer; |
369 |
> |
|
370 |
> |
return result; |
371 |
|
} |
372 |
|
|
373 |
|
//----------------------------------------------------------------------------// |
374 |
|
|
375 |
< |
void PrepareVisitor::internalVisit(Atom * atom){ |
376 |
< |
GenericData* data; |
377 |
< |
AtomData* atomData; |
375 |
> |
void PrepareVisitor::internalVisit(Atom *atom) { |
376 |
> |
GenericData *data; |
377 |
> |
AtomData * atomData; |
378 |
|
|
379 |
< |
//if visited property is existed, remove it |
380 |
< |
data = atom->getPropertyByName("VISITED"); |
368 |
< |
if(data != NULL){ |
369 |
< |
atom->removeProperty("VISITED"); |
370 |
< |
} |
379 |
> |
//if visited property is existed, remove it |
380 |
> |
data = atom->getPropertyByName("VISITED"); |
381 |
|
|
382 |
< |
//remove atomdata |
383 |
< |
data = atom->getPropertyByName("ATOMDATA"); |
384 |
< |
if(data != NULL){ |
385 |
< |
atomData = dynamic_cast<AtomData*>(data); |
386 |
< |
if(atomData != NULL) |
387 |
< |
atom->removeProperty("ATOMDATA"); |
388 |
< |
} |
389 |
< |
|
382 |
> |
if (data != NULL) { |
383 |
> |
atom->removeProperty("VISITED"); |
384 |
> |
} |
385 |
> |
|
386 |
> |
//remove atomdata |
387 |
> |
data = atom->getPropertyByName("ATOMDATA"); |
388 |
> |
|
389 |
> |
if (data != NULL) { |
390 |
> |
atomData = dynamic_cast<AtomData *>(data); |
391 |
> |
|
392 |
> |
if (atomData != NULL) |
393 |
> |
atom->removeProperty("ATOMDATA"); |
394 |
> |
} |
395 |
|
} |
396 |
|
|
397 |
< |
void PrepareVisitor::internalVisit(RigidBody * rb){ |
398 |
< |
GenericData* data; |
399 |
< |
AtomData* atomData; |
400 |
< |
vector<Atom*> myAtoms; |
401 |
< |
vector<Atom*>::iterator atomIter; |
387 |
< |
|
388 |
< |
//if visited property is existed, remove it |
389 |
< |
data = rb->getPropertyByName("VISITED"); |
390 |
< |
if(data != NULL){ |
391 |
< |
rb->removeProperty("VISITED"); |
392 |
< |
} |
397 |
> |
void PrepareVisitor::internalVisit(RigidBody *rb) { |
398 |
> |
GenericData* data; |
399 |
> |
AtomData* atomData; |
400 |
> |
std::vector<Atom *> myAtoms; |
401 |
> |
std::vector<Atom *>::iterator atomIter; |
402 |
|
|
403 |
< |
//remove atomdata |
404 |
< |
data = rb->getPropertyByName("ATOMDATA"); |
396 |
< |
if(data != NULL){ |
397 |
< |
atomData = dynamic_cast<AtomData*>(data); |
398 |
< |
if(atomData != NULL) |
399 |
< |
rb->removeProperty("ATOMDATA"); |
400 |
< |
} |
403 |
> |
//if visited property is existed, remove it |
404 |
> |
data = rb->getPropertyByName("VISITED"); |
405 |
|
|
406 |
< |
myAtoms = rb->getAtoms(); |
407 |
< |
|
408 |
< |
for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter) |
409 |
< |
internalVisit (*atomIter); |
406 |
> |
if (data != NULL) { |
407 |
> |
rb->removeProperty("VISITED"); |
408 |
> |
} |
409 |
> |
|
410 |
> |
//remove atomdata |
411 |
> |
data = rb->getPropertyByName("ATOMDATA"); |
412 |
> |
|
413 |
> |
if (data != NULL) { |
414 |
> |
atomData = dynamic_cast<AtomData *>(data); |
415 |
> |
|
416 |
> |
if (atomData != NULL) |
417 |
> |
rb->removeProperty("ATOMDATA"); |
418 |
> |
} |
419 |
> |
|
420 |
> |
myAtoms = rb->getAtoms(); |
421 |
> |
|
422 |
> |
for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter ) |
423 |
> |
internalVisit(*atomIter); |
424 |
|
} |
425 |
|
|
426 |
< |
const string PrepareVisitor::toString(){ |
427 |
< |
char buffer[65535]; |
428 |
< |
string result; |
411 |
< |
|
412 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
413 |
< |
result += buffer; |
426 |
> |
const std::string PrepareVisitor::toString() { |
427 |
> |
char buffer[65535]; |
428 |
> |
std::string result; |
429 |
|
|
430 |
< |
sprintf(buffer ,"Visitor name: %s", visitorName.c_str()); |
431 |
< |
result += buffer; |
430 |
> |
sprintf(buffer, |
431 |
> |
"------------------------------------------------------------------\n"); |
432 |
> |
result += buffer; |
433 |
|
|
434 |
< |
sprintf(buffer ,"Visitor Description: prepare for operation of other vistors\n"); |
435 |
< |
result += buffer; |
434 |
> |
sprintf(buffer, "Visitor name: %s", visitorName.c_str()); |
435 |
> |
result += buffer; |
436 |
|
|
437 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
438 |
< |
result += buffer; |
437 |
> |
sprintf(buffer, |
438 |
> |
"Visitor Description: prepare for operation of other vistors\n"); |
439 |
> |
result += buffer; |
440 |
|
|
441 |
< |
return result; |
441 |
> |
sprintf(buffer, |
442 |
> |
"------------------------------------------------------------------\n"); |
443 |
> |
result += buffer; |
444 |
> |
|
445 |
> |
return result; |
446 |
|
} |
447 |
|
|
448 |
|
//----------------------------------------------------------------------------// |
449 |
|
|
450 |
< |
WaterTypeVisitor:: WaterTypeVisitor(){ |
451 |
< |
visitorName = "WaterTypeVisitor"; |
452 |
< |
waterTypeList.insert("TIP3P_RB_0"); |
453 |
< |
waterTypeList.insert("TIP4P_RB_0"); |
454 |
< |
waterTypeList.insert("TIP5P_RB_0"); |
455 |
< |
waterTypeList.insert("SPCE_RB_0"); |
450 |
> |
WaterTypeVisitor::WaterTypeVisitor() { |
451 |
> |
visitorName = "WaterTypeVisitor"; |
452 |
> |
waterTypeList.insert("TIP3P_RB_0"); |
453 |
> |
waterTypeList.insert("TIP4P_RB_0"); |
454 |
> |
waterTypeList.insert("TIP5P_RB_0"); |
455 |
> |
waterTypeList.insert("SPCE_RB_0"); |
456 |
|
} |
457 |
|
|
458 |
+ |
void WaterTypeVisitor::visit(RigidBody *rb) { |
459 |
+ |
std::string rbName; |
460 |
+ |
std::vector<Atom *> myAtoms; |
461 |
+ |
std::vector<Atom *>::iterator atomIter; |
462 |
+ |
GenericData* data; |
463 |
+ |
AtomData* atomData; |
464 |
+ |
AtomInfo* atomInfo; |
465 |
+ |
std::vector<AtomInfo *>::iterator i; |
466 |
|
|
467 |
< |
void WaterTypeVisitor:: visit(RigidBody* rb){ |
439 |
< |
string rbName; |
440 |
< |
vector<Atom*> myAtoms; |
441 |
< |
vector<Atom*>::iterator atomIter; |
442 |
< |
GenericData* data; |
443 |
< |
AtomData* atomData; |
444 |
< |
AtomInfo* atomInfo; |
445 |
< |
vector<AtomInfo*>::iterator i; |
446 |
< |
|
447 |
< |
rbName = rb->getType(); |
467 |
> |
rbName = rb->getType(); |
468 |
|
|
469 |
< |
if(waterTypeList.find(rbName) != waterTypeList.end()){ |
469 |
> |
if (waterTypeList.find(rbName) != waterTypeList.end()) { |
470 |
> |
myAtoms = rb->getAtoms(); |
471 |
|
|
472 |
< |
myAtoms = rb->getAtoms(); |
473 |
< |
for(atomIter = myAtoms.begin(); atomIter != myAtoms.end(); ++atomIter){ |
472 |
> |
for( atomIter = myAtoms.begin(); atomIter != myAtoms.end(); |
473 |
> |
++atomIter ) { |
474 |
> |
data = (*atomIter)->getPropertyByName("ATOMDATA"); |
475 |
|
|
476 |
< |
data = (*atomIter)->getPropertyByName("ATOMDATA"); |
477 |
< |
if(data != NULL){ |
456 |
< |
atomData = dynamic_cast<AtomData*>(data); |
457 |
< |
if(atomData == NULL) |
458 |
< |
continue; |
459 |
< |
} |
460 |
< |
else |
461 |
< |
continue; |
462 |
< |
|
463 |
< |
for(atomInfo = atomData->beginAtomInfo(i); atomInfo; atomInfo = atomData->nextAtomInfo(i)){ |
464 |
< |
replaceType(atomInfo->AtomType); |
465 |
< |
}//end for(atomInfo) |
476 |
> |
if (data != NULL) { |
477 |
> |
atomData = dynamic_cast<AtomData *>(data); |
478 |
|
|
479 |
< |
}//end for(atomIter) |
480 |
< |
|
481 |
< |
}//end if (waterTypeList.find(rbName) != waterTypeList.end()) |
482 |
< |
|
479 |
> |
if (atomData == NULL) |
480 |
> |
continue; |
481 |
> |
} else |
482 |
> |
continue; |
483 |
> |
|
484 |
> |
for( atomInfo = atomData->beginAtomInfo(i); atomInfo; |
485 |
> |
atomInfo = atomData->nextAtomInfo(i) ) { |
486 |
> |
replaceType(atomInfo->AtomType); |
487 |
> |
} //end for(atomInfo) |
488 |
> |
} //end for(atomIter) |
489 |
> |
} //end if (waterTypeList.find(rbName) != waterTypeList.end()) |
490 |
|
} |
491 |
|
|
492 |
< |
void WaterTypeVisitor:: replaceType(string& atomType){ |
493 |
< |
atomType = atomType.substr(0, atomType.find('_')); |
492 |
> |
void WaterTypeVisitor::replaceType(std::string&atomType) { |
493 |
> |
atomType = atomType.substr(0, atomType.find('_')); |
494 |
|
} |
495 |
|
|
496 |
< |
const string WaterTypeVisitor:: toString(){ |
497 |
< |
char buffer[65535]; |
498 |
< |
string result; |
480 |
< |
|
481 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
482 |
< |
result += buffer; |
496 |
> |
const std::string WaterTypeVisitor::toString() { |
497 |
> |
char buffer[65535]; |
498 |
> |
std::string result; |
499 |
|
|
500 |
< |
sprintf(buffer ,"Visitor name: %s\n", visitorName.c_str()); |
501 |
< |
result += buffer; |
500 |
> |
sprintf(buffer, |
501 |
> |
"------------------------------------------------------------------\n"); |
502 |
> |
result += buffer; |
503 |
|
|
504 |
< |
sprintf(buffer ,"Visitor Description: Replace the atom type in water model\n"); |
505 |
< |
result += buffer; |
504 |
> |
sprintf(buffer, "Visitor name: %s\n", visitorName.c_str()); |
505 |
> |
result += buffer; |
506 |
|
|
507 |
< |
sprintf(buffer ,"------------------------------------------------------------------\n"); |
508 |
< |
result += buffer; |
507 |
> |
sprintf(buffer, |
508 |
> |
"Visitor Description: Replace the atom type in water model\n"); |
509 |
> |
result += buffer; |
510 |
|
|
511 |
< |
return result; |
511 |
> |
sprintf(buffer, |
512 |
> |
"------------------------------------------------------------------\n"); |
513 |
> |
result += buffer; |
514 |
> |
|
515 |
> |
return result; |
516 |
|
} |
517 |
|
|
518 |
< |
|
497 |
< |
}//namespace oopse |
518 |
> |
} //namespace oopse |