31 |
|
string outMdFileName; |
32 |
|
string outInitFileName; |
33 |
|
SimInfo* oldInfo; |
34 |
– |
SimInfo* newInfo; |
34 |
|
SimSetup* oldSimSetup; |
36 |
– |
SimSetup* newSimSetup; |
35 |
|
BaseLattice* simpleLat; |
36 |
|
int numMol; |
37 |
|
double latticeConstant; |
51 |
|
// parse command line arguments |
52 |
|
if (cmdline_parser (argc, argv, &args_info) != 0) |
53 |
|
exit(1) ; |
54 |
+ |
|
55 |
+ |
density = args_info.density_arg; |
56 |
|
|
57 |
– |
//process density |
58 |
– |
if(!args_info.density_given && !args_info.ndensity_given){ |
59 |
– |
cerr << "SimpleBuilder Error: density or number density must be given" << endl; |
60 |
– |
cmdline_parser_print_help(); |
61 |
– |
exit(1); |
62 |
– |
} |
63 |
– |
else if(args_info.density_given){ |
64 |
– |
if( args_info.ndensity_given) |
65 |
– |
cerr << "SimpleBuilder Warning: both of density and number density are given, use density" << endl; |
66 |
– |
|
67 |
– |
density = args_info.density_arg; |
68 |
– |
} |
69 |
– |
else if(args_info.ndensity_given){ |
70 |
– |
//convert number density to density |
71 |
– |
} |
72 |
– |
|
73 |
– |
|
57 |
|
//get lattice type |
58 |
|
latticeType = UpperCase(args_info.latticetype_arg); |
59 |
|
if(!LatticeFactory::getInstance()->hasLatticeCreator(latticeType)){ |
90 |
|
exit(1); |
91 |
|
} |
92 |
|
|
110 |
– |
//determine the output file names |
93 |
|
|
112 |
– |
if (args_info.output_given){ |
113 |
– |
outPrefix = args_info.output_arg; |
114 |
– |
} |
115 |
– |
else |
116 |
– |
outPrefix = getPrefix(inputFileName.c_str()) + "_" + latticeType; |
117 |
– |
|
118 |
– |
outMdFileName = outPrefix + ".md"; |
119 |
– |
outInitFileName = outPrefix + ".in"; |
120 |
– |
|
94 |
|
//parse md file and set up the system |
95 |
|
oldInfo = new SimInfo; |
96 |
|
if(oldInfo == NULL){ |
103 |
|
cerr << "error in creating SimSetup" << endl; |
104 |
|
exit(1); |
105 |
|
} |
106 |
< |
|
106 |
> |
|
107 |
> |
oldSimSetup->suspendInit(); |
108 |
|
oldSimSetup->setSimInfo(oldInfo ); |
109 |
|
oldSimSetup->parseFile(&inputFileName[0] ); |
110 |
|
oldSimSetup->createSim(); |
111 |
+ |
|
112 |
|
if(oldInfo->nComponents >=2){ |
113 |
|
cerr << "can not build the system with more than two components" << endl; |
114 |
|
exit(1); |
115 |
|
} |
141 |
– |
|
116 |
|
|
117 |
|
//get mass of molecule. |
118 |
|
//Due to the design of OOPSE, given atom type, we have to query forcefiled to get the mass |
135 |
|
simpleLat->setLatticeConstant(lc); |
136 |
|
|
137 |
|
//calculate the total number of molecules |
138 |
< |
numMol = args_info.nx_arg * args_info.ny_arg * args_info.nz_arg * numMolPerCell; |
165 |
< |
|
166 |
< |
//creat new .md file on fly |
167 |
< |
createMdFile(inputFileName, outMdFileName, numMol); |
138 |
> |
numMol = nx * ny * nz * numMolPerCell; |
139 |
|
|
140 |
< |
//parse new .md file and set up the system |
170 |
< |
newInfo = new SimInfo; |
171 |
< |
if(newInfo == NULL){ |
172 |
< |
cerr << "error in creating SimInfo" << endl; |
173 |
< |
exit(1); |
174 |
< |
} |
175 |
< |
|
176 |
< |
newSimSetup = new SimSetup(); |
177 |
< |
if(newSimSetup == NULL){ |
178 |
< |
cerr << "error in creating SimSetup" << endl; |
179 |
< |
exit(1); |
180 |
< |
} |
181 |
< |
|
182 |
< |
newSimSetup->setSimInfo(newInfo ); |
183 |
< |
newSimSetup->parseFile(&outMdFileName[0] ); |
184 |
< |
newSimSetup->createSim(); |
140 |
> |
if (oldInfo->n_mol != numMol){ |
141 |
|
|
142 |
+ |
outPrefix = getPrefix(inputFileName.c_str()) + "_" + latticeType; |
143 |
+ |
outMdFileName = outPrefix + ".md"; |
144 |
+ |
|
145 |
+ |
//creat new .md file on fly which corrects the number of molecule |
146 |
+ |
createMdFile(inputFileName, outMdFileName, numMol); |
147 |
+ |
cerr << "SimpleBuilder Error: the number of molecule and the density are not matched" <<endl; |
148 |
+ |
cerr << "A new .md file: " << outMdFileName << " is generated, use it to rerun the simpleBuilder" << endl; |
149 |
+ |
exit(1); |
150 |
+ |
} |
151 |
+ |
|
152 |
+ |
//determine the output file names |
153 |
+ |
if (args_info.output_given) |
154 |
+ |
outInitFileName = args_info.output_arg; |
155 |
+ |
else |
156 |
+ |
outInitFileName = getPrefix(inputFileName.c_str()) + ".in"; |
157 |
+ |
|
158 |
+ |
|
159 |
|
//allocat memory for storing pos, vel and etc |
160 |
< |
newInfo->getConfiguration()->createArrays(newInfo->n_atoms); |
161 |
< |
for (int i = 0; i < newInfo->n_atoms; i++) |
162 |
< |
newInfo->atoms[i]->setCoords(); |
160 |
> |
oldInfo->getConfiguration()->createArrays(oldInfo->n_atoms); |
161 |
> |
for (int i = 0; i < oldInfo->n_atoms; i++) |
162 |
> |
oldInfo->atoms[i]->setCoords(); |
163 |
|
|
164 |
|
//creat Molocator |
165 |
< |
locator = new MoLocator(newInfo->compStamps[0], newSimSetup->getForceField()); |
165 |
> |
locator = new MoLocator(oldInfo->compStamps[0], oldSimSetup->getForceField()); |
166 |
|
|
167 |
|
//fill Hmat |
168 |
|
Hmat[0][0] = nx * latticeConstant; |
169 |
|
Hmat[0][1] = 0.0; |
170 |
|
Hmat[0][2] = 0.0; |
171 |
|
|
172 |
< |
Hmat[1][0] = ny * latticeConstant; |
173 |
< |
Hmat[1][1] = 0.0; |
172 |
> |
Hmat[1][0] = 0.0; |
173 |
> |
Hmat[1][1] = ny * latticeConstant; |
174 |
|
Hmat[1][2] = 0.0; |
175 |
|
|
176 |
< |
Hmat[2][0] = nz * latticeConstant; |
176 |
> |
Hmat[2][0] = 0.0; |
177 |
|
Hmat[2][1] = 0.0; |
178 |
< |
Hmat[2][2] = 0.0; |
178 |
> |
Hmat[2][2] = nz * latticeConstant ; |
179 |
|
|
180 |
|
//set Hmat |
181 |
< |
newInfo->setBoxM(Hmat); |
181 |
> |
oldInfo->setBoxM(Hmat); |
182 |
|
|
183 |
|
//place the molecules |
184 |
|
|
196 |
|
simpleLat->getLatticePointsPos(latticePos, i, j, k); |
197 |
|
|
198 |
|
for(int l = 0; l < numMolPerCell; l++) |
199 |
< |
locator->placeMol(latticePos[l], latticeOrt[l], &(newInfo->molecules[curMolIndex++])); |
199 |
> |
locator->placeMol(latticePos[l], latticeOrt[l], &(oldInfo->molecules[curMolIndex++])); |
200 |
|
} |
201 |
|
} |
202 |
|
} |
203 |
|
|
204 |
|
//create dumpwriter and write out the coordinates |
205 |
< |
writer = new DumpWriter( newInfo ); |
205 |
> |
oldInfo->finalName = outInitFileName; |
206 |
> |
writer = new DumpWriter( oldInfo ); |
207 |
|
if(writer == NULL){ |
208 |
|
cerr << "error in creating DumpWriter" << endl; |
209 |
|
exit(1); |
210 |
|
} |
211 |
|
writer->writeFinal(0); |
212 |
< |
|
212 |
> |
cout << "new initial configuration file: " << outInitFileName <<" is generated." << endl; |
213 |
|
//delete objects |
214 |
< |
if(!oldInfo) |
214 |
> |
|
215 |
> |
//delete oldInfo and oldSimSetup |
216 |
> |
if(oldInfo != NULL) |
217 |
|
delete oldInfo; |
218 |
|
|
219 |
< |
if(!oldSimSetup) |
220 |
< |
delete oldSimSetup; |
245 |
< |
|
246 |
< |
if(!newInfo) |
247 |
< |
delete newInfo; |
219 |
> |
if(oldSimSetup != NULL) |
220 |
> |
delete oldSimSetup; |
221 |
|
|
249 |
– |
if(!newSimSetup) |
250 |
– |
delete newSimSetup; |
251 |
– |
|
222 |
|
if (writer != NULL) |
223 |
|
delete writer; |
224 |
|
return 0; |
229 |
|
ofstream newMdFile; |
230 |
|
const int MAXLEN = 65535; |
231 |
|
char buffer[MAXLEN]; |
262 |
– |
string line; |
232 |
|
|
233 |
|
//create new .md file based on old .md file |
234 |
|
oldMdFile.open(oldMdFileName.c_str()); |
237 |
|
oldMdFile.getline(buffer, MAXLEN); |
238 |
|
while(!oldMdFile.eof()){ |
239 |
|
|
240 |
< |
if(line.find("nMol") < line.size()){ |
241 |
< |
|
240 |
> |
//correct molecule number |
241 |
> |
if(strstr(buffer, "nMol") !=NULL){ |
242 |
|
sprintf(buffer, "\t\tnMol = %d;", numMol); |
243 |
|
newMdFile << buffer << endl; |
244 |
|
} |