ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/utils/sysbuilder/sysBuild.cpp
Revision: 822
Committed: Mon Oct 27 16:20:59 2003 UTC (20 years, 8 months ago) by gezelter
File size: 12769 byte(s)
Log Message:
fixes for configure, sysBuild

File Contents

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