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 1474 by gezelter, Wed Jul 21 14:29:14 2010 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. Redistributions of source code must retain the above copyright
10 + *    notice, this list of conditions and the following disclaimer.
11 + *
12 + * 2. Redistributions in binary form must reproduce the above copyright
13 + *    notice, this list of conditions and the following disclaimer in the
14 + *    documentation and/or other materials provided with the
15 + *    distribution.
16 + *
17 + * This software is provided "AS IS," without a warranty of any
18 + * kind. All express or implied conditions, representations and
19 + * warranties, including any implied warranty of merchantability,
20 + * fitness for a particular purpose or non-infringement, are hereby
21 + * excluded.  The University of Notre Dame and its licensors shall not
22 + * be liable for any damages suffered by licensee as a result of
23 + * using, modifying or distributing the software or its
24 + * derivatives. In no event will the University of Notre Dame or its
25 + * licensors be liable for any lost revenue, profit or data, or for
26 + * direct, indirect, special, consequential, incidental or punitive
27 + * damages, however caused and regardless of the theory of liability,
28 + * arising out of the use of or inability to use software, even if the
29 + * University of Notre Dame has been advised of the possibility of
30 + * such damages.
31 + *
32 + * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 + * research, please cite the appropriate papers when you publish your
34 + * work.  Good starting points are:
35 + *                                                                      
36 + * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37 + * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 + * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 + * [4]  Vardeman & Gezelter, in progress (2009).                        
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 "brains/ForceManager.hpp"
51 + #include "io/DumpReader.hpp"
52 + #include "utils/simError.h"
53   #include "visitors/AtomVisitor.hpp"
54 + #include "visitors/ReplacementVisitor.hpp"
55   #include "visitors/CompositeVisitor.hpp"
56   #include "visitors/RigidBodyVisitor.hpp"
57   #include "visitors/OtherVisitor.hpp"
58   #include "visitors/ZconsVisitor.hpp"
59 + #include "selection/SelectionEvaluator.hpp"
60 + #include "selection/SelectionManager.hpp"
61 + #include "visitors/LipidTransVisitor.hpp"
62 + #include "visitors/AtomNameVisitor.hpp"
63  
64 < using namespace std;
64 > using namespace OpenMD;
65  
66   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;
67    
68 <  CompositeVisitor* compositeVisitor;
69 <  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;
68 >  //register force fields
69 >  registerForceFields();
70    
71 +  gengetopt_args_info args_info;
72 +  std::string dumpFileName;
73 +  std::string xyzFileName;
74 +  bool printVel;
75 +  bool printFrc;
76 +  bool printVec;
77 +  bool printChrg;
78 +  
79    //parse the command line option
80 <    if (cmdline_parser (argc, argv, &args_info) != 0)
81 <      exit(1) ;
82 <
83 <
80 >  if (cmdline_parser (argc, argv, &args_info) != 0) {
81 >    exit(1) ;
82 >  }
83 >  
84    //get the dumpfile name and meta-data file name
85    if (args_info.input_given){
86      dumpFileName = args_info.input_arg;
87 <  }
88 <  else{
55 <    cerr << "Does not have input file name" << endl;
87 >  } else {
88 >    std::cerr << "Does not have input file name" << std::endl;
89      exit(1);
90    }
91 <  mdFileName = dumpFileName;
59 <  mdFileName = mdFileName.substr(0, mdFileName.rfind(".")) + ".md";
60 <
91 >  
92    if (args_info.output_given){
93      xyzFileName = args_info.output_arg;
94 <  }
64 <  else{
94 >  } else {
95      xyzFileName = dumpFileName;
96      xyzFileName = xyzFileName.substr(0, xyzFileName.rfind(".")) + ".xyz";
97    }
98 <
98 >  
99    //parse md file and set up the system
100 <  info = new SimInfo();
101 <  startMe.setSimInfo(info );
102 <
73 <  strcpy(inFileName, mdFileName.c_str() );
74 <  startMe.parseFile( inFileName );
75 <
76 <  startMe.createSim();
77 <
100 >  SimCreator creator;
101 >  SimInfo* info = creator.createSim(dumpFileName, false);
102 >  ForceManager* forceMan = new ForceManager(info);
103    
104 <  //creat visitor list
105 <  compositeVisitor = new CompositeVisitor();
106 <
107 <  //creat ignore visitor
83 <  if(args_info.ignore_given ||args_info.water_flag){
84 <    
85 <    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
104 >  //create visitor list
105 >  CompositeVisitor* compositeVisitor = new CompositeVisitor();
106 >  
107 >  //create RigidBody Visitor
108    if(args_info.rigidbody_flag){
109 <    rbCOMVisitor = new RBCOMVisitor(info);
109 >    RBCOMVisitor* rbCOMVisitor = new RBCOMVisitor(info);
110      compositeVisitor->addVisitor(rbCOMVisitor, 900);
111    }
112 <
113 <  //compositeVisitor->addVisitor(lipidVisitor, 900);
114 <
114 <  //creat SSD atom visitor
115 <  ssdVisitor = new SSDAtomVisitor(info);
112 >  
113 >  //create SSD atom visitor
114 >  SSDAtomVisitor* ssdVisitor = new SSDAtomVisitor(info);
115    compositeVisitor->addVisitor(ssdVisitor, 800);
116  
117 <  //creat default atom visitor
118 <  defaultAtomVisitor = new DefaultAtomVisitor(info);
119 <  compositeVisitor->addVisitor(defaultAtomVisitor, 700);
117 >  //create GBtail atom visitor
118 >  GBtailVisitor* gbtVisitor = new GBtailVisitor(info);
119 >  compositeVisitor->addVisitor(gbtVisitor, 790);
120  
121 <  //creat waterType visitor
122 <  if(args_info.watertype_flag){
123 <    waterTypeVisitor = new WaterTypeVisitor;
124 <    compositeVisitor->addVisitor(waterTypeVisitor, 600);
121 >  //create GBhead atom visitor
122 >  GBheadVisitor* gbhVisitor = new GBheadVisitor(info);
123 >  compositeVisitor->addVisitor(gbhVisitor, 789);
124 >  
125 >  //create default atom visitor
126 >  DefaultAtomVisitor* defaultAtomVisitor = new DefaultAtomVisitor(info);
127 >  compositeVisitor->addVisitor(defaultAtomVisitor, 700);
128 >  
129 >  // if we gave the -w option, we want to skip the waters:
130 >  if (!args_info.water_given) {
131 >    //create waterType visitor
132 >    if(args_info.watertype_flag){
133 >      WaterTypeVisitor* waterTypeVisitor = new WaterTypeVisitor;
134 >      compositeVisitor->addVisitor(waterTypeVisitor, 600);
135 >    }
136 >  }
137 >  
138 >  if (args_info.basetype_flag) {
139 >    AtomNameVisitor* atomNameVisitor = new AtomNameVisitor(info);
140 >    compositeVisitor->addVisitor(atomNameVisitor, 550);    
141 >    std::cout << compositeVisitor->toString();
142    }
143 <
143 >  
144    //create ZconsVisitor
145    if(args_info.zconstraint_flag){
130    
131    zconsVisitor = new ZConsVisitor(info);
146  
147 <    if(zconsVisitor->haveZconsMol())
147 >    ZConsVisitor* zconsVisitor = new ZConsVisitor(info);
148 >    
149 >    if(zconsVisitor->haveZconsMol()) {
150        compositeVisitor->addVisitor(zconsVisitor, 500);
151 <    else
151 >    } else {
152        delete zconsVisitor;
153 +    }
154    }
138
139  //creat wrapping visitor
140
141  if(args_info.periodicBox_flag){
142    wrappingVisitor = new WrappingVisitor(info);
143    compositeVisitor->addVisitor(wrappingVisitor, 400);
144  }
155    
156 <  //creat replicate visitor
157 <  if(args_info.repeatX_given > 0 || args_info.repeatY_given > 0 ||args_info.repeatY_given > 0){
158 <    IntVec3 replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg);
159 <    replicateVisitor = new ReplicateVisitor(info, replicateOpt);
156 >  //create wrapping visitor
157 >  
158 >  //if(args_info.periodicBox_flag){
159 >  //  WrappingVisitor* wrappingVisitor = new WrappingVisitor(info);
160 >  //  compositeVisitor->addVisitor(wrappingVisitor, 400);
161 >  //}
162 >
163 >  //create replicate visitor
164 >  if(args_info.repeatX_given > 0 ||
165 >     args_info.repeatY_given > 0 ||
166 >     args_info.repeatY_given > 0) {
167 >    Vector3i replicateOpt(args_info.repeatX_arg,
168 >                          args_info.repeatY_arg,
169 >                          args_info.repeatZ_arg);
170 >    ReplicateVisitor* replicateVisitor = new ReplicateVisitor(info,
171 >                                                              replicateOpt);
172      compositeVisitor->addVisitor(replicateVisitor, 300);
173    }
174  
153  //creat xyzVisitor
154  xyzVisitor = new XYZVisitor(info);
155  compositeVisitor->addVisitor(xyzVisitor, 200);
175  
176 <  cout << compositeVisitor->toString();
176 >  //create rotation visitor
177 >  if (args_info.refsele_given&& args_info.originsele_given) {
178 >    compositeVisitor->addVisitor(new LipidTransVisitor(info,
179 >                                                       args_info.originsele_arg,
180 >                                                       args_info.refsele_arg),
181 >                                 250);
182 >  } else if (args_info.refsele_given || args_info.originsele_given) {
183 >    std::cerr << "Both of --refsele and --originsele should appear by pair"
184 >              << std::endl;
185 >    exit(1);
186 >  }
187 >  
188 >  //create xyzVisitor
189 >  XYZVisitor* xyzVisitor;
190  
191 <  //creat prepareVisitor
192 <  prepareVisitor = new PrepareVisitor();
191 >  if (args_info.selection_given) {
192 >    xyzVisitor = new XYZVisitor(info, args_info.selection_arg);
193 >  } else {
194 >    xyzVisitor = new XYZVisitor(info);
195 >  }
196  
197 +  if(args_info.velocities_flag){
198 +    printVel = true;
199 +    xyzVisitor->doVelocities(printVel);
200 +  }
201 +  if(args_info.forces_flag){
202 +    printFrc = true;
203 +    xyzVisitor->doForces(printFrc);
204 +  }
205 +  if(args_info.vectors_flag){
206 +    printVec = true;
207 +    xyzVisitor->doVectors(printVec);
208 +  }
209 +  if(args_info.charges_flag){
210 +    printChrg = true;
211 +    xyzVisitor->doCharges(printChrg);
212 +  }
213 +  
214 +  compositeVisitor->addVisitor(xyzVisitor, 200);
215 +  
216 +  //create prepareVisitor
217 +  PrepareVisitor* prepareVisitor = new PrepareVisitor();
218 +  
219    //open dump file
220 <  dumpReader = new DumpReader(dumpFileName.c_str());
221 <  nframes = dumpReader->getNframes();
165 <
166 <  xyzStream .open(xyzFileName.c_str());
220 >  DumpReader* dumpReader = new DumpReader(info, dumpFileName);
221 >  int nframes = dumpReader->getNFrames();
222    
223 +  std::ofstream xyzStream(xyzFileName.c_str());
224 +  
225 +  SimInfo::MoleculeIterator miter;
226 +  Molecule::IntegrableObjectIterator  iiter;
227 +  Molecule::RigidBodyIterator rbIter;
228 +  Molecule* mol;
229 +  StuntDouble* integrableObject;
230 +  RigidBody* rb;
231 +  Vector3d molCom;
232 +  Vector3d newMolCom;
233 +  Vector3d displacement;
234 +  Mat3x3d hmat;
235 +  Snapshot* currentSnapshot;
236 +      
237    for (int i = 0; i < nframes; i += args_info.frame_arg){
238 <    dumpReader->readFrame(info, i);
239 <
240 <    mol = info->molecules;
241 <
238 >    dumpReader->readFrame(i);
239 >    
240 >    if (printFrc) forceMan->calcForces();
241 >    
242 >    //wrapping the molecule
243 >    if(args_info.periodicBox_flag) {
244 >      currentSnapshot = info->getSnapshotManager()->getCurrentSnapshot();    
245 >      for (mol = info->beginMolecule(miter); mol != NULL;
246 >           mol = info->nextMolecule(miter)) {
247 >          molCom = mol->getCom();
248 >          newMolCom = molCom;
249 >          currentSnapshot->wrapVector(newMolCom);
250 >          displacement = newMolCom - molCom;
251 >        for (integrableObject = mol->beginIntegrableObject(iiter);
252 >             integrableObject != NULL;
253 >             integrableObject = mol->nextIntegrableObject(iiter)) {  
254 >          integrableObject->setPos(integrableObject->getPos() + displacement);
255 >        }
256 >      }    
257 >    }
258      //update atoms of rigidbody
259 <    for(int j = 0; j < info->n_mol; j++){
260 <      myRigidBodies = mol[j].getMyRigidBodies();
261 <
262 <      for(rbIter = myRigidBodies.begin(); rbIter != myRigidBodies.end(); ++rbIter)
263 <        (*rbIter)->updateAtoms();
264 <    }    
265 <
259 >    for (mol = info->beginMolecule(miter); mol != NULL;
260 >         mol = info->nextMolecule(miter)) {
261 >      
262 >      //change the positions of atoms which belong to the rigidbodies
263 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL;
264 >           rb = mol->nextRigidBody(rbIter)) {
265 >        rb->updateAtoms();
266 >        if (printVel) rb->updateAtomVel();
267 >      }
268 >    }
269      
270      //prepare visit
271 <    for(int j = 0; j < info->n_mol; j++){
272 <      integrableObjects = mol[j].getIntegrableObjects();
273 <
274 <      for(iter = integrableObjects.begin(); iter != integrableObjects.end(); ++iter)
275 <        (*iter)->accept(prepareVisitor);
276 <    }    
277 <
271 >    for (mol = info->beginMolecule(miter); mol != NULL;
272 >         mol = info->nextMolecule(miter)) {
273 >      for (integrableObject = mol->beginIntegrableObject(iiter);
274 >           integrableObject != NULL;
275 >           integrableObject = mol->nextIntegrableObject(iiter)) {
276 >        integrableObject->accept(prepareVisitor);
277 >      }
278 >    }
279 >    
280      //update visitor
281      compositeVisitor->update();
192    
193    //visit stuntdouble
194    for(int j = 0; j < info->n_mol; j++){
195      integrableObjects = mol[j].getIntegrableObjects();
282  
197      for(iter = integrableObjects.begin(); iter != integrableObjects.end(); ++iter)
198        (*iter)->accept(compositeVisitor);
199    }
283  
284 +    //visit stuntdouble
285 +    for (mol = info->beginMolecule(miter); mol != NULL;
286 +         mol = info->nextMolecule(miter)) {
287 +      for (integrableObject = mol->beginIntegrableObject(iiter);
288 +           integrableObject != NULL;
289 +           integrableObject = mol->nextIntegrableObject(iiter)) {
290 +        integrableObject->accept(compositeVisitor);
291 +      }
292 +    }
293 +    
294      xyzVisitor->writeFrame(xyzStream);
295      xyzVisitor->clear();
296      
297    }//end for (int i = 0; i < nframes; i += args_info.frame_arg)
298 <
298 >
299    xyzStream.close();
300 <
208 <
300 >  delete prepareVisitor;
301    delete compositeVisitor;
302    delete info;
211
212
303   }

Comparing trunk/src/applications/dump2Xyz/Dump2XYZ.cpp (property svn:keywords):
Revision 12 by tim, Tue Sep 28 23:24:25 2004 UTC vs.
Revision 1474 by gezelter, Wed Jul 21 14:29:14 2010 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines