ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/utils/sysbuilder/sysBuild.cpp
Revision: 821
Committed: Fri Oct 24 22:17:45 2003 UTC (20 years, 8 months ago) by mmeineke
File size: 12770 byte(s)
Log Message:
put QuickBass, MoLocator, and latticeBuilder into a Builder Library
overhauled latticeBilayer into its own program. Removed sysBuild from the Makefile

File Contents

# Content
1 #include <cstdlib>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 #include <iostream>
6
7 #include "cmdline.h"
8 #include "simError.h"
9 #include "parse_me.h"
10 #include "MakeStamps.hpp"
11 #include "Globals.hpp"
12 #include "SimInfo.hpp"
13
14 #include "sysBuild.hpp"
15 #include "latticeBuilder.hpp"
16 #include "bilayerSys.hpp"
17 #include "nanoBuilder.hpp"
18
19 // this routine is defined in BASS_interface.cpp
20 extern void set_interface_stamps( MakeStamps* ms, Globals* g );
21
22
23 // case asignments
24 #define BILAYER 1
25 #define NANOPARTICLE 2
26
27 char* program_name;
28 bassInfo bsInfo;
29 void usage(void);
30 int grabCmdArgs(void);
31
32
33
34
35 int have_prefix;
36 char* out_prefix;
37 char* in_name;
38 int isRandom;
39 includeLinked* headInc;
40 includeLinked* prevInc;
41 includeLinked* currInc;
42 gengetopt_args_info args_info;
43
44
45 int main( int argc, char* argv[]){
46
47 int i,j,k;
48 int sysType;
49 int done;
50 char current_flag;
51 // int have_prefix;
52 // char* out_prefix;
53 // char* in_name;
54 char* id;
55
56 int hasErrors;
57
58 // initialize all functions and variables
59
60 initSimError();
61 program_name = argv[0];
62 sysType = -1;
63 have_prefix = 0;
64 isRandom = 0;
65 in_name = NULL;
66 headInc = NULL;
67
68 bsInfo.includes = NULL;
69
70
71 // parse command line arguments
72
73 if (cmdline_parser (argc, argv, &args_info) != 0)
74 exit(1) ;
75
76 // Handle command line arguments.
77 sysType = grabCmdArgs();
78
79 // Keep me
80 if(in_name == NULL){
81 sprintf( painCave.errMsg,
82 "No input bass file was specified.\n");
83 painCave.isFatal = 0;
84 simError();
85 cmdline_parser_print_help();
86 }
87
88 if( sysType < 0 ){
89 sprintf( painCave.errMsg,
90 "No system type was specified.\n");
91 painCave.isFatal = 0;
92 simError();
93 cmdline_parser_print_help();
94 }
95
96
97 // if no output prefix is given default to "donkey".
98
99 if( !have_prefix ){
100 out_prefix = strdup( "donkey" );
101 }
102
103 // set command line info into the bassInfo struct
104
105 bsInfo.outPrefix = out_prefix;
106 bsInfo.includes = headInc;
107
108
109 // open and parse the bass file.
110
111 set_interface_stamps( the_stamps, the_globals );
112 yacc_BASS( in_name );
113
114 // set the easy ones first
115 bsInfo.targetTemp = the_globals->getTargetTemp();
116 bsInfo.dt = the_globals->getDt();
117 bsInfo.runTime = the_globals->getRunTime();
118
119 // get the ones we know are there, yet still may need some work.
120 bsInfo.nComponents = the_globals->getNComponents();
121 strcpy( bsInfo.forceField, the_globals->getForceField() );
122
123 // get the ensemble:
124 strcpy( bsInfo.ensemble, the_globals->getEnsemble() );
125 if( !strcasecmp( bsInfo.ensemble, "NPT" ) ) {
126
127 if (the_globals->haveTargetPressure()){
128 bsInfo.targetPressure = the_globals->getTargetPressure();
129 bsInfo.havePressure = 1;
130 }
131 else {
132 sprintf( painCave.errMsg,
133 "sysBuild error: If you use the constant pressure\n"
134 " ensemble, you must set targetPressure.\n"
135 " This was found in the BASS file.\n");
136 painCave.isFatal = 1;
137 simError();
138 }
139
140 if (the_globals->haveTauThermostat()){
141 bsInfo.tauThermostat = the_globals->getTauThermostat();
142 bsInfo.haveTauThermostat = 1;;
143 }
144 else if (the_globals->haveQmass()){
145 bsInfo.Qmass = the_globals->getQmass();
146 bsInfo.haveQmass = 1;
147 }
148 else {
149 sprintf( painCave.errMsg,
150 "sysBuild error: If you use one of the constant temperature\n"
151 " ensembles, you must set either tauThermostat or qMass.\n"
152 " Neither of these was found in the BASS file.\n");
153 painCave.isFatal = 1;
154 simError();
155 }
156
157 if (the_globals->haveTauBarostat()){
158 bsInfo.tauBarostat = the_globals->getTauBarostat();
159 bsInfo.haveTauBarostat = 1;
160 }
161 else {
162 sprintf( painCave.errMsg,
163 "sysBuild error: If you use the constant pressure\n"
164 " ensemble, you must set tauBarostat.\n"
165 " This was found in the BASS file.\n");
166 painCave.isFatal = 1;
167 simError();
168 }
169
170 }
171 else if ( !strcasecmp( bsInfo.ensemble, "NVT") ) {
172
173 if (the_globals->haveTauThermostat()){
174 bsInfo.tauThermostat = the_globals->getTauThermostat();
175 bsInfo.haveTauThermostat = 1;
176 }
177 else if (the_globals->haveQmass()){
178 bsInfo.Qmass = the_globals->getQmass();
179 bsInfo.haveQmass = 1;
180 }
181 else {
182 sprintf( painCave.errMsg,
183 "sysBuild error: If you use one of the constant temperature\n"
184 " ensembles, you must set either tauThermostat or qMass.\n"
185 " Neither of these was found in the BASS file.\n");
186 painCave.isFatal = 1;
187 simError();
188 }
189
190 }
191 else if ( !strcasecmp( bsInfo.ensemble, "NVE") ) {
192
193 // nothing special for now
194 }
195 else {
196 sprintf( painCave.errMsg,
197 "sysBuild Warning. Unrecognized Ensemble -> %s, "
198 "reverting to NVE for this simulation.\n",
199 bsInfo.ensemble );
200 painCave.isFatal = 0;
201 simError();
202 strcpy( bsInfo.ensemble, "NVE" );
203 }
204
205
206 // get the components and calculate the tot_nMol and indvidual n_mol
207
208 the_components = the_globals->getComponents();
209 bsInfo.componentsNmol = new int[bsInfo.nComponents];
210 bsInfo.compStamps = new MoleculeStamp*[bsInfo.nComponents];
211 bsInfo.totNmol = 0;
212 for( i=0; i<bsInfo.nComponents; i++ ){
213
214 if( !the_components[i]->haveNMol() ){
215 // we have a problem
216 sprintf( painCave.errMsg,
217 "sysBuild Error. No component NMol"
218 " given. Cannot calculate the number of atoms.\n" );
219 painCave.isFatal = 1;
220 simError();
221 }
222
223 bsInfo.totNmol += the_components[i]->getNMol();
224 bsInfo.componentsNmol[i] = the_components[i]->getNMol();
225 }
226
227 // make an array of molecule stamps that match the components used.
228 // also extract the used stamps out into a separate linked list
229
230 for( i=0; i<bsInfo.nComponents; i++ ){
231
232 id = the_components[i]->getType();
233 bsInfo.compStamps[i] = NULL;
234
235 // check to make sure the component isn't already in the list
236
237 bsInfo.compStamps[i] = headStamp->match( id );
238 if( bsInfo.compStamps[i] == NULL ){
239
240 // extract the component from the list;
241
242 currStamp = the_stamps->extractMolStamp( id );
243 if( currStamp == NULL ){
244 sprintf( painCave.errMsg,
245 "sysBuild error: Component \"%s\" was not found in the "
246 "list of declared molecules\n",
247 id );
248 painCave.isFatal = 1;
249 simError();
250 }
251
252 headStamp->add( currStamp );
253 bsInfo.compStamps[i] = headStamp->match( id );
254 }
255 }
256
257 // get and set the boxSize
258
259 bsInfo.haveBox = false;
260
261 std::cerr << "Box setting...";
262
263 std::cerr <<" haveBox= " << the_globals->haveBox() << "\n";
264
265 if( the_globals->haveBox() ){
266 bsInfo.boxX = the_globals->getBox();
267 bsInfo.boxY = the_globals->getBox();
268 bsInfo.boxZ = the_globals->getBox();
269 bsInfo.haveBox = true;
270 std::cerr<< "box=>yes\n";
271 }
272 else if( the_globals->haveDensity() ){
273
274 double vol;
275 vol = (double)bsInfo.totNmol / the_globals->getDensity();
276 bsInfo.boxX = pow( vol, ( 1.0 / 3.0 ) );
277 bsInfo.boxY = bsInfo.boxX;
278 bsInfo.boxZ = bsInfo.boxY;
279 bsInfo.haveBox = true;
280
281 std::cerr<< "dens=>yes\n";
282 }
283 else{
284 std::cerr<< "none.\n";
285 }
286
287
288 // ************************************************************
289 // that should be all we need from bass. now to switch to the
290 // appropriate system builder.
291 // ***********************************************************
292
293 nanoBuilder* buildNano;
294
295 switch( sysType ){
296
297 case BILAYER:
298 buildBilayer( isRandom );
299 break;
300
301 case NANOPARTICLE:
302
303 buildNano = new nanoBuilder(hasErrors);
304
305 buildNano->buildNanoParticle();
306
307 break;
308
309 default:
310 sprintf( painCave.errMsg,
311 "Unknown system type: %d\n", sysType );
312 painCave.isFatal = 1;
313 simError();
314
315 }
316
317
318
319 // clean up memory;
320
321 if( headStamp!= NULL ) delete headStamp;
322 if( the_stamps != NULL ) delete the_stamps;
323 if( the_globals != NULL ) delete the_globals;
324 // if( the_components != NULL ) delete[] the_components;
325
326 if( bsInfo.componentsNmol != NULL ) delete[] bsInfo.componentsNmol;
327 if( bsInfo.compStamps != NULL ) delete[] bsInfo.compStamps;
328 if( bsInfo.includes != NULL ){
329 prevInc = bsInfo.includes;
330 while( prevInc != NULL ){
331 currInc = prevInc->next;
332 delete prevInc;
333 prevInc = currInc;
334 }
335 }
336
337 return 0;
338 }
339
340
341
342 /* Parses command line arguments. Returns systype. If systype is -1,
343 sysType was undefined.
344 */
345 int grabCmdArgs(){
346 int sysType;
347 int i;
348
349 sysType = -1;
350
351 /* Handle model arguments first....*/
352
353 if (args_info.bilayer_given){ //Test for bilayer system.
354 sysType = BILAYER;
355 if ((args_info.water_given) && (args_info.lipid_given)){
356 strcpy( bsInfo.lipidName, args_info.lipid_arg );
357 strcpy( bsInfo.waterName, args_info.water_arg );
358 }
359 else {
360 sprintf( painCave.errMsg,
361 "You must specify a lipid and water model for bilayer.\n" );
362 painCave.isFatal = 0;
363 simError();
364 cmdline_parser_print_help();
365 }
366 }
367
368 // Test for nanoparticle system.
369 if (args_info.nanoparticle_given){
370 sysType = NANOPARTICLE;
371 if (!args_info.core_given){
372 sprintf( painCave.errMsg,
373 "You must specify core model for nanoparticle.\n" );
374 painCave.isFatal = 0;
375 simError();
376 cmdline_parser_print_help();
377 }
378
379 // set core model
380 strcpy( bsInfo.coreName, args_info.core_arg );
381 if (args_info.shell_given){
382 bsInfo.buildCoreShell = 1;
383 strcpy( bsInfo.shellName, args_info.shell_arg );
384
385
386 }
387
388 // Check for vacancies.
389 if (args_info.vacancies_given){
390
391 if (!args_info.vacancyradius_given){ // Make sure that a vacancy radius was given.
392 sprintf( painCave.errMsg,
393 "You must specify a vacancy radius for building vacancies.\n" );
394 painCave.isFatal = 0;
395 simError();
396 cmdline_parser_print_help();
397 }
398 bsInfo.hasVacancies = 1;
399 bsInfo.vacancyRadius = args_info.vacancyradius_arg;
400 }
401 else if (args_info.vacancyradius_given){
402 sprintf( painCave.errMsg,
403 "You must specify vacancies=percent for vacancy radius.\n" );
404 painCave.isFatal = 0;
405 simError();
406 cmdline_parser_print_help();
407 }
408
409 if (args_info.randomparticle_given){
410 bsInfo.isRandomParticle = 1;
411 bsInfo.soluteX = args_info.randomparticle_arg;
412 }
413
414 }
415 /* ---------------Now do general arguments-----------------------*/
416
417 if (args_info.output_given){ //Output File (defaults to donkey if not specified.
418 out_prefix = args_info.output_arg;
419 have_prefix = 1;
420 }
421
422 if (args_info.include_given){ // Deal with multiple include files.
423 for( i = 0; i < args_info.include_given;++i){
424 if( headInc == NULL ){
425 headInc = new includeLinked;
426 headInc->next = NULL;
427 strcpy( headInc->name, args_info.include_arg[i] );
428 }
429 else{
430 prevInc = headInc;
431 currInc = headInc->next;
432 while( currInc != NULL ){
433 prevInc = currInc;
434 currInc = prevInc->next;
435 }
436 currInc = new includeLinked;
437 currInc->next = NULL;
438 strcpy( currInc->name, args_info.include_arg[i] );
439 prevInc->next = currInc;
440 }
441 }
442 }
443
444 if (args_info.random_given){ // Random Particle
445 isRandom = 1;;
446 }
447
448 if (args_info.inputs_num) { //Get input file name
449 in_name = args_info.inputs[0];
450 cerr << in_name << "\n";
451 }
452 else {
453 sprintf( painCave.errMsg,
454 "You must specify a input file name.\n" );
455 painCave.isFatal = 0;
456 simError();
457 cmdline_parser_print_help();
458
459 }
460
461 return sysType;
462 }
463
464
465
466
467
468
469
470
471
472
473 /***************************************************************************
474 * prints out the usage for the command line arguments, then exits.
475 ***************************************************************************/
476
477 void usage(){
478 (void)fprintf(stdout,
479 "The proper usage is: %s [options] <input bass>\n"
480 "\n"
481 "Options:\n"
482 "\n"
483 " short:\n"
484 " ------\n"
485 " -h Display this message\n"
486 " -o <prefix> The output prefix\n"
487 " -I <include> File name that should be included at the top of the\n"
488 " output bass file.\n"
489 " -r toggle the random option\n"
490 "\n"
491 " long:\n"
492 " -----\n"
493 " --bilayer <lipid> <water> Tries to build a basic bilayer with the specified number\n"
494 " of lipids in the input bass file. The bilayer will be\n"
495 " surrounded by the number of solvent molecules given\n"
496 " in the bass file.\n"
497 " -note: combined with \"-r\" the simulation will start\n"
498 " the lipids randomly oriented in a sea of waters.\n"
499 "\n"
500 "\n",
501 program_name);
502 exit(8);
503 }