| 1 |
gezelter |
507 |
/* |
| 2 |
gezelter |
246 |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
| 3 |
|
|
* |
| 4 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
| 5 |
|
|
* non-exclusive, royalty free, license to use, modify and |
| 6 |
|
|
* redistribute this software in source and binary code form, provided |
| 7 |
|
|
* that the following conditions are met: |
| 8 |
|
|
* |
| 9 |
gezelter |
1390 |
* 1. Redistributions of source code must retain the above copyright |
| 10 |
gezelter |
246 |
* notice, this list of conditions and the following disclaimer. |
| 11 |
|
|
* |
| 12 |
gezelter |
1390 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
gezelter |
246 |
* notice, this list of conditions and the following disclaimer in the |
| 14 |
|
|
* documentation and/or other materials provided with the |
| 15 |
|
|
* distribution. |
| 16 |
|
|
* |
| 17 |
|
|
* This software is provided "AS IS," without a warranty of any |
| 18 |
|
|
* kind. All express or implied conditions, representations and |
| 19 |
|
|
* warranties, including any implied warranty of merchantability, |
| 20 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
| 21 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
| 22 |
|
|
* be liable for any damages suffered by licensee as a result of |
| 23 |
|
|
* using, modifying or distributing the software or its |
| 24 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
| 25 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
| 26 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
| 27 |
|
|
* damages, however caused and regardless of the theory of liability, |
| 28 |
|
|
* arising out of the use of or inability to use software, even if the |
| 29 |
|
|
* University of Notre Dame has been advised of the possibility of |
| 30 |
|
|
* such damages. |
| 31 |
gezelter |
1390 |
* |
| 32 |
|
|
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
| 33 |
|
|
* research, please cite the appropriate papers when you publish your |
| 34 |
|
|
* work. Good starting points are: |
| 35 |
|
|
* |
| 36 |
|
|
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
| 37 |
|
|
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
| 38 |
|
|
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
| 39 |
gezelter |
1665 |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
| 40 |
|
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
| 41 |
gezelter |
246 |
*/ |
| 42 |
|
|
|
| 43 |
tim |
12 |
#include <iostream> |
| 44 |
|
|
#include <fstream> |
| 45 |
|
|
#include <string> |
| 46 |
|
|
|
| 47 |
|
|
#include "applications/dump2Xyz/Dump2XYZCmd.h" |
| 48 |
gezelter |
246 |
#include "brains/Register.hpp" |
| 49 |
|
|
#include "brains/SimCreator.hpp" |
| 50 |
|
|
#include "brains/SimInfo.hpp" |
| 51 |
gezelter |
1456 |
#include "brains/ForceManager.hpp" |
| 52 |
gezelter |
246 |
#include "io/DumpReader.hpp" |
| 53 |
|
|
#include "utils/simError.h" |
| 54 |
tim |
12 |
#include "visitors/AtomVisitor.hpp" |
| 55 |
gezelter |
1455 |
#include "visitors/ReplacementVisitor.hpp" |
| 56 |
tim |
12 |
#include "visitors/CompositeVisitor.hpp" |
| 57 |
|
|
#include "visitors/RigidBodyVisitor.hpp" |
| 58 |
|
|
#include "visitors/OtherVisitor.hpp" |
| 59 |
|
|
#include "visitors/ZconsVisitor.hpp" |
| 60 |
tim |
291 |
#include "selection/SelectionEvaluator.hpp" |
| 61 |
tim |
324 |
#include "selection/SelectionManager.hpp" |
| 62 |
tim |
369 |
#include "visitors/LipidTransVisitor.hpp" |
| 63 |
tim |
543 |
#include "visitors/AtomNameVisitor.hpp" |
| 64 |
tim |
369 |
|
| 65 |
gezelter |
1390 |
using namespace OpenMD; |
| 66 |
tim |
12 |
|
| 67 |
gezelter |
1706 |
using namespace std; |
| 68 |
tim |
12 |
int main(int argc, char* argv[]){ |
| 69 |
gezelter |
246 |
|
| 70 |
|
|
//register force fields |
| 71 |
|
|
registerForceFields(); |
| 72 |
|
|
|
| 73 |
tim |
12 |
gengetopt_args_info args_info; |
| 74 |
gezelter |
1706 |
string dumpFileName; |
| 75 |
|
|
string xyzFileName; |
| 76 |
|
|
|
| 77 |
|
|
bool printVel(false); |
| 78 |
|
|
bool printFrc(false); |
| 79 |
|
|
bool printVec(false); |
| 80 |
|
|
bool printChrg(false); |
| 81 |
tim |
12 |
|
| 82 |
gezelter |
246 |
//parse the command line option |
| 83 |
|
|
if (cmdline_parser (argc, argv, &args_info) != 0) { |
| 84 |
|
|
exit(1) ; |
| 85 |
|
|
} |
| 86 |
tim |
12 |
|
| 87 |
|
|
//get the dumpfile name and meta-data file name |
| 88 |
|
|
if (args_info.input_given){ |
| 89 |
|
|
dumpFileName = args_info.input_arg; |
| 90 |
gezelter |
246 |
} else { |
| 91 |
gezelter |
1706 |
cerr << "Does not have input file name" << endl; |
| 92 |
tim |
12 |
exit(1); |
| 93 |
|
|
} |
| 94 |
gezelter |
246 |
|
| 95 |
tim |
12 |
if (args_info.output_given){ |
| 96 |
|
|
xyzFileName = args_info.output_arg; |
| 97 |
gezelter |
246 |
} else { |
| 98 |
tim |
12 |
xyzFileName = dumpFileName; |
| 99 |
|
|
xyzFileName = xyzFileName.substr(0, xyzFileName.rfind(".")) + ".xyz"; |
| 100 |
|
|
} |
| 101 |
gezelter |
246 |
|
| 102 |
tim |
12 |
//parse md file and set up the system |
| 103 |
gezelter |
246 |
SimCreator creator; |
| 104 |
gezelter |
1026 |
SimInfo* info = creator.createSim(dumpFileName, false); |
| 105 |
gezelter |
1456 |
ForceManager* forceMan = new ForceManager(info); |
| 106 |
tim |
12 |
|
| 107 |
chrisfen |
527 |
//create visitor list |
| 108 |
gezelter |
246 |
CompositeVisitor* compositeVisitor = new CompositeVisitor(); |
| 109 |
gezelter |
1455 |
|
| 110 |
chrisfen |
527 |
//create RigidBody Visitor |
| 111 |
tim |
12 |
if(args_info.rigidbody_flag){ |
| 112 |
gezelter |
246 |
RBCOMVisitor* rbCOMVisitor = new RBCOMVisitor(info); |
| 113 |
tim |
12 |
compositeVisitor->addVisitor(rbCOMVisitor, 900); |
| 114 |
|
|
} |
| 115 |
gezelter |
246 |
|
| 116 |
chrisfen |
527 |
//create SSD atom visitor |
| 117 |
gezelter |
246 |
SSDAtomVisitor* ssdVisitor = new SSDAtomVisitor(info); |
| 118 |
tim |
12 |
compositeVisitor->addVisitor(ssdVisitor, 800); |
| 119 |
gezelter |
246 |
|
| 120 |
gezelter |
1629 |
//create GBtail atom visitor |
| 121 |
|
|
GBtailVisitor* gbtVisitor = new GBtailVisitor(info); |
| 122 |
|
|
compositeVisitor->addVisitor(gbtVisitor, 790); |
| 123 |
|
|
|
| 124 |
|
|
//create GBhead atom visitor |
| 125 |
|
|
GBheadVisitor* gbhVisitor = new GBheadVisitor(info); |
| 126 |
|
|
compositeVisitor->addVisitor(gbhVisitor, 789); |
| 127 |
|
|
|
| 128 |
chrisfen |
527 |
//create default atom visitor |
| 129 |
gezelter |
246 |
DefaultAtomVisitor* defaultAtomVisitor = new DefaultAtomVisitor(info); |
| 130 |
tim |
12 |
compositeVisitor->addVisitor(defaultAtomVisitor, 700); |
| 131 |
gezelter |
246 |
|
| 132 |
cli2 |
1303 |
// if we gave the -w option, we want to skip the waters: |
| 133 |
|
|
if (!args_info.water_given) { |
| 134 |
|
|
//create waterType visitor |
| 135 |
|
|
if(args_info.watertype_flag){ |
| 136 |
|
|
WaterTypeVisitor* waterTypeVisitor = new WaterTypeVisitor; |
| 137 |
|
|
compositeVisitor->addVisitor(waterTypeVisitor, 600); |
| 138 |
|
|
} |
| 139 |
gezelter |
1455 |
} |
| 140 |
|
|
|
| 141 |
tim |
543 |
if (args_info.basetype_flag) { |
| 142 |
gezelter |
1455 |
AtomNameVisitor* atomNameVisitor = new AtomNameVisitor(info); |
| 143 |
|
|
compositeVisitor->addVisitor(atomNameVisitor, 550); |
| 144 |
gezelter |
1706 |
cout << compositeVisitor->toString(); |
| 145 |
tim |
543 |
} |
| 146 |
gezelter |
246 |
|
| 147 |
tim |
12 |
//create ZconsVisitor |
| 148 |
|
|
if(args_info.zconstraint_flag){ |
| 149 |
gezelter |
246 |
|
| 150 |
|
|
ZConsVisitor* zconsVisitor = new ZConsVisitor(info); |
| 151 |
tim |
12 |
|
| 152 |
gezelter |
246 |
if(zconsVisitor->haveZconsMol()) { |
| 153 |
tim |
12 |
compositeVisitor->addVisitor(zconsVisitor, 500); |
| 154 |
gezelter |
246 |
} else { |
| 155 |
tim |
12 |
delete zconsVisitor; |
| 156 |
gezelter |
246 |
} |
| 157 |
tim |
12 |
} |
| 158 |
gezelter |
246 |
|
| 159 |
chrisfen |
527 |
//create wrapping visitor |
| 160 |
gezelter |
246 |
|
| 161 |
tim |
968 |
//if(args_info.periodicBox_flag){ |
| 162 |
|
|
// WrappingVisitor* wrappingVisitor = new WrappingVisitor(info); |
| 163 |
|
|
// compositeVisitor->addVisitor(wrappingVisitor, 400); |
| 164 |
|
|
//} |
| 165 |
tim |
369 |
|
| 166 |
chrisfen |
527 |
//create replicate visitor |
| 167 |
gezelter |
1456 |
if(args_info.repeatX_given > 0 || |
| 168 |
|
|
args_info.repeatY_given > 0 || |
| 169 |
|
|
args_info.repeatY_given > 0) { |
| 170 |
|
|
Vector3i replicateOpt(args_info.repeatX_arg, |
| 171 |
|
|
args_info.repeatY_arg, |
| 172 |
|
|
args_info.repeatZ_arg); |
| 173 |
|
|
ReplicateVisitor* replicateVisitor = new ReplicateVisitor(info, |
| 174 |
|
|
replicateOpt); |
| 175 |
tim |
12 |
compositeVisitor->addVisitor(replicateVisitor, 300); |
| 176 |
|
|
} |
| 177 |
tim |
369 |
|
| 178 |
|
|
|
| 179 |
|
|
//create rotation visitor |
| 180 |
|
|
if (args_info.refsele_given&& args_info.originsele_given) { |
| 181 |
gezelter |
1456 |
compositeVisitor->addVisitor(new LipidTransVisitor(info, |
| 182 |
|
|
args_info.originsele_arg, |
| 183 |
|
|
args_info.refsele_arg), |
| 184 |
|
|
250); |
| 185 |
tim |
369 |
} else if (args_info.refsele_given || args_info.originsele_given) { |
| 186 |
gezelter |
1706 |
cerr << "Both of --refsele and --originsele should appear by pair" |
| 187 |
|
|
<< endl; |
| 188 |
tim |
369 |
exit(1); |
| 189 |
|
|
} |
| 190 |
gezelter |
1456 |
|
| 191 |
chrisfen |
527 |
//create xyzVisitor |
| 192 |
tim |
413 |
XYZVisitor* xyzVisitor; |
| 193 |
chuckv |
1117 |
|
| 194 |
tim |
413 |
if (args_info.selection_given) { |
| 195 |
|
|
xyzVisitor = new XYZVisitor(info, args_info.selection_arg); |
| 196 |
|
|
} else { |
| 197 |
|
|
xyzVisitor = new XYZVisitor(info); |
| 198 |
|
|
} |
| 199 |
chuckv |
1117 |
|
| 200 |
gezelter |
1456 |
if(args_info.velocities_flag){ |
| 201 |
|
|
printVel = true; |
| 202 |
|
|
xyzVisitor->doVelocities(printVel); |
| 203 |
chuckv |
1117 |
} |
| 204 |
gezelter |
1456 |
if(args_info.forces_flag){ |
| 205 |
|
|
printFrc = true; |
| 206 |
|
|
xyzVisitor->doForces(printFrc); |
| 207 |
|
|
} |
| 208 |
|
|
if(args_info.vectors_flag){ |
| 209 |
|
|
printVec = true; |
| 210 |
|
|
xyzVisitor->doVectors(printVec); |
| 211 |
|
|
} |
| 212 |
|
|
if(args_info.charges_flag){ |
| 213 |
|
|
printChrg = true; |
| 214 |
|
|
xyzVisitor->doCharges(printChrg); |
| 215 |
|
|
} |
| 216 |
|
|
|
| 217 |
gezelter |
1455 |
compositeVisitor->addVisitor(xyzVisitor, 200); |
| 218 |
gezelter |
246 |
|
| 219 |
chrisfen |
527 |
//create prepareVisitor |
| 220 |
gezelter |
246 |
PrepareVisitor* prepareVisitor = new PrepareVisitor(); |
| 221 |
|
|
|
| 222 |
tim |
12 |
//open dump file |
| 223 |
gezelter |
246 |
DumpReader* dumpReader = new DumpReader(info, dumpFileName); |
| 224 |
|
|
int nframes = dumpReader->getNFrames(); |
| 225 |
|
|
|
| 226 |
gezelter |
1706 |
ofstream xyzStream(xyzFileName.c_str()); |
| 227 |
tim |
12 |
|
| 228 |
gezelter |
246 |
SimInfo::MoleculeIterator miter; |
| 229 |
|
|
Molecule::IntegrableObjectIterator iiter; |
| 230 |
|
|
Molecule::RigidBodyIterator rbIter; |
| 231 |
|
|
Molecule* mol; |
| 232 |
|
|
StuntDouble* integrableObject; |
| 233 |
|
|
RigidBody* rb; |
| 234 |
tim |
968 |
Vector3d molCom; |
| 235 |
|
|
Vector3d newMolCom; |
| 236 |
|
|
Vector3d displacement; |
| 237 |
|
|
Mat3x3d hmat; |
| 238 |
|
|
Snapshot* currentSnapshot; |
| 239 |
tim |
413 |
|
| 240 |
tim |
12 |
for (int i = 0; i < nframes; i += args_info.frame_arg){ |
| 241 |
gezelter |
246 |
dumpReader->readFrame(i); |
| 242 |
gezelter |
1456 |
|
| 243 |
gezelter |
1464 |
if (printFrc) forceMan->calcForces(); |
| 244 |
gezelter |
1456 |
|
| 245 |
tim |
968 |
//wrapping the molecule |
| 246 |
|
|
if(args_info.periodicBox_flag) { |
| 247 |
|
|
currentSnapshot = info->getSnapshotManager()->getCurrentSnapshot(); |
| 248 |
gezelter |
1456 |
for (mol = info->beginMolecule(miter); mol != NULL; |
| 249 |
|
|
mol = info->nextMolecule(miter)) { |
| 250 |
tim |
968 |
molCom = mol->getCom(); |
| 251 |
|
|
newMolCom = molCom; |
| 252 |
|
|
currentSnapshot->wrapVector(newMolCom); |
| 253 |
|
|
displacement = newMolCom - molCom; |
| 254 |
gezelter |
1456 |
for (integrableObject = mol->beginIntegrableObject(iiter); |
| 255 |
|
|
integrableObject != NULL; |
| 256 |
tim |
968 |
integrableObject = mol->nextIntegrableObject(iiter)) { |
| 257 |
|
|
integrableObject->setPos(integrableObject->getPos() + displacement); |
| 258 |
|
|
} |
| 259 |
|
|
} |
| 260 |
|
|
} |
| 261 |
tim |
12 |
//update atoms of rigidbody |
| 262 |
gezelter |
1456 |
for (mol = info->beginMolecule(miter); mol != NULL; |
| 263 |
|
|
mol = info->nextMolecule(miter)) { |
| 264 |
gezelter |
246 |
|
| 265 |
|
|
//change the positions of atoms which belong to the rigidbodies |
| 266 |
gezelter |
1456 |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
| 267 |
|
|
rb = mol->nextRigidBody(rbIter)) { |
| 268 |
gezelter |
246 |
rb->updateAtoms(); |
| 269 |
gezelter |
1456 |
if (printVel) rb->updateAtomVel(); |
| 270 |
gezelter |
246 |
} |
| 271 |
|
|
} |
| 272 |
tim |
12 |
|
| 273 |
|
|
//prepare visit |
| 274 |
gezelter |
1456 |
for (mol = info->beginMolecule(miter); mol != NULL; |
| 275 |
|
|
mol = info->nextMolecule(miter)) { |
| 276 |
|
|
for (integrableObject = mol->beginIntegrableObject(iiter); |
| 277 |
|
|
integrableObject != NULL; |
| 278 |
gezelter |
246 |
integrableObject = mol->nextIntegrableObject(iiter)) { |
| 279 |
|
|
integrableObject->accept(prepareVisitor); |
| 280 |
|
|
} |
| 281 |
|
|
} |
| 282 |
|
|
|
| 283 |
tim |
12 |
//update visitor |
| 284 |
|
|
compositeVisitor->update(); |
| 285 |
tim |
291 |
|
| 286 |
tim |
413 |
|
| 287 |
tim |
12 |
//visit stuntdouble |
| 288 |
gezelter |
1456 |
for (mol = info->beginMolecule(miter); mol != NULL; |
| 289 |
|
|
mol = info->nextMolecule(miter)) { |
| 290 |
|
|
for (integrableObject = mol->beginIntegrableObject(iiter); |
| 291 |
|
|
integrableObject != NULL; |
| 292 |
gezelter |
246 |
integrableObject = mol->nextIntegrableObject(iiter)) { |
| 293 |
|
|
integrableObject->accept(compositeVisitor); |
| 294 |
|
|
} |
| 295 |
tim |
12 |
} |
| 296 |
gezelter |
246 |
|
| 297 |
tim |
12 |
xyzVisitor->writeFrame(xyzStream); |
| 298 |
|
|
xyzVisitor->clear(); |
| 299 |
|
|
|
| 300 |
|
|
}//end for (int i = 0; i < nframes; i += args_info.frame_arg) |
| 301 |
gezelter |
1282 |
|
| 302 |
tim |
12 |
xyzStream.close(); |
| 303 |
tim |
466 |
delete prepareVisitor; |
| 304 |
tim |
12 |
delete compositeVisitor; |
| 305 |
|
|
delete info; |
| 306 |
|
|
} |