ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/applications/dump2Xyz/Dump2XYZ.cpp
(Generate patch)

Comparing trunk/OOPSE-3.0/src/applications/dump2Xyz/Dump2XYZ.cpp (file contents):
Revision 1718 by chrisfen, Fri Nov 5 21:45:14 2004 UTC vs.
Revision 1930 by gezelter, Wed Jan 12 22:41:40 2005 UTC

# Line 1 | Line 1
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  
5 #include "brains/SimSetup.hpp"
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 + using namespace oopse;
58  
13 using namespace std;
14
59   int main(int argc, char* argv[]){
16  gengetopt_args_info args_info;
17  string dumpFileName;
18  string mdFileName;
19  char inFileName[2002];
20  string xyzFileName;
21  SimInfo* info;
22  SimSetup startMe;
23  DumpReader* dumpReader;
24  ofstream xyzStream;
25  int nframes;
26  Molecule* mol;  
27  vector<StuntDouble*> integrableObjects;
28  vector<StuntDouble*>::iterator iter;
29  vector<RigidBody*> myRigidBodies;
30  vector<RigidBody*>::iterator rbIter;
60    
61 <  CompositeVisitor* compositeVisitor;
62 <  SSDAtomVisitor* ssdVisitor;
34 <  LinearAtomVisitor* linearVisitor;
35 <  DefaultAtomVisitor* defaultAtomVisitor;
36 <  LipidHeadVisitor* lipidVisitor;
37 <  RBCOMVisitor* rbCOMVisitor;
38 <  ReplicateVisitor* replicateVisitor;
39 <  WrappingVisitor* wrappingVisitor;
40 <  IgnoreVisitor* ignoreVisitor;
41 <  XYZVisitor* xyzVisitor;
42 <  ZConsVisitor* zconsVisitor;
43 <  PrepareVisitor* prepareVisitor;
44 <  WaterTypeVisitor* waterTypeVisitor;
61 >  //register force fields
62 >  registerForceFields();
63    
64 +  gengetopt_args_info args_info;
65 +  std::string dumpFileName;
66 +  std::string mdFileName;
67 +  std::string xyzFileName;
68 +  
69    //parse the command line option
70 <    if (cmdline_parser (argc, argv, &args_info) != 0)
71 <      exit(1) ;
72 <
73 <
70 >  if (cmdline_parser (argc, argv, &args_info) != 0) {
71 >    exit(1) ;
72 >  }
73 >  
74    //get the dumpfile name and meta-data file name
75    if (args_info.input_given){
76      dumpFileName = args_info.input_arg;
77 <  }
78 <  else{
56 <    cerr << "Does not have input file name" << endl;
77 >  } else {
78 >    std::cerr << "Does not have input file name" << std::endl;
79      exit(1);
80    }
81 +  
82    mdFileName = dumpFileName;
83    mdFileName = mdFileName.substr(0, mdFileName.rfind(".")) + ".md";
84 <
84 >  
85    if (args_info.output_given){
86      xyzFileName = args_info.output_arg;
87 <  }
65 <  else{
87 >  } else {
88      xyzFileName = dumpFileName;
89      xyzFileName = xyzFileName.substr(0, xyzFileName.rfind(".")) + ".xyz";
90    }
91 <
91 >  
92    //parse md file and set up the system
93 <  info = new SimInfo();
94 <  startMe.setSimInfo(info );
73 <
74 <  strcpy(inFileName, mdFileName.c_str() );
75 <  startMe.parseFile( inFileName );
76 <
77 <  startMe.createSim();
78 <
93 >  SimCreator creator;
94 >  SimInfo* info = creator.createSim(mdFileName);
95    
96 +  
97 +  
98    //creat visitor list
99 <  compositeVisitor = new CompositeVisitor();
100 <
99 >  CompositeVisitor* compositeVisitor = new CompositeVisitor();
100 >  
101    //creat ignore visitor
102    if(args_info.ignore_given ||args_info.water_flag){
103      
104 <    ignoreVisitor = new IgnoreVisitor();
105 <
104 >    IgnoreVisitor* ignoreVisitor = new IgnoreVisitor();
105 >    
106      for(int i = 0; i < args_info.ignore_given; i++)
107        ignoreVisitor->addIgnoreType(args_info.ignore_arg[i]);
108 <
108 >    
109      //ignore water
110      if(args_info.water_flag){
111        ignoreVisitor->addIgnoreType("SSD");
# Line 100 | Line 118 | int main(int argc, char* argv[]){
118        ignoreVisitor->addIgnoreType("SPCE_RB_0");      
119        ignoreVisitor->addIgnoreType("DPD_RB_0");
120      }
121 <
122 <     compositeVisitor->addVisitor(ignoreVisitor, 1000);
121 >    
122 >    compositeVisitor->addVisitor(ignoreVisitor, 1000);
123    }
124 <
124 >  
125    //creat RigidBody Visitor
126    if(args_info.rigidbody_flag){
127 <    rbCOMVisitor = new RBCOMVisitor(info);
127 >    RBCOMVisitor* rbCOMVisitor = new RBCOMVisitor(info);
128      compositeVisitor->addVisitor(rbCOMVisitor, 900);
129    }
130 <
130 >  
131    //compositeVisitor->addVisitor(lipidVisitor, 900);
132 <
132 >  
133    //creat SSD atom visitor
134 <  ssdVisitor = new SSDAtomVisitor(info);
134 >  SSDAtomVisitor* ssdVisitor = new SSDAtomVisitor(info);
135    compositeVisitor->addVisitor(ssdVisitor, 800);
136 <  linearVisitor = new LinearAtomVisitor(info);
136 >  
137 >  LinearVisitor* linearVisitor = new LinearAtomVisitor(info);
138    compositeVisitor->addVisitor(linearVisitor, 750);
139 <
139 >  
140    //creat default atom visitor
141 <  defaultAtomVisitor = new DefaultAtomVisitor(info);
141 >  DefaultAtomVisitor* defaultAtomVisitor = new DefaultAtomVisitor(info);
142    compositeVisitor->addVisitor(defaultAtomVisitor, 700);
143 <
143 >  
144    //creat waterType visitor
145    if(args_info.watertype_flag){
146 <    waterTypeVisitor = new WaterTypeVisitor;
146 >    WaterTypeVisitor* waterTypeVisitor = new WaterTypeVisitor;
147      compositeVisitor->addVisitor(waterTypeVisitor, 600);
148    }
149 <
149 >  
150    //create ZconsVisitor
151    if(args_info.zconstraint_flag){
133    
134    zconsVisitor = new ZConsVisitor(info);
152  
153 <    if(zconsVisitor->haveZconsMol())
153 >    ZConsVisitor* zconsVisitor = new ZConsVisitor(info);
154 >    
155 >    if(zconsVisitor->haveZconsMol()) {
156        compositeVisitor->addVisitor(zconsVisitor, 500);
157 <    else
157 >    } else {
158        delete zconsVisitor;
159 +    }
160    }
161 <
161 >  
162    //creat wrapping visitor
163 <
163 >  
164    if(args_info.periodicBox_flag){
165 <    wrappingVisitor = new WrappingVisitor(info);
165 >    WrappingVisitor* wrappingVisitor = new WrappingVisitor(info);
166      compositeVisitor->addVisitor(wrappingVisitor, 400);
167    }
168    
169    //creat replicate visitor
170    if(args_info.repeatX_given > 0 || args_info.repeatY_given > 0 ||args_info.repeatY_given > 0){
171 <    IntVec3 replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg);
172 <    replicateVisitor = new ReplicateVisitor(info, replicateOpt);
171 >    Vector3i replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg);
172 >    ReplicateVisitor* replicateVisitor = new ReplicateVisitor(info, replicateOpt);
173      compositeVisitor->addVisitor(replicateVisitor, 300);
174    }
175 <
175 >  
176    //creat xyzVisitor
177 <  xyzVisitor = new XYZVisitor(info);
177 >  XYZVisitor* xyzVisitor = new XYZVisitor(info);
178    compositeVisitor->addVisitor(xyzVisitor, 200);
179 <
180 <  cout << compositeVisitor->toString();
181 <
179 >  
180 >  std::cout << compositeVisitor->toString();
181 >  
182    //creat prepareVisitor
183 <  prepareVisitor = new PrepareVisitor();
184 <
183 >  PrepareVisitor* prepareVisitor = new PrepareVisitor();
184 >  
185    //open dump file
186 <  dumpReader = new DumpReader(dumpFileName.c_str());
187 <  nframes = dumpReader->getNframes();
188 <
186 >  DumpReader* dumpReader = new DumpReader(info, dumpFileName);
187 >  int nframes = dumpReader->getNFrames();
188 >  
189 >  
190 >  std::ofstream xyzStream;    
191    xyzStream .open(xyzFileName.c_str());
192    
193 +  
194 +  SimInfo::MoleculeIterator miter;
195 +  Molecule::IntegrableObjectIterator  iiter;
196 +  Molecule::RigidBodyIterator rbIter;
197 +  Molecule* mol;
198 +  StuntDouble* integrableObject;
199 +  RigidBody* rb;
200 +  
201    for (int i = 0; i < nframes; i += args_info.frame_arg){
202 <    dumpReader->readFrame(info, i);
203 <
174 <    mol = info->molecules;
175 <
202 >    dumpReader->readFrame(i);
203 >    
204      //update atoms of rigidbody
205 <    for(int j = 0; j < info->n_mol; j++){
206 <      myRigidBodies = mol[j].getMyRigidBodies();
207 <
208 <      for(rbIter = myRigidBodies.begin(); rbIter != myRigidBodies.end(); ++rbIter)
209 <        (*rbIter)->updateAtoms();
210 <    }    
211 <
205 >    for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
206 >      
207 >      //change the positions of atoms which belong to the rigidbodies
208 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
209 >        rb->updateAtoms();
210 >      }
211 >    }
212      
213      //prepare visit
214 <    for(int j = 0; j < info->n_mol; j++){
215 <      integrableObjects = mol[j].getIntegrableObjects();
216 <
217 <      for(iter = integrableObjects.begin(); iter != integrableObjects.end(); ++iter)
218 <        (*iter)->accept(prepareVisitor);
219 <    }    
220 <
214 >    for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
215 >      for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL;
216 >           integrableObject = mol->nextIntegrableObject(iiter)) {
217 >        integrableObject->accept(prepareVisitor);
218 >      }
219 >    }
220 >    
221      //update visitor
222      compositeVisitor->update();
223      
224      //visit stuntdouble
225 <    for(int j = 0; j < info->n_mol; j++){
226 <      integrableObjects = mol[j].getIntegrableObjects();
227 <
228 <      for(iter = integrableObjects.begin(); iter != integrableObjects.end(); ++iter)
229 <        (*iter)->accept(compositeVisitor);
225 >    for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
226 >      for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL;
227 >           integrableObject = mol->nextIntegrableObject(iiter)) {
228 >        integrableObject->accept(compositeVisitor);
229 >      }
230      }
231 <
231 >    
232      xyzVisitor->writeFrame(xyzStream);
233      xyzVisitor->clear();
234      
235    }//end for (int i = 0; i < nframes; i += args_info.frame_arg)
236 <
236 >  
237    xyzStream.close();
238 <
239 <
238 >  
239 >  
240    delete compositeVisitor;
241    delete info;
242 <
215 <
242 >  
243   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines