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

Comparing trunk/OOPSE-4/src/applications/dump2Xyz/Dump2XYZ.cpp (file contents):
Revision 1501 by tim, Tue Sep 28 23:24:25 2004 UTC vs.
Revision 2240 by tim, Thu May 26 22:45:00 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 + #include "visitors/AtomNameVisitor.hpp"
61  
62 < using namespace std;
62 > using namespace oopse;
63  
64   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;
65    
66 <  CompositeVisitor* compositeVisitor;
67 <  SSDAtomVisitor* ssdVisitor;
34 <  DefaultAtomVisitor* defaultAtomVisitor;
35 <  LipidHeadVisitor* lipidVisitor;
36 <  RBCOMVisitor* rbCOMVisitor;
37 <  ReplicateVisitor* replicateVisitor;
38 <  WrappingVisitor* wrappingVisitor;
39 <  IgnoreVisitor* ignoreVisitor;
40 <  XYZVisitor* xyzVisitor;
41 <  ZConsVisitor* zconsVisitor;
42 <  PrepareVisitor* prepareVisitor;
43 <  WaterTypeVisitor* waterTypeVisitor;
66 >  //register force fields
67 >  registerForceFields();
68    
69 +  gengetopt_args_info args_info;
70 +  std::string dumpFileName;
71 +  std::string mdFileName;
72 +  std::string xyzFileName;
73 +  
74    //parse the command line option
75 <    if (cmdline_parser (argc, argv, &args_info) != 0)
76 <      exit(1) ;
77 <
78 <
75 >  if (cmdline_parser (argc, argv, &args_info) != 0) {
76 >    exit(1) ;
77 >  }
78 >  
79    //get the dumpfile name and meta-data file name
80    if (args_info.input_given){
81      dumpFileName = args_info.input_arg;
82 <  }
83 <  else{
55 <    cerr << "Does not have input file name" << endl;
82 >  } else {
83 >    std::cerr << "Does not have input file name" << std::endl;
84      exit(1);
85    }
86 +  
87    mdFileName = dumpFileName;
88    mdFileName = mdFileName.substr(0, mdFileName.rfind(".")) + ".md";
89  
90    if (args_info.output_given){
91      xyzFileName = args_info.output_arg;
92 <  }
64 <  else{
92 >  } else {
93      xyzFileName = dumpFileName;
94      xyzFileName = xyzFileName.substr(0, xyzFileName.rfind(".")) + ".xyz";
95    }
96 <
96 >  
97    //parse md file and set up the system
98 <  info = new SimInfo();
99 <  startMe.setSimInfo(info );
72 <
73 <  strcpy(inFileName, mdFileName.c_str() );
74 <  startMe.parseFile( inFileName );
75 <
76 <  startMe.createSim();
77 <
98 >  SimCreator creator;
99 >  SimInfo* info = creator.createSim(mdFileName, false);
100    
101 <  //creat visitor list
102 <  compositeVisitor = new CompositeVisitor();
103 <
104 <  //creat ignore visitor
83 <  if(args_info.ignore_given ||args_info.water_flag){
101 >  
102 >  
103 >  //create visitor list
104 >  CompositeVisitor* compositeVisitor = new CompositeVisitor();
105      
106 <    ignoreVisitor = new IgnoreVisitor();
86 <
87 <    for(int i = 0; i < args_info.ignore_given; i++)
88 <      ignoreVisitor->addIgnoreType(args_info.ignore_arg[i]);
89 <
90 <    //ignore water
91 <    if(args_info.water_flag){
92 <      ignoreVisitor->addIgnoreType("SSD");
93 <      ignoreVisitor->addIgnoreType("SSD1");
94 <      ignoreVisitor->addIgnoreType("SSD_E");
95 <      ignoreVisitor->addIgnoreType("SSD_RF");
96 <      ignoreVisitor->addIgnoreType("TIP3P_RB_0");
97 <      ignoreVisitor->addIgnoreType("TIP4P_RB_0");
98 <      ignoreVisitor->addIgnoreType("TIP5P_RB_0");
99 <      ignoreVisitor->addIgnoreType("SPCE_RB_0");      
100 <      ignoreVisitor->addIgnoreType("DPD_RB_0");
101 <    }
102 <
103 <     compositeVisitor->addVisitor(ignoreVisitor, 1000);
104 <  }
105 <
106 <  //creat RigidBody Visitor
106 >  //create RigidBody Visitor
107    if(args_info.rigidbody_flag){
108 <    rbCOMVisitor = new RBCOMVisitor(info);
108 >    RBCOMVisitor* rbCOMVisitor = new RBCOMVisitor(info);
109      compositeVisitor->addVisitor(rbCOMVisitor, 900);
110    }
111 <
112 <  //compositeVisitor->addVisitor(lipidVisitor, 900);
113 <
114 <  //creat SSD atom visitor
115 <  ssdVisitor = new SSDAtomVisitor(info);
111 >  
112 >  //create SSD atom visitor
113 >  SSDAtomVisitor* ssdVisitor = new SSDAtomVisitor(info);
114    compositeVisitor->addVisitor(ssdVisitor, 800);
115 <
116 <  //creat default atom visitor
117 <  defaultAtomVisitor = new DefaultAtomVisitor(info);
115 >  
116 >  LinearAtomVisitor* linearVisitor = new LinearAtomVisitor(info);
117 >  compositeVisitor->addVisitor(linearVisitor, 750);
118 >  
119 >  //create default atom visitor
120 >  DefaultAtomVisitor* defaultAtomVisitor = new DefaultAtomVisitor(info);
121    compositeVisitor->addVisitor(defaultAtomVisitor, 700);
122 <
123 <  //creat waterType visitor
122 >  
123 >  //create waterType visitor
124    if(args_info.watertype_flag){
125 <    waterTypeVisitor = new WaterTypeVisitor;
125 >    WaterTypeVisitor* waterTypeVisitor = new WaterTypeVisitor;
126      compositeVisitor->addVisitor(waterTypeVisitor, 600);
127    }
128  
129 +  if (args_info.basetype_flag) {
130 +      AtomNameVisitor* atomNameVisitor = new AtomNameVisitor(info);
131 +      compositeVisitor->addVisitor(atomNameVisitor, 550);
132 +
133 +  }
134 +  
135    //create ZconsVisitor
136    if(args_info.zconstraint_flag){
130    
131    zconsVisitor = new ZConsVisitor(info);
137  
138 <    if(zconsVisitor->haveZconsMol())
138 >    ZConsVisitor* zconsVisitor = new ZConsVisitor(info);
139 >    
140 >    if(zconsVisitor->haveZconsMol()) {
141        compositeVisitor->addVisitor(zconsVisitor, 500);
142 <    else
142 >    } else {
143        delete zconsVisitor;
144 +    }
145    }
146 <
147 <  //creat wrapping visitor
148 <
146 >  
147 >  //create wrapping visitor
148 >  
149    if(args_info.periodicBox_flag){
150 <    wrappingVisitor = new WrappingVisitor(info);
150 >    WrappingVisitor* wrappingVisitor = new WrappingVisitor(info);
151      compositeVisitor->addVisitor(wrappingVisitor, 400);
152    }
153 <  
154 <  //creat replicate visitor
153 >
154 >  //create replicate visitor
155    if(args_info.repeatX_given > 0 || args_info.repeatY_given > 0 ||args_info.repeatY_given > 0){
156 <    IntVec3 replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg);
157 <    replicateVisitor = new ReplicateVisitor(info, replicateOpt);
156 >    Vector3i replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg);
157 >    ReplicateVisitor* replicateVisitor = new ReplicateVisitor(info, replicateOpt);
158      compositeVisitor->addVisitor(replicateVisitor, 300);
159    }
160  
153  //creat xyzVisitor
154  xyzVisitor = new XYZVisitor(info);
155  compositeVisitor->addVisitor(xyzVisitor, 200);
161  
162 <  cout << compositeVisitor->toString();
163 <
164 <  //creat prepareVisitor
165 <  prepareVisitor = new PrepareVisitor();
166 <
162 >  //create rotation visitor
163 >  if (args_info.refsele_given&& args_info.originsele_given) {
164 >    compositeVisitor->addVisitor(new LipidTransVisitor(info, args_info.originsele_arg, args_info.refsele_arg), 250);
165 >  } else if (args_info.refsele_given || args_info.originsele_given) {
166 >    std::cerr << "Both of --refsele and --originsele should appear by pair" << std::endl;
167 >    exit(1);
168 >  }
169 >    
170 >  //create xyzVisitor
171 >  XYZVisitor* xyzVisitor;
172 >  if (args_info.selection_given) {
173 >    xyzVisitor = new XYZVisitor(info, args_info.selection_arg);
174 >  } else {
175 >    xyzVisitor = new XYZVisitor(info);
176 >  }
177 >  compositeVisitor->addVisitor(xyzVisitor, 200);
178 >  
179 >  std::cout << compositeVisitor->toString();
180 >  
181 >  //create prepareVisitor
182 >  PrepareVisitor* prepareVisitor = new PrepareVisitor();
183 >  
184    //open dump file
185 <  dumpReader = new DumpReader(dumpFileName.c_str());
186 <  nframes = dumpReader->getNframes();
187 <
185 >  DumpReader* dumpReader = new DumpReader(info, dumpFileName);
186 >  int nframes = dumpReader->getNFrames();
187 >  
188 >  
189 >  std::ofstream xyzStream;    
190    xyzStream .open(xyzFileName.c_str());
191    
192 +  
193 +  SimInfo::MoleculeIterator miter;
194 +  Molecule::IntegrableObjectIterator  iiter;
195 +  Molecule::RigidBodyIterator rbIter;
196 +  Molecule* mol;
197 +  StuntDouble* integrableObject;
198 +  RigidBody* rb;
199 +      
200    for (int i = 0; i < nframes; i += args_info.frame_arg){
201 <    dumpReader->readFrame(info, i);
202 <
171 <    mol = info->molecules;
172 <
201 >    dumpReader->readFrame(i);
202 >    
203      //update atoms of rigidbody
204 <    for(int j = 0; j < info->n_mol; j++){
205 <      myRigidBodies = mol[j].getMyRigidBodies();
206 <
207 <      for(rbIter = myRigidBodies.begin(); rbIter != myRigidBodies.end(); ++rbIter)
208 <        (*rbIter)->updateAtoms();
209 <    }    
210 <
204 >    for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
205 >      
206 >      //change the positions of atoms which belong to the rigidbodies
207 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
208 >        rb->updateAtoms();
209 >      }
210 >    }
211      
212      //prepare visit
213 <    for(int j = 0; j < info->n_mol; j++){
214 <      integrableObjects = mol[j].getIntegrableObjects();
215 <
216 <      for(iter = integrableObjects.begin(); iter != integrableObjects.end(); ++iter)
217 <        (*iter)->accept(prepareVisitor);
218 <    }    
219 <
213 >    for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
214 >      for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL;
215 >           integrableObject = mol->nextIntegrableObject(iiter)) {
216 >        integrableObject->accept(prepareVisitor);
217 >      }
218 >    }
219 >    
220      //update visitor
221      compositeVisitor->update();
192    
193    //visit stuntdouble
194    for(int j = 0; j < info->n_mol; j++){
195      integrableObjects = mol[j].getIntegrableObjects();
222  
197      for(iter = integrableObjects.begin(); iter != integrableObjects.end(); ++iter)
198        (*iter)->accept(compositeVisitor);
199    }
223  
224 +    //visit stuntdouble
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 +    
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 >  delete prepareVisitor;
240    delete compositeVisitor;
241    delete info;
242 <
212 <
242 >  
243   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines