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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines