1 |
#include <iostream> |
2 |
#include <fstream> |
3 |
#include <string> |
4 |
|
5 |
#include "SimSetup.hpp" |
6 |
#include "Dump2XYZCmd.h" |
7 |
#include "AtomVisitor.hpp" |
8 |
#include "CompositeVisitor.hpp" |
9 |
#include "RigidBodyVisitor.hpp" |
10 |
#include "OtherVisitor.hpp" |
11 |
#include "ZconsVisitor.hpp" |
12 |
|
13 |
using namespace std; |
14 |
|
15 |
int main(int argc, char* argv[]){ |
16 |
gengetopt_args_info args_info; |
17 |
string dumpFileName; |
18 |
string bassFileName; |
19 |
string xyzFileName; |
20 |
SimInfo* info; |
21 |
SimSetup startMe; |
22 |
DumpReader* dumpReader; |
23 |
ofstream xyzStream; |
24 |
int nframes; |
25 |
Molecule* mol; |
26 |
vector<StuntDouble*> integrableObjects; |
27 |
vector<StuntDouble*>::iterator iter; |
28 |
|
29 |
CompositeVisitor* compositeVisitor; |
30 |
SSDAtomVisitor* ssdVisitor; |
31 |
DefaultAtomVisitor* defaultAtomVisitor; |
32 |
LipidHeadVisitor* lipidVisitor; |
33 |
ReplicateVisitor* replicateVisitor; |
34 |
WrappingVisitor* wrappingVisitor; |
35 |
IgnoreVisitor* ignoreVisitor; |
36 |
XYZVisitor* xyzVisitor; |
37 |
ZConsVisitor* zconsVisitor; |
38 |
PrepareVisitor* prepareVisitor; |
39 |
|
40 |
//parse the command line option |
41 |
if (cmdline_parser (argc, argv, &args_info) != 0) |
42 |
exit(1) ; |
43 |
|
44 |
|
45 |
//get the dumpfile name and bass file name |
46 |
if (args_info.input_given){ |
47 |
dumpFileName = args_info.input_arg; |
48 |
} |
49 |
else{ |
50 |
cerr << "Does not have input file name" << endl; |
51 |
exit(1); |
52 |
} |
53 |
bassFileName = dumpFileName; |
54 |
bassFileName = bassFileName.substr(0, bassFileName.rfind(".")) + ".bass"; |
55 |
|
56 |
if (args_info.output_given){ |
57 |
xyzFileName = args_info.output_arg; |
58 |
} |
59 |
else{ |
60 |
xyzFileName = dumpFileName; |
61 |
xyzFileName = xyzFileName.substr(0, xyzFileName.rfind(".")) + ".xyz"; |
62 |
} |
63 |
|
64 |
//parse bass file and set up the system |
65 |
info = new SimInfo(); |
66 |
startMe.setSimInfo(info ); |
67 |
|
68 |
startMe.parseFile( bassFileName.c_str()); |
69 |
|
70 |
startMe.createSim(); |
71 |
|
72 |
|
73 |
//creat visitor list |
74 |
compositeVisitor = new CompositeVisitor(); |
75 |
|
76 |
//creat ignore visitor |
77 |
if(args_info.ignore_given ||args_info.water_flag){ |
78 |
|
79 |
ignoreVisitor = new IgnoreVisitor(); |
80 |
|
81 |
for(int i = 0; i < args_info.ignore_given; i++) |
82 |
ignoreVisitor->addIgnoreType(args_info.ignore_arg[i]); |
83 |
|
84 |
//ignore water |
85 |
if(args_info.water_flag){ |
86 |
ignoreVisitor->addIgnoreType("SSD"); |
87 |
ignoreVisitor->addIgnoreType("SSD1"); |
88 |
ignoreVisitor->addIgnoreType("SSD_E"); |
89 |
ignoreVisitor->addIgnoreType("SSD_RF"); |
90 |
ignoreVisitor->addIgnoreType("TIP3P_RB_0"); |
91 |
ignoreVisitor->addIgnoreType("TIP4P_RB_0"); |
92 |
ignoreVisitor->addIgnoreType("TIP5P_RB_0"); |
93 |
ignoreVisitor->addIgnoreType("SPCE_RB_0"); |
94 |
ignoreVisitor->addIgnoreType("DPD_RB_0"); |
95 |
} |
96 |
|
97 |
compositeVisitor->addVisitor(ignoreVisitor, 1000); |
98 |
} |
99 |
|
100 |
//creat RigidBody Visitor |
101 |
lipidVisitor = new LipidHeadVisitor(info); |
102 |
|
103 |
//adding names of lipid head group |
104 |
lipidVisitor->addLipidHeadName("PC_RB_0"); |
105 |
lipidVisitor->addLipidHeadName("PE_RB_0"); |
106 |
|
107 |
compositeVisitor->addVisitor(lipidVisitor, 900); |
108 |
|
109 |
//creat SSD atom visitor |
110 |
ssdVisitor = new SSDAtomVisitor(info); |
111 |
compositeVisitor->addVisitor(ssdVisitor, 800); |
112 |
|
113 |
//creat default atom visitor |
114 |
defaultAtomVisitor = new DefaultAtomVisitor(info); |
115 |
compositeVisitor->addVisitor(ssdVisitor, 700); |
116 |
|
117 |
//create ZconsVisitor |
118 |
if(args_info.replace_given){ |
119 |
|
120 |
zconsVisitor = new ZConsVisitor(info); |
121 |
|
122 |
if(zconsVisitor->haveZconsMol()) |
123 |
compositeVisitor->addVisitor(zconsVisitor, 600); |
124 |
else |
125 |
delete zconsVisitor; |
126 |
} |
127 |
|
128 |
//creat wrapping visitor |
129 |
|
130 |
if(args_info.periodicBox_flag){ |
131 |
wrappingVisitor = new WrappingVisitor(info); |
132 |
compositeVisitor->addVisitor(wrappingVisitor, 500); |
133 |
} |
134 |
|
135 |
//creat replicate visitor |
136 |
if(args_info.repeatX_given > 0 || args_info.repeatY_given > 0 ||args_info.repeatY_given > 0){ |
137 |
IntVec3 replicateOpt(args_info.repeatX_arg, args_info.repeatY_arg, args_info.repeatZ_arg); |
138 |
replicateVisitor = new ReplicateVisitor(info, replicateOpt); |
139 |
compositeVisitor->addVisitor(replicateVisitor, 400); |
140 |
} |
141 |
|
142 |
//creat xyzVisitor |
143 |
xyzVisitor = new XYZVisitor(info); |
144 |
compositeVisitor->addVisitor(wrappingVisitor, 300); |
145 |
|
146 |
|
147 |
//creat prepareVisitor |
148 |
prepareVisitor = new PrepareVisitor(); |
149 |
|
150 |
//open dump file |
151 |
dumpReader = new DumpReader(dumpFileName.c_str()); |
152 |
nframes = dumpReader->getNframes(); |
153 |
|
154 |
xyzStream .open(xyzFileName.c_str()); |
155 |
|
156 |
for (int i = 0; i < nframes; i += args_info.frame_arg){ |
157 |
dumpReader->readFrame(info, i); |
158 |
|
159 |
mol = info->molecules; |
160 |
|
161 |
//prepare visit |
162 |
for(int j = 0; j < info->n_mol; j++){ |
163 |
integrableObjects = mol[i].getIntegrableObjects(); |
164 |
|
165 |
for(iter = integrableObjects.begin(); iter != integrableObjects.end(); ++iter) |
166 |
(*iter)->accept(prepareVisitor); |
167 |
} |
168 |
|
169 |
//update visitor |
170 |
compositeVisitor->update(); |
171 |
|
172 |
//visit stuntdouble |
173 |
for(int j = 0; j < info->n_mol; j++){ |
174 |
integrableObjects = mol[i].getIntegrableObjects(); |
175 |
|
176 |
for(iter = integrableObjects.begin(); iter != integrableObjects.end(); ++iter) |
177 |
(*iter)->accept(compositeVisitor); |
178 |
} |
179 |
|
180 |
xyzVisitor->writeFrame(xyzStream); |
181 |
xyzVisitor->clear(); |
182 |
|
183 |
}//end for (int i = 0; i < nframes; i += args_info.frame_arg) |
184 |
|
185 |
xyzStream.close(); |
186 |
|
187 |
|
188 |
delete compositeVisitor; |
189 |
delete info; |
190 |
|
191 |
|
192 |
} |