OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
Dump2XYZ.cpp
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
45#include <fstream>
46#include <iostream>
47#include <string>
48
49#include "Dump2XYZCmd.hpp"
51#include "brains/Register.hpp"
52#include "brains/SimCreator.hpp"
53#include "brains/SimInfo.hpp"
54#include "io/DumpReader.hpp"
55#include "selection/SelectionEvaluator.hpp"
56#include "selection/SelectionManager.hpp"
57#include "utils/simError.h"
58#include "visitors/AtomNameVisitor.hpp"
59#include "visitors/AtomVisitor.hpp"
60#include "visitors/CompositeVisitor.hpp"
61#include "visitors/LipidTransVisitor.hpp"
62#include "visitors/OtherVisitor.hpp"
63#include "visitors/ReplacementVisitor.hpp"
64#include "visitors/RigidBodyVisitor.hpp"
65#include "visitors/ZconsVisitor.hpp"
66
67using namespace OpenMD;
68
69using namespace std;
70int main(int argc, char* argv[]) {
71 gengetopt_args_info args_info;
72 string dumpFileName;
73 string xyzFileName;
74
75 bool printVel(false);
76 bool printFrc(false);
77 bool printVec(false);
78 bool printChrg(false);
79 bool printField(false);
80 bool printGlobalID(false);
81
82 // parse the command line option
83 if (cmdline_parser(argc, argv, &args_info) != 0) { exit(1); }
84
85 // get the dumpfile name and meta-data file name
86 if (args_info.input_given) {
87 dumpFileName = args_info.input_arg;
88 } else {
89 strcpy(painCave.errMsg, "No input file name was specified.\n");
90 painCave.isFatal = 1;
91 simError();
92 }
93
94 if (args_info.output_given) {
95 xyzFileName = args_info.output_arg;
96 } else {
97 xyzFileName = dumpFileName;
98 xyzFileName = xyzFileName.substr(0, xyzFileName.rfind(".")) + ".xyz";
99 }
100
101 // parse md file and set up the system
102 SimCreator creator;
103 SimInfo* info = creator.createSim(dumpFileName, false);
104 ForceManager* forceMan = new ForceManager(info);
105
106 // create visitor list
107 CompositeVisitor* compositeVisitor = new CompositeVisitor();
108
109 // create RigidBody Visitor
110 if (args_info.rigidbody_flag) {
111 RBCOMVisitor* rbCOMVisitor = new RBCOMVisitor(info);
112 compositeVisitor->addVisitor(rbCOMVisitor, 900);
113 }
114
115 // create SSD atom visitor
116 SSDAtomVisitor* ssdVisitor = new SSDAtomVisitor(info);
117 compositeVisitor->addVisitor(ssdVisitor, 800);
118
119 // create GBtail atom visitor
120 GBtailVisitor* gbtVisitor = new GBtailVisitor(info);
121 compositeVisitor->addVisitor(gbtVisitor, 790);
122
123 // create GBhead atom visitor
124 GBheadVisitor* gbhVisitor = new GBheadVisitor(info);
125 compositeVisitor->addVisitor(gbhVisitor, 789);
126
127 // create default atom visitor
128 DefaultAtomVisitor* defaultAtomVisitor = new DefaultAtomVisitor(info);
129 compositeVisitor->addVisitor(defaultAtomVisitor, 700);
130
131 // if we gave the -w option, we want to skip the waters:
132 if (!args_info.water_given) {
133 // create waterType visitor
134 if (args_info.watertype_flag) {
135 WaterTypeVisitor* waterTypeVisitor = new WaterTypeVisitor;
136 compositeVisitor->addVisitor(waterTypeVisitor, 600);
137 }
138 }
139
140 if (args_info.basetype_flag) {
141 AtomNameVisitor* atomNameVisitor = new AtomNameVisitor(info);
142 compositeVisitor->addVisitor(atomNameVisitor, 550);
143 // When debugging visitors, you may find this helpful:
144 // cout << compositeVisitor->toString();
145 }
146
147 // create ZconsVisitor
148 if (args_info.zconstraint_flag) {
149 ZConsVisitor* zconsVisitor = new ZConsVisitor(info);
150
151 if (zconsVisitor->haveZconsMol()) {
152 compositeVisitor->addVisitor(zconsVisitor, 500);
153 } else {
154 delete zconsVisitor;
155 }
156 }
157
158 // create wrapping visitor
159
160 // if(args_info.periodicBox_flag){
161 // WrappingVisitor* wrappingVisitor = new WrappingVisitor(info);
162 // compositeVisitor->addVisitor(wrappingVisitor, 400);
163 //}
164
165 // create replicate visitor
166 if (args_info.repeatX_given > 0 || args_info.repeatY_given > 0 ||
167 args_info.repeatZ_given > 0) {
168 Vector3i replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg,
169 args_info.repeatZ_arg);
170 ReplicateVisitor* replicateVisitor =
171 new ReplicateVisitor(info, replicateOpt);
172 compositeVisitor->addVisitor(replicateVisitor, 300);
173 }
174
175 // create rotation visitor
176 if (args_info.refsele_given && args_info.originsele_given) {
177 compositeVisitor->addVisitor(
178 new LipidTransVisitor(info, args_info.originsele_arg,
179 args_info.refsele_arg),
180 250);
181 } else if (args_info.refsele_given || args_info.originsele_given) {
182 strcpy(
183 painCave.errMsg,
184 "The --refsele and --originsele arguments should appear together.\n");
185 painCave.isFatal = 1;
186 simError();
187 }
188
189 // create xyzVisitor
190 XYZVisitor* xyzVisitor;
191
192 if (args_info.selection_given) {
193 xyzVisitor = new XYZVisitor(info, args_info.selection_arg);
194 } else {
195 xyzVisitor = new XYZVisitor(info);
196 }
197
198 if (args_info.velocities_flag) {
199 printVel = true;
200 xyzVisitor->doVelocities(printVel);
201 }
202 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 if (args_info.efield_flag) {
215 printField = true;
216 xyzVisitor->doElectricFields(printField);
217 }
218 if (args_info.globalID_flag) {
219 printGlobalID = true;
220 xyzVisitor->doGlobalIDs(printGlobalID);
221 }
222
223 compositeVisitor->addVisitor(xyzVisitor, 200);
224
225 // create prepareVisitor
226 PrepareVisitor* prepareVisitor = new PrepareVisitor();
227
228 // open dump file
229 DumpReader* dumpReader = new DumpReader(info, dumpFileName);
230 int nframes = dumpReader->getNFrames();
231
232 ofstream xyzStream(xyzFileName.c_str());
233
234 SimInfo::MoleculeIterator miter;
235 Molecule::IntegrableObjectIterator iiter;
236 Molecule::RigidBodyIterator rbIter;
237 Molecule* mol;
238 StuntDouble* sd;
239 RigidBody* rb;
240 Vector3d molCom;
241 Vector3d newMolCom;
242 Vector3d displacement;
243 Mat3x3d hmat;
244 Snapshot* currentSnapshot;
245
246 for (int i = 0; i < nframes; i += args_info.frame_arg) {
247 dumpReader->readFrame(i);
248
249 if (printFrc) forceMan->calcForces();
250
251 // wrapping the molecule
252 if (args_info.periodicBox_flag) {
253 currentSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
254 for (mol = info->beginMolecule(miter); mol != NULL;
255 mol = info->nextMolecule(miter)) {
256 molCom = mol->getCom();
257 newMolCom = molCom;
258 currentSnapshot->wrapVector(newMolCom);
259 displacement = newMolCom - molCom;
260
261 for (sd = mol->beginIntegrableObject(iiter); sd != NULL;
262 sd = mol->nextIntegrableObject(iiter)) {
263 sd->setPos(sd->getPos() + displacement);
264 }
265 }
266 }
267
268 // update atoms of rigidbody
269 for (mol = info->beginMolecule(miter); mol != NULL;
270 mol = info->nextMolecule(miter)) {
271 // change the positions of atoms which belong to the rigidbodies
272 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
273 rb = mol->nextRigidBody(rbIter)) {
274 rb->updateAtoms();
275 if (printVel) rb->updateAtomVel();
276 }
277 }
278
279 // prepare visit
280 for (mol = info->beginMolecule(miter); mol != NULL;
281 mol = info->nextMolecule(miter)) {
282 for (sd = mol->beginIntegrableObject(iiter); sd != NULL;
283 sd = mol->nextIntegrableObject(iiter)) {
284 sd->accept(prepareVisitor);
285 }
286 }
287
288 // update visitor
289 compositeVisitor->update();
290
291 // visit stuntdouble
292 for (mol = info->beginMolecule(miter); mol != NULL;
293 mol = info->nextMolecule(miter)) {
294 for (sd = mol->beginIntegrableObject(iiter); sd != NULL;
295 sd = mol->nextIntegrableObject(iiter)) {
296 sd->accept(compositeVisitor);
297 }
298 }
299
300 xyzVisitor->writeFrame(xyzStream);
301 xyzVisitor->clear();
302
303 } // end for (int i = 0; i < nframes; i += args_info.frame_arg)
304
305 xyzStream.close();
306
307 delete forceMan;
308 delete compositeVisitor;
309 delete prepareVisitor;
310 delete dumpReader;
311
312 delete info;
313}
The header file for the command line option parser generated by GNU Gengetopt version 2....
ForceManager is responsible for calculating both the short range (bonded) interactions and long range...
Vector3d getCom()
Returns the current center of mass position of this molecule.
Definition Molecule.cpp:298
The only responsibility of SimCreator is to parse the meta-data file and create a SimInfo instance ba...
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Definition SimInfo.hpp:93
Molecule * beginMolecule(MoleculeIterator &i)
Returns the first molecule in this SimInfo and intialize the iterator.
Definition SimInfo.cpp:240
Molecule * nextMolecule(MoleculeIterator &i)
Returns the next avaliable Molecule based on the iterator.
Definition SimInfo.cpp:245
SnapshotManager * getSnapshotManager()
Returns the snapshot manager.
Definition SimInfo.hpp:248
The Snapshot class is a repository storing dynamic data during a Simulation.
Definition Snapshot.hpp:147
Snapshot * getCurrentSnapshot()
Returns the pointer of current snapshot.
"Don't move, or you're dead! Stand up! Captain, we've got them!"
virtual void accept(BaseVisitor *v)=0
Vector3d getPos()
Returns the current position of this stuntDouble.
void setPos(const Vector3d &pos)
Sets the current position of this stuntDouble.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Where the command line options are stored.