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

Comparing trunk/src/applications/dump2Xyz/Dump2XYZ.cpp (file contents):
Revision 12 by tim, Tue Sep 28 23:24:25 2004 UTC vs.
Revision 1303 by cli2, Mon Oct 13 21:35:22 2008 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 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{
55 <    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 <  mdFileName = dumpFileName;
59 <  mdFileName = mdFileName.substr(0, mdFileName.rfind(".")) + ".md";
60 <
85 >  
86    if (args_info.output_given){
87      xyzFileName = args_info.output_arg;
88 <  }
64 <  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 );
72 <
73 <  strcpy(inFileName, mdFileName.c_str() );
74 <  startMe.parseFile( inFileName );
75 <
76 <  startMe.createSim();
77 <
94 >  SimCreator creator;
95 >  SimInfo* info = creator.createSim(dumpFileName, false);
96    
79  //creat visitor list
80  compositeVisitor = new CompositeVisitor();
97  
98 <  //creat ignore visitor
99 <  if(args_info.ignore_given ||args_info.water_flag){
98 >  //create visitor list
99 >  CompositeVisitor* compositeVisitor = new CompositeVisitor();
100      
101 <    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
101 >  //create RigidBody Visitor
102    if(args_info.rigidbody_flag){
103 <    rbCOMVisitor = new RBCOMVisitor(info);
103 >    RBCOMVisitor* rbCOMVisitor = new RBCOMVisitor(info);
104      compositeVisitor->addVisitor(rbCOMVisitor, 900);
105    }
106 +  
107 +  //create SSD atom visitor
108 +  SSDAtomVisitor* ssdVisitor = new SSDAtomVisitor(info);
109 +  compositeVisitor->addVisitor(ssdVisitor, 800);
110 +  
111 +  LinearAtomVisitor* linearVisitor = new LinearAtomVisitor(info);
112 +  compositeVisitor->addVisitor(linearVisitor, 750);
113 +  if (args_info.gb_given) {
114 +    linearVisitor->addGayBerneAtomType(args_info.gb_arg);
115 +  }
116 +  
117 +  GBLipidAtomVisitor* gbLipidVisitor = new GBLipidAtomVisitor(info);
118 +  compositeVisitor->addVisitor(gbLipidVisitor, 740);
119  
120 <  //compositeVisitor->addVisitor(lipidVisitor, 900);
120 >  Ring5gbAtomVisitor* ring5Visitor = new Ring5gbAtomVisitor(info);
121 >  compositeVisitor->addVisitor(ring5Visitor, 730);
122  
123 <  //creat SSD atom visitor
124 <  ssdVisitor = new SSDAtomVisitor(info);
116 <  compositeVisitor->addVisitor(ssdVisitor, 800);
123 >  HeadAtomVisitor* headVisitor = new HeadAtomVisitor(info);
124 >  compositeVisitor->addVisitor(headVisitor, 720);
125  
126 <  //creat default atom visitor
127 <  defaultAtomVisitor = new DefaultAtomVisitor(info);
126 >  //create default atom visitor
127 >  DefaultAtomVisitor* defaultAtomVisitor = new DefaultAtomVisitor(info);
128    compositeVisitor->addVisitor(defaultAtomVisitor, 700);
129 <
130 <  //creat waterType visitor
131 <  if(args_info.watertype_flag){
132 <    waterTypeVisitor = new WaterTypeVisitor;
133 <    compositeVisitor->addVisitor(waterTypeVisitor, 600);
129 >  
130 >  // if we gave the -w option, we want to skip the waters:
131 >  std::cerr << "-w flag was set to:" << args_info.water_given << "\n";
132 >  if (!args_info.water_given) {
133 >    //create waterType visitor
134 >    if(args_info.watertype_flag){
135 >      WaterTypeVisitor* waterTypeVisitor = new WaterTypeVisitor;
136 >      compositeVisitor->addVisitor(waterTypeVisitor, 600);
137 >    }
138    }
139  
140 +  if (args_info.basetype_flag) {
141 +      AtomNameVisitor* atomNameVisitor = new AtomNameVisitor(info);
142 +      compositeVisitor->addVisitor(atomNameVisitor, 550);
143 +
144 +  }
145 +  
146    //create ZconsVisitor
147    if(args_info.zconstraint_flag){
130    
131    zconsVisitor = new ZConsVisitor(info);
148  
149 <    if(zconsVisitor->haveZconsMol())
149 >    ZConsVisitor* zconsVisitor = new ZConsVisitor(info);
150 >    
151 >    if(zconsVisitor->haveZconsMol()) {
152        compositeVisitor->addVisitor(zconsVisitor, 500);
153 <    else
153 >    } else {
154        delete zconsVisitor;
155 +    }
156    }
138
139  //creat wrapping visitor
140
141  if(args_info.periodicBox_flag){
142    wrappingVisitor = new WrappingVisitor(info);
143    compositeVisitor->addVisitor(wrappingVisitor, 400);
144  }
157    
158 <  //creat replicate visitor
158 >  //create wrapping visitor
159 >  
160 >  //if(args_info.periodicBox_flag){
161 >  //  WrappingVisitor* wrappingVisitor = new WrappingVisitor(info);
162 >  //  compositeVisitor->addVisitor(wrappingVisitor, 400);
163 >  //}
164 >
165 >  //create replicate visitor
166    if(args_info.repeatX_given > 0 || args_info.repeatY_given > 0 ||args_info.repeatY_given > 0){
167 <    IntVec3 replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg);
168 <    replicateVisitor = new ReplicateVisitor(info, replicateOpt);
167 >    Vector3i replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg);
168 >    ReplicateVisitor* replicateVisitor = new ReplicateVisitor(info, replicateOpt);
169      compositeVisitor->addVisitor(replicateVisitor, 300);
170    }
171  
153  //creat xyzVisitor
154  xyzVisitor = new XYZVisitor(info);
155  compositeVisitor->addVisitor(xyzVisitor, 200);
172  
173 <  cout << compositeVisitor->toString();
173 >  //create rotation visitor
174 >  if (args_info.refsele_given&& args_info.originsele_given) {
175 >    compositeVisitor->addVisitor(new LipidTransVisitor(info, args_info.originsele_arg, args_info.refsele_arg), 250);
176 >  } else if (args_info.refsele_given || args_info.originsele_given) {
177 >    std::cerr << "Both of --refsele and --originsele should appear by pair" << std::endl;
178 >    exit(1);
179 >  }
180 >    
181 >  //create xyzVisitor
182 >  XYZVisitor* xyzVisitor;
183  
184 <  //creat prepareVisitor
185 <  prepareVisitor = new PrepareVisitor();
184 >  if (args_info.selection_given) {
185 >    xyzVisitor = new XYZVisitor(info, args_info.selection_arg);
186 >  } else {
187 >    xyzVisitor = new XYZVisitor(info);
188 >  }
189  
190 <  //open dump file
191 <  dumpReader = new DumpReader(dumpFileName.c_str());
192 <  nframes = dumpReader->getNframes();
190 >  if(args_info.printPosOnly_flag){
191 >    bool posOnly = true;
192 >    xyzVisitor->setPosOnly(posOnly);
193 >  }
194  
195 <  xyzStream .open(xyzFileName.c_str());
195 >  compositeVisitor->addVisitor(xyzVisitor, 200);
196    
197 +  std::cout << compositeVisitor->toString();
198 +  
199 +  //create prepareVisitor
200 +  PrepareVisitor* prepareVisitor = new PrepareVisitor();
201 +  
202 +  //open dump file
203 +  DumpReader* dumpReader = new DumpReader(info, dumpFileName);
204 +  int nframes = dumpReader->getNFrames();
205 +  
206 +  
207 +  std::ofstream xyzStream(xyzFileName.c_str());
208 +  
209 +  SimInfo::MoleculeIterator miter;
210 +  Molecule::IntegrableObjectIterator  iiter;
211 +  Molecule::RigidBodyIterator rbIter;
212 +  Molecule* mol;
213 +  StuntDouble* integrableObject;
214 +  RigidBody* rb;
215 +  Vector3d molCom;
216 +  Vector3d newMolCom;
217 +  Vector3d displacement;
218 +  Mat3x3d hmat;
219 +  Snapshot* currentSnapshot;
220 +      
221    for (int i = 0; i < nframes; i += args_info.frame_arg){
222 <    dumpReader->readFrame(info, i);
222 >    dumpReader->readFrame(i);
223  
224 <    mol = info->molecules;
225 <
224 >    //wrapping the molecule
225 >    if(args_info.periodicBox_flag) {
226 >      currentSnapshot = info->getSnapshotManager()->getCurrentSnapshot();    
227 >      for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
228 >          molCom = mol->getCom();
229 >          newMolCom = molCom;
230 >          currentSnapshot->wrapVector(newMolCom);
231 >          displacement = newMolCom - molCom;
232 >        for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL;
233 >             integrableObject = mol->nextIntegrableObject(iiter)) {  
234 >          integrableObject->setPos(integrableObject->getPos() + displacement);
235 >        }
236 >      }    
237 >    }
238      //update atoms of rigidbody
239 <    for(int j = 0; j < info->n_mol; j++){
240 <      myRigidBodies = mol[j].getMyRigidBodies();
241 <
242 <      for(rbIter = myRigidBodies.begin(); rbIter != myRigidBodies.end(); ++rbIter)
243 <        (*rbIter)->updateAtoms();
244 <    }    
245 <
239 >    for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
240 >      
241 >      //change the positions of atoms which belong to the rigidbodies
242 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
243 >        rb->updateAtoms();
244 >      }
245 >    }
246      
247      //prepare visit
248 <    for(int j = 0; j < info->n_mol; j++){
249 <      integrableObjects = mol[j].getIntegrableObjects();
250 <
251 <      for(iter = integrableObjects.begin(); iter != integrableObjects.end(); ++iter)
252 <        (*iter)->accept(prepareVisitor);
253 <    }    
254 <
248 >    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(prepareVisitor);
252 >      }
253 >    }
254 >    
255      //update visitor
256      compositeVisitor->update();
192    
193    //visit stuntdouble
194    for(int j = 0; j < info->n_mol; j++){
195      integrableObjects = mol[j].getIntegrableObjects();
257  
197      for(iter = integrableObjects.begin(); iter != integrableObjects.end(); ++iter)
198        (*iter)->accept(compositeVisitor);
199    }
258  
259 +    //visit stuntdouble
260 +    for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
261 +      for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL;
262 +           integrableObject = mol->nextIntegrableObject(iiter)) {
263 +        integrableObject->accept(compositeVisitor);
264 +      }
265 +    }
266 +    
267      xyzVisitor->writeFrame(xyzStream);
268      xyzVisitor->clear();
269      
270    }//end for (int i = 0; i < nframes; i += args_info.frame_arg)
271 <
271 >
272    xyzStream.close();
273 <
208 <
273 >  delete prepareVisitor;
274    delete compositeVisitor;
275    delete info;
211
212
276   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines