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