ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/interface_implementation/SimSetup.cpp
Revision: 194
Committed: Wed Dec 4 21:19:38 2002 UTC (21 years, 6 months ago) by chuckv
File size: 18837 byte(s)
Log Message:
First addition of mpiDivideLabor to split mpi simulation among processors.

File Contents

# User Rev Content
1 mmeineke 10 #include <cstdlib>
2     #include <iostream>
3     #include <cmath>
4    
5     #include "SimSetup.hpp"
6     #include "parse_me.h"
7     #include "LRI.hpp"
8     #include "Integrator.hpp"
9 mmeineke 176 #include "simError.h"
10 mmeineke 144
11 chuckv 131 #ifdef IS_MPI
12 chuckv 139 #include "mpiBASS.h"
13 chuckv 131 #include "bassDiag.hpp"
14     #endif
15 mmeineke 10
16     SimSetup::SimSetup(){
17     stamps = new MakeStamps();
18     globals = new Globals();
19 mmeineke 164
20     #ifdef IS_MPI
21     strcpy( checkPointMsg, "SimSetup creation successful" );
22     MPIcheckPoint();
23 mmeineke 176 #endif // IS_MPI
24 mmeineke 10 }
25    
26     SimSetup::~SimSetup(){
27     delete stamps;
28     delete globals;
29     }
30    
31     void SimSetup::parseFile( char* fileName ){
32    
33 chuckv 131 #ifdef IS_MPI
34 mmeineke 164 if( worldRank == 0 ){
35     #endif // is_mpi
36    
37     inFileName = fileName;
38     set_interface_stamps( stamps, globals );
39    
40     #ifdef IS_MPI
41     mpiEventInit();
42 chuckv 124 #endif
43 mmeineke 164
44     yacc_BASS( fileName );
45    
46 chuckv 131 #ifdef IS_MPI
47 mmeineke 164 throwMPIEvent(NULL);
48     }
49 mmeineke 176 else receiveParse();
50 chuckv 124 #endif
51    
52 mmeineke 10 }
53    
54 chuckv 131 #ifdef IS_MPI
55 chuckv 124 void SimSetup::receiveParse(void){
56    
57     set_interface_stamps( stamps, globals );
58     mpiEventInit();
59 mmeineke 164 MPIcheckPoint();
60 chuckv 124 mpiEventLoop();
61    
62     }
63    
64 chuckv 131
65 chuckv 128 void SimSetup::testMe(void){
66     bassDiag* dumpMe = new bassDiag(globals,stamps);
67     dumpMe->dumpStamps();
68     delete dumpMe;
69     }
70 chuckv 131 #endif
71 mmeineke 176
72 mmeineke 10 void SimSetup::createSim( void ){
73    
74     MakeStamps *the_stamps;
75     Globals* the_globals;
76     int i;
77    
78     // get the stamps and globals;
79     the_stamps = stamps;
80     the_globals = globals;
81    
82     // set the easy ones first
83     simnfo->target_temp = the_globals->getTargetTemp();
84     simnfo->dt = the_globals->getDt();
85     simnfo->run_time = the_globals->getRunTime();
86    
87     // get the ones we know are there, yet still may need some work.
88     n_components = the_globals->getNComponents();
89     strcpy( force_field, the_globals->getForceField() );
90     strcpy( ensemble, the_globals->getEnsemble() );
91 chuckv 124
92 mmeineke 10 if( !strcmp( force_field, "TraPPE" ) ) the_ff = new TraPPEFF();
93     else if( !strcmp( force_field, "DipoleTest" ) ) the_ff = new DipoleTestFF();
94     else if( !strcmp( force_field, "TraPPE_Ex" ) ) the_ff = new TraPPE_ExFF();
95     else{
96 mmeineke 176 sprintf( painCave.errMsg,
97     "SimSetup Error. Unrecognized force field -> %s\n",
98     force_field );
99     painCave.isFatal = 1;
100     simError();
101 mmeineke 10 }
102    
103 mmeineke 176 #ifdef IS_MPI
104     strcpy( checkPointMsg, "ForceField creation successful" );
105     MPIcheckPoint();
106     #endif // is_mpi
107    
108 mmeineke 10 // get the components and calculate the tot_nMol and indvidual n_mol
109     the_components = the_globals->getComponents();
110     components_nmol = new int[n_components];
111     comp_stamps = new MoleculeStamp*[n_components];
112 chuckv 124
113 mmeineke 10 if( !the_globals->haveNMol() ){
114 chuckv 124 // we don't have the total number of molecules, so we assume it is
115 mmeineke 10 // given in each component
116    
117     tot_nmol = 0;
118     for( i=0; i<n_components; i++ ){
119 chuckv 124
120 mmeineke 10 if( !the_components[i]->haveNMol() ){
121     // we have a problem
122 mmeineke 189 sprintf( painCave.errMsg,
123     "SimSetup Error. No global NMol or component NMol"
124     " given. Cannot calculate the number of atoms.\n" );
125     painCave.isFatal = 1;
126     simError();
127 mmeineke 10 }
128    
129     tot_nmol += the_components[i]->getNMol();
130     components_nmol[i] = the_components[i]->getNMol();
131     }
132     }
133     else{
134 mmeineke 189 sprintf( painCave.errMsg,
135     "SimSetup error.\n"
136     "\tSorry, the ability to specify total"
137     " nMols and then give molfractions in the components\n"
138     "\tis not currently supported."
139     " Please give nMol in the components.\n" );
140     painCave.isFatal = 1;
141     simError();
142    
143    
144     // tot_nmol = the_globals->getNMol();
145    
146     // //we have the total number of molecules, now we check for molfractions
147     // for( i=0; i<n_components; i++ ){
148    
149     // if( !the_components[i]->haveMolFraction() ){
150    
151     // if( !the_components[i]->haveNMol() ){
152     // //we have a problem
153     // std::cerr << "SimSetup error. Neither molFraction nor "
154     // << " nMol was given in component
155    
156     }
157 chuckv 124
158 mmeineke 189 #ifdef IS_MPI
159     strcpy( checkPointMsg, "Have the number of components" );
160     MPIcheckPoint();
161     #endif // is_mpi
162 chuckv 124
163 mmeineke 10 // make an array of molecule stamps that match the components used.
164    
165     for( i=0; i<n_components; i++ ){
166    
167 chuckv 124 comp_stamps[i] =
168 mmeineke 10 the_stamps->getMolecule( the_components[i]->getType() );
169     }
170    
171    
172 chuckv 124
173 mmeineke 10 // caclulate the number of atoms, bonds, bends and torsions
174    
175     tot_atoms = 0;
176     tot_bonds = 0;
177     tot_bends = 0;
178     tot_torsions = 0;
179     for( i=0; i<n_components; i++ ){
180 chuckv 124
181 mmeineke 10 tot_atoms += components_nmol[i] * comp_stamps[i]->getNAtoms();
182     tot_bonds += components_nmol[i] * comp_stamps[i]->getNBonds();
183     tot_bends += components_nmol[i] * comp_stamps[i]->getNBends();
184     tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions();
185     }
186 chuckv 124
187 mmeineke 10 tot_SRI = tot_bonds + tot_bends + tot_torsions;
188 chuckv 124
189 mmeineke 10 simnfo->n_atoms = tot_atoms;
190     simnfo->n_bonds = tot_bonds;
191     simnfo->n_bends = tot_bends;
192     simnfo->n_torsions = tot_torsions;
193     simnfo->n_SRI = tot_SRI;
194    
195 chuckv 194 // divide the molecules among processors here.
196    
197    
198 mmeineke 10 // create the atom and short range interaction arrays
199 chuckv 124
200 mmeineke 184 Atom::createArrays(tot_atoms);
201 mmeineke 10 the_atoms = new Atom*[tot_atoms];
202 mmeineke 113 the_molecules = new Molecule[tot_nmol];
203 chuckv 124
204    
205 mmeineke 10 if( tot_SRI ){
206     the_sris = new SRI*[tot_SRI];
207     the_excludes = new ex_pair[tot_SRI];
208     }
209    
210     // set the arrays into the SimInfo object
211    
212     simnfo->atoms = the_atoms;
213     simnfo->sr_interactions = the_sris;
214     simnfo->n_exclude = tot_SRI;
215     simnfo->excludes = the_excludes;
216    
217 chuckv 124
218 mmeineke 10 // initialize the arrays
219 chuckv 124
220 mmeineke 10 the_ff->setSimInfo( simnfo );
221 chuckv 124
222 mmeineke 10 makeAtoms();
223    
224     if( tot_bonds ){
225     makeBonds();
226     }
227    
228     if( tot_bends ){
229     makeBends();
230     }
231    
232     if( tot_torsions ){
233     makeTorsions();
234     }
235    
236     // makeMolecules();
237    
238     // get some of the tricky things that may still be in the globals
239    
240     if( simnfo->n_dipoles ){
241    
242     if( !the_globals->haveRRF() ){
243 mmeineke 189 sprintf( painCave.errMsg,
244     "SimSetup Error, system has dipoles, but no rRF was set.\n");
245     painCave.isFatal = 1;
246     simError();
247 mmeineke 10 }
248     if( !the_globals->haveDielectric() ){
249 mmeineke 189 sprintf( painCave.errMsg,
250     "SimSetup Error, system has dipoles, but no"
251     " dielectric was set.\n" );
252     painCave.isFatal = 1;
253     simError();
254 mmeineke 10 }
255    
256     simnfo->rRF = the_globals->getRRF();
257     simnfo->dielectric = the_globals->getDielectric();
258     }
259    
260 mmeineke 189 #ifdef IS_MPI
261     strcpy( checkPointMsg, "rRf and dielectric check out" );
262     MPIcheckPoint();
263     #endif // is_mpi
264    
265 mmeineke 10 if( the_globals->haveBox() ){
266     simnfo->box_x = the_globals->getBox();
267     simnfo->box_y = the_globals->getBox();
268     simnfo->box_z = the_globals->getBox();
269     }
270     else if( the_globals->haveDensity() ){
271 chuckv 124
272 mmeineke 10 double vol;
273     vol = (double)tot_nmol / the_globals->getDensity();
274     simnfo->box_x = pow( vol, ( 1.0 / 3.0 ) );
275     simnfo->box_y = simnfo->box_x;
276     simnfo->box_z = simnfo->box_x;
277     }
278     else{
279     if( !the_globals->haveBoxX() ){
280 mmeineke 189 sprintf( painCave.errMsg,
281     "SimSetup error, no periodic BoxX size given.\n" );
282     painCave.isFatal = 1;
283     simError();
284 mmeineke 10 }
285     simnfo->box_x = the_globals->getBoxX();
286    
287     if( !the_globals->haveBoxY() ){
288 mmeineke 189 sprintf( painCave.errMsg,
289     "SimSetup error, no periodic BoxY size given.\n" );
290     painCave.isFatal = 1;
291     simError();
292 mmeineke 10 }
293     simnfo->box_y = the_globals->getBoxY();
294    
295     if( !the_globals->haveBoxZ() ){
296 mmeineke 189 sprintf( painCave.errMsg,
297     "SimSetup error, no periodic BoxZ size given.\n" );
298     painCave.isFatal = 1;
299     simError();
300 mmeineke 10 }
301     simnfo->box_z = the_globals->getBoxZ();
302     }
303    
304 mmeineke 189 #ifdef IS_MPI
305     strcpy( checkPointMsg, "Box size set up" );
306     MPIcheckPoint();
307     #endif // is_mpi
308 chuckv 124
309 mmeineke 189
310    
311 chuckv 124 // if( the_globals->haveInitialConfig() ){
312     // InitializeFromFile* fileInit;
313     // fileInit = new InitializeFromFile( the_globals->getInitialConfig() );
314    
315     // fileInit->read_xyz( simnfo ); // default velocities on
316    
317     // delete fileInit;
318     // }
319     // else{
320    
321 mmeineke 189 initFromBass();
322    
323     #ifdef IS_MPI
324     strcpy( checkPointMsg, "initFromBass successfully created the lattice" );
325     MPIcheckPoint();
326     #endif // is_mpi
327 mmeineke 10
328    
329 mmeineke 189
330    
331    
332     // }
333    
334 mmeineke 184 #ifdef IS_MPI
335 mmeineke 189 if( worldRank == 0 ){
336 mmeineke 184 #endif // is_mpi
337 mmeineke 189
338     if( the_globals->haveFinalConfig() ){
339     strcpy( simnfo->finalName, the_globals->getFinalConfig() );
340     }
341     else{
342     strcpy( simnfo->finalName, inFileName );
343     char* endTest;
344     int nameLength = strlen( simnfo->finalName );
345     endTest = &(simnfo->finalName[nameLength - 5]);
346     if( !strcmp( endTest, ".bass" ) ){
347     strcpy( endTest, ".eor" );
348 mmeineke 184 }
349 mmeineke 189 else if( !strcmp( endTest, ".BASS" ) ){
350     strcpy( endTest, ".eor" );
351     }
352 mmeineke 184 else{
353 mmeineke 189 endTest = &(simnfo->finalName[nameLength - 4]);
354     if( !strcmp( endTest, ".bss" ) ){
355 mmeineke 184 strcpy( endTest, ".eor" );
356     }
357 mmeineke 189 else if( !strcmp( endTest, ".mdl" ) ){
358 mmeineke 184 strcpy( endTest, ".eor" );
359     }
360     else{
361 mmeineke 189 strcat( simnfo->finalName, ".eor" );
362 mmeineke 184 }
363     }
364 mmeineke 189 }
365    
366     // make the sample and status out names
367    
368     strcpy( simnfo->sampleName, inFileName );
369     char* endTest;
370     int nameLength = strlen( simnfo->sampleName );
371     endTest = &(simnfo->sampleName[nameLength - 5]);
372     if( !strcmp( endTest, ".bass" ) ){
373     strcpy( endTest, ".dump" );
374     }
375     else if( !strcmp( endTest, ".BASS" ) ){
376     strcpy( endTest, ".dump" );
377     }
378     else{
379     endTest = &(simnfo->sampleName[nameLength - 4]);
380     if( !strcmp( endTest, ".bss" ) ){
381 mmeineke 184 strcpy( endTest, ".dump" );
382     }
383 mmeineke 189 else if( !strcmp( endTest, ".mdl" ) ){
384 mmeineke 184 strcpy( endTest, ".dump" );
385     }
386     else{
387 mmeineke 189 strcat( simnfo->sampleName, ".dump" );
388 mmeineke 184 }
389 mmeineke 189 }
390    
391     strcpy( simnfo->statusName, inFileName );
392     nameLength = strlen( simnfo->statusName );
393     endTest = &(simnfo->statusName[nameLength - 5]);
394     if( !strcmp( endTest, ".bass" ) ){
395     strcpy( endTest, ".stat" );
396     }
397     else if( !strcmp( endTest, ".BASS" ) ){
398     strcpy( endTest, ".stat" );
399     }
400     else{
401     endTest = &(simnfo->statusName[nameLength - 4]);
402     if( !strcmp( endTest, ".bss" ) ){
403 mmeineke 184 strcpy( endTest, ".stat" );
404     }
405 mmeineke 189 else if( !strcmp( endTest, ".mdl" ) ){
406 mmeineke 184 strcpy( endTest, ".stat" );
407     }
408     else{
409 mmeineke 189 strcat( simnfo->statusName, ".stat" );
410 mmeineke 184 }
411 mmeineke 189 }
412    
413 mmeineke 184 #ifdef IS_MPI
414 mmeineke 189 }
415 mmeineke 184 #endif // is_mpi
416 mmeineke 189
417 mmeineke 10 // set the status, sample, and themal kick times
418 mmeineke 189
419 mmeineke 10 if( the_globals->haveSampleTime() ){
420 chuckv 124 simnfo->sampleTime = the_globals->getSampleTime();
421 mmeineke 10 simnfo->statusTime = simnfo->sampleTime;
422     simnfo->thermalTime = simnfo->sampleTime;
423     }
424     else{
425 chuckv 124 simnfo->sampleTime = the_globals->getRunTime();
426 mmeineke 10 simnfo->statusTime = simnfo->sampleTime;
427     simnfo->thermalTime = simnfo->sampleTime;
428     }
429    
430     if( the_globals->haveStatusTime() ){
431     simnfo->statusTime = the_globals->getStatusTime();
432     }
433    
434     if( the_globals->haveThermalTime() ){
435     simnfo->thermalTime = the_globals->getThermalTime();
436     }
437    
438     // check for the temperature set flag
439    
440     if( the_globals->haveTempSet() ) simnfo->setTemp = the_globals->getTempSet();
441 chuckv 124
442    
443 mmeineke 10 // make the longe range forces and the integrator
444 chuckv 124
445 mmeineke 10 new AllLong( simnfo );
446 chuckv 124
447 mmeineke 10 if( !strcmp( force_field, "TraPPE" ) ) new Verlet( *simnfo );
448     if( !strcmp( force_field, "DipoleTest" ) ) new Symplectic( simnfo );
449     if( !strcmp( force_field, "TraPPE_Ex" ) ) new Symplectic( simnfo );
450     }
451    
452     void SimSetup::makeAtoms( void ){
453 chuckv 124
454 mmeineke 10 int i, j, k, index;
455     double ux, uy, uz, uSqr, u;
456     AtomStamp* current_atom;
457     DirectionalAtom* dAtom;
458 mmeineke 117 int molIndex, molStart, molEnd, nMemb;
459 mmeineke 10
460 chuckv 124
461 mmeineke 117 molIndex = 0;
462 mmeineke 10 index = 0;
463     for( i=0; i<n_components; i++ ){
464 chuckv 124
465 mmeineke 10 for( j=0; j<components_nmol[i]; j++ ){
466 chuckv 124
467 mmeineke 117 molStart = index;
468     nMemb = comp_stamps[i]->getNAtoms();
469 mmeineke 10 for( k=0; k<comp_stamps[i]->getNAtoms(); k++ ){
470 chuckv 124
471 mmeineke 10 current_atom = comp_stamps[i]->getAtom( k );
472 chuckv 124 if( current_atom->haveOrientation() ){
473 mmeineke 10
474 mmeineke 145 dAtom = new DirectionalAtom(index);
475 mmeineke 10 simnfo->n_oriented++;
476     the_atoms[index] = dAtom;
477 chuckv 124
478 mmeineke 10 ux = current_atom->getOrntX();
479     uy = current_atom->getOrntY();
480     uz = current_atom->getOrntZ();
481 chuckv 124
482 mmeineke 10 uSqr = (ux * ux) + (uy * uy) + (uz * uz);
483 chuckv 124
484 mmeineke 10 u = sqrt( uSqr );
485     ux = ux / u;
486     uy = uy / u;
487     uz = uz / u;
488 chuckv 124
489 mmeineke 10 dAtom->setSUx( ux );
490     dAtom->setSUy( uy );
491     dAtom->setSUz( uz );
492     }
493     else{
494 mmeineke 145 the_atoms[index] = new GeneralAtom(index);
495 mmeineke 10 }
496     the_atoms[index]->setType( current_atom->getType() );
497     the_atoms[index]->setIndex( index );
498 chuckv 124
499 mmeineke 10 // increment the index and repeat;
500     index++;
501     }
502 chuckv 124
503 mmeineke 117 molEnd = index -1;
504     the_molecules[molIndex].setNMembers( nMemb );
505     the_molecules[molIndex].setStartAtom( molStart );
506     the_molecules[molIndex].setEndAtom( molEnd );
507     molIndex++;
508    
509 mmeineke 10 }
510     }
511 chuckv 124
512 mmeineke 10 the_ff->initializeAtoms();
513     }
514    
515     void SimSetup::makeBonds( void ){
516    
517     int i, j, k, index, offset;
518     bond_pair* the_bonds;
519     BondStamp* current_bond;
520    
521     the_bonds = new bond_pair[tot_bonds];
522     index = 0;
523     offset = 0;
524     for( i=0; i<n_components; i++ ){
525 chuckv 124
526 mmeineke 10 for( j=0; j<components_nmol[i]; j++ ){
527 chuckv 124
528 mmeineke 10 for( k=0; k<comp_stamps[i]->getNBonds(); k++ ){
529 chuckv 124
530 mmeineke 10 current_bond = comp_stamps[i]->getBond( k );
531     the_bonds[index].a = current_bond->getA() + offset;
532     the_bonds[index].b = current_bond->getB() + offset;
533    
534     the_excludes[index].i = the_bonds[index].a;
535     the_excludes[index].j = the_bonds[index].b;
536    
537     // increment the index and repeat;
538     index++;
539     }
540     offset += comp_stamps[i]->getNAtoms();
541     }
542     }
543 chuckv 124
544 mmeineke 10 the_ff->initializeBonds( the_bonds );
545     }
546    
547     void SimSetup::makeBends( void ){
548    
549     int i, j, k, index, offset;
550     bend_set* the_bends;
551     BendStamp* current_bend;
552    
553     the_bends = new bend_set[tot_bends];
554     index = 0;
555     offset = 0;
556     for( i=0; i<n_components; i++ ){
557 chuckv 124
558 mmeineke 10 for( j=0; j<components_nmol[i]; j++ ){
559 chuckv 124
560 mmeineke 10 for( k=0; k<comp_stamps[i]->getNBends(); k++ ){
561 chuckv 124
562 mmeineke 10 current_bend = comp_stamps[i]->getBend( k );
563     the_bends[index].a = current_bend->getA() + offset;
564     the_bends[index].b = current_bend->getB() + offset;
565     the_bends[index].c = current_bend->getC() + offset;
566    
567     the_excludes[index + tot_bonds].i = the_bends[index].a;
568     the_excludes[index + tot_bonds].j = the_bends[index].c;
569    
570     // increment the index and repeat;
571     index++;
572     }
573     offset += comp_stamps[i]->getNAtoms();
574     }
575     }
576 chuckv 124
577 mmeineke 10 the_ff->initializeBends( the_bends );
578     }
579    
580     void SimSetup::makeTorsions( void ){
581    
582     int i, j, k, index, offset;
583     torsion_set* the_torsions;
584     TorsionStamp* current_torsion;
585    
586     the_torsions = new torsion_set[tot_torsions];
587     index = 0;
588     offset = 0;
589     for( i=0; i<n_components; i++ ){
590 chuckv 124
591 mmeineke 10 for( j=0; j<components_nmol[i]; j++ ){
592 chuckv 124
593 mmeineke 10 for( k=0; k<comp_stamps[i]->getNTorsions(); k++ ){
594 chuckv 124
595 mmeineke 10 current_torsion = comp_stamps[i]->getTorsion( k );
596     the_torsions[index].a = current_torsion->getA() + offset;
597     the_torsions[index].b = current_torsion->getB() + offset;
598     the_torsions[index].c = current_torsion->getC() + offset;
599     the_torsions[index].d = current_torsion->getD() + offset;
600    
601     the_excludes[index + tot_bonds + tot_bends].i = the_torsions[index].a;
602     the_excludes[index + tot_bonds + tot_bends].j = the_torsions[index].d;
603    
604     // increment the index and repeat;
605     index++;
606     }
607     offset += comp_stamps[i]->getNAtoms();
608     }
609     }
610 chuckv 124
611 mmeineke 10 the_ff->initializeTorsions( the_torsions );
612     }
613    
614     void SimSetup::initFromBass( void ){
615    
616     int i, j, k;
617     int n_cells;
618     double cellx, celly, cellz;
619     double temp1, temp2, temp3;
620     int n_per_extra;
621     int n_extra;
622     int have_extra, done;
623    
624     temp1 = (double)tot_nmol / 4.0;
625     temp2 = pow( temp1, ( 1.0 / 3.0 ) );
626     temp3 = ceil( temp2 );
627    
628     have_extra =0;
629     if( temp2 < temp3 ){ // we have a non-complete lattice
630     have_extra =1;
631    
632     n_cells = (int)temp3 - 1;
633     cellx = simnfo->box_x / temp3;
634     celly = simnfo->box_y / temp3;
635     cellz = simnfo->box_z / temp3;
636     n_extra = tot_nmol - ( 4 * n_cells * n_cells * n_cells );
637     temp1 = ((double)n_extra) / ( pow( temp3, 3.0 ) - pow( n_cells, 3.0 ) );
638     n_per_extra = (int)ceil( temp1 );
639    
640     if( n_per_extra > 4){
641 mmeineke 189 sprintf( painCave.errMsg,
642     "SimSetup error. There has been an error in constructing"
643     " the non-complete lattice.\n" );
644     painCave.isFatal = 1;
645     simError();
646 mmeineke 10 }
647     }
648     else{
649     n_cells = (int)temp3;
650     cellx = simnfo->box_x / temp3;
651     celly = simnfo->box_y / temp3;
652     cellz = simnfo->box_z / temp3;
653     }
654 chuckv 124
655 mmeineke 10 current_mol = 0;
656     current_comp_mol = 0;
657     current_comp = 0;
658     current_atom_ndx = 0;
659 chuckv 124
660 mmeineke 10 for( i=0; i < n_cells ; i++ ){
661     for( j=0; j < n_cells; j++ ){
662     for( k=0; k < n_cells; k++ ){
663 chuckv 124
664 mmeineke 10 makeElement( i * cellx,
665     j * celly,
666     k * cellz );
667 chuckv 124
668 mmeineke 10 makeElement( i * cellx + 0.5 * cellx,
669     j * celly + 0.5 * celly,
670     k * cellz );
671 chuckv 124
672 mmeineke 10 makeElement( i * cellx,
673     j * celly + 0.5 * celly,
674     k * cellz + 0.5 * cellz );
675 chuckv 124
676 mmeineke 10 makeElement( i * cellx + 0.5 * cellx,
677     j * celly,
678     k * cellz + 0.5 * cellz );
679     }
680     }
681     }
682    
683     if( have_extra ){
684     done = 0;
685 chuckv 124
686 mmeineke 10 int start_ndx;
687     for( i=0; i < (n_cells+1) && !done; i++ ){
688     for( j=0; j < (n_cells+1) && !done; j++ ){
689 chuckv 124
690 mmeineke 10 if( i < n_cells ){
691 chuckv 124
692 mmeineke 10 if( j < n_cells ){
693     start_ndx = n_cells;
694     }
695     else start_ndx = 0;
696     }
697     else start_ndx = 0;
698 chuckv 124
699 mmeineke 10 for( k=start_ndx; k < (n_cells+1) && !done; k++ ){
700 chuckv 124
701 mmeineke 10 makeElement( i * cellx,
702     j * celly,
703     k * cellz );
704     done = ( current_mol >= tot_nmol );
705 chuckv 124
706 mmeineke 10 if( !done && n_per_extra > 1 ){
707     makeElement( i * cellx + 0.5 * cellx,
708     j * celly + 0.5 * celly,
709     k * cellz );
710     done = ( current_mol >= tot_nmol );
711     }
712 chuckv 124
713 mmeineke 10 if( !done && n_per_extra > 2){
714     makeElement( i * cellx,
715     j * celly + 0.5 * celly,
716     k * cellz + 0.5 * cellz );
717     done = ( current_mol >= tot_nmol );
718     }
719 chuckv 124
720 mmeineke 10 if( !done && n_per_extra > 3){
721     makeElement( i * cellx + 0.5 * cellx,
722     j * celly,
723     k * cellz + 0.5 * cellz );
724     done = ( current_mol >= tot_nmol );
725     }
726     }
727     }
728     }
729     }
730 chuckv 124
731    
732 mmeineke 10 for( i=0; i<simnfo->n_atoms; i++ ){
733     simnfo->atoms[i]->set_vx( 0.0 );
734     simnfo->atoms[i]->set_vy( 0.0 );
735     simnfo->atoms[i]->set_vz( 0.0 );
736     }
737     }
738    
739     void SimSetup::makeElement( double x, double y, double z ){
740    
741     int k;
742     AtomStamp* current_atom;
743     DirectionalAtom* dAtom;
744     double rotMat[3][3];
745    
746     for( k=0; k<comp_stamps[current_comp]->getNAtoms(); k++ ){
747 chuckv 124
748 mmeineke 10 current_atom = comp_stamps[current_comp]->getAtom( k );
749     if( !current_atom->havePosition() ){
750 mmeineke 189 sprintf( painCave.errMsg,
751     "SimSetup:initFromBass error.\n"
752     "\tComponent %s, atom %s does not have a position specified.\n"
753     "\tThe initialization routine is unable to give a start"
754     " position.\n",
755     comp_stamps[current_comp]->getID(),
756     current_atom->getType() );
757     painCave.isFatal = 1;
758     simError();
759 mmeineke 10 }
760 chuckv 124
761 mmeineke 10 the_atoms[current_atom_ndx]->setX( x + current_atom->getPosX() );
762     the_atoms[current_atom_ndx]->setY( y + current_atom->getPosY() );
763     the_atoms[current_atom_ndx]->setZ( z + current_atom->getPosZ() );
764 chuckv 124
765 mmeineke 10 if( the_atoms[current_atom_ndx]->isDirectional() ){
766 chuckv 124
767 mmeineke 10 dAtom = (DirectionalAtom *)the_atoms[current_atom_ndx];
768 chuckv 124
769 mmeineke 10 rotMat[0][0] = 1.0;
770     rotMat[0][1] = 0.0;
771     rotMat[0][2] = 0.0;
772    
773     rotMat[1][0] = 0.0;
774     rotMat[1][1] = 1.0;
775     rotMat[1][2] = 0.0;
776    
777     rotMat[2][0] = 0.0;
778     rotMat[2][1] = 0.0;
779     rotMat[2][2] = 1.0;
780    
781     dAtom->setA( rotMat );
782     }
783    
784     current_atom_ndx++;
785     }
786 chuckv 124
787 mmeineke 10 current_mol++;
788     current_comp_mol++;
789    
790     if( current_comp_mol >= components_nmol[current_comp] ){
791 chuckv 124
792 mmeineke 10 current_comp_mol = 0;
793     current_comp++;
794     }
795     }