ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/utils/sysbuilder/sysBuild.cpp
Revision: 817
Committed: Fri Oct 24 17:36:18 2003 UTC (20 years, 8 months ago) by gezelter
File size: 13695 byte(s)
Log Message:
work on bilayer builder

File Contents

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