OpenMD 3.2
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 following paper when you publish your work:
33 *
34 * [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35 *
36 * Good starting points for code and simulation methodology are:
37 *
38 * [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39 * [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40 * [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43 * [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45 * [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46 */
47
48#include <fstream>
49#include <iostream>
50#include <string>
51
52#include "Dump2XYZCmd.hpp"
54#include "brains/Register.hpp"
55#include "brains/SimCreator.hpp"
56#include "brains/SimInfo.hpp"
57#include "io/DumpReader.hpp"
58#include "selection/SelectionEvaluator.hpp"
59#include "selection/SelectionManager.hpp"
60#include "utils/simError.h"
61#include "visitors/AtomNameVisitor.hpp"
62#include "visitors/AtomVisitor.hpp"
63#include "visitors/CompositeVisitor.hpp"
64#include "visitors/LipidTransVisitor.hpp"
65#include "visitors/OtherVisitor.hpp"
66#include "visitors/ReplacementVisitor.hpp"
67#include "visitors/RigidBodyVisitor.hpp"
68#include "visitors/ZconsVisitor.hpp"
69
70using namespace OpenMD;
71
72using namespace std;
73int main(int argc, char* argv[]) {
74 gengetopt_args_info args_info;
75 string dumpFileName;
76 string xyzFileName;
77
78 bool printVel(false);
79 bool printFrc(false);
80 bool printVec(false);
81 bool printChrg(false);
82 bool printField(false);
83 bool printGlobalID(false);
84
85 // parse the command line option
86 if (cmdline_parser(argc, argv, &args_info) != 0) { exit(1); }
87
88 // get the dumpfile name and meta-data file name
89 if (args_info.input_given) {
90 dumpFileName = args_info.input_arg;
91 } else {
92 strcpy(painCave.errMsg, "No input file name was specified.\n");
93 painCave.isFatal = 1;
94 simError();
95 }
96
97 if (args_info.output_given) {
98 xyzFileName = args_info.output_arg;
99 } else {
100 xyzFileName = dumpFileName;
101 xyzFileName = xyzFileName.substr(0, xyzFileName.rfind(".")) + ".xyz";
102 }
103
104 // parse md file and set up the system
105 SimCreator creator;
106 SimInfo* info = creator.createSim(dumpFileName, false);
107 ForceManager* forceMan = new ForceManager(info);
108
109 // create visitor list
110 CompositeVisitor* compositeVisitor = new CompositeVisitor();
111
112 // create RigidBody Visitor
113 if (args_info.rigidbody_flag) {
114 RBCOMVisitor* rbCOMVisitor = new RBCOMVisitor(info);
115 compositeVisitor->addVisitor(rbCOMVisitor, 900);
116 }
117
118 // create SSD atom visitor
119 SSDAtomVisitor* ssdVisitor = new SSDAtomVisitor(info);
120 compositeVisitor->addVisitor(ssdVisitor, 800);
121
122 // create GBtail atom visitor
123 GBtailVisitor* gbtVisitor = new GBtailVisitor(info);
124 compositeVisitor->addVisitor(gbtVisitor, 790);
125
126 // create GBhead atom visitor
127 GBheadVisitor* gbhVisitor = new GBheadVisitor(info);
128 compositeVisitor->addVisitor(gbhVisitor, 789);
129
130 // create default atom visitor
131 DefaultAtomVisitor* defaultAtomVisitor = new DefaultAtomVisitor(info);
132 compositeVisitor->addVisitor(defaultAtomVisitor, 700);
133
134 // if we gave the -w option, we want to skip the waters:
135 if (!args_info.water_given) {
136 // create waterType visitor
137 if (args_info.watertype_flag) {
138 WaterTypeVisitor* waterTypeVisitor = new WaterTypeVisitor;
139 compositeVisitor->addVisitor(waterTypeVisitor, 600);
140 }
141 }
142
143 if (args_info.basetype_flag) {
144 AtomNameVisitor* atomNameVisitor = new AtomNameVisitor(info);
145 compositeVisitor->addVisitor(atomNameVisitor, 550);
146 // When debugging visitors, you may find this helpful:
147 // cout << compositeVisitor->toString();
148 }
149
150 // create ZconsVisitor
151 if (args_info.zconstraint_flag) {
152 ZConsVisitor* zconsVisitor = new ZConsVisitor(info);
153
154 if (zconsVisitor->haveZconsMol()) {
155 compositeVisitor->addVisitor(zconsVisitor, 500);
156 } else {
157 delete zconsVisitor;
158 }
159 }
160
161 // create wrapping visitor
162
163 // if(args_info.periodicBox_flag){
164 // WrappingVisitor* wrappingVisitor = new WrappingVisitor(info);
165 // compositeVisitor->addVisitor(wrappingVisitor, 400);
166 //}
167
168 // create replicate visitor
169 if (args_info.repeatX_given > 0 || args_info.repeatY_given > 0 ||
170 args_info.repeatZ_given > 0) {
171 Vector3i replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg,
172 args_info.repeatZ_arg);
173 ReplicateVisitor* replicateVisitor =
174 new ReplicateVisitor(info, replicateOpt);
175 compositeVisitor->addVisitor(replicateVisitor, 300);
176 }
177
178 // create rotation visitor
179 if (args_info.refsele_given && args_info.originsele_given) {
180 compositeVisitor->addVisitor(
181 new LipidTransVisitor(info, args_info.originsele_arg,
182 args_info.refsele_arg),
183 250);
184 } else if (args_info.refsele_given || args_info.originsele_given) {
185 strcpy(
186 painCave.errMsg,
187 "The --refsele and --originsele arguments should appear together.\n");
188 painCave.isFatal = 1;
189 simError();
190 }
191
192 // create xyzVisitor
193 XYZVisitor* xyzVisitor;
194
195 if (args_info.selection_given) {
196 xyzVisitor = new XYZVisitor(info, args_info.selection_arg);
197 } else {
198 xyzVisitor = new XYZVisitor(info);
199 }
200
201 if (args_info.velocities_flag) {
202 printVel = true;
203 xyzVisitor->doVelocities(printVel);
204 }
205 if (args_info.forces_flag) {
206 printFrc = true;
207 xyzVisitor->doForces(printFrc);
208 }
209 if (args_info.vectors_flag) {
210 printVec = true;
211 xyzVisitor->doVectors(printVec);
212 }
213 if (args_info.charges_flag) {
214 printChrg = true;
215 xyzVisitor->doCharges(printChrg);
216 }
217 if (args_info.efield_flag) {
218 printField = true;
219 xyzVisitor->doElectricFields(printField);
220 }
221 if (args_info.globalID_flag) {
222 printGlobalID = true;
223 xyzVisitor->doGlobalIDs(printGlobalID);
224 }
225
226 compositeVisitor->addVisitor(xyzVisitor, 200);
227
228 // create prepareVisitor
229 PrepareVisitor* prepareVisitor = new PrepareVisitor();
230
231 // open dump file
232 DumpReader* dumpReader = new DumpReader(info, dumpFileName);
233 int nframes = dumpReader->getNFrames();
234
235 ofstream xyzStream(xyzFileName.c_str());
236
237 SimInfo::MoleculeIterator miter;
238 Molecule::IntegrableObjectIterator iiter;
239 Molecule::RigidBodyIterator rbIter;
240 Molecule* mol;
241 StuntDouble* sd;
242 RigidBody* rb;
243 Vector3d molCom;
244 Vector3d newMolCom;
245 Vector3d displacement;
246 Mat3x3d hmat;
247 Snapshot* currentSnapshot;
248
249 for (int i = 0; i < nframes; i += args_info.frame_arg) {
250 dumpReader->readFrame(i);
251
252 if (printFrc) forceMan->calcForces();
253
254 // wrapping the molecule
255 if (args_info.periodicBox_flag) {
256 currentSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
257 for (mol = info->beginMolecule(miter); mol != NULL;
258 mol = info->nextMolecule(miter)) {
259 molCom = mol->getCom();
260 newMolCom = molCom;
261 currentSnapshot->wrapVector(newMolCom);
262 displacement = newMolCom - molCom;
263
264 for (sd = mol->beginIntegrableObject(iiter); sd != NULL;
265 sd = mol->nextIntegrableObject(iiter)) {
266 sd->setPos(sd->getPos() + displacement);
267 }
268 }
269 }
270
271 // update atoms of rigidbody
272 for (mol = info->beginMolecule(miter); mol != NULL;
273 mol = info->nextMolecule(miter)) {
274 // change the positions of atoms which belong to the rigidbodies
275 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
276 rb = mol->nextRigidBody(rbIter)) {
277 rb->updateAtoms();
278 if (printVel) rb->updateAtomVel();
279 }
280 }
281
282 // prepare visit
283 for (mol = info->beginMolecule(miter); mol != NULL;
284 mol = info->nextMolecule(miter)) {
285 for (sd = mol->beginIntegrableObject(iiter); sd != NULL;
286 sd = mol->nextIntegrableObject(iiter)) {
287 sd->accept(prepareVisitor);
288 }
289 }
290
291 // update visitor
292 compositeVisitor->update();
293
294 // visit stuntdouble
295 for (mol = info->beginMolecule(miter); mol != NULL;
296 mol = info->nextMolecule(miter)) {
297 for (sd = mol->beginIntegrableObject(iiter); sd != NULL;
298 sd = mol->nextIntegrableObject(iiter)) {
299 sd->accept(compositeVisitor);
300 }
301 }
302
303 xyzVisitor->writeFrame(xyzStream);
304 xyzVisitor->clear();
305
306 } // end for (int i = 0; i < nframes; i += args_info.frame_arg)
307
308 xyzStream.close();
309
310 delete forceMan;
311 delete compositeVisitor;
312 delete prepareVisitor;
313 delete dumpReader;
314
315 delete info;
316}
The header file for the command line option parser generated by GNU Gengetopt version 2....
int getNFrames()
Returns the number of frames in the dump file.
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:315
void updateAtoms()
update the positions of atoms belong to this rigidbody
The only responsibility of SimCreator is to parse the meta-data file and create a SimInfo instance ba...
SimInfo * createSim(const std::string &mdFileName, bool loadInitCoords=true)
Setup Simulation.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Definition SimInfo.hpp:96
Molecule * beginMolecule(MoleculeIterator &i)
Returns the first molecule in this SimInfo and intialize the iterator.
Definition SimInfo.cpp:243
Molecule * nextMolecule(MoleculeIterator &i)
Returns the next avaliable Molecule based on the iterator.
Definition SimInfo.cpp:248
SnapshotManager * getSnapshotManager()
Returns the snapshot manager.
Definition SimInfo.hpp:251
The Snapshot class is a repository storing dynamic data during a Simulation.
Definition Snapshot.hpp:166
void wrapVector(Vector3d &v)
Wrapping the vector according to periodic boundary condition.
Definition Snapshot.cpp:340
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.
int repeatY_arg
The number of images to repeat in the y direction (default='0').
unsigned int output_given
Whether output was given.
int vectors_flag
Print vectors (dipoles, etc) in xyz file (default=off).
int rigidbody_flag
add a pseudo COM atom to rigidbody (default=off).
unsigned int repeatY_given
Whether repeatY was given.
int watertype_flag
replace the atom type of water model (default=on).
unsigned int repeatX_given
Whether repeatX was given.
int repeatX_arg
The number of images to repeat in the x direction (default='0').
int charges_flag
Print charges in xyz file (default=off).
int periodicBox_flag
map to the periodic box (default=off).
unsigned int refsele_given
Whether refsele was given.
int basetype_flag
Convert to base atom type (default=off).
char * output_arg
output file name.
char * input_arg
input dump file.
int velocities_flag
Print velocities in xyz file (default=off).
int repeatZ_arg
The number of images to repeat in the z direction (default='0').
unsigned int repeatZ_given
Whether repeatZ was given.
unsigned int selection_given
Whether selection was given.
char * refsele_arg
select reference.
int forces_flag
Print forces xyz file (default=off).
int globalID_flag
Print global ID in xyz file (default=off).
unsigned int water_given
Whether water was given.
int frame_arg
print every n frame (default='1').
unsigned int input_given
Whether input was given.
unsigned int originsele_given
Whether originsele was given.
char * originsele_arg
select origin.
int efield_flag
Print electric field vector in xyz file (default=off).
int zconstraint_flag
replace the atom types of zconstraint molecules (default=off).
char * selection_arg
general selection syntax.