| 1 |
tim |
1501 |
#include <iostream> |
| 2 |
|
|
#include <fstream> |
| 3 |
|
|
#include <string> |
| 4 |
|
|
|
| 5 |
|
|
#include "applications/dump2Xyz/Dump2XYZCmd.h" |
| 6 |
tim |
1833 |
#include "brains/SimCreator.hpp" |
| 7 |
|
|
#include "io/DumpReader.hpp" |
| 8 |
tim |
1501 |
#include "visitors/AtomVisitor.hpp" |
| 9 |
|
|
#include "visitors/CompositeVisitor.hpp" |
| 10 |
|
|
#include "visitors/RigidBodyVisitor.hpp" |
| 11 |
|
|
#include "visitors/OtherVisitor.hpp" |
| 12 |
|
|
#include "visitors/ZconsVisitor.hpp" |
| 13 |
|
|
|
| 14 |
|
|
|
| 15 |
tim |
1833 |
using namespace oopse; |
| 16 |
tim |
1827 |
|
| 17 |
tim |
1501 |
int main(int argc, char* argv[]){ |
| 18 |
tim |
1833 |
gengetopt_args_info args_info; |
| 19 |
|
|
std::string dumpFileName; |
| 20 |
|
|
std::string mdFileName; |
| 21 |
|
|
std::string xyzFileName; |
| 22 |
|
|
|
| 23 |
|
|
//parse the command line option |
| 24 |
|
|
if (cmdline_parser (argc, argv, &args_info) != 0) { |
| 25 |
|
|
exit(1) ; |
| 26 |
|
|
} |
| 27 |
tim |
1501 |
|
| 28 |
tim |
1833 |
//get the dumpfile name and meta-data file name |
| 29 |
|
|
if (args_info.input_given){ |
| 30 |
tim |
1501 |
dumpFileName = args_info.input_arg; |
| 31 |
tim |
1833 |
} else { |
| 32 |
|
|
std::cerr << "Does not have input file name" << std::endl; |
| 33 |
|
|
exit(1); |
| 34 |
|
|
} |
| 35 |
|
|
|
| 36 |
|
|
mdFileName = dumpFileName; |
| 37 |
|
|
mdFileName = mdFileName.substr(0, mdFileName.rfind(".")) + ".md"; |
| 38 |
tim |
1501 |
|
| 39 |
tim |
1833 |
if (args_info.output_given){ |
| 40 |
|
|
xyzFileName = args_info.output_arg; |
| 41 |
|
|
} else { |
| 42 |
|
|
xyzFileName = dumpFileName; |
| 43 |
|
|
xyzFileName = xyzFileName.substr(0, xyzFileName.rfind(".")) + ".xyz"; |
| 44 |
|
|
} |
| 45 |
tim |
1501 |
|
| 46 |
|
|
//parse md file and set up the system |
| 47 |
tim |
1833 |
SimCreator creator; |
| 48 |
|
|
SimInfo* info = creator.createSim(mdFileName); |
| 49 |
|
|
|
| 50 |
tim |
1501 |
|
| 51 |
tim |
1833 |
|
| 52 |
|
|
//creat visitor list |
| 53 |
|
|
CompositeVisitor* compositeVisitor = new CompositeVisitor(); |
| 54 |
tim |
1501 |
|
| 55 |
tim |
1833 |
//creat ignore visitor |
| 56 |
|
|
if(args_info.ignore_given ||args_info.water_flag){ |
| 57 |
tim |
1501 |
|
| 58 |
tim |
1833 |
IgnoreVisitor* ignoreVisitor = new IgnoreVisitor(); |
| 59 |
tim |
1501 |
|
| 60 |
tim |
1833 |
for(int i = 0; i < args_info.ignore_given; i++) |
| 61 |
|
|
ignoreVisitor->addIgnoreType(args_info.ignore_arg[i]); |
| 62 |
tim |
1501 |
|
| 63 |
tim |
1833 |
//ignore water |
| 64 |
|
|
if(args_info.water_flag){ |
| 65 |
|
|
ignoreVisitor->addIgnoreType("SSD"); |
| 66 |
|
|
ignoreVisitor->addIgnoreType("SSD1"); |
| 67 |
|
|
ignoreVisitor->addIgnoreType("SSD_E"); |
| 68 |
|
|
ignoreVisitor->addIgnoreType("SSD_RF"); |
| 69 |
|
|
ignoreVisitor->addIgnoreType("TIP3P_RB_0"); |
| 70 |
|
|
ignoreVisitor->addIgnoreType("TIP4P_RB_0"); |
| 71 |
|
|
ignoreVisitor->addIgnoreType("TIP5P_RB_0"); |
| 72 |
|
|
ignoreVisitor->addIgnoreType("SPCE_RB_0"); |
| 73 |
|
|
ignoreVisitor->addIgnoreType("DPD_RB_0"); |
| 74 |
|
|
} |
| 75 |
tim |
1501 |
|
| 76 |
tim |
1833 |
compositeVisitor->addVisitor(ignoreVisitor, 1000); |
| 77 |
tim |
1501 |
} |
| 78 |
|
|
|
| 79 |
tim |
1833 |
//creat RigidBody Visitor |
| 80 |
|
|
if(args_info.rigidbody_flag){ |
| 81 |
|
|
RBCOMVisitor* rbCOMVisitor = new RBCOMVisitor(info); |
| 82 |
|
|
compositeVisitor->addVisitor(rbCOMVisitor, 900); |
| 83 |
|
|
} |
| 84 |
tim |
1501 |
|
| 85 |
|
|
//compositeVisitor->addVisitor(lipidVisitor, 900); |
| 86 |
|
|
|
| 87 |
tim |
1833 |
//creat SSD atom visitor |
| 88 |
|
|
SSDAtomVisitor* ssdVisitor = new SSDAtomVisitor(info); |
| 89 |
|
|
compositeVisitor->addVisitor(ssdVisitor, 800); |
| 90 |
tim |
1501 |
|
| 91 |
tim |
1833 |
//creat default atom visitor |
| 92 |
|
|
DefaultAtomVisitor* defaultAtomVisitor = new DefaultAtomVisitor(info); |
| 93 |
|
|
compositeVisitor->addVisitor(defaultAtomVisitor, 700); |
| 94 |
tim |
1501 |
|
| 95 |
tim |
1833 |
//creat waterType visitor |
| 96 |
|
|
if(args_info.watertype_flag){ |
| 97 |
|
|
WaterTypeVisitor* waterTypeVisitor = new WaterTypeVisitor; |
| 98 |
|
|
compositeVisitor->addVisitor(waterTypeVisitor, 600); |
| 99 |
|
|
} |
| 100 |
tim |
1501 |
|
| 101 |
tim |
1833 |
//create ZconsVisitor |
| 102 |
|
|
if(args_info.zconstraint_flag){ |
| 103 |
tim |
1501 |
|
| 104 |
tim |
1833 |
ZConsVisitor* zconsVisitor = new ZConsVisitor(info); |
| 105 |
tim |
1501 |
|
| 106 |
tim |
1833 |
if(zconsVisitor->haveZconsMol()) { |
| 107 |
|
|
compositeVisitor->addVisitor(zconsVisitor, 500); |
| 108 |
|
|
} else { |
| 109 |
|
|
delete zconsVisitor; |
| 110 |
|
|
} |
| 111 |
|
|
} |
| 112 |
tim |
1501 |
|
| 113 |
tim |
1833 |
//creat wrapping visitor |
| 114 |
|
|
|
| 115 |
|
|
if(args_info.periodicBox_flag){ |
| 116 |
|
|
WrappingVisitor* wrappingVisitor = new WrappingVisitor(info); |
| 117 |
|
|
compositeVisitor->addVisitor(wrappingVisitor, 400); |
| 118 |
|
|
} |
| 119 |
tim |
1501 |
|
| 120 |
tim |
1833 |
//creat replicate visitor |
| 121 |
|
|
if(args_info.repeatX_given > 0 || args_info.repeatY_given > 0 ||args_info.repeatY_given > 0){ |
| 122 |
|
|
Vector3i replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg); |
| 123 |
|
|
ReplicateVisitor* replicateVisitor = new ReplicateVisitor(info, replicateOpt); |
| 124 |
|
|
compositeVisitor->addVisitor(replicateVisitor, 300); |
| 125 |
|
|
} |
| 126 |
tim |
1501 |
|
| 127 |
tim |
1833 |
//creat xyzVisitor |
| 128 |
|
|
XYZVisitor* xyzVisitor = new XYZVisitor(info); |
| 129 |
|
|
compositeVisitor->addVisitor(xyzVisitor, 200); |
| 130 |
tim |
1501 |
|
| 131 |
tim |
1833 |
std::cout << compositeVisitor->toString(); |
| 132 |
tim |
1501 |
|
| 133 |
tim |
1833 |
//creat prepareVisitor |
| 134 |
|
|
PrepareVisitor* prepareVisitor = new PrepareVisitor(); |
| 135 |
tim |
1501 |
|
| 136 |
tim |
1833 |
//open dump file |
| 137 |
|
|
DumpReader* dumpReader = new DumpReader(info, dumpFileName); |
| 138 |
|
|
int nframes = dumpReader->getNFrames(); |
| 139 |
tim |
1501 |
|
| 140 |
tim |
1833 |
|
| 141 |
|
|
std::ofstream xyzStream; |
| 142 |
|
|
xyzStream .open(xyzFileName.c_str()); |
| 143 |
tim |
1501 |
|
| 144 |
tim |
1833 |
|
| 145 |
|
|
SimInfo::MoleculeIterator miter; |
| 146 |
|
|
Molecule::IntegrableObjectIterator iiter; |
| 147 |
|
|
Molecule::RigidBodyIterator rbIter; |
| 148 |
|
|
Molecule* mol; |
| 149 |
|
|
StuntDouble* integrableObject; |
| 150 |
|
|
RigidBody* rb; |
| 151 |
|
|
|
| 152 |
|
|
for (int i = 0; i < nframes; i += args_info.frame_arg){ |
| 153 |
|
|
dumpReader->readFrame(i); |
| 154 |
tim |
1501 |
|
| 155 |
tim |
1833 |
//update atoms of rigidbody |
| 156 |
|
|
for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) { |
| 157 |
tim |
1501 |
|
| 158 |
tim |
1833 |
//change the positions of atoms which belong to the rigidbodies |
| 159 |
|
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
| 160 |
|
|
rb->updateAtoms(); |
| 161 |
|
|
} |
| 162 |
|
|
} |
| 163 |
tim |
1501 |
|
| 164 |
tim |
1833 |
//prepare visit |
| 165 |
|
|
for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) { |
| 166 |
|
|
for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL; |
| 167 |
|
|
integrableObject = mol->nextIntegrableObject(iiter)) { |
| 168 |
|
|
integrableObject->accept(prepareVisitor); |
| 169 |
|
|
} |
| 170 |
|
|
} |
| 171 |
tim |
1501 |
|
| 172 |
tim |
1833 |
//update visitor |
| 173 |
|
|
compositeVisitor->update(); |
| 174 |
tim |
1501 |
|
| 175 |
tim |
1833 |
//visit stuntdouble |
| 176 |
|
|
for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) { |
| 177 |
|
|
for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL; |
| 178 |
|
|
integrableObject = mol->nextIntegrableObject(iiter)) { |
| 179 |
|
|
integrableObject->accept(compositeVisitor); |
| 180 |
|
|
} |
| 181 |
|
|
} |
| 182 |
tim |
1501 |
|
| 183 |
tim |
1833 |
xyzVisitor->writeFrame(xyzStream); |
| 184 |
|
|
xyzVisitor->clear(); |
| 185 |
tim |
1501 |
|
| 186 |
tim |
1833 |
}//end for (int i = 0; i < nframes; i += args_info.frame_arg) |
| 187 |
tim |
1501 |
|
| 188 |
tim |
1833 |
xyzStream.close(); |
| 189 |
tim |
1501 |
|
| 190 |
|
|
|
| 191 |
tim |
1833 |
delete compositeVisitor; |
| 192 |
|
|
delete info; |
| 193 |
tim |
1501 |
|
| 194 |
|
|
|
| 195 |
|
|
} |