# | Line 1 | Line 1 | |
---|---|---|
1 | #include <cstdlib> | |
2 | #include <cstdio> | |
3 | #include <cstring> | |
4 | + | #include <cmath> |
5 | ||
6 | #include "simError.h" | |
7 | + | #include "parse_me.h" |
8 | + | #include "MakeStamps.hpp" |
9 | + | #include "Globals.hpp" |
10 | + | #include "SimInfo.hpp" |
11 | ||
12 | + | #include "sysBuild.hpp" |
13 | #include "bilayerSys.hpp" | |
14 | ||
15 | < | // quick case asignments |
15 | > | // this routine is defined in BASS_interface.cpp |
16 | > | extern void set_interface_stamps( MakeStamps* ms, Globals* g ); |
17 | ||
18 | + | |
19 | + | // case asignments |
20 | #define BILAYER 1 | |
21 | ||
22 | ||
23 | char* program_name; | |
24 | + | bassInfo bsInfo; |
25 | void usage(void); | |
26 | ||
27 | ||
# | Line 23 | Line 33 | int main( int argc, char* argv[]){ | |
33 | char current_flag; | |
34 | char* out_prefix; | |
35 | char* in_name; | |
36 | + | char* id; |
37 | ||
38 | < | sysBuildInfo info; |
38 | > | includeLinked* headInc; |
39 | > | includeLinked* prevInc; |
40 | > | includeLinked* currInc; |
41 | ||
42 | < | // initialize simError |
43 | < | initSimError(); |
42 | > | MakeStamps* the_stamps = NULL; |
43 | > | Globals* the_globals = NULL; |
44 | > | Component** the_components = NULL; |
45 | > | LinkedMolStamp* headStamp = NULL; |
46 | > | LinkedMolStamp* currStamp; |
47 | ||
48 | + | // initialize all functions and variables |
49 | ||
50 | < | program_name = argv[0]; /*save the program name in case we need it*/ |
50 | > | initSimError(); |
51 | > | program_name = argv[0]; |
52 | sysType = -1; | |
53 | have_prefix = 0; | |
54 | isRandom = 0; | |
55 | in_name = NULL; | |
56 | + | headInc = NULL; |
57 | + | |
58 | + | bsInfo.includes = NULL; |
59 | + | bsInfo.componentsNmol = NULL; |
60 | + | bsInfo.compStamps = NULL; |
61 | + | bsInfo.havePressure = 0; |
62 | + | bsInfo.haveTauBarostat = 0; |
63 | + | bsInfo.haveTauThermostat = 0; |
64 | + | bsInfo.haveQmass = 0; |
65 | + | |
66 | + | headStamp = new LinkedMolStamp(); |
67 | + | the_stamps = new MakeStamps(); |
68 | + | the_globals = new Globals(); |
69 | + | set_interface_stamps( the_stamps, the_globals ); |
70 | + | |
71 | + | // parse command line arguments |
72 | + | |
73 | for( i = 1; i < argc; i++){ | |
74 | ||
75 | if(argv[i][0] =='-'){ | |
# | Line 85 | Line 120 | int main( int argc, char* argv[]){ | |
120 | done = 1; | |
121 | break; | |
122 | ||
123 | + | case 'I': |
124 | + | // -I <include> => the include file. |
125 | + | |
126 | + | i++; |
127 | + | if( headInc == NULL ){ |
128 | + | headInc = new includeLinked; |
129 | + | headInc->next = NULL; |
130 | + | strcpy( headInc->name, argv[i] ); |
131 | + | } |
132 | + | else{ |
133 | + | prevInc = headInc; |
134 | + | currInc = headInc->next; |
135 | + | while( currInc != NULL ){ |
136 | + | prevInc = currInc; |
137 | + | currInc = prevInc->next; |
138 | + | } |
139 | + | currInc = new includeLinked; |
140 | + | currInc->next = NULL; |
141 | + | strcpy( currInc->name, argv[i] ); |
142 | + | prevInc->next = currInc; |
143 | + | } |
144 | + | |
145 | + | done = 1; |
146 | + | break; |
147 | + | |
148 | case 'h': | |
149 | // -h => give the usage | |
150 | ||
# | Line 149 | Line 209 | int main( int argc, char* argv[]){ | |
209 | if( !have_prefix ){ | |
210 | out_prefix = strdup( "donkey" ); | |
211 | } | |
152 | – | |
153 | – | info.in_name = in_name; |
154 | – | info.out_prefix = out_prefix; |
155 | – | info.isRandom = isRandom; |
212 | ||
213 | < | // switch the system type |
213 | > | // set command line info into the bassInfo struct |
214 | > | |
215 | > | bsInfo.outPrefix = out_prefix; |
216 | > | bsInfo.includes = headInc; |
217 | > | |
218 | > | |
219 | > | // open and parse the bass file. |
220 | > | |
221 | > | set_interface_stamps( the_stamps, the_globals ); |
222 | > | yacc_BASS( in_name ); |
223 | > | |
224 | > | // set the easy ones first |
225 | > | bsInfo.targetTemp = the_globals->getTargetTemp(); |
226 | > | bsInfo.dt = the_globals->getDt(); |
227 | > | bsInfo.runTime = the_globals->getRunTime(); |
228 | > | |
229 | > | // get the ones we know are there, yet still may need some work. |
230 | > | bsInfo.nComponents = the_globals->getNComponents(); |
231 | > | strcpy( bsInfo.forceField, the_globals->getForceField() ); |
232 | > | |
233 | > | // get the ensemble: |
234 | > | strcpy( bsInfo.ensemble, the_globals->getEnsemble() ); |
235 | > | if( !strcasecmp( bsInfo.ensemble, "NPT" ) ) { |
236 | > | |
237 | > | if (the_globals->haveTargetPressure()){ |
238 | > | bsInfo.targetPressure = the_globals->getTargetPressure(); |
239 | > | bsInfo.havePressure = 1; |
240 | > | } |
241 | > | else { |
242 | > | sprintf( painCave.errMsg, |
243 | > | "sysBuild error: If you use the constant pressure\n" |
244 | > | " ensemble, you must set targetPressure.\n" |
245 | > | " This was found in the BASS file.\n"); |
246 | > | painCave.isFatal = 1; |
247 | > | simError(); |
248 | > | } |
249 | > | |
250 | > | if (the_globals->haveTauThermostat()){ |
251 | > | bsInfo.tauThermostat = the_globals->getTauThermostat(); |
252 | > | bsInfo.haveTauThermostat = 1;; |
253 | > | } |
254 | > | else if (the_globals->haveQmass()){ |
255 | > | bsInfo.Qmass = the_globals->getQmass(); |
256 | > | bsInfo.haveQmass = 1; |
257 | > | } |
258 | > | else { |
259 | > | sprintf( painCave.errMsg, |
260 | > | "sysBuild error: If you use one of the constant temperature\n" |
261 | > | " ensembles, you must set either tauThermostat or qMass.\n" |
262 | > | " Neither of these was found in the BASS file.\n"); |
263 | > | painCave.isFatal = 1; |
264 | > | simError(); |
265 | > | } |
266 | > | |
267 | > | if (the_globals->haveTauBarostat()){ |
268 | > | bsInfo.tauBarostat = the_globals->getTauBarostat(); |
269 | > | bsInfo.haveTauBarostat = 1; |
270 | > | } |
271 | > | else { |
272 | > | sprintf( painCave.errMsg, |
273 | > | "sysBuild error: If you use the constant pressure\n" |
274 | > | " ensemble, you must set tauBarostat.\n" |
275 | > | " This was found in the BASS file.\n"); |
276 | > | painCave.isFatal = 1; |
277 | > | simError(); |
278 | > | } |
279 | > | |
280 | > | } |
281 | > | else if ( !strcasecmp( bsInfo.ensemble, "NVT") ) { |
282 | > | |
283 | > | if (the_globals->haveTauThermostat()){ |
284 | > | bsInfo.tauThermostat = the_globals->getTauThermostat(); |
285 | > | bsInfo.haveTauThermostat = 1; |
286 | > | } |
287 | > | else if (the_globals->haveQmass()){ |
288 | > | bsInfo.Qmass = the_globals->getQmass(); |
289 | > | bsInfo.haveQmass = 1; |
290 | > | } |
291 | > | else { |
292 | > | sprintf( painCave.errMsg, |
293 | > | "sysBuild error: If you use one of the constant temperature\n" |
294 | > | " ensembles, you must set either tauThermostat or qMass.\n" |
295 | > | " Neither of these was found in the BASS file.\n"); |
296 | > | painCave.isFatal = 1; |
297 | > | simError(); |
298 | > | } |
299 | > | |
300 | > | } |
301 | > | else if ( !strcasecmp( bsInfo.ensemble, "NVE") ) { |
302 | > | |
303 | > | // nothing special for now |
304 | > | } |
305 | > | else { |
306 | > | sprintf( painCave.errMsg, |
307 | > | "sysBuild Warning. Unrecognized Ensemble -> %s, " |
308 | > | "reverting to NVE for this simulation.\n", |
309 | > | bsInfo.ensemble ); |
310 | > | painCave.isFatal = 0; |
311 | > | simError(); |
312 | > | strcpy( bsInfo.ensemble, "NVE" ); |
313 | > | } |
314 | ||
315 | + | |
316 | + | // get the components and calculate the tot_nMol and indvidual n_mol |
317 | + | |
318 | + | the_components = the_globals->getComponents(); |
319 | + | bsInfo.componentsNmol = new int[bsInfo.nComponents]; |
320 | + | bsInfo.compStamps = new MoleculeStamp*[bsInfo.nComponents]; |
321 | + | bsInfo.totNmol = 0; |
322 | + | for( i=0; i<bsInfo.nComponents; i++ ){ |
323 | + | |
324 | + | if( !the_components[i]->haveNMol() ){ |
325 | + | // we have a problem |
326 | + | sprintf( painCave.errMsg, |
327 | + | "sysBuild Error. No component NMol" |
328 | + | " given. Cannot calculate the number of atoms.\n" ); |
329 | + | painCave.isFatal = 1; |
330 | + | simError(); |
331 | + | } |
332 | + | |
333 | + | bsInfo.totNmol += the_components[i]->getNMol(); |
334 | + | bsInfo.componentsNmol[i] = the_components[i]->getNMol(); |
335 | + | } |
336 | + | |
337 | + | // make an array of molecule stamps that match the components used. |
338 | + | // also extract the used stamps out into a separate linked list |
339 | + | |
340 | + | for( i=0; i<bsInfo.nComponents; i++ ){ |
341 | + | |
342 | + | id = the_components[i]->getType(); |
343 | + | bsInfo.compStamps[i] = NULL; |
344 | + | |
345 | + | // check to make sure the component isn't already in the list |
346 | + | |
347 | + | bsInfo.compStamps[i] = headStamp->match( id ); |
348 | + | if( bsInfo.compStamps[i] == NULL ){ |
349 | + | |
350 | + | // extract the component from the list; |
351 | + | |
352 | + | currStamp = the_stamps->extractMolStamp( id ); |
353 | + | if( currStamp == NULL ){ |
354 | + | sprintf( painCave.errMsg, |
355 | + | "sysBuild error: Component \"%s\" was not found in the " |
356 | + | "list of declared molecules\n", |
357 | + | id ); |
358 | + | painCave.isFatal = 1; |
359 | + | simError(); |
360 | + | } |
361 | + | |
362 | + | headStamp->add( currStamp ); |
363 | + | bsInfo.compStamps[i] = headStamp->match( id ); |
364 | + | } |
365 | + | } |
366 | + | |
367 | + | // get and set the boxSize |
368 | + | |
369 | + | if( the_globals->haveBox() ){ |
370 | + | bsInfo.boxX = the_globals->getBox(); |
371 | + | bsInfo.boxY = the_globals->getBox(); |
372 | + | bsInfo.boxZ = the_globals->getBox(); |
373 | + | } |
374 | + | else if( the_globals->haveDensity() ){ |
375 | + | |
376 | + | double vol; |
377 | + | vol = (double)bsInfo.totNmol / the_globals->getDensity(); |
378 | + | bsInfo.boxX = pow( vol, ( 1.0 / 3.0 ) ); |
379 | + | bsInfo.boxY = bsInfo.boxX; |
380 | + | bsInfo.boxZ = bsInfo.boxY; |
381 | + | } |
382 | + | else{ |
383 | + | if( !the_globals->haveBoxX() ){ |
384 | + | sprintf( painCave.errMsg, |
385 | + | "sysBuild error, no periodic BoxX size given.\n" ); |
386 | + | painCave.isFatal = 1; |
387 | + | simError(); |
388 | + | } |
389 | + | bsInfo.boxX = the_globals->getBoxX(); |
390 | + | |
391 | + | if( !the_globals->haveBoxY() ){ |
392 | + | sprintf( painCave.errMsg, |
393 | + | "sysBuild error, no periodic BoxY size given.\n" ); |
394 | + | painCave.isFatal = 1; |
395 | + | simError(); |
396 | + | } |
397 | + | bsInfo.boxY = the_globals->getBoxY(); |
398 | + | |
399 | + | if( !the_globals->haveBoxZ() ){ |
400 | + | sprintf( painCave.errMsg, |
401 | + | "SimSetup error, no periodic BoxZ size given.\n" ); |
402 | + | painCave.isFatal = 1; |
403 | + | simError(); |
404 | + | } |
405 | + | bsInfo.boxZ = the_globals->getBoxZ(); |
406 | + | } |
407 | + | |
408 | + | |
409 | + | //************************************************************ |
410 | + | // that should be all we need from bass. now to switch to the |
411 | + | // appropriate system builder. |
412 | + | // *********************************************************** |
413 | + | |
414 | + | |
415 | switch( sysType ){ | |
416 | ||
417 | case BILAYER: | |
418 | ||
419 | < | buildBilayer( info ); |
419 | > | buildBilayer( isRandom ); |
420 | break; | |
421 | ||
422 | default: | |
# | Line 170 | Line 426 | int main( int argc, char* argv[]){ | |
426 | simError(); | |
427 | } | |
428 | ||
429 | + | |
430 | + | |
431 | + | // clean up memory; |
432 | + | |
433 | + | if( headStamp!= NULL ) delete headStamp; |
434 | + | if( the_stamps != NULL ) delete the_stamps; |
435 | + | if( the_globals != NULL ) delete the_globals; |
436 | + | if( the_components != NULL ) delete[] the_components; |
437 | + | |
438 | + | if( bsInfo.componentsNmol != NULL ) delete[] bsInfo.componentsNmol; |
439 | + | if( bsInfo.compStamps != NULL ) delete[] bsInfo.compStamps; |
440 | + | if( bsInfo.includes != NULL ){ |
441 | + | prevInc = bsInfo.includes; |
442 | + | while( prevInc != NULL ){ |
443 | + | currInc = prevInc->next; |
444 | + | delete prevInc; |
445 | + | prevInc = currInc; |
446 | + | } |
447 | + | } |
448 | + | |
449 | return 0; | |
450 | } | |
451 | ||
# | Line 188 | Line 464 | void usage(){ | |
464 | " ------\n" | |
465 | " -h Display this message\n" | |
466 | " -o <prefix> The output prefix\n" | |
467 | + | " -I <include> File name that should be included at the top of the\n" |
468 | + | " output bass file.\n" |
469 | " -r toggle the random option\n" | |
470 | "\n" | |
471 | " long:\n" |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |