| 1 | gezelter | 246 | /* | 
| 2 |  |  | * 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 |  |  | * 1. Acknowledgement of the program authors must be made in any | 
| 10 |  |  | *    publication of scientific results based in part on use of the | 
| 11 |  |  | *    program.  An acceptable form of acknowledgement is citation of | 
| 12 |  |  | *    the article in which the program was described (Matthew | 
| 13 |  |  | *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher | 
| 14 |  |  | *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented | 
| 15 |  |  | *    Parallel Simulation Engine for Molecular Dynamics," | 
| 16 |  |  | *    J. Comput. Chem. 26, pp. 252-271 (2005)) | 
| 17 |  |  | * | 
| 18 |  |  | * 2. Redistributions of source code must retain the above copyright | 
| 19 |  |  | *    notice, this list of conditions and the following disclaimer. | 
| 20 |  |  | * | 
| 21 |  |  | * 3. Redistributions in binary form must reproduce the above copyright | 
| 22 |  |  | *    notice, this list of conditions and the following disclaimer in the | 
| 23 |  |  | *    documentation and/or other materials provided with the | 
| 24 |  |  | *    distribution. | 
| 25 |  |  | * | 
| 26 |  |  | * This software is provided "AS IS," without a warranty of any | 
| 27 |  |  | * kind. All express or implied conditions, representations and | 
| 28 |  |  | * warranties, including any implied warranty of merchantability, | 
| 29 |  |  | * fitness for a particular purpose or non-infringement, are hereby | 
| 30 |  |  | * excluded.  The University of Notre Dame and its licensors shall not | 
| 31 |  |  | * be liable for any damages suffered by licensee as a result of | 
| 32 |  |  | * using, modifying or distributing the software or its | 
| 33 |  |  | * derivatives. In no event will the University of Notre Dame or its | 
| 34 |  |  | * licensors be liable for any lost revenue, profit or data, or for | 
| 35 |  |  | * direct, indirect, special, consequential, incidental or punitive | 
| 36 |  |  | * damages, however caused and regardless of the theory of liability, | 
| 37 |  |  | * arising out of the use of or inability to use software, even if the | 
| 38 |  |  | * University of Notre Dame has been advised of the possibility of | 
| 39 |  |  | * such damages. | 
| 40 |  |  | */ | 
| 41 |  |  |  | 
| 42 | tim | 12 | #include <iostream> | 
| 43 |  |  | #include <fstream> | 
| 44 |  |  | #include <string> | 
| 45 |  |  |  | 
| 46 |  |  | #include "applications/dump2Xyz/Dump2XYZCmd.h" | 
| 47 | gezelter | 246 | #include "brains/Register.hpp" | 
| 48 |  |  | #include "brains/SimCreator.hpp" | 
| 49 |  |  | #include "brains/SimInfo.hpp" | 
| 50 |  |  | #include "io/DumpReader.hpp" | 
| 51 |  |  | #include "utils/simError.h" | 
| 52 | tim | 12 | #include "visitors/AtomVisitor.hpp" | 
| 53 |  |  | #include "visitors/CompositeVisitor.hpp" | 
| 54 |  |  | #include "visitors/RigidBodyVisitor.hpp" | 
| 55 |  |  | #include "visitors/OtherVisitor.hpp" | 
| 56 |  |  | #include "visitors/ZconsVisitor.hpp" | 
| 57 | tim | 291 | #include "selection/SelectionEvaluator.hpp" | 
| 58 | tim | 324 | #include "selection/SelectionManager.hpp" | 
| 59 | tim | 369 | #include "visitors/LipidTransVisitor.hpp" | 
| 60 |  |  |  | 
| 61 | gezelter | 246 | using namespace oopse; | 
| 62 | tim | 12 |  | 
| 63 |  |  | int main(int argc, char* argv[]){ | 
| 64 | gezelter | 246 |  | 
| 65 |  |  | //register force fields | 
| 66 |  |  | registerForceFields(); | 
| 67 |  |  |  | 
| 68 | tim | 12 | gengetopt_args_info args_info; | 
| 69 | gezelter | 246 | std::string dumpFileName; | 
| 70 |  |  | std::string mdFileName; | 
| 71 |  |  | std::string xyzFileName; | 
| 72 | tim | 12 |  | 
| 73 | gezelter | 246 | //parse the command line option | 
| 74 |  |  | if (cmdline_parser (argc, argv, &args_info) != 0) { | 
| 75 |  |  | exit(1) ; | 
| 76 |  |  | } | 
| 77 | tim | 12 |  | 
| 78 |  |  | //get the dumpfile name and meta-data file name | 
| 79 |  |  | if (args_info.input_given){ | 
| 80 |  |  | dumpFileName = args_info.input_arg; | 
| 81 | gezelter | 246 | } else { | 
| 82 |  |  | std::cerr << "Does not have input file name" << std::endl; | 
| 83 | tim | 12 | exit(1); | 
| 84 |  |  | } | 
| 85 | gezelter | 246 |  | 
| 86 | tim | 12 | mdFileName = dumpFileName; | 
| 87 |  |  | mdFileName = mdFileName.substr(0, mdFileName.rfind(".")) + ".md"; | 
| 88 | tim | 273 |  | 
| 89 | tim | 12 | if (args_info.output_given){ | 
| 90 |  |  | xyzFileName = args_info.output_arg; | 
| 91 | gezelter | 246 | } else { | 
| 92 | tim | 12 | xyzFileName = dumpFileName; | 
| 93 |  |  | xyzFileName = xyzFileName.substr(0, xyzFileName.rfind(".")) + ".xyz"; | 
| 94 |  |  | } | 
| 95 | gezelter | 246 |  | 
| 96 | tim | 12 | //parse md file and set up the system | 
| 97 | gezelter | 246 | SimCreator creator; | 
| 98 | tim | 273 | SimInfo* info = creator.createSim(mdFileName, false); | 
| 99 | tim | 12 |  | 
| 100 | gezelter | 246 |  | 
| 101 |  |  |  | 
| 102 | tim | 12 | //creat visitor list | 
| 103 | gezelter | 246 | CompositeVisitor* compositeVisitor = new CompositeVisitor(); | 
| 104 | tim | 12 |  | 
| 105 |  |  | //creat RigidBody Visitor | 
| 106 |  |  | if(args_info.rigidbody_flag){ | 
| 107 | gezelter | 246 | RBCOMVisitor* rbCOMVisitor = new RBCOMVisitor(info); | 
| 108 | tim | 12 | compositeVisitor->addVisitor(rbCOMVisitor, 900); | 
| 109 |  |  | } | 
| 110 | gezelter | 246 |  | 
| 111 | tim | 12 | //creat SSD atom visitor | 
| 112 | gezelter | 246 | SSDAtomVisitor* ssdVisitor = new SSDAtomVisitor(info); | 
| 113 | tim | 12 | compositeVisitor->addVisitor(ssdVisitor, 800); | 
| 114 | gezelter | 246 |  | 
| 115 | tim | 250 | LinearAtomVisitor* linearVisitor = new LinearAtomVisitor(info); | 
| 116 | chrisfen | 211 | compositeVisitor->addVisitor(linearVisitor, 750); | 
| 117 | gezelter | 246 |  | 
| 118 | tim | 12 | //creat default atom visitor | 
| 119 | gezelter | 246 | DefaultAtomVisitor* defaultAtomVisitor = new DefaultAtomVisitor(info); | 
| 120 | tim | 12 | compositeVisitor->addVisitor(defaultAtomVisitor, 700); | 
| 121 | gezelter | 246 |  | 
| 122 | tim | 12 | //creat waterType visitor | 
| 123 |  |  | if(args_info.watertype_flag){ | 
| 124 | gezelter | 246 | WaterTypeVisitor* waterTypeVisitor = new WaterTypeVisitor; | 
| 125 | tim | 12 | compositeVisitor->addVisitor(waterTypeVisitor, 600); | 
| 126 |  |  | } | 
| 127 | gezelter | 246 |  | 
| 128 | tim | 12 | //create ZconsVisitor | 
| 129 |  |  | if(args_info.zconstraint_flag){ | 
| 130 | gezelter | 246 |  | 
| 131 |  |  | ZConsVisitor* zconsVisitor = new ZConsVisitor(info); | 
| 132 | tim | 12 |  | 
| 133 | gezelter | 246 | if(zconsVisitor->haveZconsMol()) { | 
| 134 | tim | 12 | compositeVisitor->addVisitor(zconsVisitor, 500); | 
| 135 | gezelter | 246 | } else { | 
| 136 | tim | 12 | delete zconsVisitor; | 
| 137 | gezelter | 246 | } | 
| 138 | tim | 12 | } | 
| 139 | gezelter | 246 |  | 
| 140 | tim | 12 | //creat wrapping visitor | 
| 141 | gezelter | 246 |  | 
| 142 | tim | 12 | if(args_info.periodicBox_flag){ | 
| 143 | gezelter | 246 | WrappingVisitor* wrappingVisitor = new WrappingVisitor(info); | 
| 144 | tim | 12 | compositeVisitor->addVisitor(wrappingVisitor, 400); | 
| 145 |  |  | } | 
| 146 | tim | 369 |  | 
| 147 | tim | 12 | //creat replicate visitor | 
| 148 |  |  | if(args_info.repeatX_given > 0 || args_info.repeatY_given > 0 ||args_info.repeatY_given > 0){ | 
| 149 | gezelter | 246 | Vector3i replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg); | 
| 150 |  |  | ReplicateVisitor* replicateVisitor = new ReplicateVisitor(info, replicateOpt); | 
| 151 | tim | 12 | compositeVisitor->addVisitor(replicateVisitor, 300); | 
| 152 |  |  | } | 
| 153 | tim | 369 |  | 
| 154 |  |  |  | 
| 155 |  |  | //create rotation visitor | 
| 156 |  |  | if (args_info.refsele_given&& args_info.originsele_given) { | 
| 157 |  |  | compositeVisitor->addVisitor(new LipidTransVisitor(info, args_info.originsele_arg, args_info.refsele_arg), 250); | 
| 158 |  |  | } else if (args_info.refsele_given || args_info.originsele_given) { | 
| 159 | tim | 381 | std::cerr << "Both of --refsele and --originsele should appear by pair" << std::endl; | 
| 160 | tim | 369 | exit(1); | 
| 161 |  |  | } | 
| 162 |  |  |  | 
| 163 | tim | 12 | //creat xyzVisitor | 
| 164 | tim | 413 | XYZVisitor* xyzVisitor; | 
| 165 |  |  | if (args_info.selection_given) { | 
| 166 |  |  | xyzVisitor = new XYZVisitor(info, args_info.selection_arg); | 
| 167 |  |  | } else { | 
| 168 |  |  | xyzVisitor = new XYZVisitor(info); | 
| 169 |  |  | } | 
| 170 | tim | 12 | compositeVisitor->addVisitor(xyzVisitor, 200); | 
| 171 | gezelter | 246 |  | 
| 172 |  |  | std::cout << compositeVisitor->toString(); | 
| 173 |  |  |  | 
| 174 | tim | 12 | //creat prepareVisitor | 
| 175 | gezelter | 246 | PrepareVisitor* prepareVisitor = new PrepareVisitor(); | 
| 176 |  |  |  | 
| 177 | tim | 12 | //open dump file | 
| 178 | gezelter | 246 | DumpReader* dumpReader = new DumpReader(info, dumpFileName); | 
| 179 |  |  | int nframes = dumpReader->getNFrames(); | 
| 180 |  |  |  | 
| 181 |  |  |  | 
| 182 |  |  | std::ofstream xyzStream; | 
| 183 | tim | 12 | xyzStream .open(xyzFileName.c_str()); | 
| 184 |  |  |  | 
| 185 | gezelter | 246 |  | 
| 186 |  |  | SimInfo::MoleculeIterator miter; | 
| 187 |  |  | Molecule::IntegrableObjectIterator  iiter; | 
| 188 |  |  | Molecule::RigidBodyIterator rbIter; | 
| 189 |  |  | Molecule* mol; | 
| 190 |  |  | StuntDouble* integrableObject; | 
| 191 |  |  | RigidBody* rb; | 
| 192 | tim | 413 |  | 
| 193 | tim | 12 | for (int i = 0; i < nframes; i += args_info.frame_arg){ | 
| 194 | gezelter | 246 | dumpReader->readFrame(i); | 
| 195 |  |  |  | 
| 196 | tim | 12 | //update atoms of rigidbody | 
| 197 | gezelter | 246 | for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) { | 
| 198 |  |  |  | 
| 199 |  |  | //change the positions of atoms which belong to the rigidbodies | 
| 200 |  |  | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 201 |  |  | rb->updateAtoms(); | 
| 202 |  |  | } | 
| 203 |  |  | } | 
| 204 | tim | 12 |  | 
| 205 |  |  | //prepare visit | 
| 206 | gezelter | 246 | for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) { | 
| 207 |  |  | for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL; | 
| 208 |  |  | integrableObject = mol->nextIntegrableObject(iiter)) { | 
| 209 |  |  | integrableObject->accept(prepareVisitor); | 
| 210 |  |  | } | 
| 211 |  |  | } | 
| 212 |  |  |  | 
| 213 | tim | 12 | //update visitor | 
| 214 |  |  | compositeVisitor->update(); | 
| 215 | tim | 291 |  | 
| 216 | tim | 413 |  | 
| 217 | tim | 12 | //visit stuntdouble | 
| 218 | gezelter | 246 | for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) { | 
| 219 |  |  | for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL; | 
| 220 |  |  | integrableObject = mol->nextIntegrableObject(iiter)) { | 
| 221 |  |  | integrableObject->accept(compositeVisitor); | 
| 222 |  |  | } | 
| 223 | tim | 12 | } | 
| 224 | gezelter | 246 |  | 
| 225 | tim | 12 | xyzVisitor->writeFrame(xyzStream); | 
| 226 |  |  | xyzVisitor->clear(); | 
| 227 |  |  |  | 
| 228 |  |  | }//end for (int i = 0; i < nframes; i += args_info.frame_arg) | 
| 229 | gezelter | 246 |  | 
| 230 | tim | 12 | xyzStream.close(); | 
| 231 | gezelter | 246 |  | 
| 232 | tim | 466 | delete prepareVisitor; | 
| 233 | tim | 12 | delete compositeVisitor; | 
| 234 |  |  | delete info; | 
| 235 | gezelter | 246 |  | 
| 236 | tim | 12 | } |