ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/dump2Xyz/Dump2XYZ.cpp
Revision: 291
Committed: Fri Feb 4 22:43:54 2005 UTC (20 years, 3 months ago) by tim
Original Path: trunk/src/applications/dump2Xyz/Dump2XYZ.cpp
File size: 8893 byte(s)
Log Message:
dump2Xyz now take advantage of selection library

File Contents

# User Rev Content
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 "visitors/SelectionVisitor.hpp"
58     #include "selection/SelectionEvaluator.hpp"
59 gezelter 246 using namespace oopse;
60 tim 12
61     int main(int argc, char* argv[]){
62 gezelter 246
63     //register force fields
64     registerForceFields();
65    
66 tim 12 gengetopt_args_info args_info;
67 gezelter 246 std::string dumpFileName;
68     std::string mdFileName;
69     std::string xyzFileName;
70 tim 12
71 gezelter 246 //parse the command line option
72     if (cmdline_parser (argc, argv, &args_info) != 0) {
73     exit(1) ;
74     }
75 tim 12
76     //get the dumpfile name and meta-data file name
77     if (args_info.input_given){
78     dumpFileName = args_info.input_arg;
79 gezelter 246 } else {
80     std::cerr << "Does not have input file name" << std::endl;
81 tim 12 exit(1);
82     }
83 gezelter 246
84 tim 12 mdFileName = dumpFileName;
85     mdFileName = mdFileName.substr(0, mdFileName.rfind(".")) + ".md";
86 tim 273
87 tim 12 if (args_info.output_given){
88     xyzFileName = args_info.output_arg;
89 gezelter 246 } else {
90 tim 12 xyzFileName = dumpFileName;
91     xyzFileName = xyzFileName.substr(0, xyzFileName.rfind(".")) + ".xyz";
92     }
93 gezelter 246
94 tim 12 //parse md file and set up the system
95 gezelter 246 SimCreator creator;
96 tim 273 SimInfo* info = creator.createSim(mdFileName, false);
97 tim 12
98 gezelter 246
99    
100 tim 12 //creat visitor list
101 gezelter 246 CompositeVisitor* compositeVisitor = new CompositeVisitor();
102    
103 tim 12 //creat ignore visitor
104     if(args_info.ignore_given ||args_info.water_flag){
105    
106 tim 291 IgnoreVisitor* ignoreVisitor = new IgnoreVisitor(info);
107 gezelter 246
108 tim 12 for(int i = 0; i < args_info.ignore_given; i++)
109     ignoreVisitor->addIgnoreType(args_info.ignore_arg[i]);
110 gezelter 246
111 tim 12 //ignore water
112     if(args_info.water_flag){
113     ignoreVisitor->addIgnoreType("SSD");
114     ignoreVisitor->addIgnoreType("SSD1");
115     ignoreVisitor->addIgnoreType("SSD_E");
116     ignoreVisitor->addIgnoreType("SSD_RF");
117     ignoreVisitor->addIgnoreType("TIP3P_RB_0");
118     ignoreVisitor->addIgnoreType("TIP4P_RB_0");
119     ignoreVisitor->addIgnoreType("TIP5P_RB_0");
120     ignoreVisitor->addIgnoreType("SPCE_RB_0");
121     ignoreVisitor->addIgnoreType("DPD_RB_0");
122     }
123 gezelter 246
124     compositeVisitor->addVisitor(ignoreVisitor, 1000);
125 tim 12 }
126 gezelter 246
127 tim 12 //creat RigidBody Visitor
128     if(args_info.rigidbody_flag){
129 gezelter 246 RBCOMVisitor* rbCOMVisitor = new RBCOMVisitor(info);
130 tim 12 compositeVisitor->addVisitor(rbCOMVisitor, 900);
131     }
132 gezelter 246
133 tim 291 //create selection visitor
134     //if (args_info.selection_given){
135     // SelectionVisitor* selectionVisitor = new SelectionVisitor(info, args_info.selection_arg);
136     // compositeVisitor->addVisitor(selectionVisitor, 850);
137     //}
138    
139     SelectionEvaluator* evaluator = NULL;
140     if (args_info.selection_given) {
141     evaluator = new SelectionEvaluator(info);
142     assert(evaluator);
143     evaluator->loadScriptString( args_info.selection_arg);
144    
145     }
146 gezelter 246
147 tim 12 //creat SSD atom visitor
148 gezelter 246 SSDAtomVisitor* ssdVisitor = new SSDAtomVisitor(info);
149 tim 12 compositeVisitor->addVisitor(ssdVisitor, 800);
150 gezelter 246
151 tim 250 LinearAtomVisitor* linearVisitor = new LinearAtomVisitor(info);
152 chrisfen 211 compositeVisitor->addVisitor(linearVisitor, 750);
153 gezelter 246
154 tim 12 //creat default atom visitor
155 gezelter 246 DefaultAtomVisitor* defaultAtomVisitor = new DefaultAtomVisitor(info);
156 tim 12 compositeVisitor->addVisitor(defaultAtomVisitor, 700);
157 gezelter 246
158 tim 12 //creat waterType visitor
159     if(args_info.watertype_flag){
160 gezelter 246 WaterTypeVisitor* waterTypeVisitor = new WaterTypeVisitor;
161 tim 12 compositeVisitor->addVisitor(waterTypeVisitor, 600);
162     }
163 gezelter 246
164 tim 12 //create ZconsVisitor
165     if(args_info.zconstraint_flag){
166 gezelter 246
167     ZConsVisitor* zconsVisitor = new ZConsVisitor(info);
168 tim 12
169 gezelter 246 if(zconsVisitor->haveZconsMol()) {
170 tim 12 compositeVisitor->addVisitor(zconsVisitor, 500);
171 gezelter 246 } else {
172 tim 12 delete zconsVisitor;
173 gezelter 246 }
174 tim 12 }
175 gezelter 246
176 tim 12 //creat wrapping visitor
177 gezelter 246
178 tim 12 if(args_info.periodicBox_flag){
179 gezelter 246 WrappingVisitor* wrappingVisitor = new WrappingVisitor(info);
180 tim 12 compositeVisitor->addVisitor(wrappingVisitor, 400);
181     }
182    
183     //creat replicate visitor
184     if(args_info.repeatX_given > 0 || args_info.repeatY_given > 0 ||args_info.repeatY_given > 0){
185 gezelter 246 Vector3i replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg);
186     ReplicateVisitor* replicateVisitor = new ReplicateVisitor(info, replicateOpt);
187 tim 12 compositeVisitor->addVisitor(replicateVisitor, 300);
188     }
189 gezelter 246
190 tim 12 //creat xyzVisitor
191 gezelter 246 XYZVisitor* xyzVisitor = new XYZVisitor(info);
192 tim 12 compositeVisitor->addVisitor(xyzVisitor, 200);
193 gezelter 246
194     std::cout << compositeVisitor->toString();
195    
196 tim 12 //creat prepareVisitor
197 gezelter 246 PrepareVisitor* prepareVisitor = new PrepareVisitor();
198    
199 tim 12 //open dump file
200 gezelter 246 DumpReader* dumpReader = new DumpReader(info, dumpFileName);
201     int nframes = dumpReader->getNFrames();
202    
203    
204     std::ofstream xyzStream;
205 tim 12 xyzStream .open(xyzFileName.c_str());
206    
207 gezelter 246
208     SimInfo::MoleculeIterator miter;
209     Molecule::IntegrableObjectIterator iiter;
210     Molecule::RigidBodyIterator rbIter;
211     Molecule* mol;
212     StuntDouble* integrableObject;
213     RigidBody* rb;
214 tim 291
215     if (evaluator && !evaluator->isDynamic()) {
216     info->getSelectionManager()->setSelectionSet(evaluator->evaluate());
217     }
218 gezelter 246
219 tim 12 for (int i = 0; i < nframes; i += args_info.frame_arg){
220 gezelter 246 dumpReader->readFrame(i);
221    
222 tim 12 //update atoms of rigidbody
223 gezelter 246 for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
224    
225     //change the positions of atoms which belong to the rigidbodies
226     for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
227     rb->updateAtoms();
228     }
229     }
230 tim 12
231     //prepare visit
232 gezelter 246 for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
233     for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL;
234     integrableObject = mol->nextIntegrableObject(iiter)) {
235     integrableObject->accept(prepareVisitor);
236     }
237     }
238    
239 tim 12 //update visitor
240     compositeVisitor->update();
241 tim 291
242     //if dynamic, we need to re-evaluate the selection
243     if (evaluator && evaluator->isDynamic()) {
244     info->getSelectionManager()->setSelectionSet(evaluator->evaluate());
245     }
246 tim 12
247     //visit stuntdouble
248 gezelter 246 for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
249     for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL;
250     integrableObject = mol->nextIntegrableObject(iiter)) {
251     integrableObject->accept(compositeVisitor);
252     }
253 tim 12 }
254 gezelter 246
255 tim 12 xyzVisitor->writeFrame(xyzStream);
256     xyzVisitor->clear();
257    
258     }//end for (int i = 0; i < nframes; i += args_info.frame_arg)
259 gezelter 246
260 tim 12 xyzStream.close();
261 gezelter 246
262    
263 tim 12 delete compositeVisitor;
264     delete info;
265 gezelter 246
266 tim 12 }

Properties

Name Value
svn:executable *