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 |
gezelter |
1850 |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (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 |
tim |
12 |
gengetopt_args_info args_info; |
71 |
gezelter |
1706 |
string dumpFileName; |
72 |
|
|
string xyzFileName; |
73 |
|
|
|
74 |
|
|
bool printVel(false); |
75 |
|
|
bool printFrc(false); |
76 |
|
|
bool printVec(false); |
77 |
|
|
bool printChrg(false); |
78 |
gezelter |
1871 |
bool printField(false); |
79 |
tim |
12 |
|
80 |
gezelter |
246 |
//parse the command line option |
81 |
|
|
if (cmdline_parser (argc, argv, &args_info) != 0) { |
82 |
|
|
exit(1) ; |
83 |
|
|
} |
84 |
tim |
12 |
|
85 |
|
|
//get the dumpfile name and meta-data file name |
86 |
|
|
if (args_info.input_given){ |
87 |
|
|
dumpFileName = args_info.input_arg; |
88 |
gezelter |
246 |
} else { |
89 |
gezelter |
1706 |
cerr << "Does not have input file name" << endl; |
90 |
tim |
12 |
exit(1); |
91 |
|
|
} |
92 |
gezelter |
246 |
|
93 |
tim |
12 |
if (args_info.output_given){ |
94 |
|
|
xyzFileName = args_info.output_arg; |
95 |
gezelter |
246 |
} else { |
96 |
tim |
12 |
xyzFileName = dumpFileName; |
97 |
|
|
xyzFileName = xyzFileName.substr(0, xyzFileName.rfind(".")) + ".xyz"; |
98 |
|
|
} |
99 |
gezelter |
246 |
|
100 |
tim |
12 |
//parse md file and set up the system |
101 |
gezelter |
246 |
SimCreator creator; |
102 |
gezelter |
1026 |
SimInfo* info = creator.createSim(dumpFileName, false); |
103 |
gezelter |
1456 |
ForceManager* forceMan = new ForceManager(info); |
104 |
tim |
12 |
|
105 |
chrisfen |
527 |
//create visitor list |
106 |
gezelter |
246 |
CompositeVisitor* compositeVisitor = new CompositeVisitor(); |
107 |
gezelter |
1455 |
|
108 |
chrisfen |
527 |
//create RigidBody Visitor |
109 |
tim |
12 |
if(args_info.rigidbody_flag){ |
110 |
gezelter |
246 |
RBCOMVisitor* rbCOMVisitor = new RBCOMVisitor(info); |
111 |
tim |
12 |
compositeVisitor->addVisitor(rbCOMVisitor, 900); |
112 |
|
|
} |
113 |
gezelter |
246 |
|
114 |
chrisfen |
527 |
//create SSD atom visitor |
115 |
gezelter |
246 |
SSDAtomVisitor* ssdVisitor = new SSDAtomVisitor(info); |
116 |
tim |
12 |
compositeVisitor->addVisitor(ssdVisitor, 800); |
117 |
gezelter |
246 |
|
118 |
gezelter |
1629 |
//create GBtail atom visitor |
119 |
|
|
GBtailVisitor* gbtVisitor = new GBtailVisitor(info); |
120 |
|
|
compositeVisitor->addVisitor(gbtVisitor, 790); |
121 |
|
|
|
122 |
|
|
//create GBhead atom visitor |
123 |
|
|
GBheadVisitor* gbhVisitor = new GBheadVisitor(info); |
124 |
|
|
compositeVisitor->addVisitor(gbhVisitor, 789); |
125 |
|
|
|
126 |
chrisfen |
527 |
//create default atom visitor |
127 |
gezelter |
246 |
DefaultAtomVisitor* defaultAtomVisitor = new DefaultAtomVisitor(info); |
128 |
tim |
12 |
compositeVisitor->addVisitor(defaultAtomVisitor, 700); |
129 |
gezelter |
246 |
|
130 |
cli2 |
1303 |
// if we gave the -w option, we want to skip the waters: |
131 |
|
|
if (!args_info.water_given) { |
132 |
|
|
//create waterType visitor |
133 |
|
|
if(args_info.watertype_flag){ |
134 |
|
|
WaterTypeVisitor* waterTypeVisitor = new WaterTypeVisitor; |
135 |
|
|
compositeVisitor->addVisitor(waterTypeVisitor, 600); |
136 |
|
|
} |
137 |
gezelter |
1455 |
} |
138 |
|
|
|
139 |
tim |
543 |
if (args_info.basetype_flag) { |
140 |
gezelter |
1455 |
AtomNameVisitor* atomNameVisitor = new AtomNameVisitor(info); |
141 |
|
|
compositeVisitor->addVisitor(atomNameVisitor, 550); |
142 |
gezelter |
1706 |
cout << compositeVisitor->toString(); |
143 |
tim |
543 |
} |
144 |
gezelter |
246 |
|
145 |
tim |
12 |
//create ZconsVisitor |
146 |
|
|
if(args_info.zconstraint_flag){ |
147 |
gezelter |
246 |
|
148 |
|
|
ZConsVisitor* zconsVisitor = new ZConsVisitor(info); |
149 |
tim |
12 |
|
150 |
gezelter |
246 |
if(zconsVisitor->haveZconsMol()) { |
151 |
tim |
12 |
compositeVisitor->addVisitor(zconsVisitor, 500); |
152 |
gezelter |
246 |
} else { |
153 |
tim |
12 |
delete zconsVisitor; |
154 |
gezelter |
246 |
} |
155 |
tim |
12 |
} |
156 |
gezelter |
246 |
|
157 |
chrisfen |
527 |
//create wrapping visitor |
158 |
gezelter |
246 |
|
159 |
tim |
968 |
//if(args_info.periodicBox_flag){ |
160 |
|
|
// WrappingVisitor* wrappingVisitor = new WrappingVisitor(info); |
161 |
|
|
// compositeVisitor->addVisitor(wrappingVisitor, 400); |
162 |
|
|
//} |
163 |
tim |
369 |
|
164 |
chrisfen |
527 |
//create replicate visitor |
165 |
gezelter |
1456 |
if(args_info.repeatX_given > 0 || |
166 |
|
|
args_info.repeatY_given > 0 || |
167 |
gezelter |
1874 |
args_info.repeatZ_given > 0) { |
168 |
gezelter |
1456 |
Vector3i replicateOpt(args_info.repeatX_arg, |
169 |
|
|
args_info.repeatY_arg, |
170 |
|
|
args_info.repeatZ_arg); |
171 |
|
|
ReplicateVisitor* replicateVisitor = new ReplicateVisitor(info, |
172 |
|
|
replicateOpt); |
173 |
tim |
12 |
compositeVisitor->addVisitor(replicateVisitor, 300); |
174 |
|
|
} |
175 |
tim |
369 |
|
176 |
|
|
|
177 |
|
|
//create rotation visitor |
178 |
|
|
if (args_info.refsele_given&& args_info.originsele_given) { |
179 |
gezelter |
1456 |
compositeVisitor->addVisitor(new LipidTransVisitor(info, |
180 |
|
|
args_info.originsele_arg, |
181 |
|
|
args_info.refsele_arg), |
182 |
|
|
250); |
183 |
tim |
369 |
} else if (args_info.refsele_given || args_info.originsele_given) { |
184 |
gezelter |
1706 |
cerr << "Both of --refsele and --originsele should appear by pair" |
185 |
gezelter |
1769 |
<< endl; |
186 |
tim |
369 |
exit(1); |
187 |
|
|
} |
188 |
gezelter |
1456 |
|
189 |
chrisfen |
527 |
//create xyzVisitor |
190 |
tim |
413 |
XYZVisitor* xyzVisitor; |
191 |
chuckv |
1117 |
|
192 |
tim |
413 |
if (args_info.selection_given) { |
193 |
|
|
xyzVisitor = new XYZVisitor(info, args_info.selection_arg); |
194 |
|
|
} else { |
195 |
|
|
xyzVisitor = new XYZVisitor(info); |
196 |
|
|
} |
197 |
chuckv |
1117 |
|
198 |
gezelter |
1456 |
if(args_info.velocities_flag){ |
199 |
|
|
printVel = true; |
200 |
|
|
xyzVisitor->doVelocities(printVel); |
201 |
chuckv |
1117 |
} |
202 |
gezelter |
1456 |
if(args_info.forces_flag){ |
203 |
|
|
printFrc = true; |
204 |
|
|
xyzVisitor->doForces(printFrc); |
205 |
|
|
} |
206 |
|
|
if(args_info.vectors_flag){ |
207 |
|
|
printVec = true; |
208 |
|
|
xyzVisitor->doVectors(printVec); |
209 |
|
|
} |
210 |
|
|
if(args_info.charges_flag){ |
211 |
|
|
printChrg = true; |
212 |
|
|
xyzVisitor->doCharges(printChrg); |
213 |
|
|
} |
214 |
gezelter |
1871 |
if(args_info.efield_flag){ |
215 |
|
|
printField = true; |
216 |
|
|
xyzVisitor->doElectricFields(printField); |
217 |
|
|
} |
218 |
gezelter |
1456 |
|
219 |
gezelter |
1455 |
compositeVisitor->addVisitor(xyzVisitor, 200); |
220 |
gezelter |
246 |
|
221 |
chrisfen |
527 |
//create prepareVisitor |
222 |
gezelter |
246 |
PrepareVisitor* prepareVisitor = new PrepareVisitor(); |
223 |
|
|
|
224 |
tim |
12 |
//open dump file |
225 |
gezelter |
246 |
DumpReader* dumpReader = new DumpReader(info, dumpFileName); |
226 |
|
|
int nframes = dumpReader->getNFrames(); |
227 |
|
|
|
228 |
gezelter |
1706 |
ofstream xyzStream(xyzFileName.c_str()); |
229 |
tim |
12 |
|
230 |
gezelter |
246 |
SimInfo::MoleculeIterator miter; |
231 |
|
|
Molecule::IntegrableObjectIterator iiter; |
232 |
|
|
Molecule::RigidBodyIterator rbIter; |
233 |
|
|
Molecule* mol; |
234 |
gezelter |
1769 |
StuntDouble* sd; |
235 |
gezelter |
246 |
RigidBody* rb; |
236 |
tim |
968 |
Vector3d molCom; |
237 |
|
|
Vector3d newMolCom; |
238 |
|
|
Vector3d displacement; |
239 |
|
|
Mat3x3d hmat; |
240 |
|
|
Snapshot* currentSnapshot; |
241 |
tim |
413 |
|
242 |
tim |
12 |
for (int i = 0; i < nframes; i += args_info.frame_arg){ |
243 |
gezelter |
246 |
dumpReader->readFrame(i); |
244 |
gezelter |
1456 |
|
245 |
gezelter |
1464 |
if (printFrc) forceMan->calcForces(); |
246 |
gezelter |
1456 |
|
247 |
tim |
968 |
//wrapping the molecule |
248 |
|
|
if(args_info.periodicBox_flag) { |
249 |
|
|
currentSnapshot = info->getSnapshotManager()->getCurrentSnapshot(); |
250 |
gezelter |
1456 |
for (mol = info->beginMolecule(miter); mol != NULL; |
251 |
|
|
mol = info->nextMolecule(miter)) { |
252 |
gezelter |
1769 |
|
253 |
|
|
molCom = mol->getCom(); |
254 |
|
|
newMolCom = molCom; |
255 |
|
|
currentSnapshot->wrapVector(newMolCom); |
256 |
|
|
displacement = newMolCom - molCom; |
257 |
|
|
|
258 |
|
|
for (sd = mol->beginIntegrableObject(iiter); sd != NULL; |
259 |
|
|
sd = mol->nextIntegrableObject(iiter)) { |
260 |
|
|
|
261 |
|
|
sd->setPos(sd->getPos() + displacement); |
262 |
|
|
|
263 |
tim |
968 |
} |
264 |
|
|
} |
265 |
|
|
} |
266 |
gezelter |
1769 |
|
267 |
tim |
12 |
//update atoms of rigidbody |
268 |
gezelter |
1456 |
for (mol = info->beginMolecule(miter); mol != NULL; |
269 |
|
|
mol = info->nextMolecule(miter)) { |
270 |
gezelter |
246 |
|
271 |
|
|
//change the positions of atoms which belong to the rigidbodies |
272 |
gezelter |
1456 |
for (rb = mol->beginRigidBody(rbIter); rb != NULL; |
273 |
|
|
rb = mol->nextRigidBody(rbIter)) { |
274 |
gezelter |
1769 |
|
275 |
gezelter |
246 |
rb->updateAtoms(); |
276 |
gezelter |
1456 |
if (printVel) rb->updateAtomVel(); |
277 |
gezelter |
1769 |
|
278 |
gezelter |
246 |
} |
279 |
|
|
} |
280 |
tim |
12 |
|
281 |
|
|
//prepare visit |
282 |
gezelter |
1456 |
for (mol = info->beginMolecule(miter); mol != NULL; |
283 |
|
|
mol = info->nextMolecule(miter)) { |
284 |
gezelter |
1769 |
|
285 |
|
|
for (sd = mol->beginIntegrableObject(iiter); sd != NULL; |
286 |
|
|
sd = mol->nextIntegrableObject(iiter)) { |
287 |
|
|
|
288 |
|
|
sd->accept(prepareVisitor); |
289 |
|
|
|
290 |
gezelter |
246 |
} |
291 |
|
|
} |
292 |
|
|
|
293 |
tim |
12 |
//update visitor |
294 |
|
|
compositeVisitor->update(); |
295 |
tim |
291 |
|
296 |
tim |
413 |
|
297 |
tim |
12 |
//visit stuntdouble |
298 |
gezelter |
1456 |
for (mol = info->beginMolecule(miter); mol != NULL; |
299 |
|
|
mol = info->nextMolecule(miter)) { |
300 |
gezelter |
1769 |
|
301 |
|
|
for (sd = mol->beginIntegrableObject(iiter); sd != NULL; |
302 |
|
|
sd = mol->nextIntegrableObject(iiter)) { |
303 |
|
|
|
304 |
|
|
sd->accept(compositeVisitor); |
305 |
|
|
|
306 |
gezelter |
246 |
} |
307 |
tim |
12 |
} |
308 |
gezelter |
246 |
|
309 |
tim |
12 |
xyzVisitor->writeFrame(xyzStream); |
310 |
|
|
xyzVisitor->clear(); |
311 |
|
|
|
312 |
|
|
}//end for (int i = 0; i < nframes; i += args_info.frame_arg) |
313 |
gezelter |
1282 |
|
314 |
tim |
12 |
xyzStream.close(); |
315 |
tim |
466 |
delete prepareVisitor; |
316 |
tim |
12 |
delete compositeVisitor; |
317 |
|
|
delete info; |
318 |
|
|
} |