ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/SimSetup.cpp
Revision: 422
Committed: Thu Mar 27 19:21:42 2003 UTC (21 years, 3 months ago) by mmeineke
File size: 27745 byte(s)
Log Message:
finished updating SimSetup to initialize and use the new MPI division of labour, and Molecule class

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