ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/dump2Xyz/Dump2XYZ.cpp
Revision: 3321
Committed: Wed Jan 23 21:21:13 2008 UTC (16 years, 5 months ago) by xsun
File size: 9318 byte(s)
Log Message:
Added a few visitors

File Contents

# Content
1 /*
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 #include <iostream>
43 #include <fstream>
44 #include <string>
45
46 #include "applications/dump2Xyz/Dump2XYZCmd.h"
47 #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 #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 #include "selection/SelectionEvaluator.hpp"
58 #include "selection/SelectionManager.hpp"
59 #include "visitors/LipidTransVisitor.hpp"
60 #include "visitors/AtomNameVisitor.hpp"
61
62 using namespace oopse;
63
64 int main(int argc, char* argv[]){
65
66 //register force fields
67 registerForceFields();
68
69 gengetopt_args_info args_info;
70 std::string dumpFileName;
71 std::string xyzFileName;
72
73 //parse the command line option
74 if (cmdline_parser (argc, argv, &args_info) != 0) {
75 exit(1) ;
76 }
77
78 //get the dumpfile name and meta-data file name
79 if (args_info.input_given){
80 dumpFileName = args_info.input_arg;
81 } else {
82 std::cerr << "Does not have input file name" << std::endl;
83 exit(1);
84 }
85
86 if (args_info.output_given){
87 xyzFileName = args_info.output_arg;
88 } else {
89 xyzFileName = dumpFileName;
90 xyzFileName = xyzFileName.substr(0, xyzFileName.rfind(".")) + ".xyz";
91 }
92
93 //parse md file and set up the system
94 SimCreator creator;
95 SimInfo* info = creator.createSim(dumpFileName, false);
96
97
98 //create visitor list
99 CompositeVisitor* compositeVisitor = new CompositeVisitor();
100
101 //create RigidBody Visitor
102 if(args_info.rigidbody_flag){
103 RBCOMVisitor* rbCOMVisitor = new RBCOMVisitor(info);
104 compositeVisitor->addVisitor(rbCOMVisitor, 900);
105 }
106
107 //create SSD atom visitor
108 SSDAtomVisitor* ssdVisitor = new SSDAtomVisitor(info);
109 compositeVisitor->addVisitor(ssdVisitor, 800);
110
111 LinearAtomVisitor* linearVisitor = new LinearAtomVisitor(info);
112 compositeVisitor->addVisitor(linearVisitor, 750);
113 if (args_info.gb_given) {
114 linearVisitor->addGayBerneAtomType(args_info.gb_arg);
115 }
116
117 GBLipidAtomVisitor* gbLipidVisitor = new GBLipidAtomVisitor(info);
118 compositeVisitor->addVisitor(gbLipidVisitor, 740);
119
120 Ring5gbAtomVisitor* ring5Visitor = new Ring5gbAtomVisitor(info);
121 compositeVisitor->addVisitor(ring5Visitor, 730);
122
123 HeadAtomVisitor* headVisitor = new HeadAtomVisitor(info);
124 compositeVisitor->addVisitor(headVisitor, 720);
125
126 //create default atom visitor
127 DefaultAtomVisitor* defaultAtomVisitor = new DefaultAtomVisitor(info);
128 compositeVisitor->addVisitor(defaultAtomVisitor, 700);
129
130 //create waterType visitor
131 if(args_info.watertype_flag){
132 WaterTypeVisitor* waterTypeVisitor = new WaterTypeVisitor;
133 compositeVisitor->addVisitor(waterTypeVisitor, 600);
134 }
135
136 if (args_info.basetype_flag) {
137 AtomNameVisitor* atomNameVisitor = new AtomNameVisitor(info);
138 compositeVisitor->addVisitor(atomNameVisitor, 550);
139
140 }
141
142 //create ZconsVisitor
143 if(args_info.zconstraint_flag){
144
145 ZConsVisitor* zconsVisitor = new ZConsVisitor(info);
146
147 if(zconsVisitor->haveZconsMol()) {
148 compositeVisitor->addVisitor(zconsVisitor, 500);
149 } else {
150 delete zconsVisitor;
151 }
152 }
153
154 //create wrapping visitor
155
156 //if(args_info.periodicBox_flag){
157 // WrappingVisitor* wrappingVisitor = new WrappingVisitor(info);
158 // compositeVisitor->addVisitor(wrappingVisitor, 400);
159 //}
160
161 //create replicate visitor
162 if(args_info.repeatX_given > 0 || args_info.repeatY_given > 0 ||args_info.repeatY_given > 0){
163 Vector3i replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg);
164 ReplicateVisitor* replicateVisitor = new ReplicateVisitor(info, replicateOpt);
165 compositeVisitor->addVisitor(replicateVisitor, 300);
166 }
167
168
169 //create rotation visitor
170 if (args_info.refsele_given&& args_info.originsele_given) {
171 compositeVisitor->addVisitor(new LipidTransVisitor(info, args_info.originsele_arg, args_info.refsele_arg), 250);
172 } else if (args_info.refsele_given || args_info.originsele_given) {
173 std::cerr << "Both of --refsele and --originsele should appear by pair" << std::endl;
174 exit(1);
175 }
176
177 //create xyzVisitor
178 XYZVisitor* xyzVisitor;
179
180 if (args_info.selection_given) {
181 xyzVisitor = new XYZVisitor(info, args_info.selection_arg);
182 } else {
183 xyzVisitor = new XYZVisitor(info);
184 }
185
186 if(args_info.printPosOnly_flag){
187 bool posOnly = true;
188 xyzVisitor->setPosOnly(posOnly);
189 }
190
191 compositeVisitor->addVisitor(xyzVisitor, 200);
192
193 std::cout << compositeVisitor->toString();
194
195 //create prepareVisitor
196 PrepareVisitor* prepareVisitor = new PrepareVisitor();
197
198 //open dump file
199 DumpReader* dumpReader = new DumpReader(info, dumpFileName);
200 int nframes = dumpReader->getNFrames();
201
202
203 std::ofstream xyzStream;
204 xyzStream .open(xyzFileName.c_str());
205
206
207 SimInfo::MoleculeIterator miter;
208 Molecule::IntegrableObjectIterator iiter;
209 Molecule::RigidBodyIterator rbIter;
210 Molecule* mol;
211 StuntDouble* integrableObject;
212 RigidBody* rb;
213 Vector3d molCom;
214 Vector3d newMolCom;
215 Vector3d displacement;
216 Mat3x3d hmat;
217 Snapshot* currentSnapshot;
218
219 for (int i = 0; i < nframes; i += args_info.frame_arg){
220 dumpReader->readFrame(i);
221
222 //wrapping the molecule
223 if(args_info.periodicBox_flag) {
224 currentSnapshot = info->getSnapshotManager()->getCurrentSnapshot();
225 for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
226 molCom = mol->getCom();
227 newMolCom = molCom;
228 currentSnapshot->wrapVector(newMolCom);
229 displacement = newMolCom - molCom;
230 for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL;
231 integrableObject = mol->nextIntegrableObject(iiter)) {
232 integrableObject->setPos(integrableObject->getPos() + displacement);
233 }
234 }
235 }
236 //update atoms of rigidbody
237 for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
238
239 //change the positions of atoms which belong to the rigidbodies
240 for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
241 rb->updateAtoms();
242 }
243 }
244
245 //prepare visit
246 for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
247 for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL;
248 integrableObject = mol->nextIntegrableObject(iiter)) {
249 integrableObject->accept(prepareVisitor);
250 }
251 }
252
253 //update visitor
254 compositeVisitor->update();
255
256
257 //visit stuntdouble
258 for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
259 for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL;
260 integrableObject = mol->nextIntegrableObject(iiter)) {
261 integrableObject->accept(compositeVisitor);
262 }
263 }
264
265 xyzVisitor->writeFrame(xyzStream);
266 xyzVisitor->clear();
267
268 }//end for (int i = 0; i < nframes; i += args_info.frame_arg)
269
270 xyzStream.close();
271
272 delete prepareVisitor;
273 delete compositeVisitor;
274 delete info;
275
276 }

Properties

Name Value
svn:executable *