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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines