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 211 by chrisfen, Fri Nov 5 21:45:14 2004 UTC vs.
Revision 1455 by gezelter, Thu Jun 24 20:44:18 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 "io/DumpReader.hpp"
51 + #include "utils/simError.h"
52   #include "visitors/AtomVisitor.hpp"
53 + #include "visitors/ReplacementVisitor.hpp"
54   #include "visitors/CompositeVisitor.hpp"
55   #include "visitors/RigidBodyVisitor.hpp"
56   #include "visitors/OtherVisitor.hpp"
57   #include "visitors/ZconsVisitor.hpp"
58 + #include "selection/SelectionEvaluator.hpp"
59 + #include "selection/SelectionManager.hpp"
60 + #include "visitors/LipidTransVisitor.hpp"
61 + #include "visitors/AtomNameVisitor.hpp"
62  
63 < using namespace std;
63 > using namespace OpenMD;
64  
65   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;
66    
67 <  CompositeVisitor* compositeVisitor;
68 <  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;
67 >  //register force fields
68 >  registerForceFields();
69    
70 +  gengetopt_args_info args_info;
71 +  std::string dumpFileName;
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{
56 <    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 <  mdFileName = dumpFileName;
60 <  mdFileName = mdFileName.substr(0, mdFileName.rfind(".")) + ".md";
61 <
86 >  
87    if (args_info.output_given){
88      xyzFileName = args_info.output_arg;
89 <  }
65 <  else{
89 >  } else {
90      xyzFileName = dumpFileName;
91      xyzFileName = xyzFileName.substr(0, xyzFileName.rfind(".")) + ".xyz";
92    }
93 <
93 >  
94    //parse md file and set up the system
95 <  info = new SimInfo();
96 <  startMe.setSimInfo(info );
73 <
74 <  strcpy(inFileName, mdFileName.c_str() );
75 <  startMe.parseFile( inFileName );
76 <
77 <  startMe.createSim();
78 <
95 >  SimCreator creator;
96 >  SimInfo* info = creator.createSim(dumpFileName, false);
97    
98 <  //creat visitor list
99 <  compositeVisitor = new CompositeVisitor();
100 <
101 <  //creat ignore visitor
84 <  if(args_info.ignore_given ||args_info.water_flag){
85 <    
86 <    ignoreVisitor = new IgnoreVisitor();
87 <
88 <    for(int i = 0; i < args_info.ignore_given; i++)
89 <      ignoreVisitor->addIgnoreType(args_info.ignore_arg[i]);
90 <
91 <    //ignore water
92 <    if(args_info.water_flag){
93 <      ignoreVisitor->addIgnoreType("SSD");
94 <      ignoreVisitor->addIgnoreType("SSD1");
95 <      ignoreVisitor->addIgnoreType("SSD_E");
96 <      ignoreVisitor->addIgnoreType("SSD_RF");
97 <      ignoreVisitor->addIgnoreType("TIP3P_RB_0");
98 <      ignoreVisitor->addIgnoreType("TIP4P_RB_0");
99 <      ignoreVisitor->addIgnoreType("TIP5P_RB_0");
100 <      ignoreVisitor->addIgnoreType("SPCE_RB_0");      
101 <      ignoreVisitor->addIgnoreType("DPD_RB_0");
102 <    }
103 <
104 <     compositeVisitor->addVisitor(ignoreVisitor, 1000);
105 <  }
106 <
107 <  //creat RigidBody Visitor
98 >  //create visitor list
99 >  CompositeVisitor* compositeVisitor = new CompositeVisitor();
100 >  
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 <  //compositeVisitor->addVisitor(lipidVisitor, 900);
108 <
115 <  //creat SSD atom visitor
116 <  ssdVisitor = new SSDAtomVisitor(info);
106 >  
107 >  //create SSD atom visitor
108 >  SSDAtomVisitor* ssdVisitor = new SSDAtomVisitor(info);
109    compositeVisitor->addVisitor(ssdVisitor, 800);
110 <  linearVisitor = new LinearAtomVisitor(info);
111 <  compositeVisitor->addVisitor(linearVisitor, 750);
112 <
121 <  //creat default atom visitor
122 <  defaultAtomVisitor = new DefaultAtomVisitor(info);
110 >  
111 >  //create default atom visitor
112 >  DefaultAtomVisitor* defaultAtomVisitor = new DefaultAtomVisitor(info);
113    compositeVisitor->addVisitor(defaultAtomVisitor, 700);
114 <
115 <  //creat waterType visitor
116 <  if(args_info.watertype_flag){
117 <    waterTypeVisitor = new WaterTypeVisitor;
118 <    compositeVisitor->addVisitor(waterTypeVisitor, 600);
114 >  
115 >  // if we gave the -w option, we want to skip the waters:
116 >  if (!args_info.water_given) {
117 >    //create waterType visitor
118 >    if(args_info.watertype_flag){
119 >      WaterTypeVisitor* waterTypeVisitor = new WaterTypeVisitor;
120 >      compositeVisitor->addVisitor(waterTypeVisitor, 600);
121 >    }
122 >  }
123 >  
124 >  if (args_info.basetype_flag) {
125 >    AtomNameVisitor* atomNameVisitor = new AtomNameVisitor(info);
126 >    compositeVisitor->addVisitor(atomNameVisitor, 550);    
127 >    std::cout << compositeVisitor->toString();
128    }
129 <
129 >  
130    //create ZconsVisitor
131    if(args_info.zconstraint_flag){
133    
134    zconsVisitor = new ZConsVisitor(info);
132  
133 <    if(zconsVisitor->haveZconsMol())
133 >    ZConsVisitor* zconsVisitor = new ZConsVisitor(info);
134 >    
135 >    if(zconsVisitor->haveZconsMol()) {
136        compositeVisitor->addVisitor(zconsVisitor, 500);
137 <    else
137 >    } else {
138        delete zconsVisitor;
139 +    }
140    }
141
142  //creat wrapping visitor
143
144  if(args_info.periodicBox_flag){
145    wrappingVisitor = new WrappingVisitor(info);
146    compositeVisitor->addVisitor(wrappingVisitor, 400);
147  }
141    
142 <  //creat replicate visitor
142 >  //create wrapping visitor
143 >  
144 >  //if(args_info.periodicBox_flag){
145 >  //  WrappingVisitor* wrappingVisitor = new WrappingVisitor(info);
146 >  //  compositeVisitor->addVisitor(wrappingVisitor, 400);
147 >  //}
148 >
149 >  //create replicate visitor
150    if(args_info.repeatX_given > 0 || args_info.repeatY_given > 0 ||args_info.repeatY_given > 0){
151 <    IntVec3 replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg);
152 <    replicateVisitor = new ReplicateVisitor(info, replicateOpt);
151 >    Vector3i replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg);
152 >    ReplicateVisitor* replicateVisitor = new ReplicateVisitor(info, replicateOpt);
153      compositeVisitor->addVisitor(replicateVisitor, 300);
154    }
155  
156  //creat xyzVisitor
157  xyzVisitor = new XYZVisitor(info);
158  compositeVisitor->addVisitor(xyzVisitor, 200);
156  
157 <  cout << compositeVisitor->toString();
157 >  //create rotation visitor
158 >  if (args_info.refsele_given&& args_info.originsele_given) {
159 >    compositeVisitor->addVisitor(new LipidTransVisitor(info, args_info.originsele_arg, args_info.refsele_arg), 250);
160 >  } else if (args_info.refsele_given || args_info.originsele_given) {
161 >    std::cerr << "Both of --refsele and --originsele should appear by pair" << std::endl;
162 >    exit(1);
163 >  }
164 >    
165 >  //create xyzVisitor
166 >  XYZVisitor* xyzVisitor;
167  
168 <  //creat prepareVisitor
169 <  prepareVisitor = new PrepareVisitor();
168 >  if (args_info.selection_given) {
169 >    xyzVisitor = new XYZVisitor(info, args_info.selection_arg);
170 >  } else {
171 >    xyzVisitor = new XYZVisitor(info);
172 >  }
173  
174 <  //open dump file
175 <  dumpReader = new DumpReader(dumpFileName.c_str());
176 <  nframes = dumpReader->getNframes();
174 >  if(args_info.printPosOnly_flag){
175 >    bool posOnly = true;
176 >    xyzVisitor->setPosOnly(posOnly);
177 >  }
178  
179 <  xyzStream .open(xyzFileName.c_str());
179 >  compositeVisitor->addVisitor(xyzVisitor, 200);
180    
181 +  //create prepareVisitor
182 +  PrepareVisitor* prepareVisitor = new PrepareVisitor();
183 +  
184 +  //open dump file
185 +  DumpReader* dumpReader = new DumpReader(info, dumpFileName);
186 +  int nframes = dumpReader->getNFrames();
187 +  
188 +  
189 +  std::ofstream xyzStream(xyzFileName.c_str());
190 +  
191 +  SimInfo::MoleculeIterator miter;
192 +  Molecule::IntegrableObjectIterator  iiter;
193 +  Molecule::RigidBodyIterator rbIter;
194 +  Molecule* mol;
195 +  StuntDouble* integrableObject;
196 +  RigidBody* rb;
197 +  Vector3d molCom;
198 +  Vector3d newMolCom;
199 +  Vector3d displacement;
200 +  Mat3x3d hmat;
201 +  Snapshot* currentSnapshot;
202 +      
203    for (int i = 0; i < nframes; i += args_info.frame_arg){
204 <    dumpReader->readFrame(info, i);
204 >    dumpReader->readFrame(i);
205  
206 <    mol = info->molecules;
207 <
206 >    //wrapping the molecule
207 >    if(args_info.periodicBox_flag) {
208 >      currentSnapshot = info->getSnapshotManager()->getCurrentSnapshot();    
209 >      for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
210 >          molCom = mol->getCom();
211 >          newMolCom = molCom;
212 >          currentSnapshot->wrapVector(newMolCom);
213 >          displacement = newMolCom - molCom;
214 >        for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL;
215 >             integrableObject = mol->nextIntegrableObject(iiter)) {  
216 >          integrableObject->setPos(integrableObject->getPos() + displacement);
217 >        }
218 >      }    
219 >    }
220      //update atoms of rigidbody
221 <    for(int j = 0; j < info->n_mol; j++){
222 <      myRigidBodies = mol[j].getMyRigidBodies();
223 <
224 <      for(rbIter = myRigidBodies.begin(); rbIter != myRigidBodies.end(); ++rbIter)
225 <        (*rbIter)->updateAtoms();
226 <    }    
227 <
221 >    for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
222 >      
223 >      //change the positions of atoms which belong to the rigidbodies
224 >      for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
225 >        rb->updateAtoms();
226 >      }
227 >    }
228      
229      //prepare visit
230 <    for(int j = 0; j < info->n_mol; j++){
231 <      integrableObjects = mol[j].getIntegrableObjects();
232 <
233 <      for(iter = integrableObjects.begin(); iter != integrableObjects.end(); ++iter)
234 <        (*iter)->accept(prepareVisitor);
235 <    }    
236 <
230 >    for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
231 >      for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL;
232 >           integrableObject = mol->nextIntegrableObject(iiter)) {
233 >        integrableObject->accept(prepareVisitor);
234 >      }
235 >    }
236 >    
237      //update visitor
238      compositeVisitor->update();
195    
196    //visit stuntdouble
197    for(int j = 0; j < info->n_mol; j++){
198      integrableObjects = mol[j].getIntegrableObjects();
239  
200      for(iter = integrableObjects.begin(); iter != integrableObjects.end(); ++iter)
201        (*iter)->accept(compositeVisitor);
202    }
240  
241 +    //visit stuntdouble
242 +    for (mol = info->beginMolecule(miter); mol != NULL; mol = info->nextMolecule(miter)) {
243 +      for (integrableObject = mol->beginIntegrableObject(iiter); integrableObject != NULL;
244 +           integrableObject = mol->nextIntegrableObject(iiter)) {
245 +        integrableObject->accept(compositeVisitor);
246 +      }
247 +    }
248 +    
249      xyzVisitor->writeFrame(xyzStream);
250      xyzVisitor->clear();
251      
252    }//end for (int i = 0; i < nframes; i += args_info.frame_arg)
253 <
253 >
254    xyzStream.close();
255 <
211 <
255 >  delete prepareVisitor;
256    delete compositeVisitor;
257    delete info;
214
215
258   }

Comparing trunk/src/applications/dump2Xyz/Dump2XYZ.cpp (property svn:keywords):
Revision 211 by chrisfen, Fri Nov 5 21:45:14 2004 UTC vs.
Revision 1455 by gezelter, Thu Jun 24 20:44:18 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines