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

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