ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/interface_implementation/SimSetup.cpp
Revision: 202
Committed: Tue Dec 10 21:41:26 2002 UTC (21 years, 6 months ago) by mmeineke
File size: 20969 byte(s)
Log Message:
*** empty log message ***

File Contents

# Content
1 #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 #include "simError.h"
10
11 #ifdef IS_MPI
12 #include "mpiBASS.h"
13 #include "bassDiag.hpp"
14 #endif
15
16 SimSetup::SimSetup(){
17 stamps = new MakeStamps();
18 globals = new Globals();
19
20 #ifdef IS_MPI
21 strcpy( checkPointMsg, "SimSetup creation successful" );
22 MPIcheckPoint();
23 #endif // IS_MPI
24 }
25
26 SimSetup::~SimSetup(){
27 delete stamps;
28 delete globals;
29 }
30
31 void SimSetup::parseFile( char* fileName ){
32
33 #ifdef IS_MPI
34 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 #endif
43
44 yacc_BASS( fileName );
45
46 #ifdef IS_MPI
47 throwMPIEvent(NULL);
48 }
49 else receiveParse();
50 #endif
51
52 }
53
54 #ifdef IS_MPI
55 void SimSetup::receiveParse(void){
56
57 set_interface_stamps( stamps, globals );
58 mpiEventInit();
59 MPIcheckPoint();
60 mpiEventLoop();
61
62 }
63
64
65 void SimSetup::testMe(void){
66 bassDiag* dumpMe = new bassDiag(globals,stamps);
67 dumpMe->dumpStamps();
68 delete dumpMe;
69 }
70 #endif
71
72 void SimSetup::createSim( void ){
73
74 MakeStamps *the_stamps;
75 Globals* the_globals;
76 int i, j;
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
92 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 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 // 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
113 if( !the_globals->haveNMol() ){
114 // we don't have the total number of molecules, so we assume it is
115 // given in each component
116
117 tot_nmol = 0;
118 for( i=0; i<n_components; i++ ){
119
120 if( !the_components[i]->haveNMol() ){
121 // we have a problem
122 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 }
128
129 tot_nmol += the_components[i]->getNMol();
130 components_nmol[i] = the_components[i]->getNMol();
131 }
132 }
133 else{
134 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
158 #ifdef IS_MPI
159 strcpy( checkPointMsg, "Have the number of components" );
160 MPIcheckPoint();
161 #endif // is_mpi
162
163 // make an array of molecule stamps that match the components used.
164 // also extract the used stamps out into a separate linked list
165
166 simnfo->nComponents = n_components;
167 simnfo->componentsNmol = components_nmol;
168 simnfo->compStamps = comp_stamps;
169 simnfo->headStamp = new LinkedMolStamp();
170
171 char* id;
172 LinkedMolStamp* headStamp = simnfo->headStamp;
173 LinkedMolStamp* currentStamp = NULL;
174 for( i=0; i<n_components; i++ ){
175
176 id = the_components[i]->getType();
177 comp_stamps[i] = NULL;
178
179 // check to make sure the component isn't already in the list
180
181 comp_stamps[i] = headStamp->match( id );
182 if( comp_stamps[i] == NULL ){
183
184 // extract the component from the list;
185
186 currentStamp = the_stamps->extractMolStamp( id );
187 if( currentStamp == NULL ){
188 sprintf( painCave.errMsg,
189 "SimSetup error: Component \"%s\" was not found in the "
190 "list of declared molecules\n"
191 id );
192 painCave.isFatal = 1;
193 simError();
194 }
195
196 headStamp->add( currentStamp );
197 comp_stamps[i] = headStamp->match( id );
198 }
199 }
200
201 #ifdef IS_MPI
202 strcpy( checkPointMsg, "Component stamps successfully extracted\n" );
203 MPIcheckPoint();
204 #endif // is_mpi
205
206
207
208
209 // caclulate the number of atoms, bonds, bends and torsions
210
211 tot_atoms = 0;
212 tot_bonds = 0;
213 tot_bends = 0;
214 tot_torsions = 0;
215 for( i=0; i<n_components; i++ ){
216
217 tot_atoms += components_nmol[i] * comp_stamps[i]->getNAtoms();
218 tot_bonds += components_nmol[i] * comp_stamps[i]->getNBonds();
219 tot_bends += components_nmol[i] * comp_stamps[i]->getNBends();
220 tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions();
221 }
222
223 tot_SRI = tot_bonds + tot_bends + tot_torsions;
224
225 simnfo->n_atoms = tot_atoms;
226 simnfo->n_bonds = tot_bonds;
227 simnfo->n_bends = tot_bends;
228 simnfo->n_torsions = tot_torsions;
229 simnfo->n_SRI = tot_SRI;
230 simnfo->n_mol = tot_nmol;
231
232
233 #ifdef IS_MPI
234
235 // divide the molecules among processors here.
236
237 mpiSimulation* mpiSim = new mpiSimulation( simnfo );
238
239 mpiSim->divideLabor();
240
241 // set up the local variables
242
243 int localMol;
244 int local_atoms, local_bonds, local_bends, local_torsions, local_SRI;
245
246 localMol = 0;
247 local_atoms = 0;
248 local_bonds = 0;
249 local_bends = 0;
250 local_torsions = 0;
251 for( i=0; i<n_components; i++ ){
252
253 for( j=0; j<components_nmol[i]; j++ ){
254
255 if( mpiSim->getMyMolStart() <= j &&
256 j <= mpiSim->getMyMolEnd() ){
257
258 local_atoms += comp_stamps[i]->getNAtoms();
259 local_bonds += comp_stamps[i]->getNBonds();
260 local_bends += comp_stamps[i]->getNBends();
261 local_torsions += comp_stamps[i]->getNTorsions();
262 localMol++;
263 }
264 }
265 }
266
267
268
269 simnfo->n_atoms = mpiSim->getMyNlocal();
270
271
272 #endif // is_mpi
273
274
275 // create the atom and short range interaction arrays
276
277 Atom::createArrays(simnfo->n_atoms);
278 the_atoms = new Atom*[simnfo->n_atoms];
279 the_molecules = new Molecule[simnfo->n_mol];
280
281
282 if( simnfo->n_SRI ){
283 the_sris = new SRI*[simnfo->n_SRI];
284 the_excludes = new ex_pair[simnfo->n_SRI];
285 }
286
287 // set the arrays into the SimInfo object
288
289 simnfo->atoms = the_atoms;
290 simnfo->sr_interactions = the_sris;
291 simnfo->n_exclude = tot_SRI;
292 simnfo->excludes = the_excludes;
293
294
295 // initialize the arrays
296
297 the_ff->setSimInfo( simnfo );
298
299 makeAtoms();
300
301 if( tot_bonds ){
302 makeBonds();
303 }
304
305 if( tot_bends ){
306 makeBends();
307 }
308
309 if( tot_torsions ){
310 makeTorsions();
311 }
312
313
314 // get some of the tricky things that may still be in the globals
315
316 if( simnfo->n_dipoles ){
317
318 if( !the_globals->haveRRF() ){
319 sprintf( painCave.errMsg,
320 "SimSetup Error, system has dipoles, but no rRF was set.\n");
321 painCave.isFatal = 1;
322 simError();
323 }
324 if( !the_globals->haveDielectric() ){
325 sprintf( painCave.errMsg,
326 "SimSetup Error, system has dipoles, but no"
327 " dielectric was set.\n" );
328 painCave.isFatal = 1;
329 simError();
330 }
331
332 simnfo->rRF = the_globals->getRRF();
333 simnfo->dielectric = the_globals->getDielectric();
334 }
335
336 #ifdef IS_MPI
337 strcpy( checkPointMsg, "rRf and dielectric check out" );
338 MPIcheckPoint();
339 #endif // is_mpi
340
341 if( the_globals->haveBox() ){
342 simnfo->box_x = the_globals->getBox();
343 simnfo->box_y = the_globals->getBox();
344 simnfo->box_z = the_globals->getBox();
345 }
346 else if( the_globals->haveDensity() ){
347
348 double vol;
349 vol = (double)tot_nmol / the_globals->getDensity();
350 simnfo->box_x = pow( vol, ( 1.0 / 3.0 ) );
351 simnfo->box_y = simnfo->box_x;
352 simnfo->box_z = simnfo->box_x;
353 }
354 else{
355 if( !the_globals->haveBoxX() ){
356 sprintf( painCave.errMsg,
357 "SimSetup error, no periodic BoxX size given.\n" );
358 painCave.isFatal = 1;
359 simError();
360 }
361 simnfo->box_x = the_globals->getBoxX();
362
363 if( !the_globals->haveBoxY() ){
364 sprintf( painCave.errMsg,
365 "SimSetup error, no periodic BoxY size given.\n" );
366 painCave.isFatal = 1;
367 simError();
368 }
369 simnfo->box_y = the_globals->getBoxY();
370
371 if( !the_globals->haveBoxZ() ){
372 sprintf( painCave.errMsg,
373 "SimSetup error, no periodic BoxZ size given.\n" );
374 painCave.isFatal = 1;
375 simError();
376 }
377 simnfo->box_z = the_globals->getBoxZ();
378 }
379
380 #ifdef IS_MPI
381 strcpy( checkPointMsg, "Box size set up" );
382 MPIcheckPoint();
383 #endif // is_mpi
384
385
386
387 // if( the_globals->haveInitialConfig() ){
388 // InitializeFromFile* fileInit;
389 // fileInit = new InitializeFromFile( the_globals->getInitialConfig() );
390
391 // fileInit->read_xyz( simnfo ); // default velocities on
392
393 // delete fileInit;
394 // }
395 // else{
396
397 #ifdef IS_MPI
398
399 // no init from bass
400
401 sprintf( painCave.errMsg,
402 "Cannot intialize a parallel simulation without an initial configuration file.\n" );
403 painCave.isFatal;
404 simError();
405
406 #else
407
408 initFromBass();
409
410 #endif // is_mpi
411
412 #ifdef IS_MPI
413 strcpy( checkPointMsg, "Successfully read in the initial configuration" );
414 MPIcheckPoint();
415 #endif // is_mpi
416
417
418
419
420
421 // }
422
423 #ifdef IS_MPI
424 if( worldRank == 0 ){
425 #endif // is_mpi
426
427 if( the_globals->haveFinalConfig() ){
428 strcpy( simnfo->finalName, the_globals->getFinalConfig() );
429 }
430 else{
431 strcpy( simnfo->finalName, inFileName );
432 char* endTest;
433 int nameLength = strlen( simnfo->finalName );
434 endTest = &(simnfo->finalName[nameLength - 5]);
435 if( !strcmp( endTest, ".bass" ) ){
436 strcpy( endTest, ".eor" );
437 }
438 else if( !strcmp( endTest, ".BASS" ) ){
439 strcpy( endTest, ".eor" );
440 }
441 else{
442 endTest = &(simnfo->finalName[nameLength - 4]);
443 if( !strcmp( endTest, ".bss" ) ){
444 strcpy( endTest, ".eor" );
445 }
446 else if( !strcmp( endTest, ".mdl" ) ){
447 strcpy( endTest, ".eor" );
448 }
449 else{
450 strcat( simnfo->finalName, ".eor" );
451 }
452 }
453 }
454
455 // make the sample and status out names
456
457 strcpy( simnfo->sampleName, inFileName );
458 char* endTest;
459 int nameLength = strlen( simnfo->sampleName );
460 endTest = &(simnfo->sampleName[nameLength - 5]);
461 if( !strcmp( endTest, ".bass" ) ){
462 strcpy( endTest, ".dump" );
463 }
464 else if( !strcmp( endTest, ".BASS" ) ){
465 strcpy( endTest, ".dump" );
466 }
467 else{
468 endTest = &(simnfo->sampleName[nameLength - 4]);
469 if( !strcmp( endTest, ".bss" ) ){
470 strcpy( endTest, ".dump" );
471 }
472 else if( !strcmp( endTest, ".mdl" ) ){
473 strcpy( endTest, ".dump" );
474 }
475 else{
476 strcat( simnfo->sampleName, ".dump" );
477 }
478 }
479
480 strcpy( simnfo->statusName, inFileName );
481 nameLength = strlen( simnfo->statusName );
482 endTest = &(simnfo->statusName[nameLength - 5]);
483 if( !strcmp( endTest, ".bass" ) ){
484 strcpy( endTest, ".stat" );
485 }
486 else if( !strcmp( endTest, ".BASS" ) ){
487 strcpy( endTest, ".stat" );
488 }
489 else{
490 endTest = &(simnfo->statusName[nameLength - 4]);
491 if( !strcmp( endTest, ".bss" ) ){
492 strcpy( endTest, ".stat" );
493 }
494 else if( !strcmp( endTest, ".mdl" ) ){
495 strcpy( endTest, ".stat" );
496 }
497 else{
498 strcat( simnfo->statusName, ".stat" );
499 }
500 }
501
502 #ifdef IS_MPI
503 }
504 #endif // is_mpi
505
506 // set the status, sample, and themal kick times
507
508 if( the_globals->haveSampleTime() ){
509 simnfo->sampleTime = the_globals->getSampleTime();
510 simnfo->statusTime = simnfo->sampleTime;
511 simnfo->thermalTime = simnfo->sampleTime;
512 }
513 else{
514 simnfo->sampleTime = the_globals->getRunTime();
515 simnfo->statusTime = simnfo->sampleTime;
516 simnfo->thermalTime = simnfo->sampleTime;
517 }
518
519 if( the_globals->haveStatusTime() ){
520 simnfo->statusTime = the_globals->getStatusTime();
521 }
522
523 if( the_globals->haveThermalTime() ){
524 simnfo->thermalTime = the_globals->getThermalTime();
525 }
526
527 // check for the temperature set flag
528
529 if( the_globals->haveTempSet() ) simnfo->setTemp = the_globals->getTempSet();
530
531
532 // make the longe range forces and the integrator
533
534 new AllLong( simnfo );
535
536 if( !strcmp( force_field, "TraPPE" ) ) new Verlet( *simnfo );
537 if( !strcmp( force_field, "DipoleTest" ) ) new Symplectic( simnfo );
538 if( !strcmp( force_field, "TraPPE_Ex" ) ) new Symplectic( simnfo );
539 }
540
541 void SimSetup::makeAtoms( void ){
542
543 int i, j, k, index;
544 double ux, uy, uz, uSqr, u;
545 AtomStamp* current_atom;
546 DirectionalAtom* dAtom;
547 int molIndex, molStart, molEnd, nMemb;
548
549
550 molIndex = 0;
551 index = 0;
552 for( i=0; i<n_components; i++ ){
553
554 for( j=0; j<components_nmol[i]; j++ ){
555
556 molStart = index;
557 nMemb = comp_stamps[i]->getNAtoms();
558 for( k=0; k<comp_stamps[i]->getNAtoms(); k++ ){
559
560 current_atom = comp_stamps[i]->getAtom( k );
561 if( current_atom->haveOrientation() ){
562
563 dAtom = new DirectionalAtom(index);
564 simnfo->n_oriented++;
565 the_atoms[index] = dAtom;
566
567 ux = current_atom->getOrntX();
568 uy = current_atom->getOrntY();
569 uz = current_atom->getOrntZ();
570
571 uSqr = (ux * ux) + (uy * uy) + (uz * uz);
572
573 u = sqrt( uSqr );
574 ux = ux / u;
575 uy = uy / u;
576 uz = uz / u;
577
578 dAtom->setSUx( ux );
579 dAtom->setSUy( uy );
580 dAtom->setSUz( uz );
581 }
582 else{
583 the_atoms[index] = new GeneralAtom(index);
584 }
585 the_atoms[index]->setType( current_atom->getType() );
586 the_atoms[index]->setIndex( index );
587
588 // increment the index and repeat;
589 index++;
590 }
591
592 molEnd = index -1;
593 the_molecules[molIndex].setNMembers( nMemb );
594 the_molecules[molIndex].setStartAtom( molStart );
595 the_molecules[molIndex].setEndAtom( molEnd );
596 the_molecules[molIndex].setStampID( i );
597 molIndex++;
598
599 }
600 }
601
602 the_ff->initializeAtoms();
603 }
604
605 void SimSetup::makeBonds( void ){
606
607 int i, j, k, index, offset;
608 bond_pair* the_bonds;
609 BondStamp* current_bond;
610
611 the_bonds = new bond_pair[tot_bonds];
612 index = 0;
613 offset = 0;
614 for( i=0; i<n_components; i++ ){
615
616 for( j=0; j<components_nmol[i]; j++ ){
617
618 for( k=0; k<comp_stamps[i]->getNBonds(); k++ ){
619
620 current_bond = comp_stamps[i]->getBond( k );
621 the_bonds[index].a = current_bond->getA() + offset;
622 the_bonds[index].b = current_bond->getB() + offset;
623
624 the_excludes[index].i = the_bonds[index].a;
625 the_excludes[index].j = the_bonds[index].b;
626
627 // increment the index and repeat;
628 index++;
629 }
630 offset += comp_stamps[i]->getNAtoms();
631 }
632 }
633
634 the_ff->initializeBonds( the_bonds );
635 }
636
637 void SimSetup::makeBends( void ){
638
639 int i, j, k, index, offset;
640 bend_set* the_bends;
641 BendStamp* current_bend;
642
643 the_bends = new bend_set[tot_bends];
644 index = 0;
645 offset = 0;
646 for( i=0; i<n_components; i++ ){
647
648 for( j=0; j<components_nmol[i]; j++ ){
649
650 for( k=0; k<comp_stamps[i]->getNBends(); k++ ){
651
652 current_bend = comp_stamps[i]->getBend( k );
653 the_bends[index].a = current_bend->getA() + offset;
654 the_bends[index].b = current_bend->getB() + offset;
655 the_bends[index].c = current_bend->getC() + offset;
656
657 the_excludes[index + tot_bonds].i = the_bends[index].a;
658 the_excludes[index + tot_bonds].j = the_bends[index].c;
659
660 // increment the index and repeat;
661 index++;
662 }
663 offset += comp_stamps[i]->getNAtoms();
664 }
665 }
666
667 the_ff->initializeBends( the_bends );
668 }
669
670 void SimSetup::makeTorsions( void ){
671
672 int i, j, k, index, offset;
673 torsion_set* the_torsions;
674 TorsionStamp* current_torsion;
675
676 the_torsions = new torsion_set[tot_torsions];
677 index = 0;
678 offset = 0;
679 for( i=0; i<n_components; i++ ){
680
681 for( j=0; j<components_nmol[i]; j++ ){
682
683 for( k=0; k<comp_stamps[i]->getNTorsions(); k++ ){
684
685 current_torsion = comp_stamps[i]->getTorsion( k );
686 the_torsions[index].a = current_torsion->getA() + offset;
687 the_torsions[index].b = current_torsion->getB() + offset;
688 the_torsions[index].c = current_torsion->getC() + offset;
689 the_torsions[index].d = current_torsion->getD() + offset;
690
691 the_excludes[index + tot_bonds + tot_bends].i = the_torsions[index].a;
692 the_excludes[index + tot_bonds + tot_bends].j = the_torsions[index].d;
693
694 // increment the index and repeat;
695 index++;
696 }
697 offset += comp_stamps[i]->getNAtoms();
698 }
699 }
700
701 the_ff->initializeTorsions( the_torsions );
702 }
703
704 void SimSetup::initFromBass( void ){
705
706 int i, j, k;
707 int n_cells;
708 double cellx, celly, cellz;
709 double temp1, temp2, temp3;
710 int n_per_extra;
711 int n_extra;
712 int have_extra, done;
713
714 temp1 = (double)tot_nmol / 4.0;
715 temp2 = pow( temp1, ( 1.0 / 3.0 ) );
716 temp3 = ceil( temp2 );
717
718 have_extra =0;
719 if( temp2 < temp3 ){ // we have a non-complete lattice
720 have_extra =1;
721
722 n_cells = (int)temp3 - 1;
723 cellx = simnfo->box_x / temp3;
724 celly = simnfo->box_y / temp3;
725 cellz = simnfo->box_z / temp3;
726 n_extra = tot_nmol - ( 4 * n_cells * n_cells * n_cells );
727 temp1 = ((double)n_extra) / ( pow( temp3, 3.0 ) - pow( n_cells, 3.0 ) );
728 n_per_extra = (int)ceil( temp1 );
729
730 if( n_per_extra > 4){
731 sprintf( painCave.errMsg,
732 "SimSetup error. There has been an error in constructing"
733 " the non-complete lattice.\n" );
734 painCave.isFatal = 1;
735 simError();
736 }
737 }
738 else{
739 n_cells = (int)temp3;
740 cellx = simnfo->box_x / temp3;
741 celly = simnfo->box_y / temp3;
742 cellz = simnfo->box_z / temp3;
743 }
744
745 current_mol = 0;
746 current_comp_mol = 0;
747 current_comp = 0;
748 current_atom_ndx = 0;
749
750 for( i=0; i < n_cells ; i++ ){
751 for( j=0; j < n_cells; j++ ){
752 for( k=0; k < n_cells; k++ ){
753
754 makeElement( i * cellx,
755 j * celly,
756 k * cellz );
757
758 makeElement( i * cellx + 0.5 * cellx,
759 j * celly + 0.5 * celly,
760 k * cellz );
761
762 makeElement( i * cellx,
763 j * celly + 0.5 * celly,
764 k * cellz + 0.5 * cellz );
765
766 makeElement( i * cellx + 0.5 * cellx,
767 j * celly,
768 k * cellz + 0.5 * cellz );
769 }
770 }
771 }
772
773 if( have_extra ){
774 done = 0;
775
776 int start_ndx;
777 for( i=0; i < (n_cells+1) && !done; i++ ){
778 for( j=0; j < (n_cells+1) && !done; j++ ){
779
780 if( i < n_cells ){
781
782 if( j < n_cells ){
783 start_ndx = n_cells;
784 }
785 else start_ndx = 0;
786 }
787 else start_ndx = 0;
788
789 for( k=start_ndx; k < (n_cells+1) && !done; k++ ){
790
791 makeElement( i * cellx,
792 j * celly,
793 k * cellz );
794 done = ( current_mol >= tot_nmol );
795
796 if( !done && n_per_extra > 1 ){
797 makeElement( i * cellx + 0.5 * cellx,
798 j * celly + 0.5 * celly,
799 k * cellz );
800 done = ( current_mol >= tot_nmol );
801 }
802
803 if( !done && n_per_extra > 2){
804 makeElement( i * cellx,
805 j * celly + 0.5 * celly,
806 k * cellz + 0.5 * cellz );
807 done = ( current_mol >= tot_nmol );
808 }
809
810 if( !done && n_per_extra > 3){
811 makeElement( i * cellx + 0.5 * cellx,
812 j * celly,
813 k * cellz + 0.5 * cellz );
814 done = ( current_mol >= tot_nmol );
815 }
816 }
817 }
818 }
819 }
820
821
822 for( i=0; i<simnfo->n_atoms; i++ ){
823 simnfo->atoms[i]->set_vx( 0.0 );
824 simnfo->atoms[i]->set_vy( 0.0 );
825 simnfo->atoms[i]->set_vz( 0.0 );
826 }
827 }
828
829 void SimSetup::makeElement( double x, double y, double z ){
830
831 int k;
832 AtomStamp* current_atom;
833 DirectionalAtom* dAtom;
834 double rotMat[3][3];
835
836 for( k=0; k<comp_stamps[current_comp]->getNAtoms(); k++ ){
837
838 current_atom = comp_stamps[current_comp]->getAtom( k );
839 if( !current_atom->havePosition() ){
840 sprintf( painCave.errMsg,
841 "SimSetup:initFromBass error.\n"
842 "\tComponent %s, atom %s does not have a position specified.\n"
843 "\tThe initialization routine is unable to give a start"
844 " position.\n",
845 comp_stamps[current_comp]->getID(),
846 current_atom->getType() );
847 painCave.isFatal = 1;
848 simError();
849 }
850
851 the_atoms[current_atom_ndx]->setX( x + current_atom->getPosX() );
852 the_atoms[current_atom_ndx]->setY( y + current_atom->getPosY() );
853 the_atoms[current_atom_ndx]->setZ( z + current_atom->getPosZ() );
854
855 if( the_atoms[current_atom_ndx]->isDirectional() ){
856
857 dAtom = (DirectionalAtom *)the_atoms[current_atom_ndx];
858
859 rotMat[0][0] = 1.0;
860 rotMat[0][1] = 0.0;
861 rotMat[0][2] = 0.0;
862
863 rotMat[1][0] = 0.0;
864 rotMat[1][1] = 1.0;
865 rotMat[1][2] = 0.0;
866
867 rotMat[2][0] = 0.0;
868 rotMat[2][1] = 0.0;
869 rotMat[2][2] = 1.0;
870
871 dAtom->setA( rotMat );
872 }
873
874 current_atom_ndx++;
875 }
876
877 current_mol++;
878 current_comp_mol++;
879
880 if( current_comp_mol >= components_nmol[current_comp] ){
881
882 current_comp_mol = 0;
883 current_comp++;
884 }
885 }