ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/SimSetup.cpp
Revision: 490
Committed: Fri Apr 11 15:16:59 2003 UTC (21 years, 2 months ago) by gezelter
File size: 31580 byte(s)
Log Message:
Bug fix in progress for NPT

File Contents

# Content
1 #include <cstdlib>
2 #include <iostream>
3 #include <cmath>
4
5 #include "SimSetup.hpp"
6 #include "parse_me.h"
7 #include "Integrator.hpp"
8 #include "simError.h"
9
10 #ifdef IS_MPI
11 #include "mpiBASS.h"
12 #include "mpiSimulation.hpp"
13 #endif
14
15 SimSetup::SimSetup(){
16 stamps = new MakeStamps();
17 globals = new Globals();
18
19 #ifdef IS_MPI
20 strcpy( checkPointMsg, "SimSetup creation successful" );
21 MPIcheckPoint();
22 #endif // IS_MPI
23 }
24
25 SimSetup::~SimSetup(){
26 delete stamps;
27 delete globals;
28 }
29
30 void SimSetup::parseFile( char* fileName ){
31
32 #ifdef IS_MPI
33 if( worldRank == 0 ){
34 #endif // is_mpi
35
36 inFileName = fileName;
37 set_interface_stamps( stamps, globals );
38
39 #ifdef IS_MPI
40 mpiEventInit();
41 #endif
42
43 yacc_BASS( fileName );
44
45 #ifdef IS_MPI
46 throwMPIEvent(NULL);
47 }
48 else receiveParse();
49 #endif
50
51 }
52
53 #ifdef IS_MPI
54 void SimSetup::receiveParse(void){
55
56 set_interface_stamps( stamps, globals );
57 mpiEventInit();
58 MPIcheckPoint();
59 mpiEventLoop();
60
61 }
62
63 #endif // is_mpi
64
65 void SimSetup::createSim( void ){
66
67 MakeStamps *the_stamps;
68 Globals* the_globals;
69 ExtendedSystem* the_extendedsystem;
70 int i, j, k, globalAtomIndex;
71
72 // get the stamps and globals;
73 the_stamps = stamps;
74 the_globals = globals;
75
76 // set the easy ones first
77 simnfo->target_temp = the_globals->getTargetTemp();
78 simnfo->dt = the_globals->getDt();
79 simnfo->run_time = the_globals->getRunTime();
80
81 // get the ones we know are there, yet still may need some work.
82 n_components = the_globals->getNComponents();
83 strcpy( force_field, the_globals->getForceField() );
84
85 // get the ensemble and set up an extended system if we need it:
86 strcpy( ensemble, the_globals->getEnsemble() );
87 if( !strcasecmp( ensemble, "NPT" ) ) {
88 the_extendedsystem = new ExtendedSystem( simnfo );
89 the_extendedsystem->setTargetTemp(the_globals->getTargetTemp());
90 if (the_globals->haveTargetPressure())
91 the_extendedsystem->setTargetPressure(the_globals->getTargetPressure());
92 else {
93 sprintf( painCave.errMsg,
94 "SimSetup error: If you use the constant pressure\n"
95 " ensemble, you must set targetPressure.\n"
96 " This was found in the BASS file.\n");
97 painCave.isFatal = 1;
98 simError();
99 }
100
101 if (the_globals->haveTauThermostat())
102 the_extendedsystem->setTauThermostat(the_globals->getTauThermostat());
103 else if (the_globals->haveQmass())
104 the_extendedsystem->setQmass(the_globals->getQmass());
105 else {
106 sprintf( painCave.errMsg,
107 "SimSetup error: If you use one of the constant temperature\n"
108 " ensembles, you must set either tauThermostat or qMass.\n"
109 " Neither of these was found in the BASS file.\n");
110 painCave.isFatal = 1;
111 simError();
112 }
113
114 if (the_globals->haveTauBarostat())
115 the_extendedsystem->setTauBarostat(the_globals->getTauBarostat());
116 else {
117 sprintf( painCave.errMsg,
118 "SimSetup error: If you use the constant pressure\n"
119 " ensemble, you must set tauBarostat.\n"
120 " This was found in the BASS file.\n");
121 painCave.isFatal = 1;
122 simError();
123 }
124
125 } else if ( !strcasecmp( ensemble, "NVT") ) {
126 the_extendedsystem = new ExtendedSystem( simnfo );
127 the_extendedsystem->setTargetTemp(the_globals->getTargetTemp());
128
129 if (the_globals->haveTauThermostat())
130 the_extendedsystem->setTauThermostat(the_globals->getTauThermostat());
131 else if (the_globals->haveQmass())
132 the_extendedsystem->setQmass(the_globals->getQmass());
133 else {
134 sprintf( painCave.errMsg,
135 "SimSetup error: If you use one of the constant temperature\n"
136 " ensembles, you must set either tauThermostat or qMass.\n"
137 " Neither of these was found in the BASS file.\n");
138 painCave.isFatal = 1;
139 simError();
140 }
141
142 } else if ( !strcasecmp( ensemble, "NVE") ) {
143 } else {
144 sprintf( painCave.errMsg,
145 "SimSetup Warning. Unrecognized Ensemble -> %s, "
146 "reverting to NVE for this simulation.\n",
147 ensemble );
148 painCave.isFatal = 0;
149 simError();
150 strcpy( ensemble, "NVE" );
151 }
152 strcpy( simnfo->ensemble, ensemble );
153
154 strcpy( simnfo->mixingRule, the_globals->getMixingRule() );
155 simnfo->usePBC = the_globals->getPBC();
156
157 int usesDipoles = 0;
158 if( !strcmp( force_field, "TraPPE_Ex" ) ){
159 the_ff = new TraPPE_ExFF();
160 usesDipoles = 1;
161 }
162 else if( !strcasecmp( force_field, "LJ" ) ) the_ff = new LJ_FF();
163 else{
164 sprintf( painCave.errMsg,
165 "SimSetup Error. Unrecognized force field -> %s\n",
166 force_field );
167 painCave.isFatal = 1;
168 simError();
169 }
170
171 #ifdef IS_MPI
172 strcpy( checkPointMsg, "ForceField creation successful" );
173 MPIcheckPoint();
174 #endif // is_mpi
175
176
177
178 // get the components and calculate the tot_nMol and indvidual n_mol
179 the_components = the_globals->getComponents();
180 components_nmol = new int[n_components];
181 comp_stamps = new MoleculeStamp*[n_components];
182
183 if( !the_globals->haveNMol() ){
184 // we don't have the total number of molecules, so we assume it is
185 // given in each component
186
187 tot_nmol = 0;
188 for( i=0; i<n_components; i++ ){
189
190 if( !the_components[i]->haveNMol() ){
191 // we have a problem
192 sprintf( painCave.errMsg,
193 "SimSetup Error. No global NMol or component NMol"
194 " given. Cannot calculate the number of atoms.\n" );
195 painCave.isFatal = 1;
196 simError();
197 }
198
199 tot_nmol += the_components[i]->getNMol();
200 components_nmol[i] = the_components[i]->getNMol();
201 }
202 }
203 else{
204 sprintf( painCave.errMsg,
205 "SimSetup error.\n"
206 "\tSorry, the ability to specify total"
207 " nMols and then give molfractions in the components\n"
208 "\tis not currently supported."
209 " Please give nMol in the components.\n" );
210 painCave.isFatal = 1;
211 simError();
212
213
214 // tot_nmol = the_globals->getNMol();
215
216 // //we have the total number of molecules, now we check for molfractions
217 // for( i=0; i<n_components; i++ ){
218
219 // if( !the_components[i]->haveMolFraction() ){
220
221 // if( !the_components[i]->haveNMol() ){
222 // //we have a problem
223 // std::cerr << "SimSetup error. Neither molFraction nor "
224 // << " nMol was given in component
225
226 }
227
228 #ifdef IS_MPI
229 strcpy( checkPointMsg, "Have the number of components" );
230 MPIcheckPoint();
231 #endif // is_mpi
232
233 // make an array of molecule stamps that match the components used.
234 // also extract the used stamps out into a separate linked list
235
236 simnfo->nComponents = n_components;
237 simnfo->componentsNmol = components_nmol;
238 simnfo->compStamps = comp_stamps;
239 simnfo->headStamp = new LinkedMolStamp();
240
241 char* id;
242 LinkedMolStamp* headStamp = simnfo->headStamp;
243 LinkedMolStamp* currentStamp = NULL;
244 for( i=0; i<n_components; i++ ){
245
246 id = the_components[i]->getType();
247 comp_stamps[i] = NULL;
248
249 // check to make sure the component isn't already in the list
250
251 comp_stamps[i] = headStamp->match( id );
252 if( comp_stamps[i] == NULL ){
253
254 // extract the component from the list;
255
256 currentStamp = the_stamps->extractMolStamp( id );
257 if( currentStamp == NULL ){
258 sprintf( painCave.errMsg,
259 "SimSetup error: Component \"%s\" was not found in the "
260 "list of declared molecules\n",
261 id );
262 painCave.isFatal = 1;
263 simError();
264 }
265
266 headStamp->add( currentStamp );
267 comp_stamps[i] = headStamp->match( id );
268 }
269 }
270
271 #ifdef IS_MPI
272 strcpy( checkPointMsg, "Component stamps successfully extracted\n" );
273 MPIcheckPoint();
274 #endif // is_mpi
275
276
277
278
279 // caclulate the number of atoms, bonds, bends and torsions
280
281 tot_atoms = 0;
282 tot_bonds = 0;
283 tot_bends = 0;
284 tot_torsions = 0;
285 for( i=0; i<n_components; i++ ){
286
287 tot_atoms += components_nmol[i] * comp_stamps[i]->getNAtoms();
288 tot_bonds += components_nmol[i] * comp_stamps[i]->getNBonds();
289 tot_bends += components_nmol[i] * comp_stamps[i]->getNBends();
290 tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions();
291 }
292
293 tot_SRI = tot_bonds + tot_bends + tot_torsions;
294
295 simnfo->n_atoms = tot_atoms;
296 simnfo->n_bonds = tot_bonds;
297 simnfo->n_bends = tot_bends;
298 simnfo->n_torsions = tot_torsions;
299 simnfo->n_SRI = tot_SRI;
300 simnfo->n_mol = tot_nmol;
301 simnfo->molMembershipArray = new int[tot_atoms];
302
303 #ifdef IS_MPI
304
305 // divide the molecules among processors here.
306
307 mpiSim = new mpiSimulation( simnfo );
308
309 globalIndex = mpiSim->divideLabor();
310
311 // set up the local variables
312
313 int localMol, allMol;
314 int local_atoms, local_bonds, local_bends, local_torsions, local_SRI;
315
316 int* mol2proc = mpiSim->getMolToProcMap();
317 int* molCompType = mpiSim->getMolComponentType();
318
319 allMol = 0;
320 localMol = 0;
321 local_atoms = 0;
322 local_bonds = 0;
323 local_bends = 0;
324 local_torsions = 0;
325 globalAtomIndex = 0;
326
327
328 for( i=0; i<n_components; i++ ){
329
330 for( j=0; j<components_nmol[i]; j++ ){
331
332 if( mol2proc[allMol] == worldRank ){
333
334 local_atoms += comp_stamps[i]->getNAtoms();
335 local_bonds += comp_stamps[i]->getNBonds();
336 local_bends += comp_stamps[i]->getNBends();
337 local_torsions += comp_stamps[i]->getNTorsions();
338 localMol++;
339 }
340 for (k = 0; k < comp_stamps[i]->getNAtoms(); k++) {
341 simnfo->molMembershipArray[globalAtomIndex] = allMol;
342 globalAtomIndex++;
343 }
344
345 allMol++;
346 }
347 }
348 local_SRI = local_bonds + local_bends + local_torsions;
349
350 if (worldRank != 0) {
351 for (i =0; i < tot_atoms; i++){
352 std::cerr << "i = " << i << " molMembershipArray[i] = " << simnfo->molMembershipArray[i] << "\n";
353 }
354 }
355
356 simnfo->n_atoms = mpiSim->getMyNlocal();
357
358 if( local_atoms != simnfo->n_atoms ){
359 sprintf( painCave.errMsg,
360 "SimSetup error: mpiSim's localAtom (%d) and SimSetup's"
361 " localAtom (%d) are not equal.\n",
362 simnfo->n_atoms,
363 local_atoms );
364 painCave.isFatal = 1;
365 simError();
366 }
367
368 simnfo->n_bonds = local_bonds;
369 simnfo->n_bends = local_bends;
370 simnfo->n_torsions = local_torsions;
371 simnfo->n_SRI = local_SRI;
372 simnfo->n_mol = localMol;
373
374 strcpy( checkPointMsg, "Passed nlocal consistency check." );
375 MPIcheckPoint();
376
377
378 #endif // is_mpi
379
380
381 // create the atom and short range interaction arrays
382
383 Atom::createArrays(simnfo->n_atoms);
384 the_atoms = new Atom*[simnfo->n_atoms];
385 the_molecules = new Molecule[simnfo->n_mol];
386 int molIndex;
387
388 // initialize the molecule's stampID's
389
390 #ifdef IS_MPI
391
392
393 molIndex = 0;
394 for(i=0; i<mpiSim->getTotNmol(); i++){
395
396 if(mol2proc[i] == worldRank ){
397 the_molecules[molIndex].setStampID( molCompType[i] );
398 the_molecules[molIndex].setMyIndex( molIndex );
399 the_molecules[molIndex].setGlobalIndex( i );
400 molIndex++;
401 }
402 }
403
404 #else // is_mpi
405
406 molIndex = 0;
407 globalAtomIndex = 0;
408 for(i=0; i<n_components; i++){
409 for(j=0; j<components_nmol[i]; j++ ){
410 the_molecules[molIndex].setStampID( i );
411 the_molecules[molIndex].setMyIndex( molIndex );
412 the_molecules[molIndex].setGlobalIndex( molIndex );
413 for (k = 0; k < comp_stamps[i]->getNAtoms(); k++) {
414 simnfo->molMembershipArray[globalAtomIndex] = molIndex;
415 globalAtomIndex++;
416 }
417 molIndex++;
418 }
419 }
420
421
422 #endif // is_mpi
423
424
425 if( simnfo->n_SRI ){
426
427 Exclude::createArray(simnfo->n_SRI);
428 the_excludes = new Exclude*[simnfo->n_SRI];
429 for( int ex=0; ex<simnfo->n_SRI; ex++) the_excludes[ex] = new Exclude(ex);
430 simnfo->globalExcludes = new int;
431 simnfo->n_exclude = simnfo->n_SRI;
432 }
433 else{
434
435 Exclude::createArray( 1 );
436 the_excludes = new Exclude*;
437 the_excludes[0] = new Exclude(0);
438 the_excludes[0]->setPair( 0,0 );
439 simnfo->globalExcludes = new int;
440 simnfo->globalExcludes[0] = 0;
441 simnfo->n_exclude = 0;
442 }
443
444 // set the arrays into the SimInfo object
445
446 simnfo->atoms = the_atoms;
447 simnfo->molecules = the_molecules;
448 simnfo->nGlobalExcludes = 0;
449 simnfo->excludes = the_excludes;
450
451
452 // get some of the tricky things that may still be in the globals
453
454
455 if( the_globals->haveBox() ){
456 simnfo->box_x = the_globals->getBox();
457 simnfo->box_y = the_globals->getBox();
458 simnfo->box_z = the_globals->getBox();
459 }
460 else if( the_globals->haveDensity() ){
461
462 double vol;
463 vol = (double)tot_nmol / the_globals->getDensity();
464 simnfo->box_x = pow( vol, ( 1.0 / 3.0 ) );
465 simnfo->box_y = simnfo->box_x;
466 simnfo->box_z = simnfo->box_x;
467 }
468 else{
469 if( !the_globals->haveBoxX() ){
470 sprintf( painCave.errMsg,
471 "SimSetup error, no periodic BoxX size given.\n" );
472 painCave.isFatal = 1;
473 simError();
474 }
475 simnfo->box_x = the_globals->getBoxX();
476
477 if( !the_globals->haveBoxY() ){
478 sprintf( painCave.errMsg,
479 "SimSetup error, no periodic BoxY size given.\n" );
480 painCave.isFatal = 1;
481 simError();
482 }
483 simnfo->box_y = the_globals->getBoxY();
484
485 if( !the_globals->haveBoxZ() ){
486 sprintf( painCave.errMsg,
487 "SimSetup error, no periodic BoxZ size given.\n" );
488 painCave.isFatal = 1;
489 simError();
490 }
491 simnfo->box_z = the_globals->getBoxZ();
492 }
493
494 #ifdef IS_MPI
495 strcpy( checkPointMsg, "Box size set up" );
496 MPIcheckPoint();
497 #endif // is_mpi
498
499
500 // initialize the arrays
501
502 the_ff->setSimInfo( simnfo );
503
504 makeMolecules();
505 simnfo->identArray = new int[simnfo->n_atoms];
506 for(i=0; i<simnfo->n_atoms; i++){
507 simnfo->identArray[i] = the_atoms[i]->getIdent();
508 }
509
510 if (the_globals->getUseRF() ) {
511 simnfo->useReactionField = 1;
512
513 if( !the_globals->haveECR() ){
514 sprintf( painCave.errMsg,
515 "SimSetup Warning: using default value of 1/2 the smallest "
516 "box length for the electrostaticCutoffRadius.\n"
517 "I hope you have a very fast processor!\n");
518 painCave.isFatal = 0;
519 simError();
520 double smallest;
521 smallest = simnfo->box_x;
522 if (simnfo->box_y <= smallest) smallest = simnfo->box_y;
523 if (simnfo->box_z <= smallest) smallest = simnfo->box_z;
524 simnfo->ecr = 0.5 * smallest;
525 } else {
526 simnfo->ecr = the_globals->getECR();
527 }
528
529 if( !the_globals->haveEST() ){
530 sprintf( painCave.errMsg,
531 "SimSetup Warning: using default value of 0.05 * the "
532 "electrostaticCutoffRadius for the electrostaticSkinThickness\n"
533 );
534 painCave.isFatal = 0;
535 simError();
536 simnfo->est = 0.05 * simnfo->ecr;
537 } else {
538 simnfo->est = the_globals->getEST();
539 }
540
541 if(!the_globals->haveDielectric() ){
542 sprintf( painCave.errMsg,
543 "SimSetup Error: You are trying to use Reaction Field without"
544 "setting a dielectric constant!\n"
545 );
546 painCave.isFatal = 1;
547 simError();
548 }
549 simnfo->dielectric = the_globals->getDielectric();
550 } else {
551 if (usesDipoles) {
552
553 if( !the_globals->haveECR() ){
554 sprintf( painCave.errMsg,
555 "SimSetup Warning: using default value of 1/2 the smallest "
556 "box length for the electrostaticCutoffRadius.\n"
557 "I hope you have a very fast processor!\n");
558 painCave.isFatal = 0;
559 simError();
560 double smallest;
561 smallest = simnfo->box_x;
562 if (simnfo->box_y <= smallest) smallest = simnfo->box_y;
563 if (simnfo->box_z <= smallest) smallest = simnfo->box_z;
564 simnfo->ecr = 0.5 * smallest;
565 } else {
566 simnfo->ecr = the_globals->getECR();
567 }
568
569 if( !the_globals->haveEST() ){
570 sprintf( painCave.errMsg,
571 "SimSetup Warning: using default value of 5%% of the "
572 "electrostaticCutoffRadius for the "
573 "electrostaticSkinThickness\n"
574 );
575 painCave.isFatal = 0;
576 simError();
577 simnfo->est = 0.05 * simnfo->ecr;
578 } else {
579 simnfo->est = the_globals->getEST();
580 }
581 }
582 }
583
584 #ifdef IS_MPI
585 strcpy( checkPointMsg, "electrostatic parameters check out" );
586 MPIcheckPoint();
587 #endif // is_mpi
588
589 if( the_globals->haveInitialConfig() ){
590
591 InitializeFromFile* fileInit;
592 #ifdef IS_MPI // is_mpi
593 if( worldRank == 0 ){
594 #endif //is_mpi
595 fileInit = new InitializeFromFile( the_globals->getInitialConfig() );
596 #ifdef IS_MPI
597 }else fileInit = new InitializeFromFile( NULL );
598 #endif
599 fileInit->read_xyz( simnfo ); // default velocities on
600
601 delete fileInit;
602 }
603 else{
604
605 #ifdef IS_MPI
606
607 // no init from bass
608
609 sprintf( painCave.errMsg,
610 "Cannot intialize a parallel simulation without an initial configuration file.\n" );
611 painCave.isFatal;
612 simError();
613
614 #else
615
616 initFromBass();
617
618
619 #endif
620 }
621
622 #ifdef IS_MPI
623 strcpy( checkPointMsg, "Successfully read in the initial configuration" );
624 MPIcheckPoint();
625 #endif // is_mpi
626
627
628
629
630
631
632
633 #ifdef IS_MPI
634 if( worldRank == 0 ){
635 #endif // is_mpi
636
637 if( the_globals->haveFinalConfig() ){
638 strcpy( simnfo->finalName, the_globals->getFinalConfig() );
639 }
640 else{
641 strcpy( simnfo->finalName, inFileName );
642 char* endTest;
643 int nameLength = strlen( simnfo->finalName );
644 endTest = &(simnfo->finalName[nameLength - 5]);
645 if( !strcmp( endTest, ".bass" ) ){
646 strcpy( endTest, ".eor" );
647 }
648 else if( !strcmp( endTest, ".BASS" ) ){
649 strcpy( endTest, ".eor" );
650 }
651 else{
652 endTest = &(simnfo->finalName[nameLength - 4]);
653 if( !strcmp( endTest, ".bss" ) ){
654 strcpy( endTest, ".eor" );
655 }
656 else if( !strcmp( endTest, ".mdl" ) ){
657 strcpy( endTest, ".eor" );
658 }
659 else{
660 strcat( simnfo->finalName, ".eor" );
661 }
662 }
663 }
664
665 // make the sample and status out names
666
667 strcpy( simnfo->sampleName, inFileName );
668 char* endTest;
669 int nameLength = strlen( simnfo->sampleName );
670 endTest = &(simnfo->sampleName[nameLength - 5]);
671 if( !strcmp( endTest, ".bass" ) ){
672 strcpy( endTest, ".dump" );
673 }
674 else if( !strcmp( endTest, ".BASS" ) ){
675 strcpy( endTest, ".dump" );
676 }
677 else{
678 endTest = &(simnfo->sampleName[nameLength - 4]);
679 if( !strcmp( endTest, ".bss" ) ){
680 strcpy( endTest, ".dump" );
681 }
682 else if( !strcmp( endTest, ".mdl" ) ){
683 strcpy( endTest, ".dump" );
684 }
685 else{
686 strcat( simnfo->sampleName, ".dump" );
687 }
688 }
689
690 strcpy( simnfo->statusName, inFileName );
691 nameLength = strlen( simnfo->statusName );
692 endTest = &(simnfo->statusName[nameLength - 5]);
693 if( !strcmp( endTest, ".bass" ) ){
694 strcpy( endTest, ".stat" );
695 }
696 else if( !strcmp( endTest, ".BASS" ) ){
697 strcpy( endTest, ".stat" );
698 }
699 else{
700 endTest = &(simnfo->statusName[nameLength - 4]);
701 if( !strcmp( endTest, ".bss" ) ){
702 strcpy( endTest, ".stat" );
703 }
704 else if( !strcmp( endTest, ".mdl" ) ){
705 strcpy( endTest, ".stat" );
706 }
707 else{
708 strcat( simnfo->statusName, ".stat" );
709 }
710 }
711
712 #ifdef IS_MPI
713 }
714 #endif // is_mpi
715
716 // set the status, sample, and themal kick times
717
718 if( the_globals->haveSampleTime() ){
719 simnfo->sampleTime = the_globals->getSampleTime();
720 simnfo->statusTime = simnfo->sampleTime;
721 simnfo->thermalTime = simnfo->sampleTime;
722 }
723 else{
724 simnfo->sampleTime = the_globals->getRunTime();
725 simnfo->statusTime = simnfo->sampleTime;
726 simnfo->thermalTime = simnfo->sampleTime;
727 }
728
729 if( the_globals->haveStatusTime() ){
730 simnfo->statusTime = the_globals->getStatusTime();
731 }
732
733 if( the_globals->haveThermalTime() ){
734 simnfo->thermalTime = the_globals->getThermalTime();
735 }
736
737 // check for the temperature set flag
738
739 if( the_globals->haveTempSet() ) simnfo->setTemp = the_globals->getTempSet();
740
741
742 // // make the longe range forces and the integrator
743
744 // new AllLong( simnfo );
745
746
747 if( !strcmp( force_field, "TraPPE_Ex" ) ){
748 new Symplectic(simnfo, the_ff, the_extendedsystem);
749 }
750 else if( !strcmp( force_field, "LJ" ) ){
751 new Verlet( *simnfo, the_ff, the_extendedsystem );
752 }
753 else {
754 std::cerr << "I'm a bug.\n";
755 fprintf( stderr, "Ima bug. stderr %s\n", force_field);
756 }
757 #ifdef IS_MPI
758 mpiSim->mpiRefresh();
759 #endif
760
761 // initialize the Fortran
762
763
764 simnfo->refreshSim();
765
766 if( !strcmp( simnfo->mixingRule, "standard") ){
767 the_ff->initForceField( LB_MIXING_RULE );
768 }
769 else if( !strcmp( simnfo->mixingRule, "explicit") ){
770 the_ff->initForceField( EXPLICIT_MIXING_RULE );
771 }
772 else{
773 sprintf( painCave.errMsg,
774 "SimSetup Error: unknown mixing rule -> \"%s\"\n",
775 simnfo->mixingRule );
776 painCave.isFatal = 1;
777 simError();
778 }
779
780
781 #ifdef IS_MPI
782 strcpy( checkPointMsg,
783 "Successfully intialized the mixingRule for Fortran." );
784 MPIcheckPoint();
785 #endif // is_mpi
786 }
787
788
789 void SimSetup::makeMolecules( void ){
790
791 int i, j, exI, exJ, tempEx, stampID, atomOffset, excludeOffset;
792 molInit info;
793 DirectionalAtom* dAtom;
794 LinkedAssign* extras;
795 LinkedAssign* current_extra;
796 AtomStamp* currentAtom;
797 BondStamp* currentBond;
798 BendStamp* currentBend;
799 TorsionStamp* currentTorsion;
800
801 bond_pair* theBonds;
802 bend_set* theBends;
803 torsion_set* theTorsions;
804
805
806 //init the forceField paramters
807
808 the_ff->readParams();
809
810
811 // init the atoms
812
813 double ux, uy, uz, u, uSqr;
814
815 atomOffset = 0;
816 excludeOffset = 0;
817 for(i=0; i<simnfo->n_mol; i++){
818
819 stampID = the_molecules[i].getStampID();
820
821 info.nAtoms = comp_stamps[stampID]->getNAtoms();
822 info.nBonds = comp_stamps[stampID]->getNBonds();
823 info.nBends = comp_stamps[stampID]->getNBends();
824 info.nTorsions = comp_stamps[stampID]->getNTorsions();
825 info.nExcludes = info.nBonds + info.nBends + info.nTorsions;
826
827 info.myAtoms = &the_atoms[atomOffset];
828 info.myExcludes = &the_excludes[excludeOffset];
829 info.myBonds = new Bond*[info.nBonds];
830 info.myBends = new Bend*[info.nBends];
831 info.myTorsions = new Torsion*[info.nTorsions];
832
833 theBonds = new bond_pair[info.nBonds];
834 theBends = new bend_set[info.nBends];
835 theTorsions = new torsion_set[info.nTorsions];
836
837 // make the Atoms
838
839 for(j=0; j<info.nAtoms; j++){
840
841 currentAtom = comp_stamps[stampID]->getAtom( j );
842 if( currentAtom->haveOrientation() ){
843
844 dAtom = new DirectionalAtom(j + atomOffset);
845 simnfo->n_oriented++;
846 info.myAtoms[j] = dAtom;
847
848 ux = currentAtom->getOrntX();
849 uy = currentAtom->getOrntY();
850 uz = currentAtom->getOrntZ();
851
852 uSqr = (ux * ux) + (uy * uy) + (uz * uz);
853
854 u = sqrt( uSqr );
855 ux = ux / u;
856 uy = uy / u;
857 uz = uz / u;
858
859 dAtom->setSUx( ux );
860 dAtom->setSUy( uy );
861 dAtom->setSUz( uz );
862 }
863 else{
864 info.myAtoms[j] = new GeneralAtom(j + atomOffset);
865 }
866 info.myAtoms[j]->setType( currentAtom->getType() );
867
868 #ifdef IS_MPI
869
870 info.myAtoms[j]->setGlobalIndex( globalIndex[j+atomOffset] );
871
872 #endif // is_mpi
873 }
874
875 // make the bonds
876 for(j=0; j<info.nBonds; j++){
877
878 currentBond = comp_stamps[stampID]->getBond( j );
879 theBonds[j].a = currentBond->getA() + atomOffset;
880 theBonds[j].b = currentBond->getB() + atomOffset;
881
882 exI = theBonds[j].a;
883 exJ = theBonds[j].b;
884
885 // exclude_I must always be the smaller of the pair
886 if( exI > exJ ){
887 tempEx = exI;
888 exI = exJ;
889 exJ = tempEx;
890 }
891 #ifdef IS_MPI
892 tempEx = exI;
893 exI = the_atoms[tempEx]->getGlobalIndex() + 1;
894 tempEx = exJ;
895 exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
896
897 the_excludes[j+excludeOffset]->setPair( exI, exJ );
898 #else // isn't MPI
899
900 the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
901 #endif //is_mpi
902 }
903 excludeOffset += info.nBonds;
904
905 //make the bends
906 for(j=0; j<info.nBends; j++){
907
908 currentBend = comp_stamps[stampID]->getBend( j );
909 theBends[j].a = currentBend->getA() + atomOffset;
910 theBends[j].b = currentBend->getB() + atomOffset;
911 theBends[j].c = currentBend->getC() + atomOffset;
912
913 if( currentBend->haveExtras() ){
914
915 extras = currentBend->getExtras();
916 current_extra = extras;
917
918 while( current_extra != NULL ){
919 if( !strcmp( current_extra->getlhs(), "ghostVectorSource" )){
920
921 switch( current_extra->getType() ){
922
923 case 0:
924 theBends[j].ghost =
925 current_extra->getInt() + atomOffset;
926 theBends[j].isGhost = 1;
927 break;
928
929 case 1:
930 theBends[j].ghost =
931 (int)current_extra->getDouble() + atomOffset;
932 theBends[j].isGhost = 1;
933 break;
934
935 default:
936 sprintf( painCave.errMsg,
937 "SimSetup Error: ghostVectorSource was neither a "
938 "double nor an int.\n"
939 "-->Bend[%d] in %s\n",
940 j, comp_stamps[stampID]->getID() );
941 painCave.isFatal = 1;
942 simError();
943 }
944 }
945
946 else{
947
948 sprintf( painCave.errMsg,
949 "SimSetup Error: unhandled bend assignment:\n"
950 " -->%s in Bend[%d] in %s\n",
951 current_extra->getlhs(),
952 j, comp_stamps[stampID]->getID() );
953 painCave.isFatal = 1;
954 simError();
955 }
956
957 current_extra = current_extra->getNext();
958 }
959 }
960
961 if( !theBends[j].isGhost ){
962
963 exI = theBends[j].a;
964 exJ = theBends[j].c;
965 }
966 else{
967
968 exI = theBends[j].a;
969 exJ = theBends[j].b;
970 }
971
972 // exclude_I must always be the smaller of the pair
973 if( exI > exJ ){
974 tempEx = exI;
975 exI = exJ;
976 exJ = tempEx;
977 }
978 #ifdef IS_MPI
979 tempEx = exI;
980 exI = the_atoms[tempEx]->getGlobalIndex() + 1;
981 tempEx = exJ;
982 exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
983
984 the_excludes[j+excludeOffset]->setPair( exI, exJ );
985 #else // isn't MPI
986 the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
987 #endif //is_mpi
988 }
989 excludeOffset += info.nBends;
990
991 for(j=0; j<info.nTorsions; j++){
992
993 currentTorsion = comp_stamps[stampID]->getTorsion( j );
994 theTorsions[j].a = currentTorsion->getA() + atomOffset;
995 theTorsions[j].b = currentTorsion->getB() + atomOffset;
996 theTorsions[j].c = currentTorsion->getC() + atomOffset;
997 theTorsions[j].d = currentTorsion->getD() + atomOffset;
998
999 exI = theTorsions[j].a;
1000 exJ = theTorsions[j].d;
1001
1002 // exclude_I must always be the smaller of the pair
1003 if( exI > exJ ){
1004 tempEx = exI;
1005 exI = exJ;
1006 exJ = tempEx;
1007 }
1008 #ifdef IS_MPI
1009 tempEx = exI;
1010 exI = the_atoms[tempEx]->getGlobalIndex() + 1;
1011 tempEx = exJ;
1012 exJ = the_atoms[tempEx]->getGlobalIndex() + 1;
1013
1014 the_excludes[j+excludeOffset]->setPair( exI, exJ );
1015 #else // isn't MPI
1016 the_excludes[j+excludeOffset]->setPair( (exI+1), (exJ+1) );
1017 #endif //is_mpi
1018 }
1019 excludeOffset += info.nTorsions;
1020
1021
1022 // send the arrays off to the forceField for init.
1023
1024 the_ff->initializeAtoms( info.nAtoms, info.myAtoms );
1025 the_ff->initializeBonds( info.nBonds, info.myBonds, theBonds );
1026 the_ff->initializeBends( info.nBends, info.myBends, theBends );
1027 the_ff->initializeTorsions( info.nTorsions, info.myTorsions, theTorsions );
1028
1029
1030 the_molecules[i].initialize( info );
1031
1032
1033 atomOffset += info.nAtoms;
1034 delete[] theBonds;
1035 delete[] theBends;
1036 delete[] theTorsions;
1037 }
1038
1039 #ifdef IS_MPI
1040 sprintf( checkPointMsg, "all molecules initialized succesfully" );
1041 MPIcheckPoint();
1042 #endif // is_mpi
1043
1044 // clean up the forcefield
1045 the_ff->calcRcut();
1046 the_ff->cleanMe();
1047
1048 }
1049
1050 void SimSetup::initFromBass( void ){
1051
1052 int i, j, k;
1053 int n_cells;
1054 double cellx, celly, cellz;
1055 double temp1, temp2, temp3;
1056 int n_per_extra;
1057 int n_extra;
1058 int have_extra, done;
1059
1060 temp1 = (double)tot_nmol / 4.0;
1061 temp2 = pow( temp1, ( 1.0 / 3.0 ) );
1062 temp3 = ceil( temp2 );
1063
1064 have_extra =0;
1065 if( temp2 < temp3 ){ // we have a non-complete lattice
1066 have_extra =1;
1067
1068 n_cells = (int)temp3 - 1;
1069 cellx = simnfo->box_x / temp3;
1070 celly = simnfo->box_y / temp3;
1071 cellz = simnfo->box_z / temp3;
1072 n_extra = tot_nmol - ( 4 * n_cells * n_cells * n_cells );
1073 temp1 = ((double)n_extra) / ( pow( temp3, 3.0 ) - pow( n_cells, 3.0 ) );
1074 n_per_extra = (int)ceil( temp1 );
1075
1076 if( n_per_extra > 4){
1077 sprintf( painCave.errMsg,
1078 "SimSetup error. There has been an error in constructing"
1079 " the non-complete lattice.\n" );
1080 painCave.isFatal = 1;
1081 simError();
1082 }
1083 }
1084 else{
1085 n_cells = (int)temp3;
1086 cellx = simnfo->box_x / temp3;
1087 celly = simnfo->box_y / temp3;
1088 cellz = simnfo->box_z / temp3;
1089 }
1090
1091 current_mol = 0;
1092 current_comp_mol = 0;
1093 current_comp = 0;
1094 current_atom_ndx = 0;
1095
1096 for( i=0; i < n_cells ; i++ ){
1097 for( j=0; j < n_cells; j++ ){
1098 for( k=0; k < n_cells; k++ ){
1099
1100 makeElement( i * cellx,
1101 j * celly,
1102 k * cellz );
1103
1104 makeElement( i * cellx + 0.5 * cellx,
1105 j * celly + 0.5 * celly,
1106 k * cellz );
1107
1108 makeElement( i * cellx,
1109 j * celly + 0.5 * celly,
1110 k * cellz + 0.5 * cellz );
1111
1112 makeElement( i * cellx + 0.5 * cellx,
1113 j * celly,
1114 k * cellz + 0.5 * cellz );
1115 }
1116 }
1117 }
1118
1119 if( have_extra ){
1120 done = 0;
1121
1122 int start_ndx;
1123 for( i=0; i < (n_cells+1) && !done; i++ ){
1124 for( j=0; j < (n_cells+1) && !done; j++ ){
1125
1126 if( i < n_cells ){
1127
1128 if( j < n_cells ){
1129 start_ndx = n_cells;
1130 }
1131 else start_ndx = 0;
1132 }
1133 else start_ndx = 0;
1134
1135 for( k=start_ndx; k < (n_cells+1) && !done; k++ ){
1136
1137 makeElement( i * cellx,
1138 j * celly,
1139 k * cellz );
1140 done = ( current_mol >= tot_nmol );
1141
1142 if( !done && n_per_extra > 1 ){
1143 makeElement( i * cellx + 0.5 * cellx,
1144 j * celly + 0.5 * celly,
1145 k * cellz );
1146 done = ( current_mol >= tot_nmol );
1147 }
1148
1149 if( !done && n_per_extra > 2){
1150 makeElement( i * cellx,
1151 j * celly + 0.5 * celly,
1152 k * cellz + 0.5 * cellz );
1153 done = ( current_mol >= tot_nmol );
1154 }
1155
1156 if( !done && n_per_extra > 3){
1157 makeElement( i * cellx + 0.5 * cellx,
1158 j * celly,
1159 k * cellz + 0.5 * cellz );
1160 done = ( current_mol >= tot_nmol );
1161 }
1162 }
1163 }
1164 }
1165 }
1166
1167
1168 for( i=0; i<simnfo->n_atoms; i++ ){
1169 simnfo->atoms[i]->set_vx( 0.0 );
1170 simnfo->atoms[i]->set_vy( 0.0 );
1171 simnfo->atoms[i]->set_vz( 0.0 );
1172 }
1173 }
1174
1175 void SimSetup::makeElement( double x, double y, double z ){
1176
1177 int k;
1178 AtomStamp* current_atom;
1179 DirectionalAtom* dAtom;
1180 double rotMat[3][3];
1181
1182 for( k=0; k<comp_stamps[current_comp]->getNAtoms(); k++ ){
1183
1184 current_atom = comp_stamps[current_comp]->getAtom( k );
1185 if( !current_atom->havePosition() ){
1186 sprintf( painCave.errMsg,
1187 "SimSetup:initFromBass error.\n"
1188 "\tComponent %s, atom %s does not have a position specified.\n"
1189 "\tThe initialization routine is unable to give a start"
1190 " position.\n",
1191 comp_stamps[current_comp]->getID(),
1192 current_atom->getType() );
1193 painCave.isFatal = 1;
1194 simError();
1195 }
1196
1197 the_atoms[current_atom_ndx]->setX( x + current_atom->getPosX() );
1198 the_atoms[current_atom_ndx]->setY( y + current_atom->getPosY() );
1199 the_atoms[current_atom_ndx]->setZ( z + current_atom->getPosZ() );
1200
1201 if( the_atoms[current_atom_ndx]->isDirectional() ){
1202
1203 dAtom = (DirectionalAtom *)the_atoms[current_atom_ndx];
1204
1205 rotMat[0][0] = 1.0;
1206 rotMat[0][1] = 0.0;
1207 rotMat[0][2] = 0.0;
1208
1209 rotMat[1][0] = 0.0;
1210 rotMat[1][1] = 1.0;
1211 rotMat[1][2] = 0.0;
1212
1213 rotMat[2][0] = 0.0;
1214 rotMat[2][1] = 0.0;
1215 rotMat[2][2] = 1.0;
1216
1217 dAtom->setA( rotMat );
1218 }
1219
1220 current_atom_ndx++;
1221 }
1222
1223 current_mol++;
1224 current_comp_mol++;
1225
1226 if( current_comp_mol >= components_nmol[current_comp] ){
1227
1228 current_comp_mol = 0;
1229 current_comp++;
1230 }
1231 }